| 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 |
| chaviw | 308ddba | 2020-08-11 16:23:51 -0700 | [diff] [blame] | 19 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <sys/types.h> |
| 23 | |
| Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 24 | #include <android/native_window.h> |
| Robert Carr | 0d48072 | 2017-01-10 16:42:54 -0800 | [diff] [blame] | 25 | #include <gui/IGraphicBufferProducer.h> |
| Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -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 | |
| chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 29 | #include <android/gui/FocusRequest.h> |
| Robert Carr | 2c358bf | 2018-08-08 15:58:15 -0700 | [diff] [blame] | 30 | |
| chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 31 | #include <gui/ISurfaceComposer.h> |
| Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 32 | #include <gui/LayerMetadata.h> |
| Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 33 | #include <gui/SurfaceControl.h> |
| chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 34 | #include <gui/WindowInfo.h> |
| chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 35 | #include <math/vec3.h> |
| Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 36 | #include <ui/BlurRegion.h> |
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 37 | #include <ui/GraphicTypes.h> |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 38 | #include <ui/Rect.h> |
| 39 | #include <ui/Region.h> |
| Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 40 | #include <ui/Rotation.h> |
| John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 41 | #include <ui/StretchEffect.h> |
| Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 42 | #include <ui/Transform.h> |
| Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 43 | #include <utils/Errors.h> |
| Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 44 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | namespace android { |
| 46 | |
| 47 | class Parcel; |
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 48 | class ISurfaceComposerClient; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | |
| Marissa Wall | 947d34e | 2019-03-29 14:03:53 -0700 | [diff] [blame] | 50 | struct client_cache_t { |
| 51 | wp<IBinder> token = nullptr; |
| 52 | uint64_t id; |
| 53 | |
| 54 | bool operator==(const client_cache_t& other) const { return id == other.id; } |
| 55 | |
| 56 | bool isValid() const { return token != nullptr; } |
| Marissa Wall | 78b7220 | 2019-03-15 14:58:34 -0700 | [diff] [blame] | 57 | }; |
| 58 | |
| Andy McFadden | 4125a4f | 2014-01-29 17:17:11 -0800 | [diff] [blame] | 59 | /* |
| 60 | * Used to communicate layer information between SurfaceFlinger and its clients. |
| 61 | */ |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | struct layer_state_t { |
| Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 63 | enum { |
| chaviw | c5676c6 | 2020-09-18 15:01:04 -0700 | [diff] [blame] | 64 | eLayerHidden = 0x01, // SURFACE_HIDDEN in SurfaceControl.java |
| 65 | eLayerOpaque = 0x02, // SURFACE_OPAQUE |
| 66 | eLayerSkipScreenshot = 0x40, // SKIP_SCREENSHOT |
| 67 | eLayerSecure = 0x80, // SECURE |
| Vishnu Nair | f6eddb6 | 2021-01-27 22:02:11 -0800 | [diff] [blame] | 68 | // Queue up BufferStateLayer buffers instead of dropping the oldest buffer when this flag is |
| 69 | // set. This blocks the client until all the buffers have been presented. If the buffers |
| 70 | // have presentation timestamps, then we may drop buffers. |
| 71 | eEnableBackpressure = 0x100, // ENABLE_BACKPRESSURE |
| Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | enum { |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 75 | ePositionChanged = 0x00000001, |
| 76 | eLayerChanged = 0x00000002, |
| 77 | eSizeChanged = 0x00000004, |
| 78 | eAlphaChanged = 0x00000008, |
| 79 | eMatrixChanged = 0x00000010, |
| 80 | eTransparentRegionChanged = 0x00000020, |
| 81 | eFlagsChanged = 0x00000040, |
| 82 | eLayerStackChanged = 0x00000080, |
| Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 83 | eReleaseBufferListenerChanged = 0x00000400, |
| Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 84 | eShadowRadiusChanged = 0x00000800, |
| arthurhung | dba591c | 2021-02-08 17:28:49 +0800 | [diff] [blame] | 85 | eLayerCreated = 0x00001000, |
| chaviw | f3f40fe | 2021-04-27 15:54:02 -0500 | [diff] [blame] | 86 | eBufferCropChanged = 0x00002000, |
| Vishnu Nair | dcce0e2 | 2018-08-23 08:35:19 -0700 | [diff] [blame] | 87 | eRelativeLayerChanged = 0x00004000, |
| 88 | eReparent = 0x00008000, |
| 89 | eColorChanged = 0x00010000, |
| 90 | eDestroySurface = 0x00020000, |
| 91 | eTransformChanged = 0x00040000, |
| 92 | eTransformToDisplayInverseChanged = 0x00080000, |
| 93 | eCropChanged = 0x00100000, |
| 94 | eBufferChanged = 0x00200000, |
| 95 | eAcquireFenceChanged = 0x00400000, |
| 96 | eDataspaceChanged = 0x00800000, |
| 97 | eHdrMetadataChanged = 0x01000000, |
| 98 | eSurfaceDamageRegionChanged = 0x02000000, |
| 99 | eApiChanged = 0x04000000, |
| 100 | eSidebandStreamChanged = 0x08000000, |
| Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 101 | eColorTransformChanged = 0x10000000, |
| Marissa Wall | 3dad52d | 2019-03-22 14:03:19 -0700 | [diff] [blame] | 102 | eHasListenerCallbacksChanged = 0x20000000, |
| Robert Carr | 2c358bf | 2018-08-08 15:58:15 -0700 | [diff] [blame] | 103 | eInputInfoChanged = 0x40000000, |
| Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 104 | eCornerRadiusChanged = 0x80000000, |
| Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 105 | eDestinationFrameChanged = 0x1'00000000, |
| Marissa Wall | ebc2c05 | 2019-01-16 19:16:55 -0800 | [diff] [blame] | 106 | eCachedBufferChanged = 0x2'00000000, |
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 107 | eBackgroundColorChanged = 0x4'00000000, |
| 108 | eMetadataChanged = 0x8'00000000, |
| Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 109 | eColorSpaceAgnosticChanged = 0x10'00000000, |
| Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 110 | eFrameRateSelectionPriority = 0x20'00000000, |
| Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 111 | eFrameRateChanged = 0x40'00000000, |
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 112 | eBackgroundBlurRadiusChanged = 0x80'00000000, |
| Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 113 | eProducerDisconnect = 0x100'00000000, |
| Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 114 | eFixedTransformHintChanged = 0x200'00000000, |
| Vishnu Nair | 6b7c5c9 | 2020-09-29 17:27:05 -0700 | [diff] [blame] | 115 | eFrameNumberChanged = 0x400'00000000, |
| Ady Abraham | 8db1010 | 2021-03-15 17:19:23 -0700 | [diff] [blame] | 116 | eBlurRegionsChanged = 0x800'00000000, |
| 117 | eAutoRefreshChanged = 0x1000'00000000, |
| 118 | eStretchChanged = 0x2000'00000000, |
| Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 119 | }; |
| 120 | |
| Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 121 | layer_state_t(); |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | |
| Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 123 | void merge(const layer_state_t& other); |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 124 | status_t write(Parcel& output) const; |
| 125 | status_t read(const Parcel& input); |
| Vishnu Nair | ddf9b5c | 2021-03-29 18:53:41 -0700 | [diff] [blame] | 126 | bool hasBufferChanges() const; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 128 | struct matrix22_t { |
| 129 | float dsdx{0}; |
| 130 | float dtdx{0}; |
| 131 | float dtdy{0}; |
| 132 | float dsdy{0}; |
| chaviw | 308ddba | 2020-08-11 16:23:51 -0700 | [diff] [blame] | 133 | status_t write(Parcel& output) const; |
| 134 | status_t read(const Parcel& input); |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 135 | }; |
| 136 | sp<IBinder> surface; |
| Pablo Gamito | dbc3167 | 2020-09-01 18:28:58 +0000 | [diff] [blame] | 137 | int32_t layerId; |
| Garfield Tan | 8a3083e | 2018-12-03 13:21:07 -0800 | [diff] [blame] | 138 | uint64_t what; |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 139 | float x; |
| 140 | float y; |
| 141 | int32_t z; |
| 142 | uint32_t w; |
| 143 | uint32_t h; |
| 144 | uint32_t layerStack; |
| 145 | float alpha; |
| Vishnu Nair | f6eddb6 | 2021-01-27 22:02:11 -0800 | [diff] [blame] | 146 | uint32_t flags; |
| 147 | uint32_t mask; |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 148 | uint8_t reserved; |
| 149 | matrix22_t matrix; |
| Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 150 | float cornerRadius; |
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 151 | uint32_t backgroundBlurRadius; |
| Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 152 | sp<SurfaceControl> reparentSurfaceControl; |
| Robert Carr | 0d48072 | 2017-01-10 16:42:54 -0800 | [diff] [blame] | 153 | |
| Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 154 | sp<SurfaceControl> relativeLayerSurfaceControl; |
| Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 155 | |
| Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame] | 156 | sp<SurfaceControl> parentSurfaceControlForChild; |
| chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 157 | |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 158 | half3 color; |
| chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 159 | |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 160 | // non POD must be last. see write/read |
| 161 | Region transparentRegion; |
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 162 | |
| 163 | uint32_t transform; |
| 164 | bool transformToDisplayInverse; |
| 165 | Rect crop; |
| Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 166 | Rect orientedDisplaySpaceRect; |
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 167 | sp<GraphicBuffer> buffer; |
| 168 | sp<Fence> acquireFence; |
| 169 | ui::Dataspace dataspace; |
| 170 | HdrMetadata hdrMetadata; |
| 171 | Region surfaceDamageRegion; |
| 172 | int32_t api; |
| 173 | sp<NativeHandle> sidebandStream; |
| Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 174 | mat4 colorTransform; |
| Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 175 | std::vector<BlurRegion> blurRegions; |
| Marissa Wall | c837b5e | 2018-10-12 10:04:44 -0700 | [diff] [blame] | 176 | |
| chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 177 | sp<gui::WindowInfoHandle> windowInfoHandle = new gui::WindowInfoHandle(); |
| Marissa Wall | ebc2c05 | 2019-01-16 19:16:55 -0800 | [diff] [blame] | 178 | |
| Marissa Wall | 947d34e | 2019-03-29 14:03:53 -0700 | [diff] [blame] | 179 | client_cache_t cachedBuffer; |
| Valerie Hau | ed54efa | 2019-01-11 20:03:14 -0800 | [diff] [blame] | 180 | |
| Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 181 | LayerMetadata metadata; |
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 182 | |
| 183 | // The following refer to the alpha, and dataspace, respectively of |
| 184 | // the background color layer |
| 185 | float bgColorAlpha; |
| 186 | ui::Dataspace bgColorDataspace; |
| Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 187 | |
| 188 | // A color space agnostic layer means the color of this layer can be |
| 189 | // interpreted in any color space. |
| 190 | bool colorSpaceAgnostic; |
| Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 191 | |
| 192 | std::vector<ListenerCallbacks> listeners; |
| Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 193 | |
| 194 | // Draws a shadow around the surface. |
| 195 | float shadowRadius; |
| Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 196 | |
| 197 | // Priority of the layer assigned by Window Manager. |
| 198 | int32_t frameRateSelectionPriority; |
| Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 199 | |
| Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 200 | // Layer frame rate and compatibility. See ANativeWindow_setFrameRate(). |
| Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 201 | float frameRate; |
| Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 202 | int8_t frameRateCompatibility; |
| Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 203 | int8_t changeFrameRateStrategy; |
| Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 204 | |
| 205 | // Set by window manager indicating the layer and all its children are |
| 206 | // in a different orientation than the display. The hint suggests that |
| 207 | // the graphic producers should receive a transform hint as if the |
| 208 | // display was in this orientation. When the display changes to match |
| 209 | // the layer orientation, the graphic producer may not need to allocate |
| 210 | // a buffer of a different size. -1 means the transform hint is not set, |
| 211 | // otherwise the value will be a valid ui::Rotation. |
| 212 | ui::Transform::RotationFlags fixedTransformHint; |
| Vishnu Nair | 6b7c5c9 | 2020-09-29 17:27:05 -0700 | [diff] [blame] | 213 | |
| 214 | // Used by BlastBufferQueue to forward the framenumber generated by the |
| 215 | // graphics producer. |
| 216 | uint64_t frameNumber; |
| Robert Carr | 9b611b7 | 2020-10-19 12:00:23 -0700 | [diff] [blame] | 217 | |
| Vishnu Nair | cf26a0a | 2020-11-13 12:56:20 -0800 | [diff] [blame] | 218 | // Indicates that the consumer should acquire the next frame as soon as it |
| 219 | // can and not wait for a frame to become available. This is only relevant |
| 220 | // in shared buffer mode. |
| 221 | bool autoRefresh; |
| John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 222 | |
| 223 | // Stretch effect to be applied to this layer |
| 224 | StretchEffect stretchEffect; |
| Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 225 | |
| chaviw | f3f40fe | 2021-04-27 15:54:02 -0500 | [diff] [blame] | 226 | Rect bufferCrop; |
| Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 227 | Rect destinationFrame; |
| chaviw | f3f40fe | 2021-04-27 15:54:02 -0500 | [diff] [blame] | 228 | |
| Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 229 | // Listens to when the buffer is safe to be released. This is used for blast |
| 230 | // layers only. The callback includes a release fence as well as the graphic |
| 231 | // buffer id to identify the buffer. |
| 232 | sp<ITransactionCompletedListener> releaseBufferListener; |
| Vishnu Nair | 4ba0c2e | 2021-06-24 11:27:17 -0700 | [diff] [blame] | 233 | |
| 234 | // Keeps track of the release callback id associated with the listener. This |
| 235 | // is not sent to the server since the id can be reconstructed there. This |
| 236 | // is used to remove the old callback from the client process map if it is |
| 237 | // overwritten by another setBuffer call. |
| 238 | ReleaseCallbackId releaseCallbackId; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | }; |
| 240 | |
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 241 | struct ComposerState { |
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 242 | layer_state_t state; |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 243 | status_t write(Parcel& output) const; |
| 244 | status_t read(const Parcel& input); |
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 245 | }; |
| 246 | |
| Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 247 | struct DisplayState { |
| Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 248 | enum { |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 249 | eSurfaceChanged = 0x01, |
| 250 | eLayerStackChanged = 0x02, |
| 251 | eDisplayProjectionChanged = 0x04, |
| Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 252 | eDisplaySizeChanged = 0x08, |
| 253 | eFlagsChanged = 0x10 |
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 254 | }; |
| 255 | |
| Pablo Ceballos | 60d6922 | 2015-08-07 14:47:20 -0700 | [diff] [blame] | 256 | DisplayState(); |
| Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 257 | void merge(const DisplayState& other); |
| Pablo Ceballos | 60d6922 | 2015-08-07 14:47:20 -0700 | [diff] [blame] | 258 | |
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 259 | uint32_t what; |
| 260 | sp<IBinder> token; |
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 261 | sp<IGraphicBufferProducer> surface; |
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 262 | uint32_t layerStack; |
| Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 263 | uint32_t flags; |
| Chia-I Wu | ff79ef8 | 2018-08-22 15:27:32 -0700 | [diff] [blame] | 264 | |
| 265 | // These states define how layers are projected onto the physical display. |
| 266 | // |
| Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 267 | // Layers are first clipped to `layerStackSpaceRect'. They are then translated and |
| 268 | // scaled from `layerStackSpaceRect' to `orientedDisplaySpaceRect'. Finally, they are rotated |
| 269 | // according to `orientation', `width', and `height'. |
| Chia-I Wu | ff79ef8 | 2018-08-22 15:27:32 -0700 | [diff] [blame] | 270 | // |
| Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 271 | // For example, assume layerStackSpaceRect is Rect(0, 0, 200, 100), orientedDisplaySpaceRect is |
| 272 | // Rect(20, 10, 420, 210), and the size of the display is WxH. When orientation is 0, layers |
| 273 | // will be scaled by a factor of 2 and translated by (20, 10). When orientation is 1, layers |
| 274 | // will be additionally rotated by 90 degrees around the origin clockwise and translated by (W, |
| 275 | // 0). |
| Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 276 | ui::Rotation orientation = ui::ROTATION_0; |
| Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 277 | Rect layerStackSpaceRect; |
| 278 | Rect orientedDisplaySpaceRect; |
| Chia-I Wu | ff79ef8 | 2018-08-22 15:27:32 -0700 | [diff] [blame] | 279 | |
| Michael Wright | 1f6078a | 2014-06-26 16:01:02 -0700 | [diff] [blame] | 280 | uint32_t width, height; |
| Chia-I Wu | ff79ef8 | 2018-08-22 15:27:32 -0700 | [diff] [blame] | 281 | |
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 282 | status_t write(Parcel& output) const; |
| 283 | status_t read(const Parcel& input); |
| Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 284 | }; |
| 285 | |
| chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 286 | struct InputWindowCommands { |
| chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 287 | std::vector<gui::FocusRequest> focusRequests; |
| chaviw | 291d88a | 2019-02-14 10:33:58 -0800 | [diff] [blame] | 288 | bool syncInputWindows{false}; |
| chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 289 | |
| Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 290 | // Merges the passed in commands and returns true if there were any changes. |
| 291 | bool merge(const InputWindowCommands& other); |
| Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 292 | bool empty() const; |
| chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 293 | void clear(); |
| chaviw | 308ddba | 2020-08-11 16:23:51 -0700 | [diff] [blame] | 294 | status_t write(Parcel& output) const; |
| 295 | status_t read(const Parcel& input); |
| chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 296 | }; |
| 297 | |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 298 | static inline int compare_type(const ComposerState& lhs, const ComposerState& rhs) { |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 299 | if (lhs.state.surface < rhs.state.surface) return -1; |
| 300 | if (lhs.state.surface > rhs.state.surface) return 1; |
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 301 | return 0; |
| 302 | } |
| 303 | |
| Marissa Wall | 1130324 | 2018-07-26 13:36:24 -0700 | [diff] [blame] | 304 | static inline int compare_type(const DisplayState& lhs, const DisplayState& rhs) { |
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 305 | return compare_type(lhs.token, rhs.token); |
| 306 | } |
| 307 | |
| Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 308 | // Returns true if the frameRate is valid. |
| 309 | // |
| 310 | // @param frameRate the frame rate in Hz |
| 311 | // @param compatibility a ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_* |
| Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 312 | // @param changeFrameRateStrategy a ANATIVEWINDOW_CHANGE_FRAME_RATE_* |
| Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 313 | // @param functionName calling function or nullptr. Used for logging |
| 314 | // @param privileged whether caller has unscoped surfaceflinger access |
| Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 315 | bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy, |
| 316 | const char* functionName, bool privileged = false); |
| Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 317 | |
| chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 318 | struct CaptureArgs { |
| chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 319 | const static int32_t UNSET_UID = -1; |
| chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 320 | virtual ~CaptureArgs() = default; |
| 321 | |
| 322 | ui::PixelFormat pixelFormat{ui::PixelFormat::RGBA_8888}; |
| 323 | Rect sourceCrop; |
| chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 324 | float frameScaleX{1}; |
| 325 | float frameScaleY{1}; |
| chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 326 | bool captureSecureLayers{false}; |
| chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 327 | int32_t uid{UNSET_UID}; |
| Peiyong Lin | cd26147 | 2020-10-06 18:05:25 -0700 | [diff] [blame] | 328 | // Force capture to be in a color space. If the value is ui::Dataspace::UNKNOWN, the captured |
| 329 | // result will be in the display's colorspace. |
| arthurhung | 79e81aa | 2020-08-28 00:09:19 +0800 | [diff] [blame] | 330 | // The display may use non-RGB dataspace (ex. displayP3) that could cause pixel data could be |
| Peiyong Lin | cd26147 | 2020-10-06 18:05:25 -0700 | [diff] [blame] | 331 | // different from SRGB (byte per color), and failed when checking colors in tests. |
| 332 | // NOTE: In normal cases, we want the screen to be captured in display's colorspace. |
| 333 | ui::Dataspace dataspace = ui::Dataspace::UNKNOWN; |
| chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 334 | |
| Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 335 | // The receiver of the capture can handle protected buffer. A protected buffer has |
| 336 | // GRALLOC_USAGE_PROTECTED usage bit and must not be accessed unprotected behaviour. |
| 337 | // Any read/write access from unprotected context will result in undefined behaviour. |
| 338 | // Protected contents are typically DRM contents. This has no direct implication to the |
| 339 | // secure property of the surface, which is specified by the application explicitly to avoid |
| 340 | // the contents being accessed/captured by screenshot or unsecure display. |
| 341 | bool allowProtected = false; |
| 342 | |
| chaviw | 17ac24b | 2021-01-28 18:50:05 -0800 | [diff] [blame] | 343 | bool grayscale = false; |
| 344 | |
| chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 345 | virtual status_t write(Parcel& output) const; |
| 346 | virtual status_t read(const Parcel& input); |
| 347 | }; |
| 348 | |
| 349 | struct DisplayCaptureArgs : CaptureArgs { |
| 350 | sp<IBinder> displayToken; |
| 351 | uint32_t width{0}; |
| 352 | uint32_t height{0}; |
| 353 | bool useIdentityTransform{false}; |
| chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 354 | |
| 355 | status_t write(Parcel& output) const override; |
| 356 | status_t read(const Parcel& input) override; |
| 357 | }; |
| 358 | |
| 359 | struct LayerCaptureArgs : CaptureArgs { |
| 360 | sp<IBinder> layerHandle; |
| 361 | std::unordered_set<sp<IBinder>, ISurfaceComposer::SpHash<IBinder>> excludeHandles; |
| chaviw | 70cb6a4 | 2020-07-30 13:57:36 -0700 | [diff] [blame] | 362 | bool childrenOnly{false}; |
| chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 363 | |
| 364 | status_t write(Parcel& output) const override; |
| 365 | status_t read(const Parcel& input) override; |
| 366 | }; |
| 367 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | }; // namespace android |
| 369 | |
| Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 370 | #endif // ANDROID_SF_LAYER_STATE_H |