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