gralloc.h revision 22423852817b19245a2134653eef3f71a39cf42a
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 2133c0fe022e166007547d9c7390e7e6dbba5122e7Iliyan Malchev#include <system/window.h> 2206e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray#include <system/graphics.h> 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 295337b102898cfd48eda7215df15baaf3bc96521fMathias Agopian#include <cutils/native_handle.h> 305337b102898cfd48eda7215df15baaf3bc96521fMathias Agopian 315337b102898cfd48eda7215df15baaf3bc96521fMathias Agopian#include <hardware/hardware.h> 325337b102898cfd48eda7215df15baaf3bc96521fMathias Agopian#include <hardware/fb.h> 335337b102898cfd48eda7215df15baaf3bc96521fMathias Agopian 34a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian__BEGIN_DECLS 35a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 3606e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray/** 3706e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray * Module versioning information for the Gralloc hardware module, based on 3806e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray * gralloc_module_t.common.module_api_version. 3906e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray * 4006e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray * Version History: 4106e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray * 4206e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray * GRALLOC_MODULE_API_VERSION_0_1: 4306e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray * Initial Gralloc hardware module API. 4406e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray * 4506e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray * GRALLOC_MODULE_API_VERSION_0_2: 4606e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray * Add support for flexible YCbCr format with (*lock_ycbcr)() method. 4706e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray */ 4806e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray 4906e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray#define GRALLOC_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1) 5006e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray#define GRALLOC_MODULE_API_VERSION_0_2 HARDWARE_MODULE_API_VERSION(0, 2) 5106e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray 5206e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray#define GRALLOC_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION(0, 1) 53e99520400f228e45b1feff28eb4105b8e5599196Erik Gilling 54a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/** 55a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * The id of this module 56a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 57a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#define GRALLOC_HARDWARE_MODULE_ID "gralloc" 58a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 59a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/** 60a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Name of the graphics device to open 61a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 62a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 63a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#define GRALLOC_HARDWARE_GPU0 "gpu0" 64a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 65a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopianenum { 66a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* buffer is never read in software */ 6729ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis GRALLOC_USAGE_SW_READ_NEVER = 0x00000000, 68a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* buffer is rarely read in software */ 6929ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis GRALLOC_USAGE_SW_READ_RARELY = 0x00000002, 70a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* buffer is often read in software */ 7129ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis GRALLOC_USAGE_SW_READ_OFTEN = 0x00000003, 72a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* mask for the software read values */ 7329ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis GRALLOC_USAGE_SW_READ_MASK = 0x0000000F, 74a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 75a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* buffer is never written in software */ 7629ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis GRALLOC_USAGE_SW_WRITE_NEVER = 0x00000000, 77d6f7aad8de5d122d4189ecc608c749a63de4983dGreg Hackmann /* buffer is rarely written in software */ 7829ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis GRALLOC_USAGE_SW_WRITE_RARELY = 0x00000020, 79d6f7aad8de5d122d4189ecc608c749a63de4983dGreg Hackmann /* buffer is often written in software */ 8029ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis GRALLOC_USAGE_SW_WRITE_OFTEN = 0x00000030, 81a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* mask for the software write values */ 8229ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis GRALLOC_USAGE_SW_WRITE_MASK = 0x000000F0, 83a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 84a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* buffer will be used as an OpenGL ES texture */ 8529ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis GRALLOC_USAGE_HW_TEXTURE = 0x00000100, 86a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* buffer will be used as an OpenGL ES render target */ 8729ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis GRALLOC_USAGE_HW_RENDER = 0x00000200, 88a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* buffer will be used by the 2D hardware blitter */ 8929ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis GRALLOC_USAGE_HW_2D = 0x00000400, 904b560d5563ee4699cd24938c2f13b4a416408273Jamie Gennis /* buffer will be used by the HWComposer HAL module */ 9129ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis GRALLOC_USAGE_HW_COMPOSER = 0x00000800, 92a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* buffer will be used with the framebuffer device */ 9329ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis GRALLOC_USAGE_HW_FB = 0x00001000, 9429ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis /* buffer will be used with the HW video encoder */ 9529ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis GRALLOC_USAGE_HW_VIDEO_ENCODER = 0x00010000, 967797d75b12a90cd03a47642c59dbb677aa4daa88Eino-Ville Talvala /* buffer will be written by the HW camera pipeline */ 977797d75b12a90cd03a47642c59dbb677aa4daa88Eino-Ville Talvala GRALLOC_USAGE_HW_CAMERA_WRITE = 0x00020000, 987797d75b12a90cd03a47642c59dbb677aa4daa88Eino-Ville Talvala /* buffer will be read by the HW camera pipeline */ 997797d75b12a90cd03a47642c59dbb677aa4daa88Eino-Ville Talvala GRALLOC_USAGE_HW_CAMERA_READ = 0x00040000, 1002388a2dc91979364d96e49456b189f904f0267f3Eino-Ville Talvala /* buffer will be used as part of zero-shutter-lag queue */ 1017f8dd0ad2d3d40b57c8359971a351fd194668613Eino-Ville Talvala GRALLOC_USAGE_HW_CAMERA_ZSL = 0x00060000, 1027f8dd0ad2d3d40b57c8359971a351fd194668613Eino-Ville Talvala /* mask for the camera access values */ 1037f8dd0ad2d3d40b57c8359971a351fd194668613Eino-Ville Talvala GRALLOC_USAGE_HW_CAMERA_MASK = 0x00060000, 104a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* mask for the software usage bit-mask */ 1057797d75b12a90cd03a47642c59dbb677aa4daa88Eino-Ville Talvala GRALLOC_USAGE_HW_MASK = 0x00071F00, 10695d78bef32edd183fb8c16b7775bf0a069948420Jamie Gennis 10722423852817b19245a2134653eef3f71a39cf42aJason Sams /* buffer will be used as a RenderScript Allocation */ 10822423852817b19245a2134653eef3f71a39cf42aJason Sams GRALLOC_USAGE_RENDERSCRIPT = 0x00100000, 10922423852817b19245a2134653eef3f71a39cf42aJason Sams 1107edeaf91a8d066e6797f875451f8aa9e9a4682f6Jamie Gennis /* buffer should be displayed full-screen on an external display when 1117edeaf91a8d066e6797f875451f8aa9e9a4682f6Jamie Gennis * possible 1127edeaf91a8d066e6797f875451f8aa9e9a4682f6Jamie Gennis */ 11329ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis GRALLOC_USAGE_EXTERNAL_DISP = 0x00002000, 1147edeaf91a8d066e6797f875451f8aa9e9a4682f6Jamie Gennis 1157cb277a5c26447df01196bb19650235603062e93Glenn Kasten /* Must have a hardware-protected path to external display sink for 1167cb277a5c26447df01196bb19650235603062e93Glenn Kasten * this buffer. If a hardware-protected path is not available, then 1177cb277a5c26447df01196bb19650235603062e93Glenn Kasten * either don't composite only this buffer (preferred) to the 1187cb277a5c26447df01196bb19650235603062e93Glenn Kasten * external sink, or (less desirable) do not route the entire 1197cb277a5c26447df01196bb19650235603062e93Glenn Kasten * composition to the external sink. 1207cb277a5c26447df01196bb19650235603062e93Glenn Kasten */ 12129ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis GRALLOC_USAGE_PROTECTED = 0x00004000, 1227cb277a5c26447df01196bb19650235603062e93Glenn Kasten 12395d78bef32edd183fb8c16b7775bf0a069948420Jamie Gennis /* implementation-specific private usage flags */ 12429ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis GRALLOC_USAGE_PRIVATE_0 = 0x10000000, 12529ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis GRALLOC_USAGE_PRIVATE_1 = 0x20000000, 12629ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis GRALLOC_USAGE_PRIVATE_2 = 0x40000000, 12729ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis GRALLOC_USAGE_PRIVATE_3 = 0x80000000, 12829ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis GRALLOC_USAGE_PRIVATE_MASK = 0xF0000000, 129a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian}; 130a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 131a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/*****************************************************************************/ 132a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 133a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/** 134a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM 135a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * and the fields of this data structure must begin with hw_module_t 136a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * followed by module specific information. 137a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 1389d82c1a447a72a2c086b9cd34c5b73b163d7acbcMathias Agopiantypedef struct gralloc_module_t { 139a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian struct hw_module_t common; 140a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 141988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian /* 142988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * (*registerBuffer)() must be called before a buffer_handle_t that has not 143988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * been created with (*alloc_device_t::alloc)() can be used. 144988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * 145988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * This is intended to be used with buffer_handle_t's that have been 146988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * received in this process through IPC. 147988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * 148988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * This function checks that the handle is indeed a valid one and prepares 149988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * it for use with (*lock)() and (*unlock)(). 150988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * 151988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * It is not necessary to call (*registerBuffer)() on a handle created 152988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * with (*alloc_device_t::alloc)(). 153a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * 154988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * returns an error if this buffer_handle_t is not valid. 155a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 156988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian int (*registerBuffer)(struct gralloc_module_t const* module, 157988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian buffer_handle_t handle); 158a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 159a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* 160988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * (*unregisterBuffer)() is called once this handle is no longer needed in 161988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * this process. After this call, it is an error to call (*lock)(), 162988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * (*unlock)(), or (*registerBuffer)(). 163988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * 164988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * This function doesn't close or free the handle itself; this is done 165988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * by other means, usually through libcutils's native_handle_close() and 166988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * native_handle_free(). 167a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * 168988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * It is an error to call (*unregisterBuffer)() on a buffer that wasn't 169988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * explicitly registered first. 170a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 171988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian int (*unregisterBuffer)(struct gralloc_module_t const* module, 172988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian buffer_handle_t handle); 173a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 174a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* 175a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * The (*lock)() method is called before a buffer is accessed for the 176a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * specified usage. This call may block, for instance if the h/w needs 177a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * to finish rendering or if CPU caches need to be synchronized. 178a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * 179988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * The caller promises to modify only pixels in the area specified 180988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * by (l,t,w,h). 181a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * 182a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * The content of the buffer outside of the specified area is NOT modified 183a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * by this call. 184988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * 185988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * If usage specifies GRALLOC_USAGE_SW_*, vaddr is filled with the address 186988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * of the buffer in virtual memory. 187988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * 18806e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray * Note calling (*lock)() on HAL_PIXEL_FORMAT_YCbCr_*_888 buffers will fail 18906e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray * and return -EINVAL. These buffers must be locked with (*lock_ycbcr)() 19006e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray * instead. 19106e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray * 192485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * THREADING CONSIDERATIONS: 193485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * 194485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * It is legal for several different threads to lock a buffer from 195485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * read access, none of the threads are blocked. 196485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * 197485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * However, locking a buffer simultaneously for write or read/write is 198485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * undefined, but: 199485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * - shall not result in termination of the process 200485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * - shall not block the caller 201485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * It is acceptable to return an error or to leave the buffer's content 202485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * into an indeterminate state. 203485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian * 204988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * If the buffer was created with a usage mask incompatible with the 205988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian * requested usage flags here, -EINVAL is returned. 206a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * 207a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 208a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 209a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian int (*lock)(struct gralloc_module_t const* module, 210a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian buffer_handle_t handle, int usage, 211988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian int l, int t, int w, int h, 212988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian void** vaddr); 213a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 214a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 215a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* 216a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * The (*unlock)() method must be called after all changes to the buffer 217a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * are completed. 218a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 219a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 220a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian int (*unlock)(struct gralloc_module_t const* module, 221a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian buffer_handle_t handle); 222a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 223cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian 224cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian /* reserved for future use */ 225cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian int (*perform)(struct gralloc_module_t const* module, 226cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian int operation, ... ); 227cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian 22806e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray /* 22906e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray * The (*lock_ycbcr)() method is like the (*lock)() method, with the 23006e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray * difference that it fills a struct ycbcr with a description of the buffer 23106e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray * layout, and zeroes out the reserved fields. 23206e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray * 23306e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray * This will only work on buffers with HAL_PIXEL_FORMAT_YCbCr_*_888, and 23406e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray * will return -EINVAL on any other buffer formats. 23506e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray * 23606e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray * Added in GRALLOC_MODULE_API_VERSION_0_2. 23706e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray */ 23806e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray 23906e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray int (*lock_ycbcr)(struct gralloc_module_t const* module, 24006e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray buffer_handle_t handle, int usage, 24106e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray int l, int t, int w, int h, 24206e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray struct android_ycbcr *ycbcr); 24306e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray 2448255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian /* reserved for future use */ 24506e3bf25660a25b417e7a2e146327b35bee5ba00Alex Ray void* reserved_proc[6]; 2469d82c1a447a72a2c086b9cd34c5b73b163d7acbcMathias Agopian} gralloc_module_t; 247a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 248a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/*****************************************************************************/ 249a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 250a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/** 251a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Every device data structure must begin with hw_device_t 252a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * followed by module specific public methods and attributes. 253a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 254a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 2559d82c1a447a72a2c086b9cd34c5b73b163d7acbcMathias Agopiantypedef struct alloc_device_t { 256a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian struct hw_device_t common; 257a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 258a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* 259a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * (*alloc)() Allocates a buffer in graphic memory with the requested 260a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * parameters and returns a buffer_handle_t and the stride in pixels to 261a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * allow the implementation to satisfy hardware constraints on the width 262a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * of a pixmap (eg: it may have to be multiple of 8 pixels). 263a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * The CALLER TAKES OWNERSHIP of the buffer_handle_t. 2646efab252d59ceff806840111b2e6c0e478d377aeEino-Ville Talvala * 2656efab252d59ceff806840111b2e6c0e478d377aeEino-Ville Talvala * If format is HAL_PIXEL_FORMAT_YCbCr_420_888, the returned stride must be 2666efab252d59ceff806840111b2e6c0e478d377aeEino-Ville Talvala * 0, since the actual strides are available from the android_ycbcr 2676efab252d59ceff806840111b2e6c0e478d377aeEino-Ville Talvala * structure. 268a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * 269a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Returns 0 on success or -errno on error. 270a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 271a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 272a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian int (*alloc)(struct alloc_device_t* dev, 273a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian int w, int h, int format, int usage, 274a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian buffer_handle_t* handle, int* stride); 275a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 276a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian /* 277a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * (*free)() Frees a previously allocated buffer. 278a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Behavior is undefined if the buffer is still mapped in any process, 279a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * but shall not result in termination of the program or security breaches 280a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * (allowing a process to get access to another process' buffers). 281a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * THIS FUNCTION TAKES OWNERSHIP of the buffer_handle_t which becomes 282a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * invalid after the call. 283a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * 284a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Returns 0 on success or -errno on error. 285a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */ 286a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian int (*free)(struct alloc_device_t* dev, 287a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian buffer_handle_t handle); 288a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 289158549c89405186d9ecaefd3811cfae3949056eeErik Gilling /* This hook is OPTIONAL. 290158549c89405186d9ecaefd3811cfae3949056eeErik Gilling * 291158549c89405186d9ecaefd3811cfae3949056eeErik Gilling * If non NULL it will be caused by SurfaceFlinger on dumpsys 292158549c89405186d9ecaefd3811cfae3949056eeErik Gilling */ 293158549c89405186d9ecaefd3811cfae3949056eeErik Gilling void (*dump)(struct alloc_device_t *dev, char *buff, int buff_len); 294158549c89405186d9ecaefd3811cfae3949056eeErik Gilling 295158549c89405186d9ecaefd3811cfae3949056eeErik Gilling void* reserved_proc[7]; 2969d82c1a447a72a2c086b9cd34c5b73b163d7acbcMathias Agopian} alloc_device_t; 297a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 298a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 299a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/** convenience API for opening and closing a supported device */ 300a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 301a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopianstatic inline int gralloc_open(const struct hw_module_t* module, 302a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian struct alloc_device_t** device) { 303a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian return module->methods->open(module, 304a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian GRALLOC_HARDWARE_GPU0, (struct hw_device_t**)device); 305a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian} 306a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 307a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopianstatic inline int gralloc_close(struct alloc_device_t* device) { 308a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian return device->common.close(&device->common); 309a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian} 310a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 311a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian__END_DECLS 312a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian 313bb56a1007d80ef8165493395ac8c9b0bf05a435fGlenn Kasten#endif // ANDROID_GRALLOC_INTERFACE_H 314