Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 1 | /* |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame^] | 2 | * Copyright (C) 2016 The Android Open Source Project |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 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 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame^] | 17 | package android.hardware.graphics.mapper@2.0; |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 18 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame^] | 19 | import android.hardware.graphics.common@1.0::PixelFormat; |
| 20 | import android.hardware.graphics.allocator@2.0; |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 21 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame^] | 22 | interface IMapper { |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 23 | struct Rect { |
| 24 | int32_t left; |
| 25 | int32_t top; |
| 26 | int32_t width; |
| 27 | int32_t height; |
| 28 | }; |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 29 | |
| 30 | /* |
| 31 | * Adds a reference to the given buffer handle. |
| 32 | * |
| 33 | * A buffer handle received from a remote process or exported by |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame^] | 34 | * IAllocator::exportHandle is unknown to the mapper. There is also no |
| 35 | * guarantee that the buffer's backing store will stay alive. This |
| 36 | * function must be called at least once in both cases to intrdouce the |
| 37 | * buffer handle to the mapper and to secure the backing store. It may |
| 38 | * also be called more than once to increase the reference count if two |
| 39 | * components in the same process want to interact with the buffer |
| 40 | * independently. |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 41 | * |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 42 | * @param bufferHandle is the buffer to which a reference must be added. |
| 43 | * @return error is NONE upon success. Otherwise, |
| 44 | * BAD_BUFFER when the buffer handle is invalid |
| 45 | * NO_RESOURCES when it is not possible to add a |
| 46 | * reference to this buffer at this time |
| 47 | */ |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame^] | 48 | @entry |
| 49 | @callflow(next="*") |
| 50 | retain(handle bufferHandle) generates (Error error); |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 51 | |
| 52 | /* |
| 53 | * Removes a reference from the given buffer buffer. |
| 54 | * |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame^] | 55 | * If no references remain, the buffer handle must be freed with |
| 56 | * native_handle_close/native_handle_delete by the mapper. When the last |
| 57 | * buffer handle referring to a particular backing store is freed, that |
| 58 | * backing store must also be freed. |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 59 | * |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 60 | * @param bufferHandle is the buffer from which a reference must be |
| 61 | * removed. |
| 62 | * @return error is NONE upon success. Otherwise, |
| 63 | * BAD_BUFFER when the buffer handle is invalid. |
| 64 | */ |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame^] | 65 | @exit |
| 66 | release(handle bufferHandle) generates (Error error); |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 67 | |
| 68 | /* |
| 69 | * Gets the width and height of the buffer in pixels. |
| 70 | * |
| 71 | * See IAllocator::BufferDescriptorInfo for more information. |
| 72 | * |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 73 | * @param bufferHandle is the buffer from which to get the dimensions. |
| 74 | * @return error is NONE upon success. Otherwise, |
| 75 | * BAD_BUFFER when the buffer handle is invalid. |
| 76 | * @return width is the width of the buffer in pixels. |
| 77 | * @return height is the height of the buffer in pixels. |
| 78 | */ |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame^] | 79 | @callflow(next="*") |
| 80 | getDimensions(handle bufferHandle) |
| 81 | generates (Error error, |
| 82 | uint32_t width, |
| 83 | uint32_t height); |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 84 | |
| 85 | /* |
| 86 | * Gets the format of the buffer. |
| 87 | * |
| 88 | * See IAllocator::BufferDescriptorInfo for more information. |
| 89 | * |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 90 | * @param bufferHandle is the buffer from which to get format. |
| 91 | * @return error is NONE upon success. Otherwise, |
| 92 | * BAD_BUFFER when the buffer handle is invalid. |
| 93 | * @return format is the format of the buffer. |
| 94 | */ |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame^] | 95 | @callflow(next="*") |
| 96 | getFormat(handle bufferHandle) |
| 97 | generates (Error error, |
| 98 | PixelFormat format); |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 99 | |
| 100 | /* |
Craig Donner | 0b00adf | 2016-10-20 17:12:58 -0700 | [diff] [blame] | 101 | * Gets the number of layers of the buffer. |
| 102 | * |
| 103 | * See IAllocator::BufferDescriptorInfo for more information. |
| 104 | * |
Craig Donner | 0b00adf | 2016-10-20 17:12:58 -0700 | [diff] [blame] | 105 | * @param bufferHandle is the buffer from which to get format. |
| 106 | * @return error is NONE upon success. Otherwise, |
| 107 | * BAD_BUFFER when the buffer handle is invalid. |
| 108 | * @return layerCount is the number of layers of the buffer. |
| 109 | */ |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame^] | 110 | @callflow(next="*") |
| 111 | getLayerCount(handle bufferHandle) |
| 112 | generates (Error error, |
| 113 | uint32_t layerCount); |
Craig Donner | 0b00adf | 2016-10-20 17:12:58 -0700 | [diff] [blame] | 114 | |
| 115 | /* |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 116 | * Gets the producer usage flags which were used to allocate this buffer. |
| 117 | * |
| 118 | * See IAllocator::BufferDescriptorInfo for more information. |
| 119 | * |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 120 | * @param bufferHandle is the buffer from which to get the producer usage |
| 121 | * flags. |
| 122 | * @return error is NONE upon success. Otherwise, |
| 123 | * BAD_BUFFER when the buffer handle is invalid. |
| 124 | * @return usageMask contains the producer usage flags of the buffer. |
| 125 | */ |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame^] | 126 | @callflow(next="*") |
| 127 | getProducerUsageMask(handle bufferHandle) |
| 128 | generates (Error error, |
| 129 | uint64_t usageMask); |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 130 | |
| 131 | /* |
| 132 | * Gets the consumer usage flags which were used to allocate this buffer. |
| 133 | * |
| 134 | * See IAllocator::BufferDescriptorInfo for more information. |
| 135 | * |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 136 | * @param bufferHandle is the buffer from which to get the consumer usage |
| 137 | * flags. |
| 138 | * @return error is NONE upon success. Otherwise, |
| 139 | * BAD_BUFFER when the buffer handle is invalid. |
| 140 | * @return usageMask contains the consumer usage flags of the buffer. |
| 141 | */ |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame^] | 142 | @callflow(next="*") |
| 143 | getConsumerUsageMask(handle bufferHandle) |
| 144 | generates (Error error, |
| 145 | uint64_t usageMask); |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 146 | |
| 147 | /* |
| 148 | * Gets a value that uniquely identifies the backing store of the given |
| 149 | * buffer. |
| 150 | * |
| 151 | * Buffers which share a backing store should return the same value from |
| 152 | * this function. If the buffer is present in more than one process, the |
| 153 | * backing store value for that buffer is not required to be the same in |
| 154 | * every process. |
| 155 | * |
| 156 | * @param device is the mapper device. |
| 157 | * @param bufferHandle is the buffer from which to get the backing store |
| 158 | * identifier. |
| 159 | * @return error is NONE upon success. Otherwise, |
| 160 | * BAD_BUFFER when the buffer handle is invalid. |
| 161 | * @return store is the backing store identifier for this buffer. |
| 162 | */ |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame^] | 163 | @callflow(next="*") |
| 164 | getBackingStore(handle bufferHandle) |
| 165 | generates (Error error, |
| 166 | BackingStore store); |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 167 | |
| 168 | /* |
| 169 | * Gets the stride of the buffer in pixels. |
| 170 | * |
| 171 | * The stride is the offset in pixel-sized elements between the same |
| 172 | * column in two adjacent rows of pixels. This may not be equal to the |
| 173 | * width of the buffer. |
| 174 | * |
| 175 | * @param device is the mapper device. |
| 176 | * @param bufferHandle is the buffer from which to get the stride. |
| 177 | * @return error is NONE upon success. Otherwise, |
| 178 | * BAD_BUFFER when the buffer handle is invalid. |
| 179 | * UNDEFINED when the notion of a stride is not |
| 180 | * meaningful for the buffer format. |
| 181 | * @return store is the stride in pixels. |
| 182 | */ |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame^] | 183 | @callflow(next="*") |
| 184 | getStride(handle bufferHandle) |
| 185 | generates (Error error, |
| 186 | uint32_t stride); |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 187 | |
| 188 | /* |
| 189 | * Locks the given buffer for the specified CPU usage. |
| 190 | * |
| 191 | * Exactly one of producerUsageMask and consumerUsageMask must be 0. The |
| 192 | * usage which is not 0 must be one of the *Usage::CPU* values, as |
| 193 | * applicable. Locking a buffer for a non-CPU usage is not supported. |
| 194 | * |
| 195 | * Locking the same buffer simultaneously from multiple threads is |
| 196 | * permitted, but if any of the threads attempt to lock the buffer for |
| 197 | * writing, the behavior is undefined, except that it must not cause |
| 198 | * process termination or block the client indefinitely. Leaving the |
| 199 | * buffer content in an indeterminate state or returning an error are both |
| 200 | * acceptable. |
| 201 | * |
| 202 | * The client must not modify the content of the buffer outside of |
| 203 | * accessRegion, and the device need not guarantee that content outside of |
| 204 | * accessRegion is valid for reading. The result of reading or writing |
| 205 | * outside of accessRegion is undefined, except that it must not cause |
| 206 | * process termination. |
| 207 | * |
| 208 | * data will be filled with a pointer to the locked buffer memory. This |
| 209 | * address will represent the top-left corner of the entire buffer, even |
| 210 | * if accessRegion does not begin at the top-left corner. |
| 211 | * |
| 212 | * acquireFence is a file descriptor referring to a acquire sync fence |
| 213 | * object, which will be signaled when it is safe for the device to access |
| 214 | * the contents of the buffer (prior to locking). If it is already safe to |
| 215 | * access the buffer contents, -1 may be passed instead. |
| 216 | * |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 217 | * @param bufferHandle is the buffer to lock. |
| 218 | * @param producerUsageMask contains the producer usage flags to request; |
| 219 | * either this or consumerUsagemask must be 0, and the other must |
| 220 | * be a CPU usage. |
| 221 | * @param consumerUsageMask contains the consumer usage flags to request; |
| 222 | * either this or producerUsageMask must be 0, and the other must |
| 223 | * be a CPU usage. |
| 224 | * @param accessRegion is the portion of the buffer that the client |
| 225 | * intends to access. |
| 226 | * @param acquireFence is a sync fence file descriptor as described above. |
| 227 | * @return error is NONE upon success. Otherwise, |
| 228 | * BAD_BUFFER when the buffer handle is invalid. |
| 229 | * BAD_VALUE when neither or both of producerUsageMask |
| 230 | * and consumerUsageMask were 0, or the usage |
| 231 | * which was not 0 was not a CPU usage. |
| 232 | * NO_RESOURCES when the buffer cannot be locked at this |
| 233 | * time, but locking may succeed at a future |
| 234 | * time. |
| 235 | * UNSUPPORTED when the buffer cannot be locked with the |
| 236 | * given usage, and any future attempts at |
| 237 | * locking will also fail. |
| 238 | * @return data will be filled with a CPU-accessible pointer to the buffer |
| 239 | * data. |
| 240 | */ |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame^] | 241 | @callflow(next="unlock") |
| 242 | lock(handle bufferHandle, |
| 243 | uint64_t producerUsageMask, |
| 244 | uint64_t consumerUsageMask, |
| 245 | Rect accessRegion, |
| 246 | handle acquireFence) |
| 247 | generates (Error error, |
| 248 | pointer data); |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 249 | |
| 250 | /* |
| 251 | * This is largely the same as lock(), except that instead of returning a |
| 252 | * pointer directly to the buffer data, it returns an FlexLayout struct |
| 253 | * describing how to access the data planes. |
| 254 | * |
| 255 | * This function must work on buffers with PixelFormat::YCbCr_*_888 if |
| 256 | * supported by the device, as well as with any other formats requested by |
| 257 | * multimedia codecs when they are configured with a |
| 258 | * flexible-YUV-compatible color format. |
| 259 | * |
| 260 | * This function may also be called on buffers of other formats, including |
| 261 | * non-YUV formats, but if the buffer format is not compatible with a |
| 262 | * flexible representation, it may return UNSUPPORTED. |
| 263 | * |
| 264 | * @param device is the mapper device. |
| 265 | * @param bufferHandle is the buffer to lock. |
| 266 | * @param producerUsageMask contains the producer usage flags to request; |
| 267 | * either this or consumerUsagemask must be 0, and the other must |
| 268 | * be a CPU usage. |
| 269 | * @param consumerUsageMask contains the consumer usage flags to request; |
| 270 | * either this or producerUsageMask must be 0, and the other must |
| 271 | * be a CPU usage. |
| 272 | * @param accessRegion is the portion of the buffer that the client |
| 273 | * intends to access. |
| 274 | * @param acquireFence is a sync fence file descriptor as described in |
| 275 | * lock(). |
| 276 | * @return error is NONE upon success. Otherwise, |
| 277 | * BAD_BUFFER when the buffer handle is invalid. |
| 278 | * BAD_VALUE when neither or both of producerUsageMask |
| 279 | * and consumerUsageMask were 0, or the usage |
| 280 | * which was not 0 was not a CPU usage. |
| 281 | * NO_RESOURCES when the buffer cannot be locked at this |
| 282 | * time, but locking may succeed at a future |
| 283 | * time. |
| 284 | * UNSUPPORTED when the buffer cannot be locked with the |
| 285 | * given usage, and any future attempts at |
| 286 | * locking will also fail. |
| 287 | * @return flexLayout will be filled with the description of the planes in |
| 288 | * the buffer. |
| 289 | */ |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame^] | 290 | @callflow(next="unlock") |
| 291 | lockFlex(handle bufferHandle, |
| 292 | uint64_t producerUsageMask, |
| 293 | uint64_t consumerUsageMask, |
| 294 | Rect accessRegion, |
| 295 | handle acquireFence) |
| 296 | generates (Error error, |
| 297 | FlexLayout layout); |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 298 | |
| 299 | /* |
| 300 | * This function indicates to the device that the client will be done with |
| 301 | * the buffer when releaseFence signals. |
| 302 | * |
| 303 | * releaseFence will be filled with a file descriptor referring to a |
| 304 | * release sync fence object, which will be signaled when it is safe to |
| 305 | * access the contents of the buffer (after the buffer has been unlocked). |
| 306 | * If it is already safe to access the buffer contents, then -1 may be |
| 307 | * returned instead. |
| 308 | * |
| 309 | * This function is used to unlock both buffers locked by lock() and those |
| 310 | * locked by lockFlex(). |
| 311 | * |
| 312 | * @param device is the mapper device. |
| 313 | * @param bufferHandle is the buffer to unlock. |
| 314 | * @return error is NONE upon success. Otherwise, |
| 315 | * BAD_BUFFER when the buffer handle is invalid. |
| 316 | * @return releaseFence is a sync fence file descriptor as described |
| 317 | * above. |
| 318 | */ |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame^] | 319 | @callflow(next="*") |
| 320 | unlock(handle bufferHandle) |
| 321 | generates (Error error, |
| 322 | handle releaseFence); |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 323 | }; |