Path: blob/21.2-virgl/include/android_stub/hardware/gralloc1.h
7143 views
/*1* Copyright 2015 The Android Open Source Project2*3* Licensed under the Apache License, Version 2.0 (the "License");4* you may not use this file except in compliance with the License.5* You may obtain a copy of the License at6*7* http://www.apache.org/licenses/LICENSE-2.08*9* Unless required by applicable law or agreed to in writing, software10* distributed under the License is distributed on an "AS IS" BASIS,11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12* See the License for the specific language governing permissions and13* limitations under the License.14*/1516#ifndef ANDROID_HARDWARE_GRALLOC1_H17#define ANDROID_HARDWARE_GRALLOC1_H1819#include <hardware/hardware.h>20#include <cutils/native_handle.h>2122__BEGIN_DECLS2324#define GRALLOC_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)25#define GRALLOC_HARDWARE_MODULE_ID "gralloc"2627/*28* Enums29*/3031typedef enum {32GRALLOC1_CAPABILITY_INVALID = 0,3334/* If this capability is supported, then the outBuffers parameter to35* allocate may be NULL, which instructs the device to report whether the36* given allocation is possible or not. */37GRALLOC1_CAPABILITY_TEST_ALLOCATE = 1,3839/* If this capability is supported, then the implementation supports40* allocating buffers with more than one image layer. */41GRALLOC1_CAPABILITY_LAYERED_BUFFERS = 2,4243/* If this capability is supported, then the implementation always closes44* and deletes a buffer handle whenever the last reference is removed.45*46* Supporting this capability is strongly recommended. It will become47* mandatory in future releases. */48GRALLOC1_CAPABILITY_RELEASE_IMPLY_DELETE = 3,4950GRALLOC1_LAST_CAPABILITY = 3,51} gralloc1_capability_t;5253typedef enum {54GRALLOC1_CONSUMER_USAGE_NONE = 0,55GRALLOC1_CONSUMER_USAGE_CPU_READ_NEVER = 0,56/* 1ULL << 0 */57GRALLOC1_CONSUMER_USAGE_CPU_READ = 1ULL << 1,58GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN = 1ULL << 2 |59GRALLOC1_CONSUMER_USAGE_CPU_READ,60/* 1ULL << 3 */61/* 1ULL << 4 */62/* 1ULL << 5 */63/* 1ULL << 6 */64/* 1ULL << 7 */65GRALLOC1_CONSUMER_USAGE_GPU_TEXTURE = 1ULL << 8,66/* 1ULL << 9 */67/* 1ULL << 10 */68GRALLOC1_CONSUMER_USAGE_HWCOMPOSER = 1ULL << 11,69GRALLOC1_CONSUMER_USAGE_CLIENT_TARGET = 1ULL << 12,70/* 1ULL << 13 */71/* 1ULL << 14 */72GRALLOC1_CONSUMER_USAGE_CURSOR = 1ULL << 15,73GRALLOC1_CONSUMER_USAGE_VIDEO_ENCODER = 1ULL << 16,74/* 1ULL << 17 */75GRALLOC1_CONSUMER_USAGE_CAMERA = 1ULL << 18,76/* 1ULL << 19 */77GRALLOC1_CONSUMER_USAGE_RENDERSCRIPT = 1ULL << 20,7879/* Indicates that the consumer may attach buffers to their end of the80* BufferQueue, which means that the producer may never have seen a given81* dequeued buffer before. May be ignored by the gralloc device. */82GRALLOC1_CONSUMER_USAGE_FOREIGN_BUFFERS = 1ULL << 21,8384/* 1ULL << 22 */85GRALLOC1_CONSUMER_USAGE_GPU_DATA_BUFFER = 1ULL << 23,86/* 1ULL << 24 */87/* 1ULL << 25 */88/* 1ULL << 26 */89/* 1ULL << 27 */9091/* Bits reserved for implementation-specific usage flags */92GRALLOC1_CONSUMER_USAGE_PRIVATE_0 = 1ULL << 28,93GRALLOC1_CONSUMER_USAGE_PRIVATE_1 = 1ULL << 29,94GRALLOC1_CONSUMER_USAGE_PRIVATE_2 = 1ULL << 30,95GRALLOC1_CONSUMER_USAGE_PRIVATE_3 = 1ULL << 31,9697/* 1ULL << 32 */98/* 1ULL << 33 */99/* 1ULL << 34 */100/* 1ULL << 35 */101/* 1ULL << 36 */102/* 1ULL << 37 */103/* 1ULL << 38 */104/* 1ULL << 39 */105/* 1ULL << 40 */106/* 1ULL << 41 */107/* 1ULL << 42 */108/* 1ULL << 43 */109/* 1ULL << 44 */110/* 1ULL << 45 */111/* 1ULL << 46 */112/* 1ULL << 47 */113114/* Bits reserved for implementation-specific usage flags */115GRALLOC1_CONSUMER_USAGE_PRIVATE_19 = 1ULL << 48,116GRALLOC1_CONSUMER_USAGE_PRIVATE_18 = 1ULL << 49,117GRALLOC1_CONSUMER_USAGE_PRIVATE_17 = 1ULL << 50,118GRALLOC1_CONSUMER_USAGE_PRIVATE_16 = 1ULL << 51,119GRALLOC1_CONSUMER_USAGE_PRIVATE_15 = 1ULL << 52,120GRALLOC1_CONSUMER_USAGE_PRIVATE_14 = 1ULL << 53,121GRALLOC1_CONSUMER_USAGE_PRIVATE_13 = 1ULL << 54,122GRALLOC1_CONSUMER_USAGE_PRIVATE_12 = 1ULL << 55,123GRALLOC1_CONSUMER_USAGE_PRIVATE_11 = 1ULL << 56,124GRALLOC1_CONSUMER_USAGE_PRIVATE_10 = 1ULL << 57,125GRALLOC1_CONSUMER_USAGE_PRIVATE_9 = 1ULL << 58,126GRALLOC1_CONSUMER_USAGE_PRIVATE_8 = 1ULL << 59,127GRALLOC1_CONSUMER_USAGE_PRIVATE_7 = 1ULL << 60,128GRALLOC1_CONSUMER_USAGE_PRIVATE_6 = 1ULL << 61,129GRALLOC1_CONSUMER_USAGE_PRIVATE_5 = 1ULL << 62,130GRALLOC1_CONSUMER_USAGE_PRIVATE_4 = 1ULL << 63,131} gralloc1_consumer_usage_t;132133typedef enum {134GRALLOC1_FUNCTION_INVALID = 0,135GRALLOC1_FUNCTION_DUMP = 1,136GRALLOC1_FUNCTION_CREATE_DESCRIPTOR = 2,137GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR = 3,138GRALLOC1_FUNCTION_SET_CONSUMER_USAGE = 4,139GRALLOC1_FUNCTION_SET_DIMENSIONS = 5,140GRALLOC1_FUNCTION_SET_FORMAT = 6,141GRALLOC1_FUNCTION_SET_PRODUCER_USAGE = 7,142GRALLOC1_FUNCTION_GET_BACKING_STORE = 8,143GRALLOC1_FUNCTION_GET_CONSUMER_USAGE = 9,144GRALLOC1_FUNCTION_GET_DIMENSIONS = 10,145GRALLOC1_FUNCTION_GET_FORMAT = 11,146GRALLOC1_FUNCTION_GET_PRODUCER_USAGE = 12,147GRALLOC1_FUNCTION_GET_STRIDE = 13,148GRALLOC1_FUNCTION_ALLOCATE = 14,149GRALLOC1_FUNCTION_RETAIN = 15,150GRALLOC1_FUNCTION_RELEASE = 16,151GRALLOC1_FUNCTION_GET_NUM_FLEX_PLANES = 17,152GRALLOC1_FUNCTION_LOCK = 18,153GRALLOC1_FUNCTION_LOCK_FLEX = 19,154GRALLOC1_FUNCTION_UNLOCK = 20,155GRALLOC1_FUNCTION_SET_LAYER_COUNT = 21,156GRALLOC1_FUNCTION_GET_LAYER_COUNT = 22,157GRALLOC1_FUNCTION_VALIDATE_BUFFER_SIZE = 23,158GRALLOC1_FUNCTION_GET_TRANSPORT_SIZE = 24,159GRALLOC1_FUNCTION_IMPORT_BUFFER = 25,160GRALLOC1_LAST_FUNCTION = 25,161} gralloc1_function_descriptor_t;162163typedef enum {164GRALLOC1_ERROR_NONE = 0,165GRALLOC1_ERROR_BAD_DESCRIPTOR = 1,166GRALLOC1_ERROR_BAD_HANDLE = 2,167GRALLOC1_ERROR_BAD_VALUE = 3,168GRALLOC1_ERROR_NOT_SHARED = 4,169GRALLOC1_ERROR_NO_RESOURCES = 5,170GRALLOC1_ERROR_UNDEFINED = 6,171GRALLOC1_ERROR_UNSUPPORTED = 7,172} gralloc1_error_t;173174typedef enum {175GRALLOC1_PRODUCER_USAGE_NONE = 0,176GRALLOC1_PRODUCER_USAGE_CPU_WRITE_NEVER = 0,177/* 1ULL << 0 */178GRALLOC1_PRODUCER_USAGE_CPU_READ = 1ULL << 1,179GRALLOC1_PRODUCER_USAGE_CPU_READ_OFTEN = 1ULL << 2 |180GRALLOC1_PRODUCER_USAGE_CPU_READ,181/* 1ULL << 3 */182/* 1ULL << 4 */183GRALLOC1_PRODUCER_USAGE_CPU_WRITE = 1ULL << 5,184GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN = 1ULL << 6 |185GRALLOC1_PRODUCER_USAGE_CPU_WRITE,186/* 1ULL << 7 */187/* 1ULL << 8 */188GRALLOC1_PRODUCER_USAGE_GPU_RENDER_TARGET = 1ULL << 9,189/* 1ULL << 10 */190/* 1ULL << 11 */191/* 1ULL << 12 */192/* 1ULL << 13 */193194/* The consumer must have a hardware-protected path to an external display195* sink for this buffer. If a hardware-protected path is not available, then196* do not attempt to display this buffer. */197GRALLOC1_PRODUCER_USAGE_PROTECTED = 1ULL << 14,198199/* 1ULL << 15 */200/* 1ULL << 16 */201GRALLOC1_PRODUCER_USAGE_CAMERA = 1ULL << 17,202/* 1ULL << 18 */203/* 1ULL << 19 */204/* 1ULL << 20 */205/* 1ULL << 21 */206GRALLOC1_PRODUCER_USAGE_VIDEO_DECODER = 1ULL << 22,207GRALLOC1_PRODUCER_USAGE_SENSOR_DIRECT_DATA = 1ULL << 23,208/* 1ULL << 24 */209/* 1ULL << 25 */210/* 1ULL << 26 */211/* 1ULL << 27 */212213/* Bits reserved for implementation-specific usage flags */214GRALLOC1_PRODUCER_USAGE_PRIVATE_0 = 1ULL << 28,215GRALLOC1_PRODUCER_USAGE_PRIVATE_1 = 1ULL << 29,216GRALLOC1_PRODUCER_USAGE_PRIVATE_2 = 1ULL << 30,217GRALLOC1_PRODUCER_USAGE_PRIVATE_3 = 1ULL << 31,218219/* 1ULL << 32 */220/* 1ULL << 33 */221/* 1ULL << 34 */222/* 1ULL << 35 */223/* 1ULL << 36 */224/* 1ULL << 37 */225/* 1ULL << 38 */226/* 1ULL << 39 */227/* 1ULL << 40 */228/* 1ULL << 41 */229/* 1ULL << 42 */230/* 1ULL << 43 */231/* 1ULL << 44 */232/* 1ULL << 45 */233/* 1ULL << 46 */234/* 1ULL << 47 */235236/* Bits reserved for implementation-specific usage flags */237GRALLOC1_PRODUCER_USAGE_PRIVATE_19 = 1ULL << 48,238GRALLOC1_PRODUCER_USAGE_PRIVATE_18 = 1ULL << 49,239GRALLOC1_PRODUCER_USAGE_PRIVATE_17 = 1ULL << 50,240GRALLOC1_PRODUCER_USAGE_PRIVATE_16 = 1ULL << 51,241GRALLOC1_PRODUCER_USAGE_PRIVATE_15 = 1ULL << 52,242GRALLOC1_PRODUCER_USAGE_PRIVATE_14 = 1ULL << 53,243GRALLOC1_PRODUCER_USAGE_PRIVATE_13 = 1ULL << 54,244GRALLOC1_PRODUCER_USAGE_PRIVATE_12 = 1ULL << 55,245GRALLOC1_PRODUCER_USAGE_PRIVATE_11 = 1ULL << 56,246GRALLOC1_PRODUCER_USAGE_PRIVATE_10 = 1ULL << 57,247GRALLOC1_PRODUCER_USAGE_PRIVATE_9 = 1ULL << 58,248GRALLOC1_PRODUCER_USAGE_PRIVATE_8 = 1ULL << 59,249GRALLOC1_PRODUCER_USAGE_PRIVATE_7 = 1ULL << 60,250GRALLOC1_PRODUCER_USAGE_PRIVATE_6 = 1ULL << 61,251GRALLOC1_PRODUCER_USAGE_PRIVATE_5 = 1ULL << 62,252GRALLOC1_PRODUCER_USAGE_PRIVATE_4 = 1ULL << 63,253} gralloc1_producer_usage_t;254255/*256* Typedefs257*/258259typedef void (*gralloc1_function_pointer_t)();260261typedef uint64_t gralloc1_backing_store_t;262typedef uint64_t gralloc1_buffer_descriptor_t;263264/*265* Device Struct266*/267268typedef struct gralloc1_device {269/* Must be the first member of this struct, since a pointer to this struct270* will be generated by casting from a hw_device_t* */271struct hw_device_t common;272273/* getCapabilities(..., outCount, outCapabilities)274*275* Provides a list of capabilities (described in the definition of276* gralloc1_capability_t above) supported by this device. This list must not277* change after the device has been loaded.278*279* Parameters:280* outCount - if outCapabilities was NULL, the number of capabilities281* which would have been returned; if outCapabilities was not NULL,282* the number of capabilities returned, which must not exceed the283* value stored in outCount prior to the call284* outCapabilities - a list of capabilities supported by this device; may285* be NULL, in which case this function must write into outCount the286* number of capabilities which would have been written into287* outCapabilities288*/289void (*getCapabilities)(struct gralloc1_device* device, uint32_t* outCount,290int32_t* /*gralloc1_capability_t*/ outCapabilities);291292/* getFunction(..., descriptor)293*294* Returns a function pointer which implements the requested description.295*296* Parameters:297* descriptor - the function to return298*299* Returns either a function pointer implementing the requested descriptor300* or NULL if the described function is not supported by this device.301*/302gralloc1_function_pointer_t (*getFunction)(struct gralloc1_device* device,303int32_t /*gralloc1_function_descriptor_t*/ descriptor);304} gralloc1_device_t;305306static inline int gralloc1_open(const struct hw_module_t* module,307gralloc1_device_t** device) {308return module->methods->open(module, GRALLOC_HARDWARE_MODULE_ID,309TO_HW_DEVICE_T_OPEN(device));310}311312static inline int gralloc1_close(gralloc1_device_t* device) {313return device->common.close(&device->common);314}315316/* dump(..., outSize, outBuffer)317* Function descriptor: GRALLOC1_FUNCTION_DUMP318* Must be provided by all gralloc1 devices319*320* Retrieves implementation-defined debug information, which will be displayed321* during, for example, `dumpsys SurfaceFlinger`.322*323* If called with outBuffer == NULL, the device should store a copy of the324* desired output and return its length in bytes in outSize. If the device325* already has a stored copy, that copy should be purged and replaced with a326* fresh copy.327*328* If called with outBuffer != NULL, the device should copy its stored version329* of the output into outBuffer and store how many bytes of data it copied into330* outSize. Prior to this call, the client will have populated outSize with the331* maximum number of bytes outBuffer can hold. The device must not write more332* than this amount into outBuffer. If the device does not currently have a333* stored copy, then it should return 0 in outSize.334*335* Any data written into outBuffer need not be null-terminated.336*337* Parameters:338* outSize - if outBuffer was NULL, the number of bytes needed to copy the339* device's stored output; if outBuffer was not NULL, the number of bytes340* written into it, which must not exceed the value stored in outSize341* prior to the call; pointer will be non-NULL342* outBuffer - the buffer to write the dump output into; may be NULL as343* described above; data written into this buffer need not be344* null-terminated345*/346typedef void (*GRALLOC1_PFN_DUMP)(gralloc1_device_t* device, uint32_t* outSize,347char* outBuffer);348349/*350* Buffer descriptor lifecycle functions351*352* All of these functions take as their first parameter a device pointer, so353* this parameter is omitted from the described parameter lists.354*/355356/* createDescriptor(..., outDescriptor)357* Function descriptor: GRALLOC1_FUNCTION_CREATE_DESCRIPTOR358* Must be provided by all gralloc1 devices359*360* Creates a new, empty buffer descriptor.361*362* Parameters:363* outDescriptor - the new buffer descriptor364*365* Returns GRALLOC1_ERROR_NONE or one of the following errors:366* GRALLOC1_ERROR_NO_RESOURCES - no more descriptors can currently be created367*/368typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_CREATE_DESCRIPTOR)(369gralloc1_device_t* device, gralloc1_buffer_descriptor_t* outDescriptor);370371/* destroyDescriptor(..., descriptor)372* Function descriptor: GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR373* Must be provided by all gralloc1 devices374*375* Destroys an existing buffer descriptor.376*377* Parameters:378* descriptor - the buffer descriptor to destroy379*380* Returns GRALLOC1_ERROR_NONE or one of the following errors:381* GRALLOC1_ERROR_BAD_DESCRIPTOR - descriptor does not refer to a valid382* buffer descriptor383*/384typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_DESTROY_DESCRIPTOR)(385gralloc1_device_t* device, gralloc1_buffer_descriptor_t descriptor);386387/*388* Buffer descriptor modification functions389*390* All of these functions take as their first two parameters a device pointer391* and a buffer descriptor, so these parameters are omitted from the described392* parameter lists.393*/394395/* setConsumerUsage(..., usage)396* Function descriptor: GRALLOC1_FUNCTION_SET_CONSUMER_USAGE397* Must be provided by all gralloc1 devices398*399* Sets the desired consumer usage flags of the buffer.400*401* Valid usage flags can be found in the definition of gralloc1_consumer_usage_t402* above.403*404* Parameters:405* usage - the desired consumer usage flags406*407* Returns GRALLOC1_ERROR_NONE or one of the following errors:408* GRALLOC1_ERROR_BAD_DESCRIPTOR - the buffer descriptor is invalid409* GRALLOC1_ERROR_BAD_VALUE - an invalid usage flag was passed in410*/411typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_SET_CONSUMER_USAGE)(412gralloc1_device_t* device, gralloc1_buffer_descriptor_t descriptor,413uint64_t /*gralloc1_consumer_usage_t*/ usage);414415/* setDimensions(..., width, height)416* Function descriptor: GRALLOC1_FUNCTION_SET_DIMENSIONS417* Must be provided by all gralloc1 devices418*419* Sets the desired width and height of the buffer in pixels.420*421* The width specifies how many columns of pixels should be in the allocated422* buffer, but does not necessarily represent the offset in columns between the423* same column in adjacent rows. If this offset is required, consult getStride424* below.425*426* The height specifies how many rows of pixels should be in the allocated427* buffer.428*429* Parameters:430* width - the desired width in pixels431* height - the desired height in pixels432*433* Returns GRALLOC1_ERROR_NONE or one of the following errors:434* GRALLOC1_ERROR_BAD_DESCRIPTOR - the buffer descriptor is invalid435*/436typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_SET_DIMENSIONS)(437gralloc1_device_t* device, gralloc1_buffer_descriptor_t descriptor,438uint32_t width, uint32_t height);439440/* setFormat(..., format)441* Function descriptor: GRALLOC1_FUNCTION_SET_FORMAT442* Must be provided by all gralloc1 devices443*444* Sets the desired format of the buffer.445*446* The valid formats can be found in <system/graphics.h>.447*448* Parameters:449* format - the desired format450*451* Returns GRALLOC1_ERROR_NONE or one of the following errors:452* GRALLOC1_ERROR_BAD_DESCRIPTOR - the buffer descriptor is invalid453* GRALLOC1_ERROR_BAD_VALUE - format is invalid454*/455typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_SET_FORMAT)(456gralloc1_device_t* device, gralloc1_buffer_descriptor_t descriptor,457int32_t /*android_pixel_format_t*/ format);458459/* setLayerCount(..., layerCount)460* Function descriptor: GRALLOC1_FUNCTION_SET_LAYER_COUNT461* Must be provided by all gralloc1 devices that provide the462* GRALLOC1_CAPABILITY_LAYERED_BUFFERS capability.463*464* Sets the number of layers in the buffer.465*466* A buffer with multiple layers may be used as the backing store of an array467* texture. All layers of a buffer share the same characteristics (e.g.,468* dimensions, format, usage). Devices that do not support469* GRALLOC1_CAPABILITY_LAYERED_BUFFERS must allocate only buffers with a single470* layer.471*472* Parameters:473* layerCount - the desired number of layers, must be non-zero474*475* Returns GRALLOC1_ERROR_NONE or one of the following errors:476* GRALLOC1_ERROR_BAD_DESCRIPTOR - the buffer descriptor is invalid477* GRALLOC1_ERROR_BAD_VALUE - the layer count is invalid478*/479typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_SET_LAYER_COUNT)(480gralloc1_device_t* device, gralloc1_buffer_descriptor_t descriptor,481uint32_t layerCount);482483/* setProducerUsage(..., usage)484* Function descriptor: GRALLOC1_FUNCTION_SET_PRODUCER_USAGE485* Must be provided by all gralloc1 devices486*487* Sets the desired producer usage flags of the buffer.488*489* Valid usage flags can be found in the definition of gralloc1_producer_usage_t490* above.491*492* Parameters:493* usage - the desired producer usage flags494*495* Returns GRALLOC1_ERROR_NONE or one of the following errors:496* GRALLOC1_ERROR_BAD_DESCRIPTOR - the buffer descriptor is invalid497* GRALLOC1_ERROR_BAD_VALUE - an invalid usage flag was passed in498*/499typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_SET_PRODUCER_USAGE)(500gralloc1_device_t* device, gralloc1_buffer_descriptor_t descriptor,501uint64_t /*gralloc1_producer_usage_t*/ usage);502503/*504* Buffer handle query functions505*506* All of these functions take as their first two parameters a device pointer507* and a buffer handle, so these parameters are omitted from the described508* parameter lists.509*510* [1] Currently many of these functions may return GRALLOC1_ERROR_UNSUPPORTED,511* which means that the device is not able to retrieve the requested information512* from the buffer. This is necessary to enable a smooth transition from earlier513* versions of the gralloc HAL, but gralloc1 implementers are strongly514* discouraged from returning this value, as future versions of the platform515* code will require all of these functions to succeed given a valid handle.516*/517518/* getBackingStore(..., outStore)519* Function descriptor: GRALLOC1_FUNCTION_GET_BACKING_STORE520* Must be provided by all gralloc1 devices521*522* Gets a value that uniquely identifies the backing store of the given buffer.523*524* Buffers which share a backing store should return the same value from this525* function. If the buffer is present in more than one process, the backing526* store value for that buffer is not required to be the same in every process.527*528* Parameters:529* outStore - the backing store identifier for this buffer530*531* Returns GRALLOC1_ERROR_NONE or one of the following errors:532* GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid533* GRALLOC1_ERROR_UNSUPPORTED - the device is unable to retrieve the534* backing store identifier from the buffer; see note [1] in this535* section's header for more information536*/537typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_GET_BACKING_STORE)(538gralloc1_device_t* device, buffer_handle_t buffer,539gralloc1_backing_store_t* outStore);540541/* getConsumerUsage(..., outUsage)542* Function descriptor: GRALLOC1_FUNCTION_GET_CONSUMER_USAGE543* Must be provided by all gralloc1 devices544*545* Gets the consumer usage flags which were used to allocate this buffer.546*547* Usage flags can be found in the definition of gralloc1_consumer_usage_t above548*549* Parameters:550* outUsage - the consumer usage flags used to allocate this buffer; must be551* non-NULL552*553* Returns GRALLOC1_ERROR_NONE or one of the following errors:554* GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid555* GRALLOC1_ERROR_UNSUPPORTED - the device is unable to retrieve the556* dimensions from the buffer; see note [1] in this section's header for557* more information558*/559typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_GET_CONSUMER_USAGE)(560gralloc1_device_t* device, buffer_handle_t buffer,561uint64_t* /*gralloc1_consumer_usage_t*/ outUsage);562563/* getDimensions(..., outWidth, outHeight)564* Function descriptor: GRALLOC1_FUNCTION_GET_DIMENSIONS565* Must be provided by all gralloc1 devices566*567* Gets the width and height of the buffer in pixels.568*569* See setDimensions for more information about these values.570*571* Parameters:572* outWidth - the width of the buffer in pixels, must be non-NULL573* outHeight - the height of the buffer in pixels, must be non-NULL574*575* Returns GRALLOC1_ERROR_NONE or one of the following errors:576* GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid577* GRALLOC1_ERROR_UNSUPPORTED - the device is unable to retrieve the578* dimensions from the buffer; see note [1] in this section's header for579* more information580*/581typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_GET_DIMENSIONS)(582gralloc1_device_t* device, buffer_handle_t buffer, uint32_t* outWidth,583uint32_t* outHeight);584585/* getFormat(..., outFormat)586* Function descriptor: GRALLOC1_FUNCTION_GET_FORMAT587* Must be provided by all gralloc1 devices588*589* Gets the format of the buffer.590*591* The valid formats can be found in the HAL_PIXEL_FORMAT_* enum in592* system/graphics.h.593*594* Parameters:595* outFormat - the format of the buffer; must be non-NULL596*597* Returns GRALLOC1_ERROR_NONE or one of the following errors:598* GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid599* GRALLOC1_ERROR_UNSUPPORTED - the device is unable to retrieve the format600* from the buffer; see note [1] in this section's header for more601* information602*/603typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_GET_FORMAT)(604gralloc1_device_t* device, buffer_handle_t descriptor,605int32_t* outFormat);606607/* getLayerCount(..., outLayerCount)608* Function descriptor: GRALLOC1_FUNCTION_GET_LAYER_COUNT609* Must be provided by all gralloc1 devices that provide the610* GRALLOC1_CAPABILITY_LAYERED_BUFFERS capability.611*612* Gets the number of layers of the buffer.613*614* See setLayerCount for more information about this value.615*616* Parameters:617* outLayerCount - the number of layers in the image, must be non-NULL618*619* Returns GRALLOC1_ERROR_NONE or one of the following errors:620* GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid621* GRALLOC1_ERROR_UNSUPPORTED - the device is unable to retrieve the622* layer count from the buffer; see note [1] in this section's header for623* more information624*/625typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_GET_LAYER_COUNT)(626gralloc1_device_t* device, buffer_handle_t buffer,627uint32_t* outLayerCount);628629/* getProducerUsage(..., outUsage)630* Function descriptor: GRALLOC1_FUNCTION_GET_PRODUCER_USAGE631* Must be provided by all gralloc1 devices632*633* Gets the producer usage flags which were used to allocate this buffer.634*635* Usage flags can be found in the definition of gralloc1_producer_usage_t above636*637* Parameters:638* outUsage - the producer usage flags used to allocate this buffer; must be639* non-NULL640*641* Returns GRALLOC1_ERROR_NONE or one of the following errors:642* GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid643* GRALLOC1_ERROR_UNSUPPORTED - the device is unable to retrieve the usage644* from the buffer; see note [1] in this section's header for more645* information646*/647typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_GET_PRODUCER_USAGE)(648gralloc1_device_t* device, buffer_handle_t buffer,649uint64_t* /*gralloc1_producer_usage_t*/ outUsage);650651/* getStride(..., outStride)652* Function descriptor: GRALLOC1_FUNCTION_GET_STRIDE653* Must be provided by all gralloc1 devices654*655* Gets the stride of the buffer in pixels.656*657* The stride is the offset in pixel-sized elements between the same column in658* two adjacent rows of pixels. This may not be equal to the width of the659* buffer.660*661* Parameters:662* outStride - the stride in pixels; must be non-NULL663*664* Returns GRALLOC1_ERROR_NONE or one of the following errors:665* GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid666* GRALLOC1_ERROR_UNDEFINED - the notion of a stride is not meaningful for667* this format668* GRALLOC1_ERROR_UNSUPPORTED - the device is unable to retrieve the stride669* from the descriptor; see note [1] in this section's header for more670* information671*/672typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_GET_STRIDE)(673gralloc1_device_t* device, buffer_handle_t buffer, uint32_t* outStride);674675/* getTransportSize(..., outNumFds, outNumInts)676* Function descriptor: GRALLOC1_FUNCTION_GET_TRANSPORT_SIZE677*678* Get the transport size of a buffer. An imported buffer handle is a raw679* buffer handle with the process-local runtime data appended. This680* function, for example, allows a caller to omit the process-local681* runtime data at the tail when serializing the imported buffer handle.682*683* Note that a client might or might not omit the process-local runtime684* data when sending an imported buffer handle. The mapper must support685* both cases on the receiving end.686*687* Parameters:688* outNumFds - the number of file descriptors needed for transport689* outNumInts - the number of integers needed for transport690*691* Returns GRALLOC1_ERROR_NONE or one of the following errors:692* GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid693* GRALLOC1_ERROR_UNSUPPORTED - the device is unable to retrieve the numFds694* and numInts; see note [1] in this section's header for more information695*/696typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_GET_TRANSPORT_SIZE)(697gralloc1_device_t* device, buffer_handle_t buffer, uint32_t *outNumFds,698uint32_t *outNumInts);699700typedef struct gralloc1_buffer_descriptor_info {701uint32_t width;702uint32_t height;703uint32_t layerCount;704int32_t /*android_pixel_format_t*/ format;705uint64_t producerUsage;706uint64_t consumerUsage;707} gralloc1_buffer_descriptor_info_t;708709/* validateBufferSize(..., )710* Function descriptor: GRALLOC1_FUNCTION_VALIDATE_BUFFER_SIZE711*712* Validate that the buffer can be safely accessed by a caller who assumes713* the specified descriptorInfo and stride. This must at least validate714* that the buffer size is large enough. Validating the buffer against715* individual buffer attributes is optional.716*717* Parameters:718* descriptor - specifies the attributes of the buffer719* stride - the buffer stride returned by IAllocator::allocate720*721* Returns GRALLOC1_ERROR_NONE or one of the following errors:722* GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid723* GRALLOC1_ERROR_BAD_VALUE - when buffer cannot be safely accessed724* GRALLOC1_ERROR_UNSUPPORTED - the device is unable to validate the buffer725* size; see note [1] in this section's header for more information726*/727typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_VALIDATE_BUFFER_SIZE)(728gralloc1_device_t* device, buffer_handle_t buffer,729const gralloc1_buffer_descriptor_info_t* descriptorInfo,730uint32_t stride);731732/*733* Buffer management functions734*/735736/* allocate(..., numDescriptors, descriptors, outBuffers)737* Function descriptor: GRALLOC1_FUNCTION_ALLOCATE738* Must be provided by all gralloc1 devices739*740* Attempts to allocate a number of buffers sharing a backing store.741*742* Each buffer will correspond to one of the descriptors passed into the743* function. If the device is unable to share the backing store between the744* buffers, it should attempt to allocate the buffers with different backing745* stores and return GRALLOC1_ERROR_NOT_SHARED if it is successful.746*747* If this call is successful, the client is responsible for freeing the748* buffer_handle_t using release() when it is finished with the buffer. It is749* not necessary to call retain() on the returned buffers, as they must have a750* reference added by the device before returning.751*752* If GRALLOC1_CAPABILITY_TEST_ALLOCATE is supported by this device, outBuffers753* may be NULL. In this case, the device must not attempt to allocate any754* buffers, but instead must return either GRALLOC1_ERROR_NONE if such an755* allocation is possible (ignoring potential resource contention which might756* lead to a GRALLOC1_ERROR_NO_RESOURCES error), GRALLOC1_ERROR_NOT_SHARED if757* the buffers can be allocated, but cannot share a backing store, or758* GRALLOC1_ERROR_UNSUPPORTED if one or more of the descriptors can never be759* allocated by the device.760*761* Parameters:762* numDescriptors - the number of buffer descriptors, which must also be equal763* to the size of the outBuffers array764* descriptors - the buffer descriptors to attempt to allocate765* outBuffers - the allocated buffers; must be non-NULL unless the device766* supports GRALLOC1_CAPABILITY_TEST_ALLOCATE (see above), and must not be767* modified by the device if allocation is unsuccessful768*769* Returns GRALLOC1_ERROR_NONE or one of the following errors:770* GRALLOC1_ERROR_BAD_DESCRIPTOR - one of the descriptors does not refer to a771* valid buffer descriptor772* GRALLOC1_ERROR_NOT_SHARED - allocation was successful, but required more773* than one backing store to satisfy all of the buffer descriptors774* GRALLOC1_ERROR_NO_RESOURCES - allocation failed because one or more of the775* backing stores could not be created at this time (but this allocation776* might succeed at a future time)777* GRALLOC1_ERROR_UNSUPPORTED - one or more of the descriptors can never be778* satisfied by the device779*/780typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_ALLOCATE)(781gralloc1_device_t* device, uint32_t numDescriptors,782const gralloc1_buffer_descriptor_t* descriptors,783buffer_handle_t* outBuffers);784785/* importBuffer(..., rawHandle, outBuffer);786* Function descriptor: GRALLOC1_FUNCTION_IMPORT_BUFFER787* This function is optional for all gralloc1 devices.788* When supported, GRALLOC1_CAPABILITY_RELEASE_IMPLY_DELETE must also be789* supported.790*791* Explictly imports a buffer into a proccess.792*793* This function can be called in place of retain when a raw buffer handle is794* received by a remote process. Import producess a import handle that can795* be used to access the underlying graphic buffer. The new import handle has a796* ref count of 1.797*798* This function must at least validate the raw handle before creating the799* imported handle. It must also support importing the same raw handle800* multiple times to create multiple imported handles. The imported handle801* must be considered valid everywhere in the process.802*803* Parameters:804* rawHandle - the raw buffer handle to import805* outBuffer - a handle to the newly imported buffer806*807* Returns GRALLOC1_ERROR_NONE or one of the following errors:808* GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid809* GRALLOC1_ERROR_NO_RESOURCES - it is not possible to add a import to this810* buffer at this time811*/812typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_IMPORT_BUFFER)(813gralloc1_device_t* device, const buffer_handle_t rawHandle,814buffer_handle_t* outBuffer);815816/* retain(..., buffer)817* Function descriptor: GRALLOC1_FUNCTION_RETAIN818* Must be provided by all gralloc1 devices819*820* Adds a reference to the given buffer.821*822* This function must be called when a buffer_handle_t is received from a remote823* process to prevent the buffer's data from being freed when the remote process824* releases the buffer. It may also be called to increase the reference count if825* two components in the same process want to interact with the buffer826* independently.827*828* Parameters:829* buffer - the buffer to which a reference should be added830*831* Returns GRALLOC1_ERROR_NONE or one of the following errors:832* GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid833* GRALLOC1_ERROR_NO_RESOURCES - it is not possible to add a reference to this834* buffer at this time835*/836typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_RETAIN)(837gralloc1_device_t* device, buffer_handle_t buffer);838839/* release(..., buffer)840* Function descriptor: GRALLOC1_FUNCTION_RELEASE841* Must be provided by all gralloc1 devices842*843* Removes a reference from the given buffer.844*845* If no references remain, the buffer should be freed. When the last buffer846* referring to a particular backing store is freed, that backing store should847* also be freed.848*849* When GRALLOC1_CAPABILITY_RELEASE_IMPLY_DELETE is supported,850* native_handle_close and native_handle_delete must always be called by the851* implementation whenever the last reference is removed. Otherwise, a call852* to release() will be followed by native_handle_close and native_handle_delete853* by the caller when the buffer is not allocated locally through allocate().854*855* Parameters:856* buffer - the buffer from which a reference should be removed857*858* Returns GRALLOC1_ERROR_NONE or one of the following errors:859* GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid860*/861typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_RELEASE)(862gralloc1_device_t* device, buffer_handle_t buffer);863864/*865* Buffer access functions866*867* All of these functions take as their first parameter a device pointer, so868* this parameter is omitted from the described parameter lists.869*/870871typedef struct gralloc1_rect {872int32_t left;873int32_t top;874int32_t width;875int32_t height;876} gralloc1_rect_t;877878/* getNumFlexPlanes(..., buffer, outNumPlanes)879* Function descriptor: GRALLOC1_FUNCTION_GET_NUM_FLEX_PLANES880* Must be provided by all gralloc1 devices881*882* Returns the number of flex layout planes which are needed to represent the883* given buffer. This may be used to efficiently allocate only as many plane884* structures as necessary before calling into lockFlex.885*886* If the given buffer cannot be locked as a flex format, this function may887* return GRALLOC1_ERROR_UNSUPPORTED (as lockFlex would).888*889* Parameters:890* buffer - the buffers for which the number of planes should be queried891* outNumPlanes - the number of flex planes required to describe the given892* buffer; must be non-NULL893*894* Returns GRALLOC1_ERROR_NONE or one of the following errors:895* GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid896* GRALLOC1_ERROR_UNSUPPORTED - the buffer's format cannot be represented in a897* flex layout898*/899typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_GET_NUM_FLEX_PLANES)(900gralloc1_device_t* device, buffer_handle_t buffer,901uint32_t* outNumPlanes);902903/* lock(..., buffer, producerUsage, consumerUsage, accessRegion, outData,904* acquireFence)905* Function descriptor: GRALLOC1_FUNCTION_LOCK906* Must be provided by all gralloc1 devices907*908* Locks the given buffer for the specified CPU usage.909*910* Exactly one of producerUsage and consumerUsage must be *_USAGE_NONE. The911* usage which is not *_USAGE_NONE must be one of the *_USAGE_CPU_* values, as912* applicable. Locking a buffer for a non-CPU usage is not supported.913*914* Locking the same buffer simultaneously from multiple threads is permitted,915* but if any of the threads attempt to lock the buffer for writing, the916* behavior is undefined, except that it must not cause process termination or917* block the client indefinitely. Leaving the buffer content in an indeterminate918* state or returning an error are both acceptable.919*920* The client must not modify the content of the buffer outside of accessRegion,921* and the device need not guarantee that content outside of accessRegion is922* valid for reading. The result of reading or writing outside of accessRegion923* is undefined, except that it must not cause process termination.924*925* outData must be a non-NULL pointer, the contents of which which will be926* filled with a pointer to the locked buffer memory. This address will927* represent the top-left corner of the entire buffer, even if accessRegion does928* not begin at the top-left corner.929*930* acquireFence is a file descriptor referring to a acquire sync fence object,931* which will be signaled when it is safe for the device to access the contents932* of the buffer (prior to locking). If it is already safe to access the buffer933* contents, -1 may be passed instead.934*935* Parameters:936* buffer - the buffer to lock937* producerUsage - the producer usage flags to request; either this or938* consumerUsage must be GRALLOC1_*_USAGE_NONE, and the other must be a939* CPU usage940* consumerUsage - the consumer usage flags to request; either this or941* producerUsage must be GRALLOC1_*_USAGE_NONE, and the other must be a942* CPU usage943* accessRegion - the portion of the buffer that the client intends to access;944* must be non-NULL945* outData - will be filled with a CPU-accessible pointer to the buffer data;946* must be non-NULL947* acquireFence - a sync fence file descriptor as described above948*949* Returns GRALLOC1_ERROR_NONE or one of the following errors:950* GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid951* GRALLOC1_ERROR_BAD_VALUE - neither or both of producerUsage and952* consumerUsage were GRALLOC1_*_USAGE_NONE, or the usage which was not953* *_USAGE_NONE was not a CPU usage954* GRALLOC1_ERROR_NO_RESOURCES - the buffer cannot be locked at this time, but955* locking may succeed at a future time956* GRALLOC1_ERROR_UNSUPPORTED - the buffer cannot be locked with the given957* usage, and any future attempts at locking will also fail958*/959typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_LOCK)(960gralloc1_device_t* device, buffer_handle_t buffer,961uint64_t /*gralloc1_producer_usage_t*/ producerUsage,962uint64_t /*gralloc1_consumer_usage_t*/ consumerUsage,963const gralloc1_rect_t* accessRegion, void** outData,964int32_t acquireFence);965966/* lockFlex(..., buffer, producerUsage, consumerUsage, accessRegion,967* outFlexLayout, outAcquireFence)968* Function descriptor: GRALLOC1_FUNCTION_LOCK_FLEX969* Must be provided by all gralloc1 devices970*971* This is largely the same as lock(), except that instead of returning a972* pointer directly to the buffer data, it returns an android_flex_layout973* struct describing how to access the data planes.974*975* This function must work on buffers with HAL_PIXEL_FORMAT_YCbCr_*_888 if976* supported by the device, as well as with any other formats requested by977* multimedia codecs when they are configured with a flexible-YUV-compatible978* color format.979*980* This function may also be called on buffers of other formats, including981* non-YUV formats, but if the buffer format is not compatible with a flexible982* representation, it may return GRALLOC1_ERROR_UNSUPPORTED.983*984* Parameters:985* buffer - the buffer to lock986* producerUsage - the producer usage flags to request; either this or987* consumerUsage must be GRALLOC1_*_USAGE_NONE, and the other must be a988* CPU usage989* consumerUsage - the consumer usage flags to request; either this or990* producerUsage must be GRALLOC1_*_USAGE_NONE, and the other must be a991* CPU usage992* accessRegion - the portion of the buffer that the client intends to access;993* must be non-NULL994* outFlexLayout - will be filled with the description of the planes in the995* buffer996* acquireFence - a sync fence file descriptor as described in lock()997*998* Returns GRALLOC1_ERROR_NONE or one of the following errors:999* GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid1000* GRALLOC1_ERROR_BAD_VALUE - neither or both of producerUsage and1001* consumerUsage were *_USAGE_NONE, or the usage which was not1002* *_USAGE_NONE was not a CPU usage1003* GRALLOC1_ERROR_NO_RESOURCES - the buffer cannot be locked at this time, but1004* locking may succeed at a future time1005* GRALLOC1_ERROR_UNSUPPORTED - the buffer cannot be locked with the given1006* usage, and any future attempts at locking will also fail1007*/1008typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_LOCK_FLEX)(1009gralloc1_device_t* device, buffer_handle_t buffer,1010uint64_t /*gralloc1_producer_usage_t*/ producerUsage,1011uint64_t /*gralloc1_consumer_usage_t*/ consumerUsage,1012const gralloc1_rect_t* accessRegion,1013struct android_flex_layout* outFlexLayout, int32_t acquireFence);10141015/* unlock(..., buffer, releaseFence)1016* Function descriptor: GRALLOC1_FUNCTION_UNLOCK1017* Must be provided by all gralloc1 devices1018*1019* This function indicates to the device that the client will be done with the1020* buffer when releaseFence signals.1021*1022* outReleaseFence will be filled with a file descriptor referring to a release1023* sync fence object, which will be signaled when it is safe to access the1024* contents of the buffer (after the buffer has been unlocked). If it is already1025* safe to access the buffer contents, then -1 may be returned instead.1026*1027* This function is used to unlock both buffers locked by lock() and those1028* locked by lockFlex().1029*1030* Parameters:1031* buffer - the buffer to unlock1032* outReleaseFence - a sync fence file descriptor as described above1033*1034* Returns GRALLOC1_ERROR_NONE or one of the following errors:1035* GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid1036*/1037typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_UNLOCK)(1038gralloc1_device_t* device, buffer_handle_t buffer,1039int32_t* outReleaseFence);10401041__END_DECLS10421043#endif104410451046