Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | |
| 17 | /** |
| 18 | * @addtogroup NativeActivity Native Activity |
| 19 | * @{ |
| 20 | */ |
| 21 | |
| 22 | /** |
| 23 | * @file surface_control.h |
| 24 | */ |
| 25 | |
| 26 | #ifndef ANDROID_SURFACE_CONTROL_H |
| 27 | #define ANDROID_SURFACE_CONTROL_H |
| 28 | |
| 29 | #include <sys/cdefs.h> |
| 30 | |
Marissa Wall | 3ff826c | 2019-02-07 11:58:25 -0800 | [diff] [blame] | 31 | #include <android/data_space.h> |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 32 | #include <android/hardware_buffer.h> |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 33 | #include <android/hdr_metadata.h> |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 34 | #include <android/native_window.h> |
| 35 | |
| 36 | __BEGIN_DECLS |
| 37 | |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 38 | struct ASurfaceControl; |
| 39 | |
| 40 | /** |
Elliott Hughes | 733bf99 | 2019-03-08 11:25:28 -0800 | [diff] [blame] | 41 | * The SurfaceControl API can be used to provide a hierarchy of surfaces for |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 42 | * composition to the system compositor. ASurfaceControl represents a content node in |
Elliott Hughes | 733bf99 | 2019-03-08 11:25:28 -0800 | [diff] [blame] | 43 | * this hierarchy. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 44 | */ |
| 45 | typedef struct ASurfaceControl ASurfaceControl; |
| 46 | |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 47 | /** |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 48 | * Creates an ASurfaceControl with either ANativeWindow or an ASurfaceControl as its parent. |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 49 | * \a debug_name is a debug name associated with this surface. It can be used to |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 50 | * identify this surface in the SurfaceFlinger's layer tree. It must not be |
| 51 | * null. |
| 52 | * |
| 53 | * The caller takes ownership of the ASurfaceControl returned and must release it |
| 54 | * using ASurfaceControl_release below. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 55 | * |
| 56 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 57 | */ |
| 58 | ASurfaceControl* ASurfaceControl_createFromWindow(ANativeWindow* parent, const char* debug_name) |
| 59 | __INTRODUCED_IN(29); |
| 60 | |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 61 | /** |
| 62 | * See ASurfaceControl_createFromWindow. |
| 63 | * |
| 64 | * Available since API level 29. |
| 65 | */ |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 66 | ASurfaceControl* ASurfaceControl_create(ASurfaceControl* parent, const char* debug_name) |
| 67 | __INTRODUCED_IN(29); |
| 68 | |
| 69 | /** |
Huihong Luo | db5778e | 2021-01-28 14:48:59 -0800 | [diff] [blame] | 70 | * Acquires a reference on the given ASurfaceControl object. This prevents the object |
| 71 | * from being deleted until the reference is removed. |
| 72 | * |
| 73 | * To release the reference, use the ASurfaceControl_release function. |
| 74 | * |
| 75 | * Available since API level 31. |
| 76 | */ |
| 77 | void ASurfaceControl_acquire(ASurfaceControl* surface_control) __INTRODUCED_IN(31); |
| 78 | |
| 79 | /** |
| 80 | * Removes a reference that was previously acquired with one of the following functions: |
| 81 | * ASurfaceControl_createFromWindow |
| 82 | * ASurfaceControl_create |
| 83 | * ANativeWindow_acquire |
| 84 | * The surface and its children may remain on display as long as their parent remains on display. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 85 | * |
| 86 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 87 | */ |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 88 | void ASurfaceControl_release(ASurfaceControl* surface_control) __INTRODUCED_IN(29); |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 89 | |
| 90 | struct ASurfaceTransaction; |
| 91 | |
| 92 | /** |
| 93 | * ASurfaceTransaction is a collection of updates to the surface tree that must |
| 94 | * be applied atomically. |
| 95 | */ |
| 96 | typedef struct ASurfaceTransaction ASurfaceTransaction; |
| 97 | |
| 98 | /** |
| 99 | * The caller takes ownership of the transaction and must release it using |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 100 | * ASurfaceTransaction_delete() below. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 101 | * |
| 102 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 103 | */ |
| 104 | ASurfaceTransaction* ASurfaceTransaction_create() __INTRODUCED_IN(29); |
| 105 | |
| 106 | /** |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 107 | * Destroys the \a transaction object. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 108 | * |
| 109 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 110 | */ |
| 111 | void ASurfaceTransaction_delete(ASurfaceTransaction* transaction) __INTRODUCED_IN(29); |
| 112 | |
| 113 | /** |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 114 | * Applies the updates accumulated in \a transaction. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 115 | * |
| 116 | * Note that the transaction is guaranteed to be applied atomically. The |
| 117 | * transactions which are applied on the same thread are also guaranteed to be |
| 118 | * applied in order. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 119 | * |
| 120 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 121 | */ |
| 122 | void ASurfaceTransaction_apply(ASurfaceTransaction* transaction) __INTRODUCED_IN(29); |
| 123 | |
| 124 | /** |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 125 | * An opaque handle returned during a callback that can be used to query general stats and stats for |
| 126 | * surfaces which were either removed or for which buffers were updated after this transaction was |
| 127 | * applied. |
| 128 | */ |
| 129 | typedef struct ASurfaceTransactionStats ASurfaceTransactionStats; |
| 130 | |
| 131 | /** |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 132 | * Since the transactions are applied asynchronously, the |
| 133 | * ASurfaceTransaction_OnComplete callback can be used to be notified when a frame |
| 134 | * including the updates in a transaction was presented. |
| 135 | * |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 136 | * \param context Optional context provided by the client that is passed into |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 137 | * the callback. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 138 | * |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 139 | * \param stats Opaque handle that can be passed to ASurfaceTransactionStats functions to query |
Elliott Hughes | 733bf99 | 2019-03-08 11:25:28 -0800 | [diff] [blame] | 140 | * information about the transaction. The handle is only valid during the callback. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 141 | * |
| 142 | * THREADING |
| 143 | * The transaction completed callback can be invoked on any thread. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 144 | * |
| 145 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 146 | */ |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 147 | typedef void (*ASurfaceTransaction_OnComplete)(void* context, ASurfaceTransactionStats* stats) |
| 148 | __INTRODUCED_IN(29); |
| 149 | |
| 150 | /** |
| 151 | * Returns the timestamp of when the frame was latched by the framework. Once a frame is |
| 152 | * latched by the framework, it is presented at the following hardware vsync. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 153 | * |
| 154 | * Available since API level 29. |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 155 | */ |
| 156 | int64_t ASurfaceTransactionStats_getLatchTime(ASurfaceTransactionStats* surface_transaction_stats) |
| 157 | __INTRODUCED_IN(29); |
| 158 | |
| 159 | /** |
| 160 | * Returns a sync fence that signals when the transaction has been presented. |
| 161 | * The recipient of the callback takes ownership of the fence and is responsible for closing |
Marissa Wall | 183c44c | 2019-04-08 12:58:50 -0700 | [diff] [blame] | 162 | * it. If a device does not support present fences, a -1 will be returned. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 163 | * |
| 164 | * Available since API level 29. |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 165 | */ |
| 166 | int ASurfaceTransactionStats_getPresentFenceFd(ASurfaceTransactionStats* surface_transaction_stats) |
| 167 | __INTRODUCED_IN(29); |
| 168 | |
| 169 | /** |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 170 | * \a outASurfaceControls returns an array of ASurfaceControl pointers that were updated during the |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 171 | * transaction. Stats for the surfaces can be queried through ASurfaceTransactionStats functions. |
| 172 | * When the client is done using the array, it must release it by calling |
| 173 | * ASurfaceTransactionStats_releaseASurfaceControls. |
| 174 | * |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 175 | * Available since API level 29. |
| 176 | * |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 177 | * \a outASurfaceControlsSize returns the size of the ASurfaceControls array. |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 178 | */ |
| 179 | void ASurfaceTransactionStats_getASurfaceControls(ASurfaceTransactionStats* surface_transaction_stats, |
| 180 | ASurfaceControl*** outASurfaceControls, |
| 181 | size_t* outASurfaceControlsSize) |
| 182 | __INTRODUCED_IN(29); |
| 183 | /** |
| 184 | * Releases the array of ASurfaceControls that were returned by |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 185 | * ASurfaceTransactionStats_getASurfaceControls(). |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 186 | * |
| 187 | * Available since API level 29. |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 188 | */ |
| 189 | void ASurfaceTransactionStats_releaseASurfaceControls(ASurfaceControl** surface_controls) |
| 190 | __INTRODUCED_IN(29); |
| 191 | |
| 192 | /** |
| 193 | * Returns the timestamp of when the CURRENT buffer was acquired. A buffer is considered |
| 194 | * acquired when its acquire_fence_fd has signaled. A buffer cannot be latched or presented until |
| 195 | * it is acquired. If no acquire_fence_fd was provided, this timestamp will be set to -1. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 196 | * |
| 197 | * Available since API level 29. |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 198 | */ |
| 199 | int64_t ASurfaceTransactionStats_getAcquireTime(ASurfaceTransactionStats* surface_transaction_stats, |
| 200 | ASurfaceControl* surface_control) |
| 201 | __INTRODUCED_IN(29); |
| 202 | |
| 203 | /** |
| 204 | * The returns the fence used to signal the release of the PREVIOUS buffer set on |
| 205 | * this surface. If this fence is valid (>=0), the PREVIOUS buffer has not yet been released and the |
| 206 | * fence will signal when the PREVIOUS buffer has been released. If the fence is -1 , the PREVIOUS |
| 207 | * buffer is already released. The recipient of the callback takes ownership of the |
| 208 | * previousReleaseFenceFd and is responsible for closing it. |
| 209 | * |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 210 | * Each time a buffer is set through ASurfaceTransaction_setBuffer() on a transaction |
| 211 | * which is applied, the framework takes a ref on this buffer. The framework treats the |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 212 | * addition of a buffer to a particular surface as a unique ref. When a transaction updates or |
| 213 | * removes a buffer from a surface, or removes the surface itself from the tree, this ref is |
| 214 | * guaranteed to be released in the OnComplete callback for this transaction. The |
| 215 | * ASurfaceControlStats provided in the callback for this surface may contain an optional fence |
| 216 | * which must be signaled before the ref is assumed to be released. |
| 217 | * |
| 218 | * The client must ensure that all pending refs on a buffer are released before attempting to reuse |
| 219 | * this buffer, otherwise synchronization errors may occur. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 220 | * |
| 221 | * Available since API level 29. |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 222 | */ |
| 223 | int ASurfaceTransactionStats_getPreviousReleaseFenceFd( |
| 224 | ASurfaceTransactionStats* surface_transaction_stats, |
| 225 | ASurfaceControl* surface_control) |
| 226 | __INTRODUCED_IN(29); |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 227 | |
| 228 | /** |
| 229 | * Sets the callback that will be invoked when the updates from this transaction |
| 230 | * are presented. For details on the callback semantics and data, see the |
| 231 | * comments on the ASurfaceTransaction_OnComplete declaration above. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 232 | * |
| 233 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 234 | */ |
| 235 | void ASurfaceTransaction_setOnComplete(ASurfaceTransaction* transaction, void* context, |
| 236 | ASurfaceTransaction_OnComplete func) __INTRODUCED_IN(29); |
| 237 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 238 | /** |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 239 | * Reparents the \a surface_control from its old parent to the \a new_parent surface control. |
| 240 | * Any children of the reparented \a surface_control will remain children of the \a surface_control. |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 241 | * |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 242 | * The \a new_parent can be null. Surface controls with a null parent do not appear on the display. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 243 | * |
| 244 | * Available since API level 29. |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 245 | */ |
| 246 | void ASurfaceTransaction_reparent(ASurfaceTransaction* transaction, |
| 247 | ASurfaceControl* surface_control, ASurfaceControl* new_parent) |
| 248 | __INTRODUCED_IN(29); |
| 249 | |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 250 | /** |
| 251 | * Parameter for ASurfaceTransaction_setVisibility(). |
| 252 | */ |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 253 | enum { |
| 254 | ASURFACE_TRANSACTION_VISIBILITY_HIDE = 0, |
| 255 | ASURFACE_TRANSACTION_VISIBILITY_SHOW = 1, |
| 256 | }; |
| 257 | /** |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 258 | * Updates the visibility of \a surface_control. If show is set to |
| 259 | * ASURFACE_TRANSACTION_VISIBILITY_HIDE, the \a surface_control and all surfaces in its subtree will |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 260 | * be hidden. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 261 | * |
| 262 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 263 | */ |
| 264 | void ASurfaceTransaction_setVisibility(ASurfaceTransaction* transaction, |
| 265 | ASurfaceControl* surface_control, int8_t visibility) |
| 266 | __INTRODUCED_IN(29); |
| 267 | |
| 268 | /** |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 269 | * Updates the z order index for \a surface_control. Note that the z order for a surface |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 270 | * is relative to other surfaces which are siblings of this surface. The behavior of sibilings with |
| 271 | * the same z order is undefined. |
| 272 | * |
| 273 | * Z orders may be from MIN_INT32 to MAX_INT32. A layer's default z order index is 0. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 274 | * |
| 275 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 276 | */ |
| 277 | void ASurfaceTransaction_setZOrder(ASurfaceTransaction* transaction, |
| 278 | ASurfaceControl* surface_control, int32_t z_order) |
| 279 | __INTRODUCED_IN(29); |
| 280 | |
| 281 | /** |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 282 | * Updates the AHardwareBuffer displayed for \a surface_control. If not -1, the |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 283 | * acquire_fence_fd should be a file descriptor that is signaled when all pending work |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 284 | * for the buffer is complete and the buffer can be safely read. |
| 285 | * |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 286 | * The frameworks takes ownership of the \a acquire_fence_fd passed and is responsible |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 287 | * for closing it. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 288 | * |
| 289 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 290 | */ |
| 291 | void ASurfaceTransaction_setBuffer(ASurfaceTransaction* transaction, |
| 292 | ASurfaceControl* surface_control, AHardwareBuffer* buffer, |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 293 | int acquire_fence_fd = -1) __INTRODUCED_IN(29); |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 294 | |
| 295 | /** |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 296 | * Updates the color for \a surface_control. This will make the background color for the |
| 297 | * ASurfaceControl visible in transparent regions of the surface. Colors \a r, \a g, |
| 298 | * and \a b must be within the range that is valid for \a dataspace. \a dataspace and \a alpha |
Valerie Hau | ed54efa | 2019-01-11 20:03:14 -0800 | [diff] [blame] | 299 | * will be the dataspace and alpha set for the background color layer. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 300 | * |
| 301 | * Available since API level 29. |
Valerie Hau | ed54efa | 2019-01-11 20:03:14 -0800 | [diff] [blame] | 302 | */ |
| 303 | void ASurfaceTransaction_setColor(ASurfaceTransaction* transaction, |
| 304 | ASurfaceControl* surface_control, float r, float g, float b, |
| 305 | float alpha, ADataSpace dataspace) |
| 306 | __INTRODUCED_IN(29); |
| 307 | |
| 308 | /** |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 309 | * \param source The sub-rect within the buffer's content to be rendered inside the surface's area |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 310 | * The surface's source rect is clipped by the bounds of its current buffer. The source rect's width |
| 311 | * and height must be > 0. |
| 312 | * |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 313 | * \param destination Specifies the rect in the parent's space where this surface will be drawn. The post |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 314 | * source rect bounds are scaled to fit the destination rect. The surface's destination rect is |
| 315 | * clipped by the bounds of its parent. The destination rect's width and height must be > 0. |
| 316 | * |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 317 | * \param transform The transform applied after the source rect is applied to the buffer. This parameter |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 318 | * should be set to 0 for no transform. To specify a transfrom use the NATIVE_WINDOW_TRANSFORM_* |
| 319 | * enum. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 320 | * |
| 321 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 322 | */ |
| 323 | void ASurfaceTransaction_setGeometry(ASurfaceTransaction* transaction, |
| 324 | ASurfaceControl* surface_control, const ARect& source, |
| 325 | const ARect& destination, int32_t transform) |
| 326 | __INTRODUCED_IN(29); |
| 327 | |
| 328 | |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 329 | /** |
| 330 | * Parameter for ASurfaceTransaction_setBufferTransparency(). |
| 331 | */ |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 332 | enum { |
| 333 | ASURFACE_TRANSACTION_TRANSPARENCY_TRANSPARENT = 0, |
| 334 | ASURFACE_TRANSACTION_TRANSPARENCY_TRANSLUCENT = 1, |
| 335 | ASURFACE_TRANSACTION_TRANSPARENCY_OPAQUE = 2, |
| 336 | }; |
| 337 | /** |
| 338 | * Updates whether the content for the buffer associated with this surface is |
| 339 | * completely opaque. If true, every pixel of content inside the buffer must be |
| 340 | * opaque or visual errors can occur. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 341 | * |
| 342 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 343 | */ |
| 344 | void ASurfaceTransaction_setBufferTransparency(ASurfaceTransaction* transaction, |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 345 | ASurfaceControl* surface_control, |
| 346 | int8_t transparency) |
| 347 | __INTRODUCED_IN(29); |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 348 | |
| 349 | /** |
| 350 | * Updates the region for the content on this surface updated in this |
| 351 | * transaction. If unspecified, the complete surface is assumed to be damaged. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 352 | * |
| 353 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 354 | */ |
| 355 | void ASurfaceTransaction_setDamageRegion(ASurfaceTransaction* transaction, |
| 356 | ASurfaceControl* surface_control, const ARect rects[], |
| 357 | uint32_t count) __INTRODUCED_IN(29); |
| 358 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 359 | /** |
| 360 | * Specifies a desiredPresentTime for the transaction. The framework will try to present |
| 361 | * the transaction at or after the time specified. |
| 362 | * |
| 363 | * Transactions will not be presented until all of their acquire fences have signaled even if the |
| 364 | * app requests an earlier present time. |
| 365 | * |
| 366 | * If an earlier transaction has a desired present time of x, and a later transaction has a desired |
| 367 | * present time that is before x, the later transaction will not preempt the earlier transaction. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 368 | * |
| 369 | * Available since API level 29. |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 370 | */ |
| 371 | void ASurfaceTransaction_setDesiredPresentTime(ASurfaceTransaction* transaction, |
| 372 | int64_t desiredPresentTime) __INTRODUCED_IN(29); |
| 373 | |
| 374 | /** |
| 375 | * Sets the alpha for the buffer. It uses a premultiplied blending. |
| 376 | * |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 377 | * The \a alpha must be between 0.0 and 1.0. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 378 | * |
| 379 | * Available since API level 29. |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 380 | */ |
| 381 | void ASurfaceTransaction_setBufferAlpha(ASurfaceTransaction* transaction, |
| 382 | ASurfaceControl* surface_control, float alpha) |
| 383 | __INTRODUCED_IN(29); |
| 384 | |
Marissa Wall | 3ff826c | 2019-02-07 11:58:25 -0800 | [diff] [blame] | 385 | /** |
| 386 | * Sets the data space of the surface_control's buffers. |
| 387 | * |
| 388 | * If no data space is set, the surface control defaults to ADATASPACE_SRGB. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 389 | * |
| 390 | * Available since API level 29. |
Marissa Wall | 3ff826c | 2019-02-07 11:58:25 -0800 | [diff] [blame] | 391 | */ |
| 392 | void ASurfaceTransaction_setBufferDataSpace(ASurfaceTransaction* transaction, |
| 393 | ASurfaceControl* surface_control, ADataSpace data_space) |
| 394 | __INTRODUCED_IN(29); |
| 395 | |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 396 | /** |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 397 | * SMPTE ST 2086 "Mastering Display Color Volume" static metadata |
| 398 | * |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 399 | * When \a metadata is set to null, the framework does not use any smpte2086 metadata when rendering |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 400 | * the surface's buffer. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 401 | * |
| 402 | * Available since API level 29. |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 403 | */ |
| 404 | void ASurfaceTransaction_setHdrMetadata_smpte2086(ASurfaceTransaction* transaction, |
| 405 | ASurfaceControl* surface_control, |
| 406 | struct AHdrMetadata_smpte2086* metadata) |
| 407 | __INTRODUCED_IN(29); |
| 408 | |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 409 | /** |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 410 | * Sets the CTA 861.3 "HDR Static Metadata Extension" static metadata on a surface. |
| 411 | * |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 412 | * When \a metadata is set to null, the framework does not use any cta861.3 metadata when rendering |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 413 | * the surface's buffer. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 414 | * |
| 415 | * Available since API level 29. |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 416 | */ |
| 417 | void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* transaction, |
| 418 | ASurfaceControl* surface_control, |
| 419 | struct AHdrMetadata_cta861_3* metadata) |
| 420 | __INTRODUCED_IN(29); |
| 421 | |
Steven Thomas | 15b6f9c | 2020-03-26 13:44:28 -0700 | [diff] [blame] | 422 | /** |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 423 | * Same as ASurfaceTransaction_setFrameRateWithSeamlessness(transaction, surface_control, |
| 424 | * frameRate, compatibility, true). |
Steven Thomas | 6d88a48 | 2019-12-02 22:00:47 -0800 | [diff] [blame] | 425 | * |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 426 | * See ASurfaceTransaction_setFrameRateWithSeamlessness(). |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 427 | * |
Steven Thomas | 6d88a48 | 2019-12-02 22:00:47 -0800 | [diff] [blame] | 428 | * Available since API level 30. |
| 429 | */ |
| 430 | void ASurfaceTransaction_setFrameRate(ASurfaceTransaction* transaction, |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 431 | ASurfaceControl* surface_control, float frameRate, |
| 432 | int8_t compatibility) __INTRODUCED_IN(30); |
Steven Thomas | 6d88a48 | 2019-12-02 22:00:47 -0800 | [diff] [blame] | 433 | |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 434 | /** |
| 435 | * Sets the intended frame rate for \a surface_control. |
| 436 | * |
| 437 | * On devices that are capable of running the display at different refresh rates, the system may |
| 438 | * choose a display refresh rate to better match this surface's frame rate. Usage of this API won't |
| 439 | * directly affect the application's frame production pipeline. However, because the system may |
| 440 | * change the display refresh rate, calls to this function may result in changes to Choreographer |
| 441 | * callback timings, and changes to the time interval at which the system releases buffers back to |
| 442 | * the application. |
| 443 | * |
| 444 | * \param frameRate is the intended frame rate of this surface, in frames per second. 0 is a special |
| 445 | * value that indicates the app will accept the system's choice for the display frame rate, which is |
| 446 | * the default behavior if this function isn't called. The frameRate param does <em>not</em> need to |
| 447 | * be a valid refresh rate for this device's display - e.g., it's fine to pass 30fps to a device |
| 448 | * that can only run the display at 60fps. |
| 449 | * |
| 450 | * \param compatibility The frame rate compatibility of this surface. The compatibility value may |
| 451 | * influence the system's choice of display frame rate. To specify a compatibility use the |
| 452 | * ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_* enum. |
| 453 | * |
| 454 | * \param shouldBeSeamless Whether display refresh rate transitions should be seamless. A |
| 455 | * seamless transition is one that doesn't have any visual interruptions, such as a black |
| 456 | * screen for a second or two. True indicates that any frame rate changes caused by this |
| 457 | * request should be seamless. False indicates that non-seamless refresh rates are also |
| 458 | * acceptable. |
| 459 | * |
| 460 | * Available since API level 31. |
| 461 | */ |
| 462 | void ASurfaceTransaction_setFrameRateWithSeamlessness(ASurfaceTransaction* transaction, |
| 463 | ASurfaceControl* surface_control, float frameRate, |
| 464 | int8_t compatibility, bool shouldBeSeamless) |
| 465 | __INTRODUCED_IN(31); |
| 466 | |
Robert Carr | f08168d | 2021-03-24 15:49:18 -0700 | [diff] [blame^] | 467 | /** |
| 468 | * Indicate whether to enable backpressure for buffer submission to a given SurfaceControl. |
| 469 | * |
| 470 | * By default backpressure is disabled, which means submitting a buffer prior to receiving |
| 471 | * a callback for the previous buffer could lead to that buffer being "dropped". In cases |
| 472 | * where you are selecting for latency, this may be a desirable behavior! We had a new buffer |
| 473 | * ready, why shouldn't we show it? |
| 474 | * |
| 475 | * When back pressure is enabled, each buffer will be required to be presented |
| 476 | * before it is released and the callback delivered |
| 477 | * (absent the whole SurfaceControl being removed). |
| 478 | * |
| 479 | * Most apps are likely to have some sort of backpressure internally, e.g. you are |
| 480 | * waiting on the callback from frame N-2 before starting frame N. In high refresh |
| 481 | * rate scenarios there may not be much time between SurfaceFlinger completing frame |
| 482 | * N-1 (and therefore releasing buffer N-2) and beginning frame N. This means |
| 483 | * your app may not have enough time to respond in the callback. Using this flag |
| 484 | * and pushing buffers earlier for server side queuing will be advantageous |
| 485 | * in such cases. |
| 486 | * |
| 487 | * \param transaction The transaction in which to make the change. |
| 488 | * \param surface_control The ASurfaceControl on which to control buffer backpressure behavior. |
| 489 | * \param enableBackPressure Whether to enable back pressure. |
| 490 | */ |
| 491 | void ASurfaceTransaction_setEnableBackPressure(ASurfaceTransaction* transaction, |
| 492 | ASurfaceControl* surface_control, |
| 493 | bool enableBackPressure) |
| 494 | __INTRODUCED_IN(31); |
| 495 | |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 496 | __END_DECLS |
| 497 | |
| 498 | #endif // ANDROID_SURFACE_CONTROL_H |
Marin Shalamanov | 574c58d | 2021-03-18 15:10:02 +0100 | [diff] [blame] | 499 | |
| 500 | /** @} */ |