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 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 /* 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 40 typedef android_pixel_format_t android_pixel_format; 41 typedef android_transform_t android_transform; 42 typedef android_dataspace_t android_dataspace; 43 typedef android_color_mode_t android_color_mode; 44 typedef android_color_transform_t android_color_transform; 45 typedef android_hdr_t android_hdr; 46 47 /* 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 61 /* 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 * 70 * y, cb, and cr point to the first byte of their respective planes. 71 * 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. 75 * ystride is the stride of the luma plane. 76 * cstride is the stride of the chroma planes. 77 * 78 * chroma_step is the distance in bytes from one chroma pixel value to the 79 * 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 83 struct 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 }; 94 95 /* 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 127 typedef 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 146 typedef 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 169 typedef 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 179 typedef 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 191 /** 192 * 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 * 197 * 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. 202 * 203 * num_points is the number of points in the list 204 * 205 * xyz_points is the flexible array of floating-point values. 206 * It contains (num_points) * 4 floats. 207 * 208 * For example: 209 * android_depth_points d = get_depth_buffer(); 210 * struct { 211 * float x; float y; float z; float confidence; 212 * } firstPoint, lastPoint; 213 * 214 * 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]; 222 */ 223 224 struct 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 230 #if defined(__clang__) 231 #pragma clang diagnostic push 232 #pragma clang diagnostic ignored "-Wc99-extensions" 233 #endif 234 float xyzc_points[]; 235 #if defined(__clang__) 236 #pragma clang diagnostic pop 237 #endif 238 }; 239 240 /** 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 */ 246 struct android_xy_color { 247 float x; 248 float y; 249 }; 250 251 struct 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 260 #ifdef __cplusplus 261 } 262 #endif 263 264 #endif /* SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H */ 265