Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (C) 2008 The Android Open Source Project |
michael@0 | 3 | * |
michael@0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
michael@0 | 5 | * you may not use this file except in compliance with the License. |
michael@0 | 6 | * You may obtain a copy of the License at |
michael@0 | 7 | * |
michael@0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
michael@0 | 9 | * |
michael@0 | 10 | * Unless required by applicable law or agreed to in writing, software |
michael@0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
michael@0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
michael@0 | 13 | * See the License for the specific language governing permissions and |
michael@0 | 14 | * limitations under the License. |
michael@0 | 15 | */ |
michael@0 | 16 | |
michael@0 | 17 | |
michael@0 | 18 | #ifndef ANDROID_GRALLOC_INTERFACE_H |
michael@0 | 19 | #define ANDROID_GRALLOC_INTERFACE_H |
michael@0 | 20 | |
michael@0 | 21 | #include <system/window.h> |
michael@0 | 22 | #include <hardware/hardware.h> |
michael@0 | 23 | |
michael@0 | 24 | #include <stdint.h> |
michael@0 | 25 | #include <sys/cdefs.h> |
michael@0 | 26 | #include <sys/types.h> |
michael@0 | 27 | |
michael@0 | 28 | #include <cutils/native_handle.h> |
michael@0 | 29 | |
michael@0 | 30 | #include <hardware/hardware.h> |
michael@0 | 31 | #include <hardware/fb.h> |
michael@0 | 32 | |
michael@0 | 33 | __BEGIN_DECLS |
michael@0 | 34 | |
michael@0 | 35 | #define GRALLOC_API_VERSION 1 |
michael@0 | 36 | |
michael@0 | 37 | /** |
michael@0 | 38 | * The id of this module |
michael@0 | 39 | */ |
michael@0 | 40 | #define GRALLOC_HARDWARE_MODULE_ID "gralloc" |
michael@0 | 41 | |
michael@0 | 42 | /** |
michael@0 | 43 | * Name of the graphics device to open |
michael@0 | 44 | */ |
michael@0 | 45 | |
michael@0 | 46 | #define GRALLOC_HARDWARE_GPU0 "gpu0" |
michael@0 | 47 | |
michael@0 | 48 | enum { |
michael@0 | 49 | /* buffer is never read in software */ |
michael@0 | 50 | GRALLOC_USAGE_SW_READ_NEVER = 0x00000000, |
michael@0 | 51 | /* buffer is rarely read in software */ |
michael@0 | 52 | GRALLOC_USAGE_SW_READ_RARELY = 0x00000002, |
michael@0 | 53 | /* buffer is often read in software */ |
michael@0 | 54 | GRALLOC_USAGE_SW_READ_OFTEN = 0x00000003, |
michael@0 | 55 | /* mask for the software read values */ |
michael@0 | 56 | GRALLOC_USAGE_SW_READ_MASK = 0x0000000F, |
michael@0 | 57 | |
michael@0 | 58 | /* buffer is never written in software */ |
michael@0 | 59 | GRALLOC_USAGE_SW_WRITE_NEVER = 0x00000000, |
michael@0 | 60 | /* buffer is never written in software */ |
michael@0 | 61 | GRALLOC_USAGE_SW_WRITE_RARELY = 0x00000020, |
michael@0 | 62 | /* buffer is never written in software */ |
michael@0 | 63 | GRALLOC_USAGE_SW_WRITE_OFTEN = 0x00000030, |
michael@0 | 64 | /* mask for the software write values */ |
michael@0 | 65 | GRALLOC_USAGE_SW_WRITE_MASK = 0x000000F0, |
michael@0 | 66 | |
michael@0 | 67 | /* buffer will be used as an OpenGL ES texture */ |
michael@0 | 68 | GRALLOC_USAGE_HW_TEXTURE = 0x00000100, |
michael@0 | 69 | /* buffer will be used as an OpenGL ES render target */ |
michael@0 | 70 | GRALLOC_USAGE_HW_RENDER = 0x00000200, |
michael@0 | 71 | /* buffer will be used by the 2D hardware blitter */ |
michael@0 | 72 | GRALLOC_USAGE_HW_2D = 0x00000400, |
michael@0 | 73 | /* buffer will be used by the HWComposer HAL module */ |
michael@0 | 74 | GRALLOC_USAGE_HW_COMPOSER = 0x00000800, |
michael@0 | 75 | /* buffer will be used with the framebuffer device */ |
michael@0 | 76 | GRALLOC_USAGE_HW_FB = 0x00001000, |
michael@0 | 77 | /* buffer will be used with the HW video encoder */ |
michael@0 | 78 | GRALLOC_USAGE_HW_VIDEO_ENCODER = 0x00010000, |
michael@0 | 79 | /* mask for the software usage bit-mask */ |
michael@0 | 80 | GRALLOC_USAGE_HW_MASK = 0x00011F00, |
michael@0 | 81 | |
michael@0 | 82 | /* buffer should be displayed full-screen on an external display when |
michael@0 | 83 | * possible |
michael@0 | 84 | */ |
michael@0 | 85 | GRALLOC_USAGE_EXTERNAL_DISP = 0x00002000, |
michael@0 | 86 | |
michael@0 | 87 | /* Must have a hardware-protected path to external display sink for |
michael@0 | 88 | * this buffer. If a hardware-protected path is not available, then |
michael@0 | 89 | * either don't composite only this buffer (preferred) to the |
michael@0 | 90 | * external sink, or (less desirable) do not route the entire |
michael@0 | 91 | * composition to the external sink. |
michael@0 | 92 | */ |
michael@0 | 93 | GRALLOC_USAGE_PROTECTED = 0x00004000, |
michael@0 | 94 | |
michael@0 | 95 | /* implementation-specific private usage flags */ |
michael@0 | 96 | GRALLOC_USAGE_PRIVATE_0 = 0x10000000, |
michael@0 | 97 | GRALLOC_USAGE_PRIVATE_1 = 0x20000000, |
michael@0 | 98 | GRALLOC_USAGE_PRIVATE_2 = 0x40000000, |
michael@0 | 99 | GRALLOC_USAGE_PRIVATE_3 = 0x80000000, |
michael@0 | 100 | GRALLOC_USAGE_PRIVATE_MASK = 0xF0000000, |
michael@0 | 101 | }; |
michael@0 | 102 | |
michael@0 | 103 | /*****************************************************************************/ |
michael@0 | 104 | |
michael@0 | 105 | /** |
michael@0 | 106 | * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM |
michael@0 | 107 | * and the fields of this data structure must begin with hw_module_t |
michael@0 | 108 | * followed by module specific information. |
michael@0 | 109 | */ |
michael@0 | 110 | typedef struct gralloc_module_t { |
michael@0 | 111 | struct hw_module_t common; |
michael@0 | 112 | |
michael@0 | 113 | /* |
michael@0 | 114 | * (*registerBuffer)() must be called before a buffer_handle_t that has not |
michael@0 | 115 | * been created with (*alloc_device_t::alloc)() can be used. |
michael@0 | 116 | * |
michael@0 | 117 | * This is intended to be used with buffer_handle_t's that have been |
michael@0 | 118 | * received in this process through IPC. |
michael@0 | 119 | * |
michael@0 | 120 | * This function checks that the handle is indeed a valid one and prepares |
michael@0 | 121 | * it for use with (*lock)() and (*unlock)(). |
michael@0 | 122 | * |
michael@0 | 123 | * It is not necessary to call (*registerBuffer)() on a handle created |
michael@0 | 124 | * with (*alloc_device_t::alloc)(). |
michael@0 | 125 | * |
michael@0 | 126 | * returns an error if this buffer_handle_t is not valid. |
michael@0 | 127 | */ |
michael@0 | 128 | int (*registerBuffer)(struct gralloc_module_t const* module, |
michael@0 | 129 | buffer_handle_t handle); |
michael@0 | 130 | |
michael@0 | 131 | /* |
michael@0 | 132 | * (*unregisterBuffer)() is called once this handle is no longer needed in |
michael@0 | 133 | * this process. After this call, it is an error to call (*lock)(), |
michael@0 | 134 | * (*unlock)(), or (*registerBuffer)(). |
michael@0 | 135 | * |
michael@0 | 136 | * This function doesn't close or free the handle itself; this is done |
michael@0 | 137 | * by other means, usually through libcutils's native_handle_close() and |
michael@0 | 138 | * native_handle_free(). |
michael@0 | 139 | * |
michael@0 | 140 | * It is an error to call (*unregisterBuffer)() on a buffer that wasn't |
michael@0 | 141 | * explicitly registered first. |
michael@0 | 142 | */ |
michael@0 | 143 | int (*unregisterBuffer)(struct gralloc_module_t const* module, |
michael@0 | 144 | buffer_handle_t handle); |
michael@0 | 145 | |
michael@0 | 146 | /* |
michael@0 | 147 | * The (*lock)() method is called before a buffer is accessed for the |
michael@0 | 148 | * specified usage. This call may block, for instance if the h/w needs |
michael@0 | 149 | * to finish rendering or if CPU caches need to be synchronized. |
michael@0 | 150 | * |
michael@0 | 151 | * The caller promises to modify only pixels in the area specified |
michael@0 | 152 | * by (l,t,w,h). |
michael@0 | 153 | * |
michael@0 | 154 | * The content of the buffer outside of the specified area is NOT modified |
michael@0 | 155 | * by this call. |
michael@0 | 156 | * |
michael@0 | 157 | * If usage specifies GRALLOC_USAGE_SW_*, vaddr is filled with the address |
michael@0 | 158 | * of the buffer in virtual memory. |
michael@0 | 159 | * |
michael@0 | 160 | * THREADING CONSIDERATIONS: |
michael@0 | 161 | * |
michael@0 | 162 | * It is legal for several different threads to lock a buffer from |
michael@0 | 163 | * read access, none of the threads are blocked. |
michael@0 | 164 | * |
michael@0 | 165 | * However, locking a buffer simultaneously for write or read/write is |
michael@0 | 166 | * undefined, but: |
michael@0 | 167 | * - shall not result in termination of the process |
michael@0 | 168 | * - shall not block the caller |
michael@0 | 169 | * It is acceptable to return an error or to leave the buffer's content |
michael@0 | 170 | * into an indeterminate state. |
michael@0 | 171 | * |
michael@0 | 172 | * If the buffer was created with a usage mask incompatible with the |
michael@0 | 173 | * requested usage flags here, -EINVAL is returned. |
michael@0 | 174 | * |
michael@0 | 175 | */ |
michael@0 | 176 | |
michael@0 | 177 | int (*lock)(struct gralloc_module_t const* module, |
michael@0 | 178 | buffer_handle_t handle, int usage, |
michael@0 | 179 | int l, int t, int w, int h, |
michael@0 | 180 | void** vaddr); |
michael@0 | 181 | |
michael@0 | 182 | |
michael@0 | 183 | /* |
michael@0 | 184 | * The (*unlock)() method must be called after all changes to the buffer |
michael@0 | 185 | * are completed. |
michael@0 | 186 | */ |
michael@0 | 187 | |
michael@0 | 188 | int (*unlock)(struct gralloc_module_t const* module, |
michael@0 | 189 | buffer_handle_t handle); |
michael@0 | 190 | |
michael@0 | 191 | |
michael@0 | 192 | /* reserved for future use */ |
michael@0 | 193 | int (*perform)(struct gralloc_module_t const* module, |
michael@0 | 194 | int operation, ... ); |
michael@0 | 195 | |
michael@0 | 196 | /* reserved for future use */ |
michael@0 | 197 | void* reserved_proc[7]; |
michael@0 | 198 | } gralloc_module_t; |
michael@0 | 199 | |
michael@0 | 200 | /*****************************************************************************/ |
michael@0 | 201 | |
michael@0 | 202 | /** |
michael@0 | 203 | * Every device data structure must begin with hw_device_t |
michael@0 | 204 | * followed by module specific public methods and attributes. |
michael@0 | 205 | */ |
michael@0 | 206 | |
michael@0 | 207 | typedef struct alloc_device_t { |
michael@0 | 208 | struct hw_device_t common; |
michael@0 | 209 | |
michael@0 | 210 | /* |
michael@0 | 211 | * (*alloc)() Allocates a buffer in graphic memory with the requested |
michael@0 | 212 | * parameters and returns a buffer_handle_t and the stride in pixels to |
michael@0 | 213 | * allow the implementation to satisfy hardware constraints on the width |
michael@0 | 214 | * of a pixmap (eg: it may have to be multiple of 8 pixels). |
michael@0 | 215 | * The CALLER TAKES OWNERSHIP of the buffer_handle_t. |
michael@0 | 216 | * |
michael@0 | 217 | * Returns 0 on success or -errno on error. |
michael@0 | 218 | */ |
michael@0 | 219 | |
michael@0 | 220 | int (*alloc)(struct alloc_device_t* dev, |
michael@0 | 221 | int w, int h, int format, int usage, |
michael@0 | 222 | buffer_handle_t* handle, int* stride); |
michael@0 | 223 | |
michael@0 | 224 | /* |
michael@0 | 225 | * (*free)() Frees a previously allocated buffer. |
michael@0 | 226 | * Behavior is undefined if the buffer is still mapped in any process, |
michael@0 | 227 | * but shall not result in termination of the program or security breaches |
michael@0 | 228 | * (allowing a process to get access to another process' buffers). |
michael@0 | 229 | * THIS FUNCTION TAKES OWNERSHIP of the buffer_handle_t which becomes |
michael@0 | 230 | * invalid after the call. |
michael@0 | 231 | * |
michael@0 | 232 | * Returns 0 on success or -errno on error. |
michael@0 | 233 | */ |
michael@0 | 234 | int (*free)(struct alloc_device_t* dev, |
michael@0 | 235 | buffer_handle_t handle); |
michael@0 | 236 | |
michael@0 | 237 | /* This hook is OPTIONAL. |
michael@0 | 238 | * |
michael@0 | 239 | * If non NULL it will be caused by SurfaceFlinger on dumpsys |
michael@0 | 240 | */ |
michael@0 | 241 | void (*dump)(struct alloc_device_t *dev, char *buff, int buff_len); |
michael@0 | 242 | |
michael@0 | 243 | void* reserved_proc[7]; |
michael@0 | 244 | } alloc_device_t; |
michael@0 | 245 | |
michael@0 | 246 | |
michael@0 | 247 | /** convenience API for opening and closing a supported device */ |
michael@0 | 248 | |
michael@0 | 249 | static inline int gralloc_open(const struct hw_module_t* module, |
michael@0 | 250 | struct alloc_device_t** device) { |
michael@0 | 251 | return module->methods->open(module, |
michael@0 | 252 | GRALLOC_HARDWARE_GPU0, (struct hw_device_t**)device); |
michael@0 | 253 | } |
michael@0 | 254 | |
michael@0 | 255 | static inline int gralloc_close(struct alloc_device_t* device) { |
michael@0 | 256 | return device->common.close(&device->common); |
michael@0 | 257 | } |
michael@0 | 258 | |
michael@0 | 259 | __END_DECLS |
michael@0 | 260 | |
michael@0 | 261 | #endif // ANDROID_ALLOC_INTERFACE_H |