blob: 6323333429029400a32941068013cfd9d3fb740d [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
Sally Qi01e9f302024-11-04 11:40:06 -080031#include <android/display_luts.h>
Rachel Lee1fb2ddc2022-01-12 14:33:07 -080032#include <android/choreographer.h>
Marissa Wall3ff826c2019-02-07 11:58:25 -080033#include <android/data_space.h>
Marissa Wall53da7e32018-09-25 15:59:38 -070034#include <android/hardware_buffer.h>
Marissa Wall80d94ad2019-01-18 16:04:36 -080035#include <android/hdr_metadata.h>
Marissa Wall53da7e32018-09-25 15:59:38 -070036#include <android/native_window.h>
37
38__BEGIN_DECLS
39
Marissa Wall53da7e32018-09-25 15:59:38 -070040struct ASurfaceControl;
41
42/**
Elliott Hughes733bf992019-03-08 11:25:28 -080043 * The SurfaceControl API can be used to provide a hierarchy of surfaces for
Marissa Wall53da7e32018-09-25 15:59:38 -070044 * composition to the system compositor. ASurfaceControl represents a content node in
Elliott Hughes733bf992019-03-08 11:25:28 -080045 * this hierarchy.
Marissa Wall53da7e32018-09-25 15:59:38 -070046 */
47typedef struct ASurfaceControl ASurfaceControl;
48
Elliott Hughes3d70e532019-10-29 08:59:39 -070049/**
Marissa Wall53da7e32018-09-25 15:59:38 -070050 * Creates an ASurfaceControl with either ANativeWindow or an ASurfaceControl as its parent.
Marin Shalamanov110c6bc2020-11-16 17:57:59 +010051 * \a debug_name is a debug name associated with this surface. It can be used to
Marissa Wall53da7e32018-09-25 15:59:38 -070052 * identify this surface in the SurfaceFlinger's layer tree. It must not be
53 * null.
54 *
55 * The caller takes ownership of the ASurfaceControl returned and must release it
56 * using ASurfaceControl_release below.
Elliott Hughes3d70e532019-10-29 08:59:39 -070057 *
Vishnu Nair172d5a32023-04-25 22:23:41 +000058 * By default the \a ASurfaceControl will be visible and display any buffer submitted. In
59 * addition, the default buffer submission control may release and not display all buffers
60 * that are submitted before receiving a callback for the previous buffer. See
61 * \a ASurfaceTransaction_setVisibility and \a ASurfaceTransaction_setEnableBackPressure to
62 * change the default behaviors after creation.
63 *
Elliott Hughes3d70e532019-10-29 08:59:39 -070064 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -070065 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +010066ASurfaceControl* _Nullable ASurfaceControl_createFromWindow(ANativeWindow* _Nonnull parent,
67 const char* _Nonnull debug_name)
68 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -070069
Elliott Hughes3d70e532019-10-29 08:59:39 -070070/**
71 * See ASurfaceControl_createFromWindow.
72 *
73 * Available since API level 29.
74 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +010075ASurfaceControl* _Nullable ASurfaceControl_create(ASurfaceControl* _Nonnull parent,
76 const char* _Nonnull debug_name)
77 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -070078
79/**
Huihong Luodb5778e2021-01-28 14:48:59 -080080 * Acquires a reference on the given ASurfaceControl object. This prevents the object
81 * from being deleted until the reference is removed.
82 *
83 * To release the reference, use the ASurfaceControl_release function.
84 *
85 * Available since API level 31.
86 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +010087void ASurfaceControl_acquire(ASurfaceControl* _Nonnull surface_control) __INTRODUCED_IN(31);
Huihong Luodb5778e2021-01-28 14:48:59 -080088
89/**
90 * Removes a reference that was previously acquired with one of the following functions:
91 * ASurfaceControl_createFromWindow
92 * ASurfaceControl_create
93 * ANativeWindow_acquire
94 * The surface and its children may remain on display as long as their parent remains on display.
Elliott Hughes3d70e532019-10-29 08:59:39 -070095 *
96 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -070097 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +010098void ASurfaceControl_release(ASurfaceControl* _Nonnull surface_control) __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -070099
100struct ASurfaceTransaction;
101
102/**
103 * ASurfaceTransaction is a collection of updates to the surface tree that must
104 * be applied atomically.
105 */
106typedef struct ASurfaceTransaction ASurfaceTransaction;
107
108/**
109 * The caller takes ownership of the transaction and must release it using
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100110 * ASurfaceTransaction_delete() below.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700111 *
112 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700113 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100114ASurfaceTransaction* _Nonnull ASurfaceTransaction_create() __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700115
116/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100117 * Destroys the \a transaction object.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700118 *
119 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700120 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100121void ASurfaceTransaction_delete(ASurfaceTransaction* _Nullable transaction) __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700122
123/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100124 * Applies the updates accumulated in \a transaction.
Marissa Wall53da7e32018-09-25 15:59:38 -0700125 *
126 * Note that the transaction is guaranteed to be applied atomically. The
127 * transactions which are applied on the same thread are also guaranteed to be
128 * applied in order.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700129 *
130 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700131 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100132void ASurfaceTransaction_apply(ASurfaceTransaction* _Nonnull transaction) __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700133
134/**
Marissa Wall80d94ad2019-01-18 16:04:36 -0800135 * An opaque handle returned during a callback that can be used to query general stats and stats for
136 * surfaces which were either removed or for which buffers were updated after this transaction was
137 * applied.
138 */
139typedef struct ASurfaceTransactionStats ASurfaceTransactionStats;
140
141/**
Marissa Wall53da7e32018-09-25 15:59:38 -0700142 * Since the transactions are applied asynchronously, the
143 * ASurfaceTransaction_OnComplete callback can be used to be notified when a frame
144 * including the updates in a transaction was presented.
145 *
Robert Carr11085792021-05-12 14:35:35 -0700146 * Buffers which are replaced or removed from the scene in the transaction invoking
147 * this callback may be reused after this point.
148 *
Vishnu Nair879a41a2024-09-16 17:43:59 +0000149 * Starting with API level 36, prefer using \a ASurfaceTransaction_OnBufferRelease to listen
150 * to when a buffer is ready to be reused.
151 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100152 * \param context Optional context provided by the client that is passed into
Marissa Wall53da7e32018-09-25 15:59:38 -0700153 * the callback.
Marissa Wall53da7e32018-09-25 15:59:38 -0700154 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100155 * \param stats Opaque handle that can be passed to ASurfaceTransactionStats functions to query
Elliott Hughes733bf992019-03-08 11:25:28 -0800156 * information about the transaction. The handle is only valid during the callback.
Marissa Wall53da7e32018-09-25 15:59:38 -0700157 *
158 * THREADING
159 * The transaction completed callback can be invoked on any thread.
160 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100161typedef void (*ASurfaceTransaction_OnComplete)(void* _Null_unspecified context,
Vishnu Nair72c71a82024-09-17 23:00:20 +0000162 ASurfaceTransactionStats* _Nonnull stats);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700163
164/**
165 * The ASurfaceTransaction_OnCommit callback is invoked when transaction is applied and the updates
166 * are ready to be presented. This callback will be invoked before the
167 * ASurfaceTransaction_OnComplete callback.
168 *
Robert Carr11085792021-05-12 14:35:35 -0700169 * This callback does not mean buffers have been released! It simply means that any new
170 * transactions applied will not overwrite the transaction for which we are receiving
171 * a callback and instead will be included in the next frame. If you are trying to avoid
172 * dropping frames (overwriting transactions), and unable to use timestamps (Which provide
173 * a more efficient solution), then this method provides a method to pace your transaction
174 * application.
175 *
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700176 * \param context Optional context provided by the client that is passed into the callback.
177 *
178 * \param stats Opaque handle that can be passed to ASurfaceTransactionStats functions to query
179 * information about the transaction. The handle is only valid during the callback.
180 * Present and release fences are not available for this callback. Querying them using
181 * ASurfaceTransactionStats_getPresentFenceFd and ASurfaceTransactionStats_getPreviousReleaseFenceFd
182 * will result in failure.
183 *
184 * THREADING
185 * The transaction committed callback can be invoked on any thread.
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700186 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100187typedef void (*ASurfaceTransaction_OnCommit)(void* _Null_unspecified context,
Vishnu Nair72c71a82024-09-17 23:00:20 +0000188 ASurfaceTransactionStats* _Nonnull stats);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700189
Marissa Wall80d94ad2019-01-18 16:04:36 -0800190/**
Vishnu Nair879a41a2024-09-16 17:43:59 +0000191 * The ASurfaceTransaction_OnBufferRelease callback is invoked when a buffer that was passed in
192 * ASurfaceTransaction_setBuffer is ready to be reused.
193 *
194 * This callback is guaranteed to be invoked if ASurfaceTransaction_setBuffer is called with a non
195 * null buffer. If the buffer in the transaction is replaced via another call to
196 * ASurfaceTransaction_setBuffer, the callback will be invoked immediately. Otherwise the callback
197 * will be invoked before the ASurfaceTransaction_OnComplete callback after the buffer was
198 * presented.
199 *
200 * If this callback is set, caller should not release the buffer using the
201 * ASurfaceTransaction_OnComplete.
202 *
203 * \param context Optional context provided by the client that is passed into the callback.
204 *
205 * \param release_fence_fd Returns the fence file descriptor used to signal the release of buffer
206 * associated with this callback. If this fence is valid (>=0), the buffer has not yet been released
207 * and the fence will signal when the buffer has been released. If the fence is -1 , the buffer is
208 * already released. The recipient of the callback takes ownership of the fence fd and is
209 * responsible for closing it.
210 *
211 * THREADING
212 * The callback can be invoked on any thread.
Vishnu Nair879a41a2024-09-16 17:43:59 +0000213 */
214typedef void (*ASurfaceTransaction_OnBufferRelease)(void* _Null_unspecified context,
Vishnu Nair72c71a82024-09-17 23:00:20 +0000215 int release_fence_fd);
Vishnu Nair879a41a2024-09-16 17:43:59 +0000216
217/**
Marissa Wall80d94ad2019-01-18 16:04:36 -0800218 * Returns the timestamp of when the frame was latched by the framework. Once a frame is
219 * latched by the framework, it is presented at the following hardware vsync.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700220 *
221 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800222 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100223int64_t ASurfaceTransactionStats_getLatchTime(
224 ASurfaceTransactionStats* _Nonnull surface_transaction_stats) __INTRODUCED_IN(29);
Marissa Wall80d94ad2019-01-18 16:04:36 -0800225
226/**
227 * Returns a sync fence that signals when the transaction has been presented.
228 * The recipient of the callback takes ownership of the fence and is responsible for closing
Marissa Wall183c44c2019-04-08 12:58:50 -0700229 * it. If a device does not support present fences, a -1 will be returned.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700230 *
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700231 * This query is not valid for ASurfaceTransaction_OnCommit callback.
232 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700233 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800234 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100235int ASurfaceTransactionStats_getPresentFenceFd(
236 ASurfaceTransactionStats* _Nonnull surface_transaction_stats) __INTRODUCED_IN(29);
Marissa Wall80d94ad2019-01-18 16:04:36 -0800237
238/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100239 * \a outASurfaceControls returns an array of ASurfaceControl pointers that were updated during the
Marissa Wall80d94ad2019-01-18 16:04:36 -0800240 * transaction. Stats for the surfaces can be queried through ASurfaceTransactionStats functions.
241 * When the client is done using the array, it must release it by calling
242 * ASurfaceTransactionStats_releaseASurfaceControls.
243 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700244 * Available since API level 29.
245 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100246 * \a outASurfaceControlsSize returns the size of the ASurfaceControls array.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800247 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100248void ASurfaceTransactionStats_getASurfaceControls(
249 ASurfaceTransactionStats* _Nonnull surface_transaction_stats,
250 ASurfaceControl* _Nullable* _Nullable* _Nonnull outASurfaceControls,
251 size_t* _Nonnull outASurfaceControlsSize) __INTRODUCED_IN(29);
Marissa Wall80d94ad2019-01-18 16:04:36 -0800252/**
253 * Releases the array of ASurfaceControls that were returned by
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100254 * ASurfaceTransactionStats_getASurfaceControls().
Elliott Hughes3d70e532019-10-29 08:59:39 -0700255 *
256 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800257 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100258void ASurfaceTransactionStats_releaseASurfaceControls(
259 ASurfaceControl* _Nonnull* _Nonnull surface_controls) __INTRODUCED_IN(29);
Marissa Wall80d94ad2019-01-18 16:04:36 -0800260
261/**
262 * Returns the timestamp of when the CURRENT buffer was acquired. A buffer is considered
263 * acquired when its acquire_fence_fd has signaled. A buffer cannot be latched or presented until
264 * it is acquired. If no acquire_fence_fd was provided, this timestamp will be set to -1.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700265 *
266 * Available since API level 29.
Chavi Weingartenfed621c2024-03-14 15:46:05 +0000267 *
268 * @deprecated This may return SIGNAL_PENDING because the stats can arrive before the acquire
269 * fence has signaled, depending on internal timing differences. Therefore the caller should
270 * use the acquire fence passed in to setBuffer and query the signal time.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800271 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100272int64_t ASurfaceTransactionStats_getAcquireTime(
273 ASurfaceTransactionStats* _Nonnull surface_transaction_stats,
274 ASurfaceControl* _Nonnull surface_control) __INTRODUCED_IN(29);
Marissa Wall80d94ad2019-01-18 16:04:36 -0800275
276/**
277 * The returns the fence used to signal the release of the PREVIOUS buffer set on
278 * 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 +0000279 * fence will signal when the PREVIOUS buffer has been released. If the fence is -1, the PREVIOUS
Marissa Wall80d94ad2019-01-18 16:04:36 -0800280 * buffer is already released. The recipient of the callback takes ownership of the
281 * previousReleaseFenceFd and is responsible for closing it.
282 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100283 * Each time a buffer is set through ASurfaceTransaction_setBuffer() on a transaction
284 * which is applied, the framework takes a ref on this buffer. The framework treats the
Marissa Wall80d94ad2019-01-18 16:04:36 -0800285 * addition of a buffer to a particular surface as a unique ref. When a transaction updates or
286 * removes a buffer from a surface, or removes the surface itself from the tree, this ref is
287 * guaranteed to be released in the OnComplete callback for this transaction. The
288 * ASurfaceControlStats provided in the callback for this surface may contain an optional fence
289 * which must be signaled before the ref is assumed to be released.
290 *
291 * The client must ensure that all pending refs on a buffer are released before attempting to reuse
292 * this buffer, otherwise synchronization errors may occur.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700293 *
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700294 * This query is not valid for ASurfaceTransaction_OnCommit callback.
295 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700296 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800297 */
298int ASurfaceTransactionStats_getPreviousReleaseFenceFd(
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100299 ASurfaceTransactionStats* _Nonnull surface_transaction_stats,
300 ASurfaceControl* _Nonnull surface_control) __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700301
302/**
303 * Sets the callback that will be invoked when the updates from this transaction
304 * are presented. For details on the callback semantics and data, see the
305 * comments on the ASurfaceTransaction_OnComplete declaration above.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700306 *
307 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700308 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100309void ASurfaceTransaction_setOnComplete(ASurfaceTransaction* _Nonnull transaction,
310 void* _Null_unspecified context,
311 ASurfaceTransaction_OnComplete _Nonnull func)
312 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700313
Marissa Wall80d94ad2019-01-18 16:04:36 -0800314/**
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700315 * Sets the callback that will be invoked when the updates from this transaction are applied and are
316 * ready to be presented. This callback will be invoked before the ASurfaceTransaction_OnComplete
317 * callback.
318 *
319 * Available since API level 31.
320 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100321void ASurfaceTransaction_setOnCommit(ASurfaceTransaction* _Nonnull transaction,
322 void* _Null_unspecified context,
323 ASurfaceTransaction_OnCommit _Nonnull func)
324 __INTRODUCED_IN(31);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700325
326/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100327 * Reparents the \a surface_control from its old parent to the \a new_parent surface control.
328 * Any children of the reparented \a surface_control will remain children of the \a surface_control.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800329 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100330 * 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 -0700331 *
332 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800333 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100334void ASurfaceTransaction_reparent(ASurfaceTransaction* _Nonnull transaction,
335 ASurfaceControl* _Nonnull surface_control,
336 ASurfaceControl* _Nullable new_parent) __INTRODUCED_IN(29);
Marissa Wall80d94ad2019-01-18 16:04:36 -0800337
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100338/**
339 * Parameter for ASurfaceTransaction_setVisibility().
340 */
Marijn Suijten896a6612024-01-19 00:50:34 +0100341enum ASurfaceTransactionVisibility : int8_t {
Marissa Wall53da7e32018-09-25 15:59:38 -0700342 ASURFACE_TRANSACTION_VISIBILITY_HIDE = 0,
343 ASURFACE_TRANSACTION_VISIBILITY_SHOW = 1,
344};
345/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100346 * Updates the visibility of \a surface_control. If show is set to
347 * ASURFACE_TRANSACTION_VISIBILITY_HIDE, the \a surface_control and all surfaces in its subtree will
Marissa Wall53da7e32018-09-25 15:59:38 -0700348 * be hidden.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700349 *
350 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700351 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100352void ASurfaceTransaction_setVisibility(ASurfaceTransaction* _Nonnull transaction,
353 ASurfaceControl* _Nonnull surface_control,
Marijn Suijten896a6612024-01-19 00:50:34 +0100354 enum ASurfaceTransactionVisibility visibility)
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100355 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700356
357/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100358 * Updates the z order index for \a surface_control. Note that the z order for a surface
Marissa Wall53da7e32018-09-25 15:59:38 -0700359 * is relative to other surfaces which are siblings of this surface. The behavior of sibilings with
360 * the same z order is undefined.
361 *
362 * 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 -0700363 *
364 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700365 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100366void ASurfaceTransaction_setZOrder(ASurfaceTransaction* _Nonnull transaction,
367 ASurfaceControl* _Nonnull surface_control, int32_t z_order)
368 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700369
370/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100371 * Updates the AHardwareBuffer displayed for \a surface_control. If not -1, the
Marissa Wall80d94ad2019-01-18 16:04:36 -0800372 * acquire_fence_fd should be a file descriptor that is signaled when all pending work
Marissa Wall53da7e32018-09-25 15:59:38 -0700373 * for the buffer is complete and the buffer can be safely read.
374 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100375 * The frameworks takes ownership of the \a acquire_fence_fd passed and is responsible
Marissa Wall53da7e32018-09-25 15:59:38 -0700376 * for closing it.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700377 *
Ady Abraham38605fc2021-03-29 20:33:42 +0000378 * Note that the buffer must be allocated with AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE
379 * as the surface control might be composited using the GPU.
380 *
Vishnu Nair879a41a2024-09-16 17:43:59 +0000381 * Starting with API level 36, prefer using \a ASurfaceTransaction_setBufferWithRelease to
382 * set a buffer and a callback which will be invoked when the buffer is ready to be reused.
383 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700384 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700385 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100386void ASurfaceTransaction_setBuffer(ASurfaceTransaction* _Nonnull transaction,
387 ASurfaceControl* _Nonnull surface_control,
388 AHardwareBuffer* _Nonnull buffer, int acquire_fence_fd)
389 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700390
391/**
Vishnu Nair879a41a2024-09-16 17:43:59 +0000392 * Updates the AHardwareBuffer displayed for \a surface_control. If not -1, the
393 * acquire_fence_fd should be a file descriptor that is signaled when all pending work
394 * for the buffer is complete and the buffer can be safely read.
395 *
396 * The frameworks takes ownership of the \a acquire_fence_fd passed and is responsible
397 * for closing it.
398 *
399 * Note that the buffer must be allocated with AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE
400 * as the surface control might be composited using the GPU.
401 *
402 * When the buffer is ready to be reused, the ASurfaceTransaction_OnBufferRelease
403 * callback will be invoked. If the buffer is null, the callback will not be invoked.
404 *
405 * Available since API level 36.
406 */
407void ASurfaceTransaction_setBufferWithRelease(ASurfaceTransaction* _Nonnull transaction,
408 ASurfaceControl* _Nonnull surface_control,
409 AHardwareBuffer* _Nonnull buffer,
410 int acquire_fence_fd, void* _Null_unspecified context,
411 ASurfaceTransaction_OnBufferRelease _Nonnull func)
412 __INTRODUCED_IN(36);
413
414/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100415 * Updates the color for \a surface_control. This will make the background color for the
416 * ASurfaceControl visible in transparent regions of the surface. Colors \a r, \a g,
417 * 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 -0800418 * will be the dataspace and alpha set for the background color layer.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700419 *
420 * Available since API level 29.
Valerie Haued54efa2019-01-11 20:03:14 -0800421 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100422void ASurfaceTransaction_setColor(ASurfaceTransaction* _Nonnull transaction,
423 ASurfaceControl* _Nonnull surface_control, float r, float g,
424 float b, float alpha, enum ADataSpace dataspace)
425 __INTRODUCED_IN(29);
Valerie Haued54efa2019-01-11 20:03:14 -0800426
Dan Albertf93853d2024-08-01 22:20:38 +0000427// These APIs (setGeometry and setCrop) were originally written in a
428// C-incompatible form using references instead of pointers, and the OS shipped
429// that version for years before it was noticed. Fortunately the compiled code
430// for callers is the same regardless of whether it's a pointer or a reference,
431// so we can declare this as a nonnull pointer for C and keep the existing C++
432// decl and definition.
433//
434// We could alternatively change the decl and the definition to both be a
435// pointer (with an inline definition using references to preserve source compat
436// for existing C++ callers), but that requires changing the definition of an
437// API that has been in the OS for years. It's theoretically a safe change, but
438// without being able to prove it that's a very big risk to take. By keeping the
439// C-compatibility hack in the header, we can be sure that we haven't changed
440// anything for existing callers. By definition there were no C users of the
441// reference-based decl; if there were any C callers of the API at all, they were
442// using the same workaround that is now used below.
443//
444// Even if this workaround turns out to not work for C, there's no permanent
445// damage done to the platform (unlike if we were to change the definition). At
446// worst it continues to work for C++ (since the preprocessed header as seen by
447// C++ hasn't changed, nor has the definition) and continues to not work for C.
448
Valerie Haued54efa2019-01-11 20:03:14 -0800449/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100450 * \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 -0700451 * The surface's source rect is clipped by the bounds of its current buffer. The source rect's width
452 * and height must be > 0.
453 *
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100454 * \param destination Specifies the rect in the parent's space where this surface will be drawn. The
455 * post source rect bounds are scaled to fit the destination rect. The surface's destination rect is
Marissa Wall53da7e32018-09-25 15:59:38 -0700456 * clipped by the bounds of its parent. The destination rect's width and height must be > 0.
457 *
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100458 * \param transform The transform applied after the source rect is applied to the buffer. This
Dan Albert61438382024-08-02 20:51:12 +0000459 * parameter should be set to 0 for no transform. To specify a transform use the
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100460 * NATIVE_WINDOW_TRANSFORM_* enum.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700461 *
462 * Available since API level 29.
chaviw1f5e7402021-04-29 09:15:20 -0500463 *
464 * @deprecated Use setCrop, setPosition, setBufferTransform, and setScale instead. Those functions
465 * provide well defined behavior and allows for more control by the apps. It also allows the caller
466 * to set different properties at different times, instead of having to specify all the desired
467 * properties at once.
Marissa Wall53da7e32018-09-25 15:59:38 -0700468 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100469void ASurfaceTransaction_setGeometry(ASurfaceTransaction* _Nonnull transaction,
Dan Albertf93853d2024-08-01 22:20:38 +0000470 ASurfaceControl* _Nonnull surface_control,
471#if defined(__cplusplus)
472 const ARect& source, const ARect& destination,
473#else
474 const ARect* _Nonnull source,
475 const ARect* _Nonnull destination,
476#endif
477 int32_t transform) __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700478
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500479/**
chaviwbe8d0092021-03-29 18:49:46 -0500480 * Bounds the surface and its children to the bounds specified. The crop and buffer size will be
481 * used to determine the bounds of the surface. If no crop is specified and the surface has no
482 * buffer, the surface bounds is only constrained by the size of its parent bounds.
483 *
484 * \param crop The bounds of the crop to apply.
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500485 *
486 * Available since API level 31.
487 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100488void ASurfaceTransaction_setCrop(ASurfaceTransaction* _Nonnull transaction,
Dan Albertf93853d2024-08-01 22:20:38 +0000489 ASurfaceControl* _Nonnull surface_control,
490#if defined(__cplusplus)
491 const ARect& crop)
492#else
493 const ARect* _Nonnull crop)
494#endif
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100495 __INTRODUCED_IN(31);
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500496
497/**
chaviwbe8d0092021-03-29 18:49:46 -0500498 * Specifies the position in the parent's space where the surface will be drawn.
499 *
500 * \param x The x position to render the surface.
501 * \param y The y position to render the surface.
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500502 *
503 * Available since API level 31.
504 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100505void ASurfaceTransaction_setPosition(ASurfaceTransaction* _Nonnull transaction,
506 ASurfaceControl* _Nonnull surface_control, int32_t x,
507 int32_t y) __INTRODUCED_IN(31);
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500508
509/**
510 * \param transform The transform applied after the source rect is applied to the buffer. This
chaviwbe8d0092021-03-29 18:49:46 -0500511 * parameter should be set to 0 for no transform. To specify a transform use the
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500512 * NATIVE_WINDOW_TRANSFORM_* enum.
513 *
514 * Available since API level 31.
515 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100516void ASurfaceTransaction_setBufferTransform(ASurfaceTransaction* _Nonnull transaction,
517 ASurfaceControl* _Nonnull surface_control,
518 int32_t transform) __INTRODUCED_IN(31);
Marissa Wall53da7e32018-09-25 15:59:38 -0700519
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100520/**
chaviwbe8d0092021-03-29 18:49:46 -0500521 * Sets an x and y scale of a surface with (0, 0) as the centerpoint of the scale.
522 *
523 * \param xScale The scale in the x direction. Must be greater than 0.
524 * \param yScale The scale in the y direction. Must be greater than 0.
525 *
526 * Available since API level 31.
527 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100528void ASurfaceTransaction_setScale(ASurfaceTransaction* _Nonnull transaction,
529 ASurfaceControl* _Nonnull surface_control, float xScale,
530 float yScale) __INTRODUCED_IN(31);
chaviwbe8d0092021-03-29 18:49:46 -0500531/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100532 * Parameter for ASurfaceTransaction_setBufferTransparency().
533 */
Marijn Suijten896a6612024-01-19 00:50:34 +0100534enum ASurfaceTransactionTransparency : int8_t {
Marissa Wall53da7e32018-09-25 15:59:38 -0700535 ASURFACE_TRANSACTION_TRANSPARENCY_TRANSPARENT = 0,
536 ASURFACE_TRANSACTION_TRANSPARENCY_TRANSLUCENT = 1,
537 ASURFACE_TRANSACTION_TRANSPARENCY_OPAQUE = 2,
538};
539/**
540 * Updates whether the content for the buffer associated with this surface is
541 * completely opaque. If true, every pixel of content inside the buffer must be
542 * opaque or visual errors can occur.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700543 *
544 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700545 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100546void ASurfaceTransaction_setBufferTransparency(ASurfaceTransaction* _Nonnull transaction,
547 ASurfaceControl* _Nonnull surface_control,
Marijn Suijten896a6612024-01-19 00:50:34 +0100548 enum ASurfaceTransactionTransparency transparency)
Marissa Wall80d94ad2019-01-18 16:04:36 -0800549 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700550
551/**
552 * Updates the region for the content on this surface updated in this
553 * transaction. If unspecified, the complete surface is assumed to be damaged.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700554 *
555 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700556 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100557void ASurfaceTransaction_setDamageRegion(ASurfaceTransaction* _Nonnull transaction,
558 ASurfaceControl* _Nonnull surface_control,
559 const ARect* _Nullable rects, uint32_t count)
560 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700561
Marissa Wall80d94ad2019-01-18 16:04:36 -0800562/**
563 * Specifies a desiredPresentTime for the transaction. The framework will try to present
564 * the transaction at or after the time specified.
565 *
566 * Transactions will not be presented until all of their acquire fences have signaled even if the
567 * app requests an earlier present time.
568 *
569 * If an earlier transaction has a desired present time of x, and a later transaction has a desired
570 * present time that is before x, the later transaction will not preempt the earlier transaction.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700571 *
572 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800573 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100574void ASurfaceTransaction_setDesiredPresentTime(ASurfaceTransaction* _Nonnull transaction,
Marissa Wall80d94ad2019-01-18 16:04:36 -0800575 int64_t desiredPresentTime) __INTRODUCED_IN(29);
576
577/**
578 * Sets the alpha for the buffer. It uses a premultiplied blending.
579 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100580 * The \a alpha must be between 0.0 and 1.0.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700581 *
582 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800583 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100584void ASurfaceTransaction_setBufferAlpha(ASurfaceTransaction* _Nonnull transaction,
585 ASurfaceControl* _Nonnull surface_control, float alpha)
Marissa Wall80d94ad2019-01-18 16:04:36 -0800586 __INTRODUCED_IN(29);
587
Marissa Wall3ff826c2019-02-07 11:58:25 -0800588/**
589 * Sets the data space of the surface_control's buffers.
590 *
591 * If no data space is set, the surface control defaults to ADATASPACE_SRGB.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700592 *
593 * Available since API level 29.
Marissa Wall3ff826c2019-02-07 11:58:25 -0800594 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100595void ASurfaceTransaction_setBufferDataSpace(ASurfaceTransaction* _Nonnull transaction,
596 ASurfaceControl* _Nonnull surface_control,
597 enum ADataSpace data_space) __INTRODUCED_IN(29);
Marissa Wall3ff826c2019-02-07 11:58:25 -0800598
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100599/**
Marissa Wall80d94ad2019-01-18 16:04:36 -0800600 * SMPTE ST 2086 "Mastering Display Color Volume" static metadata
601 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100602 * When \a metadata is set to null, the framework does not use any smpte2086 metadata when rendering
Marissa Wall80d94ad2019-01-18 16:04:36 -0800603 * the surface's buffer.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700604 *
605 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800606 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100607void ASurfaceTransaction_setHdrMetadata_smpte2086(ASurfaceTransaction* _Nonnull transaction,
608 ASurfaceControl* _Nonnull surface_control,
609 struct AHdrMetadata_smpte2086* _Nullable metadata)
Marissa Wall80d94ad2019-01-18 16:04:36 -0800610 __INTRODUCED_IN(29);
611
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100612/**
Marissa Wall80d94ad2019-01-18 16:04:36 -0800613 * Sets the CTA 861.3 "HDR Static Metadata Extension" static metadata on a surface.
614 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100615 * 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 -0800616 * the surface's buffer.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700617 *
618 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800619 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100620void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* _Nonnull transaction,
621 ASurfaceControl* _Nonnull surface_control,
622 struct AHdrMetadata_cta861_3* _Nullable metadata)
Marissa Wall80d94ad2019-01-18 16:04:36 -0800623 __INTRODUCED_IN(29);
624
Steven Thomas15b6f9c2020-03-26 13:44:28 -0700625/**
John Reckfeec2c62023-02-13 10:19:08 -0500626 * Sets the desired extended range brightness for the layer. This only applies for layers whose
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000627 * dataspace has RANGE_EXTENDED set on it. See: ASurfaceTransaction_setDesiredHdrHeadroom, prefer
628 * using this API for formats that encode an HDR/SDR ratio as part of generating the buffer.
Alec Mouri5a100fa2023-02-24 00:45:29 +0000629 *
John Reckfeec2c62023-02-13 10:19:08 -0500630 * @param surface_control The layer whose extended range brightness is being specified
Alec Mouric1392202024-03-06 19:10:00 +0000631 * @param currentBufferRatio The current HDR/SDR ratio of the current buffer as represented as
John Reckfeec2c62023-02-13 10:19:08 -0500632 * peakHdrBrightnessInNits / targetSdrWhitePointInNits. For example if the
633 * buffer was rendered with a target SDR whitepoint of 100nits and a max
634 * display brightness of 200nits, this should be set to 2.0f.
635 *
636 * Default value is 1.0f.
637 *
638 * Transfer functions that encode their own brightness ranges, such as
639 * HLG or PQ, should also set this to 1.0f and instead communicate
640 * extended content brightness information via metadata such as CTA861_3
641 * or SMPTE2086.
642 *
643 * Must be finite && >= 1.0f
644 *
Alec Mouric1392202024-03-06 19:10:00 +0000645 * @param desiredRatio The desired HDR/SDR ratio as represented as peakHdrBrightnessInNits /
John Reckfeec2c62023-02-13 10:19:08 -0500646 * targetSdrWhitePointInNits. This can be used to communicate the max desired
647 * brightness range. This is similar to the "max luminance" value in other
648 * HDR metadata formats, but represented as a ratio of the target SDR whitepoint
649 * to the max display brightness. The system may not be able to, or may choose
650 * not to, deliver the requested range.
651 *
John Reck1fb63cc2023-04-19 14:39:11 -0400652 * While requesting a large desired ratio will result in the most
653 * dynamic range, voluntarily reducing the requested range can help
654 * improve battery life as well as can improve quality by ensuring
655 * greater bit depth is allocated to the luminance range in use.
656 *
657 * Default value is 1.0f and indicates that extended range brightness
658 * is not being used, so the resulting SDR or HDR behavior will be
659 * determined entirely by the dataspace being used (ie, typically SDR
660 * however PQ or HLG transfer functions will still result in HDR)
John Reckfeec2c62023-02-13 10:19:08 -0500661 *
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000662 * When called after ASurfaceTransaction_setDesiredHdrHeadroom, the
663 * desiredRatio will override the desiredHeadroom provided by
664 * ASurfaceTransaction_setDesiredHdrHeadroom. Conversely, when called before
665 * ASurfaceTransaction_setDesiredHdrHeadroom, the desiredHeadroom provided by
666 *. ASurfaceTransaction_setDesiredHdrHeadroom will override the desiredRatio.
667 *
John Reckfeec2c62023-02-13 10:19:08 -0500668 * Must be finite && >= 1.0f
John Reck8a5e2f92023-03-16 14:27:48 -0400669 *
670 * Available since API level 34.
John Reckfeec2c62023-02-13 10:19:08 -0500671 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100672void ASurfaceTransaction_setExtendedRangeBrightness(ASurfaceTransaction* _Nonnull transaction,
673 ASurfaceControl* _Nonnull surface_control,
674 float currentBufferRatio, float desiredRatio)
675 __INTRODUCED_IN(__ANDROID_API_U__);
John Reckfeec2c62023-02-13 10:19:08 -0500676
677/**
Alec Mouric1392202024-03-06 19:10:00 +0000678 * Sets the desired HDR headroom for the layer. See: ASurfaceTransaction_setExtendedRangeBrightness,
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000679 * prefer using this API for formats that conform to HDR standards like HLG or HDR10, that do not
680 * communicate a HDR/SDR ratio as part of generating the buffer.
681 *
Alec Mouric1392202024-03-06 19:10:00 +0000682 * @param surface_control The layer whose desired HDR headroom is being specified
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000683 *
Alec Mouric1392202024-03-06 19:10:00 +0000684 * @param desiredHeadroom The desired HDR/SDR ratio as represented as peakHdrBrightnessInNits /
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000685 * targetSdrWhitePointInNits. This can be used to communicate the max
686 * desired brightness range of the panel. The system may not be able to, or
687 * may choose not to, deliver the requested range.
688 *
689 * While requesting a large desired ratio will result in the most
690 * dynamic range, voluntarily reducing the requested range can help
691 * improve battery life as well as can improve quality by ensuring
692 * greater bit depth is allocated to the luminance range in use.
693 *
694 * Default value is 0.0f and indicates that the system will choose the best
695 * headroom for this surface control's content. Typically, this means that
696 * HLG/PQ encoded content will be displayed with some HDR headroom greater
697 * than 1.0.
698 *
699 * When called after ASurfaceTransaction_setExtendedRangeBrightness, the
700 * desiredHeadroom will override the desiredRatio provided by
701 * ASurfaceTransaction_setExtendedRangeBrightness. Conversely, when called
702 * before ASurfaceTransaction_setExtendedRangeBrightness, the desiredRatio
703 * provided by ASurfaceTransaction_setExtendedRangeBrightness will override
704 * the desiredHeadroom.
705 *
706 * Must be finite && >= 1.0f or 0.0f to indicate there is no desired
707 * headroom.
708 *
709 * Available since API level 35.
710 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100711void ASurfaceTransaction_setDesiredHdrHeadroom(ASurfaceTransaction* _Nonnull transaction,
712 ASurfaceControl* _Nonnull surface_control,
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000713 float desiredHeadroom)
714 __INTRODUCED_IN(__ANDROID_API_V__);
715
716/**
Sally Qi01e9f302024-11-04 11:40:06 -0800717 * Sets the Lut(s) to be applied for the layer.
718 *
719 * The function makes a deep copy of the provided `luts`.
720 * Any modifications made to the `luts` object after calling this function
721 * will not affect the Lut(s) applied to the layer.
722 *
723 * @param surface_control The layer where Lut(s) is being applied
724 * @param luts The Lut(s) to be applied
725 *
726 * Available since API level 36.
727 */
728void ASurfaceTransaction_setLuts(ASurfaceTransaction* _Nonnull transaction,
729 ASurfaceControl* _Nonnull surface_control,
730 const struct ADisplayLuts* _Nullable luts)
731 __INTRODUCED_IN(36);
732
733/**
Marin Shalamanovc5986772021-03-16 16:09:49 +0100734 * Same as ASurfaceTransaction_setFrameRateWithChangeStrategy(transaction, surface_control,
735 * frameRate, compatibility, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS).
Steven Thomas6d88a482019-12-02 22:00:47 -0800736 *
Marin Shalamanovc5986772021-03-16 16:09:49 +0100737 * See ASurfaceTransaction_setFrameRateWithChangeStrategy().
Steven Thomas62a4cf82020-01-31 12:04:03 -0800738 *
Steven Thomas6d88a482019-12-02 22:00:47 -0800739 * Available since API level 30.
740 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100741void ASurfaceTransaction_setFrameRate(ASurfaceTransaction* _Nonnull transaction,
742 ASurfaceControl* _Nonnull surface_control, float frameRate,
Steven Thomas62a4cf82020-01-31 12:04:03 -0800743 int8_t compatibility) __INTRODUCED_IN(30);
Steven Thomas6d88a482019-12-02 22:00:47 -0800744
Marin Shalamanov46084422020-10-13 12:33:42 +0200745/**
746 * Sets the intended frame rate for \a surface_control.
747 *
748 * On devices that are capable of running the display at different refresh rates, the system may
749 * choose a display refresh rate to better match this surface's frame rate. Usage of this API won't
750 * directly affect the application's frame production pipeline. However, because the system may
751 * change the display refresh rate, calls to this function may result in changes to Choreographer
752 * callback timings, and changes to the time interval at which the system releases buffers back to
753 * the application.
754 *
Marin Shalamanova308b9d2021-05-05 13:43:28 +0200755 * You can register for changes in the refresh rate using
756 * \a AChoreographer_registerRefreshRateCallback.
757 *
Kriti Dang4113fc12022-08-26 16:30:37 +0200758 * See ASurfaceTransaction_clearFrameRate().
759 *
Marin Shalamanov46084422020-10-13 12:33:42 +0200760 * \param frameRate is the intended frame rate of this surface, in frames per second. 0 is a special
761 * value that indicates the app will accept the system's choice for the display frame rate, which is
762 * the default behavior if this function isn't called. The frameRate param does <em>not</em> need to
763 * be a valid refresh rate for this device's display - e.g., it's fine to pass 30fps to a device
764 * that can only run the display at 60fps.
765 *
766 * \param compatibility The frame rate compatibility of this surface. The compatibility value may
767 * influence the system's choice of display frame rate. To specify a compatibility use the
Marin Shalamanov293ac2c2021-04-26 14:13:04 +0200768 * ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_* enum. This parameter is ignored when frameRate is 0.
Marin Shalamanov46084422020-10-13 12:33:42 +0200769 *
Marin Shalamanov293ac2c2021-04-26 14:13:04 +0200770 * \param changeFrameRateStrategy Whether display refresh rate transitions caused by this
771 * surface should be seamless. A seamless transition is one that doesn't have any visual
772 * interruptions, such as a black screen for a second or two. See the
773 * ANATIVEWINDOW_CHANGE_FRAME_RATE_* values. This parameter is ignored when frameRate is 0.
Marin Shalamanov46084422020-10-13 12:33:42 +0200774 *
775 * Available since API level 31.
776 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100777void ASurfaceTransaction_setFrameRateWithChangeStrategy(ASurfaceTransaction* _Nonnull transaction,
778 ASurfaceControl* _Nonnull surface_control,
779 float frameRate, int8_t compatibility,
780 int8_t changeFrameRateStrategy)
781 __INTRODUCED_IN(31);
Marin Shalamanov46084422020-10-13 12:33:42 +0200782
Robert Carrf08168d2021-03-24 15:49:18 -0700783/**
Kriti Dang4113fc12022-08-26 16:30:37 +0200784 * Clears the frame rate which is set for \a surface_control.
785 *
786 * This is equivalent to calling
787 * ASurfaceTransaction_setFrameRateWithChangeStrategy(
788 * transaction, 0, compatibility, changeFrameRateStrategy).
789 *
790 * Usage of this API won't directly affect the application's frame production pipeline. However,
791 * because the system may change the display refresh rate, calls to this function may result in
792 * changes to Choreographer callback timings, and changes to the time interval at which the system
793 * releases buffers back to the application.
794 *
795 * See ASurfaceTransaction_setFrameRateWithChangeStrategy()
796 *
797 * You can register for changes in the refresh rate using
798 * \a AChoreographer_registerRefreshRateCallback.
799 *
800 * See ASurfaceTransaction_setFrameRateWithChangeStrategy().
801 *
802 * Available since API level 34.
803 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100804void ASurfaceTransaction_clearFrameRate(ASurfaceTransaction* _Nonnull transaction,
805 ASurfaceControl* _Nonnull surface_control)
Kriti Dang4113fc12022-08-26 16:30:37 +0200806 __INTRODUCED_IN(__ANDROID_API_U__);
807
808/**
Robert Carrf08168d2021-03-24 15:49:18 -0700809 * Indicate whether to enable backpressure for buffer submission to a given SurfaceControl.
810 *
811 * By default backpressure is disabled, which means submitting a buffer prior to receiving
812 * a callback for the previous buffer could lead to that buffer being "dropped". In cases
813 * where you are selecting for latency, this may be a desirable behavior! We had a new buffer
814 * ready, why shouldn't we show it?
815 *
816 * When back pressure is enabled, each buffer will be required to be presented
817 * before it is released and the callback delivered
818 * (absent the whole SurfaceControl being removed).
819 *
820 * Most apps are likely to have some sort of backpressure internally, e.g. you are
821 * waiting on the callback from frame N-2 before starting frame N. In high refresh
822 * rate scenarios there may not be much time between SurfaceFlinger completing frame
823 * N-1 (and therefore releasing buffer N-2) and beginning frame N. This means
824 * your app may not have enough time to respond in the callback. Using this flag
825 * and pushing buffers earlier for server side queuing will be advantageous
826 * in such cases.
827 *
Alec Mouri5a100fa2023-02-24 00:45:29 +0000828 * Available since API level 31.
829 *
Robert Carrf08168d2021-03-24 15:49:18 -0700830 * \param transaction The transaction in which to make the change.
831 * \param surface_control The ASurfaceControl on which to control buffer backpressure behavior.
832 * \param enableBackPressure Whether to enable back pressure.
833 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100834void ASurfaceTransaction_setEnableBackPressure(ASurfaceTransaction* _Nonnull transaction,
835 ASurfaceControl* _Nonnull surface_control,
836 bool enableBackPressure) __INTRODUCED_IN(31);
Robert Carrf08168d2021-03-24 15:49:18 -0700837
Rachel Leeed511ef2021-10-11 15:09:51 -0700838/**
Rachel Leee81bf262022-08-23 14:37:59 -0700839 * Sets the frame timeline to use in SurfaceFlinger.
Rachel Lee1fb2ddc2022-01-12 14:33:07 -0800840 *
Rachel Leee81bf262022-08-23 14:37:59 -0700841 * A frame timeline should be chosen based on the frame deadline the application
842 * can meet when rendering the frame and the application's desired presentation time.
843 * By setting a frame timeline, SurfaceFlinger tries to present the frame at the corresponding
844 * expected presentation time.
Rachel Lee1fb2ddc2022-01-12 14:33:07 -0800845 *
846 * To receive frame timelines, a callback must be posted to Choreographer using
Rachel Leee81bf262022-08-23 14:37:59 -0700847 * AChoreographer_postVsyncCallback(). The \c vsyncId can then be extracted from the
Rachel Lee1fb2ddc2022-01-12 14:33:07 -0800848 * callback payload using AChoreographerFrameCallbackData_getFrameTimelineVsyncId().
Rachel Leeed511ef2021-10-11 15:09:51 -0700849 *
Alec Mouri5a100fa2023-02-24 00:45:29 +0000850 * Available since API level 33.
851 *
Rachel Leee81bf262022-08-23 14:37:59 -0700852 * \param vsyncId The vsync ID received from AChoreographer, setting the frame's presentation target
853 * to the corresponding expected presentation time and deadline from the frame to be rendered. A
854 * stale or invalid value will be ignored.
Rachel Leeed511ef2021-10-11 15:09:51 -0700855 */
Marijn Suijtenc2440ff2024-01-19 00:44:53 +0100856void ASurfaceTransaction_setFrameTimeline(ASurfaceTransaction* _Nonnull transaction,
Rachel Lee1fb2ddc2022-01-12 14:33:07 -0800857 AVsyncId vsyncId) __INTRODUCED_IN(33);
Rachel Leeed511ef2021-10-11 15:09:51 -0700858
Marissa Wall53da7e32018-09-25 15:59:38 -0700859__END_DECLS
860
861#endif // ANDROID_SURFACE_CONTROL_H
Marin Shalamanov574c58d2021-03-18 15:10:02 +0100862
863/** @} */