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 | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 19 | import android.hardware.graphics.common@1.0; |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 20 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 21 | interface IMapper { |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 22 | struct BufferDescriptorInfo { |
| 23 | /** |
| 24 | * The width specifies how many columns of pixels must be in the |
| 25 | * allocated buffer, but does not necessarily represent the offset in |
| 26 | * columns between the same column in adjacent rows. The rows may be |
| 27 | * padded. |
| 28 | */ |
| 29 | uint32_t width; |
| 30 | |
| 31 | /** |
| 32 | * The height specifies how many rows of pixels must be in the |
| 33 | * allocated buffer. |
| 34 | */ |
| 35 | uint32_t height; |
| 36 | |
| 37 | /** |
| 38 | * The number of image layers that must be in the allocated buffer. |
| 39 | */ |
| 40 | uint32_t layerCount; |
| 41 | |
| 42 | /** Buffer pixel format. */ |
| 43 | PixelFormat format; |
| 44 | |
| 45 | /** |
| 46 | * Buffer usage mask; valid flags can be found in the definition of |
| 47 | * BufferUsage. |
| 48 | */ |
| 49 | bitfield<BufferUsage> usage; |
| 50 | }; |
| 51 | |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 52 | struct Rect { |
| 53 | int32_t left; |
| 54 | int32_t top; |
| 55 | int32_t width; |
| 56 | int32_t height; |
| 57 | }; |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 58 | |
Andreas Huber | 40d3a9b | 2017-03-28 16:19:16 -0700 | [diff] [blame] | 59 | /** |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 60 | * Creates a buffer descriptor. The descriptor can be used with IAllocator |
| 61 | * to allocate buffers. |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 62 | * |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 63 | * Since the buffer descriptor fully describes a buffer, any device |
| 64 | * dependent or device independent checks must be performed here whenever |
| 65 | * possible. Specifically, when layered buffers are not supported, this |
| 66 | * function must return UNSUPPORTED if layerCount is great than 1. |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 67 | * |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 68 | * @param descriptorInfo specifies the attributes of the descriptor. |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 69 | * @return error is NONE upon success. Otherwise, |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 70 | * BAD_VALUE when any of the specified attributes is |
| 71 | * invalid or conflicting. |
| 72 | * NO_RESOURCES when the creation cannot be fullfilled at |
| 73 | * this time. |
| 74 | * UNSUPPORTED when any of the specified attributes is |
| 75 | * not supported. |
| 76 | * @return descriptor is the newly created buffer descriptor. |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 77 | */ |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 78 | @entry |
| 79 | @callflow(next="*") |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 80 | createDescriptor(BufferDescriptorInfo descriptorInfo) |
| 81 | generates (Error error, |
| 82 | BufferDescriptor descriptor); |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 83 | |
Andreas Huber | 40d3a9b | 2017-03-28 16:19:16 -0700 | [diff] [blame] | 84 | /** |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 85 | * Imports a raw buffer handle to create an imported buffer handle for use |
| 86 | * with the rest of the mapper or with other in-process libraries. |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 87 | * |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 88 | * A buffer handle is considered raw when it is cloned or when it is |
| 89 | * received from another HAL or another process. A raw buffer handle must |
| 90 | * not be used to access the underlying graphics buffer. It must be |
| 91 | * imported to create an imported handle first. |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 92 | * |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 93 | * This function must at least validate the raw handle before creating the |
| 94 | * imported handle. It must also support importing the same raw handle |
| 95 | * multiple times to create multiple imported handles. The imported handle |
| 96 | * must be considered valid everywhere in the process, including in |
| 97 | * another instance of the mapper. |
| 98 | * |
| 99 | * @param rawHandle is the raw buffer handle to import. |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 100 | * @return error is NONE upon success. Otherwise, |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 101 | * BAD_BUFFER when the raw handle is invalid. |
| 102 | * NO_RESOURCES when the raw handle cannot be imported at |
| 103 | * this time. |
| 104 | * @return buffer is the imported buffer handle and has the type |
| 105 | * buffer_handle_t. |
| 106 | */ |
| 107 | @entry |
| 108 | @callflow(next="*") |
| 109 | importBuffer(handle rawHandle) generates (Error error, pointer buffer); |
| 110 | |
| 111 | /** |
| 112 | * Frees a buffer handle. Buffer handles returned by importBuffer must be |
| 113 | * freed with this function when no longer needed. |
| 114 | * |
| 115 | * This function must free up all resources allocated by importBuffer for |
| 116 | * the imported handle. For example, if the imported handle was created |
| 117 | * with native_handle_create, this function must call native_handle_close |
| 118 | * and native_handle_delete. |
| 119 | * |
| 120 | * @return error is NONE upon success. Otherwise, |
| 121 | * BAD_BUFFER when the buffer is invalid. |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 122 | */ |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 123 | @exit |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 124 | @callflow(next="*") |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 125 | freeBuffer(pointer buffer) generates (Error error); |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 126 | |
Andreas Huber | 40d3a9b | 2017-03-28 16:19:16 -0700 | [diff] [blame] | 127 | /** |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 128 | * Locks the given buffer for the specified CPU usage. |
| 129 | * |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 130 | * Locking the same buffer simultaneously from multiple threads is |
| 131 | * permitted, but if any of the threads attempt to lock the buffer for |
| 132 | * writing, the behavior is undefined, except that it must not cause |
| 133 | * process termination or block the client indefinitely. Leaving the |
| 134 | * buffer content in an indeterminate state or returning an error are both |
| 135 | * acceptable. |
| 136 | * |
| 137 | * The client must not modify the content of the buffer outside of |
| 138 | * accessRegion, and the device need not guarantee that content outside of |
| 139 | * accessRegion is valid for reading. The result of reading or writing |
| 140 | * outside of accessRegion is undefined, except that it must not cause |
| 141 | * process termination. |
| 142 | * |
| 143 | * data will be filled with a pointer to the locked buffer memory. This |
| 144 | * address will represent the top-left corner of the entire buffer, even |
| 145 | * if accessRegion does not begin at the top-left corner. |
| 146 | * |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 147 | * @param buffer is the buffer to lock. |
| 148 | * @param cpuUsage specifies one or more CPU usage flags to request. |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 149 | * @param accessRegion is the portion of the buffer that the client |
| 150 | * intends to access. |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 151 | * @param acquireFence, when non-empty, is a handle containing a file |
| 152 | * descriptor referring to a sync fence object, which will be |
| 153 | * signaled when it is safe for the mapper to lock the buffer. If |
| 154 | * it is already safe to lock, acquireFence is empty. |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 155 | * @return error is NONE upon success. Otherwise, |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 156 | * BAD_BUFFER when the buffer is invalid or is |
| 157 | * incompatible with this function. |
| 158 | * BAD_VALUE when cpuUsage is 0, contains non-CPU usage |
| 159 | * flags, or is incompatible with the buffer. |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 160 | * NO_RESOURCES when the buffer cannot be locked at this |
| 161 | * time, but locking may succeed at a future |
| 162 | * time. |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 163 | * @return data is a CPU-accessible pointer to the buffer data. |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 164 | */ |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 165 | @callflow(next="unlock") |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 166 | lock(pointer buffer, |
| 167 | bitfield<BufferUsage> cpuUsage, |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 168 | Rect accessRegion, |
| 169 | handle acquireFence) |
| 170 | generates (Error error, |
| 171 | pointer data); |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 172 | |
Andreas Huber | 40d3a9b | 2017-03-28 16:19:16 -0700 | [diff] [blame] | 173 | /** |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 174 | * This is largely the same as lock(), except that instead of returning a |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 175 | * pointer directly to the buffer data, it returns an YCbCrLayout struct |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 176 | * describing how to access the data planes. |
| 177 | * |
| 178 | * This function must work on buffers with PixelFormat::YCbCr_*_888 if |
| 179 | * supported by the device, as well as with any other formats requested by |
| 180 | * multimedia codecs when they are configured with a |
| 181 | * flexible-YUV-compatible color format. |
| 182 | * |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 183 | * @param buffer is the buffer to lock. |
| 184 | * @param cpuUsage specifies one or more CPU usage flags to request. |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 185 | * @param accessRegion is the portion of the buffer that the client |
| 186 | * intends to access. |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 187 | * @param acquireFence, when non-empty, is a handle containing a file |
| 188 | * descriptor referring to a sync fence object, which will be |
| 189 | * signaled when it is safe for the mapper to lock the buffer. If |
| 190 | * it is already safe to lock, acquireFence is empty. |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 191 | * @return error is NONE upon success. Otherwise, |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 192 | * BAD_BUFFER when the buffer is invalid or is |
| 193 | * incompatible with this function. |
| 194 | * BAD_VALUE when cpuUsage is 0, contains non-CPU usage |
| 195 | * flags, or is incompatible with the buffer. |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 196 | * NO_RESOURCES when the buffer cannot be locked at this |
| 197 | * time, but locking may succeed at a future |
| 198 | * time. |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 199 | * @return layout is the data layout of the buffer. |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 200 | */ |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 201 | @callflow(next="unlock") |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 202 | lockYCbCr(pointer buffer, |
| 203 | bitfield<BufferUsage> cpuUsage, |
| 204 | Rect accessRegion, |
| 205 | handle acquireFence) |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 206 | generates (Error error, |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 207 | YCbCrLayout layout); |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 208 | |
Andreas Huber | 40d3a9b | 2017-03-28 16:19:16 -0700 | [diff] [blame] | 209 | /** |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 210 | * Unlocks a buffer to indicate all CPU accesses to the buffer have |
| 211 | * completed. |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 212 | * |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 213 | * @param buffer is the buffer to unlock. |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 214 | * @return error is NONE upon success. Otherwise, |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 215 | * BAD_BUFFER when the buffer is invalid or not locked. |
| 216 | * @return releaseFence, when non-empty, is a handle containing a file |
| 217 | * descriptor referring to a sync fence object. The sync fence |
| 218 | * object will be signaled when the mapper has completed any |
| 219 | * pending work. |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 220 | */ |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 221 | @callflow(next="*") |
Chia-I Wu | 79d13ff | 2017-03-31 12:48:11 -0700 | [diff] [blame^] | 222 | unlock(pointer buffer) |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 223 | generates (Error error, |
| 224 | handle releaseFence); |
Chia-I Wu | 9af67ec | 2016-10-11 10:47:27 +0800 | [diff] [blame] | 225 | }; |