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