blob: e60f6777ae81d3224e2248816b017dcea2dad64f [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 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
Mathias Agopian9cce3252010-02-09 17:46:37 -080017#ifndef ANDROID_SF_LAYER_STATE_H
18#define ANDROID_SF_LAYER_STATE_H
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080019
20#include <stdint.h>
21#include <sys/types.h>
22
Steven Thomas62a4cf82020-01-31 12:04:03 -080023#include <android/native_window.h>
Robert Carr0d480722017-01-10 16:42:54 -080024#include <gui/IGraphicBufferProducer.h>
Valerie Hau9dab9732019-08-20 09:29:25 -070025#include <gui/ITransactionCompletedListener.h>
Peiyong Lind3788632018-09-18 16:01:31 -070026#include <math/mat4.h>
Robert Carr2c358bf2018-08-08 15:58:15 -070027
28#ifndef NO_INPUT
29#include <input/InputWindow.h>
30#endif
31
Evan Rosky1f6d6d52018-12-06 10:47:26 -080032#include <gui/LayerMetadata.h>
chaviw13fdc492017-06-27 12:40:18 -070033#include <math/vec3.h>
Marissa Wall61c58622018-07-18 10:12:20 -070034#include <ui/GraphicTypes.h>
Marissa Wall11303242018-07-26 13:36:24 -070035#include <ui/Rect.h>
36#include <ui/Region.h>
Dominik Laskowski718f9602019-11-09 20:01:35 -080037#include <ui/Rotation.h>
Vishnu Nair6213bd92020-05-08 17:42:25 -070038#include <ui/Transform.h>
Steven Thomas62a4cf82020-01-31 12:04:03 -080039#include <utils/Errors.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080040
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080041namespace android {
42
43class Parcel;
Mathias Agopian698c0872011-06-28 19:09:31 -070044class ISurfaceComposerClient;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045
Marissa Wall947d34e2019-03-29 14:03:53 -070046struct client_cache_t {
47 wp<IBinder> token = nullptr;
48 uint64_t id;
49
50 bool operator==(const client_cache_t& other) const { return id == other.id; }
51
52 bool isValid() const { return token != nullptr; }
Marissa Wall78b72202019-03-15 14:58:34 -070053};
54
Andy McFadden4125a4f2014-01-29 17:17:11 -080055/*
56 * Used to communicate layer information between SurfaceFlinger and its clients.
57 */
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080058struct layer_state_t {
Mathias Agopian3165cc22012-08-08 19:42:09 -070059 enum {
Marissa Wall11303242018-07-26 13:36:24 -070060 eLayerHidden = 0x01, // SURFACE_HIDDEN in SurfaceControl.java
61 eLayerOpaque = 0x02, // SURFACE_OPAQUE
62 eLayerSecure = 0x80, // SECURE
Mathias Agopian3165cc22012-08-08 19:42:09 -070063 };
64
65 enum {
Marissa Wall11303242018-07-26 13:36:24 -070066 ePositionChanged = 0x00000001,
67 eLayerChanged = 0x00000002,
68 eSizeChanged = 0x00000004,
69 eAlphaChanged = 0x00000008,
70 eMatrixChanged = 0x00000010,
71 eTransparentRegionChanged = 0x00000020,
72 eFlagsChanged = 0x00000040,
73 eLayerStackChanged = 0x00000080,
Marissa Wallf58c14b2018-07-24 10:50:43 -070074 eCropChanged_legacy = 0x00000100,
75 eDeferTransaction_legacy = 0x00000200,
Vishnu Nairdcce0e22018-08-23 08:35:19 -070076 eOverrideScalingModeChanged = 0x00000400,
Vishnu Nairc97b8db2019-10-29 18:19:35 -070077 eShadowRadiusChanged = 0x00000800,
Vishnu Nairdcce0e22018-08-23 08:35:19 -070078 eReparentChildren = 0x00001000,
79 eDetachChildren = 0x00002000,
80 eRelativeLayerChanged = 0x00004000,
81 eReparent = 0x00008000,
82 eColorChanged = 0x00010000,
83 eDestroySurface = 0x00020000,
84 eTransformChanged = 0x00040000,
85 eTransformToDisplayInverseChanged = 0x00080000,
86 eCropChanged = 0x00100000,
87 eBufferChanged = 0x00200000,
88 eAcquireFenceChanged = 0x00400000,
89 eDataspaceChanged = 0x00800000,
90 eHdrMetadataChanged = 0x01000000,
91 eSurfaceDamageRegionChanged = 0x02000000,
92 eApiChanged = 0x04000000,
93 eSidebandStreamChanged = 0x08000000,
Peiyong Lind3788632018-09-18 16:01:31 -070094 eColorTransformChanged = 0x10000000,
Marissa Wall3dad52d2019-03-22 14:03:19 -070095 eHasListenerCallbacksChanged = 0x20000000,
Robert Carr2c358bf2018-08-08 15:58:15 -070096 eInputInfoChanged = 0x40000000,
Lucas Dupin1b6531c2018-07-05 17:18:21 -070097 eCornerRadiusChanged = 0x80000000,
Marissa Wall861616d2018-10-22 12:52:23 -070098 eFrameChanged = 0x1'00000000,
Marissa Wallebc2c052019-01-16 19:16:55 -080099 eCachedBufferChanged = 0x2'00000000,
Valerie Haudd0b7572019-01-29 14:59:27 -0800100 eBackgroundColorChanged = 0x4'00000000,
101 eMetadataChanged = 0x8'00000000,
Peiyong Linc502cb72019-03-01 15:00:23 -0800102 eColorSpaceAgnosticChanged = 0x10'00000000,
Ana Krulecc84d09b2019-11-02 23:10:29 +0100103 eFrameRateSelectionPriority = 0x20'00000000,
Steven Thomas3172e202020-01-06 19:25:30 -0800104 eFrameRateChanged = 0x40'00000000,
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800105 eBackgroundBlurRadiusChanged = 0x80'00000000,
Valerie Hau871d6352020-01-29 08:44:02 -0800106 eProducerDisconnect = 0x100'00000000,
Vishnu Nair6213bd92020-05-08 17:42:25 -0700107 eFixedTransformHintChanged = 0x200'00000000,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700108 };
109
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800110 layer_state_t()
Marissa Wall11303242018-07-26 13:36:24 -0700111 : what(0),
112 x(0),
113 y(0),
114 z(0),
115 w(0),
116 h(0),
117 layerStack(0),
118 alpha(0),
119 flags(0),
120 mask(0),
121 reserved(0),
Marissa Wallf58c14b2018-07-24 10:50:43 -0700122 crop_legacy(Rect::INVALID_RECT),
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700123 cornerRadius(0.0f),
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800124 backgroundBlurRadius(0),
Marissa Wallf58c14b2018-07-24 10:50:43 -0700125 frameNumber_legacy(0),
Marissa Wall61c58622018-07-18 10:12:20 -0700126 overrideScalingMode(-1),
127 transform(0),
128 transformToDisplayInverse(false),
129 crop(Rect::INVALID_RECT),
Marissa Wall861616d2018-10-22 12:52:23 -0700130 frame(Rect::INVALID_RECT),
Marissa Wall61c58622018-07-18 10:12:20 -0700131 dataspace(ui::Dataspace::UNKNOWN),
132 surfaceDamageRegion(),
Peiyong Lind3788632018-09-18 16:01:31 -0700133 api(-1),
Valerie Haued54efa2019-01-11 20:03:14 -0800134 colorTransform(mat4()),
Valerie Haudd0b7572019-01-29 14:59:27 -0800135 bgColorAlpha(0),
Peiyong Linc502cb72019-03-01 15:00:23 -0800136 bgColorDataspace(ui::Dataspace::UNKNOWN),
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700137 colorSpaceAgnostic(false),
Ana Krulecc84d09b2019-11-02 23:10:29 +0100138 shadowRadius(0.0f),
Steven Thomas3172e202020-01-06 19:25:30 -0800139 frameRateSelectionPriority(-1),
Steven Thomas62a4cf82020-01-31 12:04:03 -0800140 frameRate(0.0f),
Vishnu Nair6213bd92020-05-08 17:42:25 -0700141 frameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
142 fixedTransformHint(ui::Transform::ROT_INVALID) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800143 matrix.dsdx = matrix.dtdy = 1.0f;
144 matrix.dsdy = matrix.dtdx = 0.0f;
Marissa Wall61c58622018-07-18 10:12:20 -0700145 hdrMetadata.validTypes = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800146 }
147
Robert Carr2c5f6d22017-09-26 12:30:35 -0700148 void merge(const layer_state_t& other);
Marissa Wall11303242018-07-26 13:36:24 -0700149 status_t write(Parcel& output) const;
150 status_t read(const Parcel& input);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800151
Marissa Wall11303242018-07-26 13:36:24 -0700152 struct matrix22_t {
153 float dsdx{0};
154 float dtdx{0};
155 float dtdy{0};
156 float dsdy{0};
157 };
158 sp<IBinder> surface;
Garfield Tan8a3083e2018-12-03 13:21:07 -0800159 uint64_t what;
Marissa Wall11303242018-07-26 13:36:24 -0700160 float x;
161 float y;
162 int32_t z;
163 uint32_t w;
164 uint32_t h;
165 uint32_t layerStack;
166 float alpha;
167 uint8_t flags;
168 uint8_t mask;
169 uint8_t reserved;
170 matrix22_t matrix;
Marissa Wallf58c14b2018-07-24 10:50:43 -0700171 Rect crop_legacy;
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700172 float cornerRadius;
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800173 uint32_t backgroundBlurRadius;
Marissa Wallf58c14b2018-07-24 10:50:43 -0700174 sp<IBinder> barrierHandle_legacy;
Marissa Wall11303242018-07-26 13:36:24 -0700175 sp<IBinder> reparentHandle;
Marissa Wallf58c14b2018-07-24 10:50:43 -0700176 uint64_t frameNumber_legacy;
Marissa Wall11303242018-07-26 13:36:24 -0700177 int32_t overrideScalingMode;
Robert Carr0d480722017-01-10 16:42:54 -0800178
Marissa Wallf58c14b2018-07-24 10:50:43 -0700179 sp<IGraphicBufferProducer> barrierGbp_legacy;
Robert Carr0d480722017-01-10 16:42:54 -0800180
Marissa Wall11303242018-07-26 13:36:24 -0700181 sp<IBinder> relativeLayerHandle;
Robert Carrdb66e622017-04-10 16:55:57 -0700182
Marissa Wall11303242018-07-26 13:36:24 -0700183 sp<IBinder> parentHandleForChild;
chaviw06178942017-07-27 10:25:59 -0700184
Marissa Wall11303242018-07-26 13:36:24 -0700185 half3 color;
chaviw13fdc492017-06-27 12:40:18 -0700186
Marissa Wall11303242018-07-26 13:36:24 -0700187 // non POD must be last. see write/read
188 Region transparentRegion;
Marissa Wall61c58622018-07-18 10:12:20 -0700189
190 uint32_t transform;
191 bool transformToDisplayInverse;
192 Rect crop;
Marissa Wall861616d2018-10-22 12:52:23 -0700193 Rect frame;
Marissa Wall61c58622018-07-18 10:12:20 -0700194 sp<GraphicBuffer> buffer;
195 sp<Fence> acquireFence;
196 ui::Dataspace dataspace;
197 HdrMetadata hdrMetadata;
198 Region surfaceDamageRegion;
199 int32_t api;
200 sp<NativeHandle> sidebandStream;
Peiyong Lind3788632018-09-18 16:01:31 -0700201 mat4 colorTransform;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700202
Robert Carr2c358bf2018-08-08 15:58:15 -0700203#ifndef NO_INPUT
204 InputWindowInfo inputInfo;
205#endif
Marissa Wallebc2c052019-01-16 19:16:55 -0800206
Marissa Wall947d34e2019-03-29 14:03:53 -0700207 client_cache_t cachedBuffer;
Valerie Haued54efa2019-01-11 20:03:14 -0800208
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800209 LayerMetadata metadata;
Valerie Haudd0b7572019-01-29 14:59:27 -0800210
211 // The following refer to the alpha, and dataspace, respectively of
212 // the background color layer
213 float bgColorAlpha;
214 ui::Dataspace bgColorDataspace;
Peiyong Linc502cb72019-03-01 15:00:23 -0800215
216 // A color space agnostic layer means the color of this layer can be
217 // interpreted in any color space.
218 bool colorSpaceAgnostic;
Valerie Hau9dab9732019-08-20 09:29:25 -0700219
220 std::vector<ListenerCallbacks> listeners;
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700221
222 // Draws a shadow around the surface.
223 float shadowRadius;
Ana Krulecc84d09b2019-11-02 23:10:29 +0100224
225 // Priority of the layer assigned by Window Manager.
226 int32_t frameRateSelectionPriority;
Steven Thomas3172e202020-01-06 19:25:30 -0800227
Steven Thomas62a4cf82020-01-31 12:04:03 -0800228 // Layer frame rate and compatibility. See ANativeWindow_setFrameRate().
Steven Thomas3172e202020-01-06 19:25:30 -0800229 float frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800230 int8_t frameRateCompatibility;
Vishnu Nair6213bd92020-05-08 17:42:25 -0700231
232 // Set by window manager indicating the layer and all its children are
233 // in a different orientation than the display. The hint suggests that
234 // the graphic producers should receive a transform hint as if the
235 // display was in this orientation. When the display changes to match
236 // the layer orientation, the graphic producer may not need to allocate
237 // a buffer of a different size. -1 means the transform hint is not set,
238 // otherwise the value will be a valid ui::Rotation.
239 ui::Transform::RotationFlags fixedTransformHint;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800240};
241
Mathias Agopian698c0872011-06-28 19:09:31 -0700242struct ComposerState {
Mathias Agopian698c0872011-06-28 19:09:31 -0700243 layer_state_t state;
Marissa Wall11303242018-07-26 13:36:24 -0700244 status_t write(Parcel& output) const;
245 status_t read(const Parcel& input);
Mathias Agopian698c0872011-06-28 19:09:31 -0700246};
247
Mathias Agopian8b33f032012-07-24 20:43:54 -0700248struct DisplayState {
Mathias Agopian3165cc22012-08-08 19:42:09 -0700249 enum {
Marissa Wall11303242018-07-26 13:36:24 -0700250 eSurfaceChanged = 0x01,
251 eLayerStackChanged = 0x02,
252 eDisplayProjectionChanged = 0x04,
253 eDisplaySizeChanged = 0x08
Mathias Agopiane57f2922012-08-09 16:29:12 -0700254 };
255
Pablo Ceballos60d69222015-08-07 14:47:20 -0700256 DisplayState();
Robert Carr2c5f6d22017-09-26 12:30:35 -0700257 void merge(const DisplayState& other);
Pablo Ceballos60d69222015-08-07 14:47:20 -0700258
Mathias Agopiane57f2922012-08-09 16:29:12 -0700259 uint32_t what;
260 sp<IBinder> token;
Andy McFadden2adaf042012-12-18 09:49:45 -0800261 sp<IGraphicBufferProducer> surface;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700262 uint32_t layerStack;
Chia-I Wuff79ef82018-08-22 15:27:32 -0700263
264 // These states define how layers are projected onto the physical display.
265 //
266 // Layers are first clipped to `viewport'. They are then translated and
267 // scaled from `viewport' to `frame'. Finally, they are rotated according
268 // to `orientation', `width', and `height'.
269 //
270 // For example, assume viewport is Rect(0, 0, 200, 100), frame is Rect(20,
271 // 10, 420, 210), and the size of the display is WxH. When orientation is
272 // 0, layers will be scaled by a factor of 2 and translated by (20, 10).
273 // When orientation is 1, layers will be additionally rotated by 90
274 // degrees around the origin clockwise and translated by (W, 0).
Dominik Laskowski718f9602019-11-09 20:01:35 -0800275 ui::Rotation orientation = ui::ROTATION_0;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700276 Rect viewport;
277 Rect frame;
Chia-I Wuff79ef82018-08-22 15:27:32 -0700278
Michael Wright1f6078a2014-06-26 16:01:02 -0700279 uint32_t width, height;
Chia-I Wuff79ef82018-08-22 15:27:32 -0700280
Mathias Agopiane57f2922012-08-09 16:29:12 -0700281 status_t write(Parcel& output) const;
282 status_t read(const Parcel& input);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700283};
284
chaviw273171b2018-12-26 11:46:30 -0800285struct InputWindowCommands {
chaviw291d88a2019-02-14 10:33:58 -0800286 bool syncInputWindows{false};
chaviw273171b2018-12-26 11:46:30 -0800287
288 void merge(const InputWindowCommands& other);
289 void clear();
290 void write(Parcel& output) const;
291 void read(const Parcel& input);
292};
293
Marissa Wall11303242018-07-26 13:36:24 -0700294static inline int compare_type(const ComposerState& lhs, const ComposerState& rhs) {
Marissa Wall11303242018-07-26 13:36:24 -0700295 if (lhs.state.surface < rhs.state.surface) return -1;
296 if (lhs.state.surface > rhs.state.surface) return 1;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700297 return 0;
298}
299
Marissa Wall11303242018-07-26 13:36:24 -0700300static inline int compare_type(const DisplayState& lhs, const DisplayState& rhs) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700301 return compare_type(lhs.token, rhs.token);
302}
303
Steven Thomas62a4cf82020-01-31 12:04:03 -0800304// Returns true if the frameRate and compatibility are valid values, false
305// othwerise. If either of the params are invalid, an error log is printed, and
306// functionName is added to the log to indicate which function call failed.
307// functionName can be null.
308bool ValidateFrameRate(float frameRate, int8_t compatibility, const char* functionName);
309
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800310}; // namespace android
311
Mathias Agopian9cce3252010-02-09 17:46:37 -0800312#endif // ANDROID_SF_LAYER_STATE_H