blob: fb186396a63534a468ca8e8488f84eff91e36cfc [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>
Valerie Hau9dab9732019-08-20 09:29:25 -070026#include <gui/ITransactionCompletedListener.h>
Peiyong Lind3788632018-09-18 16:01:31 -070027#include <math/mat4.h>
Robert Carr2c358bf2018-08-08 15:58:15 -070028
29#ifndef NO_INPUT
30#include <input/InputWindow.h>
31#endif
32
Evan Rosky1f6d6d52018-12-06 10:47:26 -080033#include <gui/LayerMetadata.h>
chaviw13fdc492017-06-27 12:40:18 -070034#include <math/vec3.h>
Marissa Wall61c58622018-07-18 10:12:20 -070035#include <ui/GraphicTypes.h>
Marissa Wall11303242018-07-26 13:36:24 -070036#include <ui/Rect.h>
37#include <ui/Region.h>
Dominik Laskowski718f9602019-11-09 20:01:35 -080038#include <ui/Rotation.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080039
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080040namespace android {
41
42class Parcel;
Mathias Agopian698c0872011-06-28 19:09:31 -070043class ISurfaceComposerClient;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044
Marissa Wall947d34e2019-03-29 14:03:53 -070045struct client_cache_t {
46 wp<IBinder> token = nullptr;
47 uint64_t id;
48
49 bool operator==(const client_cache_t& other) const { return id == other.id; }
50
51 bool isValid() const { return token != nullptr; }
Marissa Wall78b72202019-03-15 14:58:34 -070052};
53
Andy McFadden4125a4f2014-01-29 17:17:11 -080054/*
55 * Used to communicate layer information between SurfaceFlinger and its clients.
56 */
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080057struct layer_state_t {
Mathias Agopian3165cc22012-08-08 19:42:09 -070058 enum {
Marissa Wall11303242018-07-26 13:36:24 -070059 eLayerHidden = 0x01, // SURFACE_HIDDEN in SurfaceControl.java
60 eLayerOpaque = 0x02, // SURFACE_OPAQUE
61 eLayerSecure = 0x80, // SECURE
Mathias Agopian3165cc22012-08-08 19:42:09 -070062 };
63
64 enum {
Marissa Wall11303242018-07-26 13:36:24 -070065 ePositionChanged = 0x00000001,
66 eLayerChanged = 0x00000002,
67 eSizeChanged = 0x00000004,
68 eAlphaChanged = 0x00000008,
69 eMatrixChanged = 0x00000010,
70 eTransparentRegionChanged = 0x00000020,
71 eFlagsChanged = 0x00000040,
72 eLayerStackChanged = 0x00000080,
Marissa Wallf58c14b2018-07-24 10:50:43 -070073 eCropChanged_legacy = 0x00000100,
74 eDeferTransaction_legacy = 0x00000200,
Vishnu Nairdcce0e22018-08-23 08:35:19 -070075 eOverrideScalingModeChanged = 0x00000400,
Vishnu Nairc97b8db2019-10-29 18:19:35 -070076 eShadowRadiusChanged = 0x00000800,
Vishnu Nairdcce0e22018-08-23 08:35:19 -070077 eReparentChildren = 0x00001000,
78 eDetachChildren = 0x00002000,
79 eRelativeLayerChanged = 0x00004000,
80 eReparent = 0x00008000,
81 eColorChanged = 0x00010000,
82 eDestroySurface = 0x00020000,
83 eTransformChanged = 0x00040000,
84 eTransformToDisplayInverseChanged = 0x00080000,
85 eCropChanged = 0x00100000,
86 eBufferChanged = 0x00200000,
87 eAcquireFenceChanged = 0x00400000,
88 eDataspaceChanged = 0x00800000,
89 eHdrMetadataChanged = 0x01000000,
90 eSurfaceDamageRegionChanged = 0x02000000,
91 eApiChanged = 0x04000000,
92 eSidebandStreamChanged = 0x08000000,
Peiyong Lind3788632018-09-18 16:01:31 -070093 eColorTransformChanged = 0x10000000,
Marissa Wall3dad52d2019-03-22 14:03:19 -070094 eHasListenerCallbacksChanged = 0x20000000,
Robert Carr2c358bf2018-08-08 15:58:15 -070095 eInputInfoChanged = 0x40000000,
Lucas Dupin1b6531c2018-07-05 17:18:21 -070096 eCornerRadiusChanged = 0x80000000,
Marissa Wall861616d2018-10-22 12:52:23 -070097 eFrameChanged = 0x1'00000000,
Marissa Wallebc2c052019-01-16 19:16:55 -080098 eCachedBufferChanged = 0x2'00000000,
Valerie Haudd0b7572019-01-29 14:59:27 -080099 eBackgroundColorChanged = 0x4'00000000,
100 eMetadataChanged = 0x8'00000000,
Peiyong Linc502cb72019-03-01 15:00:23 -0800101 eColorSpaceAgnosticChanged = 0x10'00000000,
Mathias Agopian3165cc22012-08-08 19:42:09 -0700102 };
103
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800104 layer_state_t()
Marissa Wall11303242018-07-26 13:36:24 -0700105 : what(0),
106 x(0),
107 y(0),
108 z(0),
109 w(0),
110 h(0),
111 layerStack(0),
112 alpha(0),
113 flags(0),
114 mask(0),
115 reserved(0),
Marissa Wallf58c14b2018-07-24 10:50:43 -0700116 crop_legacy(Rect::INVALID_RECT),
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700117 cornerRadius(0.0f),
Marissa Wallf58c14b2018-07-24 10:50:43 -0700118 frameNumber_legacy(0),
Marissa Wall61c58622018-07-18 10:12:20 -0700119 overrideScalingMode(-1),
120 transform(0),
121 transformToDisplayInverse(false),
122 crop(Rect::INVALID_RECT),
Marissa Wall861616d2018-10-22 12:52:23 -0700123 frame(Rect::INVALID_RECT),
Marissa Wall61c58622018-07-18 10:12:20 -0700124 dataspace(ui::Dataspace::UNKNOWN),
125 surfaceDamageRegion(),
Peiyong Lind3788632018-09-18 16:01:31 -0700126 api(-1),
Valerie Haued54efa2019-01-11 20:03:14 -0800127 colorTransform(mat4()),
Valerie Haudd0b7572019-01-29 14:59:27 -0800128 bgColorAlpha(0),
Peiyong Linc502cb72019-03-01 15:00:23 -0800129 bgColorDataspace(ui::Dataspace::UNKNOWN),
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700130 colorSpaceAgnostic(false),
131 shadowRadius(0.0f) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800132 matrix.dsdx = matrix.dtdy = 1.0f;
133 matrix.dsdy = matrix.dtdx = 0.0f;
Marissa Wall61c58622018-07-18 10:12:20 -0700134 hdrMetadata.validTypes = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800135 }
136
Robert Carr2c5f6d22017-09-26 12:30:35 -0700137 void merge(const layer_state_t& other);
Marissa Wall11303242018-07-26 13:36:24 -0700138 status_t write(Parcel& output) const;
139 status_t read(const Parcel& input);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800140
Marissa Wall11303242018-07-26 13:36:24 -0700141 struct matrix22_t {
142 float dsdx{0};
143 float dtdx{0};
144 float dtdy{0};
145 float dsdy{0};
146 };
147 sp<IBinder> surface;
Garfield Tan8a3083e2018-12-03 13:21:07 -0800148 uint64_t what;
Marissa Wall11303242018-07-26 13:36:24 -0700149 float x;
150 float y;
151 int32_t z;
152 uint32_t w;
153 uint32_t h;
154 uint32_t layerStack;
155 float alpha;
156 uint8_t flags;
157 uint8_t mask;
158 uint8_t reserved;
159 matrix22_t matrix;
Marissa Wallf58c14b2018-07-24 10:50:43 -0700160 Rect crop_legacy;
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700161 float cornerRadius;
Marissa Wallf58c14b2018-07-24 10:50:43 -0700162 sp<IBinder> barrierHandle_legacy;
Marissa Wall11303242018-07-26 13:36:24 -0700163 sp<IBinder> reparentHandle;
Marissa Wallf58c14b2018-07-24 10:50:43 -0700164 uint64_t frameNumber_legacy;
Marissa Wall11303242018-07-26 13:36:24 -0700165 int32_t overrideScalingMode;
Robert Carr0d480722017-01-10 16:42:54 -0800166
Marissa Wallf58c14b2018-07-24 10:50:43 -0700167 sp<IGraphicBufferProducer> barrierGbp_legacy;
Robert Carr0d480722017-01-10 16:42:54 -0800168
Marissa Wall11303242018-07-26 13:36:24 -0700169 sp<IBinder> relativeLayerHandle;
Robert Carrdb66e622017-04-10 16:55:57 -0700170
Marissa Wall11303242018-07-26 13:36:24 -0700171 sp<IBinder> parentHandleForChild;
chaviw06178942017-07-27 10:25:59 -0700172
Marissa Wall11303242018-07-26 13:36:24 -0700173 half3 color;
chaviw13fdc492017-06-27 12:40:18 -0700174
Marissa Wall11303242018-07-26 13:36:24 -0700175 // non POD must be last. see write/read
176 Region transparentRegion;
Marissa Wall61c58622018-07-18 10:12:20 -0700177
178 uint32_t transform;
179 bool transformToDisplayInverse;
180 Rect crop;
Marissa Wall861616d2018-10-22 12:52:23 -0700181 Rect frame;
Marissa Wall61c58622018-07-18 10:12:20 -0700182 sp<GraphicBuffer> buffer;
183 sp<Fence> acquireFence;
184 ui::Dataspace dataspace;
185 HdrMetadata hdrMetadata;
186 Region surfaceDamageRegion;
187 int32_t api;
188 sp<NativeHandle> sidebandStream;
Peiyong Lind3788632018-09-18 16:01:31 -0700189 mat4 colorTransform;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700190
Robert Carr2c358bf2018-08-08 15:58:15 -0700191#ifndef NO_INPUT
192 InputWindowInfo inputInfo;
193#endif
Marissa Wallebc2c052019-01-16 19:16:55 -0800194
Marissa Wall947d34e2019-03-29 14:03:53 -0700195 client_cache_t cachedBuffer;
Valerie Haued54efa2019-01-11 20:03:14 -0800196
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800197 LayerMetadata metadata;
Valerie Haudd0b7572019-01-29 14:59:27 -0800198
199 // The following refer to the alpha, and dataspace, respectively of
200 // the background color layer
201 float bgColorAlpha;
202 ui::Dataspace bgColorDataspace;
Peiyong Linc502cb72019-03-01 15:00:23 -0800203
204 // A color space agnostic layer means the color of this layer can be
205 // interpreted in any color space.
206 bool colorSpaceAgnostic;
Valerie Hau9dab9732019-08-20 09:29:25 -0700207
208 std::vector<ListenerCallbacks> listeners;
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700209
210 // Draws a shadow around the surface.
211 float shadowRadius;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800212};
213
Mathias Agopian698c0872011-06-28 19:09:31 -0700214struct ComposerState {
Mathias Agopian698c0872011-06-28 19:09:31 -0700215 layer_state_t state;
Marissa Wall11303242018-07-26 13:36:24 -0700216 status_t write(Parcel& output) const;
217 status_t read(const Parcel& input);
Mathias Agopian698c0872011-06-28 19:09:31 -0700218};
219
Mathias Agopian8b33f032012-07-24 20:43:54 -0700220struct DisplayState {
Mathias Agopian3165cc22012-08-08 19:42:09 -0700221 enum {
Marissa Wall11303242018-07-26 13:36:24 -0700222 eSurfaceChanged = 0x01,
223 eLayerStackChanged = 0x02,
224 eDisplayProjectionChanged = 0x04,
225 eDisplaySizeChanged = 0x08
Mathias Agopiane57f2922012-08-09 16:29:12 -0700226 };
227
Pablo Ceballos60d69222015-08-07 14:47:20 -0700228 DisplayState();
Robert Carr2c5f6d22017-09-26 12:30:35 -0700229 void merge(const DisplayState& other);
Pablo Ceballos60d69222015-08-07 14:47:20 -0700230
Mathias Agopiane57f2922012-08-09 16:29:12 -0700231 uint32_t what;
232 sp<IBinder> token;
Andy McFadden2adaf042012-12-18 09:49:45 -0800233 sp<IGraphicBufferProducer> surface;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700234 uint32_t layerStack;
Chia-I Wuff79ef82018-08-22 15:27:32 -0700235
236 // These states define how layers are projected onto the physical display.
237 //
238 // Layers are first clipped to `viewport'. They are then translated and
239 // scaled from `viewport' to `frame'. Finally, they are rotated according
240 // to `orientation', `width', and `height'.
241 //
242 // For example, assume viewport is Rect(0, 0, 200, 100), frame is Rect(20,
243 // 10, 420, 210), and the size of the display is WxH. When orientation is
244 // 0, layers will be scaled by a factor of 2 and translated by (20, 10).
245 // When orientation is 1, layers will be additionally rotated by 90
246 // degrees around the origin clockwise and translated by (W, 0).
Dominik Laskowski718f9602019-11-09 20:01:35 -0800247 ui::Rotation orientation = ui::ROTATION_0;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700248 Rect viewport;
249 Rect frame;
Chia-I Wuff79ef82018-08-22 15:27:32 -0700250
Michael Wright1f6078a2014-06-26 16:01:02 -0700251 uint32_t width, height;
Chia-I Wuff79ef82018-08-22 15:27:32 -0700252
Mathias Agopiane57f2922012-08-09 16:29:12 -0700253 status_t write(Parcel& output) const;
254 status_t read(const Parcel& input);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700255};
256
chaviw273171b2018-12-26 11:46:30 -0800257struct InputWindowCommands {
258 struct TransferTouchFocusCommand {
259 sp<IBinder> fromToken;
260 sp<IBinder> toToken;
261 };
262
263 std::vector<TransferTouchFocusCommand> transferTouchFocusCommands;
chaviw291d88a2019-02-14 10:33:58 -0800264 bool syncInputWindows{false};
chaviw273171b2018-12-26 11:46:30 -0800265
266 void merge(const InputWindowCommands& other);
267 void clear();
268 void write(Parcel& output) const;
269 void read(const Parcel& input);
270};
271
Marissa Wall11303242018-07-26 13:36:24 -0700272static inline int compare_type(const ComposerState& lhs, const ComposerState& rhs) {
Marissa Wall11303242018-07-26 13:36:24 -0700273 if (lhs.state.surface < rhs.state.surface) return -1;
274 if (lhs.state.surface > rhs.state.surface) return 1;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700275 return 0;
276}
277
Marissa Wall11303242018-07-26 13:36:24 -0700278static inline int compare_type(const DisplayState& lhs, const DisplayState& rhs) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700279 return compare_type(lhs.token, rhs.token);
280}
281
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800282}; // namespace android
283
Mathias Agopian9cce3252010-02-09 17:46:37 -0800284#endif // ANDROID_SF_LAYER_STATE_H