1 // clang-format off 2 /* Copyright (c) Imagination Technologies Ltd. 3 * 4 * The contents of this file are subject to the MIT license as set out below. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 * copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 * THE SOFTWARE. 23 */ 24 25 #ifndef HAL_PUBLIC_H 26 #define HAL_PUBLIC_H 27 28 /* Authors of third party hardware composer (HWC) modules will need to include 29 * this header to access functionality in the gralloc and framebuffer HALs. 30 */ 31 32 #include <hardware/gralloc.h> 33 #if 0 /* Header below is not used by drm_hwcomposer */ 34 #include <hardware/memtrack.h> 35 #endif 36 37 #define ALIGN(x,a) (((x) + (a) - 1L) & ~((a) - 1L)) 38 #define HW_ALIGN 16 39 40 /* This can be tuned down as appropriate for the SOC. 41 * 42 * IMG formats are usually a single sub-alloc. 43 * Some OEM video formats are two sub-allocs (Y, UV planes). 44 * Future OEM video formats might be three sub-allocs (Y, U, V planes). 45 */ 46 #define MAX_SUB_ALLOCS 3 47 48 /* Format is not YCbCr (e.g. a RGB format) - bIsYUVFormat should be false */ 49 #define YUV_CHROMA_ORDER_NONE 0 50 /* Cb follows Y */ 51 #define YUV_CHROMA_ORDER_CBCR_UV 1 52 /* Cr follows Y */ 53 #define YUV_CHROMA_ORDER_CRCB_VU 2 54 55 typedef struct 56 { 57 native_handle_t base; 58 59 /* These fields can be sent cross process. They are also valid 60 * to duplicate within the same process. 61 * 62 * A table is stored within psPrivateData on gralloc_module_t (this 63 * is obviously per-process) which maps stamps to a mapped 64 * PVRSRV_CLIENT_MEM_INFO in that process. Each map entry has a lock 65 * count associated with it, satisfying the requirements of the 66 * Android API. This also prevents us from leaking maps/allocations. 67 * 68 * This table has entries inserted either by alloc() 69 * (alloc_device_t) or map() (gralloc_module_t). Entries are removed 70 * by free() (alloc_device_t) and unmap() (gralloc_module_t). 71 * 72 * As a special case for framebuffer_device_t, framebuffer_open() 73 * will add and framebuffer_close() will remove from this table. 74 */ 75 76 #define IMG_NATIVE_HANDLE_NUMFDS MAX_SUB_ALLOCS 77 /* The `fd' field is used to "export" a meminfo to another process. 78 * Therefore, it is allocated by alloc_device_t, and consumed by 79 * gralloc_module_t. The framebuffer_device_t does not need a handle, 80 * and the special value IMG_FRAMEBUFFER_FD is used instead. 81 */ 82 int fd[MAX_SUB_ALLOCS]; 83 84 #define IMG_NATIVE_HANDLE_NUMINTS \ 85 ((sizeof(unsigned long long) / sizeof(int)) + 5 + MAX_SUB_ALLOCS + 1 + MAX_SUB_ALLOCS + MAX_SUB_ALLOCS) 86 /* A KERNEL unique identifier for any exported kernel meminfo. Each 87 * exported kernel meminfo will have a unique stamp, but note that in 88 * userspace, several meminfos across multiple processes could have 89 * the same stamp. As the native_handle can be dup(2)'d, there could be 90 * multiple handles with the same stamp but different file descriptors. 91 */ 92 unsigned long long ui64Stamp; 93 94 /* This is used for buffer usage validation when locking a buffer, 95 * and also in WSEGL (for the composition bypass feature). 96 */ 97 int usage; 98 99 /* In order to do efficient cache flushes we need the buffer dimensions 100 * and format. These are available on the ANativeWindowBuffer, 101 * but the platform doesn't pass them down to the graphics HAL. 102 */ 103 int iWidth; 104 int iHeight; 105 int iFormat; 106 unsigned int uiBpp; 107 108 /* The ion allocation path doesn't allow for the allocation size and 109 * mapping flags to be communicated cross-process automatically. 110 * Cache these here so we can map buffers in client processes. 111 */ 112 unsigned int uiAllocSize[MAX_SUB_ALLOCS]; 113 unsigned int uiFlags; 114 /* For multi-planar allocations, there will be multiple hstrides */ 115 int aiStride[MAX_SUB_ALLOCS]; 116 117 /* For multi-planar allocations, there will be multiple vstrides */ 118 int aiVStride[MAX_SUB_ALLOCS]; 119 120 } 121 __attribute__((aligned(sizeof(int)),packed)) IMG_native_handle_t; 122 123 typedef struct 124 { 125 int l, t, w, h; 126 } 127 IMG_write_lock_rect_t; 128 129 typedef int (*IMG_buffer_format_compute_params_pfn)( 130 unsigned int uiPlane, int *piWidth, int *piHeight, 131 int *piStride, int *piVStride, unsigned long *pulPlaneOffset); 132 133 typedef struct IMG_buffer_format_public_t 134 { 135 /* Buffer formats are returned as a linked list */ 136 struct IMG_buffer_format_public_t *psNext; 137 138 /* HAL_PIXEL_FORMAT_... enumerant */ 139 int iHalPixelFormat; 140 141 /* WSEGL_PIXELFORMAT_... enumerant */ 142 int iWSEGLPixelFormat; 143 144 /* Friendly name for format */ 145 const char *const szName; 146 147 /* Bits (not bytes) per pixel */ 148 unsigned int uiBpp; 149 150 /* Supported HW usage bits. If this is GRALLOC_USAGE_HW_MASK, all usages 151 * are supported. Used for HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED. 152 */ 153 int iSupportedUsage; 154 155 /* YUV output format */ 156 int bIsYUVFormat; 157 158 /* YCBCR_ORDERING_* defined the order of the Cb/Cr values */ 159 int eYUVChromaOrder; 160 161 /* Utility function for adjusting YUV per-plane parameters */ 162 IMG_buffer_format_compute_params_pfn pfnComputeParams; 163 } 164 IMG_buffer_format_public_t; 165 166 #if 0 /* Not used by drm_hwcomposer but require additional dependencies */ 167 168 typedef struct 169 { 170 /* Base memtrack record, copied to caller */ 171 struct memtrack_record base; 172 173 /* Record type, for filtering cached records */ 174 enum memtrack_type eType; 175 176 /* Process ID, for filtering cached records */ 177 pid_t pid; 178 } 179 IMG_memtrack_record_public_t; 180 181 typedef struct IMG_gralloc_module_public_t 182 { 183 gralloc_module_t base; 184 185 /* This function is deprecated and might be NULL. Do not use it. */ 186 int (*GetPhyAddrs)(gralloc_module_t const* module, 187 buffer_handle_t handle, void **ppvPhyAddr); 188 189 /* Obtain HAL's registered format list */ 190 const IMG_buffer_format_public_t *(*GetBufferFormats)(void); 191 192 int (*GetImplementationFormat) (struct IMG_gralloc_module_public_t const *psGrallocModule, int usage); 193 194 int (*GetMemTrackRecords)(struct IMG_gralloc_module_public_t const *module, 195 IMG_memtrack_record_public_t **ppsRecords, 196 size_t *puNumRecords); 197 198 /* Custom-blit components in lieu of overlay hardware */ 199 int (*Blit)(struct IMG_gralloc_module_public_t const *module, 200 buffer_handle_t src, 201 void *dest[MAX_SUB_ALLOCS], int format); 202 203 int (*Blit2)(struct IMG_gralloc_module_public_t const *module, 204 buffer_handle_t src, buffer_handle_t dest, 205 int w, int h, int x, int y); 206 207 int (*Blit3)(struct IMG_gralloc_module_public_t const *module, 208 unsigned long long ui64SrcStamp, int iSrcWidth, 209 int iSrcHeight, int iSrcFormat, int eSrcRotation, 210 buffer_handle_t dest, int eDestRotation); 211 } 212 IMG_gralloc_module_public_t; 213 214 #endif 215 216 /** 217 * pixel format definitions 218 */ 219 220 enum { 221 /* 222 * 0x100 = 0x1FF 223 * 224 * This range is reserved for pixel formats that are specific to the HAL 225 * implementation. Implementations can use any value in this range to 226 * communicate video pixel formats between their HAL modules. These 227 * formats must not have an alpha channel. Additionally, an EGLimage 228 * created from a gralloc buffer of one of these formats must be 229 * supported for use with the GL_OES_EGL_image_external OpenGL ES 230 * extension. 231 */ 232 233 /* 234 * These are vendor specific pixel format, by (informal) convention 235 * IMGTec formats start from the top of the range, TI formats start from 236 * the bottom 237 */ 238 HAL_PIXEL_FORMAT_TI_NV12 = 0x100, 239 HAL_PIXEL_FORMAT_TI_UNUSED = 0x101, 240 HAL_PIXEL_FORMAT_TI_NV12_1D = 0x102, 241 HAL_PIXEL_FORMAT_TI_Y8 = 0x103, 242 HAL_PIXEL_FORMAT_TI_Y16 = 0x104, 243 HAL_PIXEL_FORMAT_TI_UYVY = 0x105, 244 HAL_PIXEL_FORMAT_BGRX_8888 = 0x1FF, 245 246 /* generic format missing from Android list, not specific to vendor 247 * implementation 248 */ 249 HAL_PIXEL_FORMAT_NV12 = 0x3231564E, // FourCC for NV12 250 }; 251 252 #endif /* HAL_PUBLIC_H */ 253 // clang-format on 254