1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/omx-plugin/include/froyo/hardware/gralloc.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,344 @@ 1.4 +/* 1.5 + * Copyright (C) 2008 The Android Open Source Project 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * Unless required by applicable law or agreed to in writing, software 1.14 + * distributed under the License is distributed on an "AS IS" BASIS, 1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.16 + * See the License for the specific language governing permissions and 1.17 + * limitations under the License. 1.18 + */ 1.19 + 1.20 + 1.21 +#ifndef ANDROID_GRALLOC_INTERFACE_H 1.22 +#define ANDROID_GRALLOC_INTERFACE_H 1.23 + 1.24 +#include <cutils/native_handle.h> 1.25 + 1.26 +#include <hardware/hardware.h> 1.27 + 1.28 +#include <stdint.h> 1.29 +#include <sys/cdefs.h> 1.30 +#include <sys/types.h> 1.31 + 1.32 +__BEGIN_DECLS 1.33 + 1.34 +/** 1.35 + * The id of this module 1.36 + */ 1.37 +#define GRALLOC_HARDWARE_MODULE_ID "gralloc" 1.38 + 1.39 +/** 1.40 + * Name of the graphics device to open 1.41 + */ 1.42 + 1.43 +#define GRALLOC_HARDWARE_FB0 "fb0" 1.44 +#define GRALLOC_HARDWARE_GPU0 "gpu0" 1.45 + 1.46 +enum { 1.47 + /* buffer is never read in software */ 1.48 + GRALLOC_USAGE_SW_READ_NEVER = 0x00000000, 1.49 + /* buffer is rarely read in software */ 1.50 + GRALLOC_USAGE_SW_READ_RARELY = 0x00000002, 1.51 + /* buffer is often read in software */ 1.52 + GRALLOC_USAGE_SW_READ_OFTEN = 0x00000003, 1.53 + /* mask for the software read values */ 1.54 + GRALLOC_USAGE_SW_READ_MASK = 0x0000000F, 1.55 + 1.56 + /* buffer is never written in software */ 1.57 + GRALLOC_USAGE_SW_WRITE_NEVER = 0x00000000, 1.58 + /* buffer is never written in software */ 1.59 + GRALLOC_USAGE_SW_WRITE_RARELY = 0x00000020, 1.60 + /* buffer is never written in software */ 1.61 + GRALLOC_USAGE_SW_WRITE_OFTEN = 0x00000030, 1.62 + /* mask for the software write values */ 1.63 + GRALLOC_USAGE_SW_WRITE_MASK = 0x000000F0, 1.64 + 1.65 + /* buffer will be used as an OpenGL ES texture */ 1.66 + GRALLOC_USAGE_HW_TEXTURE = 0x00000100, 1.67 + /* buffer will be used as an OpenGL ES render target */ 1.68 + GRALLOC_USAGE_HW_RENDER = 0x00000200, 1.69 + /* buffer will be used by the 2D hardware blitter */ 1.70 + GRALLOC_USAGE_HW_2D = 0x00000C00, 1.71 + /* buffer will be used with the framebuffer device */ 1.72 + GRALLOC_USAGE_HW_FB = 0x00001000, 1.73 + /* mask for the software usage bit-mask */ 1.74 + GRALLOC_USAGE_HW_MASK = 0x00001F00, 1.75 +}; 1.76 + 1.77 +/*****************************************************************************/ 1.78 + 1.79 +typedef const native_handle* buffer_handle_t; 1.80 + 1.81 +enum { 1.82 + /* FIXME: this only exists to work-around some issues with 1.83 + * the video and camera frameworks. don't implement unless 1.84 + * you know what you're doing. 1.85 + */ 1.86 + GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER = 0x080000001, 1.87 +}; 1.88 + 1.89 +/** 1.90 + * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM 1.91 + * and the fields of this data structure must begin with hw_module_t 1.92 + * followed by module specific information. 1.93 + */ 1.94 +typedef struct gralloc_module_t { 1.95 + struct hw_module_t common; 1.96 + 1.97 + /* 1.98 + * (*registerBuffer)() must be called before a buffer_handle_t that has not 1.99 + * been created with (*alloc_device_t::alloc)() can be used. 1.100 + * 1.101 + * This is intended to be used with buffer_handle_t's that have been 1.102 + * received in this process through IPC. 1.103 + * 1.104 + * This function checks that the handle is indeed a valid one and prepares 1.105 + * it for use with (*lock)() and (*unlock)(). 1.106 + * 1.107 + * It is not necessary to call (*registerBuffer)() on a handle created 1.108 + * with (*alloc_device_t::alloc)(). 1.109 + * 1.110 + * returns an error if this buffer_handle_t is not valid. 1.111 + */ 1.112 + int (*registerBuffer)(struct gralloc_module_t const* module, 1.113 + buffer_handle_t handle); 1.114 + 1.115 + /* 1.116 + * (*unregisterBuffer)() is called once this handle is no longer needed in 1.117 + * this process. After this call, it is an error to call (*lock)(), 1.118 + * (*unlock)(), or (*registerBuffer)(). 1.119 + * 1.120 + * This function doesn't close or free the handle itself; this is done 1.121 + * by other means, usually through libcutils's native_handle_close() and 1.122 + * native_handle_free(). 1.123 + * 1.124 + * It is an error to call (*unregisterBuffer)() on a buffer that wasn't 1.125 + * explicitly registered first. 1.126 + */ 1.127 + int (*unregisterBuffer)(struct gralloc_module_t const* module, 1.128 + buffer_handle_t handle); 1.129 + 1.130 + /* 1.131 + * The (*lock)() method is called before a buffer is accessed for the 1.132 + * specified usage. This call may block, for instance if the h/w needs 1.133 + * to finish rendering or if CPU caches need to be synchronized. 1.134 + * 1.135 + * The caller promises to modify only pixels in the area specified 1.136 + * by (l,t,w,h). 1.137 + * 1.138 + * The content of the buffer outside of the specified area is NOT modified 1.139 + * by this call. 1.140 + * 1.141 + * If usage specifies GRALLOC_USAGE_SW_*, vaddr is filled with the address 1.142 + * of the buffer in virtual memory. 1.143 + * 1.144 + * THREADING CONSIDERATIONS: 1.145 + * 1.146 + * It is legal for several different threads to lock a buffer from 1.147 + * read access, none of the threads are blocked. 1.148 + * 1.149 + * However, locking a buffer simultaneously for write or read/write is 1.150 + * undefined, but: 1.151 + * - shall not result in termination of the process 1.152 + * - shall not block the caller 1.153 + * It is acceptable to return an error or to leave the buffer's content 1.154 + * into an indeterminate state. 1.155 + * 1.156 + * If the buffer was created with a usage mask incompatible with the 1.157 + * requested usage flags here, -EINVAL is returned. 1.158 + * 1.159 + */ 1.160 + 1.161 + int (*lock)(struct gralloc_module_t const* module, 1.162 + buffer_handle_t handle, int usage, 1.163 + int l, int t, int w, int h, 1.164 + void** vaddr); 1.165 + 1.166 + 1.167 + /* 1.168 + * The (*unlock)() method must be called after all changes to the buffer 1.169 + * are completed. 1.170 + */ 1.171 + 1.172 + int (*unlock)(struct gralloc_module_t const* module, 1.173 + buffer_handle_t handle); 1.174 + 1.175 + 1.176 + /* reserved for future use */ 1.177 + int (*perform)(struct gralloc_module_t const* module, 1.178 + int operation, ... ); 1.179 + 1.180 + /* reserved for future use */ 1.181 + void* reserved_proc[7]; 1.182 +} gralloc_module_t; 1.183 + 1.184 +/*****************************************************************************/ 1.185 + 1.186 +/** 1.187 + * Every device data structure must begin with hw_device_t 1.188 + * followed by module specific public methods and attributes. 1.189 + */ 1.190 + 1.191 +typedef struct alloc_device_t { 1.192 + struct hw_device_t common; 1.193 + 1.194 + /* 1.195 + * (*alloc)() Allocates a buffer in graphic memory with the requested 1.196 + * parameters and returns a buffer_handle_t and the stride in pixels to 1.197 + * allow the implementation to satisfy hardware constraints on the width 1.198 + * of a pixmap (eg: it may have to be multiple of 8 pixels). 1.199 + * The CALLER TAKES OWNERSHIP of the buffer_handle_t. 1.200 + * 1.201 + * Returns 0 on success or -errno on error. 1.202 + */ 1.203 + 1.204 + int (*alloc)(struct alloc_device_t* dev, 1.205 + int w, int h, int format, int usage, 1.206 + buffer_handle_t* handle, int* stride); 1.207 + 1.208 + /* 1.209 + * (*free)() Frees a previously allocated buffer. 1.210 + * Behavior is undefined if the buffer is still mapped in any process, 1.211 + * but shall not result in termination of the program or security breaches 1.212 + * (allowing a process to get access to another process' buffers). 1.213 + * THIS FUNCTION TAKES OWNERSHIP of the buffer_handle_t which becomes 1.214 + * invalid after the call. 1.215 + * 1.216 + * Returns 0 on success or -errno on error. 1.217 + */ 1.218 + int (*free)(struct alloc_device_t* dev, 1.219 + buffer_handle_t handle); 1.220 + 1.221 +} alloc_device_t; 1.222 + 1.223 + 1.224 +typedef struct framebuffer_device_t { 1.225 + struct hw_device_t common; 1.226 + 1.227 + /* flags describing some attributes of the framebuffer */ 1.228 + const uint32_t flags; 1.229 + 1.230 + /* dimensions of the framebuffer in pixels */ 1.231 + const uint32_t width; 1.232 + const uint32_t height; 1.233 + 1.234 + /* frambuffer stride in pixels */ 1.235 + const int stride; 1.236 + 1.237 + /* framebuffer pixel format */ 1.238 + const int format; 1.239 + 1.240 + /* resolution of the framebuffer's display panel in pixel per inch*/ 1.241 + const float xdpi; 1.242 + const float ydpi; 1.243 + 1.244 + /* framebuffer's display panel refresh rate in frames per second */ 1.245 + const float fps; 1.246 + 1.247 + /* min swap interval supported by this framebuffer */ 1.248 + const int minSwapInterval; 1.249 + 1.250 + /* max swap interval supported by this framebuffer */ 1.251 + const int maxSwapInterval; 1.252 + 1.253 + int reserved[8]; 1.254 + 1.255 + /* 1.256 + * requests a specific swap-interval (same definition than EGL) 1.257 + * 1.258 + * Returns 0 on success or -errno on error. 1.259 + */ 1.260 + int (*setSwapInterval)(struct framebuffer_device_t* window, 1.261 + int interval); 1.262 + 1.263 + /* 1.264 + * This hook is OPTIONAL. 1.265 + * 1.266 + * It is non NULL If the framebuffer driver supports "update-on-demand" 1.267 + * and the given rectangle is the area of the screen that gets 1.268 + * updated during (*post)(). 1.269 + * 1.270 + * This is useful on devices that are able to DMA only a portion of 1.271 + * the screen to the display panel, upon demand -- as opposed to 1.272 + * constantly refreshing the panel 60 times per second, for instance. 1.273 + * 1.274 + * Only the area defined by this rectangle is guaranteed to be valid, that 1.275 + * is, the driver is not allowed to post anything outside of this 1.276 + * rectangle. 1.277 + * 1.278 + * The rectangle evaluated during (*post)() and specifies which area 1.279 + * of the buffer passed in (*post)() shall to be posted. 1.280 + * 1.281 + * return -EINVAL if width or height <=0, or if left or top < 0 1.282 + */ 1.283 + int (*setUpdateRect)(struct framebuffer_device_t* window, 1.284 + int left, int top, int width, int height); 1.285 + 1.286 + /* 1.287 + * Post <buffer> to the display (display it on the screen) 1.288 + * The buffer must have been allocated with the 1.289 + * GRALLOC_USAGE_HW_FB usage flag. 1.290 + * buffer must be the same width and height as the display and must NOT 1.291 + * be locked. 1.292 + * 1.293 + * The buffer is shown during the next VSYNC. 1.294 + * 1.295 + * If the same buffer is posted again (possibly after some other buffer), 1.296 + * post() will block until the the first post is completed. 1.297 + * 1.298 + * Internally, post() is expected to lock the buffer so that a 1.299 + * subsequent call to gralloc_module_t::(*lock)() with USAGE_RENDER or 1.300 + * USAGE_*_WRITE will block until it is safe; that is typically once this 1.301 + * buffer is shown and another buffer has been posted. 1.302 + * 1.303 + * Returns 0 on success or -errno on error. 1.304 + */ 1.305 + int (*post)(struct framebuffer_device_t* dev, buffer_handle_t buffer); 1.306 + 1.307 + 1.308 + /* 1.309 + * The (*compositionComplete)() method must be called after the 1.310 + * compositor has finished issuing GL commands for client buffers. 1.311 + */ 1.312 + 1.313 + int (*compositionComplete)(struct framebuffer_device_t* dev); 1.314 + 1.315 + 1.316 + void* reserved_proc[8]; 1.317 + 1.318 +} framebuffer_device_t; 1.319 + 1.320 + 1.321 +/** convenience API for opening and closing a supported device */ 1.322 + 1.323 +static inline int gralloc_open(const struct hw_module_t* module, 1.324 + struct alloc_device_t** device) { 1.325 + return module->methods->open(module, 1.326 + GRALLOC_HARDWARE_GPU0, (struct hw_device_t**)device); 1.327 +} 1.328 + 1.329 +static inline int gralloc_close(struct alloc_device_t* device) { 1.330 + return device->common.close(&device->common); 1.331 +} 1.332 + 1.333 + 1.334 +static inline int framebuffer_open(const struct hw_module_t* module, 1.335 + struct framebuffer_device_t** device) { 1.336 + return module->methods->open(module, 1.337 + GRALLOC_HARDWARE_FB0, (struct hw_device_t**)device); 1.338 +} 1.339 + 1.340 +static inline int framebuffer_close(struct framebuffer_device_t* device) { 1.341 + return device->common.close(&device->common); 1.342 +} 1.343 + 1.344 + 1.345 +__END_DECLS 1.346 + 1.347 +#endif // ANDROID_ALLOC_INTERFACE_H