blob: 298f31ed5697818d7572e1fea2fcf37d54f3b579 [file] [log] [blame]
Marissa Wall65341642019-06-20 13:21:06 -07001/*
2 * Copyright 2019 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
17package android.hardware.graphics.mapper@4.0;
18
19import android.hardware.graphics.common@1.2::BufferUsage;
20import android.hardware.graphics.common@1.2::PixelFormat;
21import android.hardware.graphics.common@1.2::Rect;
22
23interface IMapper {
24 struct BufferDescriptorInfo {
25 /**
Marissa Wallbf9f6d32019-11-05 14:58:52 -080026 * The name of the buffer. Useful for debugging/tracing.
27 */
28 string name;
29
30 /**
Marissa Wall65341642019-06-20 13:21:06 -070031 * The width specifies how many columns of pixels must be in the
32 * allocated buffer, but does not necessarily represent the offset in
33 * columns between the same column in adjacent rows. The rows may be
34 * padded.
35 */
36 uint32_t width;
37
Marissa Wall88d87fa2019-11-05 14:57:51 -080038 /**
39 * The height specifies how many rows of pixels must be in the
40 * allocated buffer.
41 */
Marissa Wall65341642019-06-20 13:21:06 -070042 uint32_t height;
43
Marissa Wall88d87fa2019-11-05 14:57:51 -080044 /**
45 * The number of image layers that must be in the allocated buffer.
46 */
Marissa Wall65341642019-06-20 13:21:06 -070047 uint32_t layerCount;
48
Marissa Wall88d87fa2019-11-05 14:57:51 -080049 /**
50 * Buffer pixel format.
51 */
Marissa Wall65341642019-06-20 13:21:06 -070052 PixelFormat format;
53
54 /**
55 * Buffer usage mask; valid flags can be found in the definition of
56 * BufferUsage.
57 */
58 bitfield<BufferUsage> usage;
59 };
60
61 struct Rect {
62 int32_t left;
63 int32_t top;
64 int32_t width;
65 int32_t height;
66 };
67
68 /**
69 * Creates a buffer descriptor. The descriptor can be used with IAllocator
70 * to allocate buffers.
71 *
72 * Since the buffer descriptor fully describes a buffer, any device
73 * dependent or device independent checks must be performed here whenever
74 * possible. Specifically, when layered buffers are not supported, this
75 * function must return `UNSUPPORTED` if `description.layers` is great than
76 * 1.
77 *
78 * @param description Attributes of the descriptor.
79 * @return error Error status of the call, which may be
80 * - `NONE` upon success.
81 * - `BAD_VALUE` if any of the specified attributes are invalid or
82 * inconsistent.
83 * - `NO_RESOURCES` if the creation cannot be fullfilled due to
84 * unavailability of resources.
85 * - `UNSUPPORTED` when any of the specified attributes are not
86 * supported.
87 * @return descriptor Newly created buffer descriptor.
88 */
89 createDescriptor(BufferDescriptorInfo description)
90 generates (Error error,
91 BufferDescriptor descriptor);
92
93 /**
94 * Imports a raw buffer handle to create an imported buffer handle for use
95 * with the rest of the mapper or with other in-process libraries.
96 *
97 * A buffer handle is considered raw when it is cloned (e.g., with
98 * `native_handle_clone()`) from another buffer handle locally, or when it
99 * is received from another HAL server/client or another process. A raw
100 * buffer handle must not be used to access the underlying graphic
101 * buffer. It must be imported to create an imported handle first.
102 *
103 * This function must at least validate the raw handle before creating the
104 * imported handle. It must also support importing the same raw handle
105 * multiple times to create multiple imported handles. The imported handle
106 * must be considered valid everywhere in the process, including in
107 * another instance of the mapper.
108 *
109 * Because of passthrough HALs, a raw buffer handle received from a HAL
110 * may actually have been imported in the process. importBuffer() must treat
111 * such a handle as if it is raw and must not return `BAD_BUFFER`. The
112 * returned handle is independent from the input handle as usual, and
113 * freeBuffer() must be called on it when it is no longer needed.
114 *
115 * @param rawHandle Raw buffer handle to import.
116 * @return error Error status of the call, which may be
117 * - `NONE` upon success.
118 * - `BAD_BUFFER` if the raw handle is invalid.
119 * - `NO_RESOURCES` if the raw handle cannot be imported due to
120 * unavailability of resources.
121 * @return buffer Imported buffer handle that has the type
122 * `buffer_handle_t` which is a handle type.
123 */
124 importBuffer(handle rawHandle) generates (Error error, pointer buffer);
125
126 /**
127 * Frees a buffer handle. Buffer handles returned by importBuffer() must be
128 * freed with this function when no longer needed.
129 *
130 * This function must free up all resources allocated by importBuffer() for
131 * the imported handle. For example, if the imported handle was created
132 * with `native_handle_create()`, this function must call
133 * `native_handle_close()` and `native_handle_delete()`.
134 *
135 * @param buffer Imported buffer handle.
136 * @return error Error status of the call, which may be
137 * - `NONE` upon success.
138 * - `BAD_BUFFER` if the buffer is invalid.
139 */
140 freeBuffer(pointer buffer) generates (Error error);
141
142 /**
143 * Validates that the buffer can be safely accessed by a caller who assumes
144 * the specified @p description and @p stride. This must at least validate
145 * that the buffer size is large enough. Validating the buffer against
146 * individual buffer attributes is optional.
147 *
148 * @param buffer Buffer to validate against.
149 * @param description Attributes of the buffer.
150 * @param stride Stride returned by IAllocator::allocate().
151 * @return error Error status of the call, which may be
152 * - `NONE` upon success.
153 * - `BAD_BUFFER` if the buffer is invalid.
154 * - `BAD_VALUE` if the buffer cannot be safely accessed.
155 */
156 validateBufferSize(pointer buffer,
157 BufferDescriptorInfo description,
158 uint32_t stride)
159 generates (Error error);
160
161 /**
162 * Calculates the transport size of a buffer. An imported buffer handle is a
163 * raw buffer handle with the process-local runtime data appended. This
164 * function, for example, allows a caller to omit the process-local runtime
165 * data at the tail when serializing the imported buffer handle.
166 *
167 * Note that a client might or might not omit the process-local runtime data
168 * when sending an imported buffer handle. The mapper must support both
169 * cases on the receiving end.
170 *
171 * @param buffer Buffer to get the transport size from.
172 * @return error Error status of the call, which may be
173 * - `NONE` upon success.
174 * - `BAD_BUFFER` if the buffer is invalid.
175 * @return numFds The number of file descriptors needed for transport.
176 * @return numInts The number of integers needed for transport.
177 */
178 getTransportSize(pointer buffer)
179 generates (Error error,
180 uint32_t numFds,
181 uint32_t numInts);
182
183 /**
184 * Locks the given buffer for the specified CPU usage.
185 *
186 * Locking the same buffer simultaneously from multiple threads is
187 * permitted, but if any of the threads attempt to lock the buffer for
188 * writing, the behavior is undefined, except that it must not cause
189 * process termination or block the client indefinitely. Leaving the
190 * buffer content in an indeterminate state or returning an error are both
191 * acceptable.
192 *
193 * 1D buffers (width = size in bytes, height = 1, pixel_format = BLOB) must
194 * "lock in place". The buffers must be directly accessible via mapping.
195 *
196 * The client must not modify the content of the buffer outside of
197 * @p accessRegion, and the device need not guarantee that content outside
198 * of @p accessRegion is valid for reading. The result of reading or writing
199 * outside of @p accessRegion is undefined, except that it must not cause
200 * process termination.
201 *
Marissa Wall9c5ebfc2019-11-05 14:59:27 -0800202 * This function can lock both single-planar and multi-planar formats. The caller
203 * should use get() to get information about the buffer they are locking.
204 * get() can be used to get information about the planes, offsets, stride,
205 * etc.
206 *
207 * This function must also work on buffers with
208 * `AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_*` if supported by the device, as well
209 * as with any other formats requested by multimedia codecs when they are
210 * configured with a flexible-YUV-compatible color format.
211 *
Marissa Wall65341642019-06-20 13:21:06 -0700212 * On success, @p data must be filled with a pointer to the locked buffer
213 * memory. This address will represent the top-left corner of the entire
214 * buffer, even if @p accessRegion does not begin at the top-left corner.
215 *
Marissa Wallaa181ae2019-10-14 13:17:17 -0700216 * The locked buffer must adhere to the format requested at allocation time
217 * in the BufferDescriptorInfo.
218 *
Marissa Wall65341642019-06-20 13:21:06 -0700219 * @param buffer Buffer to lock.
220 * @param cpuUsage CPU usage flags to request. See +ndk
221 * libnativewindow#AHardwareBuffer_UsageFlags for possible values.
222 * @param accessRegion Portion of the buffer that the client intends to
223 * access.
224 * @param acquireFence Handle containing a file descriptor referring to a
225 * sync fence object, which will be signaled when it is safe for the
226 * mapper to lock the buffer. @p acquireFence may be an empty fence if
227 * it is already safe to lock.
228 * @return error Error status of the call, which may be
229 * - `NONE` upon success.
230 * - `BAD_BUFFER` if the buffer is invalid or is incompatible with this
231 * function.
232 * - `BAD_VALUE` if @p cpuUsage is 0, contains non-CPU usage flags, or
Marissa Walla6a2af82019-11-06 12:49:23 -0800233 * is incompatible with the buffer. Also if the @p accessRegion is
234 * outside the bounds of the buffer or the accessRegion is invalid.
Marissa Wall65341642019-06-20 13:21:06 -0700235 * - `NO_RESOURCES` if the buffer cannot be locked at this time. Note
236 * that locking may succeed at a later time.
237 * @return data CPU-accessible pointer to the buffer data.
Marissa Wall65341642019-06-20 13:21:06 -0700238 */
239 lock(pointer buffer,
240 uint64_t cpuUsage,
241 Rect accessRegion,
242 handle acquireFence)
243 generates (Error error,
Marissa Wall9c5ebfc2019-11-05 14:59:27 -0800244 pointer data);
Marissa Wall65341642019-06-20 13:21:06 -0700245
246 /**
247 * Unlocks a buffer to indicate all CPU accesses to the buffer have
248 * completed.
249 *
250 * @param buffer Buffer to unlock.
251 * @return error Error status of the call, which may be
252 * - `NONE` upon success.
253 * - `BAD_BUFFER` if the buffer is invalid or not locked.
254 * @return releaseFence Handle containing a file descriptor referring to a
255 * sync fence object. The sync fence object will be signaled when the
256 * mapper has completed any pending work. @p releaseFence may be an
257 * empty fence.
258 */
259 unlock(pointer buffer) generates (Error error, handle releaseFence);
260
261 /**
262 * Test whether the given BufferDescriptorInfo is allocatable.
263 *
264 * If this function returns true, it means that a buffer with the given
265 * description can be allocated on this implementation, unless resource
266 * exhaustion occurs. If this function returns false, it means that the
267 * allocation of the given description will never succeed.
268 *
269 * @param description the description of the buffer
270 * @return supported whether the description is supported
271 */
272 isSupported(BufferDescriptorInfo description)
273 generates (Error error,
274 bool supported);
275
Marissa Wall88d87fa2019-11-05 14:57:51 -0800276
277 /**
278 * Description for get(...), set(...) and getFromBufferDescriptorInfo(...)
279 *
280 * ------------ Overview -----------------------------------
281 * Gralloc 4 adds support for getting and setting buffer metadata on a buffer.
282 *
283 * To get buffer metadata, the client passes in a buffer handle and a token that
284 * represents the type of buffer metadata they would like to get. IMapper returns
285 * a byte stream that contains the buffer metadata. To set the buffer metadata, the
286 * client passes in a buffer handle and a token that represents the type of buffer
287 * metadata they would like to set and a byte stream that contains the buffer metadata
288 * they are setting.
289 *
290 * Buffer metadata is global for a buffer. When the metadata is set on the buffer
291 * in a process, the updated metadata should be available to all other processes.
292 * Please see "Storing and Propagating Metadata" below for more details.
293 *
294 * The getter and setter functions have been optimized for easy vendor extension.
295 * They do not require a formal HIDL extension to add support for getting and setting
296 * vendor defined buffer metadata. In order to allow easy extension, the types used
297 * here are not typical HIDL types. See "Buffer Metadata Token" and
298 * "Buffer Metadata Stream" below for more details.
299 *
300 * ------------ Storing and Propagating Metadata -----------
301 * Buffer metadata must be global. Any changes to the metadata must be propagated
302 * to all other processes immediately. Vendors may chose how they would like support
303 * this functionality.
304 *
305 * We recommend supporting this functionality by allocating an extra page of shared
306 * memory and storing it in the buffer's native_handle_t. The buffer metadata can
307 * be stored in the extra page of shared memory. Set operations are automatically
308 * propagated to all other processes.
309 *
310 * ------------ Buffer Metadata Synchronization ------------
311 * There are no explicit buffer metadata synchronization primitives. Many devices
312 * before gralloc 4 already support getting and setting of global buffer metadata
313 * with no explicit synchronization primitives. Adding synchronization primitives
314 * would just add unnecessary complexity.
315 *
316 * The general rule is if a process has permission to write to a buffer, they
317 * have permission to write to the buffer's metadata. If a process has permission
318 * to read from a buffer, they have permission to read the buffer's metadata.
319 *
320 * There is one exception to this rule. Fences CANNOT be used to protect a buffer's
Marissa Wall0129f432019-11-18 12:48:24 -0800321 * metadata. A process should finish writing to a buffer's metadata before
Marissa Wall88d87fa2019-11-05 14:57:51 -0800322 * sending the buffer to another process that will read or write to the buffer.
323 * This exception is needed because sometimes userspace needs to read the
324 * buffer's metadata before the buffer's contents are ready.
325 *
326 * As a simple example: an app renders to a buffer and then displays the buffer.
327 * In this example when the app renders to the buffer, both the buffer and its
328 * metadata need to be updated. The app's process queues up its work on the GPU
329 * and gets back an acquire fence. The app's process must update the buffer's
330 * metadata before enqueuing the buffer to SurfaceFlinger. The app process CANNOT
331 * update the buffer's metadata after enqueuing the buffer. When HardwareComposer
332 * receives the buffer, it is immediately safe to read the buffer's metadata
333 * and use it to program the display driver. To read the buffer's contents,
334 * display driver must still wait on the acquire fence.
335 *
336 * ------------ Buffer Metadata Token ----------------------
337 * In order to allow arbitrary vendor defined metadata, we could not use a
338 * HIDL enum as the buffer metadata token. Extending a HIDL enum requires a full
339 * HIDL extension. We also could not use a simple non-HIDL enum because vendor
340 * defined enums from different vendors could collide. Instead we have defined
341 * a struct that has a string representing the enum type and an int that
342 * represents the enum value. The string protects different enum values from
343 * colliding.
344 *
345 * The token struct (MetadataType) is defined as a HIDL struct since it
346 * is passed into a HIDL function. The standard buffer metadata types are NOT
347 * defined as a HIDL enum because it would have required a new IMapper version
348 * just to add future standard buffer metadata types. By putting the enum in the
349 * stable AIDL (hardware/interfaces/graphics/common/aidl/android/hardware/
350 * graphics/common/StandardMetadataType.aidl), vendors will be able to optionally
351 * choose to support future standard buffer metadata types without upgrading
352 * HIDL versions. For more information see the description of "struct MetadataType".
353 *
354 * ------------ Buffer Metadata Stream ---------------------
355 * The buffer metadata is get and set as a byte stream (vec<uint8_t>). By getting
356 * and setting buffer metadata as a byte stream, vendors can use the standard
357 * getters and setter functions defined here. Vendors do NOT need to add their own
358 * getters and setter functions for each new type of buffer metadata.
359 *
360 * Converting buffer metadata into a byte stream can be non-trivial. For the standard
361 * buffer metadata types defined in StandardMetadataType.aidl, there are also
362 * support functions that will encode the buffer metadata into a byte stream
363 * and decode the buffer metadata from a byte stream. We STRONGLY recommend using
364 * these support functions. The framework will use them when getting and setting
365 * metadata. The support functions are defined in
366 * frameworks/native/libs/gralloc/types/include/gralloctypes/Gralloc4.h.
367 */
368
369 /**
370 * MetadataType represents the different types of buffer metadata that could be
371 * associated with a buffer. It is used by IMapper to help get and set buffer metadata
372 * on the buffer's native handle.
373 *
374 * Standard buffer metadata will have the name field set to
375 * "android.hardware.graphics.common.StandardMetadataType" and will contain values
376 * from StandardMetadataType.aidl.
377 *
378 * This struct should be "extended" by devices that use a proprietary or non-standard
379 * buffer metadata. To extend the struct, first create a custom @VendorStability vendor
380 * AIDL interface that defines the new type(s) you would like to support. Set the
381 * struct's name field to the custom aidl interface's name
382 * (eg. "vendor.mycompanyname.graphics.common.MetadataType"). Set the struct's value
383 * field to the custom @VendorStabilty vendor AIDL interface.
384 *
385 * Each company should create their own StandardMetadataType.aidl extension. The name
386 * field prevents values from different companies from colliding.
387 */
388 struct MetadataType {
389 string name;
390 int64_t value;
391 };
392
393 /**
394 * Gets the buffer metadata for a given MetadataType.
395 *
396 * Buffer metadata can be changed after allocation so clients should avoid "caching"
397 * the buffer metadata. For example, if the video resolution changes and the buffers
398 * are not reallocated, several buffer metadata values may change without warning.
399 * Clients should not expect the values to be constant. They should requery them every
400 * frame. The only exception is buffer metadata that is determined at allocation
401 * time. For StandardMetadataType values, only BUFFER_ID, NAME, WIDTH,
402 * HEIGHT, LAYER_COUNT, PIXEL_FORMAT_REQUESTED and USAGE are safe to cache because
403 * they are determined at allocation time.
404 *
405 * @param buffer Buffer containing desired metadata
406 * @param metadataType MetadataType for the metadata value being queried
407 * @return error Error status of the call, which may be
408 * - `NONE` upon success.
409 * - `BAD_BUFFER` if the raw handle is invalid.
410 * - `NO_RESOURCES` if the get cannot be fullfilled due to unavailability of
411 * resources.
412 * - `UNSUPPORTED` when metadataType is unknown/unsupported.
413 * IMapper must support getting all StandardMetadataType.aidl values defined
414 * at the time the device first launches.
415 * @return metadata Vector of bytes representing the buffer metadata associated with
416 * the MetadataType.
417 */
418 get(pointer buffer, MetadataType metadataType)
419 generates (Error error,
420 vec<uint8_t> metadata);
421
422 /**
423 * Sets the global value for a given MetadataType.
424 *
425 * Metadata fields are not required to be settable. This function can
426 * return Error::UNSUPPORTED whenever it doesn't support setting a
427 * particular Metadata field.
428 *
429 * The framework may attempt to set the following StandardMetadataType
430 * values: DATASPACE, PER_FRAME_METADATA, PER_FRAME_METADATA_BLOB and BLEND_MODE.
431 * We strongly encourage everyone to support setting as many of those fields as
432 * possible. If a device's Composer implementation supports a field, it should be
433 * supported here. Over time these metadata fields will be moved out of
434 * Composer/BufferQueue/etc. and into the buffer's Metadata fields.
435 * If a device's IMapper doesn't support setting those Metadata fields,
436 * eventually the device may not longer be able to support these fields.
437 *
438 * @param buffer Buffer receiving desired metadata
439 * @param metadataType MetadataType for the metadata value being set
440 * @param metadata Vector of bytes representing the value associated with
441 * @return error Error status of the call, which may be
442 * - `NONE` upon success.
443 * - `BAD_BUFFER` if the raw handle is invalid.
444 * - `BAD_VALUE` when the field is constant and can never be set (such as
445 * BUFFER_ID, NAME, WIDTH, HEIGHT, LAYER_COUNT, PIXEL_FORMAT_REQUESTED and
446 * USAGE)
447 * - `NO_RESOURCES` if the set cannot be fullfilled due to unavailability of
448 * resources.
449 * - `UNSUPPORTED` when metadataType is unknown/unsupported or setting
450 * it is unsupported. Unsupported should also be returned if the metadata
451 * is malformed.
452 */
453 set(pointer buffer, MetadataType metadataType, vec<uint8_t> metadata)
454 generates (Error error);
455
456 /**
457 * Given a BufferDescriptorInfo, gets the starting value of a given
458 * MetadataType. This can be used to query basic information about a buffer
459 * before the buffer is allocated.
460 *
461 * @param description Attributes of the descriptor.
462 * @param metadataType MetadataType for the metadata value being queried
463 * @return error Error status of the call, which may be
464 * - `NONE` upon success.
465 * - `BAD_VALUE` if any of the specified BufferDescriptorInfo attributes
466 * are invalid.
467 * - `NO_RESOURCES` if the get cannot be fullfilled due to unavailability of
468 * resources.
469 * - `UNSUPPORTED` when any of the description attributes are unsupported or
470 * if the metadataType is unknown/unsupported. This should also be
471 * returned if the requested metadata is not defined until a buffer has been
472 * allocated.
473 * @return metadata Vector of bytes representing the value associated with
474 * the MetadataType value.
475 */
476 getFromBufferDescriptorInfo(BufferDescriptorInfo description,
477 MetadataType metadataType)
478 generates (Error error,
479 vec<uint8_t> metadata);
Marissa Wall0001a5d2019-11-11 10:50:05 -0800480
481 struct MetadataTypeDescription {
482 MetadataType metadataType;
483 /**
484 * description should contain a string representation of the MetadataType.
485 *
486 * For example: "MyExampleMetadataType is a 64-bit timestamp in nanoseconds
487 * that indicates when a buffer is decoded. It is set by the media HAL after
488 * a buffer is decoded. It is used by the display HAL for hardware
489 * synchronization".
490 *
491 * This field is required for any non-StandardMetadataTypes.
492 */
493 string description;
494 /**
495 * isGettable represents if the MetadataType can be get.
496 */
497 bool isGettable;
498 /**
499 * isSettable represents if the MetadataType can be set.
500 */
501 bool isSettable;
502 };
503
504 /**
505 * Lists all the MetadataTypes supported by IMapper as well as a description
506 * of each supported MetadataType. For StandardMetadataTypes, the description
507 * string can be left empty.
508 *
509 * @return error Error status of the call, which may be
510 * - `NONE` upon success.
511 * - `NO_RESOURCES` if the get cannot be fullfilled due to unavailability of
512 * resources.
513 * @return descriptions Vector of MetadataTypeDescriptions that represent the
514 * MetadataTypes supported by the device.
515 */
516 listSupportedMetadataTypes()
517 generates (Error error, vec<MetadataTypeDescription> descriptions);
Marissa Wall0cf07562019-11-07 09:17:43 -0800518
519 struct MetadataDump {
520 /**
521 * The type of metadata being dumped.
522 */
523 MetadataType metadataType;
524 /**
525 * The byte stream representation of the metadata. If the metadata is not
526 * gettable, the vector must be empty.
527 */
528 vec<uint8_t> metadata;
529 };
530
531 struct BufferDump {
532 /**
533 * A vector of all the metadata that is being dumped for a particular buffer.
534 */
535 vec<MetadataDump> metadataDump;
536 };
537
538 /**
539 * Dumps a buffer's metadata.
540 *
541 * @param buffer Buffer that is being dumped
542 * @return error Error status of the call, which may be
543 * - `NONE` upon success.
544 * - `BAD_BUFFER` if the raw handle is invalid.
545 * - `NO_RESOURCES` if the get cannot be fullfilled due to unavailability of
546 * resources.
547 * @return bufferDump Struct representing the metadata being dumped
548 */
549 dumpBuffer(pointer buffer)
550 generates (Error error, BufferDump bufferDump);
551
552 /**
553 * Dumps the metadata for all the buffers in the current process.
554 *
555 * @return error Error status of the call, which may be
556 * - `NONE` upon success.
557 * - `NO_RESOURCES` if the get cannot be fullfilled due to unavailability of
558 * resources.
559 * @return bufferDumps Vector of structs representing the buffers being dumped
560 */
561 dumpBuffers()
562 generates (Error error, vec<BufferDump> bufferDumps);
Marissa Wall65341642019-06-20 13:21:06 -0700563};
564