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 33 #include <hardware/gralloc.h> 34 #include <hardware/hwcomposer.h> 35 36 #define ALIGN(x,a) (((x) + (a) - 1L) & ~((a) - 1L)) 37 #define HW_ALIGN 32 38 #define CAMERA_ALIGN 64 39 40 /** YV12 specific (to handle different alignment) ****************************/ 41 42 /* We must align YV12 to a multiple of 32bytes as NEON optimizations 43 * in stagefright require the YV12 planes to be 128bit aligned. 44 * while display controller requires 64 bytes alignement 45 */ 46 #define YV12_ALIGN 128 47 48 #define HAL_PIXEL_FORMAT_BGRX_8888 0x101 // Keep consistent with android_utils.h 49 enum { 50 HAL_PIXEL_FORMAT_NV12 = 0x3231564E, // YCrCb 4:2:0 SP 51 HAL_PIXEL_FORMAT_NV21 = 0x3132564E, // YCrCb 4:2:0 SP 52 HAL_PIXEL_FORMAT_I420 = 0x30323449, 53 HAL_PIXEL_FORMAT_YUY2 = 0x32595559, 54 HAL_PIXEL_FORMAT_UYVY = 0x59565955, 55 56 // Intel video decode formats 57 HAL_PIXEL_FORMAT_NV12_VED = 0x7FA00E00, //OMX_INTEL_COLOR_FormatYUV420PackedSemiPlanar 58 HAL_PIXEL_FORMAT_NV12_VEDT = 0x7FA00F00, //OMX_INTEL_COLOR_FormatYUV420PackedSemiPlanar_Tiled 59 60 HAL_PIXEL_FORMAT_YCbCr_422_P = 0x12, // IYUV 61 HAL_PIXEL_FORMAT_YCbCr_420_P = 0x13, // YUV9 62 HAL_PIXEL_FORMAT_YCbCr_420_I = 0x15, 63 64 HAL_PIXEL_FORMAT_INTEL_UYVY = 0x107, 65 HAL_PIXEL_FORMAT_YCbCr_420_SP = 0x108, 66 HAL_PIXEL_FORMAT_ZSL = 0x109, 67 }; 68 69 /* This can be tuned down as appropriate for the SOC. 70 * 71 * IMG formats are usually a single sub-alloc. 72 * Some OEM video formats are two sub-allocs (Y, UV planes). 73 * Future OEM video formats might be three sub-allocs (Y, U, V planes). 74 */ 75 #define MAX_SUB_ALLOCS 3 76 77 78 /* This defines the maximum server sync objects used per allocation. */ 79 80 /* Note: It's unfortunate that we have to change the handle size dependent 81 * on a build option, but we have no choice because 'fd' fields must all 82 * be utilized so they are valid to be dup'ed, and we don't need some of 83 * the extra fds in a native_fence_sync build. 84 */ 85 #if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC) 86 #define MAX_SRV_SYNC_OBJS 2 87 #else 88 #define MAX_SRV_SYNC_OBJS 4 89 #endif 90 91 typedef struct 92 { 93 native_handle_t base; 94 95 /* These fields can be sent cross process. They are also valid 96 * to duplicate within the same process. 97 * 98 * A table is stored within psPrivateData on gralloc_module_t (this 99 * is obviously per-process) which maps stamps to a mapped 100 * PVRSRV_MEMDESC in that process. Each map entry has a lock 101 * count associated with it, satisfying the requirements of the 102 * Android API. This also prevents us from leaking maps/allocations. 103 * 104 * This table has entries inserted either by alloc() 105 * (alloc_device_t) or map() (gralloc_module_t). Entries are removed 106 * by free() (alloc_device_t) and unmap() (gralloc_module_t). 107 */ 108 109 #define IMG_NATIVE_HANDLE_NUMFDS (MAX_SRV_SYNC_OBJS + MAX_SUB_ALLOCS) 110 /* The `syncfd' field is used to export PVRSRV_CLIENT_SYNC_PRIM to 111 * another process. Its producer/consumer rules should match the 112 * PVRSRV_MEMDESC handles, except that there is only one sync 113 * per N memdesc objects. 114 * 115 * This should be listed before `fd' because it is not variable 116 * width. The problem with variable width is that in the case we 117 * export framebuffer allocations, we may want to patch some of 118 * the fds to (unused) ints, so we can't leave gaps. 119 */ 120 int aiSyncFD[MAX_SRV_SYNC_OBJS]; 121 122 /* The `fd' field is used to "export" a meminfo to another process. 123 * Therefore, it is allocated by alloc_device_t, and consumed by 124 * gralloc_module_t. 125 */ 126 int fd[MAX_SUB_ALLOCS]; 127 128 #define IMG_NATIVE_HANDLE_NUMINTS ((sizeof(unsigned long long) / sizeof(int)) + 5) 129 /* A KERNEL unique identifier for any exported kernel meminfo. Each 130 * exported kernel meminfo will have a unique stamp, but note that in 131 * userspace, several meminfos across multiple processes could have 132 * the same stamp. As the native_handle can be dup(2)'d, there could be 133 * multiple handles with the same stamp but different file descriptors. 134 */ 135 unsigned long long ui64Stamp; 136 137 /* This is used for buffer usage validation when locking a buffer, 138 * and also in WSEGL (for the composition bypass feature). 139 */ 140 int usage; 141 142 /* In order to do efficient cache flushes we need the buffer dimensions 143 * and format. These are available on the ANativeWindowBuffer, 144 * but the platform doesn't pass them down to the graphics HAL. 145 * 146 * These fields are also used in the composition bypass. In this 147 * capacity, these are the "real" values for the backing allocation. 148 */ 149 int iWidth; 150 int iHeight; 151 int iFormat; 152 unsigned int uiBpp; 153 } 154 __attribute__((aligned(sizeof(int)),packed)) IMG_native_handle_t; 155 156 typedef struct 157 { 158 int l, t, w, h; 159 } 160 IMG_write_lock_rect_t; 161 162 /* Keep this in sync with SGX */ 163 typedef int (*IMG_buffer_format_compute_params_pfn)( 164 unsigned int uiPlane, int *piWidth, int *piHeight, int *piStride, 165 int *piVStride, unsigned long *pulPlaneOffset); 166 167 #define IMG_BFF_YUV (1 << 0) 168 #define IMG_BFF_UVCbCrORDERING (1 << 1) 169 #define IMG_BFF_CPU_CLEAR (1 << 2) 170 #define IMG_BFF_DONT_GPU_CLEAR (1 << 3) 171 #define IMG_BFF_PARTIAL_ALLOC (1 << 4) 172 #define IMG_BFF_NEVER_COMPRESS (1 << 5) 173 174 /* Keep this in sync with SGX */ 175 typedef struct IMG_buffer_format_public_t 176 { 177 /* Buffer formats are returned as a linked list */ 178 struct IMG_buffer_format_public_t *psNext; 179 180 /* HAL_PIXEL_FORMAT_... enumerant */ 181 int iHalPixelFormat; 182 183 /* IMG_PIXFMT_... enumerant */ 184 int iIMGPixelFormat; 185 186 /* Friendly name for format */ 187 const char *const szName; 188 189 /* Bits (not bytes) per pixel */ 190 unsigned int uiBpp; 191 192 /* Supported HW usage bits. If this is GRALLOC_USAGE_HW_MASK, all usages 193 * are supported. Used for HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED. 194 */ 195 int iSupportedUsage; 196 197 /* Allocation description flags */ 198 unsigned int uiFlags; 199 200 /* Utility function for adjusting YUV per-plane parameters */ 201 IMG_buffer_format_compute_params_pfn pfnComputeParams; 202 } 203 IMG_buffer_format_public_t; 204 205 typedef struct 206 { 207 /* The original hwc layer */ 208 hwc_layer_1_t *psLayer; 209 210 /* Custom data for the display engine */ 211 unsigned long custom; 212 } 213 IMG_hwc_layer_t; 214 215 typedef struct IMG_display_device_public_t { 216 int (*post)(struct IMG_display_device_public_t *dev, IMG_hwc_layer_t *layers, 217 int num_layers, int *releaseFenceFd); 218 } IMG_display_device_public_t; 219 220 typedef struct IMG_gralloc_module_public_t 221 { 222 gralloc_module_t base; 223 IMG_display_device_public_t *psDisplayDevice; 224 225 /* Gets the head of the linked list of all registered formats */ 226 const IMG_buffer_format_public_t *(*GetBufferFormats)(void); 227 228 /* Functionality before this point should be in sync with SGX. 229 * After this point will be different. 230 */ 231 232 /* Custom-blit components in lieu of overlay hardware */ 233 int (*Blit)(struct IMG_gralloc_module_public_t const *module, 234 buffer_handle_t src, buffer_handle_t dest, 235 int w, int h, int x, int y, 236 int filter, 237 int transform, 238 int async); 239 240 int (*Blit3)(struct IMG_gralloc_module_public_t const *module, 241 unsigned long long ui64SrcStamp, int iSrcWidth, 242 int iSrcHeight, int iSrcFormat, int eSrcRotation, 243 buffer_handle_t dest, int eDestRotation); 244 245 /* Walk the above list and return only the specified format */ 246 const IMG_buffer_format_public_t *(*GetBufferFormat)(int iFormat); 247 /* intel hwc extension */ 248 int (*getCpuAddress)(struct IMG_gralloc_module_public_t const *module, 249 buffer_handle_t handle, 250 void **virt, uint32_t *size); 251 int (*putCpuAddress)(struct IMG_gralloc_module_public_t const *module, 252 buffer_handle_t handle); 253 IMG_display_device_public_t *(*getDisplayDevice)(struct IMG_gralloc_module_public_t *module); 254 } 255 IMG_gralloc_module_public_t; 256 257 #endif /* HAL_PUBLIC_H */ 258