blob: f438eb3d014c1baa804323b1a70d07b6905876aa [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
23#include <utils/Errors.h>
24
Robert Carr0d480722017-01-10 16:42:54 -080025#include <gui/IGraphicBufferProducer.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>
Mathias Agopian9cce3252010-02-09 17:46:37 -080037
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080038namespace android {
39
40class Parcel;
Mathias Agopian698c0872011-06-28 19:09:31 -070041class ISurfaceComposerClient;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042
Marissa Wall947d34e2019-03-29 14:03:53 -070043struct client_cache_t {
44 wp<IBinder> token = nullptr;
45 uint64_t id;
46
47 bool operator==(const client_cache_t& other) const { return id == other.id; }
48
49 bool isValid() const { return token != nullptr; }
Marissa Wall78b72202019-03-15 14:58:34 -070050};
51
Andy McFadden4125a4f2014-01-29 17:17:11 -080052/*
53 * Used to communicate layer information between SurfaceFlinger and its clients.
54 */
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080055struct layer_state_t {
Mathias Agopian3165cc22012-08-08 19:42:09 -070056 enum {
Marissa Wall11303242018-07-26 13:36:24 -070057 eLayerHidden = 0x01, // SURFACE_HIDDEN in SurfaceControl.java
58 eLayerOpaque = 0x02, // SURFACE_OPAQUE
59 eLayerSecure = 0x80, // SECURE
Mathias Agopian3165cc22012-08-08 19:42:09 -070060 };
61
62 enum {
Marissa Wall11303242018-07-26 13:36:24 -070063 ePositionChanged = 0x00000001,
64 eLayerChanged = 0x00000002,
65 eSizeChanged = 0x00000004,
66 eAlphaChanged = 0x00000008,
67 eMatrixChanged = 0x00000010,
68 eTransparentRegionChanged = 0x00000020,
69 eFlagsChanged = 0x00000040,
70 eLayerStackChanged = 0x00000080,
Marissa Wallf58c14b2018-07-24 10:50:43 -070071 eCropChanged_legacy = 0x00000100,
72 eDeferTransaction_legacy = 0x00000200,
Vishnu Nairdcce0e22018-08-23 08:35:19 -070073 eOverrideScalingModeChanged = 0x00000400,
74 eGeometryAppliesWithResize = 0x00000800,
75 eReparentChildren = 0x00001000,
76 eDetachChildren = 0x00002000,
77 eRelativeLayerChanged = 0x00004000,
78 eReparent = 0x00008000,
79 eColorChanged = 0x00010000,
80 eDestroySurface = 0x00020000,
81 eTransformChanged = 0x00040000,
82 eTransformToDisplayInverseChanged = 0x00080000,
83 eCropChanged = 0x00100000,
84 eBufferChanged = 0x00200000,
85 eAcquireFenceChanged = 0x00400000,
86 eDataspaceChanged = 0x00800000,
87 eHdrMetadataChanged = 0x01000000,
88 eSurfaceDamageRegionChanged = 0x02000000,
89 eApiChanged = 0x04000000,
90 eSidebandStreamChanged = 0x08000000,
Peiyong Lind3788632018-09-18 16:01:31 -070091 eColorTransformChanged = 0x10000000,
Marissa Wall3dad52d2019-03-22 14:03:19 -070092 eHasListenerCallbacksChanged = 0x20000000,
Robert Carr2c358bf2018-08-08 15:58:15 -070093 eInputInfoChanged = 0x40000000,
Lucas Dupin1b6531c2018-07-05 17:18:21 -070094 eCornerRadiusChanged = 0x80000000,
Marissa Wall861616d2018-10-22 12:52:23 -070095 eFrameChanged = 0x1'00000000,
Marissa Wallebc2c052019-01-16 19:16:55 -080096 eCachedBufferChanged = 0x2'00000000,
Valerie Haudd0b7572019-01-29 14:59:27 -080097 eBackgroundColorChanged = 0x4'00000000,
98 eMetadataChanged = 0x8'00000000,
Peiyong Linc502cb72019-03-01 15:00:23 -080099 eColorSpaceAgnosticChanged = 0x10'00000000,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700100 };
101
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102 layer_state_t()
Marissa Wall11303242018-07-26 13:36:24 -0700103 : what(0),
104 x(0),
105 y(0),
106 z(0),
107 w(0),
108 h(0),
109 layerStack(0),
110 alpha(0),
111 flags(0),
112 mask(0),
113 reserved(0),
Marissa Wallf58c14b2018-07-24 10:50:43 -0700114 crop_legacy(Rect::INVALID_RECT),
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700115 cornerRadius(0.0f),
Marissa Wallf58c14b2018-07-24 10:50:43 -0700116 frameNumber_legacy(0),
Marissa Wall61c58622018-07-18 10:12:20 -0700117 overrideScalingMode(-1),
118 transform(0),
119 transformToDisplayInverse(false),
120 crop(Rect::INVALID_RECT),
Marissa Wall861616d2018-10-22 12:52:23 -0700121 frame(Rect::INVALID_RECT),
Marissa Wall61c58622018-07-18 10:12:20 -0700122 dataspace(ui::Dataspace::UNKNOWN),
123 surfaceDamageRegion(),
Peiyong Lind3788632018-09-18 16:01:31 -0700124 api(-1),
Valerie Haued54efa2019-01-11 20:03:14 -0800125 colorTransform(mat4()),
Marissa Wall3dad52d2019-03-22 14:03:19 -0700126 hasListenerCallbacks(false),
Valerie Haudd0b7572019-01-29 14:59:27 -0800127 bgColorAlpha(0),
Peiyong Linc502cb72019-03-01 15:00:23 -0800128 bgColorDataspace(ui::Dataspace::UNKNOWN),
129 colorSpaceAgnostic(false) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800130 matrix.dsdx = matrix.dtdy = 1.0f;
131 matrix.dsdy = matrix.dtdx = 0.0f;
Marissa Wall61c58622018-07-18 10:12:20 -0700132 hdrMetadata.validTypes = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800133 }
134
Robert Carr2c5f6d22017-09-26 12:30:35 -0700135 void merge(const layer_state_t& other);
Marissa Wall11303242018-07-26 13:36:24 -0700136 status_t write(Parcel& output) const;
137 status_t read(const Parcel& input);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800138
Marissa Wall11303242018-07-26 13:36:24 -0700139 struct matrix22_t {
140 float dsdx{0};
141 float dtdx{0};
142 float dtdy{0};
143 float dsdy{0};
144 };
145 sp<IBinder> surface;
Garfield Tan8a3083e2018-12-03 13:21:07 -0800146 uint64_t what;
Marissa Wall11303242018-07-26 13:36:24 -0700147 float x;
148 float y;
149 int32_t z;
150 uint32_t w;
151 uint32_t h;
152 uint32_t layerStack;
153 float alpha;
154 uint8_t flags;
155 uint8_t mask;
156 uint8_t reserved;
157 matrix22_t matrix;
Marissa Wallf58c14b2018-07-24 10:50:43 -0700158 Rect crop_legacy;
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700159 float cornerRadius;
Marissa Wallf58c14b2018-07-24 10:50:43 -0700160 sp<IBinder> barrierHandle_legacy;
Marissa Wall11303242018-07-26 13:36:24 -0700161 sp<IBinder> reparentHandle;
Marissa Wallf58c14b2018-07-24 10:50:43 -0700162 uint64_t frameNumber_legacy;
Marissa Wall11303242018-07-26 13:36:24 -0700163 int32_t overrideScalingMode;
Robert Carr0d480722017-01-10 16:42:54 -0800164
Marissa Wallf58c14b2018-07-24 10:50:43 -0700165 sp<IGraphicBufferProducer> barrierGbp_legacy;
Robert Carr0d480722017-01-10 16:42:54 -0800166
Marissa Wall11303242018-07-26 13:36:24 -0700167 sp<IBinder> relativeLayerHandle;
Robert Carrdb66e622017-04-10 16:55:57 -0700168
Marissa Wall11303242018-07-26 13:36:24 -0700169 sp<IBinder> parentHandleForChild;
chaviw06178942017-07-27 10:25:59 -0700170
Marissa Wall11303242018-07-26 13:36:24 -0700171 half3 color;
chaviw13fdc492017-06-27 12:40:18 -0700172
Marissa Wall11303242018-07-26 13:36:24 -0700173 // non POD must be last. see write/read
174 Region transparentRegion;
Marissa Wall61c58622018-07-18 10:12:20 -0700175
176 uint32_t transform;
177 bool transformToDisplayInverse;
178 Rect crop;
Marissa Wall861616d2018-10-22 12:52:23 -0700179 Rect frame;
Marissa Wall61c58622018-07-18 10:12:20 -0700180 sp<GraphicBuffer> buffer;
181 sp<Fence> acquireFence;
182 ui::Dataspace dataspace;
183 HdrMetadata hdrMetadata;
184 Region surfaceDamageRegion;
185 int32_t api;
186 sp<NativeHandle> sidebandStream;
Peiyong Lind3788632018-09-18 16:01:31 -0700187 mat4 colorTransform;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700188
Marissa Wall3dad52d2019-03-22 14:03:19 -0700189 bool hasListenerCallbacks;
Robert Carr2c358bf2018-08-08 15:58:15 -0700190#ifndef NO_INPUT
191 InputWindowInfo inputInfo;
192#endif
Marissa Wallebc2c052019-01-16 19:16:55 -0800193
Marissa Wall947d34e2019-03-29 14:03:53 -0700194 client_cache_t cachedBuffer;
Valerie Haued54efa2019-01-11 20:03:14 -0800195
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800196 LayerMetadata metadata;
Valerie Haudd0b7572019-01-29 14:59:27 -0800197
198 // The following refer to the alpha, and dataspace, respectively of
199 // the background color layer
200 float bgColorAlpha;
201 ui::Dataspace bgColorDataspace;
Peiyong Linc502cb72019-03-01 15:00:23 -0800202
203 // A color space agnostic layer means the color of this layer can be
204 // interpreted in any color space.
205 bool colorSpaceAgnostic;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800206};
207
Mathias Agopian698c0872011-06-28 19:09:31 -0700208struct ComposerState {
209 sp<ISurfaceComposerClient> client;
210 layer_state_t state;
Marissa Wall11303242018-07-26 13:36:24 -0700211 status_t write(Parcel& output) const;
212 status_t read(const Parcel& input);
Mathias Agopian698c0872011-06-28 19:09:31 -0700213};
214
Mathias Agopian8b33f032012-07-24 20:43:54 -0700215struct DisplayState {
Mathias Agopian3165cc22012-08-08 19:42:09 -0700216 enum {
Marissa Wall11303242018-07-26 13:36:24 -0700217 eOrientationDefault = 0,
218 eOrientation90 = 1,
219 eOrientation180 = 2,
220 eOrientation270 = 3,
221 eOrientationUnchanged = 4,
222 eOrientationSwapMask = 0x01
Mathias Agopian3165cc22012-08-08 19:42:09 -0700223 };
224
Mathias Agopiane57f2922012-08-09 16:29:12 -0700225 enum {
Marissa Wall11303242018-07-26 13:36:24 -0700226 eSurfaceChanged = 0x01,
227 eLayerStackChanged = 0x02,
228 eDisplayProjectionChanged = 0x04,
229 eDisplaySizeChanged = 0x08
Mathias Agopiane57f2922012-08-09 16:29:12 -0700230 };
231
Pablo Ceballos60d69222015-08-07 14:47:20 -0700232 DisplayState();
Robert Carr2c5f6d22017-09-26 12:30:35 -0700233 void merge(const DisplayState& other);
Pablo Ceballos60d69222015-08-07 14:47:20 -0700234
Mathias Agopiane57f2922012-08-09 16:29:12 -0700235 uint32_t what;
236 sp<IBinder> token;
Andy McFadden2adaf042012-12-18 09:49:45 -0800237 sp<IGraphicBufferProducer> surface;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700238 uint32_t layerStack;
Chia-I Wuff79ef82018-08-22 15:27:32 -0700239
240 // These states define how layers are projected onto the physical display.
241 //
242 // Layers are first clipped to `viewport'. They are then translated and
243 // scaled from `viewport' to `frame'. Finally, they are rotated according
244 // to `orientation', `width', and `height'.
245 //
246 // For example, assume viewport is Rect(0, 0, 200, 100), frame is Rect(20,
247 // 10, 420, 210), and the size of the display is WxH. When orientation is
248 // 0, layers will be scaled by a factor of 2 and translated by (20, 10).
249 // When orientation is 1, layers will be additionally rotated by 90
250 // degrees around the origin clockwise and translated by (W, 0).
Mathias Agopiane57f2922012-08-09 16:29:12 -0700251 uint32_t orientation;
252 Rect viewport;
253 Rect frame;
Chia-I Wuff79ef82018-08-22 15:27:32 -0700254
Michael Wright1f6078a2014-06-26 16:01:02 -0700255 uint32_t width, height;
Chia-I Wuff79ef82018-08-22 15:27:32 -0700256
Mathias Agopiane57f2922012-08-09 16:29:12 -0700257 status_t write(Parcel& output) const;
258 status_t read(const Parcel& input);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700259};
260
chaviw273171b2018-12-26 11:46:30 -0800261struct InputWindowCommands {
262 struct TransferTouchFocusCommand {
263 sp<IBinder> fromToken;
264 sp<IBinder> toToken;
265 };
266
267 std::vector<TransferTouchFocusCommand> transferTouchFocusCommands;
chaviw291d88a2019-02-14 10:33:58 -0800268 bool syncInputWindows{false};
chaviw273171b2018-12-26 11:46:30 -0800269
270 void merge(const InputWindowCommands& other);
271 void clear();
272 void write(Parcel& output) const;
273 void read(const Parcel& input);
274};
275
Marissa Wall11303242018-07-26 13:36:24 -0700276static inline int compare_type(const ComposerState& lhs, const ComposerState& rhs) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700277 if (lhs.client < rhs.client) return -1;
278 if (lhs.client > rhs.client) return 1;
Marissa Wall11303242018-07-26 13:36:24 -0700279 if (lhs.state.surface < rhs.state.surface) return -1;
280 if (lhs.state.surface > rhs.state.surface) return 1;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700281 return 0;
282}
283
Marissa Wall11303242018-07-26 13:36:24 -0700284static inline int compare_type(const DisplayState& lhs, const DisplayState& rhs) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700285 return compare_type(lhs.token, rhs.token);
286}
287
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800288}; // namespace android
289
Mathias Agopian9cce3252010-02-09 17:46:37 -0800290#endif // ANDROID_SF_LAYER_STATE_H