blob: fb1419f0b289473627ddb9c6de33201342c2a810 [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 */
65ASurfaceControl* ASurfaceControl_createFromWindow(ANativeWindow* parent, const char* debug_name)
66 __INTRODUCED_IN(29);
67
Elliott Hughes3d70e532019-10-29 08:59:39 -070068/**
69 * See ASurfaceControl_createFromWindow.
70 *
71 * Available since API level 29.
72 */
Marissa Wall53da7e32018-09-25 15:59:38 -070073ASurfaceControl* ASurfaceControl_create(ASurfaceControl* parent, const char* debug_name)
74 __INTRODUCED_IN(29);
75
76/**
Huihong Luodb5778e2021-01-28 14:48:59 -080077 * Acquires a reference on the given ASurfaceControl object. This prevents the object
78 * from being deleted until the reference is removed.
79 *
80 * To release the reference, use the ASurfaceControl_release function.
81 *
82 * Available since API level 31.
83 */
84void ASurfaceControl_acquire(ASurfaceControl* surface_control) __INTRODUCED_IN(31);
85
86/**
87 * Removes a reference that was previously acquired with one of the following functions:
88 * ASurfaceControl_createFromWindow
89 * ASurfaceControl_create
90 * ANativeWindow_acquire
91 * The surface and its children may remain on display as long as their parent remains on display.
Elliott Hughes3d70e532019-10-29 08:59:39 -070092 *
93 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -070094 */
Marissa Wall80d94ad2019-01-18 16:04:36 -080095void ASurfaceControl_release(ASurfaceControl* surface_control) __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -070096
97struct ASurfaceTransaction;
98
99/**
100 * ASurfaceTransaction is a collection of updates to the surface tree that must
101 * be applied atomically.
102 */
103typedef struct ASurfaceTransaction ASurfaceTransaction;
104
105/**
106 * The caller takes ownership of the transaction and must release it using
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100107 * ASurfaceTransaction_delete() below.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700108 *
109 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700110 */
111ASurfaceTransaction* ASurfaceTransaction_create() __INTRODUCED_IN(29);
112
113/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100114 * Destroys the \a transaction object.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700115 *
116 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700117 */
118void ASurfaceTransaction_delete(ASurfaceTransaction* transaction) __INTRODUCED_IN(29);
119
120/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100121 * Applies the updates accumulated in \a transaction.
Marissa Wall53da7e32018-09-25 15:59:38 -0700122 *
123 * Note that the transaction is guaranteed to be applied atomically. The
124 * transactions which are applied on the same thread are also guaranteed to be
125 * applied in order.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700126 *
127 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700128 */
129void ASurfaceTransaction_apply(ASurfaceTransaction* transaction) __INTRODUCED_IN(29);
130
131/**
Marissa Wall80d94ad2019-01-18 16:04:36 -0800132 * An opaque handle returned during a callback that can be used to query general stats and stats for
133 * surfaces which were either removed or for which buffers were updated after this transaction was
134 * applied.
135 */
136typedef struct ASurfaceTransactionStats ASurfaceTransactionStats;
137
138/**
Marissa Wall53da7e32018-09-25 15:59:38 -0700139 * Since the transactions are applied asynchronously, the
140 * ASurfaceTransaction_OnComplete callback can be used to be notified when a frame
141 * including the updates in a transaction was presented.
142 *
Robert Carr11085792021-05-12 14:35:35 -0700143 * Buffers which are replaced or removed from the scene in the transaction invoking
144 * this callback may be reused after this point.
145 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100146 * \param context Optional context provided by the client that is passed into
Marissa Wall53da7e32018-09-25 15:59:38 -0700147 * the callback.
Marissa Wall53da7e32018-09-25 15:59:38 -0700148 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100149 * \param stats Opaque handle that can be passed to ASurfaceTransactionStats functions to query
Elliott Hughes733bf992019-03-08 11:25:28 -0800150 * information about the transaction. The handle is only valid during the callback.
Marissa Wall53da7e32018-09-25 15:59:38 -0700151 *
152 * THREADING
153 * The transaction completed callback can be invoked on any thread.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700154 *
155 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700156 */
Marissa Wall80d94ad2019-01-18 16:04:36 -0800157typedef void (*ASurfaceTransaction_OnComplete)(void* context, ASurfaceTransactionStats* stats)
158 __INTRODUCED_IN(29);
159
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700160
161/**
162 * The ASurfaceTransaction_OnCommit callback is invoked when transaction is applied and the updates
163 * are ready to be presented. This callback will be invoked before the
164 * ASurfaceTransaction_OnComplete callback.
165 *
Robert Carr11085792021-05-12 14:35:35 -0700166 * This callback does not mean buffers have been released! It simply means that any new
167 * transactions applied will not overwrite the transaction for which we are receiving
168 * a callback and instead will be included in the next frame. If you are trying to avoid
169 * dropping frames (overwriting transactions), and unable to use timestamps (Which provide
170 * a more efficient solution), then this method provides a method to pace your transaction
171 * application.
172 *
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700173 * \param context Optional context provided by the client that is passed into the callback.
174 *
175 * \param stats Opaque handle that can be passed to ASurfaceTransactionStats functions to query
176 * information about the transaction. The handle is only valid during the callback.
177 * Present and release fences are not available for this callback. Querying them using
178 * ASurfaceTransactionStats_getPresentFenceFd and ASurfaceTransactionStats_getPreviousReleaseFenceFd
179 * will result in failure.
180 *
181 * THREADING
182 * The transaction committed callback can be invoked on any thread.
183 *
184 * Available since API level 31.
185 */
186typedef void (*ASurfaceTransaction_OnCommit)(void* context, ASurfaceTransactionStats* stats)
187 __INTRODUCED_IN(31);
188
Marissa Wall80d94ad2019-01-18 16:04:36 -0800189/**
190 * Returns the timestamp of when the frame was latched by the framework. Once a frame is
191 * latched by the framework, it is presented at the following hardware vsync.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700192 *
193 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800194 */
195int64_t ASurfaceTransactionStats_getLatchTime(ASurfaceTransactionStats* surface_transaction_stats)
196 __INTRODUCED_IN(29);
197
198/**
199 * Returns a sync fence that signals when the transaction has been presented.
200 * The recipient of the callback takes ownership of the fence and is responsible for closing
Marissa Wall183c44c2019-04-08 12:58:50 -0700201 * it. If a device does not support present fences, a -1 will be returned.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700202 *
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700203 * This query is not valid for ASurfaceTransaction_OnCommit callback.
204 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700205 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800206 */
207int ASurfaceTransactionStats_getPresentFenceFd(ASurfaceTransactionStats* surface_transaction_stats)
208 __INTRODUCED_IN(29);
209
210/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100211 * \a outASurfaceControls returns an array of ASurfaceControl pointers that were updated during the
Marissa Wall80d94ad2019-01-18 16:04:36 -0800212 * transaction. Stats for the surfaces can be queried through ASurfaceTransactionStats functions.
213 * When the client is done using the array, it must release it by calling
214 * ASurfaceTransactionStats_releaseASurfaceControls.
215 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700216 * Available since API level 29.
217 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100218 * \a outASurfaceControlsSize returns the size of the ASurfaceControls array.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800219 */
220void ASurfaceTransactionStats_getASurfaceControls(ASurfaceTransactionStats* surface_transaction_stats,
221 ASurfaceControl*** outASurfaceControls,
222 size_t* outASurfaceControlsSize)
223 __INTRODUCED_IN(29);
224/**
225 * Releases the array of ASurfaceControls that were returned by
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100226 * ASurfaceTransactionStats_getASurfaceControls().
Elliott Hughes3d70e532019-10-29 08:59:39 -0700227 *
228 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800229 */
230void ASurfaceTransactionStats_releaseASurfaceControls(ASurfaceControl** surface_controls)
231 __INTRODUCED_IN(29);
232
233/**
234 * Returns the timestamp of when the CURRENT buffer was acquired. A buffer is considered
235 * acquired when its acquire_fence_fd has signaled. A buffer cannot be latched or presented until
236 * it is acquired. If no acquire_fence_fd was provided, this timestamp will be set to -1.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700237 *
238 * Available since API level 29.
Chavi Weingartenfed621c2024-03-14 15:46:05 +0000239 *
240 * @deprecated This may return SIGNAL_PENDING because the stats can arrive before the acquire
241 * fence has signaled, depending on internal timing differences. Therefore the caller should
242 * use the acquire fence passed in to setBuffer and query the signal time.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800243 */
244int64_t ASurfaceTransactionStats_getAcquireTime(ASurfaceTransactionStats* surface_transaction_stats,
245 ASurfaceControl* surface_control)
246 __INTRODUCED_IN(29);
247
248/**
249 * The returns the fence used to signal the release of the PREVIOUS buffer set on
250 * this surface. If this fence is valid (>=0), the PREVIOUS buffer has not yet been released and the
251 * fence will signal when the PREVIOUS buffer has been released. If the fence is -1 , the PREVIOUS
252 * buffer is already released. The recipient of the callback takes ownership of the
253 * previousReleaseFenceFd and is responsible for closing it.
254 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100255 * Each time a buffer is set through ASurfaceTransaction_setBuffer() on a transaction
256 * which is applied, the framework takes a ref on this buffer. The framework treats the
Marissa Wall80d94ad2019-01-18 16:04:36 -0800257 * addition of a buffer to a particular surface as a unique ref. When a transaction updates or
258 * removes a buffer from a surface, or removes the surface itself from the tree, this ref is
259 * guaranteed to be released in the OnComplete callback for this transaction. The
260 * ASurfaceControlStats provided in the callback for this surface may contain an optional fence
261 * which must be signaled before the ref is assumed to be released.
262 *
263 * The client must ensure that all pending refs on a buffer are released before attempting to reuse
264 * this buffer, otherwise synchronization errors may occur.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700265 *
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700266 * This query is not valid for ASurfaceTransaction_OnCommit callback.
267 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700268 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800269 */
270int ASurfaceTransactionStats_getPreviousReleaseFenceFd(
271 ASurfaceTransactionStats* surface_transaction_stats,
272 ASurfaceControl* surface_control)
273 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700274
275/**
276 * Sets the callback that will be invoked when the updates from this transaction
277 * are presented. For details on the callback semantics and data, see the
278 * comments on the ASurfaceTransaction_OnComplete declaration above.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700279 *
280 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700281 */
282void ASurfaceTransaction_setOnComplete(ASurfaceTransaction* transaction, void* context,
283 ASurfaceTransaction_OnComplete func) __INTRODUCED_IN(29);
284
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 */
292void ASurfaceTransaction_setOnCommit(ASurfaceTransaction* transaction, void* context,
293 ASurfaceTransaction_OnCommit func) __INTRODUCED_IN(31);
294
295/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100296 * Reparents the \a surface_control from its old parent to the \a new_parent surface control.
297 * Any children of the reparented \a surface_control will remain children of the \a surface_control.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800298 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100299 * 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 -0700300 *
301 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800302 */
303void ASurfaceTransaction_reparent(ASurfaceTransaction* transaction,
304 ASurfaceControl* surface_control, ASurfaceControl* new_parent)
305 __INTRODUCED_IN(29);
306
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100307/**
308 * Parameter for ASurfaceTransaction_setVisibility().
309 */
Marissa Wall53da7e32018-09-25 15:59:38 -0700310enum {
311 ASURFACE_TRANSACTION_VISIBILITY_HIDE = 0,
312 ASURFACE_TRANSACTION_VISIBILITY_SHOW = 1,
313};
314/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100315 * Updates the visibility of \a surface_control. If show is set to
316 * ASURFACE_TRANSACTION_VISIBILITY_HIDE, the \a surface_control and all surfaces in its subtree will
Marissa Wall53da7e32018-09-25 15:59:38 -0700317 * be hidden.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700318 *
319 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700320 */
321void ASurfaceTransaction_setVisibility(ASurfaceTransaction* transaction,
322 ASurfaceControl* surface_control, int8_t visibility)
323 __INTRODUCED_IN(29);
324
325/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100326 * Updates the z order index for \a surface_control. Note that the z order for a surface
Marissa Wall53da7e32018-09-25 15:59:38 -0700327 * is relative to other surfaces which are siblings of this surface. The behavior of sibilings with
328 * the same z order is undefined.
329 *
330 * 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 -0700331 *
332 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700333 */
334void ASurfaceTransaction_setZOrder(ASurfaceTransaction* transaction,
335 ASurfaceControl* surface_control, int32_t z_order)
336 __INTRODUCED_IN(29);
337
338/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100339 * Updates the AHardwareBuffer displayed for \a surface_control. If not -1, the
Marissa Wall80d94ad2019-01-18 16:04:36 -0800340 * acquire_fence_fd should be a file descriptor that is signaled when all pending work
Marissa Wall53da7e32018-09-25 15:59:38 -0700341 * for the buffer is complete and the buffer can be safely read.
342 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100343 * The frameworks takes ownership of the \a acquire_fence_fd passed and is responsible
Marissa Wall53da7e32018-09-25 15:59:38 -0700344 * for closing it.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700345 *
Ady Abraham38605fc2021-03-29 20:33:42 +0000346 * Note that the buffer must be allocated with AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE
347 * as the surface control might be composited using the GPU.
348 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700349 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700350 */
351void ASurfaceTransaction_setBuffer(ASurfaceTransaction* transaction,
352 ASurfaceControl* surface_control, AHardwareBuffer* buffer,
Dan Albertc6278e82024-02-23 00:03:40 +0000353 int acquire_fence_fd) __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700354
355/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100356 * Updates the color for \a surface_control. This will make the background color for the
357 * ASurfaceControl visible in transparent regions of the surface. Colors \a r, \a g,
358 * 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 -0800359 * will be the dataspace and alpha set for the background color layer.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700360 *
361 * Available since API level 29.
Valerie Haued54efa2019-01-11 20:03:14 -0800362 */
363void ASurfaceTransaction_setColor(ASurfaceTransaction* transaction,
364 ASurfaceControl* surface_control, float r, float g, float b,
365 float alpha, ADataSpace dataspace)
366 __INTRODUCED_IN(29);
367
368/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100369 * \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 -0700370 * The surface's source rect is clipped by the bounds of its current buffer. The source rect's width
371 * and height must be > 0.
372 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100373 * \param destination Specifies the rect in the parent's space where this surface will be drawn. The post
Marissa Wall53da7e32018-09-25 15:59:38 -0700374 * source rect bounds are scaled to fit the destination rect. The surface's destination rect is
375 * clipped by the bounds of its parent. The destination rect's width and height must be > 0.
376 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100377 * \param transform The transform applied after the source rect is applied to the buffer. This parameter
Marissa Wall53da7e32018-09-25 15:59:38 -0700378 * should be set to 0 for no transform. To specify a transfrom use the NATIVE_WINDOW_TRANSFORM_*
379 * enum.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700380 *
381 * Available since API level 29.
chaviw1f5e7402021-04-29 09:15:20 -0500382 *
383 * @deprecated Use setCrop, setPosition, setBufferTransform, and setScale instead. Those functions
384 * provide well defined behavior and allows for more control by the apps. It also allows the caller
385 * to set different properties at different times, instead of having to specify all the desired
386 * properties at once.
Marissa Wall53da7e32018-09-25 15:59:38 -0700387 */
388void ASurfaceTransaction_setGeometry(ASurfaceTransaction* transaction,
389 ASurfaceControl* surface_control, const ARect& source,
390 const ARect& destination, int32_t transform)
391 __INTRODUCED_IN(29);
392
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500393/**
chaviwbe8d0092021-03-29 18:49:46 -0500394 * Bounds the surface and its children to the bounds specified. The crop and buffer size will be
395 * used to determine the bounds of the surface. If no crop is specified and the surface has no
396 * buffer, the surface bounds is only constrained by the size of its parent bounds.
397 *
398 * \param crop The bounds of the crop to apply.
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500399 *
400 * Available since API level 31.
401 */
chaviwbe8d0092021-03-29 18:49:46 -0500402void ASurfaceTransaction_setCrop(ASurfaceTransaction* transaction,
403 ASurfaceControl* surface_control, const ARect& crop)
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500404 __INTRODUCED_IN(31);
405
406/**
chaviwbe8d0092021-03-29 18:49:46 -0500407 * Specifies the position in the parent's space where the surface will be drawn.
408 *
409 * \param x The x position to render the surface.
410 * \param y The y position to render the surface.
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500411 *
412 * Available since API level 31.
413 */
414void ASurfaceTransaction_setPosition(ASurfaceTransaction* transaction,
chaviwbe8d0092021-03-29 18:49:46 -0500415 ASurfaceControl* surface_control, int32_t x, int32_t y)
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500416 __INTRODUCED_IN(31);
417
418/**
419 * \param transform The transform applied after the source rect is applied to the buffer. This
chaviwbe8d0092021-03-29 18:49:46 -0500420 * parameter should be set to 0 for no transform. To specify a transform use the
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500421 * NATIVE_WINDOW_TRANSFORM_* enum.
422 *
423 * Available since API level 31.
424 */
chaviwbe8d0092021-03-29 18:49:46 -0500425void ASurfaceTransaction_setBufferTransform(ASurfaceTransaction* transaction,
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500426 ASurfaceControl* surface_control, int32_t transform)
427 __INTRODUCED_IN(31);
Marissa Wall53da7e32018-09-25 15:59:38 -0700428
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100429/**
chaviwbe8d0092021-03-29 18:49:46 -0500430 * Sets an x and y scale of a surface with (0, 0) as the centerpoint of the scale.
431 *
432 * \param xScale The scale in the x direction. Must be greater than 0.
433 * \param yScale The scale in the y direction. Must be greater than 0.
434 *
435 * Available since API level 31.
436 */
437void ASurfaceTransaction_setScale(ASurfaceTransaction* transaction,
438 ASurfaceControl* surface_control, float xScale, float yScale)
439 __INTRODUCED_IN(31);
440/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100441 * Parameter for ASurfaceTransaction_setBufferTransparency().
442 */
Marissa Wall53da7e32018-09-25 15:59:38 -0700443enum {
444 ASURFACE_TRANSACTION_TRANSPARENCY_TRANSPARENT = 0,
445 ASURFACE_TRANSACTION_TRANSPARENCY_TRANSLUCENT = 1,
446 ASURFACE_TRANSACTION_TRANSPARENCY_OPAQUE = 2,
447};
448/**
449 * Updates whether the content for the buffer associated with this surface is
450 * completely opaque. If true, every pixel of content inside the buffer must be
451 * opaque or visual errors can occur.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700452 *
453 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700454 */
455void ASurfaceTransaction_setBufferTransparency(ASurfaceTransaction* transaction,
Marissa Wall80d94ad2019-01-18 16:04:36 -0800456 ASurfaceControl* surface_control,
457 int8_t transparency)
458 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700459
460/**
461 * Updates the region for the content on this surface updated in this
462 * transaction. If unspecified, the complete surface is assumed to be damaged.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700463 *
464 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700465 */
466void ASurfaceTransaction_setDamageRegion(ASurfaceTransaction* transaction,
467 ASurfaceControl* surface_control, const ARect rects[],
468 uint32_t count) __INTRODUCED_IN(29);
469
Marissa Wall80d94ad2019-01-18 16:04:36 -0800470/**
471 * Specifies a desiredPresentTime for the transaction. The framework will try to present
472 * the transaction at or after the time specified.
473 *
474 * Transactions will not be presented until all of their acquire fences have signaled even if the
475 * app requests an earlier present time.
476 *
477 * If an earlier transaction has a desired present time of x, and a later transaction has a desired
478 * present time that is before x, the later transaction will not preempt the earlier transaction.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700479 *
480 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800481 */
482void ASurfaceTransaction_setDesiredPresentTime(ASurfaceTransaction* transaction,
483 int64_t desiredPresentTime) __INTRODUCED_IN(29);
484
485/**
486 * Sets the alpha for the buffer. It uses a premultiplied blending.
487 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100488 * The \a alpha must be between 0.0 and 1.0.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700489 *
490 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800491 */
492void ASurfaceTransaction_setBufferAlpha(ASurfaceTransaction* transaction,
493 ASurfaceControl* surface_control, float alpha)
494 __INTRODUCED_IN(29);
495
Marissa Wall3ff826c2019-02-07 11:58:25 -0800496/**
497 * Sets the data space of the surface_control's buffers.
498 *
499 * If no data space is set, the surface control defaults to ADATASPACE_SRGB.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700500 *
501 * Available since API level 29.
Marissa Wall3ff826c2019-02-07 11:58:25 -0800502 */
503void ASurfaceTransaction_setBufferDataSpace(ASurfaceTransaction* transaction,
504 ASurfaceControl* surface_control, ADataSpace data_space)
505 __INTRODUCED_IN(29);
506
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100507/**
Marissa Wall80d94ad2019-01-18 16:04:36 -0800508 * SMPTE ST 2086 "Mastering Display Color Volume" static metadata
509 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100510 * When \a metadata is set to null, the framework does not use any smpte2086 metadata when rendering
Marissa Wall80d94ad2019-01-18 16:04:36 -0800511 * the surface's buffer.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700512 *
513 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800514 */
515void ASurfaceTransaction_setHdrMetadata_smpte2086(ASurfaceTransaction* transaction,
516 ASurfaceControl* surface_control,
517 struct AHdrMetadata_smpte2086* metadata)
518 __INTRODUCED_IN(29);
519
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100520/**
Marissa Wall80d94ad2019-01-18 16:04:36 -0800521 * Sets the CTA 861.3 "HDR Static Metadata Extension" static metadata on a surface.
522 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100523 * 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 -0800524 * the surface's buffer.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700525 *
526 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800527 */
528void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* transaction,
529 ASurfaceControl* surface_control,
530 struct AHdrMetadata_cta861_3* metadata)
531 __INTRODUCED_IN(29);
532
Steven Thomas15b6f9c2020-03-26 13:44:28 -0700533/**
John Reckfeec2c62023-02-13 10:19:08 -0500534 * Sets the desired extended range brightness for the layer. This only applies for layers whose
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000535 * dataspace has RANGE_EXTENDED set on it. See: ASurfaceTransaction_setDesiredHdrHeadroom, prefer
536 * using this API for formats that encode an HDR/SDR ratio as part of generating the buffer.
Alec Mouri5a100fa2023-02-24 00:45:29 +0000537 *
John Reckfeec2c62023-02-13 10:19:08 -0500538 * @param surface_control The layer whose extended range brightness is being specified
Alec Mouric1392202024-03-06 19:10:00 +0000539 * @param currentBufferRatio The current HDR/SDR ratio of the current buffer as represented as
John Reckfeec2c62023-02-13 10:19:08 -0500540 * peakHdrBrightnessInNits / targetSdrWhitePointInNits. For example if the
541 * buffer was rendered with a target SDR whitepoint of 100nits and a max
542 * display brightness of 200nits, this should be set to 2.0f.
543 *
544 * Default value is 1.0f.
545 *
546 * Transfer functions that encode their own brightness ranges, such as
547 * HLG or PQ, should also set this to 1.0f and instead communicate
548 * extended content brightness information via metadata such as CTA861_3
549 * or SMPTE2086.
550 *
551 * Must be finite && >= 1.0f
552 *
Alec Mouric1392202024-03-06 19:10:00 +0000553 * @param desiredRatio The desired HDR/SDR ratio as represented as peakHdrBrightnessInNits /
John Reckfeec2c62023-02-13 10:19:08 -0500554 * targetSdrWhitePointInNits. This can be used to communicate the max desired
555 * brightness range. This is similar to the "max luminance" value in other
556 * HDR metadata formats, but represented as a ratio of the target SDR whitepoint
557 * to the max display brightness. The system may not be able to, or may choose
558 * not to, deliver the requested range.
559 *
John Reck1fb63cc2023-04-19 14:39:11 -0400560 * While requesting a large desired ratio will result in the most
561 * dynamic range, voluntarily reducing the requested range can help
562 * improve battery life as well as can improve quality by ensuring
563 * greater bit depth is allocated to the luminance range in use.
564 *
565 * Default value is 1.0f and indicates that extended range brightness
566 * is not being used, so the resulting SDR or HDR behavior will be
567 * determined entirely by the dataspace being used (ie, typically SDR
568 * however PQ or HLG transfer functions will still result in HDR)
John Reckfeec2c62023-02-13 10:19:08 -0500569 *
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000570 * When called after ASurfaceTransaction_setDesiredHdrHeadroom, the
571 * desiredRatio will override the desiredHeadroom provided by
572 * ASurfaceTransaction_setDesiredHdrHeadroom. Conversely, when called before
573 * ASurfaceTransaction_setDesiredHdrHeadroom, the desiredHeadroom provided by
574 *. ASurfaceTransaction_setDesiredHdrHeadroom will override the desiredRatio.
575 *
John Reckfeec2c62023-02-13 10:19:08 -0500576 * Must be finite && >= 1.0f
John Reck8a5e2f92023-03-16 14:27:48 -0400577 *
578 * Available since API level 34.
John Reckfeec2c62023-02-13 10:19:08 -0500579 */
580void ASurfaceTransaction_setExtendedRangeBrightness(ASurfaceTransaction* transaction,
581 ASurfaceControl* surface_control,
582 float currentBufferRatio,
583 float desiredRatio) __INTRODUCED_IN(__ANDROID_API_U__);
584
585/**
Alec Mouric1392202024-03-06 19:10:00 +0000586 * Sets the desired HDR headroom for the layer. See: ASurfaceTransaction_setExtendedRangeBrightness,
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000587 * prefer using this API for formats that conform to HDR standards like HLG or HDR10, that do not
588 * communicate a HDR/SDR ratio as part of generating the buffer.
589 *
Alec Mouric1392202024-03-06 19:10:00 +0000590 * @param surface_control The layer whose desired HDR headroom is being specified
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000591 *
Alec Mouric1392202024-03-06 19:10:00 +0000592 * @param desiredHeadroom The desired HDR/SDR ratio as represented as peakHdrBrightnessInNits /
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000593 * targetSdrWhitePointInNits. This can be used to communicate the max
594 * desired brightness range of the panel. The system may not be able to, or
595 * may choose not to, deliver the requested range.
596 *
597 * 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 0.0f and indicates that the system will choose the best
603 * headroom for this surface control's content. Typically, this means that
604 * HLG/PQ encoded content will be displayed with some HDR headroom greater
605 * than 1.0.
606 *
607 * When called after ASurfaceTransaction_setExtendedRangeBrightness, the
608 * desiredHeadroom will override the desiredRatio provided by
609 * ASurfaceTransaction_setExtendedRangeBrightness. Conversely, when called
610 * before ASurfaceTransaction_setExtendedRangeBrightness, the desiredRatio
611 * provided by ASurfaceTransaction_setExtendedRangeBrightness will override
612 * the desiredHeadroom.
613 *
614 * Must be finite && >= 1.0f or 0.0f to indicate there is no desired
615 * headroom.
616 *
617 * Available since API level 35.
618 */
619void ASurfaceTransaction_setDesiredHdrHeadroom(ASurfaceTransaction* transaction,
620 ASurfaceControl* surface_control,
621 float desiredHeadroom)
622 __INTRODUCED_IN(__ANDROID_API_V__);
623
624/**
Marin Shalamanovc5986772021-03-16 16:09:49 +0100625 * Same as ASurfaceTransaction_setFrameRateWithChangeStrategy(transaction, surface_control,
626 * frameRate, compatibility, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS).
Steven Thomas6d88a482019-12-02 22:00:47 -0800627 *
Marin Shalamanovc5986772021-03-16 16:09:49 +0100628 * See ASurfaceTransaction_setFrameRateWithChangeStrategy().
Steven Thomas62a4cf82020-01-31 12:04:03 -0800629 *
Steven Thomas6d88a482019-12-02 22:00:47 -0800630 * Available since API level 30.
631 */
632void ASurfaceTransaction_setFrameRate(ASurfaceTransaction* transaction,
Steven Thomas62a4cf82020-01-31 12:04:03 -0800633 ASurfaceControl* surface_control, float frameRate,
634 int8_t compatibility) __INTRODUCED_IN(30);
Steven Thomas6d88a482019-12-02 22:00:47 -0800635
Marin Shalamanov46084422020-10-13 12:33:42 +0200636/**
637 * Sets the intended frame rate for \a surface_control.
638 *
639 * On devices that are capable of running the display at different refresh rates, the system may
640 * choose a display refresh rate to better match this surface's frame rate. Usage of this API won't
641 * directly affect the application's frame production pipeline. However, because the system may
642 * change the display refresh rate, calls to this function may result in changes to Choreographer
643 * callback timings, and changes to the time interval at which the system releases buffers back to
644 * the application.
645 *
Marin Shalamanova308b9d2021-05-05 13:43:28 +0200646 * You can register for changes in the refresh rate using
647 * \a AChoreographer_registerRefreshRateCallback.
648 *
Kriti Dang4113fc12022-08-26 16:30:37 +0200649 * See ASurfaceTransaction_clearFrameRate().
650 *
Marin Shalamanov46084422020-10-13 12:33:42 +0200651 * \param frameRate is the intended frame rate of this surface, in frames per second. 0 is a special
652 * value that indicates the app will accept the system's choice for the display frame rate, which is
653 * the default behavior if this function isn't called. The frameRate param does <em>not</em> need to
654 * be a valid refresh rate for this device's display - e.g., it's fine to pass 30fps to a device
655 * that can only run the display at 60fps.
656 *
657 * \param compatibility The frame rate compatibility of this surface. The compatibility value may
658 * influence the system's choice of display frame rate. To specify a compatibility use the
Marin Shalamanov293ac2c2021-04-26 14:13:04 +0200659 * ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_* enum. This parameter is ignored when frameRate is 0.
Marin Shalamanov46084422020-10-13 12:33:42 +0200660 *
Marin Shalamanov293ac2c2021-04-26 14:13:04 +0200661 * \param changeFrameRateStrategy Whether display refresh rate transitions caused by this
662 * surface should be seamless. A seamless transition is one that doesn't have any visual
663 * interruptions, such as a black screen for a second or two. See the
664 * ANATIVEWINDOW_CHANGE_FRAME_RATE_* values. This parameter is ignored when frameRate is 0.
Marin Shalamanov46084422020-10-13 12:33:42 +0200665 *
666 * Available since API level 31.
667 */
Marin Shalamanovc5986772021-03-16 16:09:49 +0100668void ASurfaceTransaction_setFrameRateWithChangeStrategy(ASurfaceTransaction* transaction,
Marin Shalamanov46084422020-10-13 12:33:42 +0200669 ASurfaceControl* surface_control, float frameRate,
Marin Shalamanovc5986772021-03-16 16:09:49 +0100670 int8_t compatibility, int8_t changeFrameRateStrategy)
Marin Shalamanov46084422020-10-13 12:33:42 +0200671 __INTRODUCED_IN(31);
672
Robert Carrf08168d2021-03-24 15:49:18 -0700673/**
Kriti Dang4113fc12022-08-26 16:30:37 +0200674 * Clears the frame rate which is set for \a surface_control.
675 *
676 * This is equivalent to calling
677 * ASurfaceTransaction_setFrameRateWithChangeStrategy(
678 * transaction, 0, compatibility, changeFrameRateStrategy).
679 *
680 * Usage of this API won't directly affect the application's frame production pipeline. However,
681 * because the system may change the display refresh rate, calls to this function may result in
682 * changes to Choreographer callback timings, and changes to the time interval at which the system
683 * releases buffers back to the application.
684 *
685 * See ASurfaceTransaction_setFrameRateWithChangeStrategy()
686 *
687 * You can register for changes in the refresh rate using
688 * \a AChoreographer_registerRefreshRateCallback.
689 *
690 * See ASurfaceTransaction_setFrameRateWithChangeStrategy().
691 *
692 * Available since API level 34.
693 */
694void ASurfaceTransaction_clearFrameRate(ASurfaceTransaction* transaction,
695 ASurfaceControl* surface_control)
696 __INTRODUCED_IN(__ANDROID_API_U__);
697
698/**
Robert Carrf08168d2021-03-24 15:49:18 -0700699 * Indicate whether to enable backpressure for buffer submission to a given SurfaceControl.
700 *
701 * By default backpressure is disabled, which means submitting a buffer prior to receiving
702 * a callback for the previous buffer could lead to that buffer being "dropped". In cases
703 * where you are selecting for latency, this may be a desirable behavior! We had a new buffer
704 * ready, why shouldn't we show it?
705 *
706 * When back pressure is enabled, each buffer will be required to be presented
707 * before it is released and the callback delivered
708 * (absent the whole SurfaceControl being removed).
709 *
710 * Most apps are likely to have some sort of backpressure internally, e.g. you are
711 * waiting on the callback from frame N-2 before starting frame N. In high refresh
712 * rate scenarios there may not be much time between SurfaceFlinger completing frame
713 * N-1 (and therefore releasing buffer N-2) and beginning frame N. This means
714 * your app may not have enough time to respond in the callback. Using this flag
715 * and pushing buffers earlier for server side queuing will be advantageous
716 * in such cases.
717 *
Alec Mouri5a100fa2023-02-24 00:45:29 +0000718 * Available since API level 31.
719 *
Robert Carrf08168d2021-03-24 15:49:18 -0700720 * \param transaction The transaction in which to make the change.
721 * \param surface_control The ASurfaceControl on which to control buffer backpressure behavior.
722 * \param enableBackPressure Whether to enable back pressure.
723 */
724void ASurfaceTransaction_setEnableBackPressure(ASurfaceTransaction* transaction,
725 ASurfaceControl* surface_control,
726 bool enableBackPressure)
727 __INTRODUCED_IN(31);
728
Rachel Leeed511ef2021-10-11 15:09:51 -0700729/**
Rachel Leee81bf262022-08-23 14:37:59 -0700730 * Sets the frame timeline to use in SurfaceFlinger.
Rachel Lee1fb2ddc2022-01-12 14:33:07 -0800731 *
Rachel Leee81bf262022-08-23 14:37:59 -0700732 * A frame timeline should be chosen based on the frame deadline the application
733 * can meet when rendering the frame and the application's desired presentation time.
734 * By setting a frame timeline, SurfaceFlinger tries to present the frame at the corresponding
735 * expected presentation time.
Rachel Lee1fb2ddc2022-01-12 14:33:07 -0800736 *
737 * To receive frame timelines, a callback must be posted to Choreographer using
Rachel Leee81bf262022-08-23 14:37:59 -0700738 * AChoreographer_postVsyncCallback(). The \c vsyncId can then be extracted from the
Rachel Lee1fb2ddc2022-01-12 14:33:07 -0800739 * callback payload using AChoreographerFrameCallbackData_getFrameTimelineVsyncId().
Rachel Leeed511ef2021-10-11 15:09:51 -0700740 *
Alec Mouri5a100fa2023-02-24 00:45:29 +0000741 * Available since API level 33.
742 *
Rachel Leee81bf262022-08-23 14:37:59 -0700743 * \param vsyncId The vsync ID received from AChoreographer, setting the frame's presentation target
744 * to the corresponding expected presentation time and deadline from the frame to be rendered. A
745 * stale or invalid value will be ignored.
Rachel Leeed511ef2021-10-11 15:09:51 -0700746 */
747void ASurfaceTransaction_setFrameTimeline(ASurfaceTransaction* transaction,
Rachel Lee1fb2ddc2022-01-12 14:33:07 -0800748 AVsyncId vsyncId) __INTRODUCED_IN(33);
Rachel Leeed511ef2021-10-11 15:09:51 -0700749
Marissa Wall53da7e32018-09-25 15:59:38 -0700750__END_DECLS
751
752#endif // ANDROID_SURFACE_CONTROL_H
Marin Shalamanov574c58d2021-03-18 15:10:02 +0100753
754/** @} */