Iliyan Malchev | 66ea357 | 2011-05-01 14:05:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H |
| 18 | #define SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H |
| 19 | |
Alex Ray | e13f15a | 2013-03-19 01:41:32 -0700 | [diff] [blame] | 20 | #include <stdint.h> |
| 21 | |
Mathias Agopian | c9b0695 | 2011-08-11 22:35:31 -0700 | [diff] [blame] | 22 | #ifdef __cplusplus |
| 23 | extern "C" { |
| 24 | #endif |
Iliyan Malchev | 66ea357 | 2011-05-01 14:05:30 -0700 | [diff] [blame] | 25 | |
Mathias Agopian | 5c9be40 | 2011-08-09 18:55:44 -0700 | [diff] [blame] | 26 | /* |
| 27 | * If the HAL needs to create service threads to handle graphics related |
| 28 | * tasks, these threads need to run at HAL_PRIORITY_URGENT_DISPLAY priority |
| 29 | * if they can block the main rendering thread in any way. |
| 30 | * |
| 31 | * the priority of the current thread can be set with: |
| 32 | * |
| 33 | * #include <sys/resource.h> |
| 34 | * setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY); |
| 35 | * |
| 36 | */ |
| 37 | |
| 38 | #define HAL_PRIORITY_URGENT_DISPLAY (-8) |
| 39 | |
Iliyan Malchev | 66ea357 | 2011-05-01 14:05:30 -0700 | [diff] [blame] | 40 | /** |
| 41 | * pixel format definitions |
| 42 | */ |
| 43 | |
| 44 | enum { |
Mathias Agopian | 8d9da28 | 2013-07-25 17:07:11 -0700 | [diff] [blame] | 45 | /* |
| 46 | * "linear" color pixel formats: |
| 47 | * |
| 48 | * The pixel formats below contain sRGB data but are otherwise treated |
| 49 | * as linear formats, i.e.: no special operation is performed when |
| 50 | * reading or writing into a buffer in one of these formats |
| 51 | */ |
Iliyan Malchev | 66ea357 | 2011-05-01 14:05:30 -0700 | [diff] [blame] | 52 | HAL_PIXEL_FORMAT_RGBA_8888 = 1, |
| 53 | HAL_PIXEL_FORMAT_RGBX_8888 = 2, |
| 54 | HAL_PIXEL_FORMAT_RGB_888 = 3, |
| 55 | HAL_PIXEL_FORMAT_RGB_565 = 4, |
| 56 | HAL_PIXEL_FORMAT_BGRA_8888 = 5, |
Iliyan Malchev | 66ea357 | 2011-05-01 14:05:30 -0700 | [diff] [blame] | 57 | |
Mathias Agopian | 8d9da28 | 2013-07-25 17:07:11 -0700 | [diff] [blame] | 58 | /* |
| 59 | * sRGB color pixel formats: |
| 60 | * |
| 61 | * The red, green and blue components are stored in sRGB space, and converted |
| 62 | * to linear space when read, using the standard sRGB to linear equation: |
| 63 | * |
| 64 | * Clinear = Csrgb / 12.92 for Csrgb <= 0.04045 |
| 65 | * = (Csrgb + 0.055 / 1.055)^2.4 for Csrgb > 0.04045 |
| 66 | * |
| 67 | * When written the inverse transformation is performed: |
| 68 | * |
| 69 | * Csrgb = 12.92 * Clinear for Clinear <= 0.0031308 |
| 70 | * = 1.055 * Clinear^(1/2.4) - 0.055 for Clinear > 0.0031308 |
| 71 | * |
| 72 | * |
| 73 | * The alpha component, if present, is always stored in linear space and |
| 74 | * is left unmodified when read or written. |
| 75 | * |
| 76 | */ |
| 77 | HAL_PIXEL_FORMAT_sRGB_A_8888 = 0xC, |
Jesse Hall | 1e26356 | 2013-08-16 08:40:52 -0700 | [diff] [blame] | 78 | HAL_PIXEL_FORMAT_sRGB_X_8888 = 0xD, |
Iliyan Malchev | 66ea357 | 2011-05-01 14:05:30 -0700 | [diff] [blame] | 79 | |
| 80 | /* |
| 81 | * 0x100 - 0x1FF |
| 82 | * |
| 83 | * This range is reserved for pixel formats that are specific to the HAL |
| 84 | * implementation. Implementations can use any value in this range to |
| 85 | * communicate video pixel formats between their HAL modules. These formats |
| 86 | * must not have an alpha channel. Additionally, an EGLimage created from a |
| 87 | * gralloc buffer of one of these formats must be supported for use with the |
| 88 | * GL_OES_EGL_image_external OpenGL ES extension. |
| 89 | */ |
| 90 | |
| 91 | /* |
| 92 | * Android YUV format: |
| 93 | * |
Jamie Gennis | da1a1f6 | 2011-05-18 14:42:46 -0700 | [diff] [blame] | 94 | * This format is exposed outside of the HAL to software decoders and |
| 95 | * applications. EGLImageKHR must support it in conjunction with the |
Iliyan Malchev | 66ea357 | 2011-05-01 14:05:30 -0700 | [diff] [blame] | 96 | * OES_EGL_image_external extension. |
| 97 | * |
Jamie Gennis | da1a1f6 | 2011-05-18 14:42:46 -0700 | [diff] [blame] | 98 | * YV12 is a 4:2:0 YCrCb planar format comprised of a WxH Y plane followed |
Iliyan Malchev | 66ea357 | 2011-05-01 14:05:30 -0700 | [diff] [blame] | 99 | * by (W/2) x (H/2) Cr and Cb planes. |
| 100 | * |
| 101 | * This format assumes |
| 102 | * - an even width |
| 103 | * - an even height |
| 104 | * - a horizontal stride multiple of 16 pixels |
| 105 | * - a vertical stride equal to the height |
| 106 | * |
| 107 | * y_size = stride * height |
Jamie Gennis | 185b300 | 2012-04-30 12:50:38 -0700 | [diff] [blame] | 108 | * c_stride = ALIGN(stride/2, 16) |
| 109 | * c_size = c_stride * height/2 |
Iliyan Malchev | 66ea357 | 2011-05-01 14:05:30 -0700 | [diff] [blame] | 110 | * size = y_size + c_size * 2 |
| 111 | * cr_offset = y_size |
| 112 | * cb_offset = y_size + c_size |
| 113 | * |
| 114 | */ |
| 115 | HAL_PIXEL_FORMAT_YV12 = 0x32315659, // YCrCb 4:2:0 Planar |
| 116 | |
Igor Murashkin | 9e00e66 | 2013-01-31 17:17:43 -0800 | [diff] [blame] | 117 | |
| 118 | /* |
| 119 | * Android Y8 format: |
| 120 | * |
| 121 | * This format is exposed outside of the HAL to the framework. |
| 122 | * The expected gralloc usage flags are SW_* and HW_CAMERA_*, |
| 123 | * and no other HW_ flags will be used. |
| 124 | * |
| 125 | * Y8 is a YUV planar format comprised of a WxH Y plane, |
| 126 | * with each pixel being represented by 8 bits. |
| 127 | * |
| 128 | * It is equivalent to just the Y plane from YV12. |
| 129 | * |
| 130 | * This format assumes |
| 131 | * - an even width |
| 132 | * - an even height |
| 133 | * - a horizontal stride multiple of 16 pixels |
| 134 | * - a vertical stride equal to the height |
| 135 | * |
Igor Murashkin | d755b52 | 2013-02-11 11:34:53 -0800 | [diff] [blame] | 136 | * size = stride * height |
Igor Murashkin | 9e00e66 | 2013-01-31 17:17:43 -0800 | [diff] [blame] | 137 | * |
| 138 | */ |
| 139 | HAL_PIXEL_FORMAT_Y8 = 0x20203859, |
| 140 | |
| 141 | /* |
| 142 | * Android Y16 format: |
| 143 | * |
| 144 | * This format is exposed outside of the HAL to the framework. |
| 145 | * The expected gralloc usage flags are SW_* and HW_CAMERA_*, |
| 146 | * and no other HW_ flags will be used. |
| 147 | * |
| 148 | * Y16 is a YUV planar format comprised of a WxH Y plane, |
| 149 | * with each pixel being represented by 16 bits. |
| 150 | * |
| 151 | * It is just like Y8, but has double the bits per pixel (little endian). |
| 152 | * |
| 153 | * This format assumes |
| 154 | * - an even width |
| 155 | * - an even height |
| 156 | * - a horizontal stride multiple of 16 pixels |
| 157 | * - a vertical stride equal to the height |
| 158 | * - strides are specified in pixels, not in bytes |
| 159 | * |
Igor Murashkin | d755b52 | 2013-02-11 11:34:53 -0800 | [diff] [blame] | 160 | * size = stride * height * 2 |
Igor Murashkin | 9e00e66 | 2013-01-31 17:17:43 -0800 | [diff] [blame] | 161 | * |
| 162 | */ |
| 163 | HAL_PIXEL_FORMAT_Y16 = 0x20363159, |
| 164 | |
Eino-Ville Talvala | 0a85154 | 2012-04-10 15:10:50 -0700 | [diff] [blame] | 165 | /* |
| 166 | * Android RAW sensor format: |
| 167 | * |
| 168 | * This format is exposed outside of the HAL to applications. |
| 169 | * |
| 170 | * RAW_SENSOR is a single-channel 16-bit format, typically representing raw |
| 171 | * Bayer-pattern images from an image sensor, with minimal processing. |
| 172 | * |
| 173 | * The exact pixel layout of the data in the buffer is sensor-dependent, and |
| 174 | * needs to be queried from the camera device. |
| 175 | * |
| 176 | * Generally, not all 16 bits are used; more common values are 10 or 12 |
| 177 | * bits. All parameters to interpret the raw data (black and white points, |
| 178 | * color space, etc) must be queried from the camera device. |
| 179 | * |
| 180 | * This format assumes |
| 181 | * - an even width |
| 182 | * - an even height |
| 183 | * - a horizontal stride multiple of 16 pixels (32 bytes). |
| 184 | */ |
| 185 | HAL_PIXEL_FORMAT_RAW_SENSOR = 0x20, |
Iliyan Malchev | 66ea357 | 2011-05-01 14:05:30 -0700 | [diff] [blame] | 186 | |
Eino-Ville Talvala | 0a05248 | 2012-06-07 17:52:15 -0700 | [diff] [blame] | 187 | /* |
| 188 | * Android binary blob graphics buffer format: |
| 189 | * |
| 190 | * This format is used to carry task-specific data which does not have a |
| 191 | * standard image structure. The details of the format are left to the two |
| 192 | * endpoints. |
| 193 | * |
| 194 | * A typical use case is for transporting JPEG-compressed images from the |
| 195 | * Camera HAL to the framework or to applications. |
| 196 | * |
| 197 | * Buffers of this format must have a height of 1, and width equal to their |
| 198 | * size in bytes. |
| 199 | */ |
| 200 | HAL_PIXEL_FORMAT_BLOB = 0x21, |
| 201 | |
Jamie Gennis | febe9d9 | 2012-08-22 14:44:51 -0700 | [diff] [blame] | 202 | /* |
| 203 | * Android format indicating that the choice of format is entirely up to the |
| 204 | * device-specific Gralloc implementation. |
| 205 | * |
| 206 | * The Gralloc implementation should examine the usage bits passed in when |
| 207 | * allocating a buffer with this format, and it should derive the pixel |
| 208 | * format from those usage flags. This format will never be used with any |
| 209 | * of the GRALLOC_USAGE_SW_* usage flags. |
| 210 | * |
| 211 | * If a buffer of this format is to be used as an OpenGL ES texture, the |
| 212 | * framework will assume that sampling the texture will always return an |
| 213 | * alpha value of 1.0 (i.e. the buffer contains only opaque pixel values). |
| 214 | * |
| 215 | */ |
| 216 | HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED = 0x22, |
| 217 | |
Alex Ray | e13f15a | 2013-03-19 01:41:32 -0700 | [diff] [blame] | 218 | /* |
| 219 | * Android flexible YCbCr formats |
| 220 | * |
| 221 | * This format allows platforms to use an efficient YCbCr/YCrCb buffer |
| 222 | * layout, while still describing the buffer layout in a way accessible to |
| 223 | * the CPU in a device-independent manner. While called YCbCr, it can be |
| 224 | * used to describe formats with either chromatic ordering, as well as |
| 225 | * whole planar or semiplanar layouts. |
| 226 | * |
| 227 | * struct android_ycbcr (below) is the the struct used to describe it. |
| 228 | * |
| 229 | * This format must be accepted by the gralloc module when |
| 230 | * USAGE_HW_CAMERA_WRITE and USAGE_SW_READ_* are set. |
| 231 | * |
| 232 | * This format is locked for use by gralloc's (*lock_ycbcr) method, and |
| 233 | * locking with the (*lock) method will return an error. |
| 234 | */ |
| 235 | HAL_PIXEL_FORMAT_YCbCr_420_888 = 0x23, |
| 236 | |
Iliyan Malchev | 66ea357 | 2011-05-01 14:05:30 -0700 | [diff] [blame] | 237 | /* Legacy formats (deprecated), used by ImageFormat.java */ |
| 238 | HAL_PIXEL_FORMAT_YCbCr_422_SP = 0x10, // NV16 |
| 239 | HAL_PIXEL_FORMAT_YCrCb_420_SP = 0x11, // NV21 |
| 240 | HAL_PIXEL_FORMAT_YCbCr_422_I = 0x14, // YUY2 |
| 241 | }; |
| 242 | |
Alex Ray | e13f15a | 2013-03-19 01:41:32 -0700 | [diff] [blame] | 243 | /* |
| 244 | * Structure for describing YCbCr formats for consumption by applications. |
| 245 | * This is used with HAL_PIXEL_FORMAT_YCbCr_*_888. |
| 246 | * |
| 247 | * Buffer chroma subsampling is defined in the format. |
| 248 | * e.g. HAL_PIXEL_FORMAT_YCbCr_420_888 has subsampling 4:2:0. |
| 249 | * |
| 250 | * Buffers must have a 8 bit depth. |
| 251 | * |
| 252 | * @y, @cb, and @cr point to the first byte of their respective planes. |
| 253 | * |
| 254 | * Stride describes the distance in bytes from the first value of one row of |
| 255 | * the image to the first value of the next row. It includes the width of the |
| 256 | * image plus padding. |
| 257 | * @ystride is the stride of the luma plane. |
| 258 | * @cstride is the stride of the chroma planes. |
| 259 | * |
| 260 | * @chroma_step is the distance in bytes from one chroma pixel value to the |
| 261 | * next. This is 2 bytes for semiplanar (because chroma values are interleaved |
| 262 | * and each chroma value is one byte) and 1 for planar. |
| 263 | */ |
| 264 | |
| 265 | struct android_ycbcr { |
| 266 | void *y; |
| 267 | void *cb; |
| 268 | void *cr; |
| 269 | size_t ystride; |
| 270 | size_t cstride; |
| 271 | size_t chroma_step; |
| 272 | |
| 273 | /** reserved for future use, set to 0 by gralloc's (*lock_ycbcr)() */ |
| 274 | uint32_t reserved[8]; |
| 275 | }; |
Iliyan Malchev | 66ea357 | 2011-05-01 14:05:30 -0700 | [diff] [blame] | 276 | |
| 277 | /** |
| 278 | * Transformation definitions |
| 279 | * |
| 280 | * IMPORTANT NOTE: |
| 281 | * HAL_TRANSFORM_ROT_90 is applied CLOCKWISE and AFTER HAL_TRANSFORM_FLIP_{H|V}. |
| 282 | * |
| 283 | */ |
| 284 | |
| 285 | enum { |
| 286 | /* flip source image horizontally (around the vertical axis) */ |
| 287 | HAL_TRANSFORM_FLIP_H = 0x01, |
| 288 | /* flip source image vertically (around the horizontal axis)*/ |
| 289 | HAL_TRANSFORM_FLIP_V = 0x02, |
| 290 | /* rotate source image 90 degrees clockwise */ |
| 291 | HAL_TRANSFORM_ROT_90 = 0x04, |
| 292 | /* rotate source image 180 degrees */ |
| 293 | HAL_TRANSFORM_ROT_180 = 0x03, |
| 294 | /* rotate source image 270 degrees clockwise */ |
| 295 | HAL_TRANSFORM_ROT_270 = 0x07, |
Mathias Agopian | 96675ed | 2013-09-17 23:48:54 -0700 | [diff] [blame] | 296 | /* don't use. see system/window.h */ |
| 297 | HAL_TRANSFORM_RESERVED = 0x08, |
Iliyan Malchev | 66ea357 | 2011-05-01 14:05:30 -0700 | [diff] [blame] | 298 | }; |
| 299 | |
Mathias Agopian | c9b0695 | 2011-08-11 22:35:31 -0700 | [diff] [blame] | 300 | #ifdef __cplusplus |
| 301 | } |
| 302 | #endif |
Iliyan Malchev | 66ea357 | 2011-05-01 14:05:30 -0700 | [diff] [blame] | 303 | |
| 304 | #endif /* SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H */ |