graphics.h revision d755b52b43913913e0915c50b5ff0d03c96eed49
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#ifdef __cplusplus
21extern "C" {
22#endif
23
24/*
25 * If the HAL needs to create service threads to handle graphics related
26 * tasks, these threads need to run at HAL_PRIORITY_URGENT_DISPLAY priority
27 * if they can block the main rendering thread in any way.
28 *
29 * the priority of the current thread can be set with:
30 *
31 *      #include <sys/resource.h>
32 *      setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY);
33 *
34 */
35
36#define HAL_PRIORITY_URGENT_DISPLAY     (-8)
37
38/**
39 * pixel format definitions
40 */
41
42enum {
43    HAL_PIXEL_FORMAT_RGBA_8888          = 1,
44    HAL_PIXEL_FORMAT_RGBX_8888          = 2,
45    HAL_PIXEL_FORMAT_RGB_888            = 3,
46    HAL_PIXEL_FORMAT_RGB_565            = 4,
47    HAL_PIXEL_FORMAT_BGRA_8888          = 5,
48    HAL_PIXEL_FORMAT_RGBA_5551          = 6,
49    HAL_PIXEL_FORMAT_RGBA_4444          = 7,
50
51    /* 0x8 - 0xFF range unavailable */
52
53    /*
54     * 0x100 - 0x1FF
55     *
56     * This range is reserved for pixel formats that are specific to the HAL
57     * implementation.  Implementations can use any value in this range to
58     * communicate video pixel formats between their HAL modules.  These formats
59     * must not have an alpha channel.  Additionally, an EGLimage created from a
60     * gralloc buffer of one of these formats must be supported for use with the
61     * GL_OES_EGL_image_external OpenGL ES extension.
62     */
63
64    /*
65     * Android YUV format:
66     *
67     * This format is exposed outside of the HAL to software decoders and
68     * applications.  EGLImageKHR must support it in conjunction with the
69     * OES_EGL_image_external extension.
70     *
71     * YV12 is a 4:2:0 YCrCb planar format comprised of a WxH Y plane followed
72     * by (W/2) x (H/2) Cr and Cb planes.
73     *
74     * This format assumes
75     * - an even width
76     * - an even height
77     * - a horizontal stride multiple of 16 pixels
78     * - a vertical stride equal to the height
79     *
80     *   y_size = stride * height
81     *   c_stride = ALIGN(stride/2, 16)
82     *   c_size = c_stride * height/2
83     *   size = y_size + c_size * 2
84     *   cr_offset = y_size
85     *   cb_offset = y_size + c_size
86     *
87     */
88    HAL_PIXEL_FORMAT_YV12   = 0x32315659, // YCrCb 4:2:0 Planar
89
90
91    /*
92     * Android Y8 format:
93     *
94     * This format is exposed outside of the HAL to the framework.
95     * The expected gralloc usage flags are SW_* and HW_CAMERA_*,
96     * and no other HW_ flags will be used.
97     *
98     * Y8 is a YUV planar format comprised of a WxH Y plane,
99     * with each pixel being represented by 8 bits.
100     *
101     * It is equivalent to just the Y plane from YV12.
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     *   size = stride * height
110     *
111     */
112    HAL_PIXEL_FORMAT_Y8     = 0x20203859,
113
114    /*
115     * Android Y16 format:
116     *
117     * This format is exposed outside of the HAL to the framework.
118     * The expected gralloc usage flags are SW_* and HW_CAMERA_*,
119     * and no other HW_ flags will be used.
120     *
121     * Y16 is a YUV planar format comprised of a WxH Y plane,
122     * with each pixel being represented by 16 bits.
123     *
124     * It is just like Y8, but has double the bits per pixel (little endian).
125     *
126     * This format assumes
127     * - an even width
128     * - an even height
129     * - a horizontal stride multiple of 16 pixels
130     * - a vertical stride equal to the height
131     * - strides are specified in pixels, not in bytes
132     *
133     *   size = stride * height * 2
134     *
135     */
136    HAL_PIXEL_FORMAT_Y16    = 0x20363159,
137
138    /*
139     * Android RAW sensor format:
140     *
141     * This format is exposed outside of the HAL to applications.
142     *
143     * RAW_SENSOR is a single-channel 16-bit format, typically representing raw
144     * Bayer-pattern images from an image sensor, with minimal processing.
145     *
146     * The exact pixel layout of the data in the buffer is sensor-dependent, and
147     * needs to be queried from the camera device.
148     *
149     * Generally, not all 16 bits are used; more common values are 10 or 12
150     * bits. All parameters to interpret the raw data (black and white points,
151     * color space, etc) must be queried from the camera device.
152     *
153     * This format assumes
154     * - an even width
155     * - an even height
156     * - a horizontal stride multiple of 16 pixels (32 bytes).
157     */
158    HAL_PIXEL_FORMAT_RAW_SENSOR = 0x20,
159
160    /*
161     * Android binary blob graphics buffer format:
162     *
163     * This format is used to carry task-specific data which does not have a
164     * standard image structure. The details of the format are left to the two
165     * endpoints.
166     *
167     * A typical use case is for transporting JPEG-compressed images from the
168     * Camera HAL to the framework or to applications.
169     *
170     * Buffers of this format must have a height of 1, and width equal to their
171     * size in bytes.
172     */
173    HAL_PIXEL_FORMAT_BLOB = 0x21,
174
175    /*
176     * Android format indicating that the choice of format is entirely up to the
177     * device-specific Gralloc implementation.
178     *
179     * The Gralloc implementation should examine the usage bits passed in when
180     * allocating a buffer with this format, and it should derive the pixel
181     * format from those usage flags.  This format will never be used with any
182     * of the GRALLOC_USAGE_SW_* usage flags.
183     *
184     * If a buffer of this format is to be used as an OpenGL ES texture, the
185     * framework will assume that sampling the texture will always return an
186     * alpha value of 1.0 (i.e. the buffer contains only opaque pixel values).
187     *
188     */
189    HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED = 0x22,
190
191    /* Legacy formats (deprecated), used by ImageFormat.java */
192    HAL_PIXEL_FORMAT_YCbCr_422_SP       = 0x10, // NV16
193    HAL_PIXEL_FORMAT_YCrCb_420_SP       = 0x11, // NV21
194    HAL_PIXEL_FORMAT_YCbCr_422_I        = 0x14, // YUY2
195};
196
197
198/**
199 * Transformation definitions
200 *
201 * IMPORTANT NOTE:
202 * HAL_TRANSFORM_ROT_90 is applied CLOCKWISE and AFTER HAL_TRANSFORM_FLIP_{H|V}.
203 *
204 */
205
206enum {
207    /* flip source image horizontally (around the vertical axis) */
208    HAL_TRANSFORM_FLIP_H    = 0x01,
209    /* flip source image vertically (around the horizontal axis)*/
210    HAL_TRANSFORM_FLIP_V    = 0x02,
211    /* rotate source image 90 degrees clockwise */
212    HAL_TRANSFORM_ROT_90    = 0x04,
213    /* rotate source image 180 degrees */
214    HAL_TRANSFORM_ROT_180   = 0x03,
215    /* rotate source image 270 degrees clockwise */
216    HAL_TRANSFORM_ROT_270   = 0x07,
217};
218
219#ifdef __cplusplus
220}
221#endif
222
223#endif /* SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H */
224