blob: 67f0a0b96eb57997e193fd499abe880245627429 [file] [log] [blame]
Dan Stozaa2d5b7d2016-05-20 13:10:14 -07001/*
2 * Copyright 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_HARDWARE_GRALLOC1_H
18#define ANDROID_HARDWARE_GRALLOC1_H
19
20#include <hardware/hardware.h>
Dan Stozaa2d5b7d2016-05-20 13:10:14 -070021
22__BEGIN_DECLS
23
24#define GRALLOC_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
25#define GRALLOC_HARDWARE_MODULE_ID "gralloc"
26
27/*
28 * Enums
29 */
30
31typedef enum {
32 GRALLOC1_CAPABILITY_INVALID = 0,
33
34 /* If this capability is supported, then the outBuffers parameter to
35 * allocate may be NULL, which instructs the device to report whether the
36 * given allocation is possible or not. */
37 GRALLOC1_CAPABILITY_TEST_ALLOCATE = 1,
Chia-I Wu5cbf8f82017-03-20 13:18:48 -070038
Craig Donnerbe3802e2016-10-20 17:11:28 -070039 /* If this capability is supported, then the implementation supports
40 * allocating buffers with more than one image layer. */
41 GRALLOC1_CAPABILITY_LAYERED_BUFFERS = 2,
Chia-I Wu5cbf8f82017-03-20 13:18:48 -070042
43 /* If this capability is supported, then the implementation always closes
44 * and deletes a buffer handle whenever the last reference is removed.
45 *
46 * Supporting this capability is strongly recommended. It will become
47 * mandatory in future releases. */
48 GRALLOC1_CAPABILITY_RELEASE_IMPLY_DELETE = 3,
49
50 GRALLOC1_LAST_CAPABILITY = 3,
Dan Stozaa2d5b7d2016-05-20 13:10:14 -070051} gralloc1_capability_t;
52
53typedef enum {
54 GRALLOC1_CONSUMER_USAGE_NONE = 0,
55 GRALLOC1_CONSUMER_USAGE_CPU_READ_NEVER = 0,
56 /* 1ULL << 0 */
57 GRALLOC1_CONSUMER_USAGE_CPU_READ = 1ULL << 1,
58 GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN = 1ULL << 2 |
59 GRALLOC1_CONSUMER_USAGE_CPU_READ,
60 /* 1ULL << 3 */
61 /* 1ULL << 4 */
62 /* 1ULL << 5 */
63 /* 1ULL << 6 */
64 /* 1ULL << 7 */
65 GRALLOC1_CONSUMER_USAGE_GPU_TEXTURE = 1ULL << 8,
66 /* 1ULL << 9 */
67 /* 1ULL << 10 */
68 GRALLOC1_CONSUMER_USAGE_HWCOMPOSER = 1ULL << 11,
69 GRALLOC1_CONSUMER_USAGE_CLIENT_TARGET = 1ULL << 12,
70 /* 1ULL << 13 */
71 /* 1ULL << 14 */
72 GRALLOC1_CONSUMER_USAGE_CURSOR = 1ULL << 15,
73 GRALLOC1_CONSUMER_USAGE_VIDEO_ENCODER = 1ULL << 16,
74 /* 1ULL << 17 */
75 GRALLOC1_CONSUMER_USAGE_CAMERA = 1ULL << 18,
76 /* 1ULL << 19 */
77 GRALLOC1_CONSUMER_USAGE_RENDERSCRIPT = 1ULL << 20,
78
79 /* Indicates that the consumer may attach buffers to their end of the
80 * BufferQueue, which means that the producer may never have seen a given
81 * dequeued buffer before. May be ignored by the gralloc device. */
82 GRALLOC1_CONSUMER_USAGE_FOREIGN_BUFFERS = 1ULL << 21,
83
84 /* 1ULL << 22 */
Craig Donnerce405412017-01-12 15:52:02 -080085 GRALLOC1_CONSUMER_USAGE_GPU_DATA_BUFFER = 1ULL << 23,
Dan Stozaa2d5b7d2016-05-20 13:10:14 -070086 /* 1ULL << 24 */
87 /* 1ULL << 25 */
88 /* 1ULL << 26 */
89 /* 1ULL << 27 */
90
91 /* Bits reserved for implementation-specific usage flags */
92 GRALLOC1_CONSUMER_USAGE_PRIVATE_0 = 1ULL << 28,
93 GRALLOC1_CONSUMER_USAGE_PRIVATE_1 = 1ULL << 29,
94 GRALLOC1_CONSUMER_USAGE_PRIVATE_2 = 1ULL << 30,
95 GRALLOC1_CONSUMER_USAGE_PRIVATE_3 = 1ULL << 31,
96
97 /* 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 */
113
114 /* Bits reserved for implementation-specific usage flags */
115 GRALLOC1_CONSUMER_USAGE_PRIVATE_19 = 1ULL << 48,
116 GRALLOC1_CONSUMER_USAGE_PRIVATE_18 = 1ULL << 49,
117 GRALLOC1_CONSUMER_USAGE_PRIVATE_17 = 1ULL << 50,
118 GRALLOC1_CONSUMER_USAGE_PRIVATE_16 = 1ULL << 51,
119 GRALLOC1_CONSUMER_USAGE_PRIVATE_15 = 1ULL << 52,
120 GRALLOC1_CONSUMER_USAGE_PRIVATE_14 = 1ULL << 53,
121 GRALLOC1_CONSUMER_USAGE_PRIVATE_13 = 1ULL << 54,
122 GRALLOC1_CONSUMER_USAGE_PRIVATE_12 = 1ULL << 55,
123 GRALLOC1_CONSUMER_USAGE_PRIVATE_11 = 1ULL << 56,
124 GRALLOC1_CONSUMER_USAGE_PRIVATE_10 = 1ULL << 57,
125 GRALLOC1_CONSUMER_USAGE_PRIVATE_9 = 1ULL << 58,
126 GRALLOC1_CONSUMER_USAGE_PRIVATE_8 = 1ULL << 59,
127 GRALLOC1_CONSUMER_USAGE_PRIVATE_7 = 1ULL << 60,
128 GRALLOC1_CONSUMER_USAGE_PRIVATE_6 = 1ULL << 61,
129 GRALLOC1_CONSUMER_USAGE_PRIVATE_5 = 1ULL << 62,
130 GRALLOC1_CONSUMER_USAGE_PRIVATE_4 = 1ULL << 63,
131} gralloc1_consumer_usage_t;
132
133typedef enum {
134 GRALLOC1_FUNCTION_INVALID = 0,
135 GRALLOC1_FUNCTION_DUMP = 1,
136 GRALLOC1_FUNCTION_CREATE_DESCRIPTOR = 2,
137 GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR = 3,
138 GRALLOC1_FUNCTION_SET_CONSUMER_USAGE = 4,
139 GRALLOC1_FUNCTION_SET_DIMENSIONS = 5,
140 GRALLOC1_FUNCTION_SET_FORMAT = 6,
141 GRALLOC1_FUNCTION_SET_PRODUCER_USAGE = 7,
142 GRALLOC1_FUNCTION_GET_BACKING_STORE = 8,
143 GRALLOC1_FUNCTION_GET_CONSUMER_USAGE = 9,
144 GRALLOC1_FUNCTION_GET_DIMENSIONS = 10,
145 GRALLOC1_FUNCTION_GET_FORMAT = 11,
146 GRALLOC1_FUNCTION_GET_PRODUCER_USAGE = 12,
147 GRALLOC1_FUNCTION_GET_STRIDE = 13,
148 GRALLOC1_FUNCTION_ALLOCATE = 14,
149 GRALLOC1_FUNCTION_RETAIN = 15,
150 GRALLOC1_FUNCTION_RELEASE = 16,
151 GRALLOC1_FUNCTION_GET_NUM_FLEX_PLANES = 17,
152 GRALLOC1_FUNCTION_LOCK = 18,
153 GRALLOC1_FUNCTION_LOCK_FLEX = 19,
154 GRALLOC1_FUNCTION_UNLOCK = 20,
Craig Donnerbe3802e2016-10-20 17:11:28 -0700155 GRALLOC1_FUNCTION_SET_LAYER_COUNT = 21,
156 GRALLOC1_FUNCTION_GET_LAYER_COUNT = 22,
157 GRALLOC1_LAST_FUNCTION = 22,
Dan Stozaa2d5b7d2016-05-20 13:10:14 -0700158} gralloc1_function_descriptor_t;
159
160typedef enum {
161 GRALLOC1_ERROR_NONE = 0,
162 GRALLOC1_ERROR_BAD_DESCRIPTOR = 1,
163 GRALLOC1_ERROR_BAD_HANDLE = 2,
164 GRALLOC1_ERROR_BAD_VALUE = 3,
165 GRALLOC1_ERROR_NOT_SHARED = 4,
166 GRALLOC1_ERROR_NO_RESOURCES = 5,
167 GRALLOC1_ERROR_UNDEFINED = 6,
168 GRALLOC1_ERROR_UNSUPPORTED = 7,
169} gralloc1_error_t;
170
171typedef enum {
172 GRALLOC1_PRODUCER_USAGE_NONE = 0,
173 GRALLOC1_PRODUCER_USAGE_CPU_WRITE_NEVER = 0,
174 /* 1ULL << 0 */
175 GRALLOC1_PRODUCER_USAGE_CPU_READ = 1ULL << 1,
176 GRALLOC1_PRODUCER_USAGE_CPU_READ_OFTEN = 1ULL << 2 |
177 GRALLOC1_PRODUCER_USAGE_CPU_READ,
178 /* 1ULL << 3 */
179 /* 1ULL << 4 */
180 GRALLOC1_PRODUCER_USAGE_CPU_WRITE = 1ULL << 5,
181 GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN = 1ULL << 6 |
182 GRALLOC1_PRODUCER_USAGE_CPU_WRITE,
183 /* 1ULL << 7 */
184 /* 1ULL << 8 */
185 GRALLOC1_PRODUCER_USAGE_GPU_RENDER_TARGET = 1ULL << 9,
186 /* 1ULL << 10 */
187 /* 1ULL << 11 */
188 /* 1ULL << 12 */
189 /* 1ULL << 13 */
190
191 /* The consumer must have a hardware-protected path to an external display
192 * sink for this buffer. If a hardware-protected path is not available, then
193 * do not attempt to display this buffer. */
194 GRALLOC1_PRODUCER_USAGE_PROTECTED = 1ULL << 14,
195
196 /* 1ULL << 15 */
197 /* 1ULL << 16 */
198 GRALLOC1_PRODUCER_USAGE_CAMERA = 1ULL << 17,
199 /* 1ULL << 18 */
200 /* 1ULL << 19 */
201 /* 1ULL << 20 */
202 /* 1ULL << 21 */
203 GRALLOC1_PRODUCER_USAGE_VIDEO_DECODER = 1ULL << 22,
Craig Donnerce405412017-01-12 15:52:02 -0800204 GRALLOC1_PRODUCER_USAGE_SENSOR_DIRECT_DATA = 1ULL << 23,
Dan Stozaa2d5b7d2016-05-20 13:10:14 -0700205 /* 1ULL << 24 */
206 /* 1ULL << 25 */
207 /* 1ULL << 26 */
208 /* 1ULL << 27 */
209
210 /* Bits reserved for implementation-specific usage flags */
211 GRALLOC1_PRODUCER_USAGE_PRIVATE_0 = 1ULL << 28,
212 GRALLOC1_PRODUCER_USAGE_PRIVATE_1 = 1ULL << 29,
213 GRALLOC1_PRODUCER_USAGE_PRIVATE_2 = 1ULL << 30,
214 GRALLOC1_PRODUCER_USAGE_PRIVATE_3 = 1ULL << 31,
215
216 /* 1ULL << 32 */
217 /* 1ULL << 33 */
218 /* 1ULL << 34 */
219 /* 1ULL << 35 */
220 /* 1ULL << 36 */
221 /* 1ULL << 37 */
222 /* 1ULL << 38 */
223 /* 1ULL << 39 */
224 /* 1ULL << 40 */
225 /* 1ULL << 41 */
226 /* 1ULL << 42 */
227 /* 1ULL << 43 */
228 /* 1ULL << 44 */
229 /* 1ULL << 45 */
230 /* 1ULL << 46 */
231 /* 1ULL << 47 */
232
233 /* Bits reserved for implementation-specific usage flags */
234 GRALLOC1_PRODUCER_USAGE_PRIVATE_19 = 1ULL << 48,
235 GRALLOC1_PRODUCER_USAGE_PRIVATE_18 = 1ULL << 49,
236 GRALLOC1_PRODUCER_USAGE_PRIVATE_17 = 1ULL << 50,
237 GRALLOC1_PRODUCER_USAGE_PRIVATE_16 = 1ULL << 51,
238 GRALLOC1_PRODUCER_USAGE_PRIVATE_15 = 1ULL << 52,
239 GRALLOC1_PRODUCER_USAGE_PRIVATE_14 = 1ULL << 53,
240 GRALLOC1_PRODUCER_USAGE_PRIVATE_13 = 1ULL << 54,
241 GRALLOC1_PRODUCER_USAGE_PRIVATE_12 = 1ULL << 55,
242 GRALLOC1_PRODUCER_USAGE_PRIVATE_11 = 1ULL << 56,
243 GRALLOC1_PRODUCER_USAGE_PRIVATE_10 = 1ULL << 57,
244 GRALLOC1_PRODUCER_USAGE_PRIVATE_9 = 1ULL << 58,
245 GRALLOC1_PRODUCER_USAGE_PRIVATE_8 = 1ULL << 59,
246 GRALLOC1_PRODUCER_USAGE_PRIVATE_7 = 1ULL << 60,
247 GRALLOC1_PRODUCER_USAGE_PRIVATE_6 = 1ULL << 61,
248 GRALLOC1_PRODUCER_USAGE_PRIVATE_5 = 1ULL << 62,
249 GRALLOC1_PRODUCER_USAGE_PRIVATE_4 = 1ULL << 63,
250} gralloc1_producer_usage_t;
251
252/*
253 * Typedefs
254 */
255
256typedef void (*gralloc1_function_pointer_t)();
257
258typedef uint64_t gralloc1_backing_store_t;
259typedef uint64_t gralloc1_buffer_descriptor_t;
260
261/*
262 * Device Struct
263 */
264
265typedef struct gralloc1_device {
266 /* Must be the first member of this struct, since a pointer to this struct
267 * will be generated by casting from a hw_device_t* */
268 struct hw_device_t common;
269
270 /* getCapabilities(..., outCount, outCapabilities)
271 *
272 * Provides a list of capabilities (described in the definition of
273 * gralloc1_capability_t above) supported by this device. This list must not
274 * change after the device has been loaded.
275 *
276 * Parameters:
277 * outCount - if outCapabilities was NULL, the number of capabilities
278 * which would have been returned; if outCapabilities was not NULL,
279 * the number of capabilities returned, which must not exceed the
280 * value stored in outCount prior to the call
281 * outCapabilities - a list of capabilities supported by this device; may
282 * be NULL, in which case this function must write into outCount the
283 * number of capabilities which would have been written into
284 * outCapabilities
285 */
286 void (*getCapabilities)(struct gralloc1_device* device, uint32_t* outCount,
287 int32_t* /*gralloc1_capability_t*/ outCapabilities);
288
289 /* getFunction(..., descriptor)
290 *
291 * Returns a function pointer which implements the requested description.
292 *
293 * Parameters:
294 * descriptor - the function to return
295 *
296 * Returns either a function pointer implementing the requested descriptor
297 * or NULL if the described function is not supported by this device.
298 */
299 gralloc1_function_pointer_t (*getFunction)(struct gralloc1_device* device,
300 int32_t /*gralloc1_function_descriptor_t*/ descriptor);
301} gralloc1_device_t;
302
303static inline int gralloc1_open(const struct hw_module_t* module,
304 gralloc1_device_t** device) {
305 return module->methods->open(module, GRALLOC_HARDWARE_MODULE_ID,
Colin Crosscc8d9f92016-10-06 16:44:23 -0700306 TO_HW_DEVICE_T_OPEN(device));
Dan Stozaa2d5b7d2016-05-20 13:10:14 -0700307}
308
309static inline int gralloc1_close(gralloc1_device_t* device) {
310 return device->common.close(&device->common);
311}
312
313/* dump(..., outSize, outBuffer)
314 * Function descriptor: GRALLOC1_FUNCTION_DUMP
315 * Must be provided by all gralloc1 devices
316 *
317 * Retrieves implementation-defined debug information, which will be displayed
318 * during, for example, `dumpsys SurfaceFlinger`.
319 *
320 * If called with outBuffer == NULL, the device should store a copy of the
321 * desired output and return its length in bytes in outSize. If the device
322 * already has a stored copy, that copy should be purged and replaced with a
323 * fresh copy.
324 *
325 * If called with outBuffer != NULL, the device should copy its stored version
326 * of the output into outBuffer and store how many bytes of data it copied into
327 * outSize. Prior to this call, the client will have populated outSize with the
328 * maximum number of bytes outBuffer can hold. The device must not write more
329 * than this amount into outBuffer. If the device does not currently have a
330 * stored copy, then it should return 0 in outSize.
331 *
332 * Any data written into outBuffer need not be null-terminated.
333 *
334 * Parameters:
335 * outSize - if outBuffer was NULL, the number of bytes needed to copy the
336 * device's stored output; if outBuffer was not NULL, the number of bytes
337 * written into it, which must not exceed the value stored in outSize
338 * prior to the call; pointer will be non-NULL
339 * outBuffer - the buffer to write the dump output into; may be NULL as
340 * described above; data written into this buffer need not be
341 * null-terminated
342 */
343typedef void (*GRALLOC1_PFN_DUMP)(gralloc1_device_t* device, uint32_t* outSize,
344 char* outBuffer);
345
346/*
347 * Buffer descriptor lifecycle functions
348 *
349 * All of these functions take as their first parameter a device pointer, so
350 * this parameter is omitted from the described parameter lists.
351 */
352
353/* createDescriptor(..., outDescriptor)
354 * Function descriptor: GRALLOC1_FUNCTION_CREATE_DESCRIPTOR
355 * Must be provided by all gralloc1 devices
356 *
357 * Creates a new, empty buffer descriptor.
358 *
359 * Parameters:
360 * outDescriptor - the new buffer descriptor
361 *
362 * Returns GRALLOC1_ERROR_NONE or one of the following errors:
363 * GRALLOC1_ERROR_NO_RESOURCES - no more descriptors can currently be created
364 */
365typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_CREATE_DESCRIPTOR)(
366 gralloc1_device_t* device, gralloc1_buffer_descriptor_t* outDescriptor);
367
368/* destroyDescriptor(..., descriptor)
369 * Function descriptor: GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR
370 * Must be provided by all gralloc1 devices
371 *
372 * Destroys an existing buffer descriptor.
373 *
374 * Parameters:
375 * descriptor - the buffer descriptor to destroy
376 *
377 * Returns GRALLOC1_ERROR_NONE or one of the following errors:
378 * GRALLOC1_ERROR_BAD_DESCRIPTOR - descriptor does not refer to a valid
379 * buffer descriptor
380 */
381typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_DESTROY_DESCRIPTOR)(
382 gralloc1_device_t* device, gralloc1_buffer_descriptor_t descriptor);
383
384/*
385 * Buffer descriptor modification functions
386 *
387 * All of these functions take as their first two parameters a device pointer
388 * and a buffer descriptor, so these parameters are omitted from the described
389 * parameter lists.
390 */
391
392/* setConsumerUsage(..., usage)
393 * Function descriptor: GRALLOC1_FUNCTION_SET_CONSUMER_USAGE
394 * Must be provided by all gralloc1 devices
395 *
396 * Sets the desired consumer usage flags of the buffer.
397 *
398 * Valid usage flags can be found in the definition of gralloc1_consumer_usage_t
399 * above.
400 *
401 * Parameters:
402 * usage - the desired consumer usage flags
403 *
404 * Returns GRALLOC1_ERROR_NONE or one of the following errors:
405 * GRALLOC1_ERROR_BAD_DESCRIPTOR - the buffer descriptor is invalid
406 * GRALLOC1_ERROR_BAD_VALUE - an invalid usage flag was passed in
407 */
408typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_SET_CONSUMER_USAGE)(
409 gralloc1_device_t* device, gralloc1_buffer_descriptor_t descriptor,
410 uint64_t /*gralloc1_consumer_usage_t*/ usage);
411
412/* setDimensions(..., width, height)
413 * Function descriptor: GRALLOC1_FUNCTION_SET_DIMENSIONS
414 * Must be provided by all gralloc1 devices
415 *
416 * Sets the desired width and height of the buffer in pixels.
417 *
418 * The width specifies how many columns of pixels should be in the allocated
419 * buffer, but does not necessarily represent the offset in columns between the
420 * same column in adjacent rows. If this offset is required, consult getStride
421 * below.
422 *
423 * The height specifies how many rows of pixels should be in the allocated
424 * buffer.
425 *
426 * Parameters:
427 * width - the desired width in pixels
428 * height - the desired height in pixels
429 *
430 * Returns GRALLOC1_ERROR_NONE or one of the following errors:
431 * GRALLOC1_ERROR_BAD_DESCRIPTOR - the buffer descriptor is invalid
432 */
433typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_SET_DIMENSIONS)(
434 gralloc1_device_t* device, gralloc1_buffer_descriptor_t descriptor,
435 uint32_t width, uint32_t height);
436
437/* setFormat(..., format)
438 * Function descriptor: GRALLOC1_FUNCTION_SET_FORMAT
439 * Must be provided by all gralloc1 devices
440 *
441 * Sets the desired format of the buffer.
442 *
443 * The valid formats can be found in <system/graphics.h>.
444 *
445 * Parameters:
446 * format - the desired format
447 *
448 * Returns GRALLOC1_ERROR_NONE or one of the following errors:
449 * GRALLOC1_ERROR_BAD_DESCRIPTOR - the buffer descriptor is invalid
450 * GRALLOC1_ERROR_BAD_VALUE - format is invalid
451 */
452typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_SET_FORMAT)(
453 gralloc1_device_t* device, gralloc1_buffer_descriptor_t descriptor,
454 int32_t /*android_pixel_format_t*/ format);
455
Craig Donnerbe3802e2016-10-20 17:11:28 -0700456/* setLayerCount(..., layerCount)
457 * Function descriptor: GRALLOC1_FUNCTION_SET_LAYER_COUNT
458 * Must be provided by all gralloc1 devices that provide the
459 * GRALLOC1_CAPABILITY_LAYERED_BUFFERS capability.
460 *
461 * Sets the number of layers in the buffer.
462 *
463 * A buffer with multiple layers may be used as the backing store of an array
464 * texture. All layers of a buffer share the same characteristics (e.g.,
465 * dimensions, format, usage). Devices that do not support
466 * GRALLOC1_CAPABILITY_LAYERED_BUFFERS must allocate only buffers with a single
467 * layer.
468 *
469 * Parameters:
470 * layerCount - the desired number of layers, must be non-zero
471 *
472 * Returns GRALLOC1_ERROR_NONE or one of the following errors:
473 * GRALLOC1_ERROR_BAD_DESCRIPTOR - the buffer descriptor is invalid
474 * GRALLOC1_ERROR_BAD_VALUE - the layer count is invalid
475 */
476typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_SET_LAYER_COUNT)(
477 gralloc1_device_t* device, gralloc1_buffer_descriptor_t descriptor,
478 uint32_t layerCount);
479
Dan Stozaa2d5b7d2016-05-20 13:10:14 -0700480/* setProducerUsage(..., usage)
481 * Function descriptor: GRALLOC1_FUNCTION_SET_PRODUCER_USAGE
482 * Must be provided by all gralloc1 devices
483 *
484 * Sets the desired producer usage flags of the buffer.
485 *
486 * Valid usage flags can be found in the definition of gralloc1_producer_usage_t
487 * above.
488 *
489 * Parameters:
490 * usage - the desired producer usage flags
491 *
492 * Returns GRALLOC1_ERROR_NONE or one of the following errors:
493 * GRALLOC1_ERROR_BAD_DESCRIPTOR - the buffer descriptor is invalid
494 * GRALLOC1_ERROR_BAD_VALUE - an invalid usage flag was passed in
495 */
496typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_SET_PRODUCER_USAGE)(
497 gralloc1_device_t* device, gralloc1_buffer_descriptor_t descriptor,
498 uint64_t /*gralloc1_producer_usage_t*/ usage);
499
500/*
501 * Buffer handle query functions
502 *
503 * All of these functions take as their first two parameters a device pointer
504 * and a buffer handle, so these parameters are omitted from the described
505 * parameter lists.
506 *
507 * [1] Currently many of these functions may return GRALLOC1_ERROR_UNSUPPORTED,
508 * which means that the device is not able to retrieve the requested information
509 * from the buffer. This is necessary to enable a smooth transition from earlier
510 * versions of the gralloc HAL, but gralloc1 implementers are strongly
511 * discouraged from returning this value, as future versions of the platform
512 * code will require all of these functions to succeed given a valid handle.
513 */
514
515/* getBackingStore(..., outStore)
516 * Function descriptor: GRALLOC1_FUNCTION_GET_BACKING_STORE
517 * Must be provided by all gralloc1 devices
518 *
519 * Gets a value that uniquely identifies the backing store of the given buffer.
520 *
521 * Buffers which share a backing store should return the same value from this
522 * function. If the buffer is present in more than one process, the backing
523 * store value for that buffer is not required to be the same in every process.
524 *
525 * Parameters:
526 * outStore - the backing store identifier for this buffer
527 *
528 * Returns GRALLOC1_ERROR_NONE or one of the following errors:
529 * GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid
530 * GRALLOC1_ERROR_UNSUPPORTED - the device is unable to retrieve the
531 * backing store identifier from the buffer; see note [1] in this
532 * section's header for more information
533 */
534typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_GET_BACKING_STORE)(
535 gralloc1_device_t* device, buffer_handle_t buffer,
536 gralloc1_backing_store_t* outStore);
537
538/* getConsumerUsage(..., outUsage)
539 * Function descriptor: GRALLOC1_FUNCTION_GET_CONSUMER_USAGE
540 * Must be provided by all gralloc1 devices
541 *
542 * Gets the consumer usage flags which were used to allocate this buffer.
543 *
544 * Usage flags can be found in the definition of gralloc1_consumer_usage_t above
545 *
546 * Parameters:
547 * outUsage - the consumer usage flags used to allocate this buffer; must be
548 * non-NULL
549 *
550 * Returns GRALLOC1_ERROR_NONE or one of the following errors:
551 * GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid
552 * GRALLOC1_ERROR_UNSUPPORTED - the device is unable to retrieve the
553 * dimensions from the buffer; see note [1] in this section's header for
554 * more information
555 */
556typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_GET_CONSUMER_USAGE)(
557 gralloc1_device_t* device, buffer_handle_t buffer,
558 uint64_t* /*gralloc1_consumer_usage_t*/ outUsage);
559
560/* getDimensions(..., outWidth, outHeight)
561 * Function descriptor: GRALLOC1_FUNCTION_GET_DIMENSIONS
562 * Must be provided by all gralloc1 devices
563 *
564 * Gets the width and height of the buffer in pixels.
565 *
566 * See setDimensions for more information about these values.
567 *
568 * Parameters:
569 * outWidth - the width of the buffer in pixels, must be non-NULL
570 * outHeight - the height of the buffer in pixels, must be non-NULL
571 *
572 * Returns GRALLOC1_ERROR_NONE or one of the following errors:
573 * GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid
574 * GRALLOC1_ERROR_UNSUPPORTED - the device is unable to retrieve the
575 * dimensions from the buffer; see note [1] in this section's header for
576 * more information
577 */
578typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_GET_DIMENSIONS)(
579 gralloc1_device_t* device, buffer_handle_t buffer, uint32_t* outWidth,
580 uint32_t* outHeight);
581
582/* getFormat(..., outFormat)
583 * Function descriptor: GRALLOC1_FUNCTION_GET_FORMAT
584 * Must be provided by all gralloc1 devices
585 *
586 * Gets the format of the buffer.
587 *
588 * The valid formats can be found in the HAL_PIXEL_FORMAT_* enum in
589 * system/graphics.h.
590 *
591 * Parameters:
592 * outFormat - the format of the buffer; must be non-NULL
593 *
594 * Returns GRALLOC1_ERROR_NONE or one of the following errors:
595 * GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid
596 * GRALLOC1_ERROR_UNSUPPORTED - the device is unable to retrieve the format
597 * from the buffer; see note [1] in this section's header for more
598 * information
599 */
600typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_GET_FORMAT)(
601 gralloc1_device_t* device, buffer_handle_t descriptor,
602 int32_t* outFormat);
603
Craig Donnerbe3802e2016-10-20 17:11:28 -0700604/* getLayerCount(..., outLayerCount)
605 * Function descriptor: GRALLOC1_FUNCTION_GET_LAYER_COUNT
606 * Must be provided by all gralloc1 devices that provide the
607 * GRALLOC1_CAPABILITY_LAYERED_BUFFERS capability.
608 *
609 * Gets the number of layers of the buffer.
610 *
611 * See setLayerCount for more information about this value.
612 *
613 * Parameters:
614 * outLayerCount - the number of layers in the image, must be non-NULL
615 *
616 * Returns GRALLOC1_ERROR_NONE or one of the following errors:
617 * GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid
618 * GRALLOC1_ERROR_UNSUPPORTED - the device is unable to retrieve the
619 * layer count from the buffer; see note [1] in this section's header for
620 * more information
621 */
622typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_GET_LAYER_COUNT)(
623 gralloc1_device_t* device, buffer_handle_t buffer,
624 uint32_t* outLayerCount);
625
Dan Stozaa2d5b7d2016-05-20 13:10:14 -0700626/* getProducerUsage(..., outUsage)
627 * Function descriptor: GRALLOC1_FUNCTION_GET_PRODUCER_USAGE
628 * Must be provided by all gralloc1 devices
629 *
630 * Gets the producer usage flags which were used to allocate this buffer.
631 *
632 * Usage flags can be found in the definition of gralloc1_producer_usage_t above
633 *
634 * Parameters:
635 * outUsage - the producer usage flags used to allocate this buffer; must be
636 * non-NULL
637 *
638 * Returns GRALLOC1_ERROR_NONE or one of the following errors:
639 * GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid
640 * GRALLOC1_ERROR_UNSUPPORTED - the device is unable to retrieve the usage
641 * from the buffer; see note [1] in this section's header for more
642 * information
643 */
644typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_GET_PRODUCER_USAGE)(
645 gralloc1_device_t* device, buffer_handle_t buffer,
646 uint64_t* /*gralloc1_producer_usage_t*/ outUsage);
647
648/* getStride(..., outStride)
649 * Function descriptor: GRALLOC1_FUNCTION_GET_STRIDE
650 * Must be provided by all gralloc1 devices
651 *
652 * Gets the stride of the buffer in pixels.
653 *
654 * The stride is the offset in pixel-sized elements between the same column in
655 * two adjacent rows of pixels. This may not be equal to the width of the
656 * buffer.
657 *
658 * Parameters:
659 * outStride - the stride in pixels; must be non-NULL
660 *
661 * Returns GRALLOC1_ERROR_NONE or one of the following errors:
662 * GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid
663 * GRALLOC1_ERROR_UNDEFINED - the notion of a stride is not meaningful for
664 * this format
665 * GRALLOC1_ERROR_UNSUPPORTED - the device is unable to retrieve the stride
666 * from the descriptor; see note [1] in this section's header for more
667 * information
668 */
669typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_GET_STRIDE)(
670 gralloc1_device_t* device, buffer_handle_t buffer, uint32_t* outStride);
671
672/*
673 * Buffer management functions
674 */
675
676/* allocate(..., numDescriptors, descriptors, outBuffers)
677 * Function descriptor: GRALLOC1_FUNCTION_ALLOCATE
678 * Must be provided by all gralloc1 devices
679 *
680 * Attempts to allocate a number of buffers sharing a backing store.
681 *
682 * Each buffer will correspond to one of the descriptors passed into the
683 * function. If the device is unable to share the backing store between the
684 * buffers, it should attempt to allocate the buffers with different backing
685 * stores and return GRALLOC1_ERROR_NOT_SHARED if it is successful.
686 *
687 * If this call is successful, the client is responsible for freeing the
688 * buffer_handle_t using release() when it is finished with the buffer. It is
689 * not necessary to call retain() on the returned buffers, as they must have a
690 * reference added by the device before returning.
691 *
692 * If GRALLOC1_CAPABILITY_TEST_ALLOCATE is supported by this device, outBuffers
693 * may be NULL. In this case, the device must not attempt to allocate any
694 * buffers, but instead must return either GRALLOC1_ERROR_NONE if such an
695 * allocation is possible (ignoring potential resource contention which might
696 * lead to a GRALLOC1_ERROR_NO_RESOURCES error), GRALLOC1_ERROR_NOT_SHARED if
697 * the buffers can be allocated, but cannot share a backing store, or
698 * GRALLOC1_ERROR_UNSUPPORTED if one or more of the descriptors can never be
699 * allocated by the device.
700 *
701 * Parameters:
702 * numDescriptors - the number of buffer descriptors, which must also be equal
703 * to the size of the outBuffers array
704 * descriptors - the buffer descriptors to attempt to allocate
705 * outBuffers - the allocated buffers; must be non-NULL unless the device
706 * supports GRALLOC1_CAPABILITY_TEST_ALLOCATE (see above), and must not be
707 * modified by the device if allocation is unsuccessful
708 *
709 * Returns GRALLOC1_ERROR_NONE or one of the following errors:
710 * GRALLOC1_ERROR_BAD_DESCRIPTOR - one of the descriptors does not refer to a
711 * valid buffer descriptor
712 * GRALLOC1_ERROR_NOT_SHARED - allocation was successful, but required more
713 * than one backing store to satisfy all of the buffer descriptors
714 * GRALLOC1_ERROR_NO_RESOURCES - allocation failed because one or more of the
715 * backing stores could not be created at this time (but this allocation
716 * might succeed at a future time)
717 * GRALLOC1_ERROR_UNSUPPORTED - one or more of the descriptors can never be
718 * satisfied by the device
719 */
720typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_ALLOCATE)(
721 gralloc1_device_t* device, uint32_t numDescriptors,
722 const gralloc1_buffer_descriptor_t* descriptors,
723 buffer_handle_t* outBuffers);
724
725/* retain(..., buffer)
726 * Function descriptor: GRALLOC1_FUNCTION_RETAIN
727 * Must be provided by all gralloc1 devices
728 *
729 * Adds a reference to the given buffer.
730 *
731 * This function must be called when a buffer_handle_t is received from a remote
732 * process to prevent the buffer's data from being freed when the remote process
733 * releases the buffer. It may also be called to increase the reference count if
734 * two components in the same process want to interact with the buffer
735 * independently.
736 *
737 * Parameters:
738 * buffer - the buffer to which a reference should be added
739 *
740 * Returns GRALLOC1_ERROR_NONE or one of the following errors:
741 * GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid
742 * GRALLOC1_ERROR_NO_RESOURCES - it is not possible to add a reference to this
743 * buffer at this time
744 */
745typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_RETAIN)(
746 gralloc1_device_t* device, buffer_handle_t buffer);
747
748/* release(..., buffer)
749 * Function descriptor: GRALLOC1_FUNCTION_RELEASE
750 * Must be provided by all gralloc1 devices
751 *
752 * Removes a reference from the given buffer.
753 *
754 * If no references remain, the buffer should be freed. When the last buffer
755 * referring to a particular backing store is freed, that backing store should
756 * also be freed.
757 *
Chia-I Wu5cbf8f82017-03-20 13:18:48 -0700758 * When GRALLOC1_CAPABILITY_RELEASE_IMPLY_DELETE is supported,
759 * native_handle_close and native_handle_delete must always be called by the
760 * implementation whenever the last reference is removed. Otherwise, a call
761 * to release() will be followed by native_handle_close and native_handle_delete
762 * by the caller when the buffer is not allocated locally through allocate().
763 *
Dan Stozaa2d5b7d2016-05-20 13:10:14 -0700764 * Parameters:
765 * buffer - the buffer from which a reference should be removed
766 *
767 * Returns GRALLOC1_ERROR_NONE or one of the following errors:
768 * GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid
769 */
770typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_RELEASE)(
771 gralloc1_device_t* device, buffer_handle_t buffer);
772
773/*
774 * Buffer access functions
775 *
776 * All of these functions take as their first parameter a device pointer, so
777 * this parameter is omitted from the described parameter lists.
778 */
779
780typedef struct gralloc1_rect {
781 int32_t left;
782 int32_t top;
783 int32_t width;
784 int32_t height;
785} gralloc1_rect_t;
786
787/* getNumFlexPlanes(..., buffer, outNumPlanes)
788 * Function descriptor: GRALLOC1_FUNCTION_GET_NUM_FLEX_PLANES
789 * Must be provided by all gralloc1 devices
790 *
791 * Returns the number of flex layout planes which are needed to represent the
792 * given buffer. This may be used to efficiently allocate only as many plane
793 * structures as necessary before calling into lockFlex.
794 *
795 * If the given buffer cannot be locked as a flex format, this function may
796 * return GRALLOC1_ERROR_UNSUPPORTED (as lockFlex would).
797 *
798 * Parameters:
799 * buffer - the buffers for which the number of planes should be queried
800 * outNumPlanes - the number of flex planes required to describe the given
801 * buffer; must be non-NULL
802 *
803 * Returns GRALLOC1_ERROR_NONE or one of the following errors:
804 * GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid
805 * GRALLOC1_ERROR_UNSUPPORTED - the buffer's format cannot be represented in a
806 * flex layout
807 */
808typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_GET_NUM_FLEX_PLANES)(
809 gralloc1_device_t* device, buffer_handle_t buffer,
810 uint32_t* outNumPlanes);
811
812/* lock(..., buffer, producerUsage, consumerUsage, accessRegion, outData,
813 * acquireFence)
814 * Function descriptor: GRALLOC1_FUNCTION_LOCK
815 * Must be provided by all gralloc1 devices
816 *
817 * Locks the given buffer for the specified CPU usage.
818 *
819 * Exactly one of producerUsage and consumerUsage must be *_USAGE_NONE. The
820 * usage which is not *_USAGE_NONE must be one of the *_USAGE_CPU_* values, as
821 * applicable. Locking a buffer for a non-CPU usage is not supported.
822 *
823 * Locking the same buffer simultaneously from multiple threads is permitted,
824 * but if any of the threads attempt to lock the buffer for writing, the
825 * behavior is undefined, except that it must not cause process termination or
826 * block the client indefinitely. Leaving the buffer content in an indeterminate
827 * state or returning an error are both acceptable.
828 *
829 * The client must not modify the content of the buffer outside of accessRegion,
830 * and the device need not guarantee that content outside of accessRegion is
831 * valid for reading. The result of reading or writing outside of accessRegion
832 * is undefined, except that it must not cause process termination.
833 *
834 * outData must be a non-NULL pointer, the contents of which which will be
835 * filled with a pointer to the locked buffer memory. This address will
836 * represent the top-left corner of the entire buffer, even if accessRegion does
837 * not begin at the top-left corner.
838 *
839 * acquireFence is a file descriptor referring to a acquire sync fence object,
840 * which will be signaled when it is safe for the device to access the contents
841 * of the buffer (prior to locking). If it is already safe to access the buffer
842 * contents, -1 may be passed instead.
843 *
844 * Parameters:
845 * buffer - the buffer to lock
846 * producerUsage - the producer usage flags to request; either this or
847 * consumerUsage must be GRALLOC1_*_USAGE_NONE, and the other must be a
848 * CPU usage
849 * consumerUsage - the consumer usage flags to request; either this or
850 * producerUsage must be GRALLOC1_*_USAGE_NONE, and the other must be a
851 * CPU usage
852 * accessRegion - the portion of the buffer that the client intends to access;
853 * must be non-NULL
854 * outData - will be filled with a CPU-accessible pointer to the buffer data;
855 * must be non-NULL
856 * acquireFence - a sync fence file descriptor as described above
857 *
858 * Returns GRALLOC1_ERROR_NONE or one of the following errors:
859 * GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid
860 * GRALLOC1_ERROR_BAD_VALUE - neither or both of producerUsage and
861 * consumerUsage were GRALLOC1_*_USAGE_NONE, or the usage which was not
862 * *_USAGE_NONE was not a CPU usage
863 * GRALLOC1_ERROR_NO_RESOURCES - the buffer cannot be locked at this time, but
864 * locking may succeed at a future time
865 * GRALLOC1_ERROR_UNSUPPORTED - the buffer cannot be locked with the given
866 * usage, and any future attempts at locking will also fail
867 */
868typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_LOCK)(
869 gralloc1_device_t* device, buffer_handle_t buffer,
870 uint64_t /*gralloc1_producer_usage_t*/ producerUsage,
871 uint64_t /*gralloc1_consumer_usage_t*/ consumerUsage,
872 const gralloc1_rect_t* accessRegion, void** outData,
873 int32_t acquireFence);
874
875/* lockFlex(..., buffer, producerUsage, consumerUsage, accessRegion,
876 * outFlexLayout, outAcquireFence)
877 * Function descriptor: GRALLOC1_FUNCTION_LOCK_FLEX
878 * Must be provided by all gralloc1 devices
879 *
880 * This is largely the same as lock(), except that instead of returning a
881 * pointer directly to the buffer data, it returns an android_flex_layout
882 * struct describing how to access the data planes.
883 *
884 * This function must work on buffers with HAL_PIXEL_FORMAT_YCbCr_*_888 if
885 * supported by the device, as well as with any other formats requested by
886 * multimedia codecs when they are configured with a flexible-YUV-compatible
887 * color format.
888 *
889 * This function may also be called on buffers of other formats, including
890 * non-YUV formats, but if the buffer format is not compatible with a flexible
891 * representation, it may return GRALLOC1_ERROR_UNSUPPORTED.
892 *
893 * Parameters:
894 * buffer - the buffer to lock
895 * producerUsage - the producer usage flags to request; either this or
896 * consumerUsage must be GRALLOC1_*_USAGE_NONE, and the other must be a
897 * CPU usage
898 * consumerUsage - the consumer usage flags to request; either this or
899 * producerUsage must be GRALLOC1_*_USAGE_NONE, and the other must be a
900 * CPU usage
901 * accessRegion - the portion of the buffer that the client intends to access;
902 * must be non-NULL
903 * outFlexLayout - will be filled with the description of the planes in the
904 * buffer
905 * acquireFence - a sync fence file descriptor as described in lock()
906 *
907 * Returns GRALLOC1_ERROR_NONE or one of the following errors:
908 * GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid
909 * GRALLOC1_ERROR_BAD_VALUE - neither or both of producerUsage and
910 * consumerUsage were *_USAGE_NONE, or the usage which was not
911 * *_USAGE_NONE was not a CPU usage
912 * GRALLOC1_ERROR_NO_RESOURCES - the buffer cannot be locked at this time, but
913 * locking may succeed at a future time
914 * GRALLOC1_ERROR_UNSUPPORTED - the buffer cannot be locked with the given
915 * usage, and any future attempts at locking will also fail
916 */
917typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_LOCK_FLEX)(
918 gralloc1_device_t* device, buffer_handle_t buffer,
919 uint64_t /*gralloc1_producer_usage_t*/ producerUsage,
920 uint64_t /*gralloc1_consumer_usage_t*/ consumerUsage,
921 const gralloc1_rect_t* accessRegion,
922 struct android_flex_layout* outFlexLayout, int32_t acquireFence);
923
924/* unlock(..., buffer, releaseFence)
925 * Function descriptor: GRALLOC1_FUNCTION_UNLOCK
926 * Must be provided by all gralloc1 devices
927 *
928 * This function indicates to the device that the client will be done with the
929 * buffer when releaseFence signals.
930 *
931 * outReleaseFence will be filled with a file descriptor referring to a release
932 * sync fence object, which will be signaled when it is safe to access the
933 * contents of the buffer (after the buffer has been unlocked). If it is already
934 * safe to access the buffer contents, then -1 may be returned instead.
935 *
936 * This function is used to unlock both buffers locked by lock() and those
937 * locked by lockFlex().
938 *
939 * Parameters:
940 * buffer - the buffer to unlock
941 * outReleaseFence - a sync fence file descriptor as described above
942 *
943 * Returns GRALLOC1_ERROR_NONE or one of the following errors:
944 * GRALLOC1_ERROR_BAD_HANDLE - the buffer handle is invalid
945 */
946typedef int32_t /*gralloc1_error_t*/ (*GRALLOC1_PFN_UNLOCK)(
947 gralloc1_device_t* device, buffer_handle_t buffer,
948 int32_t* outReleaseFence);
949
950__END_DECLS
951
952#endif