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