blob: a6cf353a24856d8b68867a5845f75a0822a7c56b [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
Marissa Wall3ff826c2019-02-07 11:58:25 -080031#include <android/data_space.h>
Marissa Wall53da7e32018-09-25 15:59:38 -070032#include <android/hardware_buffer.h>
Marissa Wall80d94ad2019-01-18 16:04:36 -080033#include <android/hdr_metadata.h>
Marissa Wall53da7e32018-09-25 15:59:38 -070034#include <android/native_window.h>
35
36__BEGIN_DECLS
37
Marissa Wall53da7e32018-09-25 15:59:38 -070038struct ASurfaceControl;
39
40/**
Elliott Hughes733bf992019-03-08 11:25:28 -080041 * The SurfaceControl API can be used to provide a hierarchy of surfaces for
Marissa Wall53da7e32018-09-25 15:59:38 -070042 * composition to the system compositor. ASurfaceControl represents a content node in
Elliott Hughes733bf992019-03-08 11:25:28 -080043 * this hierarchy.
Marissa Wall53da7e32018-09-25 15:59:38 -070044 */
45typedef struct ASurfaceControl ASurfaceControl;
46
Elliott Hughes3d70e532019-10-29 08:59:39 -070047/**
Marissa Wall53da7e32018-09-25 15:59:38 -070048 * Creates an ASurfaceControl with either ANativeWindow or an ASurfaceControl as its parent.
Marin Shalamanov110c6bc2020-11-16 17:57:59 +010049 * \a debug_name is a debug name associated with this surface. It can be used to
Marissa Wall53da7e32018-09-25 15:59:38 -070050 * identify this surface in the SurfaceFlinger's layer tree. It must not be
51 * null.
52 *
53 * The caller takes ownership of the ASurfaceControl returned and must release it
54 * using ASurfaceControl_release below.
Elliott Hughes3d70e532019-10-29 08:59:39 -070055 *
56 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -070057 */
58ASurfaceControl* ASurfaceControl_createFromWindow(ANativeWindow* parent, const char* debug_name)
59 __INTRODUCED_IN(29);
60
Elliott Hughes3d70e532019-10-29 08:59:39 -070061/**
62 * See ASurfaceControl_createFromWindow.
63 *
64 * Available since API level 29.
65 */
Marissa Wall53da7e32018-09-25 15:59:38 -070066ASurfaceControl* ASurfaceControl_create(ASurfaceControl* parent, const char* debug_name)
67 __INTRODUCED_IN(29);
68
69/**
Huihong Luodb5778e2021-01-28 14:48:59 -080070 * Acquires a reference on the given ASurfaceControl object. This prevents the object
71 * from being deleted until the reference is removed.
72 *
73 * To release the reference, use the ASurfaceControl_release function.
74 *
75 * Available since API level 31.
76 */
77void ASurfaceControl_acquire(ASurfaceControl* surface_control) __INTRODUCED_IN(31);
78
79/**
80 * Removes a reference that was previously acquired with one of the following functions:
81 * ASurfaceControl_createFromWindow
82 * ASurfaceControl_create
83 * ANativeWindow_acquire
84 * The surface and its children may remain on display as long as their parent remains on display.
Elliott Hughes3d70e532019-10-29 08:59:39 -070085 *
86 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -070087 */
Marissa Wall80d94ad2019-01-18 16:04:36 -080088void ASurfaceControl_release(ASurfaceControl* surface_control) __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -070089
90struct ASurfaceTransaction;
91
92/**
93 * ASurfaceTransaction is a collection of updates to the surface tree that must
94 * be applied atomically.
95 */
96typedef struct ASurfaceTransaction ASurfaceTransaction;
97
98/**
99 * The caller takes ownership of the transaction and must release it using
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100100 * ASurfaceTransaction_delete() below.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700101 *
102 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700103 */
104ASurfaceTransaction* ASurfaceTransaction_create() __INTRODUCED_IN(29);
105
106/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100107 * Destroys the \a transaction object.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700108 *
109 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700110 */
111void ASurfaceTransaction_delete(ASurfaceTransaction* transaction) __INTRODUCED_IN(29);
112
113/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100114 * Applies the updates accumulated in \a transaction.
Marissa Wall53da7e32018-09-25 15:59:38 -0700115 *
116 * Note that the transaction is guaranteed to be applied atomically. The
117 * transactions which are applied on the same thread are also guaranteed to be
118 * applied in order.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700119 *
120 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700121 */
122void ASurfaceTransaction_apply(ASurfaceTransaction* transaction) __INTRODUCED_IN(29);
123
124/**
Marissa Wall80d94ad2019-01-18 16:04:36 -0800125 * An opaque handle returned during a callback that can be used to query general stats and stats for
126 * surfaces which were either removed or for which buffers were updated after this transaction was
127 * applied.
128 */
129typedef struct ASurfaceTransactionStats ASurfaceTransactionStats;
130
131/**
Marissa Wall53da7e32018-09-25 15:59:38 -0700132 * Since the transactions are applied asynchronously, the
133 * ASurfaceTransaction_OnComplete callback can be used to be notified when a frame
134 * including the updates in a transaction was presented.
135 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100136 * \param context Optional context provided by the client that is passed into
Marissa Wall53da7e32018-09-25 15:59:38 -0700137 * the callback.
Marissa Wall53da7e32018-09-25 15:59:38 -0700138 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100139 * \param stats Opaque handle that can be passed to ASurfaceTransactionStats functions to query
Elliott Hughes733bf992019-03-08 11:25:28 -0800140 * information about the transaction. The handle is only valid during the callback.
Marissa Wall53da7e32018-09-25 15:59:38 -0700141 *
142 * THREADING
143 * The transaction completed callback can be invoked on any thread.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700144 *
145 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700146 */
Marissa Wall80d94ad2019-01-18 16:04:36 -0800147typedef void (*ASurfaceTransaction_OnComplete)(void* context, ASurfaceTransactionStats* stats)
148 __INTRODUCED_IN(29);
149
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700150
151/**
152 * The ASurfaceTransaction_OnCommit callback is invoked when transaction is applied and the updates
153 * are ready to be presented. This callback will be invoked before the
154 * ASurfaceTransaction_OnComplete callback.
155 *
156 * \param context Optional context provided by the client that is passed into the callback.
157 *
158 * \param stats Opaque handle that can be passed to ASurfaceTransactionStats functions to query
159 * information about the transaction. The handle is only valid during the callback.
160 * Present and release fences are not available for this callback. Querying them using
161 * ASurfaceTransactionStats_getPresentFenceFd and ASurfaceTransactionStats_getPreviousReleaseFenceFd
162 * will result in failure.
163 *
164 * THREADING
165 * The transaction committed callback can be invoked on any thread.
166 *
167 * Available since API level 31.
168 */
169typedef void (*ASurfaceTransaction_OnCommit)(void* context, ASurfaceTransactionStats* stats)
170 __INTRODUCED_IN(31);
171
Marissa Wall80d94ad2019-01-18 16:04:36 -0800172/**
173 * Returns the timestamp of when the frame was latched by the framework. Once a frame is
174 * latched by the framework, it is presented at the following hardware vsync.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700175 *
176 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800177 */
178int64_t ASurfaceTransactionStats_getLatchTime(ASurfaceTransactionStats* surface_transaction_stats)
179 __INTRODUCED_IN(29);
180
181/**
182 * Returns a sync fence that signals when the transaction has been presented.
183 * The recipient of the callback takes ownership of the fence and is responsible for closing
Marissa Wall183c44c2019-04-08 12:58:50 -0700184 * it. If a device does not support present fences, a -1 will be returned.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700185 *
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700186 * This query is not valid for ASurfaceTransaction_OnCommit callback.
187 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700188 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800189 */
190int ASurfaceTransactionStats_getPresentFenceFd(ASurfaceTransactionStats* surface_transaction_stats)
191 __INTRODUCED_IN(29);
192
193/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100194 * \a outASurfaceControls returns an array of ASurfaceControl pointers that were updated during the
Marissa Wall80d94ad2019-01-18 16:04:36 -0800195 * transaction. Stats for the surfaces can be queried through ASurfaceTransactionStats functions.
196 * When the client is done using the array, it must release it by calling
197 * ASurfaceTransactionStats_releaseASurfaceControls.
198 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700199 * Available since API level 29.
200 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100201 * \a outASurfaceControlsSize returns the size of the ASurfaceControls array.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800202 */
203void ASurfaceTransactionStats_getASurfaceControls(ASurfaceTransactionStats* surface_transaction_stats,
204 ASurfaceControl*** outASurfaceControls,
205 size_t* outASurfaceControlsSize)
206 __INTRODUCED_IN(29);
207/**
208 * Releases the array of ASurfaceControls that were returned by
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100209 * ASurfaceTransactionStats_getASurfaceControls().
Elliott Hughes3d70e532019-10-29 08:59:39 -0700210 *
211 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800212 */
213void ASurfaceTransactionStats_releaseASurfaceControls(ASurfaceControl** surface_controls)
214 __INTRODUCED_IN(29);
215
216/**
217 * Returns the timestamp of when the CURRENT buffer was acquired. A buffer is considered
218 * acquired when its acquire_fence_fd has signaled. A buffer cannot be latched or presented until
219 * it is acquired. If no acquire_fence_fd was provided, this timestamp will be set to -1.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700220 *
221 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800222 */
223int64_t ASurfaceTransactionStats_getAcquireTime(ASurfaceTransactionStats* surface_transaction_stats,
224 ASurfaceControl* surface_control)
225 __INTRODUCED_IN(29);
226
227/**
228 * The returns the fence used to signal the release of the PREVIOUS buffer set on
229 * this surface. If this fence is valid (>=0), the PREVIOUS buffer has not yet been released and the
230 * fence will signal when the PREVIOUS buffer has been released. If the fence is -1 , the PREVIOUS
231 * buffer is already released. The recipient of the callback takes ownership of the
232 * previousReleaseFenceFd and is responsible for closing it.
233 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100234 * Each time a buffer is set through ASurfaceTransaction_setBuffer() on a transaction
235 * which is applied, the framework takes a ref on this buffer. The framework treats the
Marissa Wall80d94ad2019-01-18 16:04:36 -0800236 * addition of a buffer to a particular surface as a unique ref. When a transaction updates or
237 * removes a buffer from a surface, or removes the surface itself from the tree, this ref is
238 * guaranteed to be released in the OnComplete callback for this transaction. The
239 * ASurfaceControlStats provided in the callback for this surface may contain an optional fence
240 * which must be signaled before the ref is assumed to be released.
241 *
242 * The client must ensure that all pending refs on a buffer are released before attempting to reuse
243 * this buffer, otherwise synchronization errors may occur.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700244 *
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700245 * This query is not valid for ASurfaceTransaction_OnCommit callback.
246 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700247 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800248 */
249int ASurfaceTransactionStats_getPreviousReleaseFenceFd(
250 ASurfaceTransactionStats* surface_transaction_stats,
251 ASurfaceControl* surface_control)
252 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700253
254/**
255 * Sets the callback that will be invoked when the updates from this transaction
256 * are presented. For details on the callback semantics and data, see the
257 * comments on the ASurfaceTransaction_OnComplete declaration above.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700258 *
259 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700260 */
261void ASurfaceTransaction_setOnComplete(ASurfaceTransaction* transaction, void* context,
262 ASurfaceTransaction_OnComplete func) __INTRODUCED_IN(29);
263
Marissa Wall80d94ad2019-01-18 16:04:36 -0800264/**
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700265 * Sets the callback that will be invoked when the updates from this transaction are applied and are
266 * ready to be presented. This callback will be invoked before the ASurfaceTransaction_OnComplete
267 * callback.
268 *
269 * Available since API level 31.
270 */
271void ASurfaceTransaction_setOnCommit(ASurfaceTransaction* transaction, void* context,
272 ASurfaceTransaction_OnCommit func) __INTRODUCED_IN(31);
273
274/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100275 * Reparents the \a surface_control from its old parent to the \a new_parent surface control.
276 * Any children of the reparented \a surface_control will remain children of the \a surface_control.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800277 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100278 * 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 -0700279 *
280 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800281 */
282void ASurfaceTransaction_reparent(ASurfaceTransaction* transaction,
283 ASurfaceControl* surface_control, ASurfaceControl* new_parent)
284 __INTRODUCED_IN(29);
285
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100286/**
287 * Parameter for ASurfaceTransaction_setVisibility().
288 */
Marissa Wall53da7e32018-09-25 15:59:38 -0700289enum {
290 ASURFACE_TRANSACTION_VISIBILITY_HIDE = 0,
291 ASURFACE_TRANSACTION_VISIBILITY_SHOW = 1,
292};
293/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100294 * Updates the visibility of \a surface_control. If show is set to
295 * ASURFACE_TRANSACTION_VISIBILITY_HIDE, the \a surface_control and all surfaces in its subtree will
Marissa Wall53da7e32018-09-25 15:59:38 -0700296 * be hidden.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700297 *
298 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700299 */
300void ASurfaceTransaction_setVisibility(ASurfaceTransaction* transaction,
301 ASurfaceControl* surface_control, int8_t visibility)
302 __INTRODUCED_IN(29);
303
304/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100305 * Updates the z order index for \a surface_control. Note that the z order for a surface
Marissa Wall53da7e32018-09-25 15:59:38 -0700306 * is relative to other surfaces which are siblings of this surface. The behavior of sibilings with
307 * the same z order is undefined.
308 *
309 * 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 -0700310 *
311 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700312 */
313void ASurfaceTransaction_setZOrder(ASurfaceTransaction* transaction,
314 ASurfaceControl* surface_control, int32_t z_order)
315 __INTRODUCED_IN(29);
316
317/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100318 * Updates the AHardwareBuffer displayed for \a surface_control. If not -1, the
Marissa Wall80d94ad2019-01-18 16:04:36 -0800319 * acquire_fence_fd should be a file descriptor that is signaled when all pending work
Marissa Wall53da7e32018-09-25 15:59:38 -0700320 * for the buffer is complete and the buffer can be safely read.
321 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100322 * The frameworks takes ownership of the \a acquire_fence_fd passed and is responsible
Marissa Wall53da7e32018-09-25 15:59:38 -0700323 * for closing it.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700324 *
Ady Abraham38605fc2021-03-29 20:33:42 +0000325 * Note that the buffer must be allocated with AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE
326 * as the surface control might be composited using the GPU.
327 *
Elliott Hughes3d70e532019-10-29 08:59:39 -0700328 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700329 */
330void ASurfaceTransaction_setBuffer(ASurfaceTransaction* transaction,
331 ASurfaceControl* surface_control, AHardwareBuffer* buffer,
Marissa Wall80d94ad2019-01-18 16:04:36 -0800332 int acquire_fence_fd = -1) __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700333
334/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100335 * Updates the color for \a surface_control. This will make the background color for the
336 * ASurfaceControl visible in transparent regions of the surface. Colors \a r, \a g,
337 * 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 -0800338 * will be the dataspace and alpha set for the background color layer.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700339 *
340 * Available since API level 29.
Valerie Haued54efa2019-01-11 20:03:14 -0800341 */
342void ASurfaceTransaction_setColor(ASurfaceTransaction* transaction,
343 ASurfaceControl* surface_control, float r, float g, float b,
344 float alpha, ADataSpace dataspace)
345 __INTRODUCED_IN(29);
346
347/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100348 * \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 -0700349 * The surface's source rect is clipped by the bounds of its current buffer. The source rect's width
350 * and height must be > 0.
351 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100352 * \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 -0700353 * source rect bounds are scaled to fit the destination rect. The surface's destination rect is
354 * clipped by the bounds of its parent. The destination rect's width and height must be > 0.
355 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100356 * \param transform The transform applied after the source rect is applied to the buffer. This parameter
Marissa Wall53da7e32018-09-25 15:59:38 -0700357 * should be set to 0 for no transform. To specify a transfrom use the NATIVE_WINDOW_TRANSFORM_*
358 * enum.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700359 *
360 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700361 */
362void ASurfaceTransaction_setGeometry(ASurfaceTransaction* transaction,
363 ASurfaceControl* surface_control, const ARect& source,
364 const ARect& destination, int32_t transform)
365 __INTRODUCED_IN(29);
366
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500367/**
chaviwbe8d0092021-03-29 18:49:46 -0500368 * Bounds the surface and its children to the bounds specified. The crop and buffer size will be
369 * used to determine the bounds of the surface. If no crop is specified and the surface has no
370 * buffer, the surface bounds is only constrained by the size of its parent bounds.
371 *
372 * \param crop The bounds of the crop to apply.
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500373 *
374 * Available since API level 31.
375 */
chaviwbe8d0092021-03-29 18:49:46 -0500376void ASurfaceTransaction_setCrop(ASurfaceTransaction* transaction,
377 ASurfaceControl* surface_control, const ARect& crop)
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500378 __INTRODUCED_IN(31);
379
380/**
chaviwbe8d0092021-03-29 18:49:46 -0500381 * Specifies the position in the parent's space where the surface will be drawn.
382 *
383 * \param x The x position to render the surface.
384 * \param y The y position to render the surface.
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500385 *
386 * Available since API level 31.
387 */
388void ASurfaceTransaction_setPosition(ASurfaceTransaction* transaction,
chaviwbe8d0092021-03-29 18:49:46 -0500389 ASurfaceControl* surface_control, int32_t x, int32_t y)
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500390 __INTRODUCED_IN(31);
391
392/**
393 * \param transform The transform applied after the source rect is applied to the buffer. This
chaviwbe8d0092021-03-29 18:49:46 -0500394 * parameter should be set to 0 for no transform. To specify a transform use the
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500395 * NATIVE_WINDOW_TRANSFORM_* enum.
396 *
397 * Available since API level 31.
398 */
chaviwbe8d0092021-03-29 18:49:46 -0500399void ASurfaceTransaction_setBufferTransform(ASurfaceTransaction* transaction,
Vasiliy Telezhnikovfb3ab5b2021-03-13 20:00:26 -0500400 ASurfaceControl* surface_control, int32_t transform)
401 __INTRODUCED_IN(31);
Marissa Wall53da7e32018-09-25 15:59:38 -0700402
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100403/**
chaviwbe8d0092021-03-29 18:49:46 -0500404 * Sets an x and y scale of a surface with (0, 0) as the centerpoint of the scale.
405 *
406 * \param xScale The scale in the x direction. Must be greater than 0.
407 * \param yScale The scale in the y direction. Must be greater than 0.
408 *
409 * Available since API level 31.
410 */
411void ASurfaceTransaction_setScale(ASurfaceTransaction* transaction,
412 ASurfaceControl* surface_control, float xScale, float yScale)
413 __INTRODUCED_IN(31);
414/**
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100415 * Parameter for ASurfaceTransaction_setBufferTransparency().
416 */
Marissa Wall53da7e32018-09-25 15:59:38 -0700417enum {
418 ASURFACE_TRANSACTION_TRANSPARENCY_TRANSPARENT = 0,
419 ASURFACE_TRANSACTION_TRANSPARENCY_TRANSLUCENT = 1,
420 ASURFACE_TRANSACTION_TRANSPARENCY_OPAQUE = 2,
421};
422/**
423 * Updates whether the content for the buffer associated with this surface is
424 * completely opaque. If true, every pixel of content inside the buffer must be
425 * opaque or visual errors can occur.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700426 *
427 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700428 */
429void ASurfaceTransaction_setBufferTransparency(ASurfaceTransaction* transaction,
Marissa Wall80d94ad2019-01-18 16:04:36 -0800430 ASurfaceControl* surface_control,
431 int8_t transparency)
432 __INTRODUCED_IN(29);
Marissa Wall53da7e32018-09-25 15:59:38 -0700433
434/**
435 * Updates the region for the content on this surface updated in this
436 * transaction. If unspecified, the complete surface is assumed to be damaged.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700437 *
438 * Available since API level 29.
Marissa Wall53da7e32018-09-25 15:59:38 -0700439 */
440void ASurfaceTransaction_setDamageRegion(ASurfaceTransaction* transaction,
441 ASurfaceControl* surface_control, const ARect rects[],
442 uint32_t count) __INTRODUCED_IN(29);
443
Marissa Wall80d94ad2019-01-18 16:04:36 -0800444/**
445 * Specifies a desiredPresentTime for the transaction. The framework will try to present
446 * the transaction at or after the time specified.
447 *
448 * Transactions will not be presented until all of their acquire fences have signaled even if the
449 * app requests an earlier present time.
450 *
451 * If an earlier transaction has a desired present time of x, and a later transaction has a desired
452 * present time that is before x, the later transaction will not preempt the earlier transaction.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700453 *
454 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800455 */
456void ASurfaceTransaction_setDesiredPresentTime(ASurfaceTransaction* transaction,
457 int64_t desiredPresentTime) __INTRODUCED_IN(29);
458
459/**
460 * Sets the alpha for the buffer. It uses a premultiplied blending.
461 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100462 * The \a alpha must be between 0.0 and 1.0.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700463 *
464 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800465 */
466void ASurfaceTransaction_setBufferAlpha(ASurfaceTransaction* transaction,
467 ASurfaceControl* surface_control, float alpha)
468 __INTRODUCED_IN(29);
469
Marissa Wall3ff826c2019-02-07 11:58:25 -0800470/**
471 * Sets the data space of the surface_control's buffers.
472 *
473 * If no data space is set, the surface control defaults to ADATASPACE_SRGB.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700474 *
475 * Available since API level 29.
Marissa Wall3ff826c2019-02-07 11:58:25 -0800476 */
477void ASurfaceTransaction_setBufferDataSpace(ASurfaceTransaction* transaction,
478 ASurfaceControl* surface_control, ADataSpace data_space)
479 __INTRODUCED_IN(29);
480
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100481/**
Marissa Wall80d94ad2019-01-18 16:04:36 -0800482 * SMPTE ST 2086 "Mastering Display Color Volume" static metadata
483 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100484 * When \a metadata is set to null, the framework does not use any smpte2086 metadata when rendering
Marissa Wall80d94ad2019-01-18 16:04:36 -0800485 * the surface's buffer.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700486 *
487 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800488 */
489void ASurfaceTransaction_setHdrMetadata_smpte2086(ASurfaceTransaction* transaction,
490 ASurfaceControl* surface_control,
491 struct AHdrMetadata_smpte2086* metadata)
492 __INTRODUCED_IN(29);
493
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100494/**
Marissa Wall80d94ad2019-01-18 16:04:36 -0800495 * Sets the CTA 861.3 "HDR Static Metadata Extension" static metadata on a surface.
496 *
Marin Shalamanov110c6bc2020-11-16 17:57:59 +0100497 * 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 -0800498 * the surface's buffer.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700499 *
500 * Available since API level 29.
Marissa Wall80d94ad2019-01-18 16:04:36 -0800501 */
502void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* transaction,
503 ASurfaceControl* surface_control,
504 struct AHdrMetadata_cta861_3* metadata)
505 __INTRODUCED_IN(29);
506
Steven Thomas15b6f9c2020-03-26 13:44:28 -0700507/**
Marin Shalamanovc5986772021-03-16 16:09:49 +0100508 * Same as ASurfaceTransaction_setFrameRateWithChangeStrategy(transaction, surface_control,
509 * frameRate, compatibility, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS).
Steven Thomas6d88a482019-12-02 22:00:47 -0800510 *
Marin Shalamanovc5986772021-03-16 16:09:49 +0100511 * See ASurfaceTransaction_setFrameRateWithChangeStrategy().
Steven Thomas62a4cf82020-01-31 12:04:03 -0800512 *
Steven Thomas6d88a482019-12-02 22:00:47 -0800513 * Available since API level 30.
514 */
515void ASurfaceTransaction_setFrameRate(ASurfaceTransaction* transaction,
Steven Thomas62a4cf82020-01-31 12:04:03 -0800516 ASurfaceControl* surface_control, float frameRate,
517 int8_t compatibility) __INTRODUCED_IN(30);
Steven Thomas6d88a482019-12-02 22:00:47 -0800518
Marin Shalamanov46084422020-10-13 12:33:42 +0200519/**
520 * Sets the intended frame rate for \a surface_control.
521 *
522 * On devices that are capable of running the display at different refresh rates, the system may
523 * choose a display refresh rate to better match this surface's frame rate. Usage of this API won't
524 * directly affect the application's frame production pipeline. However, because the system may
525 * change the display refresh rate, calls to this function may result in changes to Choreographer
526 * callback timings, and changes to the time interval at which the system releases buffers back to
527 * the application.
528 *
Marin Shalamanova308b9d2021-05-05 13:43:28 +0200529 * You can register for changes in the refresh rate using
530 * \a AChoreographer_registerRefreshRateCallback.
531 *
Marin Shalamanov46084422020-10-13 12:33:42 +0200532 * \param frameRate is the intended frame rate of this surface, in frames per second. 0 is a special
533 * value that indicates the app will accept the system's choice for the display frame rate, which is
534 * the default behavior if this function isn't called. The frameRate param does <em>not</em> need to
535 * be a valid refresh rate for this device's display - e.g., it's fine to pass 30fps to a device
536 * that can only run the display at 60fps.
537 *
538 * \param compatibility The frame rate compatibility of this surface. The compatibility value may
539 * influence the system's choice of display frame rate. To specify a compatibility use the
540 * ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_* enum.
541 *
Marin Shalamanovc5986772021-03-16 16:09:49 +0100542 * \param changeFrameRateStrategy Whether display refresh rate transitions should be seamless.
543 * A seamless transition is one that doesn't have any visual interruptions, such as a black
544 * screen for a second or two. See the ANATIVEWINDOW_CHANGE_FRAME_RATE_* values.
Marin Shalamanov46084422020-10-13 12:33:42 +0200545 *
546 * Available since API level 31.
547 */
Marin Shalamanovc5986772021-03-16 16:09:49 +0100548void ASurfaceTransaction_setFrameRateWithChangeStrategy(ASurfaceTransaction* transaction,
Marin Shalamanov46084422020-10-13 12:33:42 +0200549 ASurfaceControl* surface_control, float frameRate,
Marin Shalamanovc5986772021-03-16 16:09:49 +0100550 int8_t compatibility, int8_t changeFrameRateStrategy)
Marin Shalamanov46084422020-10-13 12:33:42 +0200551 __INTRODUCED_IN(31);
552
Robert Carrf08168d2021-03-24 15:49:18 -0700553/**
554 * Indicate whether to enable backpressure for buffer submission to a given SurfaceControl.
555 *
556 * By default backpressure is disabled, which means submitting a buffer prior to receiving
557 * a callback for the previous buffer could lead to that buffer being "dropped". In cases
558 * where you are selecting for latency, this may be a desirable behavior! We had a new buffer
559 * ready, why shouldn't we show it?
560 *
561 * When back pressure is enabled, each buffer will be required to be presented
562 * before it is released and the callback delivered
563 * (absent the whole SurfaceControl being removed).
564 *
565 * Most apps are likely to have some sort of backpressure internally, e.g. you are
566 * waiting on the callback from frame N-2 before starting frame N. In high refresh
567 * rate scenarios there may not be much time between SurfaceFlinger completing frame
568 * N-1 (and therefore releasing buffer N-2) and beginning frame N. This means
569 * your app may not have enough time to respond in the callback. Using this flag
570 * and pushing buffers earlier for server side queuing will be advantageous
571 * in such cases.
572 *
573 * \param transaction The transaction in which to make the change.
574 * \param surface_control The ASurfaceControl on which to control buffer backpressure behavior.
575 * \param enableBackPressure Whether to enable back pressure.
576 */
577void ASurfaceTransaction_setEnableBackPressure(ASurfaceTransaction* transaction,
578 ASurfaceControl* surface_control,
579 bool enableBackPressure)
580 __INTRODUCED_IN(31);
581
Marissa Wall53da7e32018-09-25 15:59:38 -0700582__END_DECLS
583
584#endif // ANDROID_SURFACE_CONTROL_H
Marin Shalamanov574c58d2021-03-18 15:10:02 +0100585
586/** @} */