• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
2  *
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions are
5  * met:
6  *     * Redistributions of source code must retain the above copyright
7  *       notice, this list of conditions and the following disclaimer.
8  *     * Redistributions in binary form must reproduce the above
9  *       copyright notice, this list of conditions and the following
10  *       disclaimer in the documentation and/or other materials provided
11  *       with the distribution.
12  *     * Neither the name of The Linux Foundation. nor the names of its
13  *       contributors may be used to endorse or promote products derived
14  *       from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 #ifndef __c2d2_h_
30 #define __c2d2_h_
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #ifndef C2D_API
37 #define C2D_API /* define API export as needed */
38 #endif
39 #if !defined(int32) && !defined(_INT32_DEFINED)
40 typedef int                     int32;
41 #define _INT32_DEFINED
42 #endif
43 #if !defined(uint32) && !defined(_UINT32_DEFINED)
44 typedef unsigned int            uint32;
45 #define _UINT32_DEFINED
46 #endif
47 
48 /*****************************************************************************/
49 /*********************** Blit definitions *****************************/
50 /*****************************************************************************/
51 
52 /* Status codes, returned by any blit function */
53 typedef enum {
54     C2D_STATUS_OK              = 0,
55     C2D_STATUS_NOT_SUPPORTED   = 1,
56     C2D_STATUS_OUT_OF_MEMORY   = 2,
57     C2D_STATUS_INVALID_PARAM   = 3,
58     C2D_STATUS_SURFACE_IN_USE  = 4,
59 } C2D_STATUS;
60 
61 
62 /* Definitions of color format modes, used together with color formats */
63 typedef enum {
64     C2D_FORMAT_PACK_INTO_32BIT   = (1 <<  8), /* pack into dword if set */
65     C2D_FORMAT_SWAP_ENDIANNESS   = (1 <<  9), /* swaps the order */
66     C2D_FORMAT_LINEAR_SPACE      = (1 << 10), /* linear color space */
67     C2D_FORMAT_PREMULTIPLIED     = (1 << 11), /* alpha premultiplied */
68     C2D_FORMAT_INVERT_ALPHA      = (1 << 12), /* inverts alpha */
69     C2D_FORMAT_DISABLE_ALPHA     = (1 << 13), /* disables alpha */
70     C2D_FORMAT_INTERLACED        = (1 << 14), /* YUV line-interlaced */
71     C2D_FORMAT_TRANSPARENT       = (1 << 15), /* YUV 1-bit alpha in Y */
72     C2D_FORMAT_MACROTILED        = (1 << 16), /* tiled in macro level */
73     C2D_FORMAT_TILED_4x4         = (1 << 17), /* 4x4 tiled format */
74     C2D_FORMAT_SWAP_RB           = (1 << 18), /* Swap R & B color components */
75 } C2D_FORMAT_MODE;
76 
77 /* Definitions of supported RGB formats, used in C2D_RGB_SURFACE_DEF.
78  * The bits of each color channel are packed into a machine word
79  * representing a single pixel from left to right (MSB to LSB) in the
80  * order indicated by format name. For the sub-byte formats the pixels
81  * are packed into bytes from left to right (MSbit to LSBit).
82  * If the C2D_FORMAT_PACK_INTO_32BIT bit is set, the minimal
83  * machine word used for pixel storage is 32-bit and the whole word
84  * is reversed if endianness is swapped.
85  * If the C2D_FORMAT_SWAP_ENDIANNESS bit is set, the order within a
86  * minimal machine word representing a pixel
87  * is reversed for both sub-byte and multi-byte formats.
88  * If the C2D_FORMAT_LINEAR_SPACE bit is set, the color space of
89  * the formats below is considered linear, if applicable.
90  * If the C2D_FORMAT_PREMULTIPLIED bit is set, the color channels
91  * are premultiplied with the alpha, if applicable.
92  * If the C2D_FORMAT_INVERT_ALPHA bit is set, the alpha interpretation
93  * is inverted: 0 - opaque, 1 - transparent, if applicable.
94  * If the C2D_FORMAT_DISABLE_ALPHA bit is set, the alpha channel serves
95  * as a placeholder and is ignored during blit, if applicable.
96  * If the C2D_FORMAT_MACROTILED bit is set, the surface is in the
97  * tiled format : 64x32 for 8bpp, 32x32 for 16bpp formats  */
98 typedef enum {
99     C2D_COLOR_FORMAT_1            = 0,   /* 1-bit alpha/color expansion */
100 
101     C2D_COLOR_FORMAT_2_PALETTE    = 1,   /* 2-bit indices for palette */
102     C2D_COLOR_FORMAT_4_PALETTE    = 2,   /* 4-bit indices for palette */
103     C2D_COLOR_FORMAT_8_PALETTE    = 3,   /* 8-bit indices for palette */
104 
105     C2D_COLOR_FORMAT_2_L          = 4,   /* 2-bit grayscale */
106     C2D_COLOR_FORMAT_4_L          = 5,   /* 4-bit grayscale */
107     C2D_COLOR_FORMAT_8_L          = 6,   /* 8-bit grayscale */
108 
109     C2D_COLOR_FORMAT_2_A          = 7,   /* 2-bit alpha only */
110     C2D_COLOR_FORMAT_4_A          = 8,   /* 4-bit alpha only */
111     C2D_COLOR_FORMAT_8_A          = 9,   /* 8-bit alpha only */
112 
113     C2D_COLOR_FORMAT_444_RGB      = 10,  /* 12-bit colors */
114     C2D_COLOR_FORMAT_565_RGB      = 11,  /* 16-bit colors */
115     C2D_COLOR_FORMAT_888_RGB      = 12,  /* 24-bit colors */
116 
117     C2D_COLOR_FORMAT_1555_ARGB    = 13,  /* 16-bit colors (1-bit alpha) */
118     C2D_COLOR_FORMAT_4444_ARGB    = 14,  /* 16-bit colors (4-bit alpha) */
119     C2D_COLOR_FORMAT_8565_ARGB    = 15,  /* 24-bit colors (8-bit alpha) */
120     C2D_COLOR_FORMAT_8888_ARGB    = 16,  /* 32-bit colors (8-bit alpha) */
121 
122     C2D_COLOR_FORMAT_5551_RGBA    = 17,  /* 16-bit colors (1-bit alpha) */
123     C2D_COLOR_FORMAT_4444_RGBA    = 18,  /* 16-bit colors (4-bit alpha) */
124     C2D_COLOR_FORMAT_5658_RGBA    = 19,  /* 24-bit colors (8-bit alpha) */
125     C2D_COLOR_FORMAT_8888_RGBA    = 20,  /* 32-bit colors (8-bit alpha) */
126 
127     /* derived RGB color formats (base format + mode bits) */
128 
129 } C2D_RGB_FORMAT;
130 
131 /* Definitions of supported YUV formats, used in C2D_YUV_SURFACE_DEF.
132  * Each of Y,U,V channels usually takes 1 byte and therefore is
133  * individually addressable. The definitions below show how Y,U,V
134  * channels are packed into macropixels for each particular format.
135  * The order is from left (smaller byte addresses) to right (larger
136  * byte addresses). The first three digits (4xx) denote the chroma
137  * subsampling in standard YUV notation. The digits in the macropixel
138  * denote that the whole block (from the previous digit or from the
139  * beginning) has to be repeated the number of times. Underscores
140  * between Y,U,V channels are used to describe separate planes for
141  * planar YUV formats. Formats are mapped to numbers so that future
142  * versions with various YUV permutations are easy to add.
143  * If the C2D_FORMAT_INTERLACED bit is set, the line order is
144  * interlaced: 0,2,4,...1,3,5... if applicable.
145  * If the C2D_FORMAT_TRANSPARENT bit is set, the least significant
146  * bit of Y channel serves as alpha: 0 - transparent, 1 - opaque. */
147 typedef enum {
148     C2D_COLOR_FORMAT_411_YYUYYV   = 110, /* packed, 12-bit         */
149     C2D_COLOR_FORMAT_411_YUYYVY   = 111, /* packed, 12-bit         */
150     C2D_COLOR_FORMAT_411_UYYVYY   = 112, /* packed, 12-bit, "Y411" */
151     C2D_COLOR_FORMAT_411_YUYV2Y4  = 116, /* packed, 12-bit         */
152     C2D_COLOR_FORMAT_411_UYVY2Y4  = 117, /* packed, 12-bit, "Y41P" */
153 
154     C2D_COLOR_FORMAT_422_YUYV     = 120, /* packed, 16-bit, "YUY2" */
155     C2D_COLOR_FORMAT_422_UYVY     = 121, /* packed, 16-bit, "UYVY" */
156     C2D_COLOR_FORMAT_422_YVYU     = 122, /* packed, 16-bit, "YVYU" */
157     C2D_COLOR_FORMAT_422_VYUY     = 123, /* packed, 16-bit         */
158 
159     C2D_COLOR_FORMAT_444_YUV      = 130, /* packed, 24-bit         */
160     C2D_COLOR_FORMAT_444_UYV      = 131, /* packed, 24-bit, "IYU2" */
161     C2D_COLOR_FORMAT_444_AYUV     = 136, /* packed, 24-bit, "AYUV" */
162 
163     C2D_COLOR_FORMAT_410_Y_UV     = 150, /* planar, Y + interleaved UV */
164     C2D_COLOR_FORMAT_411_Y_UV     = 151, /* planar, Y + interleaved UV */
165     C2D_COLOR_FORMAT_420_Y_UV     = 152, /* planar, Y + interleaved UV */
166     C2D_COLOR_FORMAT_422_Y_UV     = 153, /* planar, Y + interleaved UV */
167     C2D_COLOR_FORMAT_444_Y_UV     = 154, /* planar, Y + interleaved UV */
168 
169     C2D_COLOR_FORMAT_410_Y_VU     = 160, /* planar, Y + interleaved VU */
170     C2D_COLOR_FORMAT_411_Y_VU     = 161, /* planar, Y + interleaved VU */
171     C2D_COLOR_FORMAT_420_Y_VU     = 162, /* planar, Y + interleaved VU */
172     C2D_COLOR_FORMAT_422_Y_VU     = 163, /* planar, Y + interleaved VU */
173     C2D_COLOR_FORMAT_444_Y_VU     = 164, /* planar, Y + interleaved VU */
174 
175     C2D_COLOR_FORMAT_410_Y_U_V    = 170, /* planar, Y + U + V separate */
176     C2D_COLOR_FORMAT_411_Y_U_V    = 171, /* planar, Y + U + V separate */
177     C2D_COLOR_FORMAT_420_Y_V_U    = 172, /* planar, Y + V + U separate */
178     C2D_COLOR_FORMAT_420_Y_U_V    = 173, /* planar, Y + U + V separate */
179     C2D_COLOR_FORMAT_422_Y_U_V    = 174, /* planar, Y + U + V separate */
180     C2D_COLOR_FORMAT_444_Y_U_V    = 175, /* planar, Y + U + V separate */
181 
182     C2D_COLOR_FORMAT_800_Y        = 190, /* planar, Y only, grayscale */
183 
184     /* derived YUV color formats (base format + mode bits), FOURCC */
185 
186     C2D_COLOR_FORMAT_411_Y411     = 112,
187     C2D_COLOR_FORMAT_411_Y41P     = 117,
188     C2D_COLOR_FORMAT_411_IY41     = 117 | (1 << 14),
189     C2D_COLOR_FORMAT_411_Y41T     = 117 | (1 << 15),
190 
191     C2D_COLOR_FORMAT_422_YUY2     = 120,
192     C2D_COLOR_FORMAT_422_IUYV     = 121 | (1 << 14),
193     C2D_COLOR_FORMAT_422_Y42T     = 121 | (1 << 15),
194     C2D_COLOR_FORMAT_444_IYU2     = 131,
195 
196     C2D_COLOR_FORMAT_420_NV12     = 152,
197     C2D_COLOR_FORMAT_420_NV21     = 162,
198 
199     C2D_COLOR_FORMAT_410_YUV9     = 170,
200     C2D_COLOR_FORMAT_410_YVU9     = 170,
201     C2D_COLOR_FORMAT_411_Y41B     = 171,
202     C2D_COLOR_FORMAT_420_YV12     = 172,
203     C2D_COLOR_FORMAT_420_IYUV     = 173,
204     C2D_COLOR_FORMAT_420_I420     = 173,
205     C2D_COLOR_FORMAT_422_YV16     = 174,
206     C2D_COLOR_FORMAT_422_Y42B     = 174,
207 
208     C2D_COLOR_FORMAT_800_Y800     = 190,
209 
210 } C2D_YUV_FORMAT;
211 
212 
213 /* Configuration bits, used in the config_mask field of C2D_OBJECT struct */
214 typedef enum {
215     C2D_SOURCE_RECT_BIT      = (1 <<  0), /* enables source_rect field */
216     C2D_MIRROR_H_BIT         = (1 <<  1), /* enables horizontal flipping */
217     C2D_MIRROR_V_BIT         = (1 <<  2), /* enables vertical flipping */
218     C2D_SOURCE_TILE_BIT      = (1 <<  3), /* enables source surface tiling */
219     C2D_TARGET_RECT_BIT      = (1 <<  4), /* enables target_rect field */
220     C2D_ROTATE_BIT           = (1 <<  5), /* enables all rotation fields */
221     C2D_SCISSOR_RECT_BIT     = (1 <<  6), /* enables scissor_rect field */
222     C2D_MASK_SURFACE_BIT     = (1 <<  7), /* enables mask_surface_id field */
223     C2D_MASK_ALIGN_BIT       = (1 <<  8), /* aligns mask to source_rect */
224     C2D_MASK_SCALE_BIT       = (1 <<  9), /* enables mask surface scaling */
225     C2D_MASK_TILE_BIT        = (1 << 10), /* enables mask surface tiling */
226     C2D_GLOBAL_ALPHA_BIT     = (1 << 11), /* enables global_alpha field */
227     C2D_COLOR_KEY_BIT        = (1 << 12), /* enables color_key field */
228     C2D_NO_PIXEL_ALPHA_BIT   = (1 << 13), /* disables source alpha channel */
229     C2D_NO_BILINEAR_BIT      = (1 << 14), /* disables bilinear on scaling */
230     C2D_NO_ANTIALIASING_BIT  = (1 << 15), /* disables antialiasing on edges */
231     C2D_DRAW_LINE_BIT        = (1 << 16), /* enables line drawing with source rectangle */
232     C2D_DRAW_LINE_NOLAST     = (1 << 17), /* disable last pixel draw for line */
233 } C2D_SOURCE_CONFIG;
234 
235 
236 /* Target configuration bits, defines rotation + mirroring.
237  * Mirror is applied prior to rotation if enabled. */
238 typedef enum {
239     C2D_TARGET_MIRROR_H        = (1 << 0), /* horizontal flip */
240     C2D_TARGET_MIRROR_V        = (1 << 1), /* vertical flip */
241     C2D_TARGET_ROTATE_0        = (0 << 2), /* no rotation */
242     C2D_TARGET_ROTATE_90       = (1 << 2), /* 90 degree rotation */
243     C2D_TARGET_ROTATE_180      = (2 << 2), /* 180 degree rotation */
244     C2D_TARGET_ROTATE_270      = (3 << 2), /* 270 degree rotation, 90 + 180 */
245     C2D_TARGET_MASK_ALIGN      = (1 << 4), /* aligns mask to target scissor */
246     C2D_TARGET_MASK_SCALE      = (1 << 5), /* enables mask scaling */
247     C2D_TARGET_MASK_TILE       = (1 << 6), /* enables mask tiling */
248     C2D_TARGET_COLOR_KEY       = (1 << 7), /* enables target_color_key */
249     C2D_TARGET_NO_PIXEL_ALPHA  = (1 << 8), /* disables target alpha channel */
250 } C2D_TARGET_CONFIG;
251 
252 #define C2D_TARGET_ROTATION_MASK  (C2D_TARGET_ROTATE_90*3)
253 
254 /* Additional blend modes, can be used with both source and target configs.
255    If none of the below is set, the default "SRC over DST" is applied. */
256 typedef enum {
257     C2D_ALPHA_BLEND_SRC_OVER   = (0  << 20), /* Default, Porter-Duff "SRC over DST" */
258     C2D_ALPHA_BLEND_SRC        = (1  << 20), /* Porter-Duff "SRC" */
259     C2D_ALPHA_BLEND_SRC_IN     = (2  << 20), /* Porter-Duff "SRC in DST" */
260     C2D_ALPHA_BLEND_DST_IN     = (3  << 20), /* Porter-Duff "DST in SRC" */
261     C2D_ALPHA_BLEND_SRC_OUT    = (4  << 20), /* Porter-Duff "SRC out DST" */
262     C2D_ALPHA_BLEND_DST_OUT    = (5  << 20), /* Porter-Duff "DST out SRC" */
263     C2D_ALPHA_BLEND_DST_OVER   = (6  << 20), /* Porter-Duff "DST over SRC" */
264     C2D_ALPHA_BLEND_SRC_ATOP   = (7  << 20), /* Porter-Duff "SRC ATOP" */
265     C2D_ALPHA_BLEND_DST_ATOP   = (8  << 20), /* Porter-Duff "DST ATOP" */
266     C2D_ALPHA_BLEND_XOR        = (9  << 20), /* Xor */
267     C2D_ALPHA_BLEND_MULTIPLY   = (10 << 20), /* OpenVG "MULTIPLY" */
268     C2D_ALPHA_BLEND_SCREEN     = (11 << 20), /* OpenVG "SCREEN" */
269     C2D_ALPHA_BLEND_DARKEN     = (12 << 20), /* OpenVG "DARKEN" */
270     C2D_ALPHA_BLEND_LIGHTEN    = (13 << 20), /* OpenVG "LIGHTEN" */
271     C2D_ALPHA_BLEND_ADDITIVE   = (14 << 20), /* OpenVG "ADDITIVE" */
272     C2D_ALPHA_BLEND_DIRECT     = (15 << 20), /* Direct alpha blitting */
273     C2D_ALPHA_BLEND_INVERTC    = (16 << 20), /* Invert color */
274     C2D_ALPHA_BLEND_NONE       = (1  << 25), /* disables alpha blending */
275 } C2D_ALPHA_BLEND_MODE;
276 
277 /* Configuration bits, used in the config_mask field of C2D_OBJECT struct */
278 typedef enum {
279     C2D_OVERRIDE_GLOBAL_TARGET_ROTATE_CONFIG = (1 << 27), /* Overrides TARGET Config */
280     C2D_OVERRIDE_TARGET_ROTATE_0             = (0 << 28), /* no rotation             */
281     C2D_OVERRIDE_TARGET_ROTATE_90            = (1 << 28), /* 90 degree rotation      */
282     C2D_OVERRIDE_TARGET_ROTATE_180           = (2 << 28), /* 180 degree rotation     */
283     C2D_OVERRIDE_TARGET_ROTATE_270           = (3 << 28), /* 270 degree rotation     */
284 } C2D_SOURCE_TARGET_CONFIG;
285 
286 #define C2D_OVERRIDE_SOURCE_CONFIG_TARGET_ROTATION_SHIFT_MASK  28
287 #define C2D_OVERRIDE_TARGET_CONFIG_TARGET_ROTATION_SHIFT_MASK  2
288 
289 
290 /* Surface caps enumeration */
291 typedef enum {
292     C2D_SOURCE          = (1 << 0), /* allows to use as a source */
293     C2D_TARGET          = (1 << 1), /* allows to use as a target */
294     C2D_MASK            = (1 << 2), /* allows to use as a mask */
295     C2D_PALETTE         = (1 << 3), /* allows to use as a palette */
296 } C2D_SURFACE_BITS;
297 
298 /* Surface type enumeration */
299 typedef enum {
300     C2D_SURFACE_RGB_HOST        = 1, /* Host memory RGB surface */
301     C2D_SURFACE_RGB_EXT         = 2, /* External memory RGB surface */
302     C2D_SURFACE_YUV_HOST        = 3, /* Host memory YUV surface */
303     C2D_SURFACE_YUV_EXT         = 4, /* External memory YUV surface */
304     C2D_SURFACE_WITH_PHYS       = (1<<3), /* physical address already mapped */
305                                         /* this bit is valid with HOST types */
306     C2D_SURFACE_WITH_PHYS_DUMMY = (1<<4), /* physical address already mapped */
307                                         /* this bit is valid with HOST types */
308 } C2D_SURFACE_TYPE;
309 
310 /* Structure for registering a RGB buffer as a blit surface */
311 typedef struct {
312     uint32 format;   /* RGB color format plus additional mode bits */
313     uint32 width;    /* defines width in pixels */
314     uint32 height;   /* defines height in pixels */
315     void  *buffer;   /* pointer to the RGB buffer */
316     void  *phys;     /* physical address */
317     int32  stride;   /* defines stride in bytes, negative stride is allowed */
318 } C2D_RGB_SURFACE_DEF;
319 
320 /* Structure for registering a YUV plane(s) as a blit surface */
321 typedef struct {
322     uint32 format;   /* YUV color format plus additional mode bits */
323     uint32 width;    /* defines width in pixels */
324     uint32 height;   /* defines height in pixels */
325     void  *plane0;  /* holds the whole buffer if YUV format is not planar */
326     void  *phys0;   /* physical address */
327     int32  stride0; /* stride in bytes if YUV format is not planar */
328     void  *plane1;  /* holds UV or VU plane for planar interleaved */
329     void  *phys1;   /* physical address */
330     int32  stride1; /* stride for UV or VU plane for planar interleaved */
331     void  *plane2;  /* holds the 3. plane, ignored if YUV format is not planar */
332     void  *phys2;    /* physical address */
333     int32  stride2; /* stride for the 3. plane, ignored if YUV format is not planar */
334 } C2D_YUV_SURFACE_DEF;
335 
336 
337 /* Rectangle definition */
338 typedef struct {
339     int32 x;        /* upper-left x */
340     int32 y;        /* upper-left y */
341     int32 width;    /* width */
342     int32 height;   /* height */
343 } C2D_RECT;
344 
345 /* C2D_OBJECT encapsulates the blit parameters for a source surface.
346  * The fg_color defines color in target format for bits equal to 1
347  * in the source C2D_COLOR_FORMAT_1 format. It also defines rendering
348  * color for all alpha-only source formats. If the surface_id is 0
349  * the fg_color defines a constant fill color used instead of the surface.
350  * The bg_color defines color in target format for bits equal to 0
351  * in the source C2D_COLOR_FORMAT_1 format, otherwise both are ignored.
352  * The palette_id is used for all palette source formats, otherwise ignored.
353 
354  * The source_rect first defines the content of the source surface,
355  * it is then horizontally/vertically flipped if C2D_MIRROR_*_BIT is set,
356  * then scaled with bilinear interpolation to exactly fit target_rect
357  * or repeated across target_rect if C2D_SOURCE_TILE_BIT is set,
358  * target_rect is then rotated clockwise by an arbitrary angle in degrees
359  * around the rot_orig_x/y, defined relative to target_rect's top left point,
360  * and then clipped to scissor_rect defined in target coordinate system.
361 
362  * Finally alpha blending is applied before pixels get written into the target.
363  * Surface's pixel alpha is combined with mask alpha and with global alpha.
364  * Mask surface follows all transformations applied to the source surface.
365  * Source color key defines transparent color, applied together with alpha. */
366 typedef struct C2D_OBJECT_STR {
367     uint32 surface_id;      /* source surface */
368 
369     uint32 fg_color;        /* foreground color */
370     uint32 bg_color;        /* background color */
371     uint32 palette_id;      /* one-dimensional horizontal palette surface */
372 
373     uint32 config_mask;     /* defines which fields below are enabled */
374 
375     C2D_RECT source_rect;  /* region of the source surface,   16.16 fp */
376     C2D_RECT target_rect;  /* position and scaling in target, 16.16 fp */
377 
378     int32 rot_orig_x;       /* rotation origin relative to target_rect's... */
379     int32 rot_orig_y;       /* ...top left point,     both are 16.16 fp */
380     int32 rotation;         /* clock-wise rotation in degrees, 16.16 fp */
381 
382     C2D_RECT scissor_rect; /* defines the clip rectangle in target surface */
383 
384     uint32 mask_surface_id; /* source alpha-mask surface */
385     uint32 global_alpha;    /* 0 = fully transparent, 255 = fully opaque */
386     uint32 color_key;       /* transparent color for the source surface */
387 
388     struct C2D_OBJECT_STR *next; /* pointer to the next object or NULL */
389 } C2D_OBJECT;
390 
391 /* Configuration bits, driver capabilities used by 2Dapplications */
392 typedef enum {
393     C2D_DRIVER_SUPPORTS_GLOBAL_ALPHA_OP           = (1 << 0),
394     C2D_DRIVER_SUPPORTS_TILE_OP                   = (1 << 1),
395     C2D_DRIVER_SUPPORTS_COLOR_KEY_OP              = (1 << 2),
396     C2D_DRIVER_SUPPORTS_NO_PIXEL_ALPHA_OP         = (1 << 3),
397     C2D_DRIVER_SUPPORTS_TARGET_ROTATE_OP          = (1 << 4),
398     C2D_DRIVER_SUPPORTS_ANTI_ALIASING_OP          = (1 << 5), /* antialiasing */
399     C2D_DRIVER_SUPPORTS_BILINEAR_FILTER_OP        = (1 << 6),
400     C2D_DRIVER_SUPPORTS_LENS_CORRECTION_OP        = (1 << 7),
401     C2D_DRIVER_SUPPORTS_OVERRIDE_TARGET_ROTATE_OP = (1 << 8),
402     C2D_DRIVER_SUPPORTS_SHADER_BLOB_OP            = (1 << 9),
403     C2D_DRIVER_SUPPORTS_MASK_SURFACE_OP           = (1 << 10), /* mask surface */
404     C2D_DRIVER_SUPPORTS_MIRROR_H_OP               = (1 << 11), /* horizontal flip */
405     C2D_DRIVER_SUPPORTS_MIRROR_V_OP               = (1 << 12), /* vertical flip */
406     C2D_DRIVER_SUPPORTS_SCISSOR_RECT_OP           = (1 << 13),
407     C2D_DRIVER_SUPPORTS_SOURCE_RECT_OP            = (1 << 14),
408     C2D_DRIVER_SUPPORTS_TARGET_RECT_OP            = (1 << 15),
409     C2D_DRIVER_SUPPORTS_ROTATE_OP                 = (1 << 16), /* all rotations */
410     C2D_DRIVER_SUPPORTS_FLUSH_WITH_FENCE_FD_OP    = (1 << 17), /* all rotations */
411     C2D_DRIVER_SUPPORTS_ALL_CAPABILITIES_OP       = ((0xFFFFFFFF) >> (31 - 17)) /* mask for all capabilities supported */
412 } C2D_DRIVER_CAPABILITIES;
413 
414 /* 2D driver workaround bits used by the 2D applications */
415 typedef enum {
416     C2D_DRIVER_WORKAROUND_NONE  = 0, /* NO workaround */
417     C2D_DRIVER_WORKAROUND_SWAP_UV_FOR_YUV_TARGET  = (1 << 0), /* Swap UV when this flag set */
418 } C2D_DRIVER_WORKAROUND;
419 
420 /* Structure to query Driver information */
421 typedef struct {
422     uint32 capabilities_mask;
423     uint32 workaround_mask;
424     uint32 reserved1;
425     uint32 reserved2;
426     uint32 reserved3;
427 } C2D_DRIVER_INFO;
428 
429 /* Structure to query Driver information */
430 typedef struct {
431     uint32          max_surface_template_needed;
432     uint32          reserved1;
433     uint32          reserved2;
434     uint32          reserved3;
435 } C2D_DRIVER_SETUP_INFO;
436 
437 /*****************************************************************************/
438 /**************************** C2D API 2.0 ********************************/
439 /*****************************************************************************/
440 
441 /******************************************************************************
442  * Functions to create/destroy surfaces */
443 
444 /* Creates a generic blit surface according to its type.
445  * Pass a combination of desired surface bits according to planned usage.
446  * Accepted values for surface_bits may include bits from C2D_SURFACE_BITS,
447  * and also from C2D_DISPLAY for compatibility with HW display controller.
448  * For host memory types the memory is preallocated outside the API
449  * and should remain valid until surface is destroyed.
450  * For external memory types the memory is allocated within API.
451  * On success, the non-zero surface identifier is returned.
452  * All numbers greater that 0 are valid surface identifiers, 0 is invalid.
453 
454  * Host memory RGB surface:
455  * surface_type       = C2D_SURFACE_RGB_HOST
456  * surface_definition = C2D_RGB_SURFACE_DEF
457  * all fields in definition structure should be set
458 
459  * External memory RGB surface:
460  * surface_type       = C2D_SURFACE_RGB_EXT
461  * surface_definition = C2D_RGB_SURFACE_DEF
462  * buffer field in definition structure is ignored
463 
464  * Host memory YUV surface:
465  * surface_type       = C2D_SURFACE_YUV_HOST
466  * surface_definition = C2D_YUV_SURFACE_DEF
467  * one or all plane and stride fields in definition structure
468  * should be set depending on whether the format is planar or not
469 
470  * External memory YUV surface:
471  * surface_type       = C2D_SURFACE_YUV_EXT
472  * surface_definition = C2D_YUV_SURFACE_DEF
473  * all plane and stride fields in definition structure are ignored */
474 C2D_API C2D_STATUS c2dCreateSurface( uint32 *surface_id,
475                          uint32 surface_bits,
476                          C2D_SURFACE_TYPE surface_type,
477                          void *surface_definition );
478 
479 /* Requests properties of the specified surface. */
480 C2D_API C2D_STATUS c2dQuerySurface( uint32 surface_id,
481                          uint32 *surface_bits,
482                          C2D_SURFACE_TYPE *surface_type,
483                          uint32 *width, uint32 *height,
484                          uint32 *format );
485 
486 /* Destroys a generic blit surface.
487  * For external memory surfaces also deallocates the memory.
488  * It is safe to free any external resources associated with a given
489  * surface on c2dCreateSurface call after this function returns. */
490 C2D_API C2D_STATUS c2dDestroySurface( uint32 surface_id );
491 
492 
493 /******************************************************************************
494  * Functions to modify/exchange surface data */
495 
496 /* The format of fill_color is the same as color format being used
497  * for specified surface. If fill_rect is NULL the whole surface is filled.
498  * Alpha-blending is not performed while filling.
499  * The operation is complete when function returns. */
500 C2D_API C2D_STATUS c2dFillSurface( uint32 surface_id,
501                          uint32 fill_color,
502                          C2D_RECT *fill_rect );
503 
504 /* Writes data located in host memory into the specified surface.
505  * The chunk of host memory is identified with surface_type and
506  * surface_definition, no surface registration needed in this case.
507  * Only C2D_SURFACE_RGB_HOST, C2D_SURFACE_YUV_HOST are accepted.
508  * If only part of the host memory buffer should be loaded, it should
509  * be configured in surface_definition using width, height and stride.
510  * The x and y are defined in target surface coordinate space.
511  * Color conversion has to be done, if color formats differ.
512  * Alpha-blending is not performed while writing.
513  * The operation is complete when function returns. */
514 C2D_API C2D_STATUS c2dWriteSurface( uint32 surface_id,
515                          C2D_SURFACE_TYPE surface_type,
516                          void *surface_definition,
517                          int32 x, int32 y );
518 
519 /* Reads data from the specified surface into the host memory.
520  * The chunk of host memory is identified with surface_type and
521  * surface_definition, no surface registration needed in this case.
522  * Only C2D_SURFACE_RGB_HOST, C2D_SURFACE_YUV_HOST are accepted.
523  * If only part of the surface should be read, it should
524  * be configured in surface_definition using width, height and stride.
525  * The x and y are defined in source surface coordinate space.
526  * Color conversion has to be done, if color formats differ.
527  * Alpha-blending is not performed while reading.
528  * The operation is complete when function returns. */
529 C2D_API C2D_STATUS c2dReadSurface( uint32 surface_id,
530                          C2D_SURFACE_TYPE surface_type,
531                          void *surface_definition,
532                          int32 x, int32 y );
533 
534 /* Notifies c2d imlementation that surface has been updated from outside the API,
535  * if updated_rect is NULL then the whole surface has been updated. */
536 C2D_API C2D_STATUS c2dSurfaceUpdated( uint32 surface_id,
537                          C2D_RECT *updated_rect );
538 
539 /* Updates surface information.
540  * Could be called only for host surfaces set with parameter "C2D_SURFACE_WITH_PHYS".
541  * Count for surface planes have to be same than for already allocated surface */
542 C2D_API C2D_STATUS c2dUpdateSurface( uint32 surface_id,
543                          uint32 surface_bits,
544                          C2D_SURFACE_TYPE surface_type,
545                          void *surface_definition );
546 
547 /******************************************************************************
548  * Functions to do actual blit */
549 
550 /* Draw a list of blit objects into the given target.
551  * The target_config is a bitwise OR of values from C2D_TARGET_CONFIG.
552  * The target transformation creates the effect that target surface
553  * is transformed before the blit and then transformed back
554  * after blit, however no physical target transform is performed.
555  * The objects_list is a linked list of blit objects, no more
556  * than num_objects is drawn from the given list.
557  * If num_objects is 0, the whole list is drawn.
558  * The blit is not guaranteed to complete after function returns. */
559 C2D_API C2D_STATUS c2dDraw( uint32 target_id,
560                          uint32 target_config, C2D_RECT *target_scissor,
561                          uint32 target_mask_id, uint32 target_color_key,
562                          C2D_OBJECT *objects_list, uint32 num_objects );
563 
564 
565 /* timstamp set in the blit commands flush */
566 typedef void*                   c2d_ts_handle;
567 
568 /* Forces any pending blit to complete for a given target.
569  * Non-blocking. All input surfaces for this target except those
570  * which are shared with other targets are expected to be immediately
571  * writable after client has been waiting returned timestamp with
572  * c2dWaitTimestamp funtion or c2dFinish has been called for same target */
573 C2D_API C2D_STATUS c2dFlush( uint32 target_id, c2d_ts_handle *timestamp);
574 
575 
576 /* Waits the pending timestamp */
577 C2D_API C2D_STATUS c2dWaitTimestamp( c2d_ts_handle timestamp );
578 
579 
580 /* Forces any pending blit to complete for a given target.
581  * Blocking version, returns when blit is done.
582  * All input surfaces for this target except those which are shared with
583  * other targets are expected to be immediately
584  * writable after this function returns. */
585 C2D_API C2D_STATUS c2dFinish( uint32 target_id );
586 
587 
588 /*****************************************************************************/
589 /****************************** Display API **********************************/
590 /*****************************************************************************/
591 
592 
593 /* Display input enumeration */
594 typedef enum {
595     C2D_DISPLAY_INPUT_0      = 0,       /*!< default input */
596     C2D_DISPLAY_INPUT_1      = (1<<16), /*!< Overlay 1     */
597     C2D_DISPLAY_INPUT_2      = (1<<17), /*!< Overlay 2...    */
598 } C2D_DISPLAY_INPUT;
599 
600 
601 /******************************************************************************
602  * Functions for display output. */
603 
604 /* Functionality described in this section is optional and is
605  * provided only for the cases when blit HW
606  * is tightly bound to the display controller. */
607 
608 /* Display enumeration, may also be used in surface caps */
609 typedef enum {
610     C2D_DISPLAY_MAIN         = (1 << 10), /* main display */
611     C2D_DISPLAY_SECONDARY    = (1 << 11), /* secondary display */
612     C2D_DISPLAY_TV_OUT       = (1 << 12), /* tv-out */
613 } C2D_DISPLAY;
614 
615 /* Display window enumeration */
616 typedef enum {
617     C2D_DISPLAY_OVERLAY      = C2D_DISPLAY_INPUT_1, /*!< Overlay window bit. This defines display input.
618                                                 When defined the surface is set on the overlay window
619                                                 otherwise the surface is set on the background window. */
620 } C2D_DISPLAY_WINDOW;                    /*!< Window bit set with display parameter */
621 
622 
623 /* Display update modes */
624 typedef enum {
625     C2D_DISPLAY_MODE_TEAR_SYNC   = (1 << 0), /* enables tearing sync */
626     C2D_DISPLAY_MODE_SURF_REMOVE = (1 << 1), /* Remove surface from given display + input */
627 } C2D_DISPLAY_MODE;
628 
629 
630 /* Sets the given surface as a current display front buffer.
631  * Several displays can be specified as an output if supported.
632  * Still only one input can be specified at a time fro display/displays.
633  * The surface remains shown until it gets replaced with another one. */
634 C2D_API C2D_STATUS c2dDisplaySetSurface( uint32 display,
635                          uint32 surface_id, uint32 mode );
636 
637 /* Returns the current surface for a particular display.
638  * Only one display can be specified at a time.
639  * The latest surface set with compDisplaySetSurface or
640  * the default pre-allocated surface is returned. */
641 C2D_API C2D_STATUS c2dDisplayGetSurface( uint32 display,
642                          uint32 *surface_id );
643 
644 /* Returns the properties for a particular display.
645  * Only one display can be specified at a time. */
646 C2D_API C2D_STATUS c2dDisplayGetProperties( uint32 display,
647                          uint32 *width, uint32 *height,
648                          uint32 *format );
649 
650 /* Sets the properties for a particular display input.
651  * Only one display + input can be specified at a time.
652  * C2D_OBJECT used to set input rect(target rect),
653  * blending operations, rotation...etc for display source */
654 C2D_API C2D_STATUS c2dDisplaySetObject( uint32 display,
655                          uint32 target_config, uint32 target_color_key,
656                          C2D_OBJECT * c2dObject, uint32 mode);
657 
658 /* allows user to map a memory region to the gpu. only supported on linux
659  * mem_fd is the fd of the memory region, hostptr is the host pointer to the region,
660  * len and offset are the size and offset of the memory.
661  * flags is one of the memory types supported by gsl
662  * gpaddr is passed by refernce back to the user
663  */
664 C2D_API C2D_STATUS c2dMapAddr ( int mem_fd, void * hostptr, uint32 len, uint32 offset, uint32 flags, void ** gpuaddr);
665 
666 /* allows user to unmap memory region mapped by c2dMapAddr.
667  * gpaddr is the gpuaddr to unmap */
668 C2D_API C2D_STATUS c2dUnMapAddr (void * gpuaddr);
669 
670 /* allows user to query driver capabilities.
671  * driver_info is the information about driver */
672 C2D_API C2D_STATUS c2dGetDriverCapabilities( C2D_DRIVER_INFO * driver_info);
673 
674 /* create a fence fd for the timestamp */
675 C2D_API C2D_STATUS c2dCreateFenceFD( uint32 target_id, c2d_ts_handle timestamp, int32 *fd);
676 
677 /*****************************************************************************/
678 
679 #ifdef __cplusplus
680 }
681 #endif
682 
683 #endif /* __c2d2_h_ */
684