blob: 640539fcee85228570c16fd206a3cd46081168e7 [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
38 /**
39 * The height specifies how many rows of pixels must be in the
40 * allocated buffer.
41 */
42 uint32_t height;
43
44 /**
45 * The number of image layers that must be in the allocated buffer.
46 */
47 uint32_t layerCount;
48
49 /** Buffer pixel format. */
50 PixelFormat format;
51
52 /**
53 * Buffer usage mask; valid flags can be found in the definition of
54 * BufferUsage.
55 */
56 bitfield<BufferUsage> usage;
57 };
58
59 struct Rect {
60 int32_t left;
61 int32_t top;
62 int32_t width;
63 int32_t height;
64 };
65
66 /**
67 * Creates a buffer descriptor. The descriptor can be used with IAllocator
68 * to allocate buffers.
69 *
70 * Since the buffer descriptor fully describes a buffer, any device
71 * dependent or device independent checks must be performed here whenever
72 * possible. Specifically, when layered buffers are not supported, this
73 * function must return `UNSUPPORTED` if `description.layers` is great than
74 * 1.
75 *
76 * @param description Attributes of the descriptor.
77 * @return error Error status of the call, which may be
78 * - `NONE` upon success.
79 * - `BAD_VALUE` if any of the specified attributes are invalid or
80 * inconsistent.
81 * - `NO_RESOURCES` if the creation cannot be fullfilled due to
82 * unavailability of resources.
83 * - `UNSUPPORTED` when any of the specified attributes are not
84 * supported.
85 * @return descriptor Newly created buffer descriptor.
86 */
87 createDescriptor(BufferDescriptorInfo description)
88 generates (Error error,
89 BufferDescriptor descriptor);
90
91 /**
92 * Imports a raw buffer handle to create an imported buffer handle for use
93 * with the rest of the mapper or with other in-process libraries.
94 *
95 * A buffer handle is considered raw when it is cloned (e.g., with
96 * `native_handle_clone()`) from another buffer handle locally, or when it
97 * is received from another HAL server/client or another process. A raw
98 * buffer handle must not be used to access the underlying graphic
99 * buffer. It must be imported to create an imported handle first.
100 *
101 * This function must at least validate the raw handle before creating the
102 * imported handle. It must also support importing the same raw handle
103 * multiple times to create multiple imported handles. The imported handle
104 * must be considered valid everywhere in the process, including in
105 * another instance of the mapper.
106 *
107 * Because of passthrough HALs, a raw buffer handle received from a HAL
108 * may actually have been imported in the process. importBuffer() must treat
109 * such a handle as if it is raw and must not return `BAD_BUFFER`. The
110 * returned handle is independent from the input handle as usual, and
111 * freeBuffer() must be called on it when it is no longer needed.
112 *
113 * @param rawHandle Raw buffer handle to import.
114 * @return error Error status of the call, which may be
115 * - `NONE` upon success.
116 * - `BAD_BUFFER` if the raw handle is invalid.
117 * - `NO_RESOURCES` if the raw handle cannot be imported due to
118 * unavailability of resources.
119 * @return buffer Imported buffer handle that has the type
120 * `buffer_handle_t` which is a handle type.
121 */
122 importBuffer(handle rawHandle) generates (Error error, pointer buffer);
123
124 /**
125 * Frees a buffer handle. Buffer handles returned by importBuffer() must be
126 * freed with this function when no longer needed.
127 *
128 * This function must free up all resources allocated by importBuffer() for
129 * the imported handle. For example, if the imported handle was created
130 * with `native_handle_create()`, this function must call
131 * `native_handle_close()` and `native_handle_delete()`.
132 *
133 * @param buffer Imported buffer handle.
134 * @return error Error status of the call, which may be
135 * - `NONE` upon success.
136 * - `BAD_BUFFER` if the buffer is invalid.
137 */
138 freeBuffer(pointer buffer) generates (Error error);
139
140 /**
141 * Validates that the buffer can be safely accessed by a caller who assumes
142 * the specified @p description and @p stride. This must at least validate
143 * that the buffer size is large enough. Validating the buffer against
144 * individual buffer attributes is optional.
145 *
146 * @param buffer Buffer to validate against.
147 * @param description Attributes of the buffer.
148 * @param stride Stride returned by IAllocator::allocate().
149 * @return error Error status of the call, which may be
150 * - `NONE` upon success.
151 * - `BAD_BUFFER` if the buffer is invalid.
152 * - `BAD_VALUE` if the buffer cannot be safely accessed.
153 */
154 validateBufferSize(pointer buffer,
155 BufferDescriptorInfo description,
156 uint32_t stride)
157 generates (Error error);
158
159 /**
160 * Calculates the transport size of a buffer. An imported buffer handle is a
161 * raw buffer handle with the process-local runtime data appended. This
162 * function, for example, allows a caller to omit the process-local runtime
163 * data at the tail when serializing the imported buffer handle.
164 *
165 * Note that a client might or might not omit the process-local runtime data
166 * when sending an imported buffer handle. The mapper must support both
167 * cases on the receiving end.
168 *
169 * @param buffer Buffer to get the transport size from.
170 * @return error Error status of the call, which may be
171 * - `NONE` upon success.
172 * - `BAD_BUFFER` if the buffer is invalid.
173 * @return numFds The number of file descriptors needed for transport.
174 * @return numInts The number of integers needed for transport.
175 */
176 getTransportSize(pointer buffer)
177 generates (Error error,
178 uint32_t numFds,
179 uint32_t numInts);
180
181 /**
182 * Locks the given buffer for the specified CPU usage.
183 *
184 * Locking the same buffer simultaneously from multiple threads is
185 * permitted, but if any of the threads attempt to lock the buffer for
186 * writing, the behavior is undefined, except that it must not cause
187 * process termination or block the client indefinitely. Leaving the
188 * buffer content in an indeterminate state or returning an error are both
189 * acceptable.
190 *
191 * 1D buffers (width = size in bytes, height = 1, pixel_format = BLOB) must
192 * "lock in place". The buffers must be directly accessible via mapping.
193 *
194 * The client must not modify the content of the buffer outside of
195 * @p accessRegion, and the device need not guarantee that content outside
196 * of @p accessRegion is valid for reading. The result of reading or writing
197 * outside of @p accessRegion is undefined, except that it must not cause
198 * process termination.
199 *
200 * On success, @p data must be filled with a pointer to the locked buffer
201 * memory. This address will represent the top-left corner of the entire
202 * buffer, even if @p accessRegion does not begin at the top-left corner.
203 *
204 * On success, bytesPerPixel must contain the number of bytes per pixel in
205 * the buffer. If the bytesPerPixel is unknown or variable, a value of -1
206 * should be returned. bytesPerStride must contain the bytes per stride of
207 * the buffer. If the bytesPerStride is unknown or variable, a value of -1
208 * should be returned.
209 *
Marissa Wallaa181ae2019-10-14 13:17:17 -0700210 * The locked buffer must adhere to the format requested at allocation time
211 * in the BufferDescriptorInfo.
212 *
Marissa Wall65341642019-06-20 13:21:06 -0700213 * @param buffer Buffer to lock.
214 * @param cpuUsage CPU usage flags to request. See +ndk
215 * libnativewindow#AHardwareBuffer_UsageFlags for possible values.
216 * @param accessRegion Portion of the buffer that the client intends to
217 * access.
218 * @param acquireFence Handle containing a file descriptor referring to a
219 * sync fence object, which will be signaled when it is safe for the
220 * mapper to lock the buffer. @p acquireFence may be an empty fence if
221 * it is already safe to lock.
222 * @return error Error status of the call, which may be
223 * - `NONE` upon success.
224 * - `BAD_BUFFER` if the buffer is invalid or is incompatible with this
225 * function.
226 * - `BAD_VALUE` if @p cpuUsage is 0, contains non-CPU usage flags, or
Marissa Walla6a2af82019-11-06 12:49:23 -0800227 * is incompatible with the buffer. Also if the @p accessRegion is
228 * outside the bounds of the buffer or the accessRegion is invalid.
Marissa Wall65341642019-06-20 13:21:06 -0700229 * - `NO_RESOURCES` if the buffer cannot be locked at this time. Note
230 * that locking may succeed at a later time.
231 * @return data CPU-accessible pointer to the buffer data.
232 * @return bytesPerPixel the number of bytes per pixel in the buffer
233 * @return bytesPerStride the number of bytes per stride of the buffer
234 */
235 lock(pointer buffer,
236 uint64_t cpuUsage,
237 Rect accessRegion,
238 handle acquireFence)
239 generates (Error error,
240 pointer data,
241 int32_t bytesPerPixel,
242 int32_t bytesPerStride);
243
244 /**
245 * Locks a YCbCr buffer for the specified CPU usage.
246 *
247 * This is largely the same as lock(), except that instead of returning a
248 * pointer directly to the buffer data, it returns a `YCbCrLayout` struct
249 * describing how to access the data planes.
250 *
251 * This function must work on buffers with
252 * `AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_*` if supported by the device, as well
253 * as with any other formats requested by multimedia codecs when they are
254 * configured with a flexible-YUV-compatible color format.
255 *
256 * @param buffer Buffer to lock.
257 * @param cpuUsage CPU usage flags to request. See +ndk
258 * libnativewindow#AHardwareBuffer_UsageFlags for possible values.
259 * @param accessRegion Portion of the buffer that the client intends to
260 * access.
261 * @param acquireFence Handle containing a file descriptor referring to a
262 * sync fence object, which will be signaled when it is safe for the
263 * mapper to lock the buffer. @p acquireFence may be empty if it is
264 * already safe to lock.
265 * @return error Error status of the call, which may be
266 * - `NONE` upon success.
267 * - `BAD_BUFFER` if the buffer is invalid or is incompatible with this
268 * function.
269 * - `BAD_VALUE` if @p cpuUsage is 0, contains non-CPU usage flags, or
270 * is incompatible with the buffer.
271 * - `NO_RESOURCES` if the buffer cannot be locked at this time. Note
272 * that locking may succeed at a later time.
273 * @return layout Data layout of the locked buffer.
274 */
275 lockYCbCr(pointer buffer,
276 uint64_t cpuUsage,
277 Rect accessRegion,
278 handle acquireFence)
279 generates (Error error,
280 YCbCrLayout layout);
281
282 /**
283 * Unlocks a buffer to indicate all CPU accesses to the buffer have
284 * completed.
285 *
286 * @param buffer Buffer to unlock.
287 * @return error Error status of the call, which may be
288 * - `NONE` upon success.
289 * - `BAD_BUFFER` if the buffer is invalid or not locked.
290 * @return releaseFence Handle containing a file descriptor referring to a
291 * sync fence object. The sync fence object will be signaled when the
292 * mapper has completed any pending work. @p releaseFence may be an
293 * empty fence.
294 */
295 unlock(pointer buffer) generates (Error error, handle releaseFence);
296
297 /**
298 * Test whether the given BufferDescriptorInfo is allocatable.
299 *
300 * If this function returns true, it means that a buffer with the given
301 * description can be allocated on this implementation, unless resource
302 * exhaustion occurs. If this function returns false, it means that the
303 * allocation of the given description will never succeed.
304 *
305 * @param description the description of the buffer
306 * @return supported whether the description is supported
307 */
308 isSupported(BufferDescriptorInfo description)
309 generates (Error error,
310 bool supported);
311
312};
313