2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H
18 #define SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H
24 * Some of the enums are now defined in HIDL in hardware/interfaces and are
27 #include "graphics-base.h"
28 #include "graphics-sw.h"
34 /* for compatibility */
35 #define HAL_PIXEL_FORMAT_YCbCr_420_888 HAL_PIXEL_FORMAT_YCBCR_420_888
36 #define HAL_PIXEL_FORMAT_YCbCr_422_SP HAL_PIXEL_FORMAT_YCBCR_422_SP
37 #define HAL_PIXEL_FORMAT_YCrCb_420_SP HAL_PIXEL_FORMAT_YCRCB_420_SP
38 #define HAL_PIXEL_FORMAT_YCbCr_422_I HAL_PIXEL_FORMAT_YCBCR_422_I
39 typedef android_pixel_format_t android_pixel_format
;
40 typedef android_transform_t android_transform
;
41 typedef android_dataspace_t android_dataspace
;
42 typedef android_color_mode_t android_color_mode
;
43 typedef android_color_transform_t android_color_transform
;
44 typedef android_hdr_t android_hdr
;
47 * If the HAL needs to create service threads to handle graphics related
48 * tasks, these threads need to run at HAL_PRIORITY_URGENT_DISPLAY priority
49 * if they can block the main rendering thread in any way.
51 * the priority of the current thread can be set with:
53 * #include <sys/resource.h>
54 * setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY);
58 #define HAL_PRIORITY_URGENT_DISPLAY (-8)
61 * Structure for describing YCbCr formats for consumption by applications.
62 * This is used with HAL_PIXEL_FORMAT_YCbCr_*_888.
64 * Buffer chroma subsampling is defined in the format.
65 * e.g. HAL_PIXEL_FORMAT_YCbCr_420_888 has subsampling 4:2:0.
67 * Buffers must have a 8 bit depth.
69 * y, cb, and cr point to the first byte of their respective planes.
71 * Stride describes the distance in bytes from the first value of one row of
72 * the image to the first value of the next row. It includes the width of the
74 * ystride is the stride of the luma plane.
75 * cstride is the stride of the chroma planes.
77 * chroma_step is the distance in bytes from one chroma pixel value to the
78 * next. This is 2 bytes for semiplanar (because chroma values are interleaved
79 * and each chroma value is one byte) and 1 for planar.
82 struct android_ycbcr
{
90 /** reserved for future use, set to 0 by gralloc's (*lock_ycbcr)() */
95 * Structures for describing flexible YUVA/RGBA formats for consumption by
96 * applications. Such flexible formats contain a plane for each component (e.g.
97 * red, green, blue), where each plane is laid out in a grid-like pattern
98 * occupying unique byte addresses and with consistent byte offsets between
101 * The android_flex_layout structure is used with any pixel format that can be
102 * represented by it, such as:
103 * - HAL_PIXEL_FORMAT_YCbCr_*_888
104 * - HAL_PIXEL_FORMAT_FLEX_RGB*_888
105 * - HAL_PIXEL_FORMAT_RGB[AX]_888[8],BGRA_8888,RGB_888
106 * - HAL_PIXEL_FORMAT_YV12,Y8,Y16,YCbCr_422_SP/I,YCrCb_420_SP
107 * - even implementation defined formats that can be represented by
110 * Vertical increment (aka. row increment or stride) describes the distance in
111 * bytes from the first pixel of one row to the first pixel of the next row
112 * (below) for the component plane. This can be negative.
114 * Horizontal increment (aka. column or pixel increment) describes the distance
115 * in bytes from one pixel to the next pixel (to the right) on the same row for
116 * the component plane. This can be negative.
118 * Each plane can be subsampled either vertically or horizontally by
119 * a power-of-two factor.
121 * The bit-depth of each component can be arbitrary, as long as the pixels are
122 * laid out on whole bytes, in native byte-order, using the most significant
126 typedef enum android_flex_component
{
128 FLEX_COMPONENT_Y
= 1 << 0,
130 FLEX_COMPONENT_Cb
= 1 << 1,
132 FLEX_COMPONENT_Cr
= 1 << 2,
135 FLEX_COMPONENT_R
= 1 << 10,
137 FLEX_COMPONENT_G
= 1 << 11,
139 FLEX_COMPONENT_B
= 1 << 12,
142 FLEX_COMPONENT_A
= 1 << 30,
143 } android_flex_component_t
;
145 typedef struct android_flex_plane
{
146 /* pointer to the first byte of the top-left pixel of the plane. */
149 android_flex_component_t component
;
151 /* bits allocated for the component in each pixel. Must be a positive
153 int32_t bits_per_component
;
154 /* number of the most significant bits used in the format for this
155 component. Must be between 1 and bits_per_component, inclusive. */
158 /* horizontal increment */
160 /* vertical increment */
162 /* horizontal subsampling. Must be a positive power of 2. */
163 int32_t h_subsampling
;
164 /* vertical subsampling. Must be a positive power of 2. */
165 int32_t v_subsampling
;
166 } android_flex_plane_t
;
168 typedef enum android_flex_format
{
169 /* not a flexible format */
170 FLEX_FORMAT_INVALID
= 0x0,
171 FLEX_FORMAT_Y
= FLEX_COMPONENT_Y
,
172 FLEX_FORMAT_YCbCr
= FLEX_COMPONENT_Y
| FLEX_COMPONENT_Cb
| FLEX_COMPONENT_Cr
,
173 FLEX_FORMAT_YCbCrA
= FLEX_FORMAT_YCbCr
| FLEX_COMPONENT_A
,
174 FLEX_FORMAT_RGB
= FLEX_COMPONENT_R
| FLEX_COMPONENT_G
| FLEX_COMPONENT_B
,
175 FLEX_FORMAT_RGBA
= FLEX_FORMAT_RGB
| FLEX_COMPONENT_A
,
176 } android_flex_format_t
;
178 typedef struct android_flex_layout
{
179 /* the kind of flexible format */
180 android_flex_format_t format
;
182 /* number of planes; 0 for FLEX_FORMAT_INVALID */
184 /* a plane for each component; ordered in increasing component value order.
185 E.g. FLEX_FORMAT_RGBA maps 0 -> R, 1 -> G, etc.
186 Can be NULL for FLEX_FORMAT_INVALID */
187 android_flex_plane_t
*planes
;
188 } android_flex_layout_t
;
191 * Structure used to define depth point clouds for format HAL_PIXEL_FORMAT_BLOB
192 * with dataSpace value of HAL_DATASPACE_DEPTH.
193 * When locking a native buffer of the above format and dataSpace value,
194 * the vaddr pointer can be cast to this structure.
196 * A variable-length list of (x,y,z, confidence) 3D points, as floats. (x, y,
197 * z) represents a measured point's position, with the coordinate system defined
198 * by the data source. Confidence represents the estimated likelihood that this
199 * measurement is correct. It is between 0.f and 1.f, inclusive, with 1.f ==
202 * num_points is the number of points in the list
204 * xyz_points is the flexible array of floating-point values.
205 * It contains (num_points) * 4 floats.
208 * android_depth_points d = get_depth_buffer();
210 * float x; float y; float z; float confidence;
211 * } firstPoint, lastPoint;
213 * firstPoint.x = d.xyzc_points[0];
214 * firstPoint.y = d.xyzc_points[1];
215 * firstPoint.z = d.xyzc_points[2];
216 * firstPoint.confidence = d.xyzc_points[3];
217 * lastPoint.x = d.xyzc_points[(d.num_points - 1) * 4 + 0];
218 * lastPoint.y = d.xyzc_points[(d.num_points - 1) * 4 + 1];
219 * lastPoint.z = d.xyzc_points[(d.num_points - 1) * 4 + 2];
220 * lastPoint.confidence = d.xyzc_points[(d.num_points - 1) * 4 + 3];
223 struct android_depth_points
{
226 /** reserved for future use, set to 0 by gralloc's (*lock)() */
227 uint32_t reserved
[8];
229 #if defined(__clang__)
230 #pragma clang diagnostic push
231 #pragma clang diagnostic ignored "-Wc99-extensions"
234 #if defined(__clang__)
235 #pragma clang diagnostic pop
240 * These structures are used to define the reference display's
241 * capabilities for HDR content. Display engine can use this
242 * to better tone map content to user's display.
243 * Color is defined in CIE XYZ coordinates
245 struct android_xy_color
{
250 struct android_smpte2086_metadata
{
251 struct android_xy_color displayPrimaryRed
;
252 struct android_xy_color displayPrimaryGreen
;
253 struct android_xy_color displayPrimaryBlue
;
254 struct android_xy_color whitePoint
;
259 struct android_cta861_3_metadata
{
260 float maxContentLightLevel
;
261 float maxFrameAverageLightLevel
;
268 #endif /* SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H */