Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 <cutils/native_handle.h> |
michael@0 | 22 | |
michael@0 | 23 | #include <hardware/hardware.h> |
michael@0 | 24 | |
michael@0 | 25 | #include <stdint.h> |
michael@0 | 26 | #include <sys/cdefs.h> |
michael@0 | 27 | #include <sys/types.h> |
michael@0 | 28 | |
michael@0 | 29 | __BEGIN_DECLS |
michael@0 | 30 | |
michael@0 | 31 | /** |
michael@0 | 32 | * The id of this module |
michael@0 | 33 | */ |
michael@0 | 34 | #define GRALLOC_HARDWARE_MODULE_ID "gralloc" |
michael@0 | 35 | |
michael@0 | 36 | /** |
michael@0 | 37 | * Name of the graphics device to open |
michael@0 | 38 | */ |
michael@0 | 39 | |
michael@0 | 40 | #define GRALLOC_HARDWARE_FB0 "fb0" |
michael@0 | 41 | #define GRALLOC_HARDWARE_GPU0 "gpu0" |
michael@0 | 42 | |
michael@0 | 43 | enum { |
michael@0 | 44 | /* buffer is never read in software */ |
michael@0 | 45 | GRALLOC_USAGE_SW_READ_NEVER = 0x00000000, |
michael@0 | 46 | /* buffer is rarely read in software */ |
michael@0 | 47 | GRALLOC_USAGE_SW_READ_RARELY = 0x00000002, |
michael@0 | 48 | /* buffer is often read in software */ |
michael@0 | 49 | GRALLOC_USAGE_SW_READ_OFTEN = 0x00000003, |
michael@0 | 50 | /* mask for the software read values */ |
michael@0 | 51 | GRALLOC_USAGE_SW_READ_MASK = 0x0000000F, |
michael@0 | 52 | |
michael@0 | 53 | /* buffer is never written in software */ |
michael@0 | 54 | GRALLOC_USAGE_SW_WRITE_NEVER = 0x00000000, |
michael@0 | 55 | /* buffer is never written in software */ |
michael@0 | 56 | GRALLOC_USAGE_SW_WRITE_RARELY = 0x00000020, |
michael@0 | 57 | /* buffer is never written in software */ |
michael@0 | 58 | GRALLOC_USAGE_SW_WRITE_OFTEN = 0x00000030, |
michael@0 | 59 | /* mask for the software write values */ |
michael@0 | 60 | GRALLOC_USAGE_SW_WRITE_MASK = 0x000000F0, |
michael@0 | 61 | |
michael@0 | 62 | /* buffer will be used as an OpenGL ES texture */ |
michael@0 | 63 | GRALLOC_USAGE_HW_TEXTURE = 0x00000100, |
michael@0 | 64 | /* buffer will be used as an OpenGL ES render target */ |
michael@0 | 65 | GRALLOC_USAGE_HW_RENDER = 0x00000200, |
michael@0 | 66 | /* buffer will be used by the 2D hardware blitter */ |
michael@0 | 67 | GRALLOC_USAGE_HW_2D = 0x00000C00, |
michael@0 | 68 | /* buffer will be used with the framebuffer device */ |
michael@0 | 69 | GRALLOC_USAGE_HW_FB = 0x00001000, |
michael@0 | 70 | /* mask for the software usage bit-mask */ |
michael@0 | 71 | GRALLOC_USAGE_HW_MASK = 0x00001F00, |
michael@0 | 72 | }; |
michael@0 | 73 | |
michael@0 | 74 | /*****************************************************************************/ |
michael@0 | 75 | |
michael@0 | 76 | typedef const native_handle* buffer_handle_t; |
michael@0 | 77 | |
michael@0 | 78 | enum { |
michael@0 | 79 | /* FIXME: this only exists to work-around some issues with |
michael@0 | 80 | * the video and camera frameworks. don't implement unless |
michael@0 | 81 | * you know what you're doing. |
michael@0 | 82 | */ |
michael@0 | 83 | GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER = 0x080000001, |
michael@0 | 84 | }; |
michael@0 | 85 | |
michael@0 | 86 | /** |
michael@0 | 87 | * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM |
michael@0 | 88 | * and the fields of this data structure must begin with hw_module_t |
michael@0 | 89 | * followed by module specific information. |
michael@0 | 90 | */ |
michael@0 | 91 | typedef struct gralloc_module_t { |
michael@0 | 92 | struct hw_module_t common; |
michael@0 | 93 | |
michael@0 | 94 | /* |
michael@0 | 95 | * (*registerBuffer)() must be called before a buffer_handle_t that has not |
michael@0 | 96 | * been created with (*alloc_device_t::alloc)() can be used. |
michael@0 | 97 | * |
michael@0 | 98 | * This is intended to be used with buffer_handle_t's that have been |
michael@0 | 99 | * received in this process through IPC. |
michael@0 | 100 | * |
michael@0 | 101 | * This function checks that the handle is indeed a valid one and prepares |
michael@0 | 102 | * it for use with (*lock)() and (*unlock)(). |
michael@0 | 103 | * |
michael@0 | 104 | * It is not necessary to call (*registerBuffer)() on a handle created |
michael@0 | 105 | * with (*alloc_device_t::alloc)(). |
michael@0 | 106 | * |
michael@0 | 107 | * returns an error if this buffer_handle_t is not valid. |
michael@0 | 108 | */ |
michael@0 | 109 | int (*registerBuffer)(struct gralloc_module_t const* module, |
michael@0 | 110 | buffer_handle_t handle); |
michael@0 | 111 | |
michael@0 | 112 | /* |
michael@0 | 113 | * (*unregisterBuffer)() is called once this handle is no longer needed in |
michael@0 | 114 | * this process. After this call, it is an error to call (*lock)(), |
michael@0 | 115 | * (*unlock)(), or (*registerBuffer)(). |
michael@0 | 116 | * |
michael@0 | 117 | * This function doesn't close or free the handle itself; this is done |
michael@0 | 118 | * by other means, usually through libcutils's native_handle_close() and |
michael@0 | 119 | * native_handle_free(). |
michael@0 | 120 | * |
michael@0 | 121 | * It is an error to call (*unregisterBuffer)() on a buffer that wasn't |
michael@0 | 122 | * explicitly registered first. |
michael@0 | 123 | */ |
michael@0 | 124 | int (*unregisterBuffer)(struct gralloc_module_t const* module, |
michael@0 | 125 | buffer_handle_t handle); |
michael@0 | 126 | |
michael@0 | 127 | /* |
michael@0 | 128 | * The (*lock)() method is called before a buffer is accessed for the |
michael@0 | 129 | * specified usage. This call may block, for instance if the h/w needs |
michael@0 | 130 | * to finish rendering or if CPU caches need to be synchronized. |
michael@0 | 131 | * |
michael@0 | 132 | * The caller promises to modify only pixels in the area specified |
michael@0 | 133 | * by (l,t,w,h). |
michael@0 | 134 | * |
michael@0 | 135 | * The content of the buffer outside of the specified area is NOT modified |
michael@0 | 136 | * by this call. |
michael@0 | 137 | * |
michael@0 | 138 | * If usage specifies GRALLOC_USAGE_SW_*, vaddr is filled with the address |
michael@0 | 139 | * of the buffer in virtual memory. |
michael@0 | 140 | * |
michael@0 | 141 | * THREADING CONSIDERATIONS: |
michael@0 | 142 | * |
michael@0 | 143 | * It is legal for several different threads to lock a buffer from |
michael@0 | 144 | * read access, none of the threads are blocked. |
michael@0 | 145 | * |
michael@0 | 146 | * However, locking a buffer simultaneously for write or read/write is |
michael@0 | 147 | * undefined, but: |
michael@0 | 148 | * - shall not result in termination of the process |
michael@0 | 149 | * - shall not block the caller |
michael@0 | 150 | * It is acceptable to return an error or to leave the buffer's content |
michael@0 | 151 | * into an indeterminate state. |
michael@0 | 152 | * |
michael@0 | 153 | * If the buffer was created with a usage mask incompatible with the |
michael@0 | 154 | * requested usage flags here, -EINVAL is returned. |
michael@0 | 155 | * |
michael@0 | 156 | */ |
michael@0 | 157 | |
michael@0 | 158 | int (*lock)(struct gralloc_module_t const* module, |
michael@0 | 159 | buffer_handle_t handle, int usage, |
michael@0 | 160 | int l, int t, int w, int h, |
michael@0 | 161 | void** vaddr); |
michael@0 | 162 | |
michael@0 | 163 | |
michael@0 | 164 | /* |
michael@0 | 165 | * The (*unlock)() method must be called after all changes to the buffer |
michael@0 | 166 | * are completed. |
michael@0 | 167 | */ |
michael@0 | 168 | |
michael@0 | 169 | int (*unlock)(struct gralloc_module_t const* module, |
michael@0 | 170 | buffer_handle_t handle); |
michael@0 | 171 | |
michael@0 | 172 | |
michael@0 | 173 | /* reserved for future use */ |
michael@0 | 174 | int (*perform)(struct gralloc_module_t const* module, |
michael@0 | 175 | int operation, ... ); |
michael@0 | 176 | |
michael@0 | 177 | /* reserved for future use */ |
michael@0 | 178 | void* reserved_proc[7]; |
michael@0 | 179 | } gralloc_module_t; |
michael@0 | 180 | |
michael@0 | 181 | /*****************************************************************************/ |
michael@0 | 182 | |
michael@0 | 183 | /** |
michael@0 | 184 | * Every device data structure must begin with hw_device_t |
michael@0 | 185 | * followed by module specific public methods and attributes. |
michael@0 | 186 | */ |
michael@0 | 187 | |
michael@0 | 188 | typedef struct alloc_device_t { |
michael@0 | 189 | struct hw_device_t common; |
michael@0 | 190 | |
michael@0 | 191 | /* |
michael@0 | 192 | * (*alloc)() Allocates a buffer in graphic memory with the requested |
michael@0 | 193 | * parameters and returns a buffer_handle_t and the stride in pixels to |
michael@0 | 194 | * allow the implementation to satisfy hardware constraints on the width |
michael@0 | 195 | * of a pixmap (eg: it may have to be multiple of 8 pixels). |
michael@0 | 196 | * The CALLER TAKES OWNERSHIP of the buffer_handle_t. |
michael@0 | 197 | * |
michael@0 | 198 | * Returns 0 on success or -errno on error. |
michael@0 | 199 | */ |
michael@0 | 200 | |
michael@0 | 201 | int (*alloc)(struct alloc_device_t* dev, |
michael@0 | 202 | int w, int h, int format, int usage, |
michael@0 | 203 | buffer_handle_t* handle, int* stride); |
michael@0 | 204 | |
michael@0 | 205 | /* |
michael@0 | 206 | * (*free)() Frees a previously allocated buffer. |
michael@0 | 207 | * Behavior is undefined if the buffer is still mapped in any process, |
michael@0 | 208 | * but shall not result in termination of the program or security breaches |
michael@0 | 209 | * (allowing a process to get access to another process' buffers). |
michael@0 | 210 | * THIS FUNCTION TAKES OWNERSHIP of the buffer_handle_t which becomes |
michael@0 | 211 | * invalid after the call. |
michael@0 | 212 | * |
michael@0 | 213 | * Returns 0 on success or -errno on error. |
michael@0 | 214 | */ |
michael@0 | 215 | int (*free)(struct alloc_device_t* dev, |
michael@0 | 216 | buffer_handle_t handle); |
michael@0 | 217 | |
michael@0 | 218 | } alloc_device_t; |
michael@0 | 219 | |
michael@0 | 220 | |
michael@0 | 221 | typedef struct framebuffer_device_t { |
michael@0 | 222 | struct hw_device_t common; |
michael@0 | 223 | |
michael@0 | 224 | /* flags describing some attributes of the framebuffer */ |
michael@0 | 225 | const uint32_t flags; |
michael@0 | 226 | |
michael@0 | 227 | /* dimensions of the framebuffer in pixels */ |
michael@0 | 228 | const uint32_t width; |
michael@0 | 229 | const uint32_t height; |
michael@0 | 230 | |
michael@0 | 231 | /* frambuffer stride in pixels */ |
michael@0 | 232 | const int stride; |
michael@0 | 233 | |
michael@0 | 234 | /* framebuffer pixel format */ |
michael@0 | 235 | const int format; |
michael@0 | 236 | |
michael@0 | 237 | /* resolution of the framebuffer's display panel in pixel per inch*/ |
michael@0 | 238 | const float xdpi; |
michael@0 | 239 | const float ydpi; |
michael@0 | 240 | |
michael@0 | 241 | /* framebuffer's display panel refresh rate in frames per second */ |
michael@0 | 242 | const float fps; |
michael@0 | 243 | |
michael@0 | 244 | /* min swap interval supported by this framebuffer */ |
michael@0 | 245 | const int minSwapInterval; |
michael@0 | 246 | |
michael@0 | 247 | /* max swap interval supported by this framebuffer */ |
michael@0 | 248 | const int maxSwapInterval; |
michael@0 | 249 | |
michael@0 | 250 | int reserved[8]; |
michael@0 | 251 | |
michael@0 | 252 | /* |
michael@0 | 253 | * requests a specific swap-interval (same definition than EGL) |
michael@0 | 254 | * |
michael@0 | 255 | * Returns 0 on success or -errno on error. |
michael@0 | 256 | */ |
michael@0 | 257 | int (*setSwapInterval)(struct framebuffer_device_t* window, |
michael@0 | 258 | int interval); |
michael@0 | 259 | |
michael@0 | 260 | /* |
michael@0 | 261 | * This hook is OPTIONAL. |
michael@0 | 262 | * |
michael@0 | 263 | * It is non NULL If the framebuffer driver supports "update-on-demand" |
michael@0 | 264 | * and the given rectangle is the area of the screen that gets |
michael@0 | 265 | * updated during (*post)(). |
michael@0 | 266 | * |
michael@0 | 267 | * This is useful on devices that are able to DMA only a portion of |
michael@0 | 268 | * the screen to the display panel, upon demand -- as opposed to |
michael@0 | 269 | * constantly refreshing the panel 60 times per second, for instance. |
michael@0 | 270 | * |
michael@0 | 271 | * Only the area defined by this rectangle is guaranteed to be valid, that |
michael@0 | 272 | * is, the driver is not allowed to post anything outside of this |
michael@0 | 273 | * rectangle. |
michael@0 | 274 | * |
michael@0 | 275 | * The rectangle evaluated during (*post)() and specifies which area |
michael@0 | 276 | * of the buffer passed in (*post)() shall to be posted. |
michael@0 | 277 | * |
michael@0 | 278 | * return -EINVAL if width or height <=0, or if left or top < 0 |
michael@0 | 279 | */ |
michael@0 | 280 | int (*setUpdateRect)(struct framebuffer_device_t* window, |
michael@0 | 281 | int left, int top, int width, int height); |
michael@0 | 282 | |
michael@0 | 283 | /* |
michael@0 | 284 | * Post <buffer> to the display (display it on the screen) |
michael@0 | 285 | * The buffer must have been allocated with the |
michael@0 | 286 | * GRALLOC_USAGE_HW_FB usage flag. |
michael@0 | 287 | * buffer must be the same width and height as the display and must NOT |
michael@0 | 288 | * be locked. |
michael@0 | 289 | * |
michael@0 | 290 | * The buffer is shown during the next VSYNC. |
michael@0 | 291 | * |
michael@0 | 292 | * If the same buffer is posted again (possibly after some other buffer), |
michael@0 | 293 | * post() will block until the the first post is completed. |
michael@0 | 294 | * |
michael@0 | 295 | * Internally, post() is expected to lock the buffer so that a |
michael@0 | 296 | * subsequent call to gralloc_module_t::(*lock)() with USAGE_RENDER or |
michael@0 | 297 | * USAGE_*_WRITE will block until it is safe; that is typically once this |
michael@0 | 298 | * buffer is shown and another buffer has been posted. |
michael@0 | 299 | * |
michael@0 | 300 | * Returns 0 on success or -errno on error. |
michael@0 | 301 | */ |
michael@0 | 302 | int (*post)(struct framebuffer_device_t* dev, buffer_handle_t buffer); |
michael@0 | 303 | |
michael@0 | 304 | |
michael@0 | 305 | /* |
michael@0 | 306 | * The (*compositionComplete)() method must be called after the |
michael@0 | 307 | * compositor has finished issuing GL commands for client buffers. |
michael@0 | 308 | */ |
michael@0 | 309 | |
michael@0 | 310 | int (*compositionComplete)(struct framebuffer_device_t* dev); |
michael@0 | 311 | |
michael@0 | 312 | |
michael@0 | 313 | void* reserved_proc[8]; |
michael@0 | 314 | |
michael@0 | 315 | } framebuffer_device_t; |
michael@0 | 316 | |
michael@0 | 317 | |
michael@0 | 318 | /** convenience API for opening and closing a supported device */ |
michael@0 | 319 | |
michael@0 | 320 | static inline int gralloc_open(const struct hw_module_t* module, |
michael@0 | 321 | struct alloc_device_t** device) { |
michael@0 | 322 | return module->methods->open(module, |
michael@0 | 323 | GRALLOC_HARDWARE_GPU0, (struct hw_device_t**)device); |
michael@0 | 324 | } |
michael@0 | 325 | |
michael@0 | 326 | static inline int gralloc_close(struct alloc_device_t* device) { |
michael@0 | 327 | return device->common.close(&device->common); |
michael@0 | 328 | } |
michael@0 | 329 | |
michael@0 | 330 | |
michael@0 | 331 | static inline int framebuffer_open(const struct hw_module_t* module, |
michael@0 | 332 | struct framebuffer_device_t** device) { |
michael@0 | 333 | return module->methods->open(module, |
michael@0 | 334 | GRALLOC_HARDWARE_FB0, (struct hw_device_t**)device); |
michael@0 | 335 | } |
michael@0 | 336 | |
michael@0 | 337 | static inline int framebuffer_close(struct framebuffer_device_t* device) { |
michael@0 | 338 | return device->common.close(&device->common); |
michael@0 | 339 | } |
michael@0 | 340 | |
michael@0 | 341 | |
michael@0 | 342 | __END_DECLS |
michael@0 | 343 | |
michael@0 | 344 | #endif // ANDROID_ALLOC_INTERFACE_H |