blob: 77bf8f1dc542a8549e92118f381319725985ec4e [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>
Marissa Wallc837b5e2018-10-12 10:04:44 -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>
Mathias Agopian9cce3252010-02-09 17:46:37 -080038
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080039namespace android {
40
41class Parcel;
Mathias Agopian698c0872011-06-28 19:09:31 -070042class ISurfaceComposerClient;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043
Marissa Wall78b72202019-03-15 14:58:34 -070044struct cached_buffer_t {
45 sp<IBinder> token = nullptr;
46 uint64_t cacheId;
47};
48
Andy McFadden4125a4f2014-01-29 17:17:11 -080049/*
50 * Used to communicate layer information between SurfaceFlinger and its clients.
51 */
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080052struct layer_state_t {
Mathias Agopian3165cc22012-08-08 19:42:09 -070053 enum {
Marissa Wall11303242018-07-26 13:36:24 -070054 eLayerHidden = 0x01, // SURFACE_HIDDEN in SurfaceControl.java
55 eLayerOpaque = 0x02, // SURFACE_OPAQUE
56 eLayerSecure = 0x80, // SECURE
Mathias Agopian3165cc22012-08-08 19:42:09 -070057 };
58
59 enum {
Marissa Wall11303242018-07-26 13:36:24 -070060 ePositionChanged = 0x00000001,
61 eLayerChanged = 0x00000002,
62 eSizeChanged = 0x00000004,
63 eAlphaChanged = 0x00000008,
64 eMatrixChanged = 0x00000010,
65 eTransparentRegionChanged = 0x00000020,
66 eFlagsChanged = 0x00000040,
67 eLayerStackChanged = 0x00000080,
Marissa Wallf58c14b2018-07-24 10:50:43 -070068 eCropChanged_legacy = 0x00000100,
69 eDeferTransaction_legacy = 0x00000200,
Vishnu Nairdcce0e22018-08-23 08:35:19 -070070 eOverrideScalingModeChanged = 0x00000400,
71 eGeometryAppliesWithResize = 0x00000800,
72 eReparentChildren = 0x00001000,
73 eDetachChildren = 0x00002000,
74 eRelativeLayerChanged = 0x00004000,
75 eReparent = 0x00008000,
76 eColorChanged = 0x00010000,
77 eDestroySurface = 0x00020000,
78 eTransformChanged = 0x00040000,
79 eTransformToDisplayInverseChanged = 0x00080000,
80 eCropChanged = 0x00100000,
81 eBufferChanged = 0x00200000,
82 eAcquireFenceChanged = 0x00400000,
83 eDataspaceChanged = 0x00800000,
84 eHdrMetadataChanged = 0x01000000,
85 eSurfaceDamageRegionChanged = 0x02000000,
86 eApiChanged = 0x04000000,
87 eSidebandStreamChanged = 0x08000000,
Peiyong Lind3788632018-09-18 16:01:31 -070088 eColorTransformChanged = 0x10000000,
Marissa Wallc837b5e2018-10-12 10:04:44 -070089 eListenerCallbacksChanged = 0x20000000,
Robert Carr2c358bf2018-08-08 15:58:15 -070090 eInputInfoChanged = 0x40000000,
Lucas Dupin1b6531c2018-07-05 17:18:21 -070091 eCornerRadiusChanged = 0x80000000,
Marissa Wall861616d2018-10-22 12:52:23 -070092 eFrameChanged = 0x1'00000000,
Marissa Wallebc2c052019-01-16 19:16:55 -080093 eCachedBufferChanged = 0x2'00000000,
Valerie Haudd0b7572019-01-29 14:59:27 -080094 eBackgroundColorChanged = 0x4'00000000,
95 eMetadataChanged = 0x8'00000000,
Peiyong Linc502cb72019-03-01 15:00:23 -080096 eColorSpaceAgnosticChanged = 0x10'00000000,
Mathias Agopian3165cc22012-08-08 19:42:09 -070097 };
98
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080099 layer_state_t()
Marissa Wall11303242018-07-26 13:36:24 -0700100 : what(0),
101 x(0),
102 y(0),
103 z(0),
104 w(0),
105 h(0),
106 layerStack(0),
107 alpha(0),
108 flags(0),
109 mask(0),
110 reserved(0),
Marissa Wallf58c14b2018-07-24 10:50:43 -0700111 crop_legacy(Rect::INVALID_RECT),
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700112 cornerRadius(0.0f),
Marissa Wallf58c14b2018-07-24 10:50:43 -0700113 frameNumber_legacy(0),
Marissa Wall61c58622018-07-18 10:12:20 -0700114 overrideScalingMode(-1),
115 transform(0),
116 transformToDisplayInverse(false),
117 crop(Rect::INVALID_RECT),
Marissa Wall861616d2018-10-22 12:52:23 -0700118 frame(Rect::INVALID_RECT),
Marissa Wall61c58622018-07-18 10:12:20 -0700119 dataspace(ui::Dataspace::UNKNOWN),
120 surfaceDamageRegion(),
Peiyong Lind3788632018-09-18 16:01:31 -0700121 api(-1),
Valerie Haued54efa2019-01-11 20:03:14 -0800122 colorTransform(mat4()),
Valerie Haudd0b7572019-01-29 14:59:27 -0800123 bgColorAlpha(0),
Peiyong Linc502cb72019-03-01 15:00:23 -0800124 bgColorDataspace(ui::Dataspace::UNKNOWN),
125 colorSpaceAgnostic(false) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800126 matrix.dsdx = matrix.dtdy = 1.0f;
127 matrix.dsdy = matrix.dtdx = 0.0f;
Marissa Wall61c58622018-07-18 10:12:20 -0700128 hdrMetadata.validTypes = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800129 }
130
Robert Carr2c5f6d22017-09-26 12:30:35 -0700131 void merge(const layer_state_t& other);
Marissa Wall11303242018-07-26 13:36:24 -0700132 status_t write(Parcel& output) const;
133 status_t read(const Parcel& input);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800134
Marissa Wall11303242018-07-26 13:36:24 -0700135 struct matrix22_t {
136 float dsdx{0};
137 float dtdx{0};
138 float dtdy{0};
139 float dsdy{0};
140 };
141 sp<IBinder> surface;
Garfield Tan8a3083e2018-12-03 13:21:07 -0800142 uint64_t what;
Marissa Wall11303242018-07-26 13:36:24 -0700143 float x;
144 float y;
145 int32_t z;
146 uint32_t w;
147 uint32_t h;
148 uint32_t layerStack;
149 float alpha;
150 uint8_t flags;
151 uint8_t mask;
152 uint8_t reserved;
153 matrix22_t matrix;
Marissa Wallf58c14b2018-07-24 10:50:43 -0700154 Rect crop_legacy;
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700155 float cornerRadius;
Marissa Wallf58c14b2018-07-24 10:50:43 -0700156 sp<IBinder> barrierHandle_legacy;
Marissa Wall11303242018-07-26 13:36:24 -0700157 sp<IBinder> reparentHandle;
Marissa Wallf58c14b2018-07-24 10:50:43 -0700158 uint64_t frameNumber_legacy;
Marissa Wall11303242018-07-26 13:36:24 -0700159 int32_t overrideScalingMode;
Robert Carr0d480722017-01-10 16:42:54 -0800160
Marissa Wallf58c14b2018-07-24 10:50:43 -0700161 sp<IGraphicBufferProducer> barrierGbp_legacy;
Robert Carr0d480722017-01-10 16:42:54 -0800162
Marissa Wall11303242018-07-26 13:36:24 -0700163 sp<IBinder> relativeLayerHandle;
Robert Carrdb66e622017-04-10 16:55:57 -0700164
Marissa Wall11303242018-07-26 13:36:24 -0700165 sp<IBinder> parentHandleForChild;
chaviw06178942017-07-27 10:25:59 -0700166
Marissa Wall11303242018-07-26 13:36:24 -0700167 half3 color;
chaviw13fdc492017-06-27 12:40:18 -0700168
Marissa Wall11303242018-07-26 13:36:24 -0700169 // non POD must be last. see write/read
170 Region transparentRegion;
Marissa Wall61c58622018-07-18 10:12:20 -0700171
172 uint32_t transform;
173 bool transformToDisplayInverse;
174 Rect crop;
Marissa Wall861616d2018-10-22 12:52:23 -0700175 Rect frame;
Marissa Wall61c58622018-07-18 10:12:20 -0700176 sp<GraphicBuffer> buffer;
177 sp<Fence> acquireFence;
178 ui::Dataspace dataspace;
179 HdrMetadata hdrMetadata;
180 Region surfaceDamageRegion;
181 int32_t api;
182 sp<NativeHandle> sidebandStream;
Peiyong Lind3788632018-09-18 16:01:31 -0700183 mat4 colorTransform;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700184
185 std::vector<ListenerCallbacks> listenerCallbacks;
Robert Carr2c358bf2018-08-08 15:58:15 -0700186#ifndef NO_INPUT
187 InputWindowInfo inputInfo;
188#endif
Marissa Wallebc2c052019-01-16 19:16:55 -0800189
190 cached_buffer_t cachedBuffer;
Valerie Haued54efa2019-01-11 20:03:14 -0800191
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800192 LayerMetadata metadata;
Valerie Haudd0b7572019-01-29 14:59:27 -0800193
194 // The following refer to the alpha, and dataspace, respectively of
195 // the background color layer
196 float bgColorAlpha;
197 ui::Dataspace bgColorDataspace;
Peiyong Linc502cb72019-03-01 15:00:23 -0800198
199 // A color space agnostic layer means the color of this layer can be
200 // interpreted in any color space.
201 bool colorSpaceAgnostic;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800202};
203
Mathias Agopian698c0872011-06-28 19:09:31 -0700204struct ComposerState {
205 sp<ISurfaceComposerClient> client;
206 layer_state_t state;
Marissa Wall11303242018-07-26 13:36:24 -0700207 status_t write(Parcel& output) const;
208 status_t read(const Parcel& input);
Mathias Agopian698c0872011-06-28 19:09:31 -0700209};
210
Mathias Agopian8b33f032012-07-24 20:43:54 -0700211struct DisplayState {
Mathias Agopian3165cc22012-08-08 19:42:09 -0700212 enum {
Marissa Wall11303242018-07-26 13:36:24 -0700213 eOrientationDefault = 0,
214 eOrientation90 = 1,
215 eOrientation180 = 2,
216 eOrientation270 = 3,
217 eOrientationUnchanged = 4,
218 eOrientationSwapMask = 0x01
Mathias Agopian3165cc22012-08-08 19:42:09 -0700219 };
220
Mathias Agopiane57f2922012-08-09 16:29:12 -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).
Mathias Agopiane57f2922012-08-09 16:29:12 -0700247 uint32_t orientation;
248 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) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700273 if (lhs.client < rhs.client) return -1;
274 if (lhs.client > rhs.client) return 1;
Marissa Wall11303242018-07-26 13:36:24 -0700275 if (lhs.state.surface < rhs.state.surface) return -1;
276 if (lhs.state.surface > rhs.state.surface) return 1;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700277 return 0;
278}
279
Marissa Wall11303242018-07-26 13:36:24 -0700280static inline int compare_type(const DisplayState& lhs, const DisplayState& rhs) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700281 return compare_type(lhs.token, rhs.token);
282}
283
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800284}; // namespace android
285
Mathias Agopian9cce3252010-02-09 17:46:37 -0800286#endif // ANDROID_SF_LAYER_STATE_H