gralloc.h revision 95d78bef32edd183fb8c16b7775bf0a069948420
1a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/* 2a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Copyright (C) 2008 The Android Open Source Project 3a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * 4a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 5a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * you may not use this file except in compliance with the License. 6a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * You may obtain a copy of the License at 7a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * 8a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 9a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * 10a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Unless required by applicable law or agreed to in writing, software 11a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 12a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * See the License for the specific language governing permissions and 14a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * limitations under the License. 15a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 16a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 17a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 18a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#ifndef ANDROID_GRALLOC_INTERFACE_H 19a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#define ANDROID_GRALLOC_INTERFACE_H 20a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 21a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#include <cutils/native_handle.h> 22a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 23a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#include <hardware/hardware.h> 24a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 25a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#include <stdint.h> 26a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#include <sys/cdefs.h> 27a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#include <sys/types.h> 28a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 29a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian__BEGIN_DECLS 30a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 31a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/** 32a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * The id of this module 33a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 34a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#define GRALLOC_HARDWARE_MODULE_ID "gralloc" 35a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 36a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/** 37a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Name of the graphics device to open 38a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 39a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 40a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#define GRALLOC_HARDWARE_FB0 "fb0" 41a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#define GRALLOC_HARDWARE_GPU0 "gpu0" 42a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 43a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopianenum { 44a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* buffer is never read in software */ 45988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian GRALLOC_USAGE_SW_READ_NEVER = 0x00000000, 46a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* buffer is rarely read in software */ 47a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian GRALLOC_USAGE_SW_READ_RARELY = 0x00000002, 48a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* buffer is often read in software */ 49a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian GRALLOC_USAGE_SW_READ_OFTEN = 0x00000003, 50a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* mask for the software read values */ 51a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian GRALLOC_USAGE_SW_READ_MASK = 0x0000000F, 52a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 53a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* buffer is never written in software */ 54988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian GRALLOC_USAGE_SW_WRITE_NEVER = 0x00000000, 55a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* buffer is never written in software */ 56a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian GRALLOC_USAGE_SW_WRITE_RARELY = 0x00000020, 57a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* buffer is never written in software */ 58a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian GRALLOC_USAGE_SW_WRITE_OFTEN = 0x00000030, 59a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* mask for the software write values */ 60a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian GRALLOC_USAGE_SW_WRITE_MASK = 0x000000F0, 61a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 62a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* buffer will be used as an OpenGL ES texture */ 63a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian GRALLOC_USAGE_HW_TEXTURE = 0x00000100, 64a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* buffer will be used as an OpenGL ES render target */ 65a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian GRALLOC_USAGE_HW_RENDER = 0x00000200, 66a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* buffer will be used by the 2D hardware blitter */ 67aabb70292351f231bfd4daae8b73edb788eeba1aJamie Gennis GRALLOC_USAGE_HW_2D = 0x00000400, 68a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* buffer will be used with the framebuffer device */ 69a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian GRALLOC_USAGE_HW_FB = 0x00001000, 70a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* mask for the software usage bit-mask */ 71a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian GRALLOC_USAGE_HW_MASK = 0x00001F00, 7295d78bef32edd183fb8c16b7775bf0a069948420Jamie Gennis 7395d78bef32edd183fb8c16b7775bf0a069948420Jamie Gennis /* implementation-specific private usage flags */ 7495d78bef32edd183fb8c16b7775bf0a069948420Jamie Gennis GRALLOC_USAGE_PRIVATE_0 = 0x10000000, 7595d78bef32edd183fb8c16b7775bf0a069948420Jamie Gennis GRALLOC_USAGE_PRIVATE_1 = 0x20000000, 7695d78bef32edd183fb8c16b7775bf0a069948420Jamie Gennis GRALLOC_USAGE_PRIVATE_2 = 0x40000000, 7795d78bef32edd183fb8c16b7775bf0a069948420Jamie Gennis GRALLOC_USAGE_PRIVATE_3 = 0x80000000, 7895d78bef32edd183fb8c16b7775bf0a069948420Jamie Gennis GRALLOC_USAGE_PRIVATE_MASK = 0xF0000000, 79a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian}; 80a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 81a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/*****************************************************************************/ 82a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 83a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopiantypedef const native_handle* buffer_handle_t; 84a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 85cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopianenum { 86cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian /* FIXME: this only exists to work-around some issues with 87cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian * the video and camera frameworks. don't implement unless 88cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian * you know what you're doing. 89cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian */ 90cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER = 0x080000001, 91cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian}; 92cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian 93a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/** 94a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM 95a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * and the fields of this data structure must begin with hw_module_t 96a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * followed by module specific information. 97a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 989d82c1a447a72a2c086b9cd34c5b73b163d7acbcMathias Agopiantypedef struct gralloc_module_t { 99a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian struct hw_module_t common; 100a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 101988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian /* 102988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * (*registerBuffer)() must be called before a buffer_handle_t that has not 103988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * been created with (*alloc_device_t::alloc)() can be used. 104988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * 105988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * This is intended to be used with buffer_handle_t's that have been 106988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * received in this process through IPC. 107988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * 108988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * This function checks that the handle is indeed a valid one and prepares 109988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * it for use with (*lock)() and (*unlock)(). 110988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * 111988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * It is not necessary to call (*registerBuffer)() on a handle created 112988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * with (*alloc_device_t::alloc)(). 113a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * 114988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * returns an error if this buffer_handle_t is not valid. 115a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 116988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian int (*registerBuffer)(struct gralloc_module_t const* module, 117988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian buffer_handle_t handle); 118a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 119a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* 120988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * (*unregisterBuffer)() is called once this handle is no longer needed in 121988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * this process. After this call, it is an error to call (*lock)(), 122988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * (*unlock)(), or (*registerBuffer)(). 123988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * 124988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * This function doesn't close or free the handle itself; this is done 125988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * by other means, usually through libcutils's native_handle_close() and 126988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * native_handle_free(). 127a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * 128988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * It is an error to call (*unregisterBuffer)() on a buffer that wasn't 129988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * explicitly registered first. 130a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 131988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian int (*unregisterBuffer)(struct gralloc_module_t const* module, 132988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian buffer_handle_t handle); 133a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 134a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* 135a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * The (*lock)() method is called before a buffer is accessed for the 136a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * specified usage. This call may block, for instance if the h/w needs 137a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * to finish rendering or if CPU caches need to be synchronized. 138a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * 139988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * The caller promises to modify only pixels in the area specified 140988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * by (l,t,w,h). 141a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * 142a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * The content of the buffer outside of the specified area is NOT modified 143a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * by this call. 144988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * 145988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * If usage specifies GRALLOC_USAGE_SW_*, vaddr is filled with the address 146988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * of the buffer in virtual memory. 147988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * 148485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * THREADING CONSIDERATIONS: 149485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * 150485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * It is legal for several different threads to lock a buffer from 151485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * read access, none of the threads are blocked. 152485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * 153485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * However, locking a buffer simultaneously for write or read/write is 154485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * undefined, but: 155485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * - shall not result in termination of the process 156485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * - shall not block the caller 157485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * It is acceptable to return an error or to leave the buffer's content 158485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * into an indeterminate state. 159485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * 160988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * If the buffer was created with a usage mask incompatible with the 161988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * requested usage flags here, -EINVAL is returned. 162a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * 163a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 164a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 165a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian int (*lock)(struct gralloc_module_t const* module, 166a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian buffer_handle_t handle, int usage, 167988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian int l, int t, int w, int h, 168988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian void** vaddr); 169a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 170a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 171a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* 172a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * The (*unlock)() method must be called after all changes to the buffer 173a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * are completed. 174a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 175a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 176a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian int (*unlock)(struct gralloc_module_t const* module, 177a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian buffer_handle_t handle); 178a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 179cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian 180cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian /* reserved for future use */ 181cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian int (*perform)(struct gralloc_module_t const* module, 182cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian int operation, ... ); 183cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian 1848255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian /* reserved for future use */ 185cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian void* reserved_proc[7]; 1869d82c1a447a72a2c086b9cd34c5b73b163d7acbcMathias Agopian} gralloc_module_t; 187a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 188a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/*****************************************************************************/ 189a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 190a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/** 191a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Every device data structure must begin with hw_device_t 192a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * followed by module specific public methods and attributes. 193a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 194a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 1959d82c1a447a72a2c086b9cd34c5b73b163d7acbcMathias Agopiantypedef struct alloc_device_t { 196a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian struct hw_device_t common; 197a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 198a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* 199a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * (*alloc)() Allocates a buffer in graphic memory with the requested 200a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * parameters and returns a buffer_handle_t and the stride in pixels to 201a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * allow the implementation to satisfy hardware constraints on the width 202a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * of a pixmap (eg: it may have to be multiple of 8 pixels). 203a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * The CALLER TAKES OWNERSHIP of the buffer_handle_t. 204a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * 205a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Returns 0 on success or -errno on error. 206a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 207a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 208a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian int (*alloc)(struct alloc_device_t* dev, 209a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian int w, int h, int format, int usage, 210a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian buffer_handle_t* handle, int* stride); 211a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 212a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* 213a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * (*free)() Frees a previously allocated buffer. 214a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Behavior is undefined if the buffer is still mapped in any process, 215a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * but shall not result in termination of the program or security breaches 216a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * (allowing a process to get access to another process' buffers). 217a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * THIS FUNCTION TAKES OWNERSHIP of the buffer_handle_t which becomes 218a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * invalid after the call. 219a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * 220a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Returns 0 on success or -errno on error. 221a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 222a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian int (*free)(struct alloc_device_t* dev, 223a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian buffer_handle_t handle); 224a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 2259d82c1a447a72a2c086b9cd34c5b73b163d7acbcMathias Agopian} alloc_device_t; 226a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 227a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 2289d82c1a447a72a2c086b9cd34c5b73b163d7acbcMathias Agopiantypedef struct framebuffer_device_t { 229a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian struct hw_device_t common; 230a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 231a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* flags describing some attributes of the framebuffer */ 232a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian const uint32_t flags; 233a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 234a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* dimensions of the framebuffer in pixels */ 235a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian const uint32_t width; 236a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian const uint32_t height; 237a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 238a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* frambuffer stride in pixels */ 239a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian const int stride; 240a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 241a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* framebuffer pixel format */ 242a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian const int format; 243a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 244a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* resolution of the framebuffer's display panel in pixel per inch*/ 245a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian const float xdpi; 246a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian const float ydpi; 247a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 248a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* framebuffer's display panel refresh rate in frames per second */ 249a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian const float fps; 250a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 251a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* min swap interval supported by this framebuffer */ 252a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian const int minSwapInterval; 253a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 254a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* max swap interval supported by this framebuffer */ 255a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian const int maxSwapInterval; 256a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 257a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian int reserved[8]; 258a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 259a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* 260a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * requests a specific swap-interval (same definition than EGL) 261a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * 262a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Returns 0 on success or -errno on error. 263a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 264a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian int (*setSwapInterval)(struct framebuffer_device_t* window, 265a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian int interval); 266a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 267a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* 268f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian * This hook is OPTIONAL. 269f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian * 270f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian * It is non NULL If the framebuffer driver supports "update-on-demand" 271f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian * and the given rectangle is the area of the screen that gets 272f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian * updated during (*post)(). 273f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian * 274f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian * This is useful on devices that are able to DMA only a portion of 275f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian * the screen to the display panel, upon demand -- as opposed to 276f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian * constantly refreshing the panel 60 times per second, for instance. 277f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian * 2788255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian * Only the area defined by this rectangle is guaranteed to be valid, that 279f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian * is, the driver is not allowed to post anything outside of this 280f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian * rectangle. 281f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian * 282f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian * The rectangle evaluated during (*post)() and specifies which area 283f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian * of the buffer passed in (*post)() shall to be posted. 284a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * 285a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * return -EINVAL if width or height <=0, or if left or top < 0 286a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 287a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian int (*setUpdateRect)(struct framebuffer_device_t* window, 288a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian int left, int top, int width, int height); 289a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 290a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* 291a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Post <buffer> to the display (display it on the screen) 292a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * The buffer must have been allocated with the 293a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * GRALLOC_USAGE_HW_FB usage flag. 294a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * buffer must be the same width and height as the display and must NOT 295a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * be locked. 296a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * 297a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * The buffer is shown during the next VSYNC. 298a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * 299a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * If the same buffer is posted again (possibly after some other buffer), 300a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * post() will block until the the first post is completed. 301a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * 302a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Internally, post() is expected to lock the buffer so that a 303a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * subsequent call to gralloc_module_t::(*lock)() with USAGE_RENDER or 304a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * USAGE_*_WRITE will block until it is safe; that is typically once this 305a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * buffer is shown and another buffer has been posted. 306a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * 307a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Returns 0 on success or -errno on error. 308a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 309a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian int (*post)(struct framebuffer_device_t* dev, buffer_handle_t buffer); 310a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 3118255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian 3128255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian /* 3138255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian * The (*compositionComplete)() method must be called after the 3148255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian * compositor has finished issuing GL commands for client buffers. 3158255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian */ 3168255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian 3178255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian int (*compositionComplete)(struct framebuffer_device_t* dev); 3188255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian 3198255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian 320a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian void* reserved_proc[8]; 3219d82c1a447a72a2c086b9cd34c5b73b163d7acbcMathias Agopian 3229d82c1a447a72a2c086b9cd34c5b73b163d7acbcMathias Agopian} framebuffer_device_t; 323a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 324a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 325a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/** convenience API for opening and closing a supported device */ 326a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 327a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopianstatic inline int gralloc_open(const struct hw_module_t* module, 328a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian struct alloc_device_t** device) { 329a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian return module->methods->open(module, 330a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian GRALLOC_HARDWARE_GPU0, (struct hw_device_t**)device); 331a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian} 332a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 333a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopianstatic inline int gralloc_close(struct alloc_device_t* device) { 334a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian return device->common.close(&device->common); 335a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian} 336a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 337a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 338a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopianstatic inline int framebuffer_open(const struct hw_module_t* module, 339a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian struct framebuffer_device_t** device) { 340a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian return module->methods->open(module, 341a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian GRALLOC_HARDWARE_FB0, (struct hw_device_t**)device); 342a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian} 343a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 344a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopianstatic inline int framebuffer_close(struct framebuffer_device_t* device) { 345a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian return device->common.close(&device->common); 346a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian} 347a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 348a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 349a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian__END_DECLS 350a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 351a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#endif // ANDROID_ALLOC_INTERFACE_H 352