• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stddef.h>
21 #include <stdint.h>
22 
23 /*
24  * Some of the enums are now defined in HIDL in hardware/interfaces and are
25  * generated.
26  */
27 #include "graphics-base.h"
28 #include "graphics-sw.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
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;
45 
46 /*
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.
50  *
51  * the priority of the current thread can be set with:
52  *
53  *      #include <sys/resource.h>
54  *      setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY);
55  *
56  */
57 
58 #define HAL_PRIORITY_URGENT_DISPLAY     (-8)
59 
60 /*
61  * Structure for describing YCbCr formats for consumption by applications.
62  * This is used with HAL_PIXEL_FORMAT_YCbCr_*_888.
63  *
64  * Buffer chroma subsampling is defined in the format.
65  * e.g. HAL_PIXEL_FORMAT_YCbCr_420_888 has subsampling 4:2:0.
66  *
67  * Buffers must have a 8 bit depth.
68  *
69  * y, cb, and cr point to the first byte of their respective planes.
70  *
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
73  * image plus padding.
74  * ystride is the stride of the luma plane.
75  * cstride is the stride of the chroma planes.
76  *
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.
80  */
81 
82 struct android_ycbcr {
83     void *y;
84     void *cb;
85     void *cr;
86     size_t ystride;
87     size_t cstride;
88     size_t chroma_step;
89 
90     /** reserved for future use, set to 0 by gralloc's (*lock_ycbcr)() */
91     uint32_t reserved[8];
92 };
93 
94 /*
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
99  * neighboring pixels.
100  *
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
108  *    the structures
109  *
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.
113  *
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.
117  *
118  * Each plane can be subsampled either vertically or horizontally by
119  * a power-of-two factor.
120  *
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
123  * bits of each unit.
124  */
125 
126 typedef enum android_flex_component {
127     /* luma */
128     FLEX_COMPONENT_Y = 1 << 0,
129     /* chroma blue */
130     FLEX_COMPONENT_Cb = 1 << 1,
131     /* chroma red */
132     FLEX_COMPONENT_Cr = 1 << 2,
133 
134     /* red */
135     FLEX_COMPONENT_R = 1 << 10,
136     /* green */
137     FLEX_COMPONENT_G = 1 << 11,
138     /* blue */
139     FLEX_COMPONENT_B = 1 << 12,
140 
141     /* alpha */
142     FLEX_COMPONENT_A = 1 << 30,
143 } android_flex_component_t;
144 
145 typedef struct android_flex_plane {
146     /* pointer to the first byte of the top-left pixel of the plane. */
147     uint8_t *top_left;
148 
149     android_flex_component_t component;
150 
151     /* bits allocated for the component in each pixel. Must be a positive
152        multiple of 8. */
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. */
156     int32_t bits_used;
157 
158     /* horizontal increment */
159     int32_t h_increment;
160     /* vertical increment */
161     int32_t v_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;
167 
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;
177 
178 typedef struct android_flex_layout {
179     /* the kind of flexible format */
180     android_flex_format_t format;
181 
182     /* number of planes; 0 for FLEX_FORMAT_INVALID */
183     uint32_t num_planes;
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;
189 
190 /**
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.
195  *
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 ==
200  * 100% confidence.
201  *
202  * num_points is the number of points in the list
203  *
204  * xyz_points is the flexible array of floating-point values.
205  *   It contains (num_points) * 4 floats.
206  *
207  *   For example:
208  *     android_depth_points d = get_depth_buffer();
209  *     struct {
210  *       float x; float y; float z; float confidence;
211  *     } firstPoint, lastPoint;
212  *
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];
221  */
222 
223 struct android_depth_points {
224     uint32_t num_points;
225 
226     /** reserved for future use, set to 0 by gralloc's (*lock)() */
227     uint32_t reserved[8];
228 
229 #if defined(__clang__)
230 #pragma clang diagnostic push
231 #pragma clang diagnostic ignored "-Wc99-extensions"
232 #endif
233     float xyzc_points[];
234 #if defined(__clang__)
235 #pragma clang diagnostic pop
236 #endif
237 };
238 
239 /**
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
244   */
245 struct android_xy_color {
246     float x;
247     float y;
248 };
249 
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;
255     float maxLuminance;
256     float minLuminance;
257 };
258 
259 struct android_cta861_3_metadata {
260     float maxContentLightLevel;
261     float maxFrameAverageLightLevel;
262 };
263 
264 #ifdef __cplusplus
265 }
266 #endif
267 
268 #endif /* SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H */
269