1 /* Copyright (c) Imagination Technologies Ltd. 2 * 3 * The contents of this file are subject to the MIT license as set out below. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a copy 6 * of this software and associated documentation files (the "Software"), to deal 7 * in the Software without restriction, including without limitation the rights 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 * copies of the Software, and to permit persons to whom the Software is 10 * furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in 13 * all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 * THE SOFTWARE. 22 */ 23 24 #ifndef HAL_PUBLIC_H 25 #define HAL_PUBLIC_H 26 27 /* Authors of third party hardware composer (HWC) modules will need to include 28 * this header to access functionality in the gralloc HAL. 29 */ 30 31 #define PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC 32 //#define SUPPORT_ANDROID_MEMTRACK_HAL 33 34 #include <hardware/gralloc.h> 35 #include <hardware/hwcomposer.h> 36 37 #define ALIGN(x,a) (((x) + (a) - 1L) & ~((a) - 1L)) 38 #define HW_ALIGN 32 39 #define CAMERA_ALIGN 64 40 41 /** YV12 specific (to handle different alignment) ****************************/ 42 43 /* We must align YV12 to a multiple of 32bytes as NEON optimizations 44 * in stagefright require the YV12 planes to be 128bit aligned. 45 * while display controller requires 64 bytes alignement 46 */ 47 #define YV12_ALIGN 128 48 49 #define HAL_PIXEL_FORMAT_BGRX_8888 0x101 // Keep consistent with android_utils.h 50 enum { 51 HAL_PIXEL_FORMAT_NV12 = 0x3231564E, // YCrCb 4:2:0 SP 52 HAL_PIXEL_FORMAT_NV21 = 0x3132564E, // YCrCb 4:2:0 SP 53 HAL_PIXEL_FORMAT_I420 = 0x30323449, 54 HAL_PIXEL_FORMAT_YUY2 = 0x32595559, 55 HAL_PIXEL_FORMAT_UYVY = 0x59565955, 56 57 // Intel video decode formats 58 HAL_PIXEL_FORMAT_NV12_VED = 0x7FA00E00, //OMX_INTEL_COLOR_FormatYUV420PackedSemiPlanar 59 HAL_PIXEL_FORMAT_NV12_VEDT = 0x7FA00F00, //OMX_INTEL_COLOR_FormatYUV420PackedSemiPlanar_Tiled 60 61 HAL_PIXEL_FORMAT_YCbCr_422_P = 0x12, // IYUV 62 HAL_PIXEL_FORMAT_YCbCr_420_P = 0x13, // YUV9 63 HAL_PIXEL_FORMAT_YCbCr_420_I = 0x15, 64 65 HAL_PIXEL_FORMAT_INTEL_UYVY = 0x107, 66 HAL_PIXEL_FORMAT_YCbCr_420_SP = 0x108, 67 HAL_PIXEL_FORMAT_ZSL = 0x109, 68 }; 69 70 /* This can be tuned down as appropriate for the SOC. 71 * 72 * IMG formats are usually a single sub-alloc. 73 * Some OEM video formats are two sub-allocs (Y, UV planes). 74 * Future OEM video formats might be three sub-allocs (Y, U, V planes). 75 */ 76 #define MAX_SUB_ALLOCS 3 77 78 79 /* This defines the maximum server sync objects used per allocation. */ 80 81 /* Note: It's unfortunate that we have to change the handle size dependent 82 * on a build option, but we have no choice because 'fd' fields must all 83 * be utilized so they are valid to be dup'ed, and we don't need some of 84 * the extra fds in a native_fence_sync build. 85 */ 86 #if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC) 87 #define MAX_SRV_SYNC_OBJS 2 88 #else 89 #define MAX_SRV_SYNC_OBJS 4 90 #endif 91 92 typedef struct 93 { 94 native_handle_t base; 95 96 /* These fields can be sent cross process. They are also valid 97 * to duplicate within the same process. 98 * 99 * A table is stored within psPrivateData on gralloc_module_t (this 100 * is obviously per-process) which maps stamps to a mapped 101 * PVRSRV_MEMDESC in that process. Each map entry has a lock 102 * count associated with it, satisfying the requirements of the 103 * Android API. This also prevents us from leaking maps/allocations. 104 * 105 * This table has entries inserted either by alloc() 106 * (alloc_device_t) or map() (gralloc_module_t). Entries are removed 107 * by free() (alloc_device_t) and unmap() (gralloc_module_t). 108 */ 109 110 #define IMG_NATIVE_HANDLE_NUMFDS (MAX_SRV_SYNC_OBJS + MAX_SUB_ALLOCS) 111 /* The `syncfd' field is used to export PVRSRV_CLIENT_SYNC_PRIM to 112 * another process. Its producer/consumer rules should match the 113 * PVRSRV_MEMDESC handles, except that there is only one sync 114 * per N memdesc objects. 115 * 116 * This should be listed before `fd' because it is not variable 117 * width. The problem with variable width is that in the case we 118 * export framebuffer allocations, we may want to patch some of 119 * the fds to (unused) ints, so we can't leave gaps. 120 */ 121 int aiSyncFD[MAX_SRV_SYNC_OBJS]; 122 123 /* The `fd' field is used to "export" a meminfo to another process. 124 * Therefore, it is allocated by alloc_device_t, and consumed by 125 * gralloc_module_t. 126 */ 127 int fd[MAX_SUB_ALLOCS]; 128 129 #define IMG_NATIVE_HANDLE_NUMINTS ((sizeof(unsigned long long) / sizeof(int)) + 5) 130 /* A KERNEL unique identifier for any exported kernel meminfo. Each 131 * exported kernel meminfo will have a unique stamp, but note that in 132 * userspace, several meminfos across multiple processes could have 133 * the same stamp. As the native_handle can be dup(2)'d, there could be 134 * multiple handles with the same stamp but different file descriptors. 135 */ 136 unsigned long long ui64Stamp; 137 138 /* This is used for buffer usage validation when locking a buffer, 139 * and also in WSEGL (for the composition bypass feature). 140 */ 141 int usage; 142 143 /* In order to do efficient cache flushes we need the buffer dimensions 144 * and format. These are available on the ANativeWindowBuffer, 145 * but the platform doesn't pass them down to the graphics HAL. 146 * 147 * These fields are also used in the composition bypass. In this 148 * capacity, these are the "real" values for the backing allocation. 149 */ 150 int iWidth; 151 int iHeight; 152 int iFormat; 153 unsigned int uiBpp; 154 } 155 __attribute__((aligned(sizeof(int)),packed)) IMG_native_handle_t; 156 157 typedef struct 158 { 159 int l, t, w, h; 160 } 161 IMG_write_lock_rect_t; 162 163 /* Keep this in sync with SGX */ 164 typedef int (*IMG_buffer_format_compute_params_pfn)( 165 unsigned int uiPlane, int *piWidth, int *piHeight, int *piStride, 166 int *piVStride, unsigned long *pulPlaneOffset); 167 168 #define IMG_BFF_YUV (1 << 0) 169 #define IMG_BFF_UVCbCrORDERING (1 << 1) 170 #define IMG_BFF_CPU_CLEAR (1 << 2) 171 #define IMG_BFF_DONT_GPU_CLEAR (1 << 3) 172 #define IMG_BFF_PARTIAL_ALLOC (1 << 4) 173 #define IMG_BFF_NEVER_COMPRESS (1 << 5) 174 175 /* Keep this in sync with SGX */ 176 typedef struct IMG_buffer_format_public_t 177 { 178 /* Buffer formats are returned as a linked list */ 179 struct IMG_buffer_format_public_t *psNext; 180 181 /* HAL_PIXEL_FORMAT_... enumerant */ 182 int iHalPixelFormat; 183 184 /* IMG_PIXFMT_... enumerant */ 185 int iIMGPixelFormat; 186 187 /* Friendly name for format */ 188 const char *const szName; 189 190 /* Bits (not bytes) per pixel */ 191 unsigned int uiBpp; 192 193 /* Supported HW usage bits. If this is GRALLOC_USAGE_HW_MASK, all usages 194 * are supported. Used for HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED. 195 */ 196 int iSupportedUsage; 197 198 /* Allocation description flags */ 199 unsigned int uiFlags; 200 201 /* Utility function for adjusting YUV per-plane parameters */ 202 IMG_buffer_format_compute_params_pfn pfnComputeParams; 203 } 204 IMG_buffer_format_public_t; 205 206 #if defined(SUPPORT_ANDROID_MEMTRACK_HAL) 207 208 #include <hardware/memtrack.h> 209 210 typedef struct 211 { 212 /* Base memtrack record, copied to caller */ 213 struct memtrack_record base; 214 215 /* Record type, for filtering cached records */ 216 enum memtrack_type eType; 217 218 /* Process ID, for filtering cached records */ 219 pid_t pid; 220 } 221 IMG_memtrack_record_public_t; 222 223 #endif /* defined(SUPPORT_ANDROID_MEMTRACK_HAL) */ 224 225 typedef struct 226 { 227 /* The original hwc layer */ 228 hwc_layer_1_t *psLayer; 229 230 /* Custom data for the display engine */ 231 uint32_t custom; 232 } 233 IMG_hwc_layer_t; 234 235 typedef struct IMG_display_device_public_t { 236 int (*post)(struct IMG_display_device_public_t *dev, IMG_hwc_layer_t *layers, 237 int num_layers, int *releaseFenceFd); 238 } IMG_display_device_public_t; 239 240 typedef struct IMG_gralloc_module_public_t 241 { 242 gralloc_module_t base; 243 IMG_display_device_public_t *psDisplayDevice; 244 245 /* Gets the head of the linked list of all registered formats */ 246 const IMG_buffer_format_public_t *(*GetBufferFormats)(void); 247 248 /* Functionality before this point should be in sync with SGX. 249 * After this point will be different. 250 */ 251 252 /* Custom-blit components in lieu of overlay hardware */ 253 int (*Blit)(struct IMG_gralloc_module_public_t const *module, 254 buffer_handle_t src, buffer_handle_t dest, 255 int w, int h, int x, int y, 256 int transform, 257 int async); 258 259 int (*Blit3)(struct IMG_gralloc_module_public_t const *module, 260 unsigned long long ui64SrcStamp, int iSrcWidth, 261 int iSrcHeight, int iSrcFormat, int eSrcRotation, 262 buffer_handle_t dest, int eDestRotation); 263 264 #if defined(SUPPORT_ANDROID_MEMTRACK_HAL) 265 int (*GetMemTrackRecords)(struct IMG_gralloc_module_public_t const *module, 266 IMG_memtrack_record_public_t **ppsRecords, 267 size_t *puNumRecords); 268 #endif /* defined(SUPPORT_ANDROID_MEMTRACK_HAL) */ 269 270 /* Walk the above list and return only the specified format */ 271 const IMG_buffer_format_public_t *(*GetBufferFormat)(int iFormat); 272 /* intel hwc extension */ 273 int (*getCpuAddress)(struct IMG_gralloc_module_public_t const *module, 274 buffer_handle_t handle, 275 void **virt, uint32_t *size); 276 int (*putCpuAddress)(struct IMG_gralloc_module_public_t const *module, 277 buffer_handle_t handle); 278 IMG_display_device_public_t *(*getDisplayDevice)(struct IMG_gralloc_module_public_t *module); 279 } 280 IMG_gralloc_module_public_t; 281 282 #endif /* HAL_PUBLIC_H */ 283