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