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 | |
Rachel Lee | 1fb2ddc | 2022-01-12 14:33:07 -0800 | [diff] [blame] | 31 | #include <android/choreographer.h> |
Marissa Wall | 3ff826c | 2019-02-07 11:58:25 -0800 | [diff] [blame] | 32 | #include <android/data_space.h> |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 33 | #include <android/hardware_buffer.h> |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 34 | #include <android/hdr_metadata.h> |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 35 | #include <android/native_window.h> |
| 36 | |
| 37 | __BEGIN_DECLS |
| 38 | |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 39 | struct ASurfaceControl; |
| 40 | |
| 41 | /** |
Elliott Hughes | 733bf99 | 2019-03-08 11:25:28 -0800 | [diff] [blame] | 42 | * 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] | 43 | * composition to the system compositor. ASurfaceControl represents a content node in |
Elliott Hughes | 733bf99 | 2019-03-08 11:25:28 -0800 | [diff] [blame] | 44 | * this hierarchy. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 45 | */ |
| 46 | typedef struct ASurfaceControl ASurfaceControl; |
| 47 | |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 48 | /** |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 49 | * Creates an ASurfaceControl with either ANativeWindow or an ASurfaceControl as its parent. |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 50 | * \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] | 51 | * identify this surface in the SurfaceFlinger's layer tree. It must not be |
| 52 | * null. |
| 53 | * |
| 54 | * The caller takes ownership of the ASurfaceControl returned and must release it |
| 55 | * using ASurfaceControl_release below. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 56 | * |
Vishnu Nair | 172d5a3 | 2023-04-25 22:23:41 +0000 | [diff] [blame] | 57 | * By default the \a ASurfaceControl will be visible and display any buffer submitted. In |
| 58 | * addition, the default buffer submission control may release and not display all buffers |
| 59 | * that are submitted before receiving a callback for the previous buffer. See |
| 60 | * \a ASurfaceTransaction_setVisibility and \a ASurfaceTransaction_setEnableBackPressure to |
| 61 | * change the default behaviors after creation. |
| 62 | * |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 63 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 64 | */ |
| 65 | ASurfaceControl* ASurfaceControl_createFromWindow(ANativeWindow* parent, const char* debug_name) |
| 66 | __INTRODUCED_IN(29); |
| 67 | |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 68 | /** |
| 69 | * See ASurfaceControl_createFromWindow. |
| 70 | * |
| 71 | * Available since API level 29. |
| 72 | */ |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 73 | ASurfaceControl* ASurfaceControl_create(ASurfaceControl* parent, const char* debug_name) |
| 74 | __INTRODUCED_IN(29); |
| 75 | |
| 76 | /** |
Huihong Luo | db5778e | 2021-01-28 14:48:59 -0800 | [diff] [blame] | 77 | * Acquires a reference on the given ASurfaceControl object. This prevents the object |
| 78 | * from being deleted until the reference is removed. |
| 79 | * |
| 80 | * To release the reference, use the ASurfaceControl_release function. |
| 81 | * |
| 82 | * Available since API level 31. |
| 83 | */ |
| 84 | void ASurfaceControl_acquire(ASurfaceControl* surface_control) __INTRODUCED_IN(31); |
| 85 | |
| 86 | /** |
| 87 | * Removes a reference that was previously acquired with one of the following functions: |
| 88 | * ASurfaceControl_createFromWindow |
| 89 | * ASurfaceControl_create |
| 90 | * ANativeWindow_acquire |
| 91 | * 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] | 92 | * |
| 93 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 94 | */ |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 95 | void ASurfaceControl_release(ASurfaceControl* surface_control) __INTRODUCED_IN(29); |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 96 | |
| 97 | struct ASurfaceTransaction; |
| 98 | |
| 99 | /** |
| 100 | * ASurfaceTransaction is a collection of updates to the surface tree that must |
| 101 | * be applied atomically. |
| 102 | */ |
| 103 | typedef struct ASurfaceTransaction ASurfaceTransaction; |
| 104 | |
| 105 | /** |
| 106 | * The caller takes ownership of the transaction and must release it using |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 107 | * ASurfaceTransaction_delete() below. |
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 | ASurfaceTransaction* ASurfaceTransaction_create() __INTRODUCED_IN(29); |
| 112 | |
| 113 | /** |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 114 | * Destroys the \a transaction object. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 115 | * |
| 116 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 117 | */ |
| 118 | void ASurfaceTransaction_delete(ASurfaceTransaction* transaction) __INTRODUCED_IN(29); |
| 119 | |
| 120 | /** |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 121 | * Applies the updates accumulated in \a transaction. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 122 | * |
| 123 | * Note that the transaction is guaranteed to be applied atomically. The |
| 124 | * transactions which are applied on the same thread are also guaranteed to be |
| 125 | * applied in order. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 126 | * |
| 127 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 128 | */ |
| 129 | void ASurfaceTransaction_apply(ASurfaceTransaction* transaction) __INTRODUCED_IN(29); |
| 130 | |
| 131 | /** |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 132 | * An opaque handle returned during a callback that can be used to query general stats and stats for |
| 133 | * surfaces which were either removed or for which buffers were updated after this transaction was |
| 134 | * applied. |
| 135 | */ |
| 136 | typedef struct ASurfaceTransactionStats ASurfaceTransactionStats; |
| 137 | |
| 138 | /** |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 139 | * Since the transactions are applied asynchronously, the |
| 140 | * ASurfaceTransaction_OnComplete callback can be used to be notified when a frame |
| 141 | * including the updates in a transaction was presented. |
| 142 | * |
Robert Carr | 1108579 | 2021-05-12 14:35:35 -0700 | [diff] [blame] | 143 | * Buffers which are replaced or removed from the scene in the transaction invoking |
| 144 | * this callback may be reused after this point. |
| 145 | * |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 146 | * \param context Optional context provided by the client that is passed into |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 147 | * the callback. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 148 | * |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 149 | * \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] | 150 | * information about the transaction. The handle is only valid during the callback. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 151 | * |
| 152 | * THREADING |
| 153 | * The transaction completed callback can be invoked on any thread. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 154 | * |
| 155 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 156 | */ |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 157 | typedef void (*ASurfaceTransaction_OnComplete)(void* context, ASurfaceTransactionStats* stats) |
| 158 | __INTRODUCED_IN(29); |
| 159 | |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 160 | |
| 161 | /** |
| 162 | * The ASurfaceTransaction_OnCommit callback is invoked when transaction is applied and the updates |
| 163 | * are ready to be presented. This callback will be invoked before the |
| 164 | * ASurfaceTransaction_OnComplete callback. |
| 165 | * |
Robert Carr | 1108579 | 2021-05-12 14:35:35 -0700 | [diff] [blame] | 166 | * This callback does not mean buffers have been released! It simply means that any new |
| 167 | * transactions applied will not overwrite the transaction for which we are receiving |
| 168 | * a callback and instead will be included in the next frame. If you are trying to avoid |
| 169 | * dropping frames (overwriting transactions), and unable to use timestamps (Which provide |
| 170 | * a more efficient solution), then this method provides a method to pace your transaction |
| 171 | * application. |
| 172 | * |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 173 | * \param context Optional context provided by the client that is passed into the callback. |
| 174 | * |
| 175 | * \param stats Opaque handle that can be passed to ASurfaceTransactionStats functions to query |
| 176 | * information about the transaction. The handle is only valid during the callback. |
| 177 | * Present and release fences are not available for this callback. Querying them using |
| 178 | * ASurfaceTransactionStats_getPresentFenceFd and ASurfaceTransactionStats_getPreviousReleaseFenceFd |
| 179 | * will result in failure. |
| 180 | * |
| 181 | * THREADING |
| 182 | * The transaction committed callback can be invoked on any thread. |
| 183 | * |
| 184 | * Available since API level 31. |
| 185 | */ |
| 186 | typedef void (*ASurfaceTransaction_OnCommit)(void* context, ASurfaceTransactionStats* stats) |
| 187 | __INTRODUCED_IN(31); |
| 188 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 189 | /** |
| 190 | * Returns the timestamp of when the frame was latched by the framework. Once a frame is |
| 191 | * latched by the framework, it is presented at the following hardware vsync. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 192 | * |
| 193 | * Available since API level 29. |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 194 | */ |
| 195 | int64_t ASurfaceTransactionStats_getLatchTime(ASurfaceTransactionStats* surface_transaction_stats) |
| 196 | __INTRODUCED_IN(29); |
| 197 | |
| 198 | /** |
| 199 | * Returns a sync fence that signals when the transaction has been presented. |
| 200 | * 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] | 201 | * 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] | 202 | * |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 203 | * This query is not valid for ASurfaceTransaction_OnCommit callback. |
| 204 | * |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 205 | * Available since API level 29. |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 206 | */ |
| 207 | int ASurfaceTransactionStats_getPresentFenceFd(ASurfaceTransactionStats* surface_transaction_stats) |
| 208 | __INTRODUCED_IN(29); |
| 209 | |
| 210 | /** |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 211 | * \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] | 212 | * transaction. Stats for the surfaces can be queried through ASurfaceTransactionStats functions. |
| 213 | * When the client is done using the array, it must release it by calling |
| 214 | * ASurfaceTransactionStats_releaseASurfaceControls. |
| 215 | * |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 216 | * Available since API level 29. |
| 217 | * |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 218 | * \a outASurfaceControlsSize returns the size of the ASurfaceControls array. |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 219 | */ |
| 220 | void ASurfaceTransactionStats_getASurfaceControls(ASurfaceTransactionStats* surface_transaction_stats, |
| 221 | ASurfaceControl*** outASurfaceControls, |
| 222 | size_t* outASurfaceControlsSize) |
| 223 | __INTRODUCED_IN(29); |
| 224 | /** |
| 225 | * Releases the array of ASurfaceControls that were returned by |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 226 | * ASurfaceTransactionStats_getASurfaceControls(). |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 227 | * |
| 228 | * Available since API level 29. |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 229 | */ |
| 230 | void ASurfaceTransactionStats_releaseASurfaceControls(ASurfaceControl** surface_controls) |
| 231 | __INTRODUCED_IN(29); |
| 232 | |
| 233 | /** |
| 234 | * Returns the timestamp of when the CURRENT buffer was acquired. A buffer is considered |
| 235 | * acquired when its acquire_fence_fd has signaled. A buffer cannot be latched or presented until |
| 236 | * 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] | 237 | * |
| 238 | * Available since API level 29. |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 239 | */ |
| 240 | int64_t ASurfaceTransactionStats_getAcquireTime(ASurfaceTransactionStats* surface_transaction_stats, |
| 241 | ASurfaceControl* surface_control) |
| 242 | __INTRODUCED_IN(29); |
| 243 | |
| 244 | /** |
| 245 | * The returns the fence used to signal the release of the PREVIOUS buffer set on |
| 246 | * this surface. If this fence is valid (>=0), the PREVIOUS buffer has not yet been released and the |
| 247 | * fence will signal when the PREVIOUS buffer has been released. If the fence is -1 , the PREVIOUS |
| 248 | * buffer is already released. The recipient of the callback takes ownership of the |
| 249 | * previousReleaseFenceFd and is responsible for closing it. |
| 250 | * |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 251 | * Each time a buffer is set through ASurfaceTransaction_setBuffer() on a transaction |
| 252 | * 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] | 253 | * addition of a buffer to a particular surface as a unique ref. When a transaction updates or |
| 254 | * removes a buffer from a surface, or removes the surface itself from the tree, this ref is |
| 255 | * guaranteed to be released in the OnComplete callback for this transaction. The |
| 256 | * ASurfaceControlStats provided in the callback for this surface may contain an optional fence |
| 257 | * which must be signaled before the ref is assumed to be released. |
| 258 | * |
| 259 | * The client must ensure that all pending refs on a buffer are released before attempting to reuse |
| 260 | * this buffer, otherwise synchronization errors may occur. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 261 | * |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 262 | * This query is not valid for ASurfaceTransaction_OnCommit callback. |
| 263 | * |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 264 | * Available since API level 29. |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 265 | */ |
| 266 | int ASurfaceTransactionStats_getPreviousReleaseFenceFd( |
| 267 | ASurfaceTransactionStats* surface_transaction_stats, |
| 268 | ASurfaceControl* surface_control) |
| 269 | __INTRODUCED_IN(29); |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 270 | |
| 271 | /** |
| 272 | * Sets the callback that will be invoked when the updates from this transaction |
| 273 | * are presented. For details on the callback semantics and data, see the |
| 274 | * comments on the ASurfaceTransaction_OnComplete declaration above. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 275 | * |
| 276 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 277 | */ |
| 278 | void ASurfaceTransaction_setOnComplete(ASurfaceTransaction* transaction, void* context, |
| 279 | ASurfaceTransaction_OnComplete func) __INTRODUCED_IN(29); |
| 280 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 281 | /** |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 282 | * Sets the callback that will be invoked when the updates from this transaction are applied and are |
| 283 | * ready to be presented. This callback will be invoked before the ASurfaceTransaction_OnComplete |
| 284 | * callback. |
| 285 | * |
| 286 | * Available since API level 31. |
| 287 | */ |
| 288 | void ASurfaceTransaction_setOnCommit(ASurfaceTransaction* transaction, void* context, |
| 289 | ASurfaceTransaction_OnCommit func) __INTRODUCED_IN(31); |
| 290 | |
| 291 | /** |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 292 | * Reparents the \a surface_control from its old parent to the \a new_parent surface control. |
| 293 | * 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] | 294 | * |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 295 | * 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] | 296 | * |
| 297 | * Available since API level 29. |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 298 | */ |
| 299 | void ASurfaceTransaction_reparent(ASurfaceTransaction* transaction, |
| 300 | ASurfaceControl* surface_control, ASurfaceControl* new_parent) |
| 301 | __INTRODUCED_IN(29); |
| 302 | |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 303 | /** |
| 304 | * Parameter for ASurfaceTransaction_setVisibility(). |
| 305 | */ |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 306 | enum { |
| 307 | ASURFACE_TRANSACTION_VISIBILITY_HIDE = 0, |
| 308 | ASURFACE_TRANSACTION_VISIBILITY_SHOW = 1, |
| 309 | }; |
| 310 | /** |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 311 | * Updates the visibility of \a surface_control. If show is set to |
| 312 | * 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] | 313 | * be hidden. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 314 | * |
| 315 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 316 | */ |
| 317 | void ASurfaceTransaction_setVisibility(ASurfaceTransaction* transaction, |
| 318 | ASurfaceControl* surface_control, int8_t visibility) |
| 319 | __INTRODUCED_IN(29); |
| 320 | |
| 321 | /** |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 322 | * 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] | 323 | * is relative to other surfaces which are siblings of this surface. The behavior of sibilings with |
| 324 | * the same z order is undefined. |
| 325 | * |
| 326 | * 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] | 327 | * |
| 328 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 329 | */ |
| 330 | void ASurfaceTransaction_setZOrder(ASurfaceTransaction* transaction, |
| 331 | ASurfaceControl* surface_control, int32_t z_order) |
| 332 | __INTRODUCED_IN(29); |
| 333 | |
| 334 | /** |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 335 | * Updates the AHardwareBuffer displayed for \a surface_control. If not -1, the |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 336 | * 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] | 337 | * for the buffer is complete and the buffer can be safely read. |
| 338 | * |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 339 | * 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] | 340 | * for closing it. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 341 | * |
Ady Abraham | 38605fc | 2021-03-29 20:33:42 +0000 | [diff] [blame] | 342 | * Note that the buffer must be allocated with AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE |
| 343 | * as the surface control might be composited using the GPU. |
| 344 | * |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 345 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 346 | */ |
| 347 | void ASurfaceTransaction_setBuffer(ASurfaceTransaction* transaction, |
| 348 | ASurfaceControl* surface_control, AHardwareBuffer* buffer, |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 349 | int acquire_fence_fd = -1) __INTRODUCED_IN(29); |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 350 | |
| 351 | /** |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 352 | * Updates the color for \a surface_control. This will make the background color for the |
| 353 | * ASurfaceControl visible in transparent regions of the surface. Colors \a r, \a g, |
| 354 | * 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] | 355 | * will be the dataspace and alpha set for the background color layer. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 356 | * |
| 357 | * Available since API level 29. |
Valerie Hau | ed54efa | 2019-01-11 20:03:14 -0800 | [diff] [blame] | 358 | */ |
| 359 | void ASurfaceTransaction_setColor(ASurfaceTransaction* transaction, |
| 360 | ASurfaceControl* surface_control, float r, float g, float b, |
| 361 | float alpha, ADataSpace dataspace) |
| 362 | __INTRODUCED_IN(29); |
| 363 | |
| 364 | /** |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 365 | * \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] | 366 | * The surface's source rect is clipped by the bounds of its current buffer. The source rect's width |
| 367 | * and height must be > 0. |
| 368 | * |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 369 | * \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] | 370 | * source rect bounds are scaled to fit the destination rect. The surface's destination rect is |
| 371 | * clipped by the bounds of its parent. The destination rect's width and height must be > 0. |
| 372 | * |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 373 | * \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] | 374 | * should be set to 0 for no transform. To specify a transfrom use the NATIVE_WINDOW_TRANSFORM_* |
| 375 | * enum. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 376 | * |
| 377 | * Available since API level 29. |
chaviw | 1f5e740 | 2021-04-29 09:15:20 -0500 | [diff] [blame] | 378 | * |
| 379 | * @deprecated Use setCrop, setPosition, setBufferTransform, and setScale instead. Those functions |
| 380 | * provide well defined behavior and allows for more control by the apps. It also allows the caller |
| 381 | * to set different properties at different times, instead of having to specify all the desired |
| 382 | * properties at once. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 383 | */ |
| 384 | void ASurfaceTransaction_setGeometry(ASurfaceTransaction* transaction, |
| 385 | ASurfaceControl* surface_control, const ARect& source, |
| 386 | const ARect& destination, int32_t transform) |
| 387 | __INTRODUCED_IN(29); |
| 388 | |
Vasiliy Telezhnikov | fb3ab5b | 2021-03-13 20:00:26 -0500 | [diff] [blame] | 389 | /** |
chaviw | be8d009 | 2021-03-29 18:49:46 -0500 | [diff] [blame] | 390 | * Bounds the surface and its children to the bounds specified. The crop and buffer size will be |
| 391 | * used to determine the bounds of the surface. If no crop is specified and the surface has no |
| 392 | * buffer, the surface bounds is only constrained by the size of its parent bounds. |
| 393 | * |
| 394 | * \param crop The bounds of the crop to apply. |
Vasiliy Telezhnikov | fb3ab5b | 2021-03-13 20:00:26 -0500 | [diff] [blame] | 395 | * |
| 396 | * Available since API level 31. |
| 397 | */ |
chaviw | be8d009 | 2021-03-29 18:49:46 -0500 | [diff] [blame] | 398 | void ASurfaceTransaction_setCrop(ASurfaceTransaction* transaction, |
| 399 | ASurfaceControl* surface_control, const ARect& crop) |
Vasiliy Telezhnikov | fb3ab5b | 2021-03-13 20:00:26 -0500 | [diff] [blame] | 400 | __INTRODUCED_IN(31); |
| 401 | |
| 402 | /** |
chaviw | be8d009 | 2021-03-29 18:49:46 -0500 | [diff] [blame] | 403 | * Specifies the position in the parent's space where the surface will be drawn. |
| 404 | * |
| 405 | * \param x The x position to render the surface. |
| 406 | * \param y The y position to render the surface. |
Vasiliy Telezhnikov | fb3ab5b | 2021-03-13 20:00:26 -0500 | [diff] [blame] | 407 | * |
| 408 | * Available since API level 31. |
| 409 | */ |
| 410 | void ASurfaceTransaction_setPosition(ASurfaceTransaction* transaction, |
chaviw | be8d009 | 2021-03-29 18:49:46 -0500 | [diff] [blame] | 411 | ASurfaceControl* surface_control, int32_t x, int32_t y) |
Vasiliy Telezhnikov | fb3ab5b | 2021-03-13 20:00:26 -0500 | [diff] [blame] | 412 | __INTRODUCED_IN(31); |
| 413 | |
| 414 | /** |
| 415 | * \param transform The transform applied after the source rect is applied to the buffer. This |
chaviw | be8d009 | 2021-03-29 18:49:46 -0500 | [diff] [blame] | 416 | * parameter should be set to 0 for no transform. To specify a transform use the |
Vasiliy Telezhnikov | fb3ab5b | 2021-03-13 20:00:26 -0500 | [diff] [blame] | 417 | * NATIVE_WINDOW_TRANSFORM_* enum. |
| 418 | * |
| 419 | * Available since API level 31. |
| 420 | */ |
chaviw | be8d009 | 2021-03-29 18:49:46 -0500 | [diff] [blame] | 421 | void ASurfaceTransaction_setBufferTransform(ASurfaceTransaction* transaction, |
Vasiliy Telezhnikov | fb3ab5b | 2021-03-13 20:00:26 -0500 | [diff] [blame] | 422 | ASurfaceControl* surface_control, int32_t transform) |
| 423 | __INTRODUCED_IN(31); |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 424 | |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 425 | /** |
chaviw | be8d009 | 2021-03-29 18:49:46 -0500 | [diff] [blame] | 426 | * Sets an x and y scale of a surface with (0, 0) as the centerpoint of the scale. |
| 427 | * |
| 428 | * \param xScale The scale in the x direction. Must be greater than 0. |
| 429 | * \param yScale The scale in the y direction. Must be greater than 0. |
| 430 | * |
| 431 | * Available since API level 31. |
| 432 | */ |
| 433 | void ASurfaceTransaction_setScale(ASurfaceTransaction* transaction, |
| 434 | ASurfaceControl* surface_control, float xScale, float yScale) |
| 435 | __INTRODUCED_IN(31); |
| 436 | /** |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 437 | * Parameter for ASurfaceTransaction_setBufferTransparency(). |
| 438 | */ |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 439 | enum { |
| 440 | ASURFACE_TRANSACTION_TRANSPARENCY_TRANSPARENT = 0, |
| 441 | ASURFACE_TRANSACTION_TRANSPARENCY_TRANSLUCENT = 1, |
| 442 | ASURFACE_TRANSACTION_TRANSPARENCY_OPAQUE = 2, |
| 443 | }; |
| 444 | /** |
| 445 | * Updates whether the content for the buffer associated with this surface is |
| 446 | * completely opaque. If true, every pixel of content inside the buffer must be |
| 447 | * opaque or visual errors can occur. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 448 | * |
| 449 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 450 | */ |
| 451 | void ASurfaceTransaction_setBufferTransparency(ASurfaceTransaction* transaction, |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 452 | ASurfaceControl* surface_control, |
| 453 | int8_t transparency) |
| 454 | __INTRODUCED_IN(29); |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 455 | |
| 456 | /** |
| 457 | * Updates the region for the content on this surface updated in this |
| 458 | * transaction. If unspecified, the complete surface is assumed to be damaged. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 459 | * |
| 460 | * Available since API level 29. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 461 | */ |
| 462 | void ASurfaceTransaction_setDamageRegion(ASurfaceTransaction* transaction, |
| 463 | ASurfaceControl* surface_control, const ARect rects[], |
| 464 | uint32_t count) __INTRODUCED_IN(29); |
| 465 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 466 | /** |
| 467 | * Specifies a desiredPresentTime for the transaction. The framework will try to present |
| 468 | * the transaction at or after the time specified. |
| 469 | * |
| 470 | * Transactions will not be presented until all of their acquire fences have signaled even if the |
| 471 | * app requests an earlier present time. |
| 472 | * |
| 473 | * If an earlier transaction has a desired present time of x, and a later transaction has a desired |
| 474 | * 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] | 475 | * |
| 476 | * Available since API level 29. |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 477 | */ |
| 478 | void ASurfaceTransaction_setDesiredPresentTime(ASurfaceTransaction* transaction, |
| 479 | int64_t desiredPresentTime) __INTRODUCED_IN(29); |
| 480 | |
| 481 | /** |
| 482 | * Sets the alpha for the buffer. It uses a premultiplied blending. |
| 483 | * |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 484 | * The \a alpha must be between 0.0 and 1.0. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 485 | * |
| 486 | * Available since API level 29. |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 487 | */ |
| 488 | void ASurfaceTransaction_setBufferAlpha(ASurfaceTransaction* transaction, |
| 489 | ASurfaceControl* surface_control, float alpha) |
| 490 | __INTRODUCED_IN(29); |
| 491 | |
Marissa Wall | 3ff826c | 2019-02-07 11:58:25 -0800 | [diff] [blame] | 492 | /** |
| 493 | * Sets the data space of the surface_control's buffers. |
| 494 | * |
| 495 | * 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] | 496 | * |
| 497 | * Available since API level 29. |
Marissa Wall | 3ff826c | 2019-02-07 11:58:25 -0800 | [diff] [blame] | 498 | */ |
| 499 | void ASurfaceTransaction_setBufferDataSpace(ASurfaceTransaction* transaction, |
| 500 | ASurfaceControl* surface_control, ADataSpace data_space) |
| 501 | __INTRODUCED_IN(29); |
| 502 | |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 503 | /** |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 504 | * SMPTE ST 2086 "Mastering Display Color Volume" static metadata |
| 505 | * |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 506 | * 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] | 507 | * the surface's buffer. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 508 | * |
| 509 | * Available since API level 29. |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 510 | */ |
| 511 | void ASurfaceTransaction_setHdrMetadata_smpte2086(ASurfaceTransaction* transaction, |
| 512 | ASurfaceControl* surface_control, |
| 513 | struct AHdrMetadata_smpte2086* metadata) |
| 514 | __INTRODUCED_IN(29); |
| 515 | |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 516 | /** |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 517 | * Sets the CTA 861.3 "HDR Static Metadata Extension" static metadata on a surface. |
| 518 | * |
Marin Shalamanov | 110c6bc | 2020-11-16 17:57:59 +0100 | [diff] [blame] | 519 | * 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] | 520 | * the surface's buffer. |
Elliott Hughes | 3d70e53 | 2019-10-29 08:59:39 -0700 | [diff] [blame] | 521 | * |
| 522 | * Available since API level 29. |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 523 | */ |
| 524 | void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* transaction, |
| 525 | ASurfaceControl* surface_control, |
| 526 | struct AHdrMetadata_cta861_3* metadata) |
| 527 | __INTRODUCED_IN(29); |
| 528 | |
Steven Thomas | 15b6f9c | 2020-03-26 13:44:28 -0700 | [diff] [blame] | 529 | /** |
John Reck | feec2c6 | 2023-02-13 10:19:08 -0500 | [diff] [blame] | 530 | * Sets the desired extended range brightness for the layer. This only applies for layers whose |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 531 | * dataspace has RANGE_EXTENDED set on it. See: ASurfaceTransaction_setDesiredHdrHeadroom, prefer |
| 532 | * using this API for formats that encode an HDR/SDR ratio as part of generating the buffer. |
Alec Mouri | 5a100fa | 2023-02-24 00:45:29 +0000 | [diff] [blame] | 533 | * |
John Reck | feec2c6 | 2023-02-13 10:19:08 -0500 | [diff] [blame] | 534 | * @param surface_control The layer whose extended range brightness is being specified |
Alec Mouri | c139220 | 2024-03-06 19:10:00 +0000 | [diff] [blame^] | 535 | * @param currentBufferRatio The current HDR/SDR ratio of the current buffer as represented as |
John Reck | feec2c6 | 2023-02-13 10:19:08 -0500 | [diff] [blame] | 536 | * peakHdrBrightnessInNits / targetSdrWhitePointInNits. For example if the |
| 537 | * buffer was rendered with a target SDR whitepoint of 100nits and a max |
| 538 | * display brightness of 200nits, this should be set to 2.0f. |
| 539 | * |
| 540 | * Default value is 1.0f. |
| 541 | * |
| 542 | * Transfer functions that encode their own brightness ranges, such as |
| 543 | * HLG or PQ, should also set this to 1.0f and instead communicate |
| 544 | * extended content brightness information via metadata such as CTA861_3 |
| 545 | * or SMPTE2086. |
| 546 | * |
| 547 | * Must be finite && >= 1.0f |
| 548 | * |
Alec Mouri | c139220 | 2024-03-06 19:10:00 +0000 | [diff] [blame^] | 549 | * @param desiredRatio The desired HDR/SDR ratio as represented as peakHdrBrightnessInNits / |
John Reck | feec2c6 | 2023-02-13 10:19:08 -0500 | [diff] [blame] | 550 | * targetSdrWhitePointInNits. This can be used to communicate the max desired |
| 551 | * brightness range. This is similar to the "max luminance" value in other |
| 552 | * HDR metadata formats, but represented as a ratio of the target SDR whitepoint |
| 553 | * to the max display brightness. The system may not be able to, or may choose |
| 554 | * not to, deliver the requested range. |
| 555 | * |
John Reck | 1fb63cc | 2023-04-19 14:39:11 -0400 | [diff] [blame] | 556 | * While requesting a large desired ratio will result in the most |
| 557 | * dynamic range, voluntarily reducing the requested range can help |
| 558 | * improve battery life as well as can improve quality by ensuring |
| 559 | * greater bit depth is allocated to the luminance range in use. |
| 560 | * |
| 561 | * Default value is 1.0f and indicates that extended range brightness |
| 562 | * is not being used, so the resulting SDR or HDR behavior will be |
| 563 | * determined entirely by the dataspace being used (ie, typically SDR |
| 564 | * however PQ or HLG transfer functions will still result in HDR) |
John Reck | feec2c6 | 2023-02-13 10:19:08 -0500 | [diff] [blame] | 565 | * |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 566 | * When called after ASurfaceTransaction_setDesiredHdrHeadroom, the |
| 567 | * desiredRatio will override the desiredHeadroom provided by |
| 568 | * ASurfaceTransaction_setDesiredHdrHeadroom. Conversely, when called before |
| 569 | * ASurfaceTransaction_setDesiredHdrHeadroom, the desiredHeadroom provided by |
| 570 | *. ASurfaceTransaction_setDesiredHdrHeadroom will override the desiredRatio. |
| 571 | * |
John Reck | feec2c6 | 2023-02-13 10:19:08 -0500 | [diff] [blame] | 572 | * Must be finite && >= 1.0f |
John Reck | 8a5e2f9 | 2023-03-16 14:27:48 -0400 | [diff] [blame] | 573 | * |
| 574 | * Available since API level 34. |
John Reck | feec2c6 | 2023-02-13 10:19:08 -0500 | [diff] [blame] | 575 | */ |
| 576 | void ASurfaceTransaction_setExtendedRangeBrightness(ASurfaceTransaction* transaction, |
| 577 | ASurfaceControl* surface_control, |
| 578 | float currentBufferRatio, |
| 579 | float desiredRatio) __INTRODUCED_IN(__ANDROID_API_U__); |
| 580 | |
| 581 | /** |
Alec Mouri | c139220 | 2024-03-06 19:10:00 +0000 | [diff] [blame^] | 582 | * Sets the desired HDR headroom for the layer. See: ASurfaceTransaction_setExtendedRangeBrightness, |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 583 | * prefer using this API for formats that conform to HDR standards like HLG or HDR10, that do not |
| 584 | * communicate a HDR/SDR ratio as part of generating the buffer. |
| 585 | * |
Alec Mouri | c139220 | 2024-03-06 19:10:00 +0000 | [diff] [blame^] | 586 | * @param surface_control The layer whose desired HDR headroom is being specified |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 587 | * |
Alec Mouri | c139220 | 2024-03-06 19:10:00 +0000 | [diff] [blame^] | 588 | * @param desiredHeadroom The desired HDR/SDR ratio as represented as peakHdrBrightnessInNits / |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 589 | * targetSdrWhitePointInNits. This can be used to communicate the max |
| 590 | * desired brightness range of the panel. The system may not be able to, or |
| 591 | * may choose not to, deliver the requested range. |
| 592 | * |
| 593 | * While requesting a large desired ratio will result in the most |
| 594 | * dynamic range, voluntarily reducing the requested range can help |
| 595 | * improve battery life as well as can improve quality by ensuring |
| 596 | * greater bit depth is allocated to the luminance range in use. |
| 597 | * |
| 598 | * Default value is 0.0f and indicates that the system will choose the best |
| 599 | * headroom for this surface control's content. Typically, this means that |
| 600 | * HLG/PQ encoded content will be displayed with some HDR headroom greater |
| 601 | * than 1.0. |
| 602 | * |
| 603 | * When called after ASurfaceTransaction_setExtendedRangeBrightness, the |
| 604 | * desiredHeadroom will override the desiredRatio provided by |
| 605 | * ASurfaceTransaction_setExtendedRangeBrightness. Conversely, when called |
| 606 | * before ASurfaceTransaction_setExtendedRangeBrightness, the desiredRatio |
| 607 | * provided by ASurfaceTransaction_setExtendedRangeBrightness will override |
| 608 | * the desiredHeadroom. |
| 609 | * |
| 610 | * Must be finite && >= 1.0f or 0.0f to indicate there is no desired |
| 611 | * headroom. |
| 612 | * |
| 613 | * Available since API level 35. |
| 614 | */ |
| 615 | void ASurfaceTransaction_setDesiredHdrHeadroom(ASurfaceTransaction* transaction, |
| 616 | ASurfaceControl* surface_control, |
| 617 | float desiredHeadroom) |
| 618 | __INTRODUCED_IN(__ANDROID_API_V__); |
| 619 | |
| 620 | /** |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 621 | * Same as ASurfaceTransaction_setFrameRateWithChangeStrategy(transaction, surface_control, |
| 622 | * frameRate, compatibility, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS). |
Steven Thomas | 6d88a48 | 2019-12-02 22:00:47 -0800 | [diff] [blame] | 623 | * |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 624 | * See ASurfaceTransaction_setFrameRateWithChangeStrategy(). |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 625 | * |
Steven Thomas | 6d88a48 | 2019-12-02 22:00:47 -0800 | [diff] [blame] | 626 | * Available since API level 30. |
| 627 | */ |
| 628 | void ASurfaceTransaction_setFrameRate(ASurfaceTransaction* transaction, |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 629 | ASurfaceControl* surface_control, float frameRate, |
| 630 | int8_t compatibility) __INTRODUCED_IN(30); |
Steven Thomas | 6d88a48 | 2019-12-02 22:00:47 -0800 | [diff] [blame] | 631 | |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 632 | /** |
| 633 | * Sets the intended frame rate for \a surface_control. |
| 634 | * |
| 635 | * On devices that are capable of running the display at different refresh rates, the system may |
| 636 | * choose a display refresh rate to better match this surface's frame rate. Usage of this API won't |
| 637 | * directly affect the application's frame production pipeline. However, because the system may |
| 638 | * change the display refresh rate, calls to this function may result in changes to Choreographer |
| 639 | * callback timings, and changes to the time interval at which the system releases buffers back to |
| 640 | * the application. |
| 641 | * |
Marin Shalamanov | a308b9d | 2021-05-05 13:43:28 +0200 | [diff] [blame] | 642 | * You can register for changes in the refresh rate using |
| 643 | * \a AChoreographer_registerRefreshRateCallback. |
| 644 | * |
Kriti Dang | 4113fc1 | 2022-08-26 16:30:37 +0200 | [diff] [blame] | 645 | * See ASurfaceTransaction_clearFrameRate(). |
| 646 | * |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 647 | * \param frameRate is the intended frame rate of this surface, in frames per second. 0 is a special |
| 648 | * value that indicates the app will accept the system's choice for the display frame rate, which is |
| 649 | * the default behavior if this function isn't called. The frameRate param does <em>not</em> need to |
| 650 | * be a valid refresh rate for this device's display - e.g., it's fine to pass 30fps to a device |
| 651 | * that can only run the display at 60fps. |
| 652 | * |
| 653 | * \param compatibility The frame rate compatibility of this surface. The compatibility value may |
| 654 | * influence the system's choice of display frame rate. To specify a compatibility use the |
Marin Shalamanov | 293ac2c | 2021-04-26 14:13:04 +0200 | [diff] [blame] | 655 | * ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_* enum. This parameter is ignored when frameRate is 0. |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 656 | * |
Marin Shalamanov | 293ac2c | 2021-04-26 14:13:04 +0200 | [diff] [blame] | 657 | * \param changeFrameRateStrategy Whether display refresh rate transitions caused by this |
| 658 | * surface should be seamless. A seamless transition is one that doesn't have any visual |
| 659 | * interruptions, such as a black screen for a second or two. See the |
| 660 | * ANATIVEWINDOW_CHANGE_FRAME_RATE_* values. This parameter is ignored when frameRate is 0. |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 661 | * |
| 662 | * Available since API level 31. |
| 663 | */ |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 664 | void ASurfaceTransaction_setFrameRateWithChangeStrategy(ASurfaceTransaction* transaction, |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 665 | ASurfaceControl* surface_control, float frameRate, |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 666 | int8_t compatibility, int8_t changeFrameRateStrategy) |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 667 | __INTRODUCED_IN(31); |
| 668 | |
Robert Carr | f08168d | 2021-03-24 15:49:18 -0700 | [diff] [blame] | 669 | /** |
Kriti Dang | 4113fc1 | 2022-08-26 16:30:37 +0200 | [diff] [blame] | 670 | * Clears the frame rate which is set for \a surface_control. |
| 671 | * |
| 672 | * This is equivalent to calling |
| 673 | * ASurfaceTransaction_setFrameRateWithChangeStrategy( |
| 674 | * transaction, 0, compatibility, changeFrameRateStrategy). |
| 675 | * |
| 676 | * Usage of this API won't directly affect the application's frame production pipeline. However, |
| 677 | * because the system may change the display refresh rate, calls to this function may result in |
| 678 | * changes to Choreographer callback timings, and changes to the time interval at which the system |
| 679 | * releases buffers back to the application. |
| 680 | * |
| 681 | * See ASurfaceTransaction_setFrameRateWithChangeStrategy() |
| 682 | * |
| 683 | * You can register for changes in the refresh rate using |
| 684 | * \a AChoreographer_registerRefreshRateCallback. |
| 685 | * |
| 686 | * See ASurfaceTransaction_setFrameRateWithChangeStrategy(). |
| 687 | * |
| 688 | * Available since API level 34. |
| 689 | */ |
| 690 | void ASurfaceTransaction_clearFrameRate(ASurfaceTransaction* transaction, |
| 691 | ASurfaceControl* surface_control) |
| 692 | __INTRODUCED_IN(__ANDROID_API_U__); |
| 693 | |
| 694 | /** |
Robert Carr | f08168d | 2021-03-24 15:49:18 -0700 | [diff] [blame] | 695 | * Indicate whether to enable backpressure for buffer submission to a given SurfaceControl. |
| 696 | * |
| 697 | * By default backpressure is disabled, which means submitting a buffer prior to receiving |
| 698 | * a callback for the previous buffer could lead to that buffer being "dropped". In cases |
| 699 | * where you are selecting for latency, this may be a desirable behavior! We had a new buffer |
| 700 | * ready, why shouldn't we show it? |
| 701 | * |
| 702 | * When back pressure is enabled, each buffer will be required to be presented |
| 703 | * before it is released and the callback delivered |
| 704 | * (absent the whole SurfaceControl being removed). |
| 705 | * |
| 706 | * Most apps are likely to have some sort of backpressure internally, e.g. you are |
| 707 | * waiting on the callback from frame N-2 before starting frame N. In high refresh |
| 708 | * rate scenarios there may not be much time between SurfaceFlinger completing frame |
| 709 | * N-1 (and therefore releasing buffer N-2) and beginning frame N. This means |
| 710 | * your app may not have enough time to respond in the callback. Using this flag |
| 711 | * and pushing buffers earlier for server side queuing will be advantageous |
| 712 | * in such cases. |
| 713 | * |
Alec Mouri | 5a100fa | 2023-02-24 00:45:29 +0000 | [diff] [blame] | 714 | * Available since API level 31. |
| 715 | * |
Robert Carr | f08168d | 2021-03-24 15:49:18 -0700 | [diff] [blame] | 716 | * \param transaction The transaction in which to make the change. |
| 717 | * \param surface_control The ASurfaceControl on which to control buffer backpressure behavior. |
| 718 | * \param enableBackPressure Whether to enable back pressure. |
| 719 | */ |
| 720 | void ASurfaceTransaction_setEnableBackPressure(ASurfaceTransaction* transaction, |
| 721 | ASurfaceControl* surface_control, |
| 722 | bool enableBackPressure) |
| 723 | __INTRODUCED_IN(31); |
| 724 | |
Rachel Lee | ed511ef | 2021-10-11 15:09:51 -0700 | [diff] [blame] | 725 | /** |
Rachel Lee | e81bf26 | 2022-08-23 14:37:59 -0700 | [diff] [blame] | 726 | * Sets the frame timeline to use in SurfaceFlinger. |
Rachel Lee | 1fb2ddc | 2022-01-12 14:33:07 -0800 | [diff] [blame] | 727 | * |
Rachel Lee | e81bf26 | 2022-08-23 14:37:59 -0700 | [diff] [blame] | 728 | * A frame timeline should be chosen based on the frame deadline the application |
| 729 | * can meet when rendering the frame and the application's desired presentation time. |
| 730 | * By setting a frame timeline, SurfaceFlinger tries to present the frame at the corresponding |
| 731 | * expected presentation time. |
Rachel Lee | 1fb2ddc | 2022-01-12 14:33:07 -0800 | [diff] [blame] | 732 | * |
| 733 | * To receive frame timelines, a callback must be posted to Choreographer using |
Rachel Lee | e81bf26 | 2022-08-23 14:37:59 -0700 | [diff] [blame] | 734 | * AChoreographer_postVsyncCallback(). The \c vsyncId can then be extracted from the |
Rachel Lee | 1fb2ddc | 2022-01-12 14:33:07 -0800 | [diff] [blame] | 735 | * callback payload using AChoreographerFrameCallbackData_getFrameTimelineVsyncId(). |
Rachel Lee | ed511ef | 2021-10-11 15:09:51 -0700 | [diff] [blame] | 736 | * |
Alec Mouri | 5a100fa | 2023-02-24 00:45:29 +0000 | [diff] [blame] | 737 | * Available since API level 33. |
| 738 | * |
Rachel Lee | e81bf26 | 2022-08-23 14:37:59 -0700 | [diff] [blame] | 739 | * \param vsyncId The vsync ID received from AChoreographer, setting the frame's presentation target |
| 740 | * to the corresponding expected presentation time and deadline from the frame to be rendered. A |
| 741 | * stale or invalid value will be ignored. |
Rachel Lee | ed511ef | 2021-10-11 15:09:51 -0700 | [diff] [blame] | 742 | */ |
| 743 | void ASurfaceTransaction_setFrameTimeline(ASurfaceTransaction* transaction, |
Rachel Lee | 1fb2ddc | 2022-01-12 14:33:07 -0800 | [diff] [blame] | 744 | AVsyncId vsyncId) __INTRODUCED_IN(33); |
Rachel Lee | ed511ef | 2021-10-11 15:09:51 -0700 | [diff] [blame] | 745 | |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 746 | __END_DECLS |
| 747 | |
| 748 | #endif // ANDROID_SURFACE_CONTROL_H |
Marin Shalamanov | 574c58d | 2021-03-18 15:10:02 +0100 | [diff] [blame] | 749 | |
| 750 | /** @} */ |