blob: 1a9918797991e49d57c212699bc88e5bdc852cb5 [file] [log] [blame]
Iliyan Malchev66ea3572011-05-01 14:05:30 -07001/*
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
Mattias Nissler9cf80c62016-02-03 22:20:06 +010020#include <stddef.h>
Alex Raye13f15a2013-03-19 01:41:32 -070021#include <stdint.h>
22
Chia-I Wue4c672a2016-10-20 10:14:29 +080023/*
24 * Some of the enums are now defined in HIDL in hardware/interfaces and are
25 * generated.
26 */
27#include "graphics-base.h"
28
Mathias Agopianc9b06952011-08-11 22:35:31 -070029#ifdef __cplusplus
30extern "C" {
31#endif
Iliyan Malchev66ea3572011-05-01 14:05:30 -070032
Chia-I Wue4c672a2016-10-20 10:14:29 +080033/* for compatibility */
34#define HAL_PIXEL_FORMAT_YCbCr_420_888 HAL_PIXEL_FORMAT_YCBCR_420_888
35#define HAL_PIXEL_FORMAT_YCbCr_422_888 HAL_PIXEL_FORMAT_YCBCR_422_888
36#define HAL_PIXEL_FORMAT_YCbCr_444_888 HAL_PIXEL_FORMAT_YCBCR_444_888
37#define HAL_PIXEL_FORMAT_YCbCr_422_SP HAL_PIXEL_FORMAT_YCBCR_422_SP
38#define HAL_PIXEL_FORMAT_YCrCb_420_SP HAL_PIXEL_FORMAT_YCRCB_420_SP
39#define HAL_PIXEL_FORMAT_YCbCr_422_I HAL_PIXEL_FORMAT_YCBCR_422_I
40typedef android_pixel_format_t android_pixel_format;
41typedef android_transform_t android_transform;
42typedef android_dataspace_t android_dataspace;
43typedef android_color_mode_t android_color_mode;
44typedef android_color_transform_t android_color_transform;
45typedef android_hdr_t android_hdr;
46
Mathias Agopian5c9be402011-08-09 18:55:44 -070047/*
48 * If the HAL needs to create service threads to handle graphics related
49 * tasks, these threads need to run at HAL_PRIORITY_URGENT_DISPLAY priority
50 * if they can block the main rendering thread in any way.
51 *
52 * the priority of the current thread can be set with:
53 *
54 * #include <sys/resource.h>
55 * setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY);
56 *
57 */
58
59#define HAL_PRIORITY_URGENT_DISPLAY (-8)
60
Alex Raye13f15a2013-03-19 01:41:32 -070061/*
62 * Structure for describing YCbCr formats for consumption by applications.
63 * This is used with HAL_PIXEL_FORMAT_YCbCr_*_888.
64 *
65 * Buffer chroma subsampling is defined in the format.
66 * e.g. HAL_PIXEL_FORMAT_YCbCr_420_888 has subsampling 4:2:0.
67 *
68 * Buffers must have a 8 bit depth.
69 *
Colin Cross7c7990e2016-09-15 18:04:04 -070070 * y, cb, and cr point to the first byte of their respective planes.
Alex Raye13f15a2013-03-19 01:41:32 -070071 *
72 * Stride describes the distance in bytes from the first value of one row of
73 * the image to the first value of the next row. It includes the width of the
74 * image plus padding.
Colin Cross7c7990e2016-09-15 18:04:04 -070075 * ystride is the stride of the luma plane.
76 * cstride is the stride of the chroma planes.
Alex Raye13f15a2013-03-19 01:41:32 -070077 *
Colin Cross7c7990e2016-09-15 18:04:04 -070078 * chroma_step is the distance in bytes from one chroma pixel value to the
Alex Raye13f15a2013-03-19 01:41:32 -070079 * next. This is 2 bytes for semiplanar (because chroma values are interleaved
80 * and each chroma value is one byte) and 1 for planar.
81 */
82
83struct android_ycbcr {
84 void *y;
85 void *cb;
86 void *cr;
87 size_t ystride;
88 size_t cstride;
89 size_t chroma_step;
90
91 /** reserved for future use, set to 0 by gralloc's (*lock_ycbcr)() */
92 uint32_t reserved[8];
93};
Iliyan Malchev66ea3572011-05-01 14:05:30 -070094
Lajos Molnar0e10df42016-04-08 21:18:12 -070095/*
96 * Structures for describing flexible YUVA/RGBA formats for consumption by
97 * applications. Such flexible formats contain a plane for each component (e.g.
98 * red, green, blue), where each plane is laid out in a grid-like pattern
99 * occupying unique byte addresses and with consistent byte offsets between
100 * neighboring pixels.
101 *
102 * The android_flex_layout structure is used with any pixel format that can be
103 * represented by it, such as:
104 * - HAL_PIXEL_FORMAT_YCbCr_*_888
105 * - HAL_PIXEL_FORMAT_FLEX_RGB*_888
106 * - HAL_PIXEL_FORMAT_RGB[AX]_888[8],BGRA_8888,RGB_888
107 * - HAL_PIXEL_FORMAT_YV12,Y8,Y16,YCbCr_422_SP/I,YCrCb_420_SP
108 * - even implementation defined formats that can be represented by
109 * the structures
110 *
111 * Vertical increment (aka. row increment or stride) describes the distance in
112 * bytes from the first pixel of one row to the first pixel of the next row
113 * (below) for the component plane. This can be negative.
114 *
115 * Horizontal increment (aka. column or pixel increment) describes the distance
116 * in bytes from one pixel to the next pixel (to the right) on the same row for
117 * the component plane. This can be negative.
118 *
119 * Each plane can be subsampled either vertically or horizontally by
120 * a power-of-two factor.
121 *
122 * The bit-depth of each component can be arbitrary, as long as the pixels are
123 * laid out on whole bytes, in native byte-order, using the most significant
124 * bits of each unit.
125 */
126
127typedef enum android_flex_component {
128 /* luma */
129 FLEX_COMPONENT_Y = 1 << 0,
130 /* chroma blue */
131 FLEX_COMPONENT_Cb = 1 << 1,
132 /* chroma red */
133 FLEX_COMPONENT_Cr = 1 << 2,
134
135 /* red */
136 FLEX_COMPONENT_R = 1 << 10,
137 /* green */
138 FLEX_COMPONENT_G = 1 << 11,
139 /* blue */
140 FLEX_COMPONENT_B = 1 << 12,
141
142 /* alpha */
143 FLEX_COMPONENT_A = 1 << 30,
144} android_flex_component_t;
145
146typedef struct android_flex_plane {
147 /* pointer to the first byte of the top-left pixel of the plane. */
148 uint8_t *top_left;
149
150 android_flex_component_t component;
151
152 /* bits allocated for the component in each pixel. Must be a positive
153 multiple of 8. */
154 int32_t bits_per_component;
155 /* number of the most significant bits used in the format for this
156 component. Must be between 1 and bits_per_component, inclusive. */
157 int32_t bits_used;
158
159 /* horizontal increment */
160 int32_t h_increment;
161 /* vertical increment */
162 int32_t v_increment;
163 /* horizontal subsampling. Must be a positive power of 2. */
164 int32_t h_subsampling;
165 /* vertical subsampling. Must be a positive power of 2. */
166 int32_t v_subsampling;
167} android_flex_plane_t;
168
169typedef enum android_flex_format {
170 /* not a flexible format */
171 FLEX_FORMAT_INVALID = 0x0,
172 FLEX_FORMAT_Y = FLEX_COMPONENT_Y,
173 FLEX_FORMAT_YCbCr = FLEX_COMPONENT_Y | FLEX_COMPONENT_Cb | FLEX_COMPONENT_Cr,
174 FLEX_FORMAT_YCbCrA = FLEX_FORMAT_YCbCr | FLEX_COMPONENT_A,
175 FLEX_FORMAT_RGB = FLEX_COMPONENT_R | FLEX_COMPONENT_G | FLEX_COMPONENT_B,
176 FLEX_FORMAT_RGBA = FLEX_FORMAT_RGB | FLEX_COMPONENT_A,
177} android_flex_format_t;
178
179typedef struct android_flex_layout {
180 /* the kind of flexible format */
181 android_flex_format_t format;
182
183 /* number of planes; 0 for FLEX_FORMAT_INVALID */
184 uint32_t num_planes;
185 /* a plane for each component; ordered in increasing component value order.
186 E.g. FLEX_FORMAT_RGBA maps 0 -> R, 1 -> G, etc.
187 Can be NULL for FLEX_FORMAT_INVALID */
188 android_flex_plane_t *planes;
189} android_flex_layout_t;
190
Iliyan Malchev66ea3572011-05-01 14:05:30 -0700191/**
Eino-Ville Talvala03743412015-02-17 15:34:44 -0800192 * Structure used to define depth point clouds for format HAL_PIXEL_FORMAT_BLOB
193 * with dataSpace value of HAL_DATASPACE_DEPTH.
194 * When locking a native buffer of the above format and dataSpace value,
195 * the vaddr pointer can be cast to this structure.
196 *
Eino-Ville Talvala20651b52015-05-21 15:17:05 -0700197 * A variable-length list of (x,y,z, confidence) 3D points, as floats. (x, y,
198 * z) represents a measured point's position, with the coordinate system defined
199 * by the data source. Confidence represents the estimated likelihood that this
200 * measurement is correct. It is between 0.f and 1.f, inclusive, with 1.f ==
201 * 100% confidence.
Eino-Ville Talvala03743412015-02-17 15:34:44 -0800202 *
Colin Cross7c7990e2016-09-15 18:04:04 -0700203 * num_points is the number of points in the list
Eino-Ville Talvala03743412015-02-17 15:34:44 -0800204 *
Colin Cross7c7990e2016-09-15 18:04:04 -0700205 * xyz_points is the flexible array of floating-point values.
Eino-Ville Talvala20651b52015-05-21 15:17:05 -0700206 * It contains (num_points) * 4 floats.
Eino-Ville Talvala03743412015-02-17 15:34:44 -0800207 *
208 * For example:
209 * android_depth_points d = get_depth_buffer();
210 * struct {
Eino-Ville Talvala20651b52015-05-21 15:17:05 -0700211 * float x; float y; float z; float confidence;
Eino-Ville Talvala03743412015-02-17 15:34:44 -0800212 * } firstPoint, lastPoint;
213 *
Eino-Ville Talvala20651b52015-05-21 15:17:05 -0700214 * firstPoint.x = d.xyzc_points[0];
215 * firstPoint.y = d.xyzc_points[1];
216 * firstPoint.z = d.xyzc_points[2];
217 * firstPoint.confidence = d.xyzc_points[3];
218 * lastPoint.x = d.xyzc_points[(d.num_points - 1) * 4 + 0];
219 * lastPoint.y = d.xyzc_points[(d.num_points - 1) * 4 + 1];
220 * lastPoint.z = d.xyzc_points[(d.num_points - 1) * 4 + 2];
221 * lastPoint.confidence = d.xyzc_points[(d.num_points - 1) * 4 + 3];
Eino-Ville Talvala03743412015-02-17 15:34:44 -0800222 */
223
224struct android_depth_points {
225 uint32_t num_points;
226
227 /** reserved for future use, set to 0 by gralloc's (*lock)() */
228 uint32_t reserved[8];
229
Colin Cross7c7990e2016-09-15 18:04:04 -0700230#if defined(__clang__)
231#pragma clang diagnostic push
232#pragma clang diagnostic ignored "-Wc99-extensions"
233#endif
Eino-Ville Talvala20651b52015-05-21 15:17:05 -0700234 float xyzc_points[];
Colin Cross7c7990e2016-09-15 18:04:04 -0700235#if defined(__clang__)
236#pragma clang diagnostic pop
237#endif
Eino-Ville Talvala03743412015-02-17 15:34:44 -0800238};
239
Courtney Goeltzenleuchtercae67672017-01-25 09:12:33 -0700240/**
241 * These structures are used to define the reference display's
242 * capabilities for HDR content. Display engine can use this
243 * to better tone map content to user's display.
244 * Color is defined in CIE XYZ coordinates
245 */
246struct android_xy_color {
247 float x;
248 float y;
249};
250
251struct android_smpte2086_metadata {
252 struct android_xy_color displayPrimaryRed;
253 struct android_xy_color displayPrimaryGreen;
254 struct android_xy_color displayPrimaryBlue;
255 struct android_xy_color whitePoint;
256 float maxLuminance;
257 float minLuminance;
258};
259
Mathias Agopianc9b06952011-08-11 22:35:31 -0700260#ifdef __cplusplus
261}
262#endif
Iliyan Malchev66ea3572011-05-01 14:05:30 -0700263
264#endif /* SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H */