The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 17 | #ifndef ANDROID_SF_LAYER_STATE_H |
| 18 | #define ANDROID_SF_LAYER_STATE_H |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
| 23 | #include <utils/Errors.h> |
| 24 | |
Robert Carr | 0d48072 | 2017-01-10 16:42:54 -0800 | [diff] [blame] | 25 | #include <gui/IGraphicBufferProducer.h> |
Marissa Wall | c837b5e | 2018-10-12 10:04:44 -0700 | [diff] [blame] | 26 | #include <gui/ITransactionCompletedListener.h> |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 27 | #include <math/mat4.h> |
Robert Carr | 2c358bf | 2018-08-08 15:58:15 -0700 | [diff] [blame] | 28 | |
| 29 | #ifndef NO_INPUT |
| 30 | #include <input/InputWindow.h> |
| 31 | #endif |
| 32 | |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 33 | #include <gui/LayerMetadata.h> |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 34 | #include <math/vec3.h> |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 35 | #include <ui/GraphicTypes.h> |
Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 36 | #include <ui/Rect.h> |
| 37 | #include <ui/Region.h> |
Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 38 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | namespace android { |
| 40 | |
| 41 | class Parcel; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 42 | class ISurfaceComposerClient; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | |
Marissa Wall | 78b7220 | 2019-03-15 14:58:34 -0700 | [diff] [blame^] | 44 | struct cached_buffer_t { |
| 45 | sp<IBinder> token = nullptr; |
| 46 | uint64_t cacheId; |
| 47 | }; |
| 48 | |
Andy McFadden | 4125a4f | 2014-01-29 17:17:11 -0800 | [diff] [blame] | 49 | /* |
| 50 | * Used to communicate layer information between SurfaceFlinger and its clients. |
| 51 | */ |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | struct layer_state_t { |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 53 | enum { |
Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 54 | eLayerHidden = 0x01, // SURFACE_HIDDEN in SurfaceControl.java |
| 55 | eLayerOpaque = 0x02, // SURFACE_OPAQUE |
| 56 | eLayerSecure = 0x80, // SECURE |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | enum { |
Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 60 | ePositionChanged = 0x00000001, |
| 61 | eLayerChanged = 0x00000002, |
| 62 | eSizeChanged = 0x00000004, |
| 63 | eAlphaChanged = 0x00000008, |
| 64 | eMatrixChanged = 0x00000010, |
| 65 | eTransparentRegionChanged = 0x00000020, |
| 66 | eFlagsChanged = 0x00000040, |
| 67 | eLayerStackChanged = 0x00000080, |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 68 | eCropChanged_legacy = 0x00000100, |
| 69 | eDeferTransaction_legacy = 0x00000200, |
Vishnu Nair | dcce0e2 | 2018-08-23 08:35:19 -0700 | [diff] [blame] | 70 | 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 Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 88 | eColorTransformChanged = 0x10000000, |
Marissa Wall | c837b5e | 2018-10-12 10:04:44 -0700 | [diff] [blame] | 89 | eListenerCallbacksChanged = 0x20000000, |
Robert Carr | 2c358bf | 2018-08-08 15:58:15 -0700 | [diff] [blame] | 90 | eInputInfoChanged = 0x40000000, |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 91 | eCornerRadiusChanged = 0x80000000, |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 92 | eFrameChanged = 0x1'00000000, |
Marissa Wall | ebc2c05 | 2019-01-16 19:16:55 -0800 | [diff] [blame] | 93 | eCachedBufferChanged = 0x2'00000000, |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 94 | eBackgroundColorChanged = 0x4'00000000, |
| 95 | eMetadataChanged = 0x8'00000000, |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 96 | eColorSpaceAgnosticChanged = 0x10'00000000, |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 97 | }; |
| 98 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | layer_state_t() |
Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 100 | : 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 Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 111 | crop_legacy(Rect::INVALID_RECT), |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 112 | cornerRadius(0.0f), |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 113 | frameNumber_legacy(0), |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 114 | overrideScalingMode(-1), |
| 115 | transform(0), |
| 116 | transformToDisplayInverse(false), |
| 117 | crop(Rect::INVALID_RECT), |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 118 | frame(Rect::INVALID_RECT), |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 119 | dataspace(ui::Dataspace::UNKNOWN), |
| 120 | surfaceDamageRegion(), |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 121 | api(-1), |
Valerie Hau | ed54efa | 2019-01-11 20:03:14 -0800 | [diff] [blame] | 122 | colorTransform(mat4()), |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 123 | bgColorAlpha(0), |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 124 | bgColorDataspace(ui::Dataspace::UNKNOWN), |
| 125 | colorSpaceAgnostic(false) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | matrix.dsdx = matrix.dtdy = 1.0f; |
| 127 | matrix.dsdy = matrix.dtdx = 0.0f; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 128 | hdrMetadata.validTypes = 0; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | } |
| 130 | |
Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 131 | void merge(const layer_state_t& other); |
Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 132 | status_t write(Parcel& output) const; |
| 133 | status_t read(const Parcel& input); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | |
Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 135 | 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 Tan | 8a3083e | 2018-12-03 13:21:07 -0800 | [diff] [blame] | 142 | uint64_t what; |
Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 143 | 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 Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 154 | Rect crop_legacy; |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 155 | float cornerRadius; |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 156 | sp<IBinder> barrierHandle_legacy; |
Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 157 | sp<IBinder> reparentHandle; |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 158 | uint64_t frameNumber_legacy; |
Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 159 | int32_t overrideScalingMode; |
Robert Carr | 0d48072 | 2017-01-10 16:42:54 -0800 | [diff] [blame] | 160 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 161 | sp<IGraphicBufferProducer> barrierGbp_legacy; |
Robert Carr | 0d48072 | 2017-01-10 16:42:54 -0800 | [diff] [blame] | 162 | |
Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 163 | sp<IBinder> relativeLayerHandle; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 164 | |
Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 165 | sp<IBinder> parentHandleForChild; |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 166 | |
Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 167 | half3 color; |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 168 | |
Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 169 | // non POD must be last. see write/read |
| 170 | Region transparentRegion; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 171 | |
| 172 | uint32_t transform; |
| 173 | bool transformToDisplayInverse; |
| 174 | Rect crop; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 175 | Rect frame; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 176 | 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 Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 183 | mat4 colorTransform; |
Marissa Wall | c837b5e | 2018-10-12 10:04:44 -0700 | [diff] [blame] | 184 | |
| 185 | std::vector<ListenerCallbacks> listenerCallbacks; |
Robert Carr | 2c358bf | 2018-08-08 15:58:15 -0700 | [diff] [blame] | 186 | #ifndef NO_INPUT |
| 187 | InputWindowInfo inputInfo; |
| 188 | #endif |
Marissa Wall | ebc2c05 | 2019-01-16 19:16:55 -0800 | [diff] [blame] | 189 | |
| 190 | cached_buffer_t cachedBuffer; |
Valerie Hau | ed54efa | 2019-01-11 20:03:14 -0800 | [diff] [blame] | 191 | |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 192 | LayerMetadata metadata; |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 193 | |
| 194 | // The following refer to the alpha, and dataspace, respectively of |
| 195 | // the background color layer |
| 196 | float bgColorAlpha; |
| 197 | ui::Dataspace bgColorDataspace; |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 198 | |
| 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 Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | }; |
| 203 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 204 | struct ComposerState { |
| 205 | sp<ISurfaceComposerClient> client; |
| 206 | layer_state_t state; |
Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 207 | status_t write(Parcel& output) const; |
| 208 | status_t read(const Parcel& input); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 209 | }; |
| 210 | |
Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 211 | struct DisplayState { |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 212 | enum { |
Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 213 | eOrientationDefault = 0, |
| 214 | eOrientation90 = 1, |
| 215 | eOrientation180 = 2, |
| 216 | eOrientation270 = 3, |
| 217 | eOrientationUnchanged = 4, |
| 218 | eOrientationSwapMask = 0x01 |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 219 | }; |
| 220 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 221 | enum { |
Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 222 | eSurfaceChanged = 0x01, |
| 223 | eLayerStackChanged = 0x02, |
| 224 | eDisplayProjectionChanged = 0x04, |
| 225 | eDisplaySizeChanged = 0x08 |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 226 | }; |
| 227 | |
Pablo Ceballos | 60d6922 | 2015-08-07 14:47:20 -0700 | [diff] [blame] | 228 | DisplayState(); |
Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 229 | void merge(const DisplayState& other); |
Pablo Ceballos | 60d6922 | 2015-08-07 14:47:20 -0700 | [diff] [blame] | 230 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 231 | uint32_t what; |
| 232 | sp<IBinder> token; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 233 | sp<IGraphicBufferProducer> surface; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 234 | uint32_t layerStack; |
Chia-I Wu | ff79ef8 | 2018-08-22 15:27:32 -0700 | [diff] [blame] | 235 | |
| 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 Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 247 | uint32_t orientation; |
| 248 | Rect viewport; |
| 249 | Rect frame; |
Chia-I Wu | ff79ef8 | 2018-08-22 15:27:32 -0700 | [diff] [blame] | 250 | |
Michael Wright | 1f6078a | 2014-06-26 16:01:02 -0700 | [diff] [blame] | 251 | uint32_t width, height; |
Chia-I Wu | ff79ef8 | 2018-08-22 15:27:32 -0700 | [diff] [blame] | 252 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 253 | status_t write(Parcel& output) const; |
| 254 | status_t read(const Parcel& input); |
Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 255 | }; |
| 256 | |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 257 | struct InputWindowCommands { |
| 258 | struct TransferTouchFocusCommand { |
| 259 | sp<IBinder> fromToken; |
| 260 | sp<IBinder> toToken; |
| 261 | }; |
| 262 | |
| 263 | std::vector<TransferTouchFocusCommand> transferTouchFocusCommands; |
chaviw | 291d88a | 2019-02-14 10:33:58 -0800 | [diff] [blame] | 264 | bool syncInputWindows{false}; |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 265 | |
| 266 | void merge(const InputWindowCommands& other); |
| 267 | void clear(); |
| 268 | void write(Parcel& output) const; |
| 269 | void read(const Parcel& input); |
| 270 | }; |
| 271 | |
Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 272 | static inline int compare_type(const ComposerState& lhs, const ComposerState& rhs) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 273 | if (lhs.client < rhs.client) return -1; |
| 274 | if (lhs.client > rhs.client) return 1; |
Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 275 | if (lhs.state.surface < rhs.state.surface) return -1; |
| 276 | if (lhs.state.surface > rhs.state.surface) return 1; |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 277 | return 0; |
| 278 | } |
| 279 | |
Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 280 | static inline int compare_type(const DisplayState& lhs, const DisplayState& rhs) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 281 | return compare_type(lhs.token, rhs.token); |
| 282 | } |
| 283 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 284 | }; // namespace android |
| 285 | |
Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 286 | #endif // ANDROID_SF_LAYER_STATE_H |