michael@0: /* michael@0: * Copyright (C) 2008 The Android Open Source Project michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: michael@0: #ifndef ANDROID_GRALLOC_INTERFACE_H michael@0: #define ANDROID_GRALLOC_INTERFACE_H michael@0: michael@0: #include michael@0: michael@0: #include michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: __BEGIN_DECLS michael@0: michael@0: /** michael@0: * The id of this module michael@0: */ michael@0: #define GRALLOC_HARDWARE_MODULE_ID "gralloc" michael@0: michael@0: /** michael@0: * Name of the graphics device to open michael@0: */ michael@0: michael@0: #define GRALLOC_HARDWARE_FB0 "fb0" michael@0: #define GRALLOC_HARDWARE_GPU0 "gpu0" michael@0: michael@0: enum { michael@0: /* buffer is never read in software */ michael@0: GRALLOC_USAGE_SW_READ_NEVER = 0x00000000, michael@0: /* buffer is rarely read in software */ michael@0: GRALLOC_USAGE_SW_READ_RARELY = 0x00000002, michael@0: /* buffer is often read in software */ michael@0: GRALLOC_USAGE_SW_READ_OFTEN = 0x00000003, michael@0: /* mask for the software read values */ michael@0: GRALLOC_USAGE_SW_READ_MASK = 0x0000000F, michael@0: michael@0: /* buffer is never written in software */ michael@0: GRALLOC_USAGE_SW_WRITE_NEVER = 0x00000000, michael@0: /* buffer is never written in software */ michael@0: GRALLOC_USAGE_SW_WRITE_RARELY = 0x00000020, michael@0: /* buffer is never written in software */ michael@0: GRALLOC_USAGE_SW_WRITE_OFTEN = 0x00000030, michael@0: /* mask for the software write values */ michael@0: GRALLOC_USAGE_SW_WRITE_MASK = 0x000000F0, michael@0: michael@0: /* buffer will be used as an OpenGL ES texture */ michael@0: GRALLOC_USAGE_HW_TEXTURE = 0x00000100, michael@0: /* buffer will be used as an OpenGL ES render target */ michael@0: GRALLOC_USAGE_HW_RENDER = 0x00000200, michael@0: /* buffer will be used by the 2D hardware blitter */ michael@0: GRALLOC_USAGE_HW_2D = 0x00000C00, michael@0: /* buffer will be used with the framebuffer device */ michael@0: GRALLOC_USAGE_HW_FB = 0x00001000, michael@0: /* mask for the software usage bit-mask */ michael@0: GRALLOC_USAGE_HW_MASK = 0x00001F00, michael@0: }; michael@0: michael@0: /*****************************************************************************/ michael@0: michael@0: typedef const native_handle* buffer_handle_t; michael@0: michael@0: enum { michael@0: /* FIXME: this only exists to work-around some issues with michael@0: * the video and camera frameworks. don't implement unless michael@0: * you know what you're doing. michael@0: */ michael@0: GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER = 0x080000001, michael@0: }; michael@0: michael@0: /** michael@0: * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM michael@0: * and the fields of this data structure must begin with hw_module_t michael@0: * followed by module specific information. michael@0: */ michael@0: typedef struct gralloc_module_t { michael@0: struct hw_module_t common; michael@0: michael@0: /* michael@0: * (*registerBuffer)() must be called before a buffer_handle_t that has not michael@0: * been created with (*alloc_device_t::alloc)() can be used. michael@0: * michael@0: * This is intended to be used with buffer_handle_t's that have been michael@0: * received in this process through IPC. michael@0: * michael@0: * This function checks that the handle is indeed a valid one and prepares michael@0: * it for use with (*lock)() and (*unlock)(). michael@0: * michael@0: * It is not necessary to call (*registerBuffer)() on a handle created michael@0: * with (*alloc_device_t::alloc)(). michael@0: * michael@0: * returns an error if this buffer_handle_t is not valid. michael@0: */ michael@0: int (*registerBuffer)(struct gralloc_module_t const* module, michael@0: buffer_handle_t handle); michael@0: michael@0: /* michael@0: * (*unregisterBuffer)() is called once this handle is no longer needed in michael@0: * this process. After this call, it is an error to call (*lock)(), michael@0: * (*unlock)(), or (*registerBuffer)(). michael@0: * michael@0: * This function doesn't close or free the handle itself; this is done michael@0: * by other means, usually through libcutils's native_handle_close() and michael@0: * native_handle_free(). michael@0: * michael@0: * It is an error to call (*unregisterBuffer)() on a buffer that wasn't michael@0: * explicitly registered first. michael@0: */ michael@0: int (*unregisterBuffer)(struct gralloc_module_t const* module, michael@0: buffer_handle_t handle); michael@0: michael@0: /* michael@0: * The (*lock)() method is called before a buffer is accessed for the michael@0: * specified usage. This call may block, for instance if the h/w needs michael@0: * to finish rendering or if CPU caches need to be synchronized. michael@0: * michael@0: * The caller promises to modify only pixels in the area specified michael@0: * by (l,t,w,h). michael@0: * michael@0: * The content of the buffer outside of the specified area is NOT modified michael@0: * by this call. michael@0: * michael@0: * If usage specifies GRALLOC_USAGE_SW_*, vaddr is filled with the address michael@0: * of the buffer in virtual memory. michael@0: * michael@0: * THREADING CONSIDERATIONS: michael@0: * michael@0: * It is legal for several different threads to lock a buffer from michael@0: * read access, none of the threads are blocked. michael@0: * michael@0: * However, locking a buffer simultaneously for write or read/write is michael@0: * undefined, but: michael@0: * - shall not result in termination of the process michael@0: * - shall not block the caller michael@0: * It is acceptable to return an error or to leave the buffer's content michael@0: * into an indeterminate state. michael@0: * michael@0: * If the buffer was created with a usage mask incompatible with the michael@0: * requested usage flags here, -EINVAL is returned. michael@0: * michael@0: */ michael@0: michael@0: int (*lock)(struct gralloc_module_t const* module, michael@0: buffer_handle_t handle, int usage, michael@0: int l, int t, int w, int h, michael@0: void** vaddr); michael@0: michael@0: michael@0: /* michael@0: * The (*unlock)() method must be called after all changes to the buffer michael@0: * are completed. michael@0: */ michael@0: michael@0: int (*unlock)(struct gralloc_module_t const* module, michael@0: buffer_handle_t handle); michael@0: michael@0: michael@0: /* reserved for future use */ michael@0: int (*perform)(struct gralloc_module_t const* module, michael@0: int operation, ... ); michael@0: michael@0: /* reserved for future use */ michael@0: void* reserved_proc[7]; michael@0: } gralloc_module_t; michael@0: michael@0: /*****************************************************************************/ michael@0: michael@0: /** michael@0: * Every device data structure must begin with hw_device_t michael@0: * followed by module specific public methods and attributes. michael@0: */ michael@0: michael@0: typedef struct alloc_device_t { michael@0: struct hw_device_t common; michael@0: michael@0: /* michael@0: * (*alloc)() Allocates a buffer in graphic memory with the requested michael@0: * parameters and returns a buffer_handle_t and the stride in pixels to michael@0: * allow the implementation to satisfy hardware constraints on the width michael@0: * of a pixmap (eg: it may have to be multiple of 8 pixels). michael@0: * The CALLER TAKES OWNERSHIP of the buffer_handle_t. michael@0: * michael@0: * Returns 0 on success or -errno on error. michael@0: */ michael@0: michael@0: int (*alloc)(struct alloc_device_t* dev, michael@0: int w, int h, int format, int usage, michael@0: buffer_handle_t* handle, int* stride); michael@0: michael@0: /* michael@0: * (*free)() Frees a previously allocated buffer. michael@0: * Behavior is undefined if the buffer is still mapped in any process, michael@0: * but shall not result in termination of the program or security breaches michael@0: * (allowing a process to get access to another process' buffers). michael@0: * THIS FUNCTION TAKES OWNERSHIP of the buffer_handle_t which becomes michael@0: * invalid after the call. michael@0: * michael@0: * Returns 0 on success or -errno on error. michael@0: */ michael@0: int (*free)(struct alloc_device_t* dev, michael@0: buffer_handle_t handle); michael@0: michael@0: } alloc_device_t; michael@0: michael@0: michael@0: typedef struct framebuffer_device_t { michael@0: struct hw_device_t common; michael@0: michael@0: /* flags describing some attributes of the framebuffer */ michael@0: const uint32_t flags; michael@0: michael@0: /* dimensions of the framebuffer in pixels */ michael@0: const uint32_t width; michael@0: const uint32_t height; michael@0: michael@0: /* frambuffer stride in pixels */ michael@0: const int stride; michael@0: michael@0: /* framebuffer pixel format */ michael@0: const int format; michael@0: michael@0: /* resolution of the framebuffer's display panel in pixel per inch*/ michael@0: const float xdpi; michael@0: const float ydpi; michael@0: michael@0: /* framebuffer's display panel refresh rate in frames per second */ michael@0: const float fps; michael@0: michael@0: /* min swap interval supported by this framebuffer */ michael@0: const int minSwapInterval; michael@0: michael@0: /* max swap interval supported by this framebuffer */ michael@0: const int maxSwapInterval; michael@0: michael@0: int reserved[8]; michael@0: michael@0: /* michael@0: * requests a specific swap-interval (same definition than EGL) michael@0: * michael@0: * Returns 0 on success or -errno on error. michael@0: */ michael@0: int (*setSwapInterval)(struct framebuffer_device_t* window, michael@0: int interval); michael@0: michael@0: /* michael@0: * This hook is OPTIONAL. michael@0: * michael@0: * It is non NULL If the framebuffer driver supports "update-on-demand" michael@0: * and the given rectangle is the area of the screen that gets michael@0: * updated during (*post)(). michael@0: * michael@0: * This is useful on devices that are able to DMA only a portion of michael@0: * the screen to the display panel, upon demand -- as opposed to michael@0: * constantly refreshing the panel 60 times per second, for instance. michael@0: * michael@0: * Only the area defined by this rectangle is guaranteed to be valid, that michael@0: * is, the driver is not allowed to post anything outside of this michael@0: * rectangle. michael@0: * michael@0: * The rectangle evaluated during (*post)() and specifies which area michael@0: * of the buffer passed in (*post)() shall to be posted. michael@0: * michael@0: * return -EINVAL if width or height <=0, or if left or top < 0 michael@0: */ michael@0: int (*setUpdateRect)(struct framebuffer_device_t* window, michael@0: int left, int top, int width, int height); michael@0: michael@0: /* michael@0: * Post to the display (display it on the screen) michael@0: * The buffer must have been allocated with the michael@0: * GRALLOC_USAGE_HW_FB usage flag. michael@0: * buffer must be the same width and height as the display and must NOT michael@0: * be locked. michael@0: * michael@0: * The buffer is shown during the next VSYNC. michael@0: * michael@0: * If the same buffer is posted again (possibly after some other buffer), michael@0: * post() will block until the the first post is completed. michael@0: * michael@0: * Internally, post() is expected to lock the buffer so that a michael@0: * subsequent call to gralloc_module_t::(*lock)() with USAGE_RENDER or michael@0: * USAGE_*_WRITE will block until it is safe; that is typically once this michael@0: * buffer is shown and another buffer has been posted. michael@0: * michael@0: * Returns 0 on success or -errno on error. michael@0: */ michael@0: int (*post)(struct framebuffer_device_t* dev, buffer_handle_t buffer); michael@0: michael@0: michael@0: /* michael@0: * The (*compositionComplete)() method must be called after the michael@0: * compositor has finished issuing GL commands for client buffers. michael@0: */ michael@0: michael@0: int (*compositionComplete)(struct framebuffer_device_t* dev); michael@0: michael@0: michael@0: void* reserved_proc[8]; michael@0: michael@0: } framebuffer_device_t; michael@0: michael@0: michael@0: /** convenience API for opening and closing a supported device */ michael@0: michael@0: static inline int gralloc_open(const struct hw_module_t* module, michael@0: struct alloc_device_t** device) { michael@0: return module->methods->open(module, michael@0: GRALLOC_HARDWARE_GPU0, (struct hw_device_t**)device); michael@0: } michael@0: michael@0: static inline int gralloc_close(struct alloc_device_t* device) { michael@0: return device->common.close(&device->common); michael@0: } michael@0: michael@0: michael@0: static inline int framebuffer_open(const struct hw_module_t* module, michael@0: struct framebuffer_device_t** device) { michael@0: return module->methods->open(module, michael@0: GRALLOC_HARDWARE_FB0, (struct hw_device_t**)device); michael@0: } michael@0: michael@0: static inline int framebuffer_close(struct framebuffer_device_t* device) { michael@0: return device->common.close(&device->common); michael@0: } michael@0: michael@0: michael@0: __END_DECLS michael@0: michael@0: #endif // ANDROID_ALLOC_INTERFACE_H