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