blob: bf9acb37daa05a3936c063fc44531b776b3704de [file] [log] [blame]
Marissa Wall53da7e32018-09-25 15:59:38 -07001/*
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 Lee1fb2ddc2022-01-12 14:33:07 -080031#include <android/choreographer.h>
Marissa Wall3ff826c2019-02-07 11:58:25 -080032#include <android/data_space.h>
Marissa Wall53da7e32018-09-25 15:59:38 -070033#include <android/hardware_buffer.h>
Marissa Wall80d94ad2019-01-18 16:04:36 -080034#include <android/hdr_metadata.h>
Marissa Wall53da7e32018-09-25 15:59:38 -070035#include <android/native_window.h>
36
37__BEGIN_DECLS
38
Marissa Wall53da7e32018-09-25 15:59:38 -070039struct ASurfaceControl;
40
41/**
Elliott Hughes733bf992019-03-08 11:25:28 -080042 * The SurfaceControl API can be used to provide a hierarchy of surfaces for
Marissa Wall53da7e32018-09-25 15:59:38 -070043 * composition to the system compositor. ASurfaceControl represents a content node in
Elliott Hughes733bf992019-03-08 11:25:28 -080044 * this hierarchy.
Marissa Wall53da7e32018-09-25 15:59:38 -070045 */
46typedef struct ASurfaceControl ASurfaceControl;
47
Elliott Hughes3d70e532019-10-29 08:59:39 -070048/**
Marissa Wall53da7e32018-09-25 15:59:38 -070049 * Creates an ASurfaceControl with either ANativeWindow or an ASurfaceControl as its parent.
Marin Shalamanov110c6bc2020-11-16 17:57:59 +010050 * \a debug_name is a debug name associated with this surface. It can be used to
Marissa Wall53da7e32018-09-25 15:59:38 -070051 * 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 Hughes3d70e532019-10-29 08:59:39 -070056 *
Vishnu Nair172d5a32023-04-25 22:23:41 +000057 * 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 Hughes3d70e532019-10-29 08:59:39 -070063 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -070064 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +010065ASurfaceControl* _Nullable ASurfaceControl_createFromWindow(ANativeWindow* _Nonnull parent,
66 const char* _Nonnull debug_name)
67 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -070068
Elliott Hughes3d70e532019-10-29 08:59:39 -070069/**
70 * See ASurfaceControl_createFromWindow.
71 *
72 * Available since API level 29.
73 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +010074ASurfaceControl* _Nullable ASurfaceControl_create(ASurfaceControl* _Nonnull parent,
75 const char* _Nonnull debug_name)
76 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -070077
78/**
Huihong Luodb5778e2021-01-28 14:48:59 -080079 * 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 Suijtenc2440ff2024-01-19 00:44:53 +010086void ASurfaceControl_acquire(ASurfaceControl* _Nonnull surface_control) __INTRODUCED_IN(31);
Huihong Luodb5778e2021-01-28 14:48:59 -080087
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 Hughes3d70e532019-10-29 08:59:39 -070094 *
95 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -070096 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +010097void ASurfaceControl_release(ASurfaceControl* _Nonnull surface_control) __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -070098
99struct ASurfaceTransaction;
100
101/**
102 * ASurfaceTransaction is a collection of updates to the surface tree that must
103 * be applied atomically.
104 */
105typedef struct ASurfaceTransaction ASurfaceTransaction;
106
107/**
108 * The caller takes ownership of the transaction and must release it using
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100109 * ASurfaceTransaction_delete() below.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700110 *
111 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700112 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100113ASurfaceTransaction* _Nonnull ASurfaceTransaction_create() __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700114
115/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100116 * Destroys the \a transaction object.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700117 *
118 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700119 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100120void ASurfaceTransaction_delete(ASurfaceTransaction* _Nullable transaction) __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700121
122/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100123 * Applies the updates accumulated in \a transaction.
Marissa Wall53da7e32018-09-25 15:59:38 -0700124 *
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 Hughes3d70e532019-10-29 08:59:39 -0700128 *
129 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700130 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100131void ASurfaceTransaction_apply(ASurfaceTransaction* _Nonnull transaction) __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700132
133/**
Marissa Wall80d94ad2019-01-18 16:04:36 -0800134 * 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 */
138typedef struct ASurfaceTransactionStats ASurfaceTransactionStats;
139
140/**
Marissa Wall53da7e32018-09-25 15:59:38 -0700141 * 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 Carr11085792021-05-12 14:35:35 -0700145 * Buffers which are replaced or removed from the scene in the transaction invoking
146 * this callback may be reused after this point.
147 *
Vishnu Nair879a41a2024-09-16 17:43:59 +0000148 * Starting with API level 36, prefer using \a ASurfaceTransaction_OnBufferRelease to listen
149 * to when a buffer is ready to be reused.
150 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100151 * \param context Optional context provided by the client that is passed into
Marissa Wall53da7e32018-09-25 15:59:38 -0700152 * the callback.
Marissa Wall53da7e32018-09-25 15:59:38 -0700153 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100154 * \param stats Opaque handle that can be passed to ASurfaceTransactionStats functions to query
Elliott Hughes733bf992019-03-08 11:25:28 -0800155 * information about the transaction. The handle is only valid during the callback.
Marissa Wall53da7e32018-09-25 15:59:38 -0700156 *
157 * THREADING
158 * The transaction completed callback can be invoked on any thread.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700159 *
160 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700161 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100162typedef void (*ASurfaceTransaction_OnComplete)(void* _Null_unspecified context,
Vishnu Nair72c71a82024-09-17 23:00:20 +0000163 ASurfaceTransactionStats* _Nonnull stats);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700164
165/**
166 * The ASurfaceTransaction_OnCommit callback is invoked when transaction is applied and the updates
167 * are ready to be presented. This callback will be invoked before the
168 * ASurfaceTransaction_OnComplete callback.
169 *
Robert Carr11085792021-05-12 14:35:35 -0700170 * This callback does not mean buffers have been released! It simply means that any new
171 * transactions applied will not overwrite the transaction for which we are receiving
172 * a callback and instead will be included in the next frame. If you are trying to avoid
173 * dropping frames (overwriting transactions), and unable to use timestamps (Which provide
174 * a more efficient solution), then this method provides a method to pace your transaction
175 * application.
176 *
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700177 * \param context Optional context provided by the client that is passed into the callback.
178 *
179 * \param stats Opaque handle that can be passed to ASurfaceTransactionStats functions to query
180 * information about the transaction. The handle is only valid during the callback.
181 * Present and release fences are not available for this callback. Querying them using
182 * ASurfaceTransactionStats_getPresentFenceFd and ASurfaceTransactionStats_getPreviousReleaseFenceFd
183 * will result in failure.
184 *
185 * THREADING
186 * The transaction committed callback can be invoked on any thread.
187 *
188 * Available since API level 31.
189 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100190typedef void (*ASurfaceTransaction_OnCommit)(void* _Null_unspecified context,
Vishnu Nair72c71a82024-09-17 23:00:20 +0000191 ASurfaceTransactionStats* _Nonnull stats);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700192
Marissa Wall80d94ad2019-01-18 16:04:36 -0800193/**
Vishnu Nair879a41a2024-09-16 17:43:59 +0000194 * The ASurfaceTransaction_OnBufferRelease callback is invoked when a buffer that was passed in
195 * ASurfaceTransaction_setBuffer is ready to be reused.
196 *
197 * This callback is guaranteed to be invoked if ASurfaceTransaction_setBuffer is called with a non
198 * null buffer. If the buffer in the transaction is replaced via another call to
199 * ASurfaceTransaction_setBuffer, the callback will be invoked immediately. Otherwise the callback
200 * will be invoked before the ASurfaceTransaction_OnComplete callback after the buffer was
201 * presented.
202 *
203 * If this callback is set, caller should not release the buffer using the
204 * ASurfaceTransaction_OnComplete.
205 *
206 * \param context Optional context provided by the client that is passed into the callback.
207 *
208 * \param release_fence_fd Returns the fence file descriptor used to signal the release of buffer
209 * associated with this callback. If this fence is valid (>=0), the buffer has not yet been released
210 * and the fence will signal when the buffer has been released. If the fence is -1 , the buffer is
211 * already released. The recipient of the callback takes ownership of the fence fd and is
212 * responsible for closing it.
213 *
214 * THREADING
215 * The callback can be invoked on any thread.
216 *
217 * Available since API level 36.
218 */
219typedef void (*ASurfaceTransaction_OnBufferRelease)(void* _Null_unspecified context,
Vishnu Nair72c71a82024-09-17 23:00:20 +0000220 int release_fence_fd);
Vishnu Nair879a41a2024-09-16 17:43:59 +0000221
222/**
Marissa Wall80d94ad2019-01-18 16:04:36 -0800223 * Returns the timestamp of when the frame was latched by the framework. Once a frame is
224 * latched by the framework, it is presented at the following hardware vsync.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700225 *
226 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800227 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100228int64_t ASurfaceTransactionStats_getLatchTime(
229 ASurfaceTransactionStats* _Nonnull surface_transaction_stats) __INTRODUCED_IN(29);
Marissa Wall80d94ad2019-01-18 16:04:36 -0800230
231/**
232 * Returns a sync fence that signals when the transaction has been presented.
233 * The recipient of the callback takes ownership of the fence and is responsible for closing
Marissa Wall183c44c2019-04-08 12:58:50 -0700234 * it. If a device does not support present fences, a -1 will be returned.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700235 *
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700236 * This query is not valid for ASurfaceTransaction_OnCommit callback.
237 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700238 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800239 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100240int ASurfaceTransactionStats_getPresentFenceFd(
241 ASurfaceTransactionStats* _Nonnull surface_transaction_stats) __INTRODUCED_IN(29);
Marissa Wall80d94ad2019-01-18 16:04:36 -0800242
243/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100244 * \a outASurfaceControls returns an array of ASurfaceControl pointers that were updated during the
Marissa Wall80d94ad2019-01-18 16:04:36 -0800245 * transaction. Stats for the surfaces can be queried through ASurfaceTransactionStats functions.
246 * When the client is done using the array, it must release it by calling
247 * ASurfaceTransactionStats_releaseASurfaceControls.
248 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700249 * Available since API level 29.
250 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100251 * \a outASurfaceControlsSize returns the size of the ASurfaceControls array.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800252 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100253void ASurfaceTransactionStats_getASurfaceControls(
254 ASurfaceTransactionStats* _Nonnull surface_transaction_stats,
255 ASurfaceControl* _Nullable* _Nullable* _Nonnull outASurfaceControls,
256 size_t* _Nonnull outASurfaceControlsSize) __INTRODUCED_IN(29);
Marissa Wall80d94ad2019-01-18 16:04:36 -0800257/**
258 * Releases the array of ASurfaceControls that were returned by
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100259 * ASurfaceTransactionStats_getASurfaceControls().
Elliott Hughes3d70e532019-10-29 08:59:39 -0700260 *
261 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800262 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100263void ASurfaceTransactionStats_releaseASurfaceControls(
264 ASurfaceControl* _Nonnull* _Nonnull surface_controls) __INTRODUCED_IN(29);
Marissa Wall80d94ad2019-01-18 16:04:36 -0800265
266/**
267 * Returns the timestamp of when the CURRENT buffer was acquired. A buffer is considered
268 * acquired when its acquire_fence_fd has signaled. A buffer cannot be latched or presented until
269 * it is acquired. If no acquire_fence_fd was provided, this timestamp will be set to -1.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700270 *
271 * Available since API level 29.
Chavi Weingartenfed621c2024-03-14 15:46:05 +0000272 *
273 * @deprecated This may return SIGNAL_PENDING because the stats can arrive before the acquire
274 * fence has signaled, depending on internal timing differences. Therefore the caller should
275 * use the acquire fence passed in to setBuffer and query the signal time.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800276 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100277int64_t ASurfaceTransactionStats_getAcquireTime(
278 ASurfaceTransactionStats* _Nonnull surface_transaction_stats,
279 ASurfaceControl* _Nonnull surface_control) __INTRODUCED_IN(29);
Marissa Wall80d94ad2019-01-18 16:04:36 -0800280
281/**
282 * The returns the fence used to signal the release of the PREVIOUS buffer set on
283 * this surface. If this fence is valid (>=0), the PREVIOUS buffer has not yet been released and the
Vishnu Nair879a41a2024-09-16 17:43:59 +0000284 * fence will signal when the PREVIOUS buffer has been released. If the fence is -1, the PREVIOUS
Marissa Wall80d94ad2019-01-18 16:04:36 -0800285 * buffer is already released. The recipient of the callback takes ownership of the
286 * previousReleaseFenceFd and is responsible for closing it.
287 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100288 * Each time a buffer is set through ASurfaceTransaction_setBuffer() on a transaction
289 * which is applied, the framework takes a ref on this buffer. The framework treats the
Marissa Wall80d94ad2019-01-18 16:04:36 -0800290 * addition of a buffer to a particular surface as a unique ref. When a transaction updates or
291 * removes a buffer from a surface, or removes the surface itself from the tree, this ref is
292 * guaranteed to be released in the OnComplete callback for this transaction. The
293 * ASurfaceControlStats provided in the callback for this surface may contain an optional fence
294 * which must be signaled before the ref is assumed to be released.
295 *
296 * The client must ensure that all pending refs on a buffer are released before attempting to reuse
297 * this buffer, otherwise synchronization errors may occur.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700298 *
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700299 * This query is not valid for ASurfaceTransaction_OnCommit callback.
300 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700301 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800302 */
303int ASurfaceTransactionStats_getPreviousReleaseFenceFd(
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100304 ASurfaceTransactionStats* _Nonnull surface_transaction_stats,
305 ASurfaceControl* _Nonnull surface_control) __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700306
307/**
308 * Sets the callback that will be invoked when the updates from this transaction
309 * are presented. For details on the callback semantics and data, see the
310 * comments on the ASurfaceTransaction_OnComplete declaration above.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700311 *
312 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700313 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100314void ASurfaceTransaction_setOnComplete(ASurfaceTransaction* _Nonnull transaction,
315 void* _Null_unspecified context,
316 ASurfaceTransaction_OnComplete _Nonnull func)
317 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700318
Marissa Wall80d94ad2019-01-18 16:04:36 -0800319/**
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700320 * Sets the callback that will be invoked when the updates from this transaction are applied and are
321 * ready to be presented. This callback will be invoked before the ASurfaceTransaction_OnComplete
322 * callback.
323 *
324 * Available since API level 31.
325 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100326void ASurfaceTransaction_setOnCommit(ASurfaceTransaction* _Nonnull transaction,
327 void* _Null_unspecified context,
328 ASurfaceTransaction_OnCommit _Nonnull func)
329 __INTRODUCED_IN(31);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700330
331/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100332 * Reparents the \a surface_control from its old parent to the \a new_parent surface control.
333 * Any children of the reparented \a surface_control will remain children of the \a surface_control.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800334 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100335 * The \a new_parent can be null. Surface controls with a null parent do not appear on the display.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700336 *
337 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800338 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100339void ASurfaceTransaction_reparent(ASurfaceTransaction* _Nonnull transaction,
340 ASurfaceControl* _Nonnull surface_control,
341 ASurfaceControl* _Nullable new_parent) __INTRODUCED_IN(29);
Marissa Wall80d94ad2019-01-18 16:04:36 -0800342
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100343/**
344 * Parameter for ASurfaceTransaction_setVisibility().
345 */
Marijn Suijten896a6612024-01-19 00:50:34 +0100346enum ASurfaceTransactionVisibility : int8_t {
Marissa Wall53da7e32018-09-25 15:59:38 -0700347 ASURFACE_TRANSACTION_VISIBILITY_HIDE = 0,
348 ASURFACE_TRANSACTION_VISIBILITY_SHOW = 1,
349};
350/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100351 * Updates the visibility of \a surface_control. If show is set to
352 * ASURFACE_TRANSACTION_VISIBILITY_HIDE, the \a surface_control and all surfaces in its subtree will
Marissa Wall53da7e32018-09-25 15:59:38 -0700353 * be hidden.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700354 *
355 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700356 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100357void ASurfaceTransaction_setVisibility(ASurfaceTransaction* _Nonnull transaction,
358 ASurfaceControl* _Nonnull surface_control,
Marijn Suijten896a6612024-01-19 00:50:34 +0100359 enum ASurfaceTransactionVisibility visibility)
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100360 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700361
362/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100363 * Updates the z order index for \a surface_control. Note that the z order for a surface
Marissa Wall53da7e32018-09-25 15:59:38 -0700364 * is relative to other surfaces which are siblings of this surface. The behavior of sibilings with
365 * the same z order is undefined.
366 *
367 * Z orders may be from MIN_INT32 to MAX_INT32. A layer's default z order index is 0.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700368 *
369 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700370 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100371void ASurfaceTransaction_setZOrder(ASurfaceTransaction* _Nonnull transaction,
372 ASurfaceControl* _Nonnull surface_control, int32_t z_order)
373 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700374
375/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100376 * Updates the AHardwareBuffer displayed for \a surface_control. If not -1, the
Marissa Wall80d94ad2019-01-18 16:04:36 -0800377 * acquire_fence_fd should be a file descriptor that is signaled when all pending work
Marissa Wall53da7e32018-09-25 15:59:38 -0700378 * for the buffer is complete and the buffer can be safely read.
379 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100380 * The frameworks takes ownership of the \a acquire_fence_fd passed and is responsible
Marissa Wall53da7e32018-09-25 15:59:38 -0700381 * for closing it.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700382 *
Ady Abraham38605fc2021-03-29 20:33:42 +0000383 * Note that the buffer must be allocated with AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE
384 * as the surface control might be composited using the GPU.
385 *
Vishnu Nair879a41a2024-09-16 17:43:59 +0000386 * Starting with API level 36, prefer using \a ASurfaceTransaction_setBufferWithRelease to
387 * set a buffer and a callback which will be invoked when the buffer is ready to be reused.
388 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700389 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700390 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100391void ASurfaceTransaction_setBuffer(ASurfaceTransaction* _Nonnull transaction,
392 ASurfaceControl* _Nonnull surface_control,
393 AHardwareBuffer* _Nonnull buffer, int acquire_fence_fd)
394 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700395
396/**
Vishnu Nair879a41a2024-09-16 17:43:59 +0000397 * Updates the AHardwareBuffer displayed for \a surface_control. If not -1, the
398 * acquire_fence_fd should be a file descriptor that is signaled when all pending work
399 * for the buffer is complete and the buffer can be safely read.
400 *
401 * The frameworks takes ownership of the \a acquire_fence_fd passed and is responsible
402 * for closing it.
403 *
404 * Note that the buffer must be allocated with AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE
405 * as the surface control might be composited using the GPU.
406 *
407 * When the buffer is ready to be reused, the ASurfaceTransaction_OnBufferRelease
408 * callback will be invoked. If the buffer is null, the callback will not be invoked.
409 *
410 * Available since API level 36.
411 */
412void ASurfaceTransaction_setBufferWithRelease(ASurfaceTransaction* _Nonnull transaction,
413 ASurfaceControl* _Nonnull surface_control,
414 AHardwareBuffer* _Nonnull buffer,
415 int acquire_fence_fd, void* _Null_unspecified context,
416 ASurfaceTransaction_OnBufferRelease _Nonnull func)
417 __INTRODUCED_IN(36);
418
419/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100420 * Updates the color for \a surface_control. This will make the background color for the
421 * ASurfaceControl visible in transparent regions of the surface. Colors \a r, \a g,
422 * and \a b must be within the range that is valid for \a dataspace. \a dataspace and \a alpha
Valerie Haued54efa2019-01-11 20:03:14 -0800423 * will be the dataspace and alpha set for the background color layer.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700424 *
425 * Available since API level 29.
Valerie Haued54efa2019-01-11 20:03:14 -0800426 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100427void ASurfaceTransaction_setColor(ASurfaceTransaction* _Nonnull transaction,
428 ASurfaceControl* _Nonnull surface_control, float r, float g,
429 float b, float alpha, enum ADataSpace dataspace)
430 __INTRODUCED_IN(29);
Valerie Haued54efa2019-01-11 20:03:14 -0800431
Dan Albertf93853d2024-08-01 22:20:38 +0000432// These APIs (setGeometry and setCrop) were originally written in a
433// C-incompatible form using references instead of pointers, and the OS shipped
434// that version for years before it was noticed. Fortunately the compiled code
435// for callers is the same regardless of whether it's a pointer or a reference,
436// so we can declare this as a nonnull pointer for C and keep the existing C++
437// decl and definition.
438//
439// We could alternatively change the decl and the definition to both be a
440// pointer (with an inline definition using references to preserve source compat
441// for existing C++ callers), but that requires changing the definition of an
442// API that has been in the OS for years. It's theoretically a safe change, but
443// without being able to prove it that's a very big risk to take. By keeping the
444// C-compatibility hack in the header, we can be sure that we haven't changed
445// anything for existing callers. By definition there were no C users of the
446// reference-based decl; if there were any C callers of the API at all, they were
447// using the same workaround that is now used below.
448//
449// Even if this workaround turns out to not work for C, there's no permanent
450// damage done to the platform (unlike if we were to change the definition). At
451// worst it continues to work for C++ (since the preprocessed header as seen by
452// C++ hasn't changed, nor has the definition) and continues to not work for C.
453
Valerie Haued54efa2019-01-11 20:03:14 -0800454/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100455 * \param source The sub-rect within the buffer's content to be rendered inside the surface's area
Marissa Wall53da7e32018-09-25 15:59:38 -0700456 * The surface's source rect is clipped by the bounds of its current buffer. The source rect's width
457 * and height must be > 0.
458 *
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100459 * \param destination Specifies the rect in the parent's space where this surface will be drawn. The
460 * post source rect bounds are scaled to fit the destination rect. The surface's destination rect is
Marissa Wall53da7e32018-09-25 15:59:38 -0700461 * clipped by the bounds of its parent. The destination rect's width and height must be > 0.
462 *
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100463 * \param transform The transform applied after the source rect is applied to the buffer. This
Dan Albert61438382024-08-02 20:51:12 +0000464 * parameter should be set to 0 for no transform. To specify a transform use the
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100465 * NATIVE_WINDOW_TRANSFORM_* enum.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700466 *
467 * Available since API level 29.
chaviw1f5e7402021-04-29 09:15:20 -0500468 *
469 * @deprecated Use setCrop, setPosition, setBufferTransform, and setScale instead. Those functions
470 * provide well defined behavior and allows for more control by the apps. It also allows the caller
471 * to set different properties at different times, instead of having to specify all the desired
472 * properties at once.
Marissa Wall53da7e32018-09-25 15:59:38 -0700473 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100474void ASurfaceTransaction_setGeometry(ASurfaceTransaction* _Nonnull transaction,
Dan Albertf93853d2024-08-01 22:20:38 +0000475 ASurfaceControl* _Nonnull surface_control,
476#if defined(__cplusplus)
477 const ARect& source, const ARect& destination,
478#else
479 const ARect* _Nonnull source,
480 const ARect* _Nonnull destination,
481#endif
482 int32_t transform) __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700483
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500484/**
chaviwbe8d0092021-03-29 18:49:46 -0500485 * Bounds the surface and its children to the bounds specified. The crop and buffer size will be
486 * used to determine the bounds of the surface. If no crop is specified and the surface has no
487 * buffer, the surface bounds is only constrained by the size of its parent bounds.
488 *
489 * \param crop The bounds of the crop to apply.
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500490 *
491 * Available since API level 31.
492 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100493void ASurfaceTransaction_setCrop(ASurfaceTransaction* _Nonnull transaction,
Dan Albertf93853d2024-08-01 22:20:38 +0000494 ASurfaceControl* _Nonnull surface_control,
495#if defined(__cplusplus)
496 const ARect& crop)
497#else
498 const ARect* _Nonnull crop)
499#endif
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100500 __INTRODUCED_IN(31);
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500501
502/**
chaviwbe8d0092021-03-29 18:49:46 -0500503 * Specifies the position in the parent's space where the surface will be drawn.
504 *
505 * \param x The x position to render the surface.
506 * \param y The y position to render the surface.
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500507 *
508 * Available since API level 31.
509 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100510void ASurfaceTransaction_setPosition(ASurfaceTransaction* _Nonnull transaction,
511 ASurfaceControl* _Nonnull surface_control, int32_t x,
512 int32_t y) __INTRODUCED_IN(31);
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500513
514/**
515 * \param transform The transform applied after the source rect is applied to the buffer. This
chaviwbe8d0092021-03-29 18:49:46 -0500516 * parameter should be set to 0 for no transform. To specify a transform use the
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500517 * NATIVE_WINDOW_TRANSFORM_* enum.
518 *
519 * Available since API level 31.
520 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100521void ASurfaceTransaction_setBufferTransform(ASurfaceTransaction* _Nonnull transaction,
522 ASurfaceControl* _Nonnull surface_control,
523 int32_t transform) __INTRODUCED_IN(31);
Marissa Wall53da7e32018-09-25 15:59:38 -0700524
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100525/**
chaviwbe8d0092021-03-29 18:49:46 -0500526 * Sets an x and y scale of a surface with (0, 0) as the centerpoint of the scale.
527 *
528 * \param xScale The scale in the x direction. Must be greater than 0.
529 * \param yScale The scale in the y direction. Must be greater than 0.
530 *
531 * Available since API level 31.
532 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100533void ASurfaceTransaction_setScale(ASurfaceTransaction* _Nonnull transaction,
534 ASurfaceControl* _Nonnull surface_control, float xScale,
535 float yScale) __INTRODUCED_IN(31);
chaviwbe8d0092021-03-29 18:49:46 -0500536/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100537 * Parameter for ASurfaceTransaction_setBufferTransparency().
538 */
Marijn Suijten896a6612024-01-19 00:50:34 +0100539enum ASurfaceTransactionTransparency : int8_t {
Marissa Wall53da7e32018-09-25 15:59:38 -0700540 ASURFACE_TRANSACTION_TRANSPARENCY_TRANSPARENT = 0,
541 ASURFACE_TRANSACTION_TRANSPARENCY_TRANSLUCENT = 1,
542 ASURFACE_TRANSACTION_TRANSPARENCY_OPAQUE = 2,
543};
544/**
545 * Updates whether the content for the buffer associated with this surface is
546 * completely opaque. If true, every pixel of content inside the buffer must be
547 * opaque or visual errors can occur.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700548 *
549 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700550 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100551void ASurfaceTransaction_setBufferTransparency(ASurfaceTransaction* _Nonnull transaction,
552 ASurfaceControl* _Nonnull surface_control,
Marijn Suijten896a6612024-01-19 00:50:34 +0100553 enum ASurfaceTransactionTransparency transparency)
Marissa Wall80d94ad2019-01-18 16:04:36 -0800554 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700555
556/**
557 * Updates the region for the content on this surface updated in this
558 * transaction. If unspecified, the complete surface is assumed to be damaged.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700559 *
560 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700561 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100562void ASurfaceTransaction_setDamageRegion(ASurfaceTransaction* _Nonnull transaction,
563 ASurfaceControl* _Nonnull surface_control,
564 const ARect* _Nullable rects, uint32_t count)
565 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700566
Marissa Wall80d94ad2019-01-18 16:04:36 -0800567/**
568 * Specifies a desiredPresentTime for the transaction. The framework will try to present
569 * the transaction at or after the time specified.
570 *
571 * Transactions will not be presented until all of their acquire fences have signaled even if the
572 * app requests an earlier present time.
573 *
574 * If an earlier transaction has a desired present time of x, and a later transaction has a desired
575 * present time that is before x, the later transaction will not preempt the earlier transaction.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700576 *
577 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800578 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100579void ASurfaceTransaction_setDesiredPresentTime(ASurfaceTransaction* _Nonnull transaction,
Marissa Wall80d94ad2019-01-18 16:04:36 -0800580 int64_t desiredPresentTime) __INTRODUCED_IN(29);
581
582/**
583 * Sets the alpha for the buffer. It uses a premultiplied blending.
584 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100585 * The \a alpha must be between 0.0 and 1.0.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700586 *
587 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800588 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100589void ASurfaceTransaction_setBufferAlpha(ASurfaceTransaction* _Nonnull transaction,
590 ASurfaceControl* _Nonnull surface_control, float alpha)
Marissa Wall80d94ad2019-01-18 16:04:36 -0800591 __INTRODUCED_IN(29);
592
Marissa Wall3ff826c2019-02-07 11:58:25 -0800593/**
594 * Sets the data space of the surface_control's buffers.
595 *
596 * If no data space is set, the surface control defaults to ADATASPACE_SRGB.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700597 *
598 * Available since API level 29.
Marissa Wall3ff826c2019-02-07 11:58:25 -0800599 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100600void ASurfaceTransaction_setBufferDataSpace(ASurfaceTransaction* _Nonnull transaction,
601 ASurfaceControl* _Nonnull surface_control,
602 enum ADataSpace data_space) __INTRODUCED_IN(29);
Marissa Wall3ff826c2019-02-07 11:58:25 -0800603
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100604/**
Marissa Wall80d94ad2019-01-18 16:04:36 -0800605 * SMPTE ST 2086 "Mastering Display Color Volume" static metadata
606 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100607 * When \a metadata is set to null, the framework does not use any smpte2086 metadata when rendering
Marissa Wall80d94ad2019-01-18 16:04:36 -0800608 * the surface's buffer.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700609 *
610 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800611 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100612void ASurfaceTransaction_setHdrMetadata_smpte2086(ASurfaceTransaction* _Nonnull transaction,
613 ASurfaceControl* _Nonnull surface_control,
614 struct AHdrMetadata_smpte2086* _Nullable metadata)
Marissa Wall80d94ad2019-01-18 16:04:36 -0800615 __INTRODUCED_IN(29);
616
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100617/**
Marissa Wall80d94ad2019-01-18 16:04:36 -0800618 * Sets the CTA 861.3 "HDR Static Metadata Extension" static metadata on a surface.
619 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100620 * When \a metadata is set to null, the framework does not use any cta861.3 metadata when rendering
Marissa Wall80d94ad2019-01-18 16:04:36 -0800621 * the surface's buffer.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700622 *
623 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800624 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100625void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* _Nonnull transaction,
626 ASurfaceControl* _Nonnull surface_control,
627 struct AHdrMetadata_cta861_3* _Nullable metadata)
Marissa Wall80d94ad2019-01-18 16:04:36 -0800628 __INTRODUCED_IN(29);
629
Steven Thomas15b6f9c2020-03-26 13:44:28 -0700630/**
John Reckfeec2c62023-02-13 10:19:08 -0500631 * Sets the desired extended range brightness for the layer. This only applies for layers whose
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000632 * dataspace has RANGE_EXTENDED set on it. See: ASurfaceTransaction_setDesiredHdrHeadroom, prefer
633 * using this API for formats that encode an HDR/SDR ratio as part of generating the buffer.
Alec Mouri5a100fa2023-02-24 00:45:29 +0000634 *
John Reckfeec2c62023-02-13 10:19:08 -0500635 * @param surface_control The layer whose extended range brightness is being specified
Alec Mouric1392202024-03-06 19:10:00 +0000636 * @param currentBufferRatio The current HDR/SDR ratio of the current buffer as represented as
John Reckfeec2c62023-02-13 10:19:08 -0500637 * peakHdrBrightnessInNits / targetSdrWhitePointInNits. For example if the
638 * buffer was rendered with a target SDR whitepoint of 100nits and a max
639 * display brightness of 200nits, this should be set to 2.0f.
640 *
641 * Default value is 1.0f.
642 *
643 * Transfer functions that encode their own brightness ranges, such as
644 * HLG or PQ, should also set this to 1.0f and instead communicate
645 * extended content brightness information via metadata such as CTA861_3
646 * or SMPTE2086.
647 *
648 * Must be finite && >= 1.0f
649 *
Alec Mouric1392202024-03-06 19:10:00 +0000650 * @param desiredRatio The desired HDR/SDR ratio as represented as peakHdrBrightnessInNits /
John Reckfeec2c62023-02-13 10:19:08 -0500651 * targetSdrWhitePointInNits. This can be used to communicate the max desired
652 * brightness range. This is similar to the "max luminance" value in other
653 * HDR metadata formats, but represented as a ratio of the target SDR whitepoint
654 * to the max display brightness. The system may not be able to, or may choose
655 * not to, deliver the requested range.
656 *
John Reck1fb63cc2023-04-19 14:39:11 -0400657 * While requesting a large desired ratio will result in the most
658 * dynamic range, voluntarily reducing the requested range can help
659 * improve battery life as well as can improve quality by ensuring
660 * greater bit depth is allocated to the luminance range in use.
661 *
662 * Default value is 1.0f and indicates that extended range brightness
663 * is not being used, so the resulting SDR or HDR behavior will be
664 * determined entirely by the dataspace being used (ie, typically SDR
665 * however PQ or HLG transfer functions will still result in HDR)
John Reckfeec2c62023-02-13 10:19:08 -0500666 *
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000667 * When called after ASurfaceTransaction_setDesiredHdrHeadroom, the
668 * desiredRatio will override the desiredHeadroom provided by
669 * ASurfaceTransaction_setDesiredHdrHeadroom. Conversely, when called before
670 * ASurfaceTransaction_setDesiredHdrHeadroom, the desiredHeadroom provided by
671 *. ASurfaceTransaction_setDesiredHdrHeadroom will override the desiredRatio.
672 *
John Reckfeec2c62023-02-13 10:19:08 -0500673 * Must be finite && >= 1.0f
John Reck8a5e2f92023-03-16 14:27:48 -0400674 *
675 * Available since API level 34.
John Reckfeec2c62023-02-13 10:19:08 -0500676 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100677void ASurfaceTransaction_setExtendedRangeBrightness(ASurfaceTransaction* _Nonnull transaction,
678 ASurfaceControl* _Nonnull surface_control,
679 float currentBufferRatio, float desiredRatio)
680 __INTRODUCED_IN(__ANDROID_API_U__);
John Reckfeec2c62023-02-13 10:19:08 -0500681
682/**
Alec Mouric1392202024-03-06 19:10:00 +0000683 * Sets the desired HDR headroom for the layer. See: ASurfaceTransaction_setExtendedRangeBrightness,
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000684 * prefer using this API for formats that conform to HDR standards like HLG or HDR10, that do not
685 * communicate a HDR/SDR ratio as part of generating the buffer.
686 *
Alec Mouric1392202024-03-06 19:10:00 +0000687 * @param surface_control The layer whose desired HDR headroom is being specified
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000688 *
Alec Mouric1392202024-03-06 19:10:00 +0000689 * @param desiredHeadroom The desired HDR/SDR ratio as represented as peakHdrBrightnessInNits /
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000690 * targetSdrWhitePointInNits. This can be used to communicate the max
691 * desired brightness range of the panel. The system may not be able to, or
692 * may choose not to, deliver the requested range.
693 *
694 * While requesting a large desired ratio will result in the most
695 * dynamic range, voluntarily reducing the requested range can help
696 * improve battery life as well as can improve quality by ensuring
697 * greater bit depth is allocated to the luminance range in use.
698 *
699 * Default value is 0.0f and indicates that the system will choose the best
700 * headroom for this surface control's content. Typically, this means that
701 * HLG/PQ encoded content will be displayed with some HDR headroom greater
702 * than 1.0.
703 *
704 * When called after ASurfaceTransaction_setExtendedRangeBrightness, the
705 * desiredHeadroom will override the desiredRatio provided by
706 * ASurfaceTransaction_setExtendedRangeBrightness. Conversely, when called
707 * before ASurfaceTransaction_setExtendedRangeBrightness, the desiredRatio
708 * provided by ASurfaceTransaction_setExtendedRangeBrightness will override
709 * the desiredHeadroom.
710 *
711 * Must be finite && >= 1.0f or 0.0f to indicate there is no desired
712 * headroom.
713 *
714 * Available since API level 35.
715 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100716void ASurfaceTransaction_setDesiredHdrHeadroom(ASurfaceTransaction* _Nonnull transaction,
717 ASurfaceControl* _Nonnull surface_control,
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000718 float desiredHeadroom)
719 __INTRODUCED_IN(__ANDROID_API_V__);
720
721/**
Marin Shalamanovc5986772021-03-16 16:09:49 +0100722 * Same as ASurfaceTransaction_setFrameRateWithChangeStrategy(transaction, surface_control,
723 * frameRate, compatibility, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS).
Steven Thomas6d88a482019-12-02 22:00:47 -0800724 *
Marin Shalamanovc5986772021-03-16 16:09:49 +0100725 * See ASurfaceTransaction_setFrameRateWithChangeStrategy().
Steven Thomas62a4cf82020-01-31 12:04:03 -0800726 *
Steven Thomas6d88a482019-12-02 22:00:47 -0800727 * Available since API level 30.
728 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100729void ASurfaceTransaction_setFrameRate(ASurfaceTransaction* _Nonnull transaction,
730 ASurfaceControl* _Nonnull surface_control, float frameRate,
Steven Thomas62a4cf82020-01-31 12:04:03 -0800731 int8_t compatibility) __INTRODUCED_IN(30);
Steven Thomas6d88a482019-12-02 22:00:47 -0800732
Marin Shalamanov46084422020-10-13 12:33:42 +0200733/**
734 * Sets the intended frame rate for \a surface_control.
735 *
736 * On devices that are capable of running the display at different refresh rates, the system may
737 * choose a display refresh rate to better match this surface's frame rate. Usage of this API won't
738 * directly affect the application's frame production pipeline. However, because the system may
739 * change the display refresh rate, calls to this function may result in changes to Choreographer
740 * callback timings, and changes to the time interval at which the system releases buffers back to
741 * the application.
742 *
Marin Shalamanova308b9d2021-05-05 13:43:28 +0200743 * You can register for changes in the refresh rate using
744 * \a AChoreographer_registerRefreshRateCallback.
745 *
Kriti Dang4113fc12022-08-26 16:30:37 +0200746 * See ASurfaceTransaction_clearFrameRate().
747 *
Marin Shalamanov46084422020-10-13 12:33:42 +0200748 * \param frameRate is the intended frame rate of this surface, in frames per second. 0 is a special
749 * value that indicates the app will accept the system's choice for the display frame rate, which is
750 * the default behavior if this function isn't called. The frameRate param does <em>not</em> need to
751 * be a valid refresh rate for this device's display - e.g., it's fine to pass 30fps to a device
752 * that can only run the display at 60fps.
753 *
754 * \param compatibility The frame rate compatibility of this surface. The compatibility value may
755 * influence the system's choice of display frame rate. To specify a compatibility use the
Marin Shalamanov293ac2c2021-04-26 14:13:04 +0200756 * ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_* enum. This parameter is ignored when frameRate is 0.
Marin Shalamanov46084422020-10-13 12:33:42 +0200757 *
Marin Shalamanov293ac2c2021-04-26 14:13:04 +0200758 * \param changeFrameRateStrategy Whether display refresh rate transitions caused by this
759 * surface should be seamless. A seamless transition is one that doesn't have any visual
760 * interruptions, such as a black screen for a second or two. See the
761 * ANATIVEWINDOW_CHANGE_FRAME_RATE_* values. This parameter is ignored when frameRate is 0.
Marin Shalamanov46084422020-10-13 12:33:42 +0200762 *
763 * Available since API level 31.
764 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100765void ASurfaceTransaction_setFrameRateWithChangeStrategy(ASurfaceTransaction* _Nonnull transaction,
766 ASurfaceControl* _Nonnull surface_control,
767 float frameRate, int8_t compatibility,
768 int8_t changeFrameRateStrategy)
769 __INTRODUCED_IN(31);
Marin Shalamanov46084422020-10-13 12:33:42 +0200770
Robert Carrf08168d2021-03-24 15:49:18 -0700771/**
Kriti Dang4113fc12022-08-26 16:30:37 +0200772 * Clears the frame rate which is set for \a surface_control.
773 *
774 * This is equivalent to calling
775 * ASurfaceTransaction_setFrameRateWithChangeStrategy(
776 * transaction, 0, compatibility, changeFrameRateStrategy).
777 *
778 * Usage of this API won't directly affect the application's frame production pipeline. However,
779 * because the system may change the display refresh rate, calls to this function may result in
780 * changes to Choreographer callback timings, and changes to the time interval at which the system
781 * releases buffers back to the application.
782 *
783 * See ASurfaceTransaction_setFrameRateWithChangeStrategy()
784 *
785 * You can register for changes in the refresh rate using
786 * \a AChoreographer_registerRefreshRateCallback.
787 *
788 * See ASurfaceTransaction_setFrameRateWithChangeStrategy().
789 *
790 * Available since API level 34.
791 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100792void ASurfaceTransaction_clearFrameRate(ASurfaceTransaction* _Nonnull transaction,
793 ASurfaceControl* _Nonnull surface_control)
Kriti Dang4113fc12022-08-26 16:30:37 +0200794 __INTRODUCED_IN(__ANDROID_API_U__);
795
796/**
Robert Carrf08168d2021-03-24 15:49:18 -0700797 * Indicate whether to enable backpressure for buffer submission to a given SurfaceControl.
798 *
799 * By default backpressure is disabled, which means submitting a buffer prior to receiving
800 * a callback for the previous buffer could lead to that buffer being "dropped". In cases
801 * where you are selecting for latency, this may be a desirable behavior! We had a new buffer
802 * ready, why shouldn't we show it?
803 *
804 * When back pressure is enabled, each buffer will be required to be presented
805 * before it is released and the callback delivered
806 * (absent the whole SurfaceControl being removed).
807 *
808 * Most apps are likely to have some sort of backpressure internally, e.g. you are
809 * waiting on the callback from frame N-2 before starting frame N. In high refresh
810 * rate scenarios there may not be much time between SurfaceFlinger completing frame
811 * N-1 (and therefore releasing buffer N-2) and beginning frame N. This means
812 * your app may not have enough time to respond in the callback. Using this flag
813 * and pushing buffers earlier for server side queuing will be advantageous
814 * in such cases.
815 *
Alec Mouri5a100fa2023-02-24 00:45:29 +0000816 * Available since API level 31.
817 *
Robert Carrf08168d2021-03-24 15:49:18 -0700818 * \param transaction The transaction in which to make the change.
819 * \param surface_control The ASurfaceControl on which to control buffer backpressure behavior.
820 * \param enableBackPressure Whether to enable back pressure.
821 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100822void ASurfaceTransaction_setEnableBackPressure(ASurfaceTransaction* _Nonnull transaction,
823 ASurfaceControl* _Nonnull surface_control,
824 bool enableBackPressure) __INTRODUCED_IN(31);
Robert Carrf08168d2021-03-24 15:49:18 -0700825
Rachel Leeed511ef2021-10-11 15:09:51 -0700826/**
Rachel Leee81bf262022-08-23 14:37:59 -0700827 * Sets the frame timeline to use in SurfaceFlinger.
Rachel Lee1fb2ddc2022-01-12 14:33:07 -0800828 *
Rachel Leee81bf262022-08-23 14:37:59 -0700829 * A frame timeline should be chosen based on the frame deadline the application
830 * can meet when rendering the frame and the application's desired presentation time.
831 * By setting a frame timeline, SurfaceFlinger tries to present the frame at the corresponding
832 * expected presentation time.
Rachel Lee1fb2ddc2022-01-12 14:33:07 -0800833 *
834 * To receive frame timelines, a callback must be posted to Choreographer using
Rachel Leee81bf262022-08-23 14:37:59 -0700835 * AChoreographer_postVsyncCallback(). The \c vsyncId can then be extracted from the
Rachel Lee1fb2ddc2022-01-12 14:33:07 -0800836 * callback payload using AChoreographerFrameCallbackData_getFrameTimelineVsyncId().
Rachel Leeed511ef2021-10-11 15:09:51 -0700837 *
Alec Mouri5a100fa2023-02-24 00:45:29 +0000838 * Available since API level 33.
839 *
Rachel Leee81bf262022-08-23 14:37:59 -0700840 * \param vsyncId The vsync ID received from AChoreographer, setting the frame's presentation target
841 * to the corresponding expected presentation time and deadline from the frame to be rendered. A
842 * stale or invalid value will be ignored.
Rachel Leeed511ef2021-10-11 15:09:51 -0700843 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100844void ASurfaceTransaction_setFrameTimeline(ASurfaceTransaction* _Nonnull transaction,
Rachel Lee1fb2ddc2022-01-12 14:33:07 -0800845 AVsyncId vsyncId) __INTRODUCED_IN(33);
Rachel Leeed511ef2021-10-11 15:09:51 -0700846
Marissa Wall53da7e32018-09-25 15:59:38 -0700847__END_DECLS
848
849#endif // ANDROID_SURFACE_CONTROL_H
Marin Shalamanov574c58d2021-03-18 15:10:02 +0100850
851/** @} */