blob: 4dc947865147d9b71dd05a9fb8fee42b0e5bd117 [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 Suijtenb54710f2024-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 Suijtenb54710f2024-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 Suijtenb54710f2024-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 Suijtenb54710f2024-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 Suijtenb54710f2024-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 Suijtenb54710f2024-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 Suijtenb54710f2024-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 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100148 * \param context Optional context provided by the client that is passed into
Marissa Wall53da7e32018-09-25 15:59:38 -0700149 * the callback.
Marissa Wall53da7e32018-09-25 15:59:38 -0700150 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100151 * \param stats Opaque handle that can be passed to ASurfaceTransactionStats functions to query
Elliott Hughes733bf992019-03-08 11:25:28 -0800152 * information about the transaction. The handle is only valid during the callback.
Marissa Wall53da7e32018-09-25 15:59:38 -0700153 *
154 * THREADING
155 * The transaction completed callback can be invoked on any thread.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700156 *
157 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700158 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100159typedef void (*ASurfaceTransaction_OnComplete)(void* _Null_unspecified context,
160 ASurfaceTransactionStats* _Nonnull stats)
161 __INTRODUCED_IN(29);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700162
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 Carr11085792021-05-12 14:35:35 -0700168 * 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 Nairfc46c1e2021-04-21 08:31:32 -0700175 * \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.
185 *
186 * Available since API level 31.
187 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100188typedef void (*ASurfaceTransaction_OnCommit)(void* _Null_unspecified context,
189 ASurfaceTransactionStats* _Nonnull stats)
190 __INTRODUCED_IN(31);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700191
Marissa Wall80d94ad2019-01-18 16:04:36 -0800192/**
193 * Returns the timestamp of when the frame was latched by the framework. Once a frame is
194 * latched by the framework, it is presented at the following hardware vsync.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700195 *
196 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800197 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100198int64_t ASurfaceTransactionStats_getLatchTime(
199 ASurfaceTransactionStats* _Nonnull surface_transaction_stats) __INTRODUCED_IN(29);
Marissa Wall80d94ad2019-01-18 16:04:36 -0800200
201/**
202 * Returns a sync fence that signals when the transaction has been presented.
203 * The recipient of the callback takes ownership of the fence and is responsible for closing
Marissa Wall183c44c2019-04-08 12:58:50 -0700204 * it. If a device does not support present fences, a -1 will be returned.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700205 *
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700206 * This query is not valid for ASurfaceTransaction_OnCommit callback.
207 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700208 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800209 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100210int ASurfaceTransactionStats_getPresentFenceFd(
211 ASurfaceTransactionStats* _Nonnull surface_transaction_stats) __INTRODUCED_IN(29);
Marissa Wall80d94ad2019-01-18 16:04:36 -0800212
213/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100214 * \a outASurfaceControls returns an array of ASurfaceControl pointers that were updated during the
Marissa Wall80d94ad2019-01-18 16:04:36 -0800215 * transaction. Stats for the surfaces can be queried through ASurfaceTransactionStats functions.
216 * When the client is done using the array, it must release it by calling
217 * ASurfaceTransactionStats_releaseASurfaceControls.
218 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700219 * Available since API level 29.
220 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100221 * \a outASurfaceControlsSize returns the size of the ASurfaceControls array.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800222 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100223void ASurfaceTransactionStats_getASurfaceControls(
224 ASurfaceTransactionStats* _Nonnull surface_transaction_stats,
225 ASurfaceControl* _Nullable* _Nullable* _Nonnull outASurfaceControls,
226 size_t* _Nonnull outASurfaceControlsSize) __INTRODUCED_IN(29);
Marissa Wall80d94ad2019-01-18 16:04:36 -0800227/**
228 * Releases the array of ASurfaceControls that were returned by
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100229 * ASurfaceTransactionStats_getASurfaceControls().
Elliott Hughes3d70e532019-10-29 08:59:39 -0700230 *
231 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800232 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100233void ASurfaceTransactionStats_releaseASurfaceControls(
234 ASurfaceControl* _Nonnull* _Nonnull surface_controls) __INTRODUCED_IN(29);
Marissa Wall80d94ad2019-01-18 16:04:36 -0800235
236/**
237 * Returns the timestamp of when the CURRENT buffer was acquired. A buffer is considered
238 * acquired when its acquire_fence_fd has signaled. A buffer cannot be latched or presented until
239 * it is acquired. If no acquire_fence_fd was provided, this timestamp will be set to -1.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700240 *
241 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800242 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100243int64_t ASurfaceTransactionStats_getAcquireTime(
244 ASurfaceTransactionStats* _Nonnull surface_transaction_stats,
245 ASurfaceControl* _Nonnull surface_control) __INTRODUCED_IN(29);
Marissa Wall80d94ad2019-01-18 16:04:36 -0800246
247/**
248 * The returns the fence used to signal the release of the PREVIOUS buffer set on
249 * this surface. If this fence is valid (>=0), the PREVIOUS buffer has not yet been released and the
250 * fence will signal when the PREVIOUS buffer has been released. If the fence is -1 , the PREVIOUS
251 * buffer is already released. The recipient of the callback takes ownership of the
252 * previousReleaseFenceFd and is responsible for closing it.
253 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100254 * Each time a buffer is set through ASurfaceTransaction_setBuffer() on a transaction
255 * which is applied, the framework takes a ref on this buffer. The framework treats the
Marissa Wall80d94ad2019-01-18 16:04:36 -0800256 * addition of a buffer to a particular surface as a unique ref. When a transaction updates or
257 * removes a buffer from a surface, or removes the surface itself from the tree, this ref is
258 * guaranteed to be released in the OnComplete callback for this transaction. The
259 * ASurfaceControlStats provided in the callback for this surface may contain an optional fence
260 * which must be signaled before the ref is assumed to be released.
261 *
262 * The client must ensure that all pending refs on a buffer are released before attempting to reuse
263 * this buffer, otherwise synchronization errors may occur.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700264 *
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700265 * This query is not valid for ASurfaceTransaction_OnCommit callback.
266 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700267 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800268 */
269int ASurfaceTransactionStats_getPreviousReleaseFenceFd(
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100270 ASurfaceTransactionStats* _Nonnull surface_transaction_stats,
271 ASurfaceControl* _Nonnull surface_control) __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700272
273/**
274 * Sets the callback that will be invoked when the updates from this transaction
275 * are presented. For details on the callback semantics and data, see the
276 * comments on the ASurfaceTransaction_OnComplete declaration above.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700277 *
278 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700279 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100280void ASurfaceTransaction_setOnComplete(ASurfaceTransaction* _Nonnull transaction,
281 void* _Null_unspecified context,
282 ASurfaceTransaction_OnComplete _Nonnull func)
283 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700284
Marissa Wall80d94ad2019-01-18 16:04:36 -0800285/**
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700286 * Sets the callback that will be invoked when the updates from this transaction are applied and are
287 * ready to be presented. This callback will be invoked before the ASurfaceTransaction_OnComplete
288 * callback.
289 *
290 * Available since API level 31.
291 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100292void ASurfaceTransaction_setOnCommit(ASurfaceTransaction* _Nonnull transaction,
293 void* _Null_unspecified context,
294 ASurfaceTransaction_OnCommit _Nonnull func)
295 __INTRODUCED_IN(31);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700296
297/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100298 * Reparents the \a surface_control from its old parent to the \a new_parent surface control.
299 * Any children of the reparented \a surface_control will remain children of the \a surface_control.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800300 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100301 * 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 -0700302 *
303 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800304 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100305void ASurfaceTransaction_reparent(ASurfaceTransaction* _Nonnull transaction,
306 ASurfaceControl* _Nonnull surface_control,
307 ASurfaceControl* _Nullable new_parent) __INTRODUCED_IN(29);
Marissa Wall80d94ad2019-01-18 16:04:36 -0800308
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100309/**
310 * Parameter for ASurfaceTransaction_setVisibility().
311 */
Marijn Suijten896a6612024-01-19 00:50:34 +0100312enum ASurfaceTransactionVisibility : int8_t {
Marissa Wall53da7e32018-09-25 15:59:38 -0700313 ASURFACE_TRANSACTION_VISIBILITY_HIDE = 0,
314 ASURFACE_TRANSACTION_VISIBILITY_SHOW = 1,
315};
316/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100317 * Updates the visibility of \a surface_control. If show is set to
318 * ASURFACE_TRANSACTION_VISIBILITY_HIDE, the \a surface_control and all surfaces in its subtree will
Marissa Wall53da7e32018-09-25 15:59:38 -0700319 * be hidden.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700320 *
321 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700322 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100323void ASurfaceTransaction_setVisibility(ASurfaceTransaction* _Nonnull transaction,
324 ASurfaceControl* _Nonnull surface_control,
Marijn Suijten896a6612024-01-19 00:50:34 +0100325 enum ASurfaceTransactionVisibility visibility)
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100326 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700327
328/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100329 * Updates the z order index for \a surface_control. Note that the z order for a surface
Marissa Wall53da7e32018-09-25 15:59:38 -0700330 * is relative to other surfaces which are siblings of this surface. The behavior of sibilings with
331 * the same z order is undefined.
332 *
333 * 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 -0700334 *
335 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700336 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100337void ASurfaceTransaction_setZOrder(ASurfaceTransaction* _Nonnull transaction,
338 ASurfaceControl* _Nonnull surface_control, int32_t z_order)
339 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700340
341/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100342 * Updates the AHardwareBuffer displayed for \a surface_control. If not -1, the
Marissa Wall80d94ad2019-01-18 16:04:36 -0800343 * acquire_fence_fd should be a file descriptor that is signaled when all pending work
Marissa Wall53da7e32018-09-25 15:59:38 -0700344 * for the buffer is complete and the buffer can be safely read.
345 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100346 * The frameworks takes ownership of the \a acquire_fence_fd passed and is responsible
Marissa Wall53da7e32018-09-25 15:59:38 -0700347 * for closing it.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700348 *
Ady Abraham38605fc2021-03-29 20:33:42 +0000349 * Note that the buffer must be allocated with AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE
350 * as the surface control might be composited using the GPU.
351 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700352 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700353 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100354void ASurfaceTransaction_setBuffer(ASurfaceTransaction* _Nonnull transaction,
355 ASurfaceControl* _Nonnull surface_control,
356 AHardwareBuffer* _Nonnull buffer, int acquire_fence_fd)
357 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700358
359/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100360 * Updates the color for \a surface_control. This will make the background color for the
361 * ASurfaceControl visible in transparent regions of the surface. Colors \a r, \a g,
362 * 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 -0800363 * will be the dataspace and alpha set for the background color layer.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700364 *
365 * Available since API level 29.
Valerie Haued54efa2019-01-11 20:03:14 -0800366 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100367void ASurfaceTransaction_setColor(ASurfaceTransaction* _Nonnull transaction,
368 ASurfaceControl* _Nonnull surface_control, float r, float g,
369 float b, float alpha, enum ADataSpace dataspace)
370 __INTRODUCED_IN(29);
Valerie Haued54efa2019-01-11 20:03:14 -0800371
Dan Albertf93853d2024-08-01 22:20:38 +0000372// These APIs (setGeometry and setCrop) were originally written in a
373// C-incompatible form using references instead of pointers, and the OS shipped
374// that version for years before it was noticed. Fortunately the compiled code
375// for callers is the same regardless of whether it's a pointer or a reference,
376// so we can declare this as a nonnull pointer for C and keep the existing C++
377// decl and definition.
378//
379// We could alternatively change the decl and the definition to both be a
380// pointer (with an inline definition using references to preserve source compat
381// for existing C++ callers), but that requires changing the definition of an
382// API that has been in the OS for years. It's theoretically a safe change, but
383// without being able to prove it that's a very big risk to take. By keeping the
384// C-compatibility hack in the header, we can be sure that we haven't changed
385// anything for existing callers. By definition there were no C users of the
386// reference-based decl; if there were any C callers of the API at all, they were
387// using the same workaround that is now used below.
388//
389// Even if this workaround turns out to not work for C, there's no permanent
390// damage done to the platform (unlike if we were to change the definition). At
391// worst it continues to work for C++ (since the preprocessed header as seen by
392// C++ hasn't changed, nor has the definition) and continues to not work for C.
393
Valerie Haued54efa2019-01-11 20:03:14 -0800394/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100395 * \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 -0700396 * The surface's source rect is clipped by the bounds of its current buffer. The source rect's width
397 * and height must be > 0.
398 *
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100399 * \param destination Specifies the rect in the parent's space where this surface will be drawn. The
400 * post source rect bounds are scaled to fit the destination rect. The surface's destination rect is
Marissa Wall53da7e32018-09-25 15:59:38 -0700401 * clipped by the bounds of its parent. The destination rect's width and height must be > 0.
402 *
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100403 * \param transform The transform applied after the source rect is applied to the buffer. This
404 * parameter should be set to 0 for no transform. To specify a transfrom use the
405 * NATIVE_WINDOW_TRANSFORM_* enum.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700406 *
407 * Available since API level 29.
chaviw1f5e7402021-04-29 09:15:20 -0500408 *
409 * @deprecated Use setCrop, setPosition, setBufferTransform, and setScale instead. Those functions
410 * provide well defined behavior and allows for more control by the apps. It also allows the caller
411 * to set different properties at different times, instead of having to specify all the desired
412 * properties at once.
Marissa Wall53da7e32018-09-25 15:59:38 -0700413 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100414void ASurfaceTransaction_setGeometry(ASurfaceTransaction* _Nonnull transaction,
Dan Albertf93853d2024-08-01 22:20:38 +0000415 ASurfaceControl* _Nonnull surface_control,
416#if defined(__cplusplus)
417 const ARect& source, const ARect& destination,
418#else
419 const ARect* _Nonnull source,
420 const ARect* _Nonnull destination,
421#endif
422 int32_t transform) __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700423
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500424/**
chaviwbe8d0092021-03-29 18:49:46 -0500425 * Bounds the surface and its children to the bounds specified. The crop and buffer size will be
426 * used to determine the bounds of the surface. If no crop is specified and the surface has no
427 * buffer, the surface bounds is only constrained by the size of its parent bounds.
428 *
429 * \param crop The bounds of the crop to apply.
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500430 *
431 * Available since API level 31.
432 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100433void ASurfaceTransaction_setCrop(ASurfaceTransaction* _Nonnull transaction,
Dan Albertf93853d2024-08-01 22:20:38 +0000434 ASurfaceControl* _Nonnull surface_control,
435#if defined(__cplusplus)
436 const ARect& crop)
437#else
438 const ARect* _Nonnull crop)
439#endif
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100440 __INTRODUCED_IN(31);
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500441
442/**
chaviwbe8d0092021-03-29 18:49:46 -0500443 * Specifies the position in the parent's space where the surface will be drawn.
444 *
445 * \param x The x position to render the surface.
446 * \param y The y position to render the surface.
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500447 *
448 * Available since API level 31.
449 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100450void ASurfaceTransaction_setPosition(ASurfaceTransaction* _Nonnull transaction,
451 ASurfaceControl* _Nonnull surface_control, int32_t x,
452 int32_t y) __INTRODUCED_IN(31);
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500453
454/**
455 * \param transform The transform applied after the source rect is applied to the buffer. This
chaviwbe8d0092021-03-29 18:49:46 -0500456 * parameter should be set to 0 for no transform. To specify a transform use the
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500457 * NATIVE_WINDOW_TRANSFORM_* enum.
458 *
459 * Available since API level 31.
460 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100461void ASurfaceTransaction_setBufferTransform(ASurfaceTransaction* _Nonnull transaction,
462 ASurfaceControl* _Nonnull surface_control,
463 int32_t transform) __INTRODUCED_IN(31);
Marissa Wall53da7e32018-09-25 15:59:38 -0700464
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100465/**
chaviwbe8d0092021-03-29 18:49:46 -0500466 * Sets an x and y scale of a surface with (0, 0) as the centerpoint of the scale.
467 *
468 * \param xScale The scale in the x direction. Must be greater than 0.
469 * \param yScale The scale in the y direction. Must be greater than 0.
470 *
471 * Available since API level 31.
472 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100473void ASurfaceTransaction_setScale(ASurfaceTransaction* _Nonnull transaction,
474 ASurfaceControl* _Nonnull surface_control, float xScale,
475 float yScale) __INTRODUCED_IN(31);
chaviwbe8d0092021-03-29 18:49:46 -0500476/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100477 * Parameter for ASurfaceTransaction_setBufferTransparency().
478 */
Marijn Suijten896a6612024-01-19 00:50:34 +0100479enum ASurfaceTransactionTransparency : int8_t {
Marissa Wall53da7e32018-09-25 15:59:38 -0700480 ASURFACE_TRANSACTION_TRANSPARENCY_TRANSPARENT = 0,
481 ASURFACE_TRANSACTION_TRANSPARENCY_TRANSLUCENT = 1,
482 ASURFACE_TRANSACTION_TRANSPARENCY_OPAQUE = 2,
483};
484/**
485 * Updates whether the content for the buffer associated with this surface is
486 * completely opaque. If true, every pixel of content inside the buffer must be
487 * opaque or visual errors can occur.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700488 *
489 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700490 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100491void ASurfaceTransaction_setBufferTransparency(ASurfaceTransaction* _Nonnull transaction,
492 ASurfaceControl* _Nonnull surface_control,
Marijn Suijten896a6612024-01-19 00:50:34 +0100493 enum ASurfaceTransactionTransparency transparency)
Marissa Wall80d94ad2019-01-18 16:04:36 -0800494 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700495
496/**
497 * Updates the region for the content on this surface updated in this
498 * transaction. If unspecified, the complete surface is assumed to be damaged.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700499 *
500 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700501 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100502void ASurfaceTransaction_setDamageRegion(ASurfaceTransaction* _Nonnull transaction,
503 ASurfaceControl* _Nonnull surface_control,
504 const ARect* _Nullable rects, uint32_t count)
505 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700506
Marissa Wall80d94ad2019-01-18 16:04:36 -0800507/**
508 * Specifies a desiredPresentTime for the transaction. The framework will try to present
509 * the transaction at or after the time specified.
510 *
511 * Transactions will not be presented until all of their acquire fences have signaled even if the
512 * app requests an earlier present time.
513 *
514 * If an earlier transaction has a desired present time of x, and a later transaction has a desired
515 * present time that is before x, the later transaction will not preempt the earlier transaction.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700516 *
517 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800518 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100519void ASurfaceTransaction_setDesiredPresentTime(ASurfaceTransaction* _Nonnull transaction,
Marissa Wall80d94ad2019-01-18 16:04:36 -0800520 int64_t desiredPresentTime) __INTRODUCED_IN(29);
521
522/**
523 * Sets the alpha for the buffer. It uses a premultiplied blending.
524 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100525 * The \a alpha must be between 0.0 and 1.0.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700526 *
527 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800528 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100529void ASurfaceTransaction_setBufferAlpha(ASurfaceTransaction* _Nonnull transaction,
530 ASurfaceControl* _Nonnull surface_control, float alpha)
Marissa Wall80d94ad2019-01-18 16:04:36 -0800531 __INTRODUCED_IN(29);
532
Marissa Wall3ff826c2019-02-07 11:58:25 -0800533/**
534 * Sets the data space of the surface_control's buffers.
535 *
536 * If no data space is set, the surface control defaults to ADATASPACE_SRGB.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700537 *
538 * Available since API level 29.
Marissa Wall3ff826c2019-02-07 11:58:25 -0800539 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100540void ASurfaceTransaction_setBufferDataSpace(ASurfaceTransaction* _Nonnull transaction,
541 ASurfaceControl* _Nonnull surface_control,
542 enum ADataSpace data_space) __INTRODUCED_IN(29);
Marissa Wall3ff826c2019-02-07 11:58:25 -0800543
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100544/**
Marissa Wall80d94ad2019-01-18 16:04:36 -0800545 * SMPTE ST 2086 "Mastering Display Color Volume" static metadata
546 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100547 * When \a metadata is set to null, the framework does not use any smpte2086 metadata when rendering
Marissa Wall80d94ad2019-01-18 16:04:36 -0800548 * the surface's buffer.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700549 *
550 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800551 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100552void ASurfaceTransaction_setHdrMetadata_smpte2086(ASurfaceTransaction* _Nonnull transaction,
553 ASurfaceControl* _Nonnull surface_control,
554 struct AHdrMetadata_smpte2086* _Nullable metadata)
Marissa Wall80d94ad2019-01-18 16:04:36 -0800555 __INTRODUCED_IN(29);
556
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100557/**
Marissa Wall80d94ad2019-01-18 16:04:36 -0800558 * Sets the CTA 861.3 "HDR Static Metadata Extension" static metadata on a surface.
559 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100560 * 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 -0800561 * the surface's buffer.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700562 *
563 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800564 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100565void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* _Nonnull transaction,
566 ASurfaceControl* _Nonnull surface_control,
567 struct AHdrMetadata_cta861_3* _Nullable metadata)
Marissa Wall80d94ad2019-01-18 16:04:36 -0800568 __INTRODUCED_IN(29);
569
Steven Thomas15b6f9c2020-03-26 13:44:28 -0700570/**
John Reckfeec2c62023-02-13 10:19:08 -0500571 * Sets the desired extended range brightness for the layer. This only applies for layers whose
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000572 * dataspace has RANGE_EXTENDED set on it. See: ASurfaceTransaction_setDesiredHdrHeadroom, prefer
573 * using this API for formats that encode an HDR/SDR ratio as part of generating the buffer.
Alec Mouri5a100fa2023-02-24 00:45:29 +0000574 *
John Reckfeec2c62023-02-13 10:19:08 -0500575 * @param surface_control The layer whose extended range brightness is being specified
576 * @param currentBufferRatio The current hdr/sdr ratio of the current buffer as represented as
577 * peakHdrBrightnessInNits / targetSdrWhitePointInNits. For example if the
578 * buffer was rendered with a target SDR whitepoint of 100nits and a max
579 * display brightness of 200nits, this should be set to 2.0f.
580 *
581 * Default value is 1.0f.
582 *
583 * Transfer functions that encode their own brightness ranges, such as
584 * HLG or PQ, should also set this to 1.0f and instead communicate
585 * extended content brightness information via metadata such as CTA861_3
586 * or SMPTE2086.
587 *
588 * Must be finite && >= 1.0f
589 *
590 * @param desiredRatio The desired hdr/sdr ratio as represented as peakHdrBrightnessInNits /
591 * targetSdrWhitePointInNits. This can be used to communicate the max desired
592 * brightness range. This is similar to the "max luminance" value in other
593 * HDR metadata formats, but represented as a ratio of the target SDR whitepoint
594 * to the max display brightness. The system may not be able to, or may choose
595 * not to, deliver the requested range.
596 *
John Reck1fb63cc2023-04-19 14:39:11 -0400597 * While requesting a large desired ratio will result in the most
598 * dynamic range, voluntarily reducing the requested range can help
599 * improve battery life as well as can improve quality by ensuring
600 * greater bit depth is allocated to the luminance range in use.
601 *
602 * Default value is 1.0f and indicates that extended range brightness
603 * is not being used, so the resulting SDR or HDR behavior will be
604 * determined entirely by the dataspace being used (ie, typically SDR
605 * however PQ or HLG transfer functions will still result in HDR)
John Reckfeec2c62023-02-13 10:19:08 -0500606 *
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000607 * When called after ASurfaceTransaction_setDesiredHdrHeadroom, the
608 * desiredRatio will override the desiredHeadroom provided by
609 * ASurfaceTransaction_setDesiredHdrHeadroom. Conversely, when called before
610 * ASurfaceTransaction_setDesiredHdrHeadroom, the desiredHeadroom provided by
611 *. ASurfaceTransaction_setDesiredHdrHeadroom will override the desiredRatio.
612 *
John Reckfeec2c62023-02-13 10:19:08 -0500613 * Must be finite && >= 1.0f
John Reck8a5e2f92023-03-16 14:27:48 -0400614 *
615 * Available since API level 34.
John Reckfeec2c62023-02-13 10:19:08 -0500616 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100617void ASurfaceTransaction_setExtendedRangeBrightness(ASurfaceTransaction* _Nonnull transaction,
618 ASurfaceControl* _Nonnull surface_control,
619 float currentBufferRatio, float desiredRatio)
620 __INTRODUCED_IN(__ANDROID_API_U__);
John Reckfeec2c62023-02-13 10:19:08 -0500621
622/**
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000623 * Sets the desired hdr headroom for the layer. See: ASurfaceTransaction_setExtendedRangeBrightness,
624 * prefer using this API for formats that conform to HDR standards like HLG or HDR10, that do not
625 * communicate a HDR/SDR ratio as part of generating the buffer.
626 *
627 * @param surface_control The layer whose desired hdr headroom is being specified
628 *
629 * @param desiredHeadroom The desired hdr/sdr ratio as represented as peakHdrBrightnessInNits /
630 * targetSdrWhitePointInNits. This can be used to communicate the max
631 * desired brightness range of the panel. The system may not be able to, or
632 * may choose not to, deliver the requested range.
633 *
634 * While requesting a large desired ratio will result in the most
635 * dynamic range, voluntarily reducing the requested range can help
636 * improve battery life as well as can improve quality by ensuring
637 * greater bit depth is allocated to the luminance range in use.
638 *
639 * Default value is 0.0f and indicates that the system will choose the best
640 * headroom for this surface control's content. Typically, this means that
641 * HLG/PQ encoded content will be displayed with some HDR headroom greater
642 * than 1.0.
643 *
644 * When called after ASurfaceTransaction_setExtendedRangeBrightness, the
645 * desiredHeadroom will override the desiredRatio provided by
646 * ASurfaceTransaction_setExtendedRangeBrightness. Conversely, when called
647 * before ASurfaceTransaction_setExtendedRangeBrightness, the desiredRatio
648 * provided by ASurfaceTransaction_setExtendedRangeBrightness will override
649 * the desiredHeadroom.
650 *
651 * Must be finite && >= 1.0f or 0.0f to indicate there is no desired
652 * headroom.
653 *
654 * Available since API level 35.
655 */
Xin Li59687812024-05-24 08:27:45 -0700656void ASurfaceTransaction_setDesiredHdrHeadroom(ASurfaceTransaction* _Nonnull transaction,
657 ASurfaceControl* _Nonnull surface_control,
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000658 float desiredHeadroom)
659 __INTRODUCED_IN(__ANDROID_API_V__);
660
661/**
Marin Shalamanovc5986772021-03-16 16:09:49 +0100662 * Same as ASurfaceTransaction_setFrameRateWithChangeStrategy(transaction, surface_control,
663 * frameRate, compatibility, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS).
Steven Thomas6d88a482019-12-02 22:00:47 -0800664 *
Marin Shalamanovc5986772021-03-16 16:09:49 +0100665 * See ASurfaceTransaction_setFrameRateWithChangeStrategy().
Steven Thomas62a4cf82020-01-31 12:04:03 -0800666 *
Steven Thomas6d88a482019-12-02 22:00:47 -0800667 * Available since API level 30.
668 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100669void ASurfaceTransaction_setFrameRate(ASurfaceTransaction* _Nonnull transaction,
670 ASurfaceControl* _Nonnull surface_control, float frameRate,
Steven Thomas62a4cf82020-01-31 12:04:03 -0800671 int8_t compatibility) __INTRODUCED_IN(30);
Steven Thomas6d88a482019-12-02 22:00:47 -0800672
Marin Shalamanov46084422020-10-13 12:33:42 +0200673/**
674 * Sets the intended frame rate for \a surface_control.
675 *
676 * On devices that are capable of running the display at different refresh rates, the system may
677 * choose a display refresh rate to better match this surface's frame rate. Usage of this API won't
678 * directly affect the application's frame production pipeline. However, because the system may
679 * change the display refresh rate, calls to this function may result in changes to Choreographer
680 * callback timings, and changes to the time interval at which the system releases buffers back to
681 * the application.
682 *
Marin Shalamanova308b9d2021-05-05 13:43:28 +0200683 * You can register for changes in the refresh rate using
684 * \a AChoreographer_registerRefreshRateCallback.
685 *
Kriti Dang4113fc12022-08-26 16:30:37 +0200686 * See ASurfaceTransaction_clearFrameRate().
687 *
Marin Shalamanov46084422020-10-13 12:33:42 +0200688 * \param frameRate is the intended frame rate of this surface, in frames per second. 0 is a special
689 * value that indicates the app will accept the system's choice for the display frame rate, which is
690 * the default behavior if this function isn't called. The frameRate param does <em>not</em> need to
691 * be a valid refresh rate for this device's display - e.g., it's fine to pass 30fps to a device
692 * that can only run the display at 60fps.
693 *
694 * \param compatibility The frame rate compatibility of this surface. The compatibility value may
695 * influence the system's choice of display frame rate. To specify a compatibility use the
Marin Shalamanov293ac2c2021-04-26 14:13:04 +0200696 * ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_* enum. This parameter is ignored when frameRate is 0.
Marin Shalamanov46084422020-10-13 12:33:42 +0200697 *
Marin Shalamanov293ac2c2021-04-26 14:13:04 +0200698 * \param changeFrameRateStrategy Whether display refresh rate transitions caused by this
699 * surface should be seamless. A seamless transition is one that doesn't have any visual
700 * interruptions, such as a black screen for a second or two. See the
701 * ANATIVEWINDOW_CHANGE_FRAME_RATE_* values. This parameter is ignored when frameRate is 0.
Marin Shalamanov46084422020-10-13 12:33:42 +0200702 *
703 * Available since API level 31.
704 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100705void ASurfaceTransaction_setFrameRateWithChangeStrategy(ASurfaceTransaction* _Nonnull transaction,
706 ASurfaceControl* _Nonnull surface_control,
707 float frameRate, int8_t compatibility,
708 int8_t changeFrameRateStrategy)
709 __INTRODUCED_IN(31);
Marin Shalamanov46084422020-10-13 12:33:42 +0200710
Robert Carrf08168d2021-03-24 15:49:18 -0700711/**
Kriti Dang4113fc12022-08-26 16:30:37 +0200712 * Clears the frame rate which is set for \a surface_control.
713 *
714 * This is equivalent to calling
715 * ASurfaceTransaction_setFrameRateWithChangeStrategy(
716 * transaction, 0, compatibility, changeFrameRateStrategy).
717 *
718 * Usage of this API won't directly affect the application's frame production pipeline. However,
719 * because the system may change the display refresh rate, calls to this function may result in
720 * changes to Choreographer callback timings, and changes to the time interval at which the system
721 * releases buffers back to the application.
722 *
723 * See ASurfaceTransaction_setFrameRateWithChangeStrategy()
724 *
725 * You can register for changes in the refresh rate using
726 * \a AChoreographer_registerRefreshRateCallback.
727 *
728 * See ASurfaceTransaction_setFrameRateWithChangeStrategy().
729 *
730 * Available since API level 34.
731 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100732void ASurfaceTransaction_clearFrameRate(ASurfaceTransaction* _Nonnull transaction,
733 ASurfaceControl* _Nonnull surface_control)
Kriti Dang4113fc12022-08-26 16:30:37 +0200734 __INTRODUCED_IN(__ANDROID_API_U__);
735
736/**
Robert Carrf08168d2021-03-24 15:49:18 -0700737 * Indicate whether to enable backpressure for buffer submission to a given SurfaceControl.
738 *
739 * By default backpressure is disabled, which means submitting a buffer prior to receiving
740 * a callback for the previous buffer could lead to that buffer being "dropped". In cases
741 * where you are selecting for latency, this may be a desirable behavior! We had a new buffer
742 * ready, why shouldn't we show it?
743 *
744 * When back pressure is enabled, each buffer will be required to be presented
745 * before it is released and the callback delivered
746 * (absent the whole SurfaceControl being removed).
747 *
748 * Most apps are likely to have some sort of backpressure internally, e.g. you are
749 * waiting on the callback from frame N-2 before starting frame N. In high refresh
750 * rate scenarios there may not be much time between SurfaceFlinger completing frame
751 * N-1 (and therefore releasing buffer N-2) and beginning frame N. This means
752 * your app may not have enough time to respond in the callback. Using this flag
753 * and pushing buffers earlier for server side queuing will be advantageous
754 * in such cases.
755 *
Alec Mouri5a100fa2023-02-24 00:45:29 +0000756 * Available since API level 31.
757 *
Robert Carrf08168d2021-03-24 15:49:18 -0700758 * \param transaction The transaction in which to make the change.
759 * \param surface_control The ASurfaceControl on which to control buffer backpressure behavior.
760 * \param enableBackPressure Whether to enable back pressure.
761 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100762void ASurfaceTransaction_setEnableBackPressure(ASurfaceTransaction* _Nonnull transaction,
763 ASurfaceControl* _Nonnull surface_control,
764 bool enableBackPressure) __INTRODUCED_IN(31);
Robert Carrf08168d2021-03-24 15:49:18 -0700765
Rachel Leeed511ef2021-10-11 15:09:51 -0700766/**
Rachel Leee81bf262022-08-23 14:37:59 -0700767 * Sets the frame timeline to use in SurfaceFlinger.
Rachel Lee1fb2ddc2022-01-12 14:33:07 -0800768 *
Rachel Leee81bf262022-08-23 14:37:59 -0700769 * A frame timeline should be chosen based on the frame deadline the application
770 * can meet when rendering the frame and the application's desired presentation time.
771 * By setting a frame timeline, SurfaceFlinger tries to present the frame at the corresponding
772 * expected presentation time.
Rachel Lee1fb2ddc2022-01-12 14:33:07 -0800773 *
774 * To receive frame timelines, a callback must be posted to Choreographer using
Rachel Leee81bf262022-08-23 14:37:59 -0700775 * AChoreographer_postVsyncCallback(). The \c vsyncId can then be extracted from the
Rachel Lee1fb2ddc2022-01-12 14:33:07 -0800776 * callback payload using AChoreographerFrameCallbackData_getFrameTimelineVsyncId().
Rachel Leeed511ef2021-10-11 15:09:51 -0700777 *
Alec Mouri5a100fa2023-02-24 00:45:29 +0000778 * Available since API level 33.
779 *
Rachel Leee81bf262022-08-23 14:37:59 -0700780 * \param vsyncId The vsync ID received from AChoreographer, setting the frame's presentation target
781 * to the corresponding expected presentation time and deadline from the frame to be rendered. A
782 * stale or invalid value will be ignored.
Rachel Leeed511ef2021-10-11 15:09:51 -0700783 */
Marijn Suijtenb54710f2024-01-19 00:44:53 +0100784void ASurfaceTransaction_setFrameTimeline(ASurfaceTransaction* _Nonnull transaction,
Rachel Lee1fb2ddc2022-01-12 14:33:07 -0800785 AVsyncId vsyncId) __INTRODUCED_IN(33);
Rachel Leeed511ef2021-10-11 15:09:51 -0700786
Marissa Wall53da7e32018-09-25 15:59:38 -0700787__END_DECLS
788
789#endif // ANDROID_SURFACE_CONTROL_H
Marin Shalamanov574c58d2021-03-18 15:10:02 +0100790
791/** @} */