1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (C) 2008 The Android Open Source Project 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 5bf215546Sopenharmony_ci * you may not use this file except in compliance with the License. 6bf215546Sopenharmony_ci * You may obtain a copy of the License at 7bf215546Sopenharmony_ci * 8bf215546Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 9bf215546Sopenharmony_ci * 10bf215546Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 11bf215546Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 12bf215546Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13bf215546Sopenharmony_ci * See the License for the specific language governing permissions and 14bf215546Sopenharmony_ci * limitations under the License. 15bf215546Sopenharmony_ci */ 16bf215546Sopenharmony_ci 17bf215546Sopenharmony_ci 18bf215546Sopenharmony_ci#ifndef ANDROID_GRALLOC_INTERFACE_H 19bf215546Sopenharmony_ci#define ANDROID_GRALLOC_INTERFACE_H 20bf215546Sopenharmony_ci 21bf215546Sopenharmony_ci#include <system/graphics.h> 22bf215546Sopenharmony_ci#include <hardware/hardware.h> 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_ci#include <stdint.h> 25bf215546Sopenharmony_ci#include <sys/cdefs.h> 26bf215546Sopenharmony_ci#include <sys/types.h> 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#include <cutils/native_handle.h> 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci#include <hardware/hardware.h> 31bf215546Sopenharmony_ci#include <hardware/fb.h> 32bf215546Sopenharmony_ci 33bf215546Sopenharmony_ci__BEGIN_DECLS 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_ci/** 36bf215546Sopenharmony_ci * Module versioning information for the Gralloc hardware module, based on 37bf215546Sopenharmony_ci * gralloc_module_t.common.module_api_version. 38bf215546Sopenharmony_ci * 39bf215546Sopenharmony_ci * Version History: 40bf215546Sopenharmony_ci * 41bf215546Sopenharmony_ci * GRALLOC_MODULE_API_VERSION_0_1: 42bf215546Sopenharmony_ci * Initial Gralloc hardware module API. 43bf215546Sopenharmony_ci * 44bf215546Sopenharmony_ci * GRALLOC_MODULE_API_VERSION_0_2: 45bf215546Sopenharmony_ci * Add support for flexible YCbCr format with (*lock_ycbcr)() method. 46bf215546Sopenharmony_ci * 47bf215546Sopenharmony_ci * GRALLOC_MODULE_API_VERSION_0_3: 48bf215546Sopenharmony_ci * Add support for fence passing to/from lock/unlock. 49bf215546Sopenharmony_ci */ 50bf215546Sopenharmony_ci 51bf215546Sopenharmony_ci#define GRALLOC_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1) 52bf215546Sopenharmony_ci#define GRALLOC_MODULE_API_VERSION_0_2 HARDWARE_MODULE_API_VERSION(0, 2) 53bf215546Sopenharmony_ci#define GRALLOC_MODULE_API_VERSION_0_3 HARDWARE_MODULE_API_VERSION(0, 3) 54bf215546Sopenharmony_ci 55bf215546Sopenharmony_ci#define GRALLOC_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION(0, 1) 56bf215546Sopenharmony_ci 57bf215546Sopenharmony_ci/** 58bf215546Sopenharmony_ci * The id of this module 59bf215546Sopenharmony_ci */ 60bf215546Sopenharmony_ci#define GRALLOC_HARDWARE_MODULE_ID "gralloc" 61bf215546Sopenharmony_ci 62bf215546Sopenharmony_ci/** 63bf215546Sopenharmony_ci * Name of the graphics device to open 64bf215546Sopenharmony_ci */ 65bf215546Sopenharmony_ci 66bf215546Sopenharmony_ci#define GRALLOC_HARDWARE_GPU0 "gpu0" 67bf215546Sopenharmony_ci 68bf215546Sopenharmony_cienum { 69bf215546Sopenharmony_ci /* buffer is never read in software */ 70bf215546Sopenharmony_ci GRALLOC_USAGE_SW_READ_NEVER = 0x00000000U, 71bf215546Sopenharmony_ci /* buffer is rarely read in software */ 72bf215546Sopenharmony_ci GRALLOC_USAGE_SW_READ_RARELY = 0x00000002U, 73bf215546Sopenharmony_ci /* buffer is often read in software */ 74bf215546Sopenharmony_ci GRALLOC_USAGE_SW_READ_OFTEN = 0x00000003U, 75bf215546Sopenharmony_ci /* mask for the software read values */ 76bf215546Sopenharmony_ci GRALLOC_USAGE_SW_READ_MASK = 0x0000000FU, 77bf215546Sopenharmony_ci 78bf215546Sopenharmony_ci /* buffer is never written in software */ 79bf215546Sopenharmony_ci GRALLOC_USAGE_SW_WRITE_NEVER = 0x00000000U, 80bf215546Sopenharmony_ci /* buffer is rarely written in software */ 81bf215546Sopenharmony_ci GRALLOC_USAGE_SW_WRITE_RARELY = 0x00000020U, 82bf215546Sopenharmony_ci /* buffer is often written in software */ 83bf215546Sopenharmony_ci GRALLOC_USAGE_SW_WRITE_OFTEN = 0x00000030U, 84bf215546Sopenharmony_ci /* mask for the software write values */ 85bf215546Sopenharmony_ci GRALLOC_USAGE_SW_WRITE_MASK = 0x000000F0U, 86bf215546Sopenharmony_ci 87bf215546Sopenharmony_ci /* buffer will be used as an OpenGL ES texture */ 88bf215546Sopenharmony_ci GRALLOC_USAGE_HW_TEXTURE = 0x00000100U, 89bf215546Sopenharmony_ci /* buffer will be used as an OpenGL ES render target */ 90bf215546Sopenharmony_ci GRALLOC_USAGE_HW_RENDER = 0x00000200U, 91bf215546Sopenharmony_ci /* buffer will be used by the 2D hardware blitter */ 92bf215546Sopenharmony_ci GRALLOC_USAGE_HW_2D = 0x00000400U, 93bf215546Sopenharmony_ci /* buffer will be used by the HWComposer HAL module */ 94bf215546Sopenharmony_ci GRALLOC_USAGE_HW_COMPOSER = 0x00000800U, 95bf215546Sopenharmony_ci /* buffer will be used with the framebuffer device */ 96bf215546Sopenharmony_ci GRALLOC_USAGE_HW_FB = 0x00001000U, 97bf215546Sopenharmony_ci 98bf215546Sopenharmony_ci /* buffer should be displayed full-screen on an external display when 99bf215546Sopenharmony_ci * possible */ 100bf215546Sopenharmony_ci GRALLOC_USAGE_EXTERNAL_DISP = 0x00002000U, 101bf215546Sopenharmony_ci 102bf215546Sopenharmony_ci /* Must have a hardware-protected path to external display sink for 103bf215546Sopenharmony_ci * this buffer. If a hardware-protected path is not available, then 104bf215546Sopenharmony_ci * either don't composite only this buffer (preferred) to the 105bf215546Sopenharmony_ci * external sink, or (less desirable) do not route the entire 106bf215546Sopenharmony_ci * composition to the external sink. */ 107bf215546Sopenharmony_ci GRALLOC_USAGE_PROTECTED = 0x00004000U, 108bf215546Sopenharmony_ci 109bf215546Sopenharmony_ci /* buffer may be used as a cursor */ 110bf215546Sopenharmony_ci GRALLOC_USAGE_CURSOR = 0x00008000U, 111bf215546Sopenharmony_ci 112bf215546Sopenharmony_ci /* buffer will be used with the HW video encoder */ 113bf215546Sopenharmony_ci GRALLOC_USAGE_HW_VIDEO_ENCODER = 0x00010000U, 114bf215546Sopenharmony_ci /* buffer will be written by the HW camera pipeline */ 115bf215546Sopenharmony_ci GRALLOC_USAGE_HW_CAMERA_WRITE = 0x00020000U, 116bf215546Sopenharmony_ci /* buffer will be read by the HW camera pipeline */ 117bf215546Sopenharmony_ci GRALLOC_USAGE_HW_CAMERA_READ = 0x00040000U, 118bf215546Sopenharmony_ci /* buffer will be used as part of zero-shutter-lag queue */ 119bf215546Sopenharmony_ci GRALLOC_USAGE_HW_CAMERA_ZSL = 0x00060000U, 120bf215546Sopenharmony_ci /* mask for the camera access values */ 121bf215546Sopenharmony_ci GRALLOC_USAGE_HW_CAMERA_MASK = 0x00060000U, 122bf215546Sopenharmony_ci /* mask for the software usage bit-mask */ 123bf215546Sopenharmony_ci GRALLOC_USAGE_HW_MASK = 0x00071F00U, 124bf215546Sopenharmony_ci 125bf215546Sopenharmony_ci /* buffer will be used as a RenderScript Allocation */ 126bf215546Sopenharmony_ci GRALLOC_USAGE_RENDERSCRIPT = 0x00100000U, 127bf215546Sopenharmony_ci 128bf215546Sopenharmony_ci /* Set by the consumer to indicate to the producer that they may attach a 129bf215546Sopenharmony_ci * buffer that they did not detach from the BufferQueue. Will be filtered 130bf215546Sopenharmony_ci * out by GRALLOC_USAGE_ALLOC_MASK, so gralloc modules will not need to 131bf215546Sopenharmony_ci * handle this flag. */ 132bf215546Sopenharmony_ci GRALLOC_USAGE_FOREIGN_BUFFERS = 0x00200000U, 133bf215546Sopenharmony_ci 134bf215546Sopenharmony_ci /* buffer will be used as input to HW HEIC image encoder */ 135bf215546Sopenharmony_ci GRALLOC_USAGE_HW_IMAGE_ENCODER = 0x08000000U, 136bf215546Sopenharmony_ci 137bf215546Sopenharmony_ci /* Mask of all flags which could be passed to a gralloc module for buffer 138bf215546Sopenharmony_ci * allocation. Any flags not in this mask do not need to be handled by 139bf215546Sopenharmony_ci * gralloc modules. */ 140bf215546Sopenharmony_ci GRALLOC_USAGE_ALLOC_MASK = ~(GRALLOC_USAGE_FOREIGN_BUFFERS), 141bf215546Sopenharmony_ci 142bf215546Sopenharmony_ci /* implementation-specific private usage flags */ 143bf215546Sopenharmony_ci GRALLOC_USAGE_PRIVATE_0 = 0x10000000U, 144bf215546Sopenharmony_ci GRALLOC_USAGE_PRIVATE_1 = 0x20000000U, 145bf215546Sopenharmony_ci GRALLOC_USAGE_PRIVATE_2 = 0x40000000U, 146bf215546Sopenharmony_ci GRALLOC_USAGE_PRIVATE_3 = 0x80000000U, 147bf215546Sopenharmony_ci GRALLOC_USAGE_PRIVATE_MASK = 0xF0000000U, 148bf215546Sopenharmony_ci}; 149bf215546Sopenharmony_ci 150bf215546Sopenharmony_ci/*****************************************************************************/ 151bf215546Sopenharmony_ci 152bf215546Sopenharmony_ci/** 153bf215546Sopenharmony_ci * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM 154bf215546Sopenharmony_ci * and the fields of this data structure must begin with hw_module_t 155bf215546Sopenharmony_ci * followed by module specific information. 156bf215546Sopenharmony_ci */ 157bf215546Sopenharmony_citypedef struct gralloc_module_t { 158bf215546Sopenharmony_ci struct hw_module_t common; 159bf215546Sopenharmony_ci 160bf215546Sopenharmony_ci /* 161bf215546Sopenharmony_ci * (*registerBuffer)() must be called before a buffer_handle_t that has not 162bf215546Sopenharmony_ci * been created with (*alloc_device_t::alloc)() can be used. 163bf215546Sopenharmony_ci * 164bf215546Sopenharmony_ci * This is intended to be used with buffer_handle_t's that have been 165bf215546Sopenharmony_ci * received in this process through IPC. 166bf215546Sopenharmony_ci * 167bf215546Sopenharmony_ci * This function checks that the handle is indeed a valid one and prepares 168bf215546Sopenharmony_ci * it for use with (*lock)() and (*unlock)(). 169bf215546Sopenharmony_ci * 170bf215546Sopenharmony_ci * It is not necessary to call (*registerBuffer)() on a handle created 171bf215546Sopenharmony_ci * with (*alloc_device_t::alloc)(). 172bf215546Sopenharmony_ci * 173bf215546Sopenharmony_ci * returns an error if this buffer_handle_t is not valid. 174bf215546Sopenharmony_ci */ 175bf215546Sopenharmony_ci int (*registerBuffer)(struct gralloc_module_t const* module, 176bf215546Sopenharmony_ci buffer_handle_t handle); 177bf215546Sopenharmony_ci 178bf215546Sopenharmony_ci /* 179bf215546Sopenharmony_ci * (*unregisterBuffer)() is called once this handle is no longer needed in 180bf215546Sopenharmony_ci * this process. After this call, it is an error to call (*lock)(), 181bf215546Sopenharmony_ci * (*unlock)(), or (*registerBuffer)(). 182bf215546Sopenharmony_ci * 183bf215546Sopenharmony_ci * This function doesn't close or free the handle itself; this is done 184bf215546Sopenharmony_ci * by other means, usually through libcutils's native_handle_close() and 185bf215546Sopenharmony_ci * native_handle_free(). 186bf215546Sopenharmony_ci * 187bf215546Sopenharmony_ci * It is an error to call (*unregisterBuffer)() on a buffer that wasn't 188bf215546Sopenharmony_ci * explicitly registered first. 189bf215546Sopenharmony_ci */ 190bf215546Sopenharmony_ci int (*unregisterBuffer)(struct gralloc_module_t const* module, 191bf215546Sopenharmony_ci buffer_handle_t handle); 192bf215546Sopenharmony_ci 193bf215546Sopenharmony_ci /* 194bf215546Sopenharmony_ci * The (*lock)() method is called before a buffer is accessed for the 195bf215546Sopenharmony_ci * specified usage. This call may block, for instance if the h/w needs 196bf215546Sopenharmony_ci * to finish rendering or if CPU caches need to be synchronized. 197bf215546Sopenharmony_ci * 198bf215546Sopenharmony_ci * The caller promises to modify only pixels in the area specified 199bf215546Sopenharmony_ci * by (l,t,w,h). 200bf215546Sopenharmony_ci * 201bf215546Sopenharmony_ci * The content of the buffer outside of the specified area is NOT modified 202bf215546Sopenharmony_ci * by this call. 203bf215546Sopenharmony_ci * 204bf215546Sopenharmony_ci * If usage specifies GRALLOC_USAGE_SW_*, vaddr is filled with the address 205bf215546Sopenharmony_ci * of the buffer in virtual memory. 206bf215546Sopenharmony_ci * 207bf215546Sopenharmony_ci * Note calling (*lock)() on HAL_PIXEL_FORMAT_YCbCr_*_888 buffers will fail 208bf215546Sopenharmony_ci * and return -EINVAL. These buffers must be locked with (*lock_ycbcr)() 209bf215546Sopenharmony_ci * instead. 210bf215546Sopenharmony_ci * 211bf215546Sopenharmony_ci * THREADING CONSIDERATIONS: 212bf215546Sopenharmony_ci * 213bf215546Sopenharmony_ci * It is legal for several different threads to lock a buffer from 214bf215546Sopenharmony_ci * read access, none of the threads are blocked. 215bf215546Sopenharmony_ci * 216bf215546Sopenharmony_ci * However, locking a buffer simultaneously for write or read/write is 217bf215546Sopenharmony_ci * undefined, but: 218bf215546Sopenharmony_ci * - shall not result in termination of the process 219bf215546Sopenharmony_ci * - shall not block the caller 220bf215546Sopenharmony_ci * It is acceptable to return an error or to leave the buffer's content 221bf215546Sopenharmony_ci * into an indeterminate state. 222bf215546Sopenharmony_ci * 223bf215546Sopenharmony_ci * If the buffer was created with a usage mask incompatible with the 224bf215546Sopenharmony_ci * requested usage flags here, -EINVAL is returned. 225bf215546Sopenharmony_ci * 226bf215546Sopenharmony_ci */ 227bf215546Sopenharmony_ci 228bf215546Sopenharmony_ci int (*lock)(struct gralloc_module_t const* module, 229bf215546Sopenharmony_ci buffer_handle_t handle, int usage, 230bf215546Sopenharmony_ci int l, int t, int w, int h, 231bf215546Sopenharmony_ci void** vaddr); 232bf215546Sopenharmony_ci 233bf215546Sopenharmony_ci 234bf215546Sopenharmony_ci /* 235bf215546Sopenharmony_ci * The (*unlock)() method must be called after all changes to the buffer 236bf215546Sopenharmony_ci * are completed. 237bf215546Sopenharmony_ci */ 238bf215546Sopenharmony_ci 239bf215546Sopenharmony_ci int (*unlock)(struct gralloc_module_t const* module, 240bf215546Sopenharmony_ci buffer_handle_t handle); 241bf215546Sopenharmony_ci 242bf215546Sopenharmony_ci 243bf215546Sopenharmony_ci /* reserved for future use */ 244bf215546Sopenharmony_ci int (*perform)(struct gralloc_module_t const* module, 245bf215546Sopenharmony_ci int operation, ... ); 246bf215546Sopenharmony_ci 247bf215546Sopenharmony_ci /* 248bf215546Sopenharmony_ci * The (*lock_ycbcr)() method is like the (*lock)() method, with the 249bf215546Sopenharmony_ci * difference that it fills a struct ycbcr with a description of the buffer 250bf215546Sopenharmony_ci * layout, and zeroes out the reserved fields. 251bf215546Sopenharmony_ci * 252bf215546Sopenharmony_ci * If the buffer format is not compatible with a flexible YUV format (e.g. 253bf215546Sopenharmony_ci * the buffer layout cannot be represented with the ycbcr struct), it 254bf215546Sopenharmony_ci * will return -EINVAL. 255bf215546Sopenharmony_ci * 256bf215546Sopenharmony_ci * This method must work on buffers with HAL_PIXEL_FORMAT_YCbCr_*_888 257bf215546Sopenharmony_ci * if supported by the device, as well as with any other format that is 258bf215546Sopenharmony_ci * requested by the multimedia codecs when they are configured with a 259bf215546Sopenharmony_ci * flexible-YUV-compatible color-format with android native buffers. 260bf215546Sopenharmony_ci * 261bf215546Sopenharmony_ci * Note that this method may also be called on buffers of other formats, 262bf215546Sopenharmony_ci * including non-YUV formats. 263bf215546Sopenharmony_ci * 264bf215546Sopenharmony_ci * Added in GRALLOC_MODULE_API_VERSION_0_2. 265bf215546Sopenharmony_ci */ 266bf215546Sopenharmony_ci 267bf215546Sopenharmony_ci int (*lock_ycbcr)(struct gralloc_module_t const* module, 268bf215546Sopenharmony_ci buffer_handle_t handle, int usage, 269bf215546Sopenharmony_ci int l, int t, int w, int h, 270bf215546Sopenharmony_ci struct android_ycbcr *ycbcr); 271bf215546Sopenharmony_ci 272bf215546Sopenharmony_ci /* 273bf215546Sopenharmony_ci * The (*lockAsync)() method is like the (*lock)() method except 274bf215546Sopenharmony_ci * that the buffer's sync fence object is passed into the lock 275bf215546Sopenharmony_ci * call instead of requiring the caller to wait for completion. 276bf215546Sopenharmony_ci * 277bf215546Sopenharmony_ci * The gralloc implementation takes ownership of the fenceFd and 278bf215546Sopenharmony_ci * is responsible for closing it when no longer needed. 279bf215546Sopenharmony_ci * 280bf215546Sopenharmony_ci * Added in GRALLOC_MODULE_API_VERSION_0_3. 281bf215546Sopenharmony_ci */ 282bf215546Sopenharmony_ci int (*lockAsync)(struct gralloc_module_t const* module, 283bf215546Sopenharmony_ci buffer_handle_t handle, int usage, 284bf215546Sopenharmony_ci int l, int t, int w, int h, 285bf215546Sopenharmony_ci void** vaddr, int fenceFd); 286bf215546Sopenharmony_ci 287bf215546Sopenharmony_ci /* 288bf215546Sopenharmony_ci * The (*unlockAsync)() method is like the (*unlock)() method 289bf215546Sopenharmony_ci * except that a buffer sync fence object is returned from the 290bf215546Sopenharmony_ci * lock call, representing the completion of any pending work 291bf215546Sopenharmony_ci * performed by the gralloc implementation. 292bf215546Sopenharmony_ci * 293bf215546Sopenharmony_ci * The caller takes ownership of the fenceFd and is responsible 294bf215546Sopenharmony_ci * for closing it when no longer needed. 295bf215546Sopenharmony_ci * 296bf215546Sopenharmony_ci * Added in GRALLOC_MODULE_API_VERSION_0_3. 297bf215546Sopenharmony_ci */ 298bf215546Sopenharmony_ci int (*unlockAsync)(struct gralloc_module_t const* module, 299bf215546Sopenharmony_ci buffer_handle_t handle, int* fenceFd); 300bf215546Sopenharmony_ci 301bf215546Sopenharmony_ci /* 302bf215546Sopenharmony_ci * The (*lockAsync_ycbcr)() method is like the (*lock_ycbcr)() 303bf215546Sopenharmony_ci * method except that the buffer's sync fence object is passed 304bf215546Sopenharmony_ci * into the lock call instead of requiring the caller to wait for 305bf215546Sopenharmony_ci * completion. 306bf215546Sopenharmony_ci * 307bf215546Sopenharmony_ci * The gralloc implementation takes ownership of the fenceFd and 308bf215546Sopenharmony_ci * is responsible for closing it when no longer needed. 309bf215546Sopenharmony_ci * 310bf215546Sopenharmony_ci * Added in GRALLOC_MODULE_API_VERSION_0_3. 311bf215546Sopenharmony_ci */ 312bf215546Sopenharmony_ci int (*lockAsync_ycbcr)(struct gralloc_module_t const* module, 313bf215546Sopenharmony_ci buffer_handle_t handle, int usage, 314bf215546Sopenharmony_ci int l, int t, int w, int h, 315bf215546Sopenharmony_ci struct android_ycbcr *ycbcr, int fenceFd); 316bf215546Sopenharmony_ci 317bf215546Sopenharmony_ci /* getTransportSize(..., outNumFds, outNumInts) 318bf215546Sopenharmony_ci * This function is mandatory on devices running IMapper2.1 or higher. 319bf215546Sopenharmony_ci * 320bf215546Sopenharmony_ci * Get the transport size of a buffer. An imported buffer handle is a raw 321bf215546Sopenharmony_ci * buffer handle with the process-local runtime data appended. This 322bf215546Sopenharmony_ci * function, for example, allows a caller to omit the process-local 323bf215546Sopenharmony_ci * runtime data at the tail when serializing the imported buffer handle. 324bf215546Sopenharmony_ci * 325bf215546Sopenharmony_ci * Note that a client might or might not omit the process-local runtime 326bf215546Sopenharmony_ci * data when sending an imported buffer handle. The mapper must support 327bf215546Sopenharmony_ci * both cases on the receiving end. 328bf215546Sopenharmony_ci */ 329bf215546Sopenharmony_ci int32_t (*getTransportSize)( 330bf215546Sopenharmony_ci struct gralloc_module_t const* module, buffer_handle_t handle, uint32_t *outNumFds, 331bf215546Sopenharmony_ci uint32_t *outNumInts); 332bf215546Sopenharmony_ci 333bf215546Sopenharmony_ci /* validateBufferSize(..., w, h, format, usage, stride) 334bf215546Sopenharmony_ci * This function is mandatory on devices running IMapper2.1 or higher. 335bf215546Sopenharmony_ci * 336bf215546Sopenharmony_ci * Validate that the buffer can be safely accessed by a caller who assumes 337bf215546Sopenharmony_ci * the specified width, height, format, usage, and stride. This must at least validate 338bf215546Sopenharmony_ci * that the buffer size is large enough. Validating the buffer against 339bf215546Sopenharmony_ci * individual buffer attributes is optional. 340bf215546Sopenharmony_ci */ 341bf215546Sopenharmony_ci int32_t (*validateBufferSize)( 342bf215546Sopenharmony_ci struct gralloc_module_t const* device, buffer_handle_t handle, 343bf215546Sopenharmony_ci uint32_t w, uint32_t h, int32_t format, int usage, 344bf215546Sopenharmony_ci uint32_t stride); 345bf215546Sopenharmony_ci 346bf215546Sopenharmony_ci /* reserved for future use */ 347bf215546Sopenharmony_ci void* reserved_proc[1]; 348bf215546Sopenharmony_ci 349bf215546Sopenharmony_ci} gralloc_module_t; 350bf215546Sopenharmony_ci 351bf215546Sopenharmony_ci/*****************************************************************************/ 352bf215546Sopenharmony_ci 353bf215546Sopenharmony_ci/** 354bf215546Sopenharmony_ci * Every device data structure must begin with hw_device_t 355bf215546Sopenharmony_ci * followed by module specific public methods and attributes. 356bf215546Sopenharmony_ci */ 357bf215546Sopenharmony_ci 358bf215546Sopenharmony_citypedef struct alloc_device_t { 359bf215546Sopenharmony_ci struct hw_device_t common; 360bf215546Sopenharmony_ci 361bf215546Sopenharmony_ci /* 362bf215546Sopenharmony_ci * (*alloc)() Allocates a buffer in graphic memory with the requested 363bf215546Sopenharmony_ci * parameters and returns a buffer_handle_t and the stride in pixels to 364bf215546Sopenharmony_ci * allow the implementation to satisfy hardware constraints on the width 365bf215546Sopenharmony_ci * of a pixmap (eg: it may have to be multiple of 8 pixels). 366bf215546Sopenharmony_ci * The CALLER TAKES OWNERSHIP of the buffer_handle_t. 367bf215546Sopenharmony_ci * 368bf215546Sopenharmony_ci * If format is HAL_PIXEL_FORMAT_YCbCr_420_888, the returned stride must be 369bf215546Sopenharmony_ci * 0, since the actual strides are available from the android_ycbcr 370bf215546Sopenharmony_ci * structure. 371bf215546Sopenharmony_ci * 372bf215546Sopenharmony_ci * Returns 0 on success or -errno on error. 373bf215546Sopenharmony_ci */ 374bf215546Sopenharmony_ci 375bf215546Sopenharmony_ci int (*alloc)(struct alloc_device_t* dev, 376bf215546Sopenharmony_ci int w, int h, int format, int usage, 377bf215546Sopenharmony_ci buffer_handle_t* handle, int* stride); 378bf215546Sopenharmony_ci 379bf215546Sopenharmony_ci /* 380bf215546Sopenharmony_ci * (*free)() Frees a previously allocated buffer. 381bf215546Sopenharmony_ci * Behavior is undefined if the buffer is still mapped in any process, 382bf215546Sopenharmony_ci * but shall not result in termination of the program or security breaches 383bf215546Sopenharmony_ci * (allowing a process to get access to another process' buffers). 384bf215546Sopenharmony_ci * THIS FUNCTION TAKES OWNERSHIP of the buffer_handle_t which becomes 385bf215546Sopenharmony_ci * invalid after the call. 386bf215546Sopenharmony_ci * 387bf215546Sopenharmony_ci * Returns 0 on success or -errno on error. 388bf215546Sopenharmony_ci */ 389bf215546Sopenharmony_ci int (*free)(struct alloc_device_t* dev, 390bf215546Sopenharmony_ci buffer_handle_t handle); 391bf215546Sopenharmony_ci 392bf215546Sopenharmony_ci /* This hook is OPTIONAL. 393bf215546Sopenharmony_ci * 394bf215546Sopenharmony_ci * If non NULL it will be caused by SurfaceFlinger on dumpsys 395bf215546Sopenharmony_ci */ 396bf215546Sopenharmony_ci void (*dump)(struct alloc_device_t *dev, char *buff, int buff_len); 397bf215546Sopenharmony_ci 398bf215546Sopenharmony_ci void* reserved_proc[7]; 399bf215546Sopenharmony_ci} alloc_device_t; 400bf215546Sopenharmony_ci 401bf215546Sopenharmony_ci 402bf215546Sopenharmony_ci/** convenience API for opening and closing a supported device */ 403bf215546Sopenharmony_ci 404bf215546Sopenharmony_cistatic inline int gralloc_open(const struct hw_module_t* module, 405bf215546Sopenharmony_ci struct alloc_device_t** device) { 406bf215546Sopenharmony_ci return module->methods->open(module, 407bf215546Sopenharmony_ci GRALLOC_HARDWARE_GPU0, TO_HW_DEVICE_T_OPEN(device)); 408bf215546Sopenharmony_ci} 409bf215546Sopenharmony_ci 410bf215546Sopenharmony_cistatic inline int gralloc_close(struct alloc_device_t* device) { 411bf215546Sopenharmony_ci return device->common.close(&device->common); 412bf215546Sopenharmony_ci} 413bf215546Sopenharmony_ci 414bf215546Sopenharmony_ci/** 415bf215546Sopenharmony_ci * map_usage_to_memtrack should be called after allocating a gralloc buffer. 416bf215546Sopenharmony_ci * 417bf215546Sopenharmony_ci * @param usage - it is the flag used when alloc function is called. 418bf215546Sopenharmony_ci * 419bf215546Sopenharmony_ci * This function maps the gralloc usage flags to appropriate memtrack bucket. 420bf215546Sopenharmony_ci * GrallocHAL implementers and users should make an additional ION_IOCTL_TAG 421bf215546Sopenharmony_ci * call using the memtrack tag returned by this function. This will help the 422bf215546Sopenharmony_ci * in-kernel memtack to categorize the memory allocated by different processes 423bf215546Sopenharmony_ci * according to their usage. 424bf215546Sopenharmony_ci * 425bf215546Sopenharmony_ci */ 426bf215546Sopenharmony_cistatic inline const char* map_usage_to_memtrack(uint32_t usage) { 427bf215546Sopenharmony_ci usage &= GRALLOC_USAGE_ALLOC_MASK; 428bf215546Sopenharmony_ci 429bf215546Sopenharmony_ci if ((usage & GRALLOC_USAGE_HW_CAMERA_WRITE) != 0) { 430bf215546Sopenharmony_ci return "camera"; 431bf215546Sopenharmony_ci } else if ((usage & GRALLOC_USAGE_HW_VIDEO_ENCODER) != 0 || 432bf215546Sopenharmony_ci (usage & GRALLOC_USAGE_EXTERNAL_DISP) != 0) { 433bf215546Sopenharmony_ci return "video"; 434bf215546Sopenharmony_ci } else if ((usage & GRALLOC_USAGE_HW_RENDER) != 0 || 435bf215546Sopenharmony_ci (usage & GRALLOC_USAGE_HW_TEXTURE) != 0) { 436bf215546Sopenharmony_ci return "gl"; 437bf215546Sopenharmony_ci } else if ((usage & GRALLOC_USAGE_HW_CAMERA_READ) != 0) { 438bf215546Sopenharmony_ci return "camera"; 439bf215546Sopenharmony_ci } else if ((usage & GRALLOC_USAGE_SW_READ_MASK) != 0 || 440bf215546Sopenharmony_ci (usage & GRALLOC_USAGE_SW_WRITE_MASK) != 0) { 441bf215546Sopenharmony_ci return "cpu"; 442bf215546Sopenharmony_ci } 443bf215546Sopenharmony_ci return "graphics"; 444bf215546Sopenharmony_ci} 445bf215546Sopenharmony_ci 446bf215546Sopenharmony_ci__END_DECLS 447bf215546Sopenharmony_ci 448bf215546Sopenharmony_ci#endif // ANDROID_GRALLOC_INTERFACE_H 449