1 /* Copyright (c) 2010-2012, Code Aurora Forum. 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 Code Aurora Forum, Inc. 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 /* Target configuration bits, defines rotation + mirroring. 236 * Mirror is applied prior to rotation if enabled. */ 237 typedef enum { 238 C2D_TARGET_MIRROR_H = (1 << 0), /* horizontal flip */ 239 C2D_TARGET_MIRROR_V = (1 << 1), /* vertical flip */ 240 C2D_TARGET_ROTATE_0 = (0 << 2), /* no rotation */ 241 C2D_TARGET_ROTATE_90 = (1 << 2), /* 90 degree rotation */ 242 C2D_TARGET_ROTATE_180 = (2 << 2), /* 180 degree rotation */ 243 C2D_TARGET_ROTATE_270 = (3 << 2), /* 270 degree rotation, 90 + 180 */ 244 C2D_TARGET_MASK_ALIGN = (1 << 4), /* aligns mask to target scissor */ 245 C2D_TARGET_MASK_SCALE = (1 << 5), /* enables mask scaling */ 246 C2D_TARGET_MASK_TILE = (1 << 6), /* enables mask tiling */ 247 C2D_TARGET_COLOR_KEY = (1 << 7), /* enables target_color_key */ 248 C2D_TARGET_NO_PIXEL_ALPHA = (1 << 8), /* disables target alpha channel */ 249 } C2D_TARGET_CONFIG; 250 251 #define C2D_TARGET_ROTATION_MASK (C2D_TARGET_ROTATE_90*3) 252 253 /* Additional blend modes, can be used with both source and target configs. 254 If none of the below is set, the default "SRC over DST" is applied. */ 255 typedef enum { 256 C2D_ALPHA_BLEND_SRC_OVER = (0 << 20), /* Default, Porter-Duff "SRC over DST" */ 257 C2D_ALPHA_BLEND_SRC = (1 << 20), /* Porter-Duff "SRC" */ 258 C2D_ALPHA_BLEND_SRC_IN = (2 << 20), /* Porter-Duff "SRC in DST" */ 259 C2D_ALPHA_BLEND_DST_IN = (3 << 20), /* Porter-Duff "DST in SRC" */ 260 C2D_ALPHA_BLEND_SRC_OUT = (4 << 20), /* Porter-Duff "SRC out DST" */ 261 C2D_ALPHA_BLEND_DST_OUT = (5 << 20), /* Porter-Duff "DST out SRC" */ 262 C2D_ALPHA_BLEND_DST_OVER = (6 << 20), /* Porter-Duff "DST over SRC" */ 263 C2D_ALPHA_BLEND_SRC_ATOP = (7 << 20), /* Porter-Duff "SRC ATOP" */ 264 C2D_ALPHA_BLEND_DST_ATOP = (8 << 20), /* Porter-Duff "DST ATOP" */ 265 C2D_ALPHA_BLEND_XOR = (9 << 20), /* Xor */ 266 C2D_ALPHA_BLEND_MULTIPLY = (10 << 20), /* OpenVG "MULTIPLY" */ 267 C2D_ALPHA_BLEND_SCREEN = (11 << 20), /* OpenVG "SCREEN" */ 268 C2D_ALPHA_BLEND_DARKEN = (12 << 20), /* OpenVG "DARKEN" */ 269 C2D_ALPHA_BLEND_LIGHTEN = (13 << 20), /* OpenVG "LIGHTEN" */ 270 C2D_ALPHA_BLEND_ADDITIVE = (14 << 20), /* OpenVG "ADDITIVE" */ 271 C2D_ALPHA_BLEND_DIRECT = (15 << 20), /* Direct alpha blitting */ 272 C2D_ALPHA_BLEND_INVERTC = (16 << 20), /* Invert color */ 273 C2D_ALPHA_BLEND_NONE = (1 << 25), /* disables alpha blending */ 274 } C2D_ALPHA_BLEND_MODE; 275 276 277 /* Surface caps enumeration */ 278 typedef enum { 279 C2D_SOURCE = (1 << 0), /* allows to use as a source */ 280 C2D_TARGET = (1 << 1), /* allows to use as a target */ 281 C2D_MASK = (1 << 2), /* allows to use as a mask */ 282 C2D_PALETTE = (1 << 3), /* allows to use as a palette */ 283 } C2D_SURFACE_BITS; 284 285 /* Surface type enumeration */ 286 typedef enum { 287 C2D_SURFACE_RGB_HOST = 1, /* Host memory RGB surface */ 288 C2D_SURFACE_RGB_EXT = 2, /* External memory RGB surface */ 289 C2D_SURFACE_YUV_HOST = 3, /* Host memory YUV surface */ 290 C2D_SURFACE_YUV_EXT = 4, /* External memory YUV surface */ 291 C2D_SURFACE_WITH_PHYS = (1<<3), /* physical address already mapped */ 292 /* this bit is valid with HOST types */ 293 C2D_SURFACE_WITH_PHYS_DUMMY = (1<<4), /* physical address already mapped */ 294 /* this bit is valid with HOST types */ 295 } C2D_SURFACE_TYPE; 296 297 /* Structure for registering a RGB buffer as a blit surface */ 298 typedef struct { 299 uint32 format; /* RGB color format plus additional mode bits */ 300 uint32 width; /* defines width in pixels */ 301 uint32 height; /* defines height in pixels */ 302 void *buffer; /* pointer to the RGB buffer */ 303 void *phys; /* physical address */ 304 int32 stride; /* defines stride in bytes, negative stride is allowed */ 305 } C2D_RGB_SURFACE_DEF; 306 307 /* Structure for registering a YUV plane(s) as a blit surface */ 308 typedef struct { 309 uint32 format; /* YUV color format plus additional mode bits */ 310 uint32 width; /* defines width in pixels */ 311 uint32 height; /* defines height in pixels */ 312 void *plane0; /* holds the whole buffer if YUV format is not planar */ 313 void *phys0; /* physical address */ 314 int32 stride0; /* stride in bytes if YUV format is not planar */ 315 void *plane1; /* holds UV or VU plane for planar interleaved */ 316 void *phys1; /* physical address */ 317 int32 stride1; /* stride for UV or VU plane for planar interleaved */ 318 void *plane2; /* holds the 3. plane, ignored if YUV format is not planar */ 319 void *phys2; /* physical address */ 320 int32 stride2; /* stride for the 3. plane, ignored if YUV format is not planar */ 321 } C2D_YUV_SURFACE_DEF; 322 323 324 /* Rectangle definition */ 325 typedef struct { 326 int32 x; /* upper-left x */ 327 int32 y; /* upper-left y */ 328 int32 width; /* width */ 329 int32 height; /* height */ 330 } C2D_RECT; 331 332 /* C2D_OBJECT encapsulates the blit parameters for a source surface. 333 * The fg_color defines color in target format for bits equal to 1 334 * in the source C2D_COLOR_FORMAT_1 format. It also defines rendering 335 * color for all alpha-only source formats. If the surface_id is 0 336 * the fg_color defines a constant fill color used instead of the surface. 337 * The bg_color defines color in target format for bits equal to 0 338 * in the source C2D_COLOR_FORMAT_1 format, otherwise both are ignored. 339 * The palette_id is used for all palette source formats, otherwise ignored. 340 341 * The source_rect first defines the content of the source surface, 342 * it is then horizontally/vertically flipped if C2D_MIRROR_*_BIT is set, 343 * then scaled with bilinear interpolation to exactly fit target_rect 344 * or repeated across target_rect if C2D_SOURCE_TILE_BIT is set, 345 * target_rect is then rotated clockwise by an arbitrary angle in degrees 346 * around the rot_orig_x/y, defined relative to target_rect's top left point, 347 * and then clipped to scissor_rect defined in target coordinate system. 348 349 * Finally alpha blending is applied before pixels get written into the target. 350 * Surface's pixel alpha is combined with mask alpha and with global alpha. 351 * Mask surface follows all transformations applied to the source surface. 352 * Source color key defines transparent color, applied together with alpha. */ 353 typedef struct C2D_OBJECT_STR { 354 uint32 surface_id; /* source surface */ 355 356 uint32 fg_color; /* foreground color */ 357 uint32 bg_color; /* background color */ 358 uint32 palette_id; /* one-dimensional horizontal palette surface */ 359 360 uint32 config_mask; /* defines which fields below are enabled */ 361 362 C2D_RECT source_rect; /* region of the source surface, 16.16 fp */ 363 C2D_RECT target_rect; /* position and scaling in target, 16.16 fp */ 364 365 int32 rot_orig_x; /* rotation origin relative to target_rect's... */ 366 int32 rot_orig_y; /* ...top left point, both are 16.16 fp */ 367 int32 rotation; /* clock-wise rotation in degrees, 16.16 fp */ 368 369 C2D_RECT scissor_rect; /* defines the clip rectangle in target surface */ 370 371 uint32 mask_surface_id; /* source alpha-mask surface */ 372 uint32 global_alpha; /* 0 = fully transparent, 255 = fully opaque */ 373 uint32 color_key; /* transparent color for the source surface */ 374 375 struct C2D_OBJECT_STR *next; /* pointer to the next object or NULL */ 376 } C2D_OBJECT; 377 378 379 /*****************************************************************************/ 380 /**************************** C2D API 2.0 ********************************/ 381 /*****************************************************************************/ 382 383 /****************************************************************************** 384 * Functions to create/destroy surfaces */ 385 386 /* Creates a generic blit surface according to its type. 387 * Pass a combination of desired surface bits according to planned usage. 388 * Accepted values for surface_bits may include bits from C2D_SURFACE_BITS, 389 * and also from C2D_DISPLAY for compatibility with HW display controller. 390 * For host memory types the memory is preallocated outside the API 391 * and should remain valid until surface is destroyed. 392 * For external memory types the memory is allocated within API. 393 * On success, the non-zero surface identifier is returned. 394 * All numbers greater that 0 are valid surface identifiers, 0 is invalid. 395 396 * Host memory RGB surface: 397 * surface_type = C2D_SURFACE_RGB_HOST 398 * surface_definition = C2D_RGB_SURFACE_DEF 399 * all fields in definition structure should be set 400 401 * External memory RGB surface: 402 * surface_type = C2D_SURFACE_RGB_EXT 403 * surface_definition = C2D_RGB_SURFACE_DEF 404 * buffer field in definition structure is ignored 405 406 * Host memory YUV surface: 407 * surface_type = C2D_SURFACE_YUV_HOST 408 * surface_definition = C2D_YUV_SURFACE_DEF 409 * one or all plane and stride fields in definition structure 410 * should be set depending on whether the format is planar or not 411 412 * External memory YUV surface: 413 * surface_type = C2D_SURFACE_YUV_EXT 414 * surface_definition = C2D_YUV_SURFACE_DEF 415 * all plane and stride fields in definition structure are ignored */ 416 C2D_API C2D_STATUS c2dCreateSurface( uint32 *surface_id, 417 uint32 surface_bits, 418 C2D_SURFACE_TYPE surface_type, 419 void *surface_definition ); 420 421 /* Requests properties of the specified surface. */ 422 C2D_API C2D_STATUS c2dQuerySurface( uint32 surface_id, 423 uint32 *surface_bits, 424 C2D_SURFACE_TYPE *surface_type, 425 uint32 *width, uint32 *height, 426 uint32 *format ); 427 428 /* Destroys a generic blit surface. 429 * For external memory surfaces also deallocates the memory. 430 * It is safe to free any external resources associated with a given 431 * surface on c2dCreateSurface call after this function returns. */ 432 C2D_API C2D_STATUS c2dDestroySurface( uint32 surface_id ); 433 434 435 /****************************************************************************** 436 * Functions to modify/exchange surface data */ 437 438 /* The format of fill_color is the same as color format being used 439 * for specified surface. If fill_rect is NULL the whole surface is filled. 440 * Alpha-blending is not performed while filling. 441 * The operation is complete when function returns. */ 442 C2D_API C2D_STATUS c2dFillSurface( uint32 surface_id, 443 uint32 fill_color, 444 C2D_RECT *fill_rect ); 445 446 /* Writes data located in host memory into the specified surface. 447 * The chunk of host memory is identified with surface_type and 448 * surface_definition, no surface registration needed in this case. 449 * Only C2D_SURFACE_RGB_HOST, C2D_SURFACE_YUV_HOST are accepted. 450 * If only part of the host memory buffer should be loaded, it should 451 * be configured in surface_definition using width, height and stride. 452 * The x and y are defined in target surface coordinate space. 453 * Color conversion has to be done, if color formats differ. 454 * Alpha-blending is not performed while writing. 455 * The operation is complete when function returns. */ 456 C2D_API C2D_STATUS c2dWriteSurface( uint32 surface_id, 457 C2D_SURFACE_TYPE surface_type, 458 void *surface_definition, 459 int32 x, int32 y ); 460 461 /* Reads data from the specified surface into the host memory. 462 * The chunk of host memory is identified with surface_type and 463 * surface_definition, no surface registration needed in this case. 464 * Only C2D_SURFACE_RGB_HOST, C2D_SURFACE_YUV_HOST are accepted. 465 * If only part of the surface should be read, it should 466 * be configured in surface_definition using width, height and stride. 467 * The x and y are defined in source surface coordinate space. 468 * Color conversion has to be done, if color formats differ. 469 * Alpha-blending is not performed while reading. 470 * The operation is complete when function returns. */ 471 C2D_API C2D_STATUS c2dReadSurface( uint32 surface_id, 472 C2D_SURFACE_TYPE surface_type, 473 void *surface_definition, 474 int32 x, int32 y ); 475 476 /* Notifies c2d imlementation that surface has been updated from outside the API, 477 * if updated_rect is NULL then the whole surface has been updated. */ 478 C2D_API C2D_STATUS c2dSurfaceUpdated( uint32 surface_id, 479 C2D_RECT *updated_rect ); 480 481 /* Updates surface information. 482 * Could be called only for host surfaces set with parameter "C2D_SURFACE_WITH_PHYS". 483 * Count for surface planes have to be same than for already allocated surface */ 484 C2D_API C2D_STATUS c2dUpdateSurface( uint32 surface_id, 485 uint32 surface_bits, 486 C2D_SURFACE_TYPE surface_type, 487 void *surface_definition ); 488 489 /****************************************************************************** 490 * Functions to do actual blit */ 491 492 /* Draw a list of blit objects into the given target. 493 * The target_config is a bitwise OR of values from C2D_TARGET_CONFIG. 494 * The target transformation creates the effect that target surface 495 * is transformed before the blit and then transformed back 496 * after blit, however no physical target transform is performed. 497 * The objects_list is a linked list of blit objects, no more 498 * than num_objects is drawn from the given list. 499 * If num_objects is 0, the whole list is drawn. 500 * The blit is not guaranteed to complete after function returns. */ 501 C2D_API C2D_STATUS c2dDraw( uint32 target_id, 502 uint32 target_config, C2D_RECT *target_scissor, 503 uint32 target_mask_id, uint32 target_color_key, 504 C2D_OBJECT *objects_list, uint32 num_objects ); 505 506 507 /* timstamp set in the blit commands flush */ 508 typedef void* c2d_ts_handle; 509 510 /* Forces any pending blit to complete for a given target. 511 * Non-blocking. All input surfaces for this target except those 512 * which are shared with other targets are expected to be immediately 513 * writable after client has been waiting returned timestamp with 514 * c2dWaitTimestamp funtion or c2dFinish has been called for same target */ 515 C2D_API C2D_STATUS c2dFlush( uint32 target_id, c2d_ts_handle *timestamp); 516 517 518 /* Waits the pending timestamp */ 519 C2D_API C2D_STATUS c2dWaitTimestamp( c2d_ts_handle timestamp ); 520 521 522 /* Forces any pending blit to complete for a given target. 523 * Blocking version, returns when blit is done. 524 * All input surfaces for this target except those which are shared with 525 * other targets are expected to be immediately 526 * writable after this function returns. */ 527 C2D_API C2D_STATUS c2dFinish( uint32 target_id ); 528 529 530 /*****************************************************************************/ 531 /****************************** Display API **********************************/ 532 /*****************************************************************************/ 533 534 535 /* Display input enumeration */ 536 typedef enum { 537 C2D_DISPLAY_INPUT_0 = 0, /*!< default input */ 538 C2D_DISPLAY_INPUT_1 = (1<<16), /*!< Overlay 1 */ 539 C2D_DISPLAY_INPUT_2 = (1<<17), /*!< Overlay 2... */ 540 } C2D_DISPLAY_INPUT; 541 542 543 /****************************************************************************** 544 * Functions for display output. */ 545 546 /* Functionality described in this section is optional and is 547 * provided only for the cases when blit HW 548 * is tightly bound to the display controller. */ 549 550 /* Display enumeration, may also be used in surface caps */ 551 typedef enum { 552 C2D_DISPLAY_MAIN = (1 << 10), /* main display */ 553 C2D_DISPLAY_SECONDARY = (1 << 11), /* secondary display */ 554 C2D_DISPLAY_TV_OUT = (1 << 12), /* tv-out */ 555 } C2D_DISPLAY; 556 557 /* Display window enumeration */ 558 typedef enum { 559 C2D_DISPLAY_OVERLAY = C2D_DISPLAY_INPUT_1, /*!< Overlay window bit. This defines display input. 560 When defined the surface is set on the overlay window 561 otherwise the surface is set on the background window. */ 562 } C2D_DISPLAY_WINDOW; /*!< Window bit set with display parameter */ 563 564 565 /* Display update modes */ 566 typedef enum { 567 C2D_DISPLAY_MODE_TEAR_SYNC = (1 << 0), /* enables tearing sync */ 568 C2D_DISPLAY_MODE_SURF_REMOVE = (1 << 1), /* Remove surface from given display + input */ 569 } C2D_DISPLAY_MODE; 570 571 572 /* Sets the given surface as a current display front buffer. 573 * Several displays can be specified as an output if supported. 574 * Still only one input can be specified at a time fro display/displays. 575 * The surface remains shown until it gets replaced with another one. */ 576 C2D_API C2D_STATUS c2dDisplaySetSurface( uint32 display, 577 uint32 surface_id, uint32 mode ); 578 579 /* Returns the current surface for a particular display. 580 * Only one display can be specified at a time. 581 * The latest surface set with compDisplaySetSurface or 582 * the default pre-allocated surface is returned. */ 583 C2D_API C2D_STATUS c2dDisplayGetSurface( uint32 display, 584 uint32 *surface_id ); 585 586 /* Returns the properties for a particular display. 587 * Only one display can be specified at a time. */ 588 C2D_API C2D_STATUS c2dDisplayGetProperties( uint32 display, 589 uint32 *width, uint32 *height, 590 uint32 *format ); 591 592 /* Sets the properties for a particular display input. 593 * Only one display + input can be specified at a time. 594 * C2D_OBJECT used to set input rect(target rect), 595 * blending operations, rotation...etc for display source */ 596 C2D_API C2D_STATUS c2dDisplaySetObject( uint32 display, 597 uint32 target_config, uint32 target_color_key, 598 C2D_OBJECT * c2dObject, uint32 mode); 599 600 /* allows user to map a memory region to the gpu. only supported on linux 601 * mem_fd is the fd of the memory region, hostptr is the host pointer to the region, 602 * len and offset are the size and offset of the memory. 603 * flags is one of the memory types supported by gsl 604 * gpaddr is passed by refernce back to the user 605 */ 606 C2D_API C2D_STATUS c2dMapAddr ( int mem_fd, void * hostptr, uint32 len, uint32 offset, uint32 flags, void ** gpuaddr); 607 608 /* allows user to unmap memory region mapped by c2dMapAddr. 609 * gpaddr is the gpuaddr to unmap */ 610 C2D_API C2D_STATUS c2dUnMapAddr (void * gpuaddr); 611 612 /*****************************************************************************/ 613 614 #ifdef __cplusplus 615 } 616 #endif 617 618 #endif /* __c2d2_h_ */ 619