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_*. 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 byte aligned channel depth or a byte aligned packed 68 * channel depth (e.g. 10 bits packed into 16 bits for 69 * HAL_PIXEL_FORMAT_YCbCr_P010). 70 * 71 * y, cb, and cr point to the first byte of their respective planes. 72 * 73 * Stride describes the distance in bytes from the first value of one row of 74 * the image to the first value of the next row. It includes the width of the 75 * image plus padding. 76 * ystride is the stride of the luma plane. 77 * cstride is the stride of the chroma planes. 78 * 79 * chroma_step is the distance in bytes from one chroma pixel value to the 80 * next. This is `2 * channel depth` bytes for semiplanar (because chroma 81 * values are interleaved) and `1 * channel depth` bytes for planar. 82 */ 83 84 struct android_ycbcr { 85 void *y; 86 void *cb; 87 void *cr; 88 size_t ystride; 89 size_t cstride; 90 size_t chroma_step; 91 92 /** reserved for future use, set to 0 by gralloc's (*lock_ycbcr)() */ 93 uint32_t reserved[8]; 94 }; 95 96 /* 97 * Structures for describing flexible YUVA/RGBA formats for consumption by 98 * applications. Such flexible formats contain a plane for each component (e.g. 99 * red, green, blue), where each plane is laid out in a grid-like pattern 100 * occupying unique byte addresses and with consistent byte offsets between 101 * neighboring pixels. 102 * 103 * The android_flex_layout structure is used with any pixel format that can be 104 * represented by it, such as: 105 * - HAL_PIXEL_FORMAT_YCbCr_*_888 106 * - HAL_PIXEL_FORMAT_FLEX_RGB*_888 107 * - HAL_PIXEL_FORMAT_RGB[AX]_888[8],BGRA_8888,RGB_888 108 * - HAL_PIXEL_FORMAT_YV12,Y8,Y16,YCbCr_422_SP/I,YCrCb_420_SP 109 * - even implementation defined formats that can be represented by 110 * the structures 111 * 112 * Vertical increment (aka. row increment or stride) describes the distance in 113 * bytes from the first pixel of one row to the first pixel of the next row 114 * (below) for the component plane. This can be negative. 115 * 116 * Horizontal increment (aka. column or pixel increment) describes the distance 117 * in bytes from one pixel to the next pixel (to the right) on the same row for 118 * the component plane. This can be negative. 119 * 120 * Each plane can be subsampled either vertically or horizontally by 121 * a power-of-two factor. 122 * 123 * The bit-depth of each component can be arbitrary, as long as the pixels are 124 * laid out on whole bytes, in native byte-order, using the most significant 125 * bits of each unit. 126 */ 127 128 typedef enum android_flex_component { 129 /* luma */ 130 FLEX_COMPONENT_Y = 1 << 0, 131 /* chroma blue */ 132 FLEX_COMPONENT_Cb = 1 << 1, 133 /* chroma red */ 134 FLEX_COMPONENT_Cr = 1 << 2, 135 136 /* red */ 137 FLEX_COMPONENT_R = 1 << 10, 138 /* green */ 139 FLEX_COMPONENT_G = 1 << 11, 140 /* blue */ 141 FLEX_COMPONENT_B = 1 << 12, 142 143 /* alpha */ 144 FLEX_COMPONENT_A = 1 << 30, 145 } android_flex_component_t; 146 147 typedef struct android_flex_plane { 148 /* pointer to the first byte of the top-left pixel of the plane. */ 149 uint8_t *top_left; 150 151 android_flex_component_t component; 152 153 /* bits allocated for the component in each pixel. Must be a positive 154 multiple of 8. */ 155 int32_t bits_per_component; 156 /* number of the most significant bits used in the format for this 157 component. Must be between 1 and bits_per_component, inclusive. */ 158 int32_t bits_used; 159 160 /* horizontal increment */ 161 int32_t h_increment; 162 /* vertical increment */ 163 int32_t v_increment; 164 /* horizontal subsampling. Must be a positive power of 2. */ 165 int32_t h_subsampling; 166 /* vertical subsampling. Must be a positive power of 2. */ 167 int32_t v_subsampling; 168 } android_flex_plane_t; 169 170 typedef enum android_flex_format { 171 /* not a flexible format */ 172 FLEX_FORMAT_INVALID = 0x0, 173 FLEX_FORMAT_Y = FLEX_COMPONENT_Y, 174 FLEX_FORMAT_YCbCr = FLEX_COMPONENT_Y | FLEX_COMPONENT_Cb | FLEX_COMPONENT_Cr, 175 FLEX_FORMAT_YCbCrA = FLEX_FORMAT_YCbCr | FLEX_COMPONENT_A, 176 FLEX_FORMAT_RGB = FLEX_COMPONENT_R | FLEX_COMPONENT_G | FLEX_COMPONENT_B, 177 FLEX_FORMAT_RGBA = FLEX_FORMAT_RGB | FLEX_COMPONENT_A, 178 } android_flex_format_t; 179 180 typedef struct android_flex_layout { 181 /* the kind of flexible format */ 182 android_flex_format_t format; 183 184 /* number of planes; 0 for FLEX_FORMAT_INVALID */ 185 uint32_t num_planes; 186 /* a plane for each component; ordered in increasing component value order. 187 E.g. FLEX_FORMAT_RGBA maps 0 -> R, 1 -> G, etc. 188 Can be NULL for FLEX_FORMAT_INVALID */ 189 android_flex_plane_t *planes; 190 } android_flex_layout_t; 191 192 /** 193 * Structure used to define depth point clouds for format HAL_PIXEL_FORMAT_BLOB 194 * with dataSpace value of HAL_DATASPACE_DEPTH. 195 * When locking a native buffer of the above format and dataSpace value, 196 * the vaddr pointer can be cast to this structure. 197 * 198 * A variable-length list of (x,y,z, confidence) 3D points, as floats. (x, y, 199 * z) represents a measured point's position, with the coordinate system defined 200 * by the data source. Confidence represents the estimated likelihood that this 201 * measurement is correct. It is between 0.f and 1.f, inclusive, with 1.f == 202 * 100% confidence. 203 * 204 * num_points is the number of points in the list 205 * 206 * xyz_points is the flexible array of floating-point values. 207 * It contains (num_points) * 4 floats. 208 * 209 * For example: 210 * android_depth_points d = get_depth_buffer(); 211 * struct { 212 * float x; float y; float z; float confidence; 213 * } firstPoint, lastPoint; 214 * 215 * firstPoint.x = d.xyzc_points[0]; 216 * firstPoint.y = d.xyzc_points[1]; 217 * firstPoint.z = d.xyzc_points[2]; 218 * firstPoint.confidence = d.xyzc_points[3]; 219 * lastPoint.x = d.xyzc_points[(d.num_points - 1) * 4 + 0]; 220 * lastPoint.y = d.xyzc_points[(d.num_points - 1) * 4 + 1]; 221 * lastPoint.z = d.xyzc_points[(d.num_points - 1) * 4 + 2]; 222 * lastPoint.confidence = d.xyzc_points[(d.num_points - 1) * 4 + 3]; 223 */ 224 225 struct android_depth_points { 226 uint32_t num_points; 227 228 /** reserved for future use, set to 0 by gralloc's (*lock)() */ 229 uint32_t reserved[8]; 230 231 #if defined(__clang__) 232 #pragma clang diagnostic push 233 #pragma clang diagnostic ignored "-Wc99-extensions" 234 #endif 235 float xyzc_points[]; 236 #if defined(__clang__) 237 #pragma clang diagnostic pop 238 #endif 239 }; 240 241 /** 242 * These structures are used to define the reference display's 243 * capabilities for HDR content. Display engine can use this 244 * to better tone map content to user's display. 245 * Color is defined in CIE XYZ coordinates 246 */ 247 struct android_xy_color { 248 float x; 249 float y; 250 }; 251 252 struct android_smpte2086_metadata { 253 struct android_xy_color displayPrimaryRed; 254 struct android_xy_color displayPrimaryGreen; 255 struct android_xy_color displayPrimaryBlue; 256 struct android_xy_color whitePoint; 257 float maxLuminance; 258 float minLuminance; 259 }; 260 261 struct android_cta861_3_metadata { 262 float maxContentLightLevel; 263 float maxFrameAverageLightLevel; 264 }; 265 266 #ifdef __cplusplus 267 } 268 #endif 269 270 #endif /* SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H */ 271