blob: e06e2b14b99a41cc69d05390bb39bdd85de48fdd [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>
chaviw13fdc492017-06-27 12:40:18 -070027#include <math/vec3.h>
Marissa Wall61c58622018-07-18 10:12:20 -070028#include <ui/GraphicTypes.h>
Marissa Wall11303242018-07-26 13:36:24 -070029#include <ui/Rect.h>
30#include <ui/Region.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080031
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080032namespace android {
33
34class Parcel;
Mathias Agopian698c0872011-06-28 19:09:31 -070035class ISurfaceComposerClient;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080036
Andy McFadden4125a4f2014-01-29 17:17:11 -080037/*
38 * Used to communicate layer information between SurfaceFlinger and its clients.
39 */
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080040struct layer_state_t {
Mathias Agopian3165cc22012-08-08 19:42:09 -070041 enum {
Marissa Wall11303242018-07-26 13:36:24 -070042 eLayerHidden = 0x01, // SURFACE_HIDDEN in SurfaceControl.java
43 eLayerOpaque = 0x02, // SURFACE_OPAQUE
44 eLayerSecure = 0x80, // SECURE
Mathias Agopian3165cc22012-08-08 19:42:09 -070045 };
46
47 enum {
Marissa Wall11303242018-07-26 13:36:24 -070048 ePositionChanged = 0x00000001,
49 eLayerChanged = 0x00000002,
50 eSizeChanged = 0x00000004,
51 eAlphaChanged = 0x00000008,
52 eMatrixChanged = 0x00000010,
53 eTransparentRegionChanged = 0x00000020,
54 eFlagsChanged = 0x00000040,
55 eLayerStackChanged = 0x00000080,
Marissa Wallf58c14b2018-07-24 10:50:43 -070056 eCropChanged_legacy = 0x00000100,
57 eDeferTransaction_legacy = 0x00000200,
Vishnu Nairdcce0e22018-08-23 08:35:19 -070058 eOverrideScalingModeChanged = 0x00000400,
59 eGeometryAppliesWithResize = 0x00000800,
60 eReparentChildren = 0x00001000,
61 eDetachChildren = 0x00002000,
62 eRelativeLayerChanged = 0x00004000,
63 eReparent = 0x00008000,
64 eColorChanged = 0x00010000,
65 eDestroySurface = 0x00020000,
66 eTransformChanged = 0x00040000,
67 eTransformToDisplayInverseChanged = 0x00080000,
68 eCropChanged = 0x00100000,
69 eBufferChanged = 0x00200000,
70 eAcquireFenceChanged = 0x00400000,
71 eDataspaceChanged = 0x00800000,
72 eHdrMetadataChanged = 0x01000000,
73 eSurfaceDamageRegionChanged = 0x02000000,
74 eApiChanged = 0x04000000,
75 eSidebandStreamChanged = 0x08000000,
Peiyong Lind3788632018-09-18 16:01:31 -070076 eColorTransformChanged = 0x10000000,
Mathias Agopian3165cc22012-08-08 19:42:09 -070077 };
78
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080079 layer_state_t()
Marissa Wall11303242018-07-26 13:36:24 -070080 : what(0),
81 x(0),
82 y(0),
83 z(0),
84 w(0),
85 h(0),
86 layerStack(0),
87 alpha(0),
88 flags(0),
89 mask(0),
90 reserved(0),
Marissa Wallf58c14b2018-07-24 10:50:43 -070091 crop_legacy(Rect::INVALID_RECT),
Marissa Wallf58c14b2018-07-24 10:50:43 -070092 frameNumber_legacy(0),
Marissa Wall61c58622018-07-18 10:12:20 -070093 overrideScalingMode(-1),
94 transform(0),
95 transformToDisplayInverse(false),
96 crop(Rect::INVALID_RECT),
97 dataspace(ui::Dataspace::UNKNOWN),
98 surfaceDamageRegion(),
Peiyong Lind3788632018-09-18 16:01:31 -070099 api(-1),
100 colorTransform(mat4()) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800101 matrix.dsdx = matrix.dtdy = 1.0f;
102 matrix.dsdy = matrix.dtdx = 0.0f;
Marissa Wall61c58622018-07-18 10:12:20 -0700103 hdrMetadata.validTypes = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800104 }
105
Robert Carr2c5f6d22017-09-26 12:30:35 -0700106 void merge(const layer_state_t& other);
Marissa Wall11303242018-07-26 13:36:24 -0700107 status_t write(Parcel& output) const;
108 status_t read(const Parcel& input);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800109
Marissa Wall11303242018-07-26 13:36:24 -0700110 struct matrix22_t {
111 float dsdx{0};
112 float dtdx{0};
113 float dtdy{0};
114 float dsdy{0};
115 };
116 sp<IBinder> surface;
117 uint32_t what;
118 float x;
119 float y;
120 int32_t z;
121 uint32_t w;
122 uint32_t h;
123 uint32_t layerStack;
124 float alpha;
125 uint8_t flags;
126 uint8_t mask;
127 uint8_t reserved;
128 matrix22_t matrix;
Marissa Wallf58c14b2018-07-24 10:50:43 -0700129 Rect crop_legacy;
Marissa Wallf58c14b2018-07-24 10:50:43 -0700130 sp<IBinder> barrierHandle_legacy;
Marissa Wall11303242018-07-26 13:36:24 -0700131 sp<IBinder> reparentHandle;
Marissa Wallf58c14b2018-07-24 10:50:43 -0700132 uint64_t frameNumber_legacy;
Marissa Wall11303242018-07-26 13:36:24 -0700133 int32_t overrideScalingMode;
Robert Carr0d480722017-01-10 16:42:54 -0800134
Marissa Wallf58c14b2018-07-24 10:50:43 -0700135 sp<IGraphicBufferProducer> barrierGbp_legacy;
Robert Carr0d480722017-01-10 16:42:54 -0800136
Marissa Wall11303242018-07-26 13:36:24 -0700137 sp<IBinder> relativeLayerHandle;
Robert Carrdb66e622017-04-10 16:55:57 -0700138
Marissa Wall11303242018-07-26 13:36:24 -0700139 sp<IBinder> parentHandleForChild;
chaviw06178942017-07-27 10:25:59 -0700140
Marissa Wall11303242018-07-26 13:36:24 -0700141 half3 color;
chaviw13fdc492017-06-27 12:40:18 -0700142
Marissa Wall11303242018-07-26 13:36:24 -0700143 // non POD must be last. see write/read
144 Region transparentRegion;
Marissa Wall61c58622018-07-18 10:12:20 -0700145
146 uint32_t transform;
147 bool transformToDisplayInverse;
148 Rect crop;
149 sp<GraphicBuffer> buffer;
150 sp<Fence> acquireFence;
151 ui::Dataspace dataspace;
152 HdrMetadata hdrMetadata;
153 Region surfaceDamageRegion;
154 int32_t api;
155 sp<NativeHandle> sidebandStream;
Peiyong Lind3788632018-09-18 16:01:31 -0700156 mat4 colorTransform;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800157};
158
Mathias Agopian698c0872011-06-28 19:09:31 -0700159struct ComposerState {
160 sp<ISurfaceComposerClient> client;
161 layer_state_t state;
Marissa Wall11303242018-07-26 13:36:24 -0700162 status_t write(Parcel& output) const;
163 status_t read(const Parcel& input);
Mathias Agopian698c0872011-06-28 19:09:31 -0700164};
165
Mathias Agopian8b33f032012-07-24 20:43:54 -0700166struct DisplayState {
Mathias Agopian3165cc22012-08-08 19:42:09 -0700167 enum {
Marissa Wall11303242018-07-26 13:36:24 -0700168 eOrientationDefault = 0,
169 eOrientation90 = 1,
170 eOrientation180 = 2,
171 eOrientation270 = 3,
172 eOrientationUnchanged = 4,
173 eOrientationSwapMask = 0x01
Mathias Agopian3165cc22012-08-08 19:42:09 -0700174 };
175
Mathias Agopiane57f2922012-08-09 16:29:12 -0700176 enum {
Marissa Wall11303242018-07-26 13:36:24 -0700177 eSurfaceChanged = 0x01,
178 eLayerStackChanged = 0x02,
179 eDisplayProjectionChanged = 0x04,
180 eDisplaySizeChanged = 0x08
Mathias Agopiane57f2922012-08-09 16:29:12 -0700181 };
182
Pablo Ceballos60d69222015-08-07 14:47:20 -0700183 DisplayState();
Robert Carr2c5f6d22017-09-26 12:30:35 -0700184 void merge(const DisplayState& other);
Pablo Ceballos60d69222015-08-07 14:47:20 -0700185
Mathias Agopiane57f2922012-08-09 16:29:12 -0700186 uint32_t what;
187 sp<IBinder> token;
Andy McFadden2adaf042012-12-18 09:49:45 -0800188 sp<IGraphicBufferProducer> surface;
Mathias Agopiane57f2922012-08-09 16:29:12 -0700189 uint32_t layerStack;
Chia-I Wuff79ef82018-08-22 15:27:32 -0700190
191 // These states define how layers are projected onto the physical display.
192 //
193 // Layers are first clipped to `viewport'. They are then translated and
194 // scaled from `viewport' to `frame'. Finally, they are rotated according
195 // to `orientation', `width', and `height'.
196 //
197 // For example, assume viewport is Rect(0, 0, 200, 100), frame is Rect(20,
198 // 10, 420, 210), and the size of the display is WxH. When orientation is
199 // 0, layers will be scaled by a factor of 2 and translated by (20, 10).
200 // When orientation is 1, layers will be additionally rotated by 90
201 // degrees around the origin clockwise and translated by (W, 0).
Mathias Agopiane57f2922012-08-09 16:29:12 -0700202 uint32_t orientation;
203 Rect viewport;
204 Rect frame;
Chia-I Wuff79ef82018-08-22 15:27:32 -0700205
Michael Wright1f6078a2014-06-26 16:01:02 -0700206 uint32_t width, height;
Chia-I Wuff79ef82018-08-22 15:27:32 -0700207
Mathias Agopiane57f2922012-08-09 16:29:12 -0700208 status_t write(Parcel& output) const;
209 status_t read(const Parcel& input);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700210};
211
Marissa Wall11303242018-07-26 13:36:24 -0700212static inline int compare_type(const ComposerState& lhs, const ComposerState& rhs) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700213 if (lhs.client < rhs.client) return -1;
214 if (lhs.client > rhs.client) return 1;
Marissa Wall11303242018-07-26 13:36:24 -0700215 if (lhs.state.surface < rhs.state.surface) return -1;
216 if (lhs.state.surface > rhs.state.surface) return 1;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700217 return 0;
218}
219
Marissa Wall11303242018-07-26 13:36:24 -0700220static inline int compare_type(const DisplayState& lhs, const DisplayState& rhs) {
Robert Carr4cdc58f2017-08-23 14:22:20 -0700221 return compare_type(lhs.token, rhs.token);
222}
223
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800224}; // namespace android
225
Mathias Agopian9cce3252010-02-09 17:46:37 -0800226#endif // ANDROID_SF_LAYER_STATE_H