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 and framebuffer HALs. 29 */ 30 31 #include <hardware/gralloc.h> 32 33 #define ALIGN(x,a) (((x) + (a) - 1L) & ~((a) - 1L)) 34 #define HW_ALIGN 32 35 36 /* This can be tuned down as appropriate for the SOC. 37 * 38 * IMG formats are usually a single sub-alloc. 39 * Some OEM video formats are two sub-allocs (Y, UV planes). 40 * Future OEM video formats might be three sub-allocs (Y, U, V planes). 41 */ 42 #define MAX_SUB_ALLOCS 3 43 44 typedef struct 45 { 46 native_handle_t base; 47 48 /* These fields can be sent cross process. They are also valid 49 * to duplicate within the same process. 50 * 51 * A table is stored within psPrivateData on gralloc_module_t (this 52 * is obviously per-process) which maps stamps to a mapped 53 * PVRSRV_CLIENT_MEM_INFO in that process. Each map entry has a lock 54 * count associated with it, satisfying the requirements of the 55 * Android API. This also prevents us from leaking maps/allocations. 56 * 57 * This table has entries inserted either by alloc() 58 * (alloc_device_t) or map() (gralloc_module_t). Entries are removed 59 * by free() (alloc_device_t) and unmap() (gralloc_module_t). 60 * 61 * As a special case for framebuffer_device_t, framebuffer_open() 62 * will add and framebuffer_close() will remove from this table. 63 */ 64 65 #define IMG_NATIVE_HANDLE_NUMFDS MAX_SUB_ALLOCS 66 /* The `fd' field is used to "export" a meminfo to another process. 67 * Therefore, it is allocated by alloc_device_t, and consumed by 68 * gralloc_module_t. The framebuffer_device_t does not need a handle, 69 * and the special value IMG_FRAMEBUFFER_FD is used instead. 70 */ 71 int fd[MAX_SUB_ALLOCS]; 72 73 #define IMG_NATIVE_HANDLE_NUMINTS ((sizeof(unsigned long long) / sizeof(int)) + 5) 74 /* A KERNEL unique identifier for any exported kernel meminfo. Each 75 * exported kernel meminfo will have a unique stamp, but note that in 76 * userspace, several meminfos across multiple processes could have 77 * the same stamp. As the native_handle can be dup(2)'d, there could be 78 * multiple handles with the same stamp but different file descriptors. 79 */ 80 unsigned long long ui64Stamp; 81 82 /* This is used for buffer usage validation when locking a buffer, 83 * and also in WSEGL (for the composition bypass feature). 84 */ 85 int usage; 86 87 //int dummy; 88 /* In order to do efficient cache flushes we need the buffer dimensions 89 * and format. These are available on the ANativeWindowBuffer, 90 * but the platform doesn't pass them down to the graphics HAL. 91 * 92 * These fields are also used in the composition bypass. In this 93 * capacity, these are the "real" values for the backing allocation. 94 */ 95 int iWidth; 96 int iHeight; 97 int iFormat; 98 unsigned int uiBpp; 99 } 100 __attribute__((aligned(sizeof(int)),packed)) IMG_native_handle_t; 101 102 typedef struct 103 { 104 framebuffer_device_t base; 105 106 /* The HWC was loaded. post() is no longer responsible for presents */ 107 int bBypassPost; 108 109 /* Custom-blit components in lieu of overlay hardware */ 110 int (*Blit)(framebuffer_device_t *device, buffer_handle_t src, 111 buffer_handle_t dest, int w, int h, int x, int y); 112 113 /* HWC path for present posts */ 114 int (*Post2)(framebuffer_device_t *fb, buffer_handle_t *buffers, 115 int num_buffers, void *data, int data_length); 116 } 117 IMG_framebuffer_device_public_t; 118 119 typedef struct IMG_gralloc_module_public_t 120 { 121 gralloc_module_t base; 122 123 /* If the framebuffer has been opened, this will point to the 124 * framebuffer device data required by the allocator, WSEGL 125 * modules and composerhal. 126 */ 127 IMG_framebuffer_device_public_t *psFrameBufferDevice; 128 129 int (*GetPhyAddrs)(struct IMG_gralloc_module_public_t const* module, 130 buffer_handle_t handle, 131 unsigned int auiPhyAddr[MAX_SUB_ALLOCS]); 132 /* Custom-blit components in lieu of overlay hardware */ 133 int (*Blit)(struct IMG_gralloc_module_public_t const *module, 134 buffer_handle_t src, 135 void *dest[MAX_SUB_ALLOCS], int format); 136 137 int (*Blit2)(struct IMG_gralloc_module_public_t const *module, 138 buffer_handle_t src, buffer_handle_t dest, 139 int w, int h, int x, int y); 140 } 141 IMG_gralloc_module_public_t; 142 143 typedef struct 144 { 145 int l, t, w, h; 146 } 147 IMG_write_lock_rect_t; 148 149 typedef struct IMG_buffer_format_public_t 150 { 151 /* Buffer formats are returned as a linked list */ 152 struct IMG_buffer_format_public_t *psNext; 153 154 /* HAL_PIXEL_FORMAT_... enumerant */ 155 int iHalPixelFormat; 156 157 /* WSEGL_PIXELFORMAT_... enumerant */ 158 int iWSEGLPixelFormat; 159 160 /* Friendly name for format */ 161 const char *const szName; 162 163 /* Bits (not bytes) per pixel */ 164 unsigned int uiBpp; 165 166 /* GPU output format (creates EGLConfig for format) */ 167 int bGPURenderable; 168 } 169 IMG_buffer_format_public_t; 170 171 #endif /* HAL_PUBLIC_H */ 172