blob: 13b630ba5749bd58269ceeab48b9c6d6da0e35c1 [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
31#include <android/hardware_buffer.h>
32#include <android/native_window.h>
33
34__BEGIN_DECLS
35
36#if __ANDROID_API__ >= 29
37
38struct ASurfaceControl;
39
40/**
41 * The SurfaceControl API can be used to provide a heirarchy of surfaces for
42 * composition to the system compositor. ASurfaceControl represents a content node in
43 * this heirarchy.
44 */
45typedef struct ASurfaceControl ASurfaceControl;
46
47/*
48 * Creates an ASurfaceControl with either ANativeWindow or an ASurfaceControl as its parent.
49 * |debug_name| is a debug name associated with this surface. It can be used to
50 * 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.
55 */
56ASurfaceControl* ASurfaceControl_createFromWindow(ANativeWindow* parent, const char* debug_name)
57 __INTRODUCED_IN(29);
58
59ASurfaceControl* ASurfaceControl_create(ASurfaceControl* parent, const char* debug_name)
60 __INTRODUCED_IN(29);
61
62/**
63 * Destroys the |surface_control| object. After releasing the ASurfaceControl the caller no longer
64 * has ownership of the AsurfaceControl.
65 */
66void ASurfaceControl_destroy(ASurfaceControl* surface_control) __INTRODUCED_IN(29);
67
68struct ASurfaceTransaction;
69
70/**
71 * ASurfaceTransaction is a collection of updates to the surface tree that must
72 * be applied atomically.
73 */
74typedef struct ASurfaceTransaction ASurfaceTransaction;
75
76/**
77 * The caller takes ownership of the transaction and must release it using
78 * ASurfaceControl_delete below.
79 */
80ASurfaceTransaction* ASurfaceTransaction_create() __INTRODUCED_IN(29);
81
82/**
83 * Destroys the |transaction| object.
84 */
85void ASurfaceTransaction_delete(ASurfaceTransaction* transaction) __INTRODUCED_IN(29);
86
87/**
88 * Applies the updates accumulated in |transaction|.
89 *
90 * Note that the transaction is guaranteed to be applied atomically. The
91 * transactions which are applied on the same thread are also guaranteed to be
92 * applied in order.
93 */
94void ASurfaceTransaction_apply(ASurfaceTransaction* transaction) __INTRODUCED_IN(29);
95
96/**
97 * Since the transactions are applied asynchronously, the
98 * ASurfaceTransaction_OnComplete callback can be used to be notified when a frame
99 * including the updates in a transaction was presented.
100 *
101 * |context| is the optional context provided by the client that is passed into
102 * the callback.
103 * |present_fence| is the sync fence that signals when the transaction has been presented.
104 * The recipient of the callback takes ownership of the present_fence and is responsible for closing
105 * it.
106 *
107 * It is safe to assume that once the present fence singals, that reads for all buffers,
108 * submitted in previous transactions, which are not in the surface tree after a transaction is
109 * applied, are finished and the buffers may be reused.
110 *
111 * THREADING
112 * The transaction completed callback can be invoked on any thread.
113 */
114typedef void (*ASurfaceTransaction_OnComplete)(void* context, int32_t present_fence);
115
116/**
117 * Sets the callback that will be invoked when the updates from this transaction
118 * are presented. For details on the callback semantics and data, see the
119 * comments on the ASurfaceTransaction_OnComplete declaration above.
120 */
121void ASurfaceTransaction_setOnComplete(ASurfaceTransaction* transaction, void* context,
122 ASurfaceTransaction_OnComplete func) __INTRODUCED_IN(29);
123
124/* Parameter for ASurfaceTransaction_setVisibility */
125enum {
126 ASURFACE_TRANSACTION_VISIBILITY_HIDE = 0,
127 ASURFACE_TRANSACTION_VISIBILITY_SHOW = 1,
128};
129/**
130 * Updates the visibility of |surface_control|. If show is set to
131 * ASURFACE_TRANSACTION_VISIBILITY_HIDE, the |surface_control| and all surfaces in its subtree will
132 * be hidden.
133 */
134void ASurfaceTransaction_setVisibility(ASurfaceTransaction* transaction,
135 ASurfaceControl* surface_control, int8_t visibility)
136 __INTRODUCED_IN(29);
137
138/**
139 * Updates the z order index for |surface_control|. Note that the z order for a surface
140 * is relative to other surfaces which are siblings of this surface. The behavior of sibilings with
141 * the same z order is undefined.
142 *
143 * Z orders may be from MIN_INT32 to MAX_INT32. A layer's default z order index is 0.
144 */
145void ASurfaceTransaction_setZOrder(ASurfaceTransaction* transaction,
146 ASurfaceControl* surface_control, int32_t z_order)
147 __INTRODUCED_IN(29);
148
149/**
150 * Updates the AHardwareBuffer displayed for |surface_control|. If not -1, the
151 * fence_fd should be a file descriptor that is signaled when all pending work
152 * for the buffer is complete and the buffer can be safely read.
153 *
154 * The frameworks takes ownership of the |fence_fd| passed and is responsible
155 * for closing it.
156 */
157void ASurfaceTransaction_setBuffer(ASurfaceTransaction* transaction,
158 ASurfaceControl* surface_control, AHardwareBuffer* buffer,
159 int fence_fd = -1) __INTRODUCED_IN(29);
160
161/**
162 * |source| the sub-rect within the buffer's content to be rendered inside the surface's area
163 * The surface's source rect is clipped by the bounds of its current buffer. The source rect's width
164 * and height must be > 0.
165 *
166 * |destination| specifies the rect in the parent's space where this surface will be drawn. The post
167 * source rect bounds are scaled to fit the destination rect. The surface's destination rect is
168 * clipped by the bounds of its parent. The destination rect's width and height must be > 0.
169 *
170 * |transform| the transform applied after the source rect is applied to the buffer. This parameter
171 * should be set to 0 for no transform. To specify a transfrom use the NATIVE_WINDOW_TRANSFORM_*
172 * enum.
173 */
174void ASurfaceTransaction_setGeometry(ASurfaceTransaction* transaction,
175 ASurfaceControl* surface_control, const ARect& source,
176 const ARect& destination, int32_t transform)
177 __INTRODUCED_IN(29);
178
179
180/* Parameter for ASurfaceTransaction_setBufferTransparency */
181enum {
182 ASURFACE_TRANSACTION_TRANSPARENCY_TRANSPARENT = 0,
183 ASURFACE_TRANSACTION_TRANSPARENCY_TRANSLUCENT = 1,
184 ASURFACE_TRANSACTION_TRANSPARENCY_OPAQUE = 2,
185};
186/**
187 * Updates whether the content for the buffer associated with this surface is
188 * completely opaque. If true, every pixel of content inside the buffer must be
189 * opaque or visual errors can occur.
190 */
191void ASurfaceTransaction_setBufferTransparency(ASurfaceTransaction* transaction,
192 ASurfaceControl* surface_control, int8_t transparency)
193 __INTRODUCED_IN(29);
194
195/**
196 * Updates the region for the content on this surface updated in this
197 * transaction. If unspecified, the complete surface is assumed to be damaged.
198 */
199void ASurfaceTransaction_setDamageRegion(ASurfaceTransaction* transaction,
200 ASurfaceControl* surface_control, const ARect rects[],
201 uint32_t count) __INTRODUCED_IN(29);
202
203#endif // __ANDROID_API__ >= 29
204
205__END_DECLS
206
207#endif // ANDROID_SURFACE_CONTROL_H