| 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> |
| Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 26 | #include <math/mat4.h> |
| chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 27 | #include <math/vec3.h> |
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 28 | #include <ui/GraphicTypes.h> |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 29 | #include <ui/Rect.h> |
| 30 | #include <ui/Region.h> |
| Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 31 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | namespace android { |
| 33 | |
| 34 | class Parcel; |
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 35 | class ISurfaceComposerClient; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
| Andy McFadden | 4125a4f | 2014-01-29 17:17:11 -0800 | [diff] [blame] | 37 | /* |
| 38 | * Used to communicate layer information between SurfaceFlinger and its clients. |
| 39 | */ |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | struct layer_state_t { |
| Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 41 | enum { |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 42 | eLayerHidden = 0x01, // SURFACE_HIDDEN in SurfaceControl.java |
| 43 | eLayerOpaque = 0x02, // SURFACE_OPAQUE |
| 44 | eLayerSecure = 0x80, // SECURE |
| Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | enum { |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 48 | ePositionChanged = 0x00000001, |
| 49 | eLayerChanged = 0x00000002, |
| 50 | eSizeChanged = 0x00000004, |
| 51 | eAlphaChanged = 0x00000008, |
| 52 | eMatrixChanged = 0x00000010, |
| 53 | eTransparentRegionChanged = 0x00000020, |
| 54 | eFlagsChanged = 0x00000040, |
| 55 | eLayerStackChanged = 0x00000080, |
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 56 | eCropChanged_legacy = 0x00000100, |
| 57 | eDeferTransaction_legacy = 0x00000200, |
| Vishnu Nair | dcce0e2 | 2018-08-23 08:35:19 -0700 | [diff] [blame] | 58 | 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 Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 76 | eColorTransformChanged = 0x10000000, |
| Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | layer_state_t() |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 80 | : 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 Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 91 | crop_legacy(Rect::INVALID_RECT), |
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 92 | frameNumber_legacy(0), |
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 93 | overrideScalingMode(-1), |
| 94 | transform(0), |
| 95 | transformToDisplayInverse(false), |
| 96 | crop(Rect::INVALID_RECT), |
| 97 | dataspace(ui::Dataspace::UNKNOWN), |
| 98 | surfaceDamageRegion(), |
| Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 99 | api(-1), |
| 100 | colorTransform(mat4()) { |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | matrix.dsdx = matrix.dtdy = 1.0f; |
| 102 | matrix.dsdy = matrix.dtdx = 0.0f; |
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 103 | hdrMetadata.validTypes = 0; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | } |
| 105 | |
| Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 106 | void merge(const layer_state_t& other); |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 107 | status_t write(Parcel& output) const; |
| 108 | status_t read(const Parcel& input); |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 110 | 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 Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 129 | Rect crop_legacy; |
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 130 | sp<IBinder> barrierHandle_legacy; |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 131 | sp<IBinder> reparentHandle; |
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 132 | uint64_t frameNumber_legacy; |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 133 | int32_t overrideScalingMode; |
| Robert Carr | 0d48072 | 2017-01-10 16:42:54 -0800 | [diff] [blame] | 134 | |
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 135 | sp<IGraphicBufferProducer> barrierGbp_legacy; |
| Robert Carr | 0d48072 | 2017-01-10 16:42:54 -0800 | [diff] [blame] | 136 | |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 137 | sp<IBinder> relativeLayerHandle; |
| Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 138 | |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 139 | sp<IBinder> parentHandleForChild; |
| chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 140 | |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 141 | half3 color; |
| chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 142 | |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 143 | // non POD must be last. see write/read |
| 144 | Region transparentRegion; |
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 145 | |
| 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 Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 156 | mat4 colorTransform; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | }; |
| 158 | |
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 159 | struct ComposerState { |
| 160 | sp<ISurfaceComposerClient> client; |
| 161 | layer_state_t state; |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 162 | status_t write(Parcel& output) const; |
| 163 | status_t read(const Parcel& input); |
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 164 | }; |
| 165 | |
| Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 166 | struct DisplayState { |
| Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 167 | enum { |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 168 | eOrientationDefault = 0, |
| 169 | eOrientation90 = 1, |
| 170 | eOrientation180 = 2, |
| 171 | eOrientation270 = 3, |
| 172 | eOrientationUnchanged = 4, |
| 173 | eOrientationSwapMask = 0x01 |
| Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 174 | }; |
| 175 | |
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 176 | enum { |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 177 | eSurfaceChanged = 0x01, |
| 178 | eLayerStackChanged = 0x02, |
| 179 | eDisplayProjectionChanged = 0x04, |
| 180 | eDisplaySizeChanged = 0x08 |
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 181 | }; |
| 182 | |
| Pablo Ceballos | 60d6922 | 2015-08-07 14:47:20 -0700 | [diff] [blame] | 183 | DisplayState(); |
| Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 184 | void merge(const DisplayState& other); |
| Pablo Ceballos | 60d6922 | 2015-08-07 14:47:20 -0700 | [diff] [blame] | 185 | |
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 186 | uint32_t what; |
| 187 | sp<IBinder> token; |
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 188 | sp<IGraphicBufferProducer> surface; |
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 189 | uint32_t layerStack; |
| Chia-I Wu | ff79ef8 | 2018-08-22 15:27:32 -0700 | [diff] [blame] | 190 | |
| 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 Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 202 | uint32_t orientation; |
| 203 | Rect viewport; |
| 204 | Rect frame; |
| Chia-I Wu | ff79ef8 | 2018-08-22 15:27:32 -0700 | [diff] [blame] | 205 | |
| Michael Wright | 1f6078a | 2014-06-26 16:01:02 -0700 | [diff] [blame] | 206 | uint32_t width, height; |
| Chia-I Wu | ff79ef8 | 2018-08-22 15:27:32 -0700 | [diff] [blame] | 207 | |
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 208 | status_t write(Parcel& output) const; |
| 209 | status_t read(const Parcel& input); |
| Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 210 | }; |
| 211 | |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 212 | static inline int compare_type(const ComposerState& lhs, const ComposerState& rhs) { |
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 213 | if (lhs.client < rhs.client) return -1; |
| 214 | if (lhs.client > rhs.client) return 1; |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 215 | if (lhs.state.surface < rhs.state.surface) return -1; |
| 216 | if (lhs.state.surface > rhs.state.surface) return 1; |
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 217 | return 0; |
| 218 | } |
| 219 | |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 220 | static inline int compare_type(const DisplayState& lhs, const DisplayState& rhs) { |
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 221 | return compare_type(lhs.token, rhs.token); |
| 222 | } |
| 223 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | }; // namespace android |
| 225 | |
| Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 226 | #endif // ANDROID_SF_LAYER_STATE_H |