1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (C) 2011 The Android Open Source Project 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 5bf215546Sopenharmony_ci * you may not use this file except in compliance with the License. 6bf215546Sopenharmony_ci * You may obtain a copy of the License at 7bf215546Sopenharmony_ci * 8bf215546Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 9bf215546Sopenharmony_ci * 10bf215546Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 11bf215546Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 12bf215546Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13bf215546Sopenharmony_ci * See the License for the specific language governing permissions and 14bf215546Sopenharmony_ci * limitations under the License. 15bf215546Sopenharmony_ci */ 16bf215546Sopenharmony_ci 17bf215546Sopenharmony_ci#ifndef SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H 18bf215546Sopenharmony_ci#define SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H 19bf215546Sopenharmony_ci 20bf215546Sopenharmony_ci#include <stddef.h> 21bf215546Sopenharmony_ci#include <stdint.h> 22bf215546Sopenharmony_ci 23bf215546Sopenharmony_ci/* 24bf215546Sopenharmony_ci * Some of the enums are now defined in HIDL in hardware/interfaces and are 25bf215546Sopenharmony_ci * generated. 26bf215546Sopenharmony_ci */ 27bf215546Sopenharmony_ci#include "graphics-base.h" 28bf215546Sopenharmony_ci#include "graphics-sw.h" 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci#ifdef __cplusplus 31bf215546Sopenharmony_ciextern "C" { 32bf215546Sopenharmony_ci#endif 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_ci/* for compatibility */ 35bf215546Sopenharmony_ci#define HAL_PIXEL_FORMAT_YCbCr_420_888 HAL_PIXEL_FORMAT_YCBCR_420_888 36bf215546Sopenharmony_ci#define HAL_PIXEL_FORMAT_YCbCr_422_SP HAL_PIXEL_FORMAT_YCBCR_422_SP 37bf215546Sopenharmony_ci#define HAL_PIXEL_FORMAT_YCrCb_420_SP HAL_PIXEL_FORMAT_YCRCB_420_SP 38bf215546Sopenharmony_ci#define HAL_PIXEL_FORMAT_YCbCr_422_I HAL_PIXEL_FORMAT_YCBCR_422_I 39bf215546Sopenharmony_citypedef android_pixel_format_t android_pixel_format; 40bf215546Sopenharmony_citypedef android_transform_t android_transform; 41bf215546Sopenharmony_citypedef android_dataspace_t android_dataspace; 42bf215546Sopenharmony_citypedef android_color_mode_t android_color_mode; 43bf215546Sopenharmony_citypedef android_color_transform_t android_color_transform; 44bf215546Sopenharmony_citypedef android_hdr_t android_hdr; 45bf215546Sopenharmony_ci 46bf215546Sopenharmony_ci/* 47bf215546Sopenharmony_ci * If the HAL needs to create service threads to handle graphics related 48bf215546Sopenharmony_ci * tasks, these threads need to run at HAL_PRIORITY_URGENT_DISPLAY priority 49bf215546Sopenharmony_ci * if they can block the main rendering thread in any way. 50bf215546Sopenharmony_ci * 51bf215546Sopenharmony_ci * the priority of the current thread can be set with: 52bf215546Sopenharmony_ci * 53bf215546Sopenharmony_ci * #include <sys/resource.h> 54bf215546Sopenharmony_ci * setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY); 55bf215546Sopenharmony_ci * 56bf215546Sopenharmony_ci */ 57bf215546Sopenharmony_ci 58bf215546Sopenharmony_ci#define HAL_PRIORITY_URGENT_DISPLAY (-8) 59bf215546Sopenharmony_ci 60bf215546Sopenharmony_ci/* 61bf215546Sopenharmony_ci * Structure for describing YCbCr formats for consumption by applications. 62bf215546Sopenharmony_ci * This is used with HAL_PIXEL_FORMAT_YCbCr_*_888. 63bf215546Sopenharmony_ci * 64bf215546Sopenharmony_ci * Buffer chroma subsampling is defined in the format. 65bf215546Sopenharmony_ci * e.g. HAL_PIXEL_FORMAT_YCbCr_420_888 has subsampling 4:2:0. 66bf215546Sopenharmony_ci * 67bf215546Sopenharmony_ci * Buffers must have a 8 bit depth. 68bf215546Sopenharmony_ci * 69bf215546Sopenharmony_ci * y, cb, and cr point to the first byte of their respective planes. 70bf215546Sopenharmony_ci * 71bf215546Sopenharmony_ci * Stride describes the distance in bytes from the first value of one row of 72bf215546Sopenharmony_ci * the image to the first value of the next row. It includes the width of the 73bf215546Sopenharmony_ci * image plus padding. 74bf215546Sopenharmony_ci * ystride is the stride of the luma plane. 75bf215546Sopenharmony_ci * cstride is the stride of the chroma planes. 76bf215546Sopenharmony_ci * 77bf215546Sopenharmony_ci * chroma_step is the distance in bytes from one chroma pixel value to the 78bf215546Sopenharmony_ci * next. This is 2 bytes for semiplanar (because chroma values are interleaved 79bf215546Sopenharmony_ci * and each chroma value is one byte) and 1 for planar. 80bf215546Sopenharmony_ci */ 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_cistruct android_ycbcr { 83bf215546Sopenharmony_ci void *y; 84bf215546Sopenharmony_ci void *cb; 85bf215546Sopenharmony_ci void *cr; 86bf215546Sopenharmony_ci size_t ystride; 87bf215546Sopenharmony_ci size_t cstride; 88bf215546Sopenharmony_ci size_t chroma_step; 89bf215546Sopenharmony_ci 90bf215546Sopenharmony_ci /** reserved for future use, set to 0 by gralloc's (*lock_ycbcr)() */ 91bf215546Sopenharmony_ci uint32_t reserved[8]; 92bf215546Sopenharmony_ci}; 93bf215546Sopenharmony_ci 94bf215546Sopenharmony_ci/* 95bf215546Sopenharmony_ci * Structures for describing flexible YUVA/RGBA formats for consumption by 96bf215546Sopenharmony_ci * applications. Such flexible formats contain a plane for each component (e.g. 97bf215546Sopenharmony_ci * red, green, blue), where each plane is laid out in a grid-like pattern 98bf215546Sopenharmony_ci * occupying unique byte addresses and with consistent byte offsets between 99bf215546Sopenharmony_ci * neighboring pixels. 100bf215546Sopenharmony_ci * 101bf215546Sopenharmony_ci * The android_flex_layout structure is used with any pixel format that can be 102bf215546Sopenharmony_ci * represented by it, such as: 103bf215546Sopenharmony_ci * - HAL_PIXEL_FORMAT_YCbCr_*_888 104bf215546Sopenharmony_ci * - HAL_PIXEL_FORMAT_FLEX_RGB*_888 105bf215546Sopenharmony_ci * - HAL_PIXEL_FORMAT_RGB[AX]_888[8],BGRA_8888,RGB_888 106bf215546Sopenharmony_ci * - HAL_PIXEL_FORMAT_YV12,Y8,Y16,YCbCr_422_SP/I,YCrCb_420_SP 107bf215546Sopenharmony_ci * - even implementation defined formats that can be represented by 108bf215546Sopenharmony_ci * the structures 109bf215546Sopenharmony_ci * 110bf215546Sopenharmony_ci * Vertical increment (aka. row increment or stride) describes the distance in 111bf215546Sopenharmony_ci * bytes from the first pixel of one row to the first pixel of the next row 112bf215546Sopenharmony_ci * (below) for the component plane. This can be negative. 113bf215546Sopenharmony_ci * 114bf215546Sopenharmony_ci * Horizontal increment (aka. column or pixel increment) describes the distance 115bf215546Sopenharmony_ci * in bytes from one pixel to the next pixel (to the right) on the same row for 116bf215546Sopenharmony_ci * the component plane. This can be negative. 117bf215546Sopenharmony_ci * 118bf215546Sopenharmony_ci * Each plane can be subsampled either vertically or horizontally by 119bf215546Sopenharmony_ci * a power-of-two factor. 120bf215546Sopenharmony_ci * 121bf215546Sopenharmony_ci * The bit-depth of each component can be arbitrary, as long as the pixels are 122bf215546Sopenharmony_ci * laid out on whole bytes, in native byte-order, using the most significant 123bf215546Sopenharmony_ci * bits of each unit. 124bf215546Sopenharmony_ci */ 125bf215546Sopenharmony_ci 126bf215546Sopenharmony_citypedef enum android_flex_component { 127bf215546Sopenharmony_ci /* luma */ 128bf215546Sopenharmony_ci FLEX_COMPONENT_Y = 1 << 0, 129bf215546Sopenharmony_ci /* chroma blue */ 130bf215546Sopenharmony_ci FLEX_COMPONENT_Cb = 1 << 1, 131bf215546Sopenharmony_ci /* chroma red */ 132bf215546Sopenharmony_ci FLEX_COMPONENT_Cr = 1 << 2, 133bf215546Sopenharmony_ci 134bf215546Sopenharmony_ci /* red */ 135bf215546Sopenharmony_ci FLEX_COMPONENT_R = 1 << 10, 136bf215546Sopenharmony_ci /* green */ 137bf215546Sopenharmony_ci FLEX_COMPONENT_G = 1 << 11, 138bf215546Sopenharmony_ci /* blue */ 139bf215546Sopenharmony_ci FLEX_COMPONENT_B = 1 << 12, 140bf215546Sopenharmony_ci 141bf215546Sopenharmony_ci /* alpha */ 142bf215546Sopenharmony_ci FLEX_COMPONENT_A = 1 << 30, 143bf215546Sopenharmony_ci} android_flex_component_t; 144bf215546Sopenharmony_ci 145bf215546Sopenharmony_citypedef struct android_flex_plane { 146bf215546Sopenharmony_ci /* pointer to the first byte of the top-left pixel of the plane. */ 147bf215546Sopenharmony_ci uint8_t *top_left; 148bf215546Sopenharmony_ci 149bf215546Sopenharmony_ci android_flex_component_t component; 150bf215546Sopenharmony_ci 151bf215546Sopenharmony_ci /* bits allocated for the component in each pixel. Must be a positive 152bf215546Sopenharmony_ci multiple of 8. */ 153bf215546Sopenharmony_ci int32_t bits_per_component; 154bf215546Sopenharmony_ci /* number of the most significant bits used in the format for this 155bf215546Sopenharmony_ci component. Must be between 1 and bits_per_component, inclusive. */ 156bf215546Sopenharmony_ci int32_t bits_used; 157bf215546Sopenharmony_ci 158bf215546Sopenharmony_ci /* horizontal increment */ 159bf215546Sopenharmony_ci int32_t h_increment; 160bf215546Sopenharmony_ci /* vertical increment */ 161bf215546Sopenharmony_ci int32_t v_increment; 162bf215546Sopenharmony_ci /* horizontal subsampling. Must be a positive power of 2. */ 163bf215546Sopenharmony_ci int32_t h_subsampling; 164bf215546Sopenharmony_ci /* vertical subsampling. Must be a positive power of 2. */ 165bf215546Sopenharmony_ci int32_t v_subsampling; 166bf215546Sopenharmony_ci} android_flex_plane_t; 167bf215546Sopenharmony_ci 168bf215546Sopenharmony_citypedef enum android_flex_format { 169bf215546Sopenharmony_ci /* not a flexible format */ 170bf215546Sopenharmony_ci FLEX_FORMAT_INVALID = 0x0, 171bf215546Sopenharmony_ci FLEX_FORMAT_Y = FLEX_COMPONENT_Y, 172bf215546Sopenharmony_ci FLEX_FORMAT_YCbCr = FLEX_COMPONENT_Y | FLEX_COMPONENT_Cb | FLEX_COMPONENT_Cr, 173bf215546Sopenharmony_ci FLEX_FORMAT_YCbCrA = FLEX_FORMAT_YCbCr | FLEX_COMPONENT_A, 174bf215546Sopenharmony_ci FLEX_FORMAT_RGB = FLEX_COMPONENT_R | FLEX_COMPONENT_G | FLEX_COMPONENT_B, 175bf215546Sopenharmony_ci FLEX_FORMAT_RGBA = FLEX_FORMAT_RGB | FLEX_COMPONENT_A, 176bf215546Sopenharmony_ci} android_flex_format_t; 177bf215546Sopenharmony_ci 178bf215546Sopenharmony_citypedef struct android_flex_layout { 179bf215546Sopenharmony_ci /* the kind of flexible format */ 180bf215546Sopenharmony_ci android_flex_format_t format; 181bf215546Sopenharmony_ci 182bf215546Sopenharmony_ci /* number of planes; 0 for FLEX_FORMAT_INVALID */ 183bf215546Sopenharmony_ci uint32_t num_planes; 184bf215546Sopenharmony_ci /* a plane for each component; ordered in increasing component value order. 185bf215546Sopenharmony_ci E.g. FLEX_FORMAT_RGBA maps 0 -> R, 1 -> G, etc. 186bf215546Sopenharmony_ci Can be NULL for FLEX_FORMAT_INVALID */ 187bf215546Sopenharmony_ci android_flex_plane_t *planes; 188bf215546Sopenharmony_ci} android_flex_layout_t; 189bf215546Sopenharmony_ci 190bf215546Sopenharmony_ci/** 191bf215546Sopenharmony_ci * Structure used to define depth point clouds for format HAL_PIXEL_FORMAT_BLOB 192bf215546Sopenharmony_ci * with dataSpace value of HAL_DATASPACE_DEPTH. 193bf215546Sopenharmony_ci * When locking a native buffer of the above format and dataSpace value, 194bf215546Sopenharmony_ci * the vaddr pointer can be cast to this structure. 195bf215546Sopenharmony_ci * 196bf215546Sopenharmony_ci * A variable-length list of (x,y,z, confidence) 3D points, as floats. (x, y, 197bf215546Sopenharmony_ci * z) represents a measured point's position, with the coordinate system defined 198bf215546Sopenharmony_ci * by the data source. Confidence represents the estimated likelihood that this 199bf215546Sopenharmony_ci * measurement is correct. It is between 0.f and 1.f, inclusive, with 1.f == 200bf215546Sopenharmony_ci * 100% confidence. 201bf215546Sopenharmony_ci * 202bf215546Sopenharmony_ci * num_points is the number of points in the list 203bf215546Sopenharmony_ci * 204bf215546Sopenharmony_ci * xyz_points is the flexible array of floating-point values. 205bf215546Sopenharmony_ci * It contains (num_points) * 4 floats. 206bf215546Sopenharmony_ci * 207bf215546Sopenharmony_ci * For example: 208bf215546Sopenharmony_ci * android_depth_points d = get_depth_buffer(); 209bf215546Sopenharmony_ci * struct { 210bf215546Sopenharmony_ci * float x; float y; float z; float confidence; 211bf215546Sopenharmony_ci * } firstPoint, lastPoint; 212bf215546Sopenharmony_ci * 213bf215546Sopenharmony_ci * firstPoint.x = d.xyzc_points[0]; 214bf215546Sopenharmony_ci * firstPoint.y = d.xyzc_points[1]; 215bf215546Sopenharmony_ci * firstPoint.z = d.xyzc_points[2]; 216bf215546Sopenharmony_ci * firstPoint.confidence = d.xyzc_points[3]; 217bf215546Sopenharmony_ci * lastPoint.x = d.xyzc_points[(d.num_points - 1) * 4 + 0]; 218bf215546Sopenharmony_ci * lastPoint.y = d.xyzc_points[(d.num_points - 1) * 4 + 1]; 219bf215546Sopenharmony_ci * lastPoint.z = d.xyzc_points[(d.num_points - 1) * 4 + 2]; 220bf215546Sopenharmony_ci * lastPoint.confidence = d.xyzc_points[(d.num_points - 1) * 4 + 3]; 221bf215546Sopenharmony_ci */ 222bf215546Sopenharmony_ci 223bf215546Sopenharmony_cistruct android_depth_points { 224bf215546Sopenharmony_ci uint32_t num_points; 225bf215546Sopenharmony_ci 226bf215546Sopenharmony_ci /** reserved for future use, set to 0 by gralloc's (*lock)() */ 227bf215546Sopenharmony_ci uint32_t reserved[8]; 228bf215546Sopenharmony_ci 229bf215546Sopenharmony_ci#if defined(__clang__) 230bf215546Sopenharmony_ci#pragma clang diagnostic push 231bf215546Sopenharmony_ci#pragma clang diagnostic ignored "-Wc99-extensions" 232bf215546Sopenharmony_ci#endif 233bf215546Sopenharmony_ci float xyzc_points[]; 234bf215546Sopenharmony_ci#if defined(__clang__) 235bf215546Sopenharmony_ci#pragma clang diagnostic pop 236bf215546Sopenharmony_ci#endif 237bf215546Sopenharmony_ci}; 238bf215546Sopenharmony_ci 239bf215546Sopenharmony_ci/** 240bf215546Sopenharmony_ci * These structures are used to define the reference display's 241bf215546Sopenharmony_ci * capabilities for HDR content. Display engine can use this 242bf215546Sopenharmony_ci * to better tone map content to user's display. 243bf215546Sopenharmony_ci * Color is defined in CIE XYZ coordinates 244bf215546Sopenharmony_ci */ 245bf215546Sopenharmony_cistruct android_xy_color { 246bf215546Sopenharmony_ci float x; 247bf215546Sopenharmony_ci float y; 248bf215546Sopenharmony_ci}; 249bf215546Sopenharmony_ci 250bf215546Sopenharmony_cistruct android_smpte2086_metadata { 251bf215546Sopenharmony_ci struct android_xy_color displayPrimaryRed; 252bf215546Sopenharmony_ci struct android_xy_color displayPrimaryGreen; 253bf215546Sopenharmony_ci struct android_xy_color displayPrimaryBlue; 254bf215546Sopenharmony_ci struct android_xy_color whitePoint; 255bf215546Sopenharmony_ci float maxLuminance; 256bf215546Sopenharmony_ci float minLuminance; 257bf215546Sopenharmony_ci}; 258bf215546Sopenharmony_ci 259bf215546Sopenharmony_cistruct android_cta861_3_metadata { 260bf215546Sopenharmony_ci float maxContentLightLevel; 261bf215546Sopenharmony_ci float maxFrameAverageLightLevel; 262bf215546Sopenharmony_ci}; 263bf215546Sopenharmony_ci 264bf215546Sopenharmony_ci#ifdef __cplusplus 265bf215546Sopenharmony_ci} 266bf215546Sopenharmony_ci#endif 267bf215546Sopenharmony_ci 268bf215546Sopenharmony_ci#endif /* SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H */ 269