The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 17 | #pragma once |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 19 | #include <android/gui/DropInputMode.h> |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 20 | #include <android/gui/ISurfaceComposerClient.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 21 | #include <gui/BufferQueue.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 22 | #include <gui/LayerState.h> |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 23 | #include <gui/WindowInfo.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 24 | #include <layerproto/LayerProtoHeader.h> |
| 25 | #include <math/vec4.h> |
| 26 | #include <renderengine/Mesh.h> |
| 27 | #include <renderengine/Texture.h> |
Alec Mouri | 1c8d720 | 2019-06-01 18:51:35 -0700 | [diff] [blame] | 28 | #include <sys/types.h> |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 29 | #include <ui/BlurRegion.h> |
Dan Stoza | 80d6116 | 2017-12-20 15:57:52 -0800 | [diff] [blame] | 30 | #include <ui/FloatRect.h> |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 31 | #include <ui/FrameStats.h> |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 32 | #include <ui/GraphicBuffer.h> |
| 33 | #include <ui/PixelFormat.h> |
| 34 | #include <ui/Region.h> |
John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 35 | #include <ui/StretchEffect.h> |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 36 | #include <ui/Transform.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 37 | #include <utils/RefBase.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 38 | #include <utils/Timers.h> |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 39 | |
Dominik Laskowski | f6b4ba6 | 2021-11-09 12:46:10 -0800 | [diff] [blame] | 40 | #include <compositionengine/LayerFE.h> |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 41 | #include <compositionengine/LayerFECompositionState.h> |
Dominik Laskowski | f6b4ba6 | 2021-11-09 12:46:10 -0800 | [diff] [blame] | 42 | #include <scheduler/Fps.h> |
| 43 | #include <scheduler/Seamlessness.h> |
| 44 | |
KaiChieh Chuang | 948c642 | 2020-10-13 10:38:48 +0800 | [diff] [blame] | 45 | #include <chrono> |
Robert Carr | cdf8320 | 2018-03-07 12:48:34 -0800 | [diff] [blame] | 46 | #include <cstdint> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 47 | #include <list> |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 48 | #include <optional> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 49 | #include <vector> |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 50 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 51 | #include "Client.h" |
Alec Mouri | 1c8d720 | 2019-06-01 18:51:35 -0700 | [diff] [blame] | 52 | #include "DisplayHardware/HWComposer.h" |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 53 | #include "FrameTracker.h" |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 54 | #include "LayerFE.h" |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 55 | #include "LayerVector.h" |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 56 | #include "Scheduler/LayerInfo.h" |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 57 | #include "SurfaceFlinger.h" |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 58 | #include "Tracing/LayerTracing.h" |
Robert Carr | 9a803c3 | 2021-01-14 16:57:58 -0800 | [diff] [blame] | 59 | #include "TransactionCallbackInvoker.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 61 | using namespace android::surfaceflinger; |
| 62 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | namespace android { |
| 64 | |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 65 | class Client; |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 66 | class Colorizer; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 67 | class DisplayDevice; |
| 68 | class GraphicBuffer; |
| 69 | class SurfaceFlinger; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 71 | namespace compositionengine { |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 72 | class OutputLayer; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 73 | struct LayerFECompositionState; |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 74 | } |
| 75 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 76 | namespace gui { |
| 77 | class LayerDebugInfo; |
| 78 | } |
| 79 | |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 80 | namespace frametimeline { |
| 81 | class SurfaceFrame; |
| 82 | } // namespace frametimeline |
| 83 | |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 84 | class Layer : public virtual RefBase { |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 85 | public: |
Ady Abraham | aae5ed5 | 2020-06-26 09:32:43 -0700 | [diff] [blame] | 86 | // The following constants represent priority of the window. SF uses this information when |
| 87 | // deciding which window has a priority when deciding about the refresh rate of the screen. |
| 88 | // Priority 0 is considered the highest priority. -1 means that the priority is unset. |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 89 | static constexpr int32_t PRIORITY_UNSET = -1; |
Ady Abraham | aae5ed5 | 2020-06-26 09:32:43 -0700 | [diff] [blame] | 90 | // Windows that are in focus and voted for the preferred mode ID |
| 91 | static constexpr int32_t PRIORITY_FOCUSED_WITH_MODE = 0; |
| 92 | // // Windows that are in focus, but have not requested a specific mode ID. |
| 93 | static constexpr int32_t PRIORITY_FOCUSED_WITHOUT_MODE = 1; |
| 94 | // Windows that are not in focus, but voted for a specific mode ID. |
| 95 | static constexpr int32_t PRIORITY_NOT_FOCUSED_WITH_MODE = 2; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 96 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 97 | enum { // flags for doTransaction() |
| 98 | eDontUpdateGeometryState = 0x00000001, |
| 99 | eVisibleRegion = 0x00000002, |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 100 | eInputInfoChanged = 0x00000004 |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | struct Geometry { |
| 104 | uint32_t w; |
| 105 | uint32_t h; |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 106 | ui::Transform transform; |
Robert Carr | 3dcabfa | 2016-03-01 18:36:58 -0800 | [diff] [blame] | 107 | |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 108 | inline bool operator==(const Geometry& rhs) const { |
| 109 | return (w == rhs.w && h == rhs.h) && (transform.tx() == rhs.transform.tx()) && |
Robert Carr | 99e27f0 | 2016-06-16 15:18:02 -0700 | [diff] [blame] | 110 | (transform.ty() == rhs.transform.ty()); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 111 | } |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 112 | inline bool operator!=(const Geometry& rhs) const { return !operator==(rhs); } |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 113 | }; |
| 114 | |
Ady Abraham | bdda8f0 | 2021-04-01 16:06:11 -0700 | [diff] [blame] | 115 | using FrameRate = scheduler::LayerInfo::FrameRate; |
| 116 | using FrameRateCompatibility = scheduler::LayerInfo::FrameRateCompatibility; |
Ady Abraham | 71c437d | 2020-01-31 15:56:57 -0800 | [diff] [blame] | 117 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 118 | struct State { |
Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 119 | int32_t z; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 120 | ui::LayerStack layerStack; |
Vishnu Nair | f6eddb6 | 2021-01-27 22:02:11 -0800 | [diff] [blame] | 121 | uint32_t flags; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 122 | int32_t sequence; // changes when visible regions can change |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 123 | bool modified; |
Fabien Sanglard | 4ed383c | 2016-12-13 14:02:41 -0800 | [diff] [blame] | 124 | // Crop is expressed in layer space coordinate. |
chaviw | 2571450 | 2021-02-11 10:01:08 -0800 | [diff] [blame] | 125 | Rect crop; |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 126 | LayerMetadata metadata; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 127 | // If non-null, a Surface this Surface's Z-order is interpreted relative to. |
| 128 | wp<Layer> zOrderRelativeOf; |
chaviw | e5ac40f | 2019-09-24 16:36:55 -0700 | [diff] [blame] | 129 | bool isRelativeOf{false}; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 130 | |
| 131 | // A list of surfaces whose Z-order is interpreted relative to ours. |
| 132 | SortedVector<wp<Layer>> zOrderRelatives; |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 133 | half4 color; |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 134 | float cornerRadius; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 135 | int backgroundBlurRadius; |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 136 | gui::WindowInfo inputInfo; |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 137 | wp<Layer> touchableRegionCrop; |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 138 | |
Valerie Hau | b153bab | 2019-03-05 10:47:28 -0800 | [diff] [blame] | 139 | ui::Dataspace dataspace; |
Vishnu Nair | bc4ee5c | 2022-08-16 03:19:37 +0000 | [diff] [blame] | 140 | bool dataspaceRequested; |
Valerie Hau | b153bab | 2019-03-05 10:47:28 -0800 | [diff] [blame] | 141 | |
Valerie Hau | 134651a | 2020-01-28 16:21:22 -0800 | [diff] [blame] | 142 | uint64_t frameNumber; |
chaviw | 766c9c5 | 2021-02-10 17:36:47 -0800 | [diff] [blame] | 143 | ui::Transform transform; |
chaviw | 766c9c5 | 2021-02-10 17:36:47 -0800 | [diff] [blame] | 144 | uint32_t bufferTransform; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 145 | bool transformToDisplayInverse; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 146 | Region transparentRegionHint; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 147 | std::shared_ptr<renderengine::ExternalTexture> buffer; |
Marissa Wall | 947d34e | 2019-03-29 14:03:53 -0700 | [diff] [blame] | 148 | client_cache_t clientCacheId; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 149 | sp<Fence> acquireFence; |
Ady Abraham | 6c1b7ac | 2021-03-31 16:56:03 -0700 | [diff] [blame] | 150 | std::shared_ptr<FenceTime> acquireFenceTime; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 151 | HdrMetadata hdrMetadata; |
| 152 | Region surfaceDamageRegion; |
| 153 | int32_t api; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 154 | sp<NativeHandle> sidebandStream; |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 155 | mat4 colorTransform; |
Peiyong Lin | 747321c | 2018-10-01 10:03:11 -0700 | [diff] [blame] | 156 | bool hasColorTransform; |
Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 157 | // pointer to background color layer that, if set, appears below the buffer state layer |
| 158 | // and the buffer state layer's children. Z order will be set to |
| 159 | // INT_MIN |
| 160 | sp<Layer> bgColorLayer; |
Valerie Hau | ed54efa | 2019-01-11 20:03:14 -0800 | [diff] [blame] | 161 | |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 162 | // The deque of callback handles for this frame. The back of the deque contains the most |
| 163 | // recent callback handle. |
| 164 | std::deque<sp<CallbackHandle>> callbackHandles; |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 165 | bool colorSpaceAgnostic; |
Ady Abraham | f0c5649 | 2020-12-17 18:04:15 -0800 | [diff] [blame] | 166 | nsecs_t desiredPresentTime = 0; |
| 167 | bool isAutoTimestamp = true; |
Vishnu Nair | 08f6eae | 2019-11-26 14:01:39 -0800 | [diff] [blame] | 168 | |
| 169 | // Length of the cast shadow. If the radius is > 0, a shadow of length shadowRadius will |
| 170 | // be rendered around the layer. |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 171 | float shadowRadius; |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 172 | |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 173 | // Layer regions that are made of custom materials, like frosted glass |
| 174 | std::vector<BlurRegion> blurRegions; |
| 175 | |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 176 | // Priority of the layer assigned by Window Manager. |
| 177 | int32_t frameRateSelectionPriority; |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 178 | |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 179 | // Default frame rate compatibility used to set the layer refresh rate votetype. |
| 180 | FrameRateCompatibility defaultFrameRateCompatibility; |
Ady Abraham | 71c437d | 2020-01-31 15:56:57 -0800 | [diff] [blame] | 181 | FrameRate frameRate; |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 182 | |
Ady Abraham | 59fd8ff | 2021-04-15 20:13:30 -0700 | [diff] [blame] | 183 | // The combined frame rate of parents / children of this layer |
| 184 | FrameRate frameRateForLayerTree; |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 185 | |
| 186 | // Set by window manager indicating the layer and all its children are |
| 187 | // in a different orientation than the display. The hint suggests that |
| 188 | // the graphic producers should receive a transform hint as if the |
| 189 | // display was in this orientation. When the display changes to match |
| 190 | // the layer orientation, the graphic producer may not need to allocate |
| 191 | // a buffer of a different size. ui::Transform::ROT_INVALID means the |
| 192 | // a fixed transform hint is not set. |
| 193 | ui::Transform::RotationFlags fixedTransformHint; |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 194 | |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 195 | // The vsync info that was used to start the transaction |
| 196 | FrameTimelineInfo frameTimelineInfo; |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 197 | |
| 198 | // When the transaction was posted |
| 199 | nsecs_t postTime; |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 200 | sp<ITransactionCompletedListener> releaseBufferListener; |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 201 | // SurfaceFrame that tracks the timeline of Transactions that contain a Buffer. Only one |
| 202 | // such SurfaceFrame exists because only one buffer can be presented on the layer per vsync. |
| 203 | // If multiple buffers are queued, the prior ones will be dropped, along with the |
| 204 | // SurfaceFrame that's tracking them. |
| 205 | std::shared_ptr<frametimeline::SurfaceFrame> bufferSurfaceFrameTX; |
| 206 | // A map of token(frametimelineVsyncId) to the SurfaceFrame that's tracking a transaction |
| 207 | // that contains the token. Only one SurfaceFrame exisits for transactions that share the |
| 208 | // same token, unless they are presented in different vsyncs. |
| 209 | std::unordered_map<int64_t, std::shared_ptr<frametimeline::SurfaceFrame>> |
| 210 | bufferlessSurfaceFramesTX; |
| 211 | // An arbitrary threshold for the number of BufferlessSurfaceFrames in the state. Used to |
| 212 | // trigger a warning if the number of SurfaceFrames crosses the threshold. |
| 213 | static constexpr uint32_t kStateSurfaceFramesThreshold = 25; |
John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 214 | |
| 215 | // Stretch effect to apply to this layer |
| 216 | StretchEffect stretchEffect; |
chaviw | f3f40fe | 2021-04-27 15:54:02 -0500 | [diff] [blame] | 217 | |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 218 | // Whether or not this layer is a trusted overlay for input |
| 219 | bool isTrustedOverlay; |
chaviw | f3f40fe | 2021-04-27 15:54:02 -0500 | [diff] [blame] | 220 | Rect bufferCrop; |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 221 | Rect destinationFrame; |
chaviw | 0b06a8d | 2021-08-06 11:49:08 -0500 | [diff] [blame] | 222 | sp<IBinder> releaseBufferEndpoint; |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 223 | gui::DropInputMode dropInputMode; |
Vishnu Nair | 86653e9 | 2021-11-03 17:19:36 -0700 | [diff] [blame] | 224 | bool autoRefresh = false; |
Sally Qi | 421ffb0 | 2022-03-21 19:41:33 -0700 | [diff] [blame] | 225 | bool dimmingEnabled = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 226 | }; |
| 227 | |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 228 | explicit Layer(const LayerCreationArgs& args); |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 229 | virtual ~Layer(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 231 | static bool isLayerFocusedBasedOnPriority(int32_t priority); |
| 232 | static void miniDumpHeader(std::string& result); |
Dominik Laskowski | 7584836 | 2019-11-11 17:57:20 -0800 | [diff] [blame] | 233 | |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 234 | // Provide unique string for each class type in the Layer hierarchy |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 235 | virtual const char* getType() const { return "Layer"; } |
Dominik Laskowski | f7a09ed | 2019-10-07 13:54:18 -0700 | [diff] [blame] | 236 | |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 237 | // true if this layer is visible, false otherwise |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 238 | virtual bool isVisible() const; |
Chia-I Wu | ab0c319 | 2017-08-01 11:29:00 -0700 | [diff] [blame] | 239 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 240 | virtual sp<Layer> createClone(); |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 241 | |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 242 | // Set a 2x2 transformation matrix on the layer. This transform |
| 243 | // will be applied after parent transforms, but before any final |
| 244 | // producer specified transform. |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 245 | bool setMatrix(const layer_state_t::matrix22_t& matrix); |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 246 | |
| 247 | // This second set of geometry attributes are controlled by |
| 248 | // setGeometryAppliesWithResize, and their default mode is to be |
| 249 | // immediate. If setGeometryAppliesWithResize is specified |
| 250 | // while a resize is pending, then update of these attributes will |
| 251 | // be delayed until the resize completes. |
| 252 | |
| 253 | // setPosition operates in parent buffer space (pre parent-transform) or display |
| 254 | // space for top-level layers. |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 255 | bool setPosition(float x, float y); |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 256 | // Buffer space |
Vishnu Nair | bc4ee5c | 2022-08-16 03:19:37 +0000 | [diff] [blame] | 257 | bool setCrop(const Rect& crop); |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 258 | |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 259 | // TODO(b/38182121): Could we eliminate the various latching modes by |
| 260 | // using the layer hierarchy? |
| 261 | // ----------------------------------------------------------------------- |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 262 | virtual bool setLayer(int32_t z); |
| 263 | virtual bool setRelativeLayer(const sp<IBinder>& relativeToHandle, int32_t relativeZ); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 264 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 265 | virtual bool setAlpha(float alpha); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 266 | bool setColor(const half3& /*color*/); |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 267 | |
| 268 | // Set rounded corner radius for this layer and its children. |
| 269 | // |
| 270 | // We only support 1 radius per layer in the hierarchy, where parent layers have precedence. |
| 271 | // The shape of the rounded corner rectangle is specified by the crop rectangle of the layer |
| 272 | // from which we inferred the rounded corner radius. |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 273 | virtual bool setCornerRadius(float cornerRadius); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 274 | // When non-zero, everything below this layer will be blurred by backgroundBlurRadius, which |
| 275 | // is specified in pixels. |
| 276 | virtual bool setBackgroundBlurRadius(int backgroundBlurRadius); |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 277 | virtual bool setBlurRegions(const std::vector<BlurRegion>& effectRegions); |
Vishnu Nair | ea04b6f | 2022-08-19 21:28:17 +0000 | [diff] [blame] | 278 | bool setTransparentRegionHint(const Region& transparent); |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 279 | virtual bool setTrustedOverlay(bool); |
Vishnu Nair | f6eddb6 | 2021-01-27 22:02:11 -0800 | [diff] [blame] | 280 | virtual bool setFlags(uint32_t flags, uint32_t mask); |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 281 | virtual bool setLayerStack(ui::LayerStack); |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 282 | virtual ui::LayerStack getLayerStack( |
| 283 | LayerVector::StateSet state = LayerVector::StateSet::Drawing) const; |
| 284 | |
Evan Rosky | ef876c9 | 2019-01-25 17:46:06 -0800 | [diff] [blame] | 285 | virtual bool setMetadata(const LayerMetadata& data); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 286 | virtual void setChildrenDrawingParent(const sp<Layer>&); |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 287 | virtual bool reparent(const sp<IBinder>& newParentHandle); |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 288 | virtual bool setColorTransform(const mat4& matrix); |
| 289 | virtual mat4 getColorTransform() const; |
| 290 | virtual bool hasColorTransform() const; |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 291 | virtual bool isColorSpaceAgnostic() const { return mDrawingState.colorSpaceAgnostic; } |
Sally Qi | 421ffb0 | 2022-03-21 19:41:33 -0700 | [diff] [blame] | 292 | virtual bool isDimmingEnabled() const { return getDrawingState().dimmingEnabled; }; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 293 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 294 | bool setTransform(uint32_t /*transform*/); |
| 295 | bool setTransformToDisplayInverse(bool /*transformToDisplayInverse*/); |
| 296 | bool setBuffer(std::shared_ptr<renderengine::ExternalTexture>& /* buffer */, |
| 297 | const BufferData& /* bufferData */, nsecs_t /* postTime */, |
| 298 | nsecs_t /*desiredPresentTime*/, bool /*isAutoTimestamp*/, |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 299 | std::optional<nsecs_t> /* dequeueTime */, const FrameTimelineInfo& /*info*/); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 300 | bool setDataspace(ui::Dataspace /*dataspace*/); |
| 301 | bool setHdrMetadata(const HdrMetadata& /*hdrMetadata*/); |
| 302 | bool setSurfaceDamageRegion(const Region& /*surfaceDamage*/); |
| 303 | bool setApi(int32_t /*api*/); |
| 304 | bool setSidebandStream(const sp<NativeHandle>& /*sidebandStream*/); |
| 305 | bool setTransactionCompletedListeners(const std::vector<sp<CallbackHandle>>& /*handles*/); |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 306 | virtual bool setBackgroundColor(const half3& color, float alpha, ui::Dataspace dataspace); |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 307 | virtual bool setColorSpaceAgnostic(const bool agnostic); |
Sally Qi | 421ffb0 | 2022-03-21 19:41:33 -0700 | [diff] [blame] | 308 | virtual bool setDimmingEnabled(const bool dimmingEnabled); |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 309 | virtual bool setDefaultFrameRateCompatibility(FrameRateCompatibility compatibility); |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 310 | virtual bool setFrameRateSelectionPriority(int32_t priority); |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 311 | virtual bool setFixedTransformHint(ui::Transform::RotationFlags fixedTransformHint); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 312 | void setAutoRefresh(bool /* autoRefresh */); |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 313 | bool setDropInputMode(gui::DropInputMode); |
| 314 | |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 315 | // If the variable is not set on the layer, it traverses up the tree to inherit the frame |
| 316 | // rate priority from its parent. |
| 317 | virtual int32_t getFrameRateSelectionPriority() const; |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 318 | // |
| 319 | virtual FrameRateCompatibility getDefaultFrameRateCompatibility() const; |
| 320 | // |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 321 | ui::Dataspace getDataSpace() const; |
| 322 | ui::Dataspace getRequestedDataSpace() const; |
Chia-I Wu | 01591c9 | 2018-05-22 12:03:00 -0700 | [diff] [blame] | 323 | |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 324 | virtual sp<LayerFE> getCompositionEngineLayerFE() const; |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 325 | virtual sp<LayerFE> copyCompositionEngineLayerFE() const; |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 326 | |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 327 | const LayerSnapshot* getLayerSnapshot() const; |
| 328 | LayerSnapshot* editLayerSnapshot(); |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 329 | |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 330 | // If we have received a new buffer this frame, we will pass its surface |
| 331 | // damage down to hardware composer. Otherwise, we must send a region with |
| 332 | // one empty rect. |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 333 | void useSurfaceDamage(); |
| 334 | void useEmptyDamage(); |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 335 | Region getVisibleRegion(const DisplayDevice*) const; |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 336 | |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 337 | /* |
| 338 | * isOpaque - true if this surface is opaque |
| 339 | * |
| 340 | * This takes into account the buffer format (i.e. whether or not the |
| 341 | * pixel format includes an alpha channel) and the "opaque" flag set |
| 342 | * on the layer. It does not examine the current plane alpha value. |
| 343 | */ |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 344 | bool isOpaque(const Layer::State&) const; |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 345 | |
| 346 | /* |
| 347 | * Returns whether this layer can receive input. |
| 348 | */ |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 349 | bool canReceiveInput() const; |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 350 | |
| 351 | /* |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 352 | * isProtected - true if the layer may contain protected contents in the |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 353 | * GRALLOC_USAGE_PROTECTED sense. |
| 354 | */ |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 355 | bool isProtected() const; |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 356 | |
| 357 | /* |
| 358 | * isFixedSize - true if content has a fixed size |
| 359 | */ |
| 360 | virtual bool isFixedSize() const { return true; } |
| 361 | |
| 362 | /* |
| 363 | * usesSourceCrop - true if content should use a source crop |
| 364 | */ |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 365 | bool usesSourceCrop() const { return hasBufferOrSidebandStream(); } |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 366 | |
| 367 | // Most layers aren't created from the main thread, and therefore need to |
| 368 | // grab the SF state lock to access HWC, but ContainerLayer does, so we need |
| 369 | // to avoid grabbing the lock again to avoid deadlock |
| 370 | virtual bool isCreatedFromMainThread() const { return false; } |
| 371 | |
chaviw | 4e76553 | 2021-04-30 12:11:39 -0500 | [diff] [blame] | 372 | ui::Transform getActiveTransform(const Layer::State& s) const { return s.transform; } |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 373 | Region getActiveTransparentRegion(const Layer::State& s) const { |
| 374 | return s.transparentRegionHint; |
| 375 | } |
Vishnu Nair | bc4ee5c | 2022-08-16 03:19:37 +0000 | [diff] [blame] | 376 | Rect getCrop(const Layer::State& s) const { return s.crop; } |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 377 | bool needsFiltering(const DisplayDevice*) const; |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 378 | |
| 379 | // True if this layer requires filtering |
| 380 | // This method is distinct from needsFiltering() in how the filter |
| 381 | // requirement is computed. needsFiltering() compares displayFrame and crop, |
| 382 | // where as this method transforms the displayFrame to layer-stack space |
| 383 | // first. This method should be used if there is no physical display to |
| 384 | // project onto when taking screenshots, as the filtering requirements are |
| 385 | // different. |
| 386 | // If the parent transform needs to be undone when capturing the layer, then |
| 387 | // the inverse parent transform is also required. |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 388 | bool needsFilteringForScreenshots(const DisplayDevice*, const ui::Transform&) const; |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 389 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 390 | // from graphics API |
| 391 | ui::Dataspace translateDataspace(ui::Dataspace dataspace); |
| 392 | void updateCloneBufferInfo(); |
| 393 | uint64_t mPreviousFrameNumber = 0; |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 394 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 395 | bool isHdrY410() const; |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 396 | |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 397 | /* |
| 398 | * called after composition. |
| 399 | * returns true if the layer latched a new buffer this frame. |
| 400 | */ |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 401 | void onPostComposition(const DisplayDevice*, const std::shared_ptr<FenceTime>& /*glDoneFence*/, |
| 402 | const std::shared_ptr<FenceTime>& /*presentFence*/, |
| 403 | const CompositorTiming&); |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 404 | |
| 405 | // If a buffer was replaced this frame, release the former buffer |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 406 | void releasePendingBuffer(nsecs_t /*dequeueReadyTime*/); |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 407 | |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 408 | /* |
| 409 | * latchBuffer - called each time the screen is redrawn and returns whether |
| 410 | * the visible regions need to be recomputed (this is a fairly heavy |
| 411 | * operation, so this should be set only if needed). Typically this is used |
| 412 | * to figure out if the content or size of a surface has changed. |
| 413 | */ |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 414 | bool latchBuffer(bool& /*recomputeVisibleRegions*/, nsecs_t /*latchTime*/); |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 415 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 416 | /* |
| 417 | * Calls latchBuffer if the buffer has a frame queued and then releases the buffer. |
| 418 | * This is used if the buffer is just latched and releases to free up the buffer |
| 419 | * and will not be shown on screen. |
| 420 | * Should only be called on the main thread. |
| 421 | */ |
| 422 | void latchAndReleaseBuffer(); |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 423 | |
| 424 | /* |
| 425 | * returns the rectangle that crops the content of the layer and scales it |
| 426 | * to the layer's size. |
| 427 | */ |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 428 | Rect getBufferCrop() const; |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 429 | |
| 430 | /* |
| 431 | * Returns the transform applied to the buffer. |
| 432 | */ |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 433 | uint32_t getBufferTransform() const; |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 434 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 435 | sp<GraphicBuffer> getBuffer() const; |
| 436 | const std::shared_ptr<renderengine::ExternalTexture>& getExternalTexture() const; |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 437 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 438 | ui::Transform::RotationFlags getTransformHint() const { return mTransformHint; } |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 439 | |
| 440 | /* |
| 441 | * Returns if a frame is ready |
| 442 | */ |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 443 | bool hasReadyFrame() const; |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 444 | |
| 445 | virtual int32_t getQueuedFrameCount() const { return 0; } |
| 446 | |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 447 | /** |
| 448 | * Returns active buffer size in the correct orientation. Buffer size is determined by undoing |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 449 | * any buffer transformations. Returns Rect::INVALID_RECT if the layer has no buffer or the |
| 450 | * layer does not have a display frame and its parent is not bounded. |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 451 | */ |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 452 | Rect getBufferSize(const Layer::State&) const; |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 453 | |
| 454 | /** |
| 455 | * Returns the source bounds. If the bounds are not defined, it is inferred from the |
| 456 | * buffer size. Failing that, the bounds are determined from the passed in parent bounds. |
| 457 | * For the root layer, this is the display viewport size. |
| 458 | */ |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 459 | FloatRect computeSourceBounds(const FloatRect& parentBounds) const; |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 460 | virtual FrameRate getFrameRateForLayerTree() const; |
| 461 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 462 | bool getTransformToDisplayInverse() const; |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 463 | |
| 464 | // Returns how rounded corners should be drawn for this layer. |
Vishnu Nair | 9dbf8e8 | 2021-09-16 16:24:47 -0700 | [diff] [blame] | 465 | // A layer can override its parent's rounded corner settings if the parent's rounded |
| 466 | // corner crop does not intersect with its own rounded corner crop. |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 467 | virtual RoundedCornerState getRoundedCornerState() const; |
| 468 | |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 469 | bool hasRoundedCorners() const { return getRoundedCornerState().hasRoundedCorners(); } |
Leon Scroggins III | f8a1831 | 2021-04-01 16:38:25 -0400 | [diff] [blame] | 470 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 471 | PixelFormat getPixelFormat() const; |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 472 | /** |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 473 | * Return whether this layer needs an input info. We generate InputWindowHandles for all |
| 474 | * non-cursor buffered layers regardless of whether they have an InputChannel. This is to enable |
| 475 | * the InputDispatcher to do PID based occlusion detection. |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 476 | */ |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 477 | bool needsInputInfo() const { |
| 478 | return (hasInputInfo() || hasBufferOrSidebandStream()) && !mPotentialCursor; |
| 479 | } |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 480 | |
| 481 | // Implements RefBase. |
| 482 | void onFirstRef() override; |
| 483 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 484 | struct BufferInfo { |
| 485 | nsecs_t mDesiredPresentTime; |
| 486 | std::shared_ptr<FenceTime> mFenceTime; |
| 487 | sp<Fence> mFence; |
| 488 | uint32_t mTransform{0}; |
| 489 | ui::Dataspace mDataspace{ui::Dataspace::UNKNOWN}; |
| 490 | Rect mCrop; |
| 491 | uint32_t mScaleMode{NATIVE_WINDOW_SCALING_MODE_FREEZE}; |
| 492 | Region mSurfaceDamage; |
| 493 | HdrMetadata mHdrMetadata; |
| 494 | int mApi; |
| 495 | PixelFormat mPixelFormat{PIXEL_FORMAT_NONE}; |
| 496 | bool mTransformToDisplayInverse{false}; |
| 497 | |
| 498 | std::shared_ptr<renderengine::ExternalTexture> mBuffer; |
| 499 | uint64_t mFrameNumber; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 500 | |
| 501 | bool mFrameLatencyNeeded{false}; |
| 502 | }; |
| 503 | |
| 504 | BufferInfo mBufferInfo; |
| 505 | |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 506 | // implements compositionengine::LayerFE |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 507 | const compositionengine::LayerFECompositionState* getCompositionState() const; |
| 508 | bool fenceHasSignaled() const; |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 509 | bool onPreComposition(nsecs_t refreshStartTime); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 510 | void onLayerDisplayed(ftl::SharedFuture<FenceResult>); |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 511 | |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 512 | void setWasClientComposed(const sp<Fence>& fence) { |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 513 | mLastClientCompositionFence = fence; |
Robert Carr | 05da008 | 2022-05-25 23:29:34 -0700 | [diff] [blame] | 514 | mClearClientCompositionFenceOnLayerDisplayed = false; |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 517 | const char* getDebugName() const; |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 518 | |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 519 | bool setShadowRadius(float shadowRadius); |
| 520 | |
| 521 | // Before color management is introduced, contents on Android have to be |
| 522 | // desaturated in order to match what they appears like visually. |
| 523 | // With color management, these contents will appear desaturated, thus |
| 524 | // needed to be saturated so that they match what they are designed for |
| 525 | // visually. |
| 526 | bool isLegacyDataSpace() const; |
| 527 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 528 | uint32_t getTransactionFlags() const { return mTransactionFlags; } |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 529 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame^] | 530 | static bool computeTrustedPresentationState(const FloatRect& bounds, |
| 531 | const FloatRect& sourceBounds, |
| 532 | const Region& coveredRegion, |
| 533 | const FloatRect& screenBounds, float, |
| 534 | const ui::Transform&, |
| 535 | const TrustedPresentationThresholds&); |
| 536 | void updateTrustedPresentationState(const DisplayDevice* display, int64_t time_in_ms, |
| 537 | bool leaveState); |
| 538 | |
| 539 | inline bool hasTrustedPresentationListener() { |
| 540 | return mTrustedPresentationListener.callbackInterface != nullptr; |
| 541 | } |
| 542 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 543 | // Sets the masked bits. |
| 544 | void setTransactionFlags(uint32_t mask); |
| 545 | |
| 546 | // Clears and returns the masked bits. |
| 547 | uint32_t clearTransactionFlags(uint32_t mask); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 548 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 549 | FloatRect getBounds(const Region& activeTransparentRegion) const; |
| 550 | FloatRect getBounds() const; |
| 551 | |
| 552 | // Compute bounds for the layer and cache the results. |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 553 | void computeBounds(FloatRect parentBounds, ui::Transform parentTransform, float shadowRadius); |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 554 | |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 555 | int32_t getSequence() const { return sequence; } |
Pablo Ceballos | 40845df | 2016-01-25 17:41:15 -0800 | [diff] [blame] | 556 | |
Mikael Pessa | 2e1608f | 2019-07-19 11:25:35 -0700 | [diff] [blame] | 557 | // For tracing. |
| 558 | // TODO: Replace with raw buffer id from buffer metadata when that becomes available. |
| 559 | // GraphicBuffer::getId() does not provide a reliable global identifier. Since the traces |
| 560 | // creates its tracks by buffer id and has no way of associating a buffer back to the process |
| 561 | // that created it, the current implementation is only sufficient for cases where a buffer is |
| 562 | // only used within a single layer. |
chaviw | d62d306 | 2019-09-04 14:48:02 -0700 | [diff] [blame] | 563 | uint64_t getCurrentBufferId() const { return getBuffer() ? getBuffer()->getId() : 0; } |
Mikael Pessa | 2e1608f | 2019-07-19 11:25:35 -0700 | [diff] [blame] | 564 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 565 | /* |
| 566 | * isSecure - true if this surface is secure, that is if it prevents |
Peiyong Lin | 05cc011 | 2020-10-14 16:16:37 -0700 | [diff] [blame] | 567 | * screenshots or VNC servers. A surface can be set to be secure by the |
| 568 | * application, being secure doesn't mean the surface has DRM contents. |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 569 | */ |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 570 | bool isSecure() const; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 571 | |
| 572 | /* |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 573 | * isHiddenByPolicy - true if this layer has been forced invisible. |
| 574 | * just because this is false, doesn't mean isVisible() is true. |
| 575 | * For example if this layer has no active buffer, it may not be hidden by |
| 576 | * policy, but it still can not be visible. |
| 577 | */ |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 578 | bool isHiddenByPolicy() const; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 579 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 580 | // True if the layer should be skipped in screenshots, screen recordings, |
| 581 | // and mirroring to external or virtual displays. |
| 582 | bool isInternalDisplayOverlay() const; |
| 583 | |
| 584 | ui::LayerFilter getOutputFilter() const { |
| 585 | return {getLayerStack(), isInternalDisplayOverlay()}; |
| 586 | } |
| 587 | |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 588 | bool isRemovedFromCurrentState() const; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 589 | |
Vishnu Nair | d8f5e9f | 2022-02-03 10:23:28 -0800 | [diff] [blame] | 590 | LayerProto* writeToProto(LayersProto& layersProto, uint32_t traceFlags); |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 591 | |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 592 | // Write states that are modified by the main thread. This includes drawing |
| 593 | // state as well as buffer data. This should be called in the main or tracing |
| 594 | // thread. |
Vishnu Nair | d8f5e9f | 2022-02-03 10:23:28 -0800 | [diff] [blame] | 595 | void writeToProtoDrawingState(LayerProto* layerInfo); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 596 | // Write drawing or current state. If writing current state, the caller should hold the |
| 597 | // external mStateLock. If writing drawing state, this function should be called on the |
| 598 | // main or tracing thread. |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 599 | void writeToProtoCommonState(LayerProto* layerInfo, LayerVector::StateSet, |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 600 | uint32_t traceFlags = LayerTracing::TRACE_ALL); |
Yiwei Zhang | 7124ad3 | 2018-02-21 13:02:45 -0800 | [diff] [blame] | 601 | |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 602 | gui::WindowInfo::Type getWindowType() const { return mWindowType; } |
Peiyong Lin | 97067b0 | 2019-03-29 17:34:45 +0000 | [diff] [blame] | 603 | |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 604 | void updateMirrorInfo(); |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 605 | |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 606 | /* |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 607 | * doTransaction - process the transaction. This is a good place to figure |
| 608 | * out which attributes of the surface have changed. |
| 609 | */ |
Robert Carr | 7121caf | 2020-12-15 13:07:32 -0800 | [diff] [blame] | 610 | virtual uint32_t doTransaction(uint32_t transactionFlags); |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 611 | |
| 612 | /* |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 613 | * Remove relative z for the layer if its relative parent is not part of the |
| 614 | * provided layer tree. |
| 615 | */ |
| 616 | void removeRelativeZ(const std::vector<Layer*>& layersInTree); |
| 617 | |
| 618 | /* |
| 619 | * Remove from current state and mark for removal. |
| 620 | */ |
| 621 | void removeFromCurrentState(); |
| 622 | |
| 623 | /* |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 624 | * called with the state lock from a binder thread when the layer is |
Chia-I Wu | c665702 | 2017-08-15 11:18:17 -0700 | [diff] [blame] | 625 | * removed from the current list to the pending removal list |
| 626 | */ |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 627 | void onRemovedFromCurrentState(); |
Chia-I Wu | c665702 | 2017-08-15 11:18:17 -0700 | [diff] [blame] | 628 | |
chaviw | 61626f2 | 2018-11-15 16:26:27 -0800 | [diff] [blame] | 629 | /* |
| 630 | * Called when the layer is added back to the current state list. |
| 631 | */ |
| 632 | void addToCurrentState(); |
| 633 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 634 | /* |
| 635 | * Sets display transform hint on BufferLayerConsumer. |
| 636 | */ |
| 637 | void updateTransformHint(ui::Transform::RotationFlags); |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 638 | void skipReportingTransformHint(); |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 639 | inline const State& getDrawingState() const { return mDrawingState; } |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 640 | inline State& getDrawingState() { return mDrawingState; } |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 641 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 642 | gui::LayerDebugInfo getLayerDebugInfo(const DisplayDevice*) const; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 643 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 644 | void miniDump(std::string& result, const DisplayDevice&) const; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 645 | void dumpFrameStats(std::string& result) const; |
Vishnu Nair | 76554eb | 2022-12-09 03:38:36 +0000 | [diff] [blame] | 646 | void dumpOffscreenDebugInfo(std::string& result) const; |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 647 | void clearFrameStats(); |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 648 | void logFrameStats(); |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 649 | void getFrameStats(FrameStats* outStats) const; |
Brian Anderson | 5ea5e59 | 2016-12-01 16:54:33 -0800 | [diff] [blame] | 650 | void onDisconnect(); |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 651 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 652 | ui::Transform getTransform() const; |
Garfield Tan | 2c1782c | 2022-02-16 15:25:05 -0800 | [diff] [blame] | 653 | bool isTransformValid() const; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 654 | |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 655 | // Returns the Alpha of the Surface, accounting for the Alpha |
| 656 | // of parent Surfaces in the hierarchy (alpha's will be multiplied |
| 657 | // down the hierarchy). |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 658 | half getAlpha() const; |
| 659 | half4 getColor() const; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 660 | int32_t getBackgroundBlurRadius() const; |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 661 | bool drawShadows() const { return mEffectiveShadowRadius > 0.f; }; |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 662 | |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 663 | // Returns the transform hint set by Window Manager on the layer or one of its parents. |
| 664 | // This traverses the current state because the data is needed when creating |
| 665 | // the layer(off drawing thread) and the hint should be available before the producer |
| 666 | // is ready to acquire a buffer. |
| 667 | ui::Transform::RotationFlags getFixedTransformHint() const; |
| 668 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 669 | /** |
| 670 | * Traverse this layer and it's hierarchy of children directly. Unlike traverseInZOrder |
| 671 | * which will not emit children who have relativeZOrder to another layer, this method |
| 672 | * just directly emits all children. It also emits them in no particular order. |
| 673 | * So this method is not suitable for graphical operations, as it doesn't represent |
| 674 | * the scene state, but it's also more efficient than traverseInZOrder and so useful for |
| 675 | * book-keeping. |
| 676 | */ |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 677 | void traverse(LayerVector::StateSet, const LayerVector::Visitor&); |
| 678 | void traverseInReverseZOrder(LayerVector::StateSet, const LayerVector::Visitor&); |
| 679 | void traverseInZOrder(LayerVector::StateSet, const LayerVector::Visitor&); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 680 | |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 681 | /** |
| 682 | * Traverse only children in z order, ignoring relative layers that are not children of the |
| 683 | * parent. |
| 684 | */ |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 685 | void traverseChildrenInZOrder(LayerVector::StateSet, const LayerVector::Visitor&); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 686 | |
Chia-I Wu | 98f1c10 | 2017-05-30 14:54:08 -0700 | [diff] [blame] | 687 | size_t getChildrenCount() const; |
Valerie Hau | c568680 | 2019-11-22 14:18:09 -0800 | [diff] [blame] | 688 | |
| 689 | // ONLY CALL THIS FROM THE LAYER DTOR! |
| 690 | // See b/141111965. We need to add current children to offscreen layers in |
| 691 | // the layer dtor so as not to dangle layers. Since the layer has not |
| 692 | // committed its transaction when the layer is destroyed, we must add |
| 693 | // current children. This is safe in the dtor as we will no longer update |
| 694 | // the current state, but should not be called anywhere else! |
| 695 | LayerVector& getCurrentChildren() { return mCurrentChildren; } |
| 696 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 697 | void addChild(const sp<Layer>&); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 698 | // Returns index if removed, or negative value otherwise |
| 699 | // for symmetry with Vector::remove |
| 700 | ssize_t removeChild(const sp<Layer>& layer); |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 701 | sp<Layer> getParent() const { return mCurrentParent.promote(); } |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 702 | |
| 703 | // Should be called with the surfaceflinger statelock held |
| 704 | bool isAtRoot() const { return mIsAtRoot; } |
| 705 | void setIsAtRoot(bool isAtRoot) { mIsAtRoot = isAtRoot; } |
| 706 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 707 | bool hasParent() const { return getParent() != nullptr; } |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 708 | Rect getScreenBounds(bool reduceTransparentRegion = true) const; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 709 | bool setChildLayer(const sp<Layer>& childLayer, int32_t z); |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 710 | bool setChildRelativeLayer(const sp<Layer>& childLayer, |
| 711 | const sp<IBinder>& relativeToHandle, int32_t relativeZ); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 712 | |
| 713 | // Copy the current list of children to the drawing state. Called by |
| 714 | // SurfaceFlinger to complete a transaction. |
| 715 | void commitChildList(); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 716 | int32_t getZ(LayerVector::StateSet) const; |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 717 | |
Vishnu Nair | efc42e2 | 2019-12-03 17:36:12 -0800 | [diff] [blame] | 718 | /** |
| 719 | * Returns the cropped buffer size or the layer crop if the layer has no buffer. Return |
| 720 | * INVALID_RECT if the layer has no buffer and no crop. |
| 721 | * A layer with an invalid buffer size and no crop is considered to be boundless. The layer |
| 722 | * bounds are constrained by its parent bounds. |
| 723 | */ |
| 724 | Rect getCroppedBufferSize(const Layer::State& s) const; |
| 725 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 726 | bool setFrameRate(FrameRate); |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 727 | |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 728 | virtual void setFrameTimelineInfoForBuffer(const FrameTimelineInfo& /*info*/) {} |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 729 | void setFrameTimelineVsyncForBufferTransaction(const FrameTimelineInfo& info, nsecs_t postTime); |
| 730 | void setFrameTimelineVsyncForBufferlessTransaction(const FrameTimelineInfo& info, |
| 731 | nsecs_t postTime); |
| 732 | |
| 733 | void addSurfaceFrameDroppedForBuffer( |
| 734 | std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame); |
| 735 | void addSurfaceFramePresentedForBuffer( |
| 736 | std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame, nsecs_t acquireFenceTime, |
| 737 | nsecs_t currentLatchTime); |
| 738 | |
| 739 | std::shared_ptr<frametimeline::SurfaceFrame> createSurfaceFrameForTransaction( |
| 740 | const FrameTimelineInfo& info, nsecs_t postTime); |
| 741 | std::shared_ptr<frametimeline::SurfaceFrame> createSurfaceFrameForBuffer( |
| 742 | const FrameTimelineInfo& info, nsecs_t queueTime, std::string debugName); |
Ady Abraham | 74e1756 | 2020-08-24 18:18:19 -0700 | [diff] [blame] | 743 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame^] | 744 | void setTrustedPresentationInfo(TrustedPresentationThresholds const& thresholds, |
| 745 | TrustedPresentationListener const& listener); |
| 746 | |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 747 | // Creates a new handle each time, so we only expect |
| 748 | // this to be called once. |
| 749 | sp<IBinder> getHandle(); |
| 750 | const std::string& getName() const { return mName; } |
| 751 | bool getPremultipledAlpha() const; |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 752 | void setInputInfo(const gui::WindowInfo& info); |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 753 | |
Prabir Pradhan | da0f62c | 2022-07-22 19:53:04 +0000 | [diff] [blame] | 754 | struct InputDisplayArgs { |
| 755 | const ui::Transform* transform = nullptr; |
| 756 | bool isSecure = false; |
| 757 | }; |
| 758 | gui::WindowInfo fillInputInfo(const InputDisplayArgs& displayArgs); |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 759 | |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 760 | /** |
| 761 | * Returns whether this layer has an explicitly set input-info. |
| 762 | */ |
| 763 | bool hasInputInfo() const; |
| 764 | |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 765 | // Sets the GameMode for the tree rooted at this layer. A layer in the tree inherits this |
| 766 | // GameMode unless it (or an ancestor) has GAME_MODE_METADATA. |
| 767 | void setGameModeForTree(GameMode); |
| 768 | |
| 769 | void setGameMode(GameMode gameMode) { mGameMode = gameMode; } |
| 770 | GameMode getGameMode() const { return mGameMode; } |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 771 | |
Ady Abraham | 62a0be2 | 2020-12-08 16:54:10 -0800 | [diff] [blame] | 772 | virtual uid_t getOwnerUid() const { return mOwnerUid; } |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 773 | |
Adithya Srinivasan | 9febda8 | 2020-10-19 10:49:41 -0700 | [diff] [blame] | 774 | pid_t getOwnerPid() { return mOwnerPid; } |
| 775 | |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 776 | // This layer is not a clone, but it's the parent to the cloned hierarchy. The |
| 777 | // variable mClonedChild represents the top layer that will be cloned so this |
| 778 | // layer will be the parent of mClonedChild. |
| 779 | // The layers in the cloned hierarchy will match the lifetime of the real layers. That is |
| 780 | // if the real layer is destroyed, then the clone layer will also be destroyed. |
| 781 | sp<Layer> mClonedChild; |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 782 | bool mHadClonedChild = false; |
| 783 | void setClonedChild(const sp<Layer>& mClonedChild); |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 784 | |
| 785 | mutable bool contentDirty{false}; |
| 786 | Region surfaceDamageRegion; |
| 787 | |
| 788 | // Layer serial number. This gives layers an explicit ordering, so we |
| 789 | // have a stable sort order when their layer stack and Z-order are |
| 790 | // the same. |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 791 | const int32_t sequence; |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 792 | |
| 793 | bool mPendingHWCDestroy{false}; |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 794 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 795 | bool backpressureEnabled() const { |
| 796 | return mDrawingState.flags & layer_state_t::eEnableBackpressure; |
| 797 | } |
Vishnu Nair | f6eddb6 | 2021-01-27 22:02:11 -0800 | [diff] [blame] | 798 | |
John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 799 | bool setStretchEffect(const StretchEffect& effect); |
John Reck | c00c669 | 2021-02-16 11:37:33 -0500 | [diff] [blame] | 800 | StretchEffect getStretchEffect() const; |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 801 | bool enableBorder(bool shouldEnable, float width, const half4& color); |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 802 | bool isBorderEnabled(); |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 803 | float getBorderWidth(); |
| 804 | const half4& getBorderColor(); |
John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 805 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 806 | bool setBufferCrop(const Rect& /* bufferCrop */); |
| 807 | bool setDestinationFrame(const Rect& /* destinationFrame */); |
| 808 | // See mPendingBufferTransactions |
| 809 | void decrementPendingBufferCount(); |
| 810 | std::atomic<int32_t>* getPendingBufferCounter() { return &mPendingBufferTransactions; } |
| 811 | std::string getPendingBufferCounterName() { return mBlastTransactionName; } |
| 812 | bool updateGeometry(); |
Vishnu Nair | 8eda69e | 2021-02-26 10:42:10 -0800 | [diff] [blame] | 813 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 814 | bool simpleBufferUpdate(const layer_state_t&) const; |
| 815 | |
| 816 | static bool isOpaqueFormat(PixelFormat format); |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 817 | |
| 818 | // Updates the LayerSnapshot. This must be called prior to sending layer data to |
| 819 | // CompositionEngine or RenderEngine (i.e. before calling CompositionEngine::present or |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 820 | // LayerFE::prepareClientComposition). |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 821 | // |
| 822 | // TODO(b/238781169) Remove direct calls to RenderEngine::drawLayers that don't go through |
| 823 | // CompositionEngine to create a single path for composing layers. |
Vishnu Nair | ba35410 | 2022-08-01 00:14:18 +0000 | [diff] [blame] | 824 | void updateSnapshot(bool updateGeometry); |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 825 | void updateMetadataSnapshot(const LayerMetadata& parentMetadata); |
| 826 | void updateRelativeMetadataSnapshot(const LayerMetadata& relativeLayerMetadata, |
| 827 | std::unordered_set<Layer*>& visited); |
Ady Abraham | 9dada82 | 2022-02-03 10:26:59 -0800 | [diff] [blame] | 828 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 829 | protected: |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 830 | // For unit tests |
| 831 | friend class TestableSurfaceFlinger; |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 832 | friend class FpsReporterTest; |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 833 | friend class RefreshRateSelectionTest; |
| 834 | friend class SetFrameRateTest; |
Adithya Srinivasan | b238cd5 | 2021-02-04 17:54:05 +0000 | [diff] [blame] | 835 | friend class TransactionFrameTracerTest; |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 836 | friend class TransactionSurfaceFrameTest; |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 837 | |
| 838 | virtual void setInitialValuesForClone(const sp<Layer>& clonedFrom); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 839 | void preparePerFrameCompositionState(); |
| 840 | void preparePerFrameBufferCompositionState(); |
| 841 | void preparePerFrameEffectsCompositionState(); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 842 | virtual void commitTransaction(State& stateToCommit); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 843 | void gatherBufferInfo(); |
| 844 | void onSurfaceFrameCreated(const std::shared_ptr<frametimeline::SurfaceFrame>&); |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 845 | |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 846 | sp<Layer> getClonedFrom() { return mClonedFrom != nullptr ? mClonedFrom.promote() : nullptr; } |
| 847 | bool isClone() { return mClonedFrom != nullptr; } |
| 848 | bool isClonedFromAlive() { return getClonedFrom() != nullptr; } |
| 849 | |
Vishnu Nair | 3bb11d0 | 2021-11-26 09:24:11 -0800 | [diff] [blame] | 850 | void cloneDrawingState(const Layer* from); |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 851 | void updateClonedDrawingState(std::map<sp<Layer>, sp<Layer>>& clonedLayersMap); |
| 852 | void updateClonedChildren(const sp<Layer>& mirrorRoot, |
| 853 | std::map<sp<Layer>, sp<Layer>>& clonedLayersMap); |
| 854 | void updateClonedRelatives(const std::map<sp<Layer>, sp<Layer>>& clonedLayersMap); |
| 855 | void addChildToDrawing(const sp<Layer>&); |
| 856 | void updateClonedInputInfo(const std::map<sp<Layer>, sp<Layer>>& clonedLayersMap); |
| 857 | |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 858 | void prepareBasicGeometryCompositionState(); |
| 859 | void prepareGeometryCompositionState(); |
| 860 | void prepareCursorCompositionState(); |
| 861 | |
| 862 | uint32_t getEffectiveUsage(uint32_t usage) const; |
| 863 | |
| 864 | /** |
| 865 | * Setup rounded corners coordinates of this layer, taking into account the layer bounds and |
| 866 | * crop coordinates, transforming them into layer space. |
| 867 | */ |
| 868 | void setupRoundedCornersCropCoordinates(Rect win, const FloatRect& roundedCornersCrop) const; |
| 869 | void setParent(const sp<Layer>&); |
| 870 | LayerVector makeTraversalList(LayerVector::StateSet, bool* outSkipRelativeZUsers); |
| 871 | void addZOrderRelative(const wp<Layer>& relative); |
| 872 | void removeZOrderRelative(const wp<Layer>& relative); |
| 873 | compositionengine::OutputLayer* findOutputLayerForDisplay(const DisplayDevice*) const; |
| 874 | bool usingRelativeZ(LayerVector::StateSet) const; |
| 875 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 876 | virtual ui::Transform getInputTransform() const; |
Prabir Pradhan | 6fa425a | 2021-12-16 07:16:04 -0800 | [diff] [blame] | 877 | /** |
| 878 | * Get the bounds in layer space within which this layer can receive input. |
| 879 | * |
| 880 | * These bounds are used to: |
| 881 | * - Determine the input frame for the layer to be used for occlusion detection; and |
| 882 | * - Determine the coordinate space within which the layer will receive input. The top-left of |
| 883 | * this rect will be the origin of the coordinate space that the input events sent to the |
| 884 | * layer will be in (prior to accounting for surface insets). |
| 885 | * |
| 886 | * The layer can still receive touch input if these bounds are invalid if |
| 887 | * "replaceTouchableRegionWithCrop" is specified. In this case, the layer will receive input |
| 888 | * in this layer's space, regardless of the specified crop layer. |
| 889 | */ |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 890 | Rect getInputBounds() const; |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 891 | |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 892 | // constant |
| 893 | sp<SurfaceFlinger> mFlinger; |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 894 | |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 895 | bool mPremultipliedAlpha{true}; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 896 | const std::string mName; |
| 897 | const std::string mTransactionName{"TX - " + mName}; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 898 | |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 899 | // These are only accessed by the main thread or the tracing thread. |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 900 | State mDrawingState; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 901 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame^] | 902 | TrustedPresentationThresholds mTrustedPresentationThresholds; |
| 903 | TrustedPresentationListener mTrustedPresentationListener; |
| 904 | bool mLastComputedTrustedPresentationState = false; |
| 905 | bool mLastReportedTrustedPresentationState = false; |
| 906 | int64_t mEnteredTrustedPresentationStateTime = -1; |
| 907 | |
Robert Carr | 38d2500 | 2021-06-11 14:30:09 -0700 | [diff] [blame] | 908 | uint32_t mTransactionFlags{0}; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 909 | // Updated in doTransaction, used to track the last sequence number we |
| 910 | // committed. Currently this is really only used for updating visible |
| 911 | // regions. |
| 912 | int32_t mLastCommittedTxSequence = -1; |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 913 | |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 914 | // Timestamp history for UIAutomation. Thread safe. |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 915 | FrameTracker mFrameTracker; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 916 | |
| 917 | // main thread |
Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 918 | sp<NativeHandle> mSidebandStream; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 919 | // False if the buffer and its contents have been previously used for GPU |
| 920 | // composition, true otherwise. |
| 921 | bool mIsActiveBufferUpdatedForGpu = true; |
| 922 | |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 923 | // We encode unset as -1. |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 924 | std::atomic<uint64_t> mCurrentFrameNumber{0}; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 925 | // Whether filtering is needed b/c of the drawingstate |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 926 | bool mNeedsFiltering{false}; |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 927 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 928 | std::atomic<bool> mRemovedFromDrawingState{false}; |
chaviw | 8b3871a | 2017-11-01 17:41:01 -0700 | [diff] [blame] | 929 | |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 930 | // page-flip thread (currently main thread) |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 931 | bool mProtectedByApp{false}; // application requires protected path to external sink |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 932 | |
| 933 | // protected by mLock |
| 934 | mutable Mutex mLock; |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 935 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 936 | const wp<Client> mClientRef; |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 937 | |
| 938 | // This layer can be a cursor on some displays. |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 939 | bool mPotentialCursor{false}; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 940 | |
Robert Carr | 88d76cd | 2021-06-22 16:23:51 -0700 | [diff] [blame] | 941 | LayerVector mCurrentChildren{LayerVector::StateSet::Current}; |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 942 | LayerVector mDrawingChildren{LayerVector::StateSet::Drawing}; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 943 | |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 944 | wp<Layer> mCurrentParent; |
| 945 | wp<Layer> mDrawingParent; |
David Sodman | 9eeae69 | 2017-11-02 10:53:32 -0700 | [diff] [blame] | 946 | |
Ady Abraham | 8f1ee7f | 2019-04-05 10:32:50 -0700 | [diff] [blame] | 947 | // Window types from WindowManager.LayoutParams |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 948 | const gui::WindowInfo::Type mWindowType; |
Ady Abraham | 8f1ee7f | 2019-04-05 10:32:50 -0700 | [diff] [blame] | 949 | |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 950 | // The owner of the layer. If created from a non system process, it will be the calling uid. |
| 951 | // If created from a system process, the value can be passed in. |
| 952 | uid_t mOwnerUid; |
| 953 | |
Adithya Srinivasan | 9febda8 | 2020-10-19 10:49:41 -0700 | [diff] [blame] | 954 | // The owner pid of the layer. If created from a non system process, it will be the calling pid. |
| 955 | // If created from a system process, the value can be passed in. |
| 956 | pid_t mOwnerPid; |
| 957 | |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 958 | // Keeps track of the time SF latched the last buffer from this layer. |
| 959 | // Used in buffer stuffing analysis in FrameTimeline. |
| 960 | nsecs_t mLastLatchTime = 0; |
| 961 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 962 | mutable bool mDrawingStateModified = false; |
Robert Carr | 0758e5d | 2021-03-11 22:15:04 -0800 | [diff] [blame] | 963 | |
Robert Carr | ccab424 | 2021-09-28 16:53:03 -0700 | [diff] [blame] | 964 | sp<Fence> mLastClientCompositionFence; |
Robert Carr | 05da008 | 2022-05-25 23:29:34 -0700 | [diff] [blame] | 965 | bool mClearClientCompositionFenceOnLayerDisplayed = false; |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 966 | private: |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 967 | friend class SlotGenerationTest; |
| 968 | friend class TransactionFrameTracerTest; |
| 969 | friend class TransactionSurfaceFrameTest; |
| 970 | |
| 971 | bool getAutoRefresh() const { return mDrawingState.autoRefresh; } |
| 972 | bool getSidebandStreamChanged() const { return mSidebandStreamChanged; } |
| 973 | |
| 974 | std::atomic<bool> mSidebandStreamChanged{false}; |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 975 | |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 976 | // Returns true if the layer can draw shadows on its border. |
| 977 | virtual bool canDrawShadows() const { return true; } |
| 978 | |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 979 | aidl::android::hardware::graphics::composer3::Composition getCompositionType( |
| 980 | const DisplayDevice&) const; |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 981 | |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 982 | /** |
| 983 | * Returns an unsorted vector of all layers that are part of this tree. |
| 984 | * That includes the current layer and all its descendants. |
| 985 | */ |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 986 | std::vector<Layer*> getLayersInTree(LayerVector::StateSet); |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 987 | /** |
| 988 | * Traverses layers that are part of this tree in the correct z order. |
| 989 | * layersInTree must be sorted before calling this method. |
| 990 | */ |
| 991 | void traverseChildrenInZOrderInner(const std::vector<Layer*>& layersInTree, |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 992 | LayerVector::StateSet, const LayerVector::Visitor&); |
| 993 | LayerVector makeChildrenTraversalList(LayerVector::StateSet, |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 994 | const std::vector<Layer*>& layersInTree); |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 995 | |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 996 | void updateTreeHasFrameRateVote(); |
Ady Abraham | a850c18 | 2021-08-04 13:04:37 -0700 | [diff] [blame] | 997 | bool propagateFrameRateForLayerTree(FrameRate parentFrameRate, bool* transactionNeeded); |
| 998 | bool setFrameRateForLayerTree(FrameRate); |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 999 | void setZOrderRelativeOf(const wp<Layer>& relativeOf); |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 1000 | bool isTrustedOverlay() const; |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 1001 | gui::DropInputMode getDropInputMode() const; |
| 1002 | void handleDropInputMode(gui::WindowInfo& info) const; |
Peiyong Lin | f243e5e | 2020-08-22 17:40:59 -0700 | [diff] [blame] | 1003 | |
| 1004 | // Find the root of the cloned hierarchy, this means the first non cloned parent. |
| 1005 | // This will return null if first non cloned parent is not found. |
| 1006 | sp<Layer> getClonedRoot(); |
| 1007 | |
| 1008 | // Finds the top most layer in the hierarchy. This will find the root Layer where the parent is |
| 1009 | // null. |
| 1010 | sp<Layer> getRootLayer(); |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1011 | |
Bernardo Rufino | a9d0a53 | 2021-06-11 15:59:12 +0100 | [diff] [blame] | 1012 | // Fills in the touch occlusion mode of the first parent (including this layer) that |
| 1013 | // hasInputInfo() or no-op if no such parent is found. |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 1014 | void fillTouchOcclusionMode(gui::WindowInfo& info); |
Bernardo Rufino | a9d0a53 | 2021-06-11 15:59:12 +0100 | [diff] [blame] | 1015 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 1016 | // Fills in the frame and transform info for the gui::WindowInfo. |
Prabir Pradhan | c9589c1 | 2021-09-22 06:11:43 -0700 | [diff] [blame] | 1017 | void fillInputFrameInfo(gui::WindowInfo&, const ui::Transform& screenToDisplay); |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 1018 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1019 | inline void tracePendingBufferCount(int32_t pendingBuffers); |
| 1020 | |
| 1021 | // Latch sideband stream and returns true if the dirty region should be updated. |
| 1022 | bool latchSidebandStream(bool& recomputeVisibleRegions); |
| 1023 | |
| 1024 | bool hasFrameUpdate() const; |
| 1025 | |
| 1026 | void updateTexImage(nsecs_t latchTime); |
| 1027 | |
| 1028 | // Crop that applies to the buffer |
| 1029 | Rect computeBufferCrop(const State& s); |
| 1030 | |
| 1031 | bool willPresentCurrentTransaction() const; |
| 1032 | |
| 1033 | // Returns true if the transformed buffer size does not match the layer size and we need |
| 1034 | // to apply filtering. |
| 1035 | bool bufferNeedsFiltering() const; |
| 1036 | |
| 1037 | void callReleaseBufferCallback(const sp<ITransactionCompletedListener>& listener, |
| 1038 | const sp<GraphicBuffer>& buffer, uint64_t framenumber, |
| 1039 | const sp<Fence>& releaseFence, |
| 1040 | uint32_t currentMaxAcquiredBufferCount); |
| 1041 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1042 | // Returns true if there is a valid color to fill. |
| 1043 | bool fillsColor() const; |
| 1044 | // Returns true if this layer has a blur value. |
| 1045 | bool hasBlur() const; |
| 1046 | bool hasEffect() const { return fillsColor() || drawShadows() || hasBlur(); } |
| 1047 | bool hasBufferOrSidebandStream() const { |
| 1048 | return ((mSidebandStream != nullptr) || (mBufferInfo.mBuffer != nullptr)); |
| 1049 | } |
| 1050 | |
Vishnu Nair | 22491b8 | 2022-10-18 14:59:14 -0700 | [diff] [blame] | 1051 | bool hasBufferOrSidebandStreamInDrawing() const { |
| 1052 | return ((mDrawingState.sidebandStream != nullptr) || (mDrawingState.buffer != nullptr)); |
| 1053 | } |
| 1054 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1055 | bool hasSomethingToDraw() const { return hasEffect() || hasBufferOrSidebandStream(); } |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 1056 | |
| 1057 | void updateChildrenSnapshots(bool updateGeometry); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1058 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 1059 | // Cached properties computed from drawing state |
Peiyong Lin | 74861ad | 2020-10-14 11:55:33 -0700 | [diff] [blame] | 1060 | // Effective transform taking into account parent transforms and any parent scaling, which is |
| 1061 | // a transform from the current layer coordinate space to display(screen) coordinate space. |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 1062 | ui::Transform mEffectiveTransform; |
| 1063 | |
| 1064 | // Bounds of the layer before any transformation is applied and before it has been cropped |
| 1065 | // by its parents. |
| 1066 | FloatRect mSourceBounds; |
| 1067 | |
| 1068 | // Bounds of the layer in layer space. This is the mSourceBounds cropped by its layer crop and |
| 1069 | // its parent bounds. |
| 1070 | FloatRect mBounds; |
| 1071 | |
| 1072 | // Layer bounds in screen space. |
| 1073 | FloatRect mScreenBounds; |
chaviw | 606e5cf | 2019-03-01 10:12:10 -0800 | [diff] [blame] | 1074 | |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 1075 | bool mGetHandleCalled = false; |
chaviw | 43cb3cb | 2019-05-31 15:23:41 -0700 | [diff] [blame] | 1076 | |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 1077 | // The current layer is a clone of mClonedFrom. This means that this layer will update it's |
| 1078 | // properties based on mClonedFrom. When mClonedFrom latches a new buffer for BufferLayers, |
| 1079 | // this layer will update it's buffer. When mClonedFrom updates it's drawing state, children, |
| 1080 | // and relatives, this layer will update as well. |
| 1081 | wp<Layer> mClonedFrom; |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 1082 | |
| 1083 | // The inherited shadow radius after taking into account the layer hierarchy. This is the |
| 1084 | // final shadow radius for this layer. If a shadow is specified for a layer, then effective |
| 1085 | // shadow radius is the set shadow radius, otherwise its the parent's shadow radius. |
Vishnu Nair | f37dcfb | 2019-11-16 07:37:09 -0800 | [diff] [blame] | 1086 | float mEffectiveShadowRadius = 0.f; |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 1087 | |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 1088 | // Game mode for the layer. Set by WindowManagerShell and recorded by SurfaceFlingerStats. |
| 1089 | GameMode mGameMode = GameMode::Unsupported; |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 1090 | |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 1091 | // A list of regions on this layer that should have blurs. |
Galia Peycheva | e0acf38 | 2021-04-12 21:22:34 +0200 | [diff] [blame] | 1092 | const std::vector<BlurRegion> getBlurRegions() const; |
Vishnu Nair | 14d218b | 2021-07-13 13:57:39 -0700 | [diff] [blame] | 1093 | |
| 1094 | bool mIsAtRoot = false; |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 1095 | |
| 1096 | uint32_t mLayerCreationFlags; |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 1097 | |
Robert Carr | 88b85e1 | 2022-03-21 15:47:35 -0700 | [diff] [blame] | 1098 | bool findInHierarchy(const sp<Layer>&); |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 1099 | |
| 1100 | bool mBorderEnabled = false; |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 1101 | float mBorderWidth; |
| 1102 | half4 mBorderColor; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1103 | |
| 1104 | void setTransformHint(ui::Transform::RotationFlags); |
| 1105 | |
| 1106 | const uint32_t mTextureName; |
| 1107 | |
| 1108 | // Transform hint provided to the producer. This must be accessed holding |
| 1109 | // the mStateLock. |
| 1110 | ui::Transform::RotationFlags mTransformHint = ui::Transform::ROT_0; |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 1111 | bool mSkipReportingTransformHint = true; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1112 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1113 | ReleaseCallbackId mPreviousReleaseCallbackId = ReleaseCallbackId::INVALID_ID; |
| 1114 | uint64_t mPreviousReleasedFrameNumber = 0; |
| 1115 | |
| 1116 | uint64_t mPreviousBarrierFrameNumber = 0; |
| 1117 | |
| 1118 | bool mReleasePreviousBuffer = false; |
| 1119 | |
| 1120 | // Stores the last set acquire fence signal time used to populate the callback handle's acquire |
| 1121 | // time. |
| 1122 | std::variant<nsecs_t, sp<Fence>> mCallbackHandleAcquireTimeOrFence = -1; |
| 1123 | |
| 1124 | std::deque<std::shared_ptr<android::frametimeline::SurfaceFrame>> mPendingJankClassifications; |
| 1125 | // An upper bound on the number of SurfaceFrames in the pending classifications deque. |
Vishnu Nair | 22491b8 | 2022-10-18 14:59:14 -0700 | [diff] [blame] | 1126 | static constexpr int kPendingClassificationMaxSurfaceFrames = 50; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 1127 | |
| 1128 | const std::string mBlastTransactionName{"BufferTX - " + mName}; |
| 1129 | // This integer is incremented everytime a buffer arrives at the server for this layer, |
| 1130 | // and decremented when a buffer is dropped or latched. When changed the integer is exported |
| 1131 | // to systrace with ATRACE_INT and mBlastTransactionName. This way when debugging perf it is |
| 1132 | // possible to see when a buffer arrived at the server, and in which frame it latched. |
| 1133 | // |
| 1134 | // You can understand the trace this way: |
| 1135 | // - If the integer increases, a buffer arrived at the server. |
| 1136 | // - If the integer decreases in latchBuffer, that buffer was latched |
| 1137 | // - If the integer decreases in setBuffer or doTransaction, a buffer was dropped |
| 1138 | std::atomic<int32_t> mPendingBufferTransactions{0}; |
| 1139 | |
| 1140 | // Contains requested position and matrix updates. This will be applied if the client does |
| 1141 | // not specify a destination frame. |
| 1142 | ui::Transform mRequestedTransform; |
| 1143 | |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 1144 | sp<LayerFE> mLayerFE; |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 1145 | std::unique_ptr<LayerSnapshot> mSnapshot = std::make_unique<LayerSnapshot>(); |
Patrick Williams | 377c014 | 2022-10-13 17:33:38 +0000 | [diff] [blame] | 1146 | |
| 1147 | friend class LayerSnapshotGuard; |
| 1148 | }; |
| 1149 | |
| 1150 | // LayerSnapshotGuard manages the movement of LayerSnapshot between a Layer and its corresponding |
| 1151 | // LayerFE. This class must be used whenever LayerFEs are passed to CompositionEngine. Instances of |
| 1152 | // LayerSnapshotGuard should only be constructed on the main thread and should not be moved outside |
| 1153 | // the main thread. |
| 1154 | // |
| 1155 | // Moving the snapshot instead of sharing common state prevents use of LayerFE outside the main |
| 1156 | // thread by making errors obvious (i.e. use outside the main thread results in SEGFAULTs due to |
| 1157 | // nullptr dereference). |
| 1158 | class LayerSnapshotGuard { |
| 1159 | public: |
| 1160 | LayerSnapshotGuard(Layer* layer) REQUIRES(kMainThreadContext); |
| 1161 | ~LayerSnapshotGuard() REQUIRES(kMainThreadContext); |
| 1162 | |
| 1163 | LayerSnapshotGuard(const LayerSnapshotGuard&) = delete; |
| 1164 | LayerSnapshotGuard& operator=(const LayerSnapshotGuard&) = delete; |
| 1165 | |
| 1166 | LayerSnapshotGuard(LayerSnapshotGuard&& other) REQUIRES(kMainThreadContext); |
| 1167 | LayerSnapshotGuard& operator=(LayerSnapshotGuard&& other) REQUIRES(kMainThreadContext); |
| 1168 | |
| 1169 | private: |
| 1170 | Layer* mLayer; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1171 | }; |
| 1172 | |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 1173 | std::ostream& operator<<(std::ostream& stream, const Layer::FrameRate& rate); |
| 1174 | |
Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame] | 1175 | } // namespace android |