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: #include michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include michael@0: michael@0: #include michael@0: #include michael@0: michael@0: __BEGIN_DECLS michael@0: michael@0: #define GRALLOC_API_VERSION 1 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_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 = 0x00000400, michael@0: /* buffer will be used by the HWComposer HAL module */ michael@0: GRALLOC_USAGE_HW_COMPOSER = 0x00000800, michael@0: /* buffer will be used with the framebuffer device */ michael@0: GRALLOC_USAGE_HW_FB = 0x00001000, michael@0: /* buffer will be used with the HW video encoder */ michael@0: GRALLOC_USAGE_HW_VIDEO_ENCODER = 0x00010000, michael@0: /* mask for the software usage bit-mask */ michael@0: GRALLOC_USAGE_HW_MASK = 0x00011F00, michael@0: michael@0: /* buffer should be displayed full-screen on an external display when michael@0: * possible michael@0: */ michael@0: GRALLOC_USAGE_EXTERNAL_DISP = 0x00002000, michael@0: michael@0: /* Must have a hardware-protected path to external display sink for michael@0: * this buffer. If a hardware-protected path is not available, then michael@0: * either don't composite only this buffer (preferred) to the michael@0: * external sink, or (less desirable) do not route the entire michael@0: * composition to the external sink. michael@0: */ michael@0: GRALLOC_USAGE_PROTECTED = 0x00004000, michael@0: michael@0: /* implementation-specific private usage flags */ michael@0: GRALLOC_USAGE_PRIVATE_0 = 0x10000000, michael@0: GRALLOC_USAGE_PRIVATE_1 = 0x20000000, michael@0: GRALLOC_USAGE_PRIVATE_2 = 0x40000000, michael@0: GRALLOC_USAGE_PRIVATE_3 = 0x80000000, michael@0: GRALLOC_USAGE_PRIVATE_MASK = 0xF0000000, michael@0: }; michael@0: 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: /* This hook is OPTIONAL. michael@0: * michael@0: * If non NULL it will be caused by SurfaceFlinger on dumpsys michael@0: */ michael@0: void (*dump)(struct alloc_device_t *dev, char *buff, int buff_len); michael@0: michael@0: void* reserved_proc[7]; michael@0: } alloc_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: __END_DECLS michael@0: michael@0: #endif // ANDROID_ALLOC_INTERFACE_H