Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 31 | #include <android/hardware_buffer.h> |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 32 | #include <android/hdr_metadata.h> |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 33 | #include <android/native_window.h> |
| 34 | |
| 35 | __BEGIN_DECLS |
| 36 | |
| 37 | #if __ANDROID_API__ >= 29 |
| 38 | |
| 39 | struct ASurfaceControl; |
| 40 | |
| 41 | /** |
| 42 | * The SurfaceControl API can be used to provide a heirarchy of surfaces for |
| 43 | * composition to the system compositor. ASurfaceControl represents a content node in |
| 44 | * this heirarchy. |
| 45 | */ |
| 46 | typedef struct ASurfaceControl ASurfaceControl; |
| 47 | |
| 48 | /* |
| 49 | * Creates an ASurfaceControl with either ANativeWindow or an ASurfaceControl as its parent. |
| 50 | * |debug_name| is a debug name associated with this surface. It can be used to |
| 51 | * 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. |
| 56 | */ |
| 57 | ASurfaceControl* ASurfaceControl_createFromWindow(ANativeWindow* parent, const char* debug_name) |
| 58 | __INTRODUCED_IN(29); |
| 59 | |
| 60 | ASurfaceControl* ASurfaceControl_create(ASurfaceControl* parent, const char* debug_name) |
| 61 | __INTRODUCED_IN(29); |
| 62 | |
| 63 | /** |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 64 | * Releases the |surface_control| object. After releasing the ASurfaceControl the caller no longer |
| 65 | * has ownership of the AsurfaceControl. The surface and it's children may remain on display as long |
| 66 | * as their parent remains on display. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 67 | */ |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 68 | void ASurfaceControl_release(ASurfaceControl* surface_control) __INTRODUCED_IN(29); |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 69 | |
| 70 | struct ASurfaceTransaction; |
| 71 | |
| 72 | /** |
| 73 | * ASurfaceTransaction is a collection of updates to the surface tree that must |
| 74 | * be applied atomically. |
| 75 | */ |
| 76 | typedef struct ASurfaceTransaction ASurfaceTransaction; |
| 77 | |
| 78 | /** |
| 79 | * The caller takes ownership of the transaction and must release it using |
| 80 | * ASurfaceControl_delete below. |
| 81 | */ |
| 82 | ASurfaceTransaction* ASurfaceTransaction_create() __INTRODUCED_IN(29); |
| 83 | |
| 84 | /** |
| 85 | * Destroys the |transaction| object. |
| 86 | */ |
| 87 | void ASurfaceTransaction_delete(ASurfaceTransaction* transaction) __INTRODUCED_IN(29); |
| 88 | |
| 89 | /** |
| 90 | * Applies the updates accumulated in |transaction|. |
| 91 | * |
| 92 | * Note that the transaction is guaranteed to be applied atomically. The |
| 93 | * transactions which are applied on the same thread are also guaranteed to be |
| 94 | * applied in order. |
| 95 | */ |
| 96 | void ASurfaceTransaction_apply(ASurfaceTransaction* transaction) __INTRODUCED_IN(29); |
| 97 | |
| 98 | /** |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 99 | * An opaque handle returned during a callback that can be used to query general stats and stats for |
| 100 | * surfaces which were either removed or for which buffers were updated after this transaction was |
| 101 | * applied. |
| 102 | */ |
| 103 | typedef struct ASurfaceTransactionStats ASurfaceTransactionStats; |
| 104 | |
| 105 | /** |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 106 | * Since the transactions are applied asynchronously, the |
| 107 | * ASurfaceTransaction_OnComplete callback can be used to be notified when a frame |
| 108 | * including the updates in a transaction was presented. |
| 109 | * |
| 110 | * |context| is the optional context provided by the client that is passed into |
| 111 | * the callback. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 112 | * |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 113 | * |stats| is an opaque handle that can be passed to ASurfaceTransactionStats functions to query |
| 114 | * information about the transaction. The handle is only valid during the the callback. |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 115 | * |
| 116 | * THREADING |
| 117 | * The transaction completed callback can be invoked on any thread. |
| 118 | */ |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 119 | typedef void (*ASurfaceTransaction_OnComplete)(void* context, ASurfaceTransactionStats* stats) |
| 120 | __INTRODUCED_IN(29); |
| 121 | |
| 122 | /** |
| 123 | * Returns the timestamp of when the frame was latched by the framework. Once a frame is |
| 124 | * latched by the framework, it is presented at the following hardware vsync. |
| 125 | */ |
| 126 | int64_t ASurfaceTransactionStats_getLatchTime(ASurfaceTransactionStats* surface_transaction_stats) |
| 127 | __INTRODUCED_IN(29); |
| 128 | |
| 129 | /** |
| 130 | * Returns a sync fence that signals when the transaction has been presented. |
| 131 | * The recipient of the callback takes ownership of the fence and is responsible for closing |
| 132 | * it. |
| 133 | */ |
| 134 | int ASurfaceTransactionStats_getPresentFenceFd(ASurfaceTransactionStats* surface_transaction_stats) |
| 135 | __INTRODUCED_IN(29); |
| 136 | |
| 137 | /** |
| 138 | * |outASurfaceControls| returns an array of ASurfaceControl pointers that were updated during the |
| 139 | * transaction. Stats for the surfaces can be queried through ASurfaceTransactionStats functions. |
| 140 | * When the client is done using the array, it must release it by calling |
| 141 | * ASurfaceTransactionStats_releaseASurfaceControls. |
| 142 | * |
| 143 | * |outASurfaceControlsSize| returns the size of the ASurfaceControls array. |
| 144 | */ |
| 145 | void ASurfaceTransactionStats_getASurfaceControls(ASurfaceTransactionStats* surface_transaction_stats, |
| 146 | ASurfaceControl*** outASurfaceControls, |
| 147 | size_t* outASurfaceControlsSize) |
| 148 | __INTRODUCED_IN(29); |
| 149 | /** |
| 150 | * Releases the array of ASurfaceControls that were returned by |
| 151 | * ASurfaceTransactionStats_getASurfaceControls. |
| 152 | */ |
| 153 | void ASurfaceTransactionStats_releaseASurfaceControls(ASurfaceControl** surface_controls) |
| 154 | __INTRODUCED_IN(29); |
| 155 | |
| 156 | /** |
| 157 | * Returns the timestamp of when the CURRENT buffer was acquired. A buffer is considered |
| 158 | * acquired when its acquire_fence_fd has signaled. A buffer cannot be latched or presented until |
| 159 | * it is acquired. If no acquire_fence_fd was provided, this timestamp will be set to -1. |
| 160 | */ |
| 161 | int64_t ASurfaceTransactionStats_getAcquireTime(ASurfaceTransactionStats* surface_transaction_stats, |
| 162 | ASurfaceControl* surface_control) |
| 163 | __INTRODUCED_IN(29); |
| 164 | |
| 165 | /** |
| 166 | * The returns the fence used to signal the release of the PREVIOUS buffer set on |
| 167 | * this surface. If this fence is valid (>=0), the PREVIOUS buffer has not yet been released and the |
| 168 | * fence will signal when the PREVIOUS buffer has been released. If the fence is -1 , the PREVIOUS |
| 169 | * buffer is already released. The recipient of the callback takes ownership of the |
| 170 | * previousReleaseFenceFd and is responsible for closing it. |
| 171 | * |
| 172 | * Each time a buffer is set through ASurfaceTransaction_setBuffer()/_setCachedBuffer() on a |
| 173 | * transaction which is applied, the framework takes a ref on this buffer. The framework treats the |
| 174 | * addition of a buffer to a particular surface as a unique ref. When a transaction updates or |
| 175 | * removes a buffer from a surface, or removes the surface itself from the tree, this ref is |
| 176 | * guaranteed to be released in the OnComplete callback for this transaction. The |
| 177 | * ASurfaceControlStats provided in the callback for this surface may contain an optional fence |
| 178 | * which must be signaled before the ref is assumed to be released. |
| 179 | * |
| 180 | * The client must ensure that all pending refs on a buffer are released before attempting to reuse |
| 181 | * this buffer, otherwise synchronization errors may occur. |
| 182 | */ |
| 183 | int ASurfaceTransactionStats_getPreviousReleaseFenceFd( |
| 184 | ASurfaceTransactionStats* surface_transaction_stats, |
| 185 | ASurfaceControl* surface_control) |
| 186 | __INTRODUCED_IN(29); |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 187 | |
| 188 | /** |
| 189 | * Sets the callback that will be invoked when the updates from this transaction |
| 190 | * are presented. For details on the callback semantics and data, see the |
| 191 | * comments on the ASurfaceTransaction_OnComplete declaration above. |
| 192 | */ |
| 193 | void ASurfaceTransaction_setOnComplete(ASurfaceTransaction* transaction, void* context, |
| 194 | ASurfaceTransaction_OnComplete func) __INTRODUCED_IN(29); |
| 195 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 196 | /** |
| 197 | * Reparents the |surface_control| from its old parent to the |new_parent| surface control. |
| 198 | * Any children of the* reparented |surface_control| will remain children of the |surface_control|. |
| 199 | * |
| 200 | * The |new_parent| can be null. Surface controls with a null parent do not appear on the display. |
| 201 | */ |
| 202 | void ASurfaceTransaction_reparent(ASurfaceTransaction* transaction, |
| 203 | ASurfaceControl* surface_control, ASurfaceControl* new_parent) |
| 204 | __INTRODUCED_IN(29); |
| 205 | |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 206 | /* Parameter for ASurfaceTransaction_setVisibility */ |
| 207 | enum { |
| 208 | ASURFACE_TRANSACTION_VISIBILITY_HIDE = 0, |
| 209 | ASURFACE_TRANSACTION_VISIBILITY_SHOW = 1, |
| 210 | }; |
| 211 | /** |
| 212 | * Updates the visibility of |surface_control|. If show is set to |
| 213 | * ASURFACE_TRANSACTION_VISIBILITY_HIDE, the |surface_control| and all surfaces in its subtree will |
| 214 | * be hidden. |
| 215 | */ |
| 216 | void ASurfaceTransaction_setVisibility(ASurfaceTransaction* transaction, |
| 217 | ASurfaceControl* surface_control, int8_t visibility) |
| 218 | __INTRODUCED_IN(29); |
| 219 | |
| 220 | /** |
| 221 | * Updates the z order index for |surface_control|. Note that the z order for a surface |
| 222 | * is relative to other surfaces which are siblings of this surface. The behavior of sibilings with |
| 223 | * the same z order is undefined. |
| 224 | * |
| 225 | * Z orders may be from MIN_INT32 to MAX_INT32. A layer's default z order index is 0. |
| 226 | */ |
| 227 | void ASurfaceTransaction_setZOrder(ASurfaceTransaction* transaction, |
| 228 | ASurfaceControl* surface_control, int32_t z_order) |
| 229 | __INTRODUCED_IN(29); |
| 230 | |
| 231 | /** |
| 232 | * Updates the AHardwareBuffer displayed for |surface_control|. If not -1, the |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 233 | * acquire_fence_fd should be a file descriptor that is signaled when all pending work |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 234 | * for the buffer is complete and the buffer can be safely read. |
| 235 | * |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 236 | * The frameworks takes ownership of the |acquire_fence_fd| passed and is responsible |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 237 | * for closing it. |
| 238 | */ |
| 239 | void ASurfaceTransaction_setBuffer(ASurfaceTransaction* transaction, |
| 240 | ASurfaceControl* surface_control, AHardwareBuffer* buffer, |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 241 | int acquire_fence_fd = -1) __INTRODUCED_IN(29); |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 242 | |
| 243 | /** |
Valerie Hau | ed54efa | 2019-01-11 20:03:14 -0800 | [diff] [blame^] | 244 | * Updates the color for |surface_control|. This will make the background color for the |
| 245 | * ASurfaceControl visible in transparent regions of the surface. Colors |r|, |g|, |
| 246 | * and |b| must be within the range that is valid for |dataspace|. |dataspace| and |alpha| |
| 247 | * will be the dataspace and alpha set for the background color layer. |
| 248 | */ |
| 249 | void ASurfaceTransaction_setColor(ASurfaceTransaction* transaction, |
| 250 | ASurfaceControl* surface_control, float r, float g, float b, |
| 251 | float alpha, ADataSpace dataspace) |
| 252 | __INTRODUCED_IN(29); |
| 253 | |
| 254 | /** |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 255 | * |source| the sub-rect within the buffer's content to be rendered inside the surface's area |
| 256 | * The surface's source rect is clipped by the bounds of its current buffer. The source rect's width |
| 257 | * and height must be > 0. |
| 258 | * |
| 259 | * |destination| specifies the rect in the parent's space where this surface will be drawn. The post |
| 260 | * source rect bounds are scaled to fit the destination rect. The surface's destination rect is |
| 261 | * clipped by the bounds of its parent. The destination rect's width and height must be > 0. |
| 262 | * |
| 263 | * |transform| the transform applied after the source rect is applied to the buffer. This parameter |
| 264 | * should be set to 0 for no transform. To specify a transfrom use the NATIVE_WINDOW_TRANSFORM_* |
| 265 | * enum. |
| 266 | */ |
| 267 | void ASurfaceTransaction_setGeometry(ASurfaceTransaction* transaction, |
| 268 | ASurfaceControl* surface_control, const ARect& source, |
| 269 | const ARect& destination, int32_t transform) |
| 270 | __INTRODUCED_IN(29); |
| 271 | |
| 272 | |
| 273 | /* Parameter for ASurfaceTransaction_setBufferTransparency */ |
| 274 | enum { |
| 275 | ASURFACE_TRANSACTION_TRANSPARENCY_TRANSPARENT = 0, |
| 276 | ASURFACE_TRANSACTION_TRANSPARENCY_TRANSLUCENT = 1, |
| 277 | ASURFACE_TRANSACTION_TRANSPARENCY_OPAQUE = 2, |
| 278 | }; |
| 279 | /** |
| 280 | * Updates whether the content for the buffer associated with this surface is |
| 281 | * completely opaque. If true, every pixel of content inside the buffer must be |
| 282 | * opaque or visual errors can occur. |
| 283 | */ |
| 284 | void ASurfaceTransaction_setBufferTransparency(ASurfaceTransaction* transaction, |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 285 | ASurfaceControl* surface_control, |
| 286 | int8_t transparency) |
| 287 | __INTRODUCED_IN(29); |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 288 | |
| 289 | /** |
| 290 | * Updates the region for the content on this surface updated in this |
| 291 | * transaction. If unspecified, the complete surface is assumed to be damaged. |
| 292 | */ |
| 293 | void ASurfaceTransaction_setDamageRegion(ASurfaceTransaction* transaction, |
| 294 | ASurfaceControl* surface_control, const ARect rects[], |
| 295 | uint32_t count) __INTRODUCED_IN(29); |
| 296 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 297 | /** |
| 298 | * Specifies a desiredPresentTime for the transaction. The framework will try to present |
| 299 | * the transaction at or after the time specified. |
| 300 | * |
| 301 | * Transactions will not be presented until all of their acquire fences have signaled even if the |
| 302 | * app requests an earlier present time. |
| 303 | * |
| 304 | * If an earlier transaction has a desired present time of x, and a later transaction has a desired |
| 305 | * present time that is before x, the later transaction will not preempt the earlier transaction. |
| 306 | */ |
| 307 | void ASurfaceTransaction_setDesiredPresentTime(ASurfaceTransaction* transaction, |
| 308 | int64_t desiredPresentTime) __INTRODUCED_IN(29); |
| 309 | |
| 310 | /** |
| 311 | * Sets the alpha for the buffer. It uses a premultiplied blending. |
| 312 | * |
| 313 | * The |alpha| must be between 0.0 and 1.0. |
| 314 | */ |
| 315 | void ASurfaceTransaction_setBufferAlpha(ASurfaceTransaction* transaction, |
| 316 | ASurfaceControl* surface_control, float alpha) |
| 317 | __INTRODUCED_IN(29); |
| 318 | |
| 319 | /* |
| 320 | * SMPTE ST 2086 "Mastering Display Color Volume" static metadata |
| 321 | * |
| 322 | * When |metadata| is set to null, the framework does not use any smpte2086 metadata when rendering |
| 323 | * the surface's buffer. |
| 324 | */ |
| 325 | void ASurfaceTransaction_setHdrMetadata_smpte2086(ASurfaceTransaction* transaction, |
| 326 | ASurfaceControl* surface_control, |
| 327 | struct AHdrMetadata_smpte2086* metadata) |
| 328 | __INTRODUCED_IN(29); |
| 329 | |
| 330 | /* |
| 331 | * Sets the CTA 861.3 "HDR Static Metadata Extension" static metadata on a surface. |
| 332 | * |
| 333 | * When |metadata| is set to null, the framework does not use any cta861.3 metadata when rendering |
| 334 | * the surface's buffer. |
| 335 | */ |
| 336 | void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* transaction, |
| 337 | ASurfaceControl* surface_control, |
| 338 | struct AHdrMetadata_cta861_3* metadata) |
| 339 | __INTRODUCED_IN(29); |
| 340 | |
Marissa Wall | 53da7e3 | 2018-09-25 15:59:38 -0700 | [diff] [blame] | 341 | #endif // __ANDROID_API__ >= 29 |
| 342 | |
| 343 | __END_DECLS |
| 344 | |
| 345 | #endif // ANDROID_SURFACE_CONTROL_H |