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