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