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 | |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wconversion" |
| 20 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 21 | //#define LOG_NDEBUG 0 |
| 22 | #undef LOG_TAG |
| 23 | #define LOG_TAG "Layer" |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 24 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 25 | |
Alec Mouri | e60041e | 2019-06-14 18:59:51 -0700 | [diff] [blame] | 26 | #include "Layer.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 28 | #include <android-base/properties.h> |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 29 | #include <android-base/stringprintf.h> |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 30 | #include <android/native_window.h> |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 31 | #include <binder/IPCThreadState.h> |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 32 | #include <compositionengine/CompositionEngine.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 33 | #include <compositionengine/Display.h> |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 34 | #include <compositionengine/LayerFECompositionState.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 35 | #include <compositionengine/OutputLayer.h> |
| 36 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 37 | #include <cutils/compiler.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 38 | #include <cutils/native_handle.h> |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 39 | #include <cutils/properties.h> |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 40 | #include <ftl/enum.h> |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 41 | #include <ftl/fake_guard.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 42 | #include <gui/BufferItem.h> |
| 43 | #include <gui/LayerDebugInfo.h> |
| 44 | #include <gui/Surface.h> |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 45 | #include <gui/TraceUtils.h> |
Alec Mouri | e60041e | 2019-06-14 18:59:51 -0700 | [diff] [blame] | 46 | #include <math.h> |
chaviw | 250bcbb | 2020-08-05 11:17:54 -0700 | [diff] [blame] | 47 | #include <private/android_filesystem_config.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 48 | #include <renderengine/RenderEngine.h> |
Alec Mouri | e60041e | 2019-06-14 18:59:51 -0700 | [diff] [blame] | 49 | #include <stdint.h> |
| 50 | #include <stdlib.h> |
| 51 | #include <sys/types.h> |
Alec Mouri | dda07d9 | 2022-04-25 22:39:25 +0000 | [diff] [blame] | 52 | #include <system/graphics-base-v1.0.h> |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 53 | #include <ui/DataspaceUtils.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 54 | #include <ui/DebugUtils.h> |
| 55 | #include <ui/GraphicBuffer.h> |
| 56 | #include <ui/PixelFormat.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | #include <utils/Errors.h> |
| 58 | #include <utils/Log.h> |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 59 | #include <utils/NativeHandle.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | #include <utils/StopWatch.h> |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 61 | #include <utils/Trace.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | |
Alec Mouri | e60041e | 2019-06-14 18:59:51 -0700 | [diff] [blame] | 63 | #include <algorithm> |
| 64 | #include <mutex> |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 65 | #include <optional> |
Alec Mouri | e60041e | 2019-06-14 18:59:51 -0700 | [diff] [blame] | 66 | #include <sstream> |
| 67 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 68 | #include "DisplayDevice.h" |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 69 | #include "DisplayHardware/HWComposer.h" |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 70 | #include "FrameTimeline.h" |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 71 | #include "FrameTracer/FrameTracer.h" |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 72 | #include "FrontEnd/LayerCreationArgs.h" |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 73 | #include "FrontEnd/LayerHandle.h" |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 74 | #include "LayerProtoHelper.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | #include "SurfaceFlinger.h" |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 76 | #include "TimeStats/TimeStats.h" |
Robert Carr | 3e2a299 | 2021-06-11 13:42:55 -0700 | [diff] [blame] | 77 | #include "TunnelModeEnabledReporter.h" |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 78 | |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 79 | #define DEBUG_RESIZE 0 |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 80 | #define EARLY_RELEASE_ENABLED false |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | namespace android { |
Marin Shalamanov | 1876e2e | 2020-12-04 13:23:59 +0100 | [diff] [blame] | 83 | namespace { |
| 84 | constexpr int kDumpTableRowLength = 159; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 85 | |
Prabir Pradhan | da0f62c | 2022-07-22 19:53:04 +0000 | [diff] [blame] | 86 | const ui::Transform kIdentityTransform; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 87 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 88 | bool assignTransform(ui::Transform* dst, ui::Transform& from) { |
| 89 | if (*dst == from) { |
| 90 | return false; |
| 91 | } |
| 92 | *dst = from; |
| 93 | return true; |
| 94 | } |
| 95 | |
| 96 | TimeStats::SetFrameRateVote frameRateToSetFrameRateVotePayload(Layer::FrameRate frameRate) { |
| 97 | using FrameRateCompatibility = TimeStats::SetFrameRateVote::FrameRateCompatibility; |
| 98 | using Seamlessness = TimeStats::SetFrameRateVote::Seamlessness; |
| 99 | const auto frameRateCompatibility = [frameRate] { |
| 100 | switch (frameRate.type) { |
| 101 | case Layer::FrameRateCompatibility::Default: |
| 102 | return FrameRateCompatibility::Default; |
| 103 | case Layer::FrameRateCompatibility::ExactOrMultiple: |
| 104 | return FrameRateCompatibility::ExactOrMultiple; |
| 105 | default: |
| 106 | return FrameRateCompatibility::Undefined; |
| 107 | } |
| 108 | }(); |
| 109 | |
| 110 | const auto seamlessness = [frameRate] { |
| 111 | switch (frameRate.seamlessness) { |
| 112 | case scheduler::Seamlessness::OnlySeamless: |
| 113 | return Seamlessness::ShouldBeSeamless; |
| 114 | case scheduler::Seamlessness::SeamedAndSeamless: |
| 115 | return Seamlessness::NotRequired; |
| 116 | default: |
| 117 | return Seamlessness::Undefined; |
| 118 | } |
| 119 | }(); |
| 120 | |
| 121 | return TimeStats::SetFrameRateVote{.frameRate = frameRate.rate.getValue(), |
| 122 | .frameRateCompatibility = frameRateCompatibility, |
| 123 | .seamlessness = seamlessness}; |
| 124 | } |
| 125 | |
Marin Shalamanov | 1876e2e | 2020-12-04 13:23:59 +0100 | [diff] [blame] | 126 | } // namespace |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | |
Dominik Laskowski | 2f01d77 | 2022-03-23 16:01:29 -0700 | [diff] [blame] | 128 | using namespace ftl::flag_operators; |
| 129 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 130 | using base::StringAppendF; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 131 | using frontend::LayerSnapshot; |
| 132 | using frontend::RoundedCornerState; |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 133 | using gui::GameMode; |
| 134 | using gui::LayerMetadata; |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 135 | using gui::WindowInfo; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 136 | |
Dominik Laskowski | 2f01d77 | 2022-03-23 16:01:29 -0700 | [diff] [blame] | 137 | using PresentState = frametimeline::SurfaceFrame::PresentState; |
| 138 | |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 139 | Layer::Layer(const LayerCreationArgs& args) |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 140 | : sequence(args.sequence), |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 141 | mFlinger(sp<SurfaceFlinger>::fromExisting(args.flinger)), |
Arthur Hung | 23e0750 | 2021-10-15 11:58:19 +0000 | [diff] [blame] | 142 | mName(base::StringPrintf("%s#%d", args.name.c_str(), sequence)), |
Ady Abraham | 8f1ee7f | 2019-04-05 10:32:50 -0700 | [diff] [blame] | 143 | mClientRef(args.client), |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 144 | mWindowType(static_cast<WindowInfo::Type>( |
| 145 | args.metadata.getInt32(gui::METADATA_WINDOW_TYPE, 0))), |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 146 | mLayerCreationFlags(args.flags), |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 147 | mBorderEnabled(false), |
| 148 | mTextureName(args.textureName), |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 149 | mLegacyLayerFE(args.flinger->getFactory().createLayerFE(mName)) { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 150 | ALOGV("Creating Layer %s", getDebugName()); |
| 151 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 152 | uint32_t layerFlags = 0; |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 153 | if (args.flags & ISurfaceComposerClient::eHidden) layerFlags |= layer_state_t::eLayerHidden; |
| 154 | if (args.flags & ISurfaceComposerClient::eOpaque) layerFlags |= layer_state_t::eLayerOpaque; |
| 155 | if (args.flags & ISurfaceComposerClient::eSecure) layerFlags |= layer_state_t::eLayerSecure; |
chaviw | c5676c6 | 2020-09-18 15:01:04 -0700 | [diff] [blame] | 156 | if (args.flags & ISurfaceComposerClient::eSkipScreenshot) |
| 157 | layerFlags |= layer_state_t::eLayerSkipScreenshot; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 158 | mDrawingState.flags = layerFlags; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 159 | mDrawingState.crop.makeInvalid(); |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 160 | mDrawingState.z = 0; |
| 161 | mDrawingState.color.a = 1.0f; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 162 | mDrawingState.layerStack = ui::DEFAULT_LAYER_STACK; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 163 | mDrawingState.sequence = 0; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 164 | mDrawingState.transform.set(0, 0); |
| 165 | mDrawingState.frameNumber = 0; |
| 166 | mDrawingState.bufferTransform = 0; |
| 167 | mDrawingState.transformToDisplayInverse = false; |
| 168 | mDrawingState.crop.makeInvalid(); |
| 169 | mDrawingState.acquireFence = sp<Fence>::make(-1); |
| 170 | mDrawingState.acquireFenceTime = std::make_shared<FenceTime>(mDrawingState.acquireFence); |
| 171 | mDrawingState.dataspace = ui::Dataspace::UNKNOWN; |
Vishnu Nair | bc4ee5c | 2022-08-16 03:19:37 +0000 | [diff] [blame] | 172 | mDrawingState.dataspaceRequested = false; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 173 | mDrawingState.hdrMetadata.validTypes = 0; |
| 174 | mDrawingState.surfaceDamageRegion = Region::INVALID_REGION; |
| 175 | mDrawingState.cornerRadius = 0.0f; |
| 176 | mDrawingState.backgroundBlurRadius = 0; |
| 177 | mDrawingState.api = -1; |
| 178 | mDrawingState.hasColorTransform = false; |
| 179 | mDrawingState.colorSpaceAgnostic = false; |
| 180 | mDrawingState.frameRateSelectionPriority = PRIORITY_UNSET; |
| 181 | mDrawingState.metadata = args.metadata; |
| 182 | mDrawingState.shadowRadius = 0.f; |
| 183 | mDrawingState.fixedTransformHint = ui::Transform::ROT_INVALID; |
| 184 | mDrawingState.frameTimelineInfo = {}; |
| 185 | mDrawingState.postTime = -1; |
| 186 | mDrawingState.destinationFrame.makeInvalid(); |
Robin Lee | edb375d | 2021-09-10 12:03:42 +0000 | [diff] [blame] | 187 | mDrawingState.isTrustedOverlay = false; |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 188 | mDrawingState.dropInputMode = gui::DropInputMode::NONE; |
Sally Qi | 81d95e6 | 2022-03-21 19:41:33 -0700 | [diff] [blame] | 189 | mDrawingState.dimmingEnabled = true; |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 190 | mDrawingState.defaultFrameRateCompatibility = FrameRateCompatibility::Default; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 191 | |
Vishnu Nair | c43a23c | 2020-05-29 14:32:27 -0700 | [diff] [blame] | 192 | if (args.flags & ISurfaceComposerClient::eNoColorFill) { |
| 193 | // Set an invalid color so there is no color fill. |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 194 | mDrawingState.color.r = -1.0_hf; |
| 195 | mDrawingState.color.g = -1.0_hf; |
| 196 | mDrawingState.color.b = -1.0_hf; |
Vishnu Nair | c43a23c | 2020-05-29 14:32:27 -0700 | [diff] [blame] | 197 | } |
Dominik Laskowski | 4376bd8 | 2022-07-07 11:50:20 -0700 | [diff] [blame] | 198 | |
Dominik Laskowski | 933f8de | 2023-01-20 13:15:51 -0500 | [diff] [blame] | 199 | mFrameTracker.setDisplayRefreshPeriod(args.flinger->mScheduler->getLeaderVsyncPeriod().ns()); |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 200 | |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 201 | mOwnerUid = args.ownerUid; |
| 202 | mOwnerPid = args.ownerPid; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 203 | |
| 204 | mPremultipliedAlpha = !(args.flags & ISurfaceComposerClient::eNonPremultiplied); |
| 205 | mPotentialCursor = args.flags & ISurfaceComposerClient::eCursorWindow; |
| 206 | mProtectedByApp = args.flags & ISurfaceComposerClient::eProtectedByApp; |
| 207 | mDrawingState.dataspace = ui::Dataspace::V0_SRGB; |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 208 | |
| 209 | mSnapshot->sequence = sequence; |
| 210 | mSnapshot->name = getDebugName(); |
| 211 | mSnapshot->textureName = mTextureName; |
| 212 | mSnapshot->premultipliedAlpha = mPremultipliedAlpha; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 213 | mSnapshot->parentTransform = {}; |
Dominik Laskowski | 7584836 | 2019-11-11 17:57:20 -0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | void Layer::onFirstRef() { |
| 217 | mFlinger->onLayerFirstRef(this); |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 218 | } |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 219 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 220 | Layer::~Layer() { |
Patrick Williams | 70093fd | 2022-12-12 16:51:52 +0000 | [diff] [blame] | 221 | LOG_ALWAYS_FATAL_IF(std::this_thread::get_id() != mFlinger->mMainThreadId, |
| 222 | "Layer destructor called off the main thread."); |
| 223 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 224 | // The original layer and the clone layer share the same texture and buffer. Therefore, only |
| 225 | // one of the layers, in this case the original layer, needs to handle the deletion. The |
| 226 | // original layer and the clone should be removed at the same time so there shouldn't be any |
| 227 | // issue with the clone layer trying to use the texture. |
| 228 | if (mBufferInfo.mBuffer != nullptr) { |
| 229 | callReleaseBufferCallback(mDrawingState.releaseBufferListener, |
| 230 | mBufferInfo.mBuffer->getBuffer(), mBufferInfo.mFrameNumber, |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 231 | mBufferInfo.mFence); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 232 | } |
| 233 | if (!isClone()) { |
| 234 | // The original layer and the clone layer share the same texture. Therefore, only one of |
| 235 | // the layers, in this case the original layer, needs to handle the deletion. The original |
| 236 | // layer and the clone should be removed at the same time so there shouldn't be any issue |
| 237 | // with the clone layer trying to use the deleted texture. |
| 238 | mFlinger->deleteTextureAsync(mTextureName); |
| 239 | } |
| 240 | const int32_t layerId = getSequence(); |
| 241 | mFlinger->mTimeStats->onDestroy(layerId); |
| 242 | mFlinger->mFrameTracer->onDestroy(layerId); |
| 243 | |
Jorim Jaggi | 10c985e | 2018-10-23 11:17:45 +0000 | [diff] [blame] | 244 | mFrameTracker.logAndResetStats(mName); |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 245 | mFlinger->onLayerDestroyed(this); |
Robert Carr | 3e2a299 | 2021-06-11 13:42:55 -0700 | [diff] [blame] | 246 | |
| 247 | if (mDrawingState.sidebandStream != nullptr) { |
| 248 | mFlinger->mTunnelModeEnabledReporter->decrementTunnelModeCount(); |
| 249 | } |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 250 | if (mHadClonedChild) { |
| 251 | mFlinger->mNumClones--; |
| 252 | } |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 253 | if (hasTrustedPresentationListener()) { |
| 254 | mFlinger->mNumTrustedPresentationListeners--; |
Vishnu Nair | 781d725 | 2023-01-30 18:16:01 +0000 | [diff] [blame] | 255 | updateTrustedPresentationState(nullptr, nullptr, -1 /* time_in_ms */, true /* leaveState*/); |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 256 | } |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 259 | // --------------------------------------------------------------------------- |
| 260 | // callbacks |
| 261 | // --------------------------------------------------------------------------- |
| 262 | |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 263 | void Layer::removeRelativeZ(const std::vector<Layer*>& layersInTree) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 264 | if (mDrawingState.zOrderRelativeOf == nullptr) { |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 265 | return; |
| 266 | } |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 267 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 268 | sp<Layer> strongRelative = mDrawingState.zOrderRelativeOf.promote(); |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 269 | if (strongRelative == nullptr) { |
| 270 | setZOrderRelativeOf(nullptr); |
| 271 | return; |
| 272 | } |
| 273 | |
| 274 | if (!std::binary_search(layersInTree.begin(), layersInTree.end(), strongRelative.get())) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 275 | strongRelative->removeZOrderRelative(wp<Layer>::fromExisting(this)); |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 276 | mFlinger->setTransactionFlags(eTraversalNeeded); |
chaviw | 606e5cf | 2019-03-01 10:12:10 -0800 | [diff] [blame] | 277 | setZOrderRelativeOf(nullptr); |
Robert Carr | 5edb1ad | 2017-04-25 10:54:24 -0700 | [diff] [blame] | 278 | } |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | void Layer::removeFromCurrentState() { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 282 | if (!mRemovedFromDrawingState) { |
| 283 | mRemovedFromDrawingState = true; |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 284 | mFlinger->mScheduler->deregisterLayer(this); |
| 285 | } |
Vishnu Nair | 781d725 | 2023-01-30 18:16:01 +0000 | [diff] [blame] | 286 | updateTrustedPresentationState(nullptr, nullptr, -1 /* time_in_ms */, true /* leaveState*/); |
Rob Carr | 4bba370 | 2018-10-08 21:53:30 +0000 | [diff] [blame] | 287 | |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 288 | mFlinger->markLayerPendingRemovalLocked(sp<Layer>::fromExisting(this)); |
Chia-I Wu | c665702 | 2017-08-15 11:18:17 -0700 | [diff] [blame] | 289 | } |
Chia-I Wu | 3851225 | 2017-05-17 14:36:16 -0700 | [diff] [blame] | 290 | |
chaviw | 68d4dab | 2020-06-08 15:07:32 -0700 | [diff] [blame] | 291 | sp<Layer> Layer::getRootLayer() { |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 292 | sp<Layer> parent = getParent(); |
chaviw | 68d4dab | 2020-06-08 15:07:32 -0700 | [diff] [blame] | 293 | if (parent == nullptr) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 294 | return sp<Layer>::fromExisting(this); |
chaviw | 68d4dab | 2020-06-08 15:07:32 -0700 | [diff] [blame] | 295 | } |
| 296 | return parent->getRootLayer(); |
| 297 | } |
| 298 | |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 299 | void Layer::onRemovedFromCurrentState() { |
chaviw | 68d4dab | 2020-06-08 15:07:32 -0700 | [diff] [blame] | 300 | // Use the root layer since we want to maintain the hierarchy for the entire subtree. |
| 301 | auto layersInTree = getRootLayer()->getLayersInTree(LayerVector::StateSet::Current); |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 302 | std::sort(layersInTree.begin(), layersInTree.end()); |
chaviw | 68d4dab | 2020-06-08 15:07:32 -0700 | [diff] [blame] | 303 | |
| 304 | traverse(LayerVector::StateSet::Current, [&](Layer* layer) { |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 305 | layer->removeFromCurrentState(); |
| 306 | layer->removeRelativeZ(layersInTree); |
chaviw | 68d4dab | 2020-06-08 15:07:32 -0700 | [diff] [blame] | 307 | }); |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 308 | } |
| 309 | |
chaviw | 61626f2 | 2018-11-15 16:26:27 -0800 | [diff] [blame] | 310 | void Layer::addToCurrentState() { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 311 | if (mRemovedFromDrawingState) { |
| 312 | mRemovedFromDrawingState = false; |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 313 | mFlinger->mScheduler->registerLayer(this); |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 314 | mFlinger->removeFromOffscreenLayers(this); |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 315 | } |
chaviw | 61626f2 | 2018-11-15 16:26:27 -0800 | [diff] [blame] | 316 | |
| 317 | for (const auto& child : mCurrentChildren) { |
| 318 | child->addToCurrentState(); |
| 319 | } |
| 320 | } |
| 321 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 322 | // --------------------------------------------------------------------------- |
| 323 | // set-up |
| 324 | // --------------------------------------------------------------------------- |
| 325 | |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 326 | bool Layer::getPremultipledAlpha() const { |
| 327 | return mPremultipliedAlpha; |
| 328 | } |
| 329 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 330 | sp<IBinder> Layer::getHandle() { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 331 | Mutex::Autolock _l(mLock); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 332 | if (mGetHandleCalled) { |
| 333 | ALOGE("Get handle called twice" ); |
| 334 | return nullptr; |
| 335 | } |
| 336 | mGetHandleCalled = true; |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 337 | return sp<LayerHandle>::make(mFlinger, sp<Layer>::fromExisting(this)); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | // --------------------------------------------------------------------------- |
| 341 | // h/w composer set-up |
| 342 | // --------------------------------------------------------------------------- |
| 343 | |
Mathias Agopian | f3e85d4 | 2013-05-10 18:01:12 -0700 | [diff] [blame] | 344 | static Rect reduce(const Rect& win, const Region& exclude) { |
| 345 | if (CC_LIKELY(exclude.isEmpty())) { |
| 346 | return win; |
| 347 | } |
| 348 | if (exclude.isRect()) { |
| 349 | return win.reduce(exclude.getBounds()); |
| 350 | } |
| 351 | return Region(win).subtract(exclude).getBounds(); |
| 352 | } |
| 353 | |
Dan Stoza | 80d6116 | 2017-12-20 15:57:52 -0800 | [diff] [blame] | 354 | static FloatRect reduce(const FloatRect& win, const Region& exclude) { |
| 355 | if (CC_LIKELY(exclude.isEmpty())) { |
| 356 | return win; |
| 357 | } |
| 358 | // Convert through Rect (by rounding) for lack of FloatRegion |
| 359 | return Region(Rect{win}).subtract(exclude).getBounds().toFloatRect(); |
| 360 | } |
| 361 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 362 | Rect Layer::getScreenBounds(bool reduceTransparentRegion) const { |
Vishnu Nair | f0c2851 | 2019-02-08 12:40:28 -0800 | [diff] [blame] | 363 | if (!reduceTransparentRegion) { |
| 364 | return Rect{mScreenBounds}; |
| 365 | } |
| 366 | |
| 367 | FloatRect bounds = getBounds(); |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 368 | ui::Transform t = getTransform(); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 369 | // Transform to screen space. |
| 370 | bounds = t.transform(bounds); |
| 371 | return Rect{bounds}; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 374 | FloatRect Layer::getBounds() const { |
Alec Mouri | b416efd | 2018-09-06 21:01:59 +0000 | [diff] [blame] | 375 | const State& s(getDrawingState()); |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 376 | return getBounds(getActiveTransparentRegion(s)); |
Michael Lentine | 6c925ed | 2014-09-26 17:55:01 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Vishnu Nair | f0c2851 | 2019-02-08 12:40:28 -0800 | [diff] [blame] | 379 | FloatRect Layer::getBounds(const Region& activeTransparentRegion) const { |
| 380 | // Subtract the transparent region and snap to the bounds. |
| 381 | return reduce(mBounds, activeTransparentRegion); |
| 382 | } |
| 383 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 384 | // No early returns. |
Vishnu Nair | 781d725 | 2023-01-30 18:16:01 +0000 | [diff] [blame] | 385 | void Layer::updateTrustedPresentationState(const DisplayDevice* display, |
| 386 | const frontend::LayerSnapshot* snapshot, |
| 387 | int64_t time_in_ms, bool leaveState) { |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 388 | if (!hasTrustedPresentationListener()) { |
| 389 | return; |
| 390 | } |
| 391 | const bool lastState = mLastComputedTrustedPresentationState; |
| 392 | mLastComputedTrustedPresentationState = false; |
| 393 | |
| 394 | if (!leaveState) { |
| 395 | const auto outputLayer = findOutputLayerForDisplay(display); |
Chavi Weingarten | 545da0e | 2023-02-09 14:55:57 +0000 | [diff] [blame] | 396 | if (outputLayer != nullptr) { |
| 397 | if (outputLayer->getState().coveredRegionExcludingDisplayOverlays) { |
| 398 | Region coveredRegion = |
| 399 | *outputLayer->getState().coveredRegionExcludingDisplayOverlays; |
| 400 | mLastComputedTrustedPresentationState = |
| 401 | computeTrustedPresentationState(snapshot->geomLayerBounds, |
| 402 | snapshot->sourceBounds(), coveredRegion, |
| 403 | snapshot->transformedBounds, |
| 404 | snapshot->alpha, |
| 405 | snapshot->geomLayerTransform, |
| 406 | mTrustedPresentationThresholds); |
| 407 | } else { |
| 408 | ALOGE("CoveredRegionExcludingDisplayOverlays was not set for %s. Don't compute " |
| 409 | "TrustedPresentationState", |
| 410 | getDebugName()); |
| 411 | } |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 412 | } |
| 413 | } |
| 414 | const bool newState = mLastComputedTrustedPresentationState; |
| 415 | if (lastState && !newState) { |
| 416 | // We were in the trusted presentation state, but now we left it, |
| 417 | // emit the callback if needed |
| 418 | if (mLastReportedTrustedPresentationState) { |
| 419 | mLastReportedTrustedPresentationState = false; |
| 420 | mTrustedPresentationListener.invoke(false); |
| 421 | } |
| 422 | // Reset the timer |
| 423 | mEnteredTrustedPresentationStateTime = -1; |
| 424 | } else if (!lastState && newState) { |
| 425 | // We were not in the trusted presentation state, but we entered it, begin the timer |
| 426 | // and make sure this gets called at least once more! |
| 427 | mEnteredTrustedPresentationStateTime = time_in_ms; |
| 428 | mFlinger->forceFutureUpdate(mTrustedPresentationThresholds.stabilityRequirementMs * 1.5); |
| 429 | } |
| 430 | |
| 431 | // Has the timer elapsed, but we are still in the state? Emit a callback if needed |
| 432 | if (!mLastReportedTrustedPresentationState && newState && |
| 433 | (time_in_ms - mEnteredTrustedPresentationStateTime > |
| 434 | mTrustedPresentationThresholds.stabilityRequirementMs)) { |
| 435 | mLastReportedTrustedPresentationState = true; |
| 436 | mTrustedPresentationListener.invoke(true); |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | /** |
| 441 | * See SurfaceComposerClient.h: setTrustedPresentationCallback for discussion |
| 442 | * of how the parameters and thresholds are interpreted. The general spirit is |
| 443 | * to produce an upper bound on the amount of the buffer which was presented. |
| 444 | */ |
| 445 | bool Layer::computeTrustedPresentationState(const FloatRect& bounds, const FloatRect& sourceBounds, |
| 446 | const Region& coveredRegion, |
| 447 | const FloatRect& screenBounds, float alpha, |
| 448 | const ui::Transform& effectiveTransform, |
| 449 | const TrustedPresentationThresholds& thresholds) { |
| 450 | if (alpha < thresholds.minAlpha) { |
| 451 | return false; |
| 452 | } |
| 453 | if (sourceBounds.getWidth() == 0 || sourceBounds.getHeight() == 0) { |
| 454 | return false; |
| 455 | } |
| 456 | if (screenBounds.getWidth() == 0 || screenBounds.getHeight() == 0) { |
| 457 | return false; |
| 458 | } |
| 459 | |
| 460 | const float sx = effectiveTransform.dsdx(); |
| 461 | const float sy = effectiveTransform.dsdy(); |
| 462 | float fractionRendered = std::min(sx * sy, 1.0f); |
| 463 | |
| 464 | float boundsOverSourceW = bounds.getWidth() / (float)sourceBounds.getWidth(); |
| 465 | float boundsOverSourceH = bounds.getHeight() / (float)sourceBounds.getHeight(); |
| 466 | fractionRendered *= boundsOverSourceW * boundsOverSourceH; |
| 467 | |
Chavi Weingarten | 545da0e | 2023-02-09 14:55:57 +0000 | [diff] [blame] | 468 | Region tJunctionFreeRegion = Region::createTJunctionFreeRegion(coveredRegion); |
| 469 | // Compute the size of all the rects since they may be disconnected. |
| 470 | float coveredSize = 0; |
| 471 | for (auto rect = tJunctionFreeRegion.begin(); rect < tJunctionFreeRegion.end(); rect++) { |
| 472 | float size = rect->width() * rect->height(); |
| 473 | coveredSize += size; |
| 474 | } |
| 475 | |
| 476 | fractionRendered *= (1 - (coveredSize / (screenBounds.getWidth() * screenBounds.getHeight()))); |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 477 | |
| 478 | if (fractionRendered < thresholds.minFractionRendered) { |
| 479 | return false; |
| 480 | } |
| 481 | |
| 482 | return true; |
| 483 | } |
| 484 | |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 485 | void Layer::computeBounds(FloatRect parentBounds, ui::Transform parentTransform, |
| 486 | float parentShadowRadius) { |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 487 | const State& s(getDrawingState()); |
| 488 | |
| 489 | // Calculate effective layer transform |
| 490 | mEffectiveTransform = parentTransform * getActiveTransform(s); |
| 491 | |
Garfield Tan | 2c1782c | 2022-02-16 15:25:05 -0800 | [diff] [blame] | 492 | if (CC_UNLIKELY(!isTransformValid())) { |
| 493 | ALOGW("Stop computing bounds for %s because it has invalid transformation.", |
| 494 | getDebugName()); |
| 495 | return; |
| 496 | } |
| 497 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 498 | // Transform parent bounds to layer space |
| 499 | parentBounds = getActiveTransform(s).inverse().transform(parentBounds); |
| 500 | |
Vishnu Nair | c652ff8 | 2019-03-15 12:48:54 -0700 | [diff] [blame] | 501 | // Calculate source bounds |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 502 | mSourceBounds = computeSourceBounds(parentBounds); |
| 503 | |
| 504 | // Calculate bounds by croping diplay frame with layer crop and parent bounds |
| 505 | FloatRect bounds = mSourceBounds; |
| 506 | const Rect layerCrop = getCrop(s); |
| 507 | if (!layerCrop.isEmpty()) { |
| 508 | bounds = mSourceBounds.intersect(layerCrop.toFloatRect()); |
| 509 | } |
| 510 | bounds = bounds.intersect(parentBounds); |
| 511 | |
| 512 | mBounds = bounds; |
| 513 | mScreenBounds = mEffectiveTransform.transform(mBounds); |
Vishnu Nair | c652ff8 | 2019-03-15 12:48:54 -0700 | [diff] [blame] | 514 | |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 515 | // Use the layer's own shadow radius if set. Otherwise get the radius from |
| 516 | // parent. |
| 517 | if (s.shadowRadius > 0.f) { |
| 518 | mEffectiveShadowRadius = s.shadowRadius; |
| 519 | } else { |
| 520 | mEffectiveShadowRadius = parentShadowRadius; |
| 521 | } |
| 522 | |
| 523 | // Shadow radius is passed down to only one layer so if the layer can draw shadows, |
| 524 | // don't pass it to its children. |
| 525 | const float childShadowRadius = canDrawShadows() ? 0.f : mEffectiveShadowRadius; |
| 526 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 527 | for (const sp<Layer>& child : mDrawingChildren) { |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 528 | child->computeBounds(mBounds, mEffectiveTransform, childShadowRadius); |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 529 | } |
Vishnu Nair | ba35410 | 2022-08-01 00:14:18 +0000 | [diff] [blame] | 530 | |
| 531 | if (mPotentialCursor) { |
| 532 | prepareCursorCompositionState(); |
| 533 | } |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 534 | } |
| 535 | |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 536 | Rect Layer::getCroppedBufferSize(const State& s) const { |
| 537 | Rect size = getBufferSize(s); |
| 538 | Rect crop = getCrop(s); |
| 539 | if (!crop.isEmpty() && size.isValid()) { |
| 540 | size.intersect(crop, &size); |
| 541 | } else if (!crop.isEmpty()) { |
| 542 | size = crop; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 543 | } |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 544 | return size; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 545 | } |
| 546 | |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 547 | void Layer::setupRoundedCornersCropCoordinates(Rect win, |
| 548 | const FloatRect& roundedCornersCrop) const { |
| 549 | // Translate win by the rounded corners rect coordinates, to have all values in |
| 550 | // layer coordinate space. |
| 551 | win.left -= roundedCornersCrop.left; |
| 552 | win.right -= roundedCornersCrop.left; |
| 553 | win.top -= roundedCornersCrop.top; |
| 554 | win.bottom -= roundedCornersCrop.top; |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 555 | } |
| 556 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 557 | void Layer::prepareBasicGeometryCompositionState() { |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 558 | const auto& drawingState{getDrawingState()}; |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 559 | const auto alpha = static_cast<float>(getAlpha()); |
| 560 | const bool opaque = isOpaque(drawingState); |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 561 | const bool usesRoundedCorners = hasRoundedCorners(); |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 562 | |
| 563 | auto blendMode = Hwc2::IComposerClient::BlendMode::NONE; |
| 564 | if (!opaque || alpha != 1.0f) { |
| 565 | blendMode = mPremultipliedAlpha ? Hwc2::IComposerClient::BlendMode::PREMULTIPLIED |
| 566 | : Hwc2::IComposerClient::BlendMode::COVERAGE; |
| 567 | } |
| 568 | |
Alec Mouri | f4af03e | 2023-02-11 00:25:24 +0000 | [diff] [blame] | 569 | // Please keep in sync with LayerSnapshotBuilder |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 570 | auto* snapshot = editLayerSnapshot(); |
| 571 | snapshot->outputFilter = getOutputFilter(); |
| 572 | snapshot->isVisible = isVisible(); |
| 573 | snapshot->isOpaque = opaque && !usesRoundedCorners && alpha == 1.f; |
| 574 | snapshot->shadowRadius = mEffectiveShadowRadius; |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 575 | |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 576 | snapshot->contentDirty = contentDirty; |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 577 | contentDirty = false; |
| 578 | |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 579 | snapshot->geomLayerBounds = mBounds; |
| 580 | snapshot->geomLayerTransform = getTransform(); |
| 581 | snapshot->geomInverseLayerTransform = snapshot->geomLayerTransform.inverse(); |
| 582 | snapshot->transparentRegionHint = getActiveTransparentRegion(drawingState); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 583 | snapshot->localTransform = getActiveTransform(drawingState); |
| 584 | snapshot->localTransformInverse = snapshot->localTransform.inverse(); |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 585 | snapshot->blendMode = static_cast<Hwc2::IComposerClient::BlendMode>(blendMode); |
| 586 | snapshot->alpha = alpha; |
| 587 | snapshot->backgroundBlurRadius = drawingState.backgroundBlurRadius; |
| 588 | snapshot->blurRegions = drawingState.blurRegions; |
| 589 | snapshot->stretchEffect = getStretchEffect(); |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 590 | } |
| 591 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 592 | void Layer::prepareGeometryCompositionState() { |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 593 | const auto& drawingState{getDrawingState()}; |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 594 | auto* snapshot = editLayerSnapshot(); |
David Sodman | 1509411 | 2018-10-11 09:39:37 -0700 | [diff] [blame] | 595 | |
Alec Mouri | f4af03e | 2023-02-11 00:25:24 +0000 | [diff] [blame] | 596 | // Please keep in sync with LayerSnapshotBuilder |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 597 | snapshot->geomBufferSize = getBufferSize(drawingState); |
| 598 | snapshot->geomContentCrop = getBufferCrop(); |
| 599 | snapshot->geomCrop = getCrop(drawingState); |
| 600 | snapshot->geomBufferTransform = getBufferTransform(); |
| 601 | snapshot->geomBufferUsesDisplayInverseTransform = getTransformToDisplayInverse(); |
| 602 | snapshot->geomUsesSourceCrop = usesSourceCrop(); |
| 603 | snapshot->isSecure = isSecure(); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 604 | |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 605 | snapshot->metadata.clear(); |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 606 | const auto& supportedMetadata = mFlinger->getHwComposer().getSupportedLayerGenericMetadata(); |
| 607 | for (const auto& [key, mandatory] : supportedMetadata) { |
| 608 | const auto& genericLayerMetadataCompatibilityMap = |
| 609 | mFlinger->getGenericLayerMetadataKeyMap(); |
| 610 | auto compatIter = genericLayerMetadataCompatibilityMap.find(key); |
| 611 | if (compatIter == std::end(genericLayerMetadataCompatibilityMap)) { |
| 612 | continue; |
| 613 | } |
| 614 | const uint32_t id = compatIter->second; |
| 615 | |
| 616 | auto it = drawingState.metadata.mMap.find(id); |
| 617 | if (it == std::end(drawingState.metadata.mMap)) { |
| 618 | continue; |
| 619 | } |
| 620 | |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 621 | snapshot->metadata.emplace(key, |
| 622 | compositionengine::GenericLayerMetadataEntry{mandatory, |
| 623 | it->second}); |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 624 | } |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 625 | } |
David Sodman | ba34049 | 2018-08-05 21:51:33 -0700 | [diff] [blame] | 626 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 627 | void Layer::preparePerFrameCompositionState() { |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 628 | const auto& drawingState{getDrawingState()}; |
Alec Mouri | f4af03e | 2023-02-11 00:25:24 +0000 | [diff] [blame] | 629 | // Please keep in sync with LayerSnapshotBuilder |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 630 | auto* snapshot = editLayerSnapshot(); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 631 | |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 632 | snapshot->forceClientComposition = false; |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 633 | |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 634 | snapshot->isColorspaceAgnostic = isColorSpaceAgnostic(); |
| 635 | snapshot->dataspace = getDataSpace(); |
| 636 | snapshot->colorTransform = getColorTransform(); |
| 637 | snapshot->colorTransformIsIdentity = !hasColorTransform(); |
| 638 | snapshot->surfaceDamage = surfaceDamageRegion; |
| 639 | snapshot->hasProtectedContent = isProtected(); |
| 640 | snapshot->dimmingEnabled = isDimmingEnabled(); |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 641 | snapshot->currentSdrHdrRatio = getCurrentSdrHdrRatio(); |
| 642 | snapshot->desiredSdrHdrRatio = getDesiredSdrHdrRatio(); |
Alec Mouri | f4af03e | 2023-02-11 00:25:24 +0000 | [diff] [blame] | 643 | snapshot->cachingHint = getCachingHint(); |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 644 | |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 645 | const bool usesRoundedCorners = hasRoundedCorners(); |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 646 | |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 647 | snapshot->isOpaque = isOpaque(drawingState) && !usesRoundedCorners && getAlpha() == 1.0_hf; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 648 | |
| 649 | // Force client composition for special cases known only to the front-end. |
Leon Scroggins III | d305ef2 | 2021-04-06 09:53:26 -0400 | [diff] [blame] | 650 | // Rounded corners no longer force client composition, since we may use a |
| 651 | // hole punch so that the layer will appear to have rounded corners. |
| 652 | if (isHdrY410() || drawShadows() || drawingState.blurRegions.size() > 0 || |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 653 | snapshot->stretchEffect.hasEffect()) { |
| 654 | snapshot->forceClientComposition = true; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 655 | } |
Vishnu Nair | b801a98 | 2021-11-02 15:12:08 -0700 | [diff] [blame] | 656 | // If there are no visible region changes, we still need to update blur parameters. |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 657 | snapshot->blurRegions = drawingState.blurRegions; |
| 658 | snapshot->backgroundBlurRadius = drawingState.backgroundBlurRadius; |
Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 659 | |
| 660 | // Layer framerate is used in caching decisions. |
| 661 | // Retrieve it from the scheduler which maintains an instance of LayerHistory, and store it in |
| 662 | // LayerFECompositionState where it would be visible to Flattener. |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 663 | snapshot->fps = mFlinger->getLayerFramerate(systemTime(), getSequence()); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 664 | |
| 665 | if (hasBufferOrSidebandStream()) { |
| 666 | preparePerFrameBufferCompositionState(); |
| 667 | } else { |
| 668 | preparePerFrameEffectsCompositionState(); |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | void Layer::preparePerFrameBufferCompositionState() { |
Alec Mouri | f4af03e | 2023-02-11 00:25:24 +0000 | [diff] [blame] | 673 | // Please keep in sync with LayerSnapshotBuilder |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 674 | auto* snapshot = editLayerSnapshot(); |
Alec Mouri | f4af03e | 2023-02-11 00:25:24 +0000 | [diff] [blame] | 675 | // Sideband layers |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 676 | if (snapshot->sidebandStream.get() && !snapshot->sidebandStreamHasFrame) { |
| 677 | snapshot->compositionType = |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 678 | aidl::android::hardware::graphics::composer3::Composition::SIDEBAND; |
| 679 | return; |
| 680 | } else if ((mDrawingState.flags & layer_state_t::eLayerIsDisplayDecoration) != 0) { |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 681 | snapshot->compositionType = |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 682 | aidl::android::hardware::graphics::composer3::Composition::DISPLAY_DECORATION; |
| 683 | } else { |
| 684 | // Normal buffer layers |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 685 | snapshot->hdrMetadata = mBufferInfo.mHdrMetadata; |
| 686 | snapshot->compositionType = mPotentialCursor |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 687 | ? aidl::android::hardware::graphics::composer3::Composition::CURSOR |
| 688 | : aidl::android::hardware::graphics::composer3::Composition::DEVICE; |
| 689 | } |
| 690 | |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 691 | snapshot->buffer = getBuffer(); |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 692 | snapshot->acquireFence = mBufferInfo.mFence; |
| 693 | snapshot->frameNumber = mBufferInfo.mFrameNumber; |
| 694 | snapshot->sidebandStreamHasFrame = false; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | void Layer::preparePerFrameEffectsCompositionState() { |
Alec Mouri | f4af03e | 2023-02-11 00:25:24 +0000 | [diff] [blame] | 698 | // Please keep in sync with LayerSnapshotBuilder |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 699 | auto* snapshot = editLayerSnapshot(); |
| 700 | snapshot->color = getColor(); |
| 701 | snapshot->compositionType = |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 702 | aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 703 | } |
| 704 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 705 | void Layer::prepareCursorCompositionState() { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 706 | const State& drawingState{getDrawingState()}; |
Alec Mouri | f4af03e | 2023-02-11 00:25:24 +0000 | [diff] [blame] | 707 | // Please keep in sync with LayerSnapshotBuilder |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 708 | auto* snapshot = editLayerSnapshot(); |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 709 | |
| 710 | // Apply the layer's transform, followed by the display's global transform |
| 711 | // Here we're guaranteed that the layer's transform preserves rects |
| 712 | Rect win = getCroppedBufferSize(drawingState); |
| 713 | // Subtract the transparent region and snap to the bounds |
| 714 | Rect bounds = reduce(win, getActiveTransparentRegion(drawingState)); |
| 715 | Rect frame(getTransform().transform(bounds)); |
| 716 | |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 717 | snapshot->cursorFrame = frame; |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 718 | } |
| 719 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 720 | const char* Layer::getDebugName() const { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 721 | return mName.c_str(); |
David Sodman | 4b7c4bc | 2017-11-17 12:13:59 -0800 | [diff] [blame] | 722 | } |
| 723 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 724 | // --------------------------------------------------------------------------- |
| 725 | // drawing... |
| 726 | // --------------------------------------------------------------------------- |
| 727 | |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 728 | aidl::android::hardware::graphics::composer3::Composition Layer::getCompositionType( |
| 729 | const DisplayDevice& display) const { |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 730 | const auto outputLayer = findOutputLayerForDisplay(&display); |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 731 | if (outputLayer == nullptr) { |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 732 | return aidl::android::hardware::graphics::composer3::Composition::INVALID; |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 733 | } |
| 734 | if (outputLayer->getState().hwc) { |
| 735 | return (*outputLayer->getState().hwc).hwcCompositionType; |
| 736 | } else { |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 737 | return aidl::android::hardware::graphics::composer3::Composition::CLIENT; |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 738 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 739 | } |
| 740 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 741 | // ---------------------------------------------------------------------------- |
| 742 | // local state |
| 743 | // ---------------------------------------------------------------------------- |
| 744 | |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 745 | bool Layer::isSecure() const { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 746 | const State& s(mDrawingState); |
Garfield Tan | de619fa | 2020-10-02 17:13:53 -0700 | [diff] [blame] | 747 | if (s.flags & layer_state_t::eLayerSecure) { |
| 748 | return true; |
| 749 | } |
| 750 | |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 751 | const auto p = mDrawingParent.promote(); |
Garfield Tan | de619fa | 2020-10-02 17:13:53 -0700 | [diff] [blame] | 752 | return (p != nullptr) ? p->isSecure() : false; |
Dan Stoza | 2311608 | 2015-06-18 14:58:39 -0700 | [diff] [blame] | 753 | } |
| 754 | |
Pascal Muetschard | f54181b | 2022-12-13 14:53:25 +0100 | [diff] [blame] | 755 | void Layer::transferAvailableJankData(const std::deque<sp<CallbackHandle>>& handles, |
| 756 | std::vector<JankData>& jankData) { |
| 757 | if (mPendingJankClassifications.empty() || |
| 758 | !mPendingJankClassifications.front()->getJankType()) { |
| 759 | return; |
| 760 | } |
| 761 | |
| 762 | bool includeJankData = false; |
| 763 | for (const auto& handle : handles) { |
| 764 | for (const auto& cb : handle->callbackIds) { |
| 765 | if (cb.includeJankData) { |
| 766 | includeJankData = true; |
| 767 | break; |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | if (includeJankData) { |
| 772 | jankData.reserve(mPendingJankClassifications.size()); |
| 773 | break; |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | while (!mPendingJankClassifications.empty() && |
| 778 | mPendingJankClassifications.front()->getJankType()) { |
| 779 | if (includeJankData) { |
| 780 | std::shared_ptr<frametimeline::SurfaceFrame> surfaceFrame = |
| 781 | mPendingJankClassifications.front(); |
| 782 | jankData.emplace_back( |
| 783 | JankData(surfaceFrame->getToken(), surfaceFrame->getJankType().value())); |
| 784 | } |
| 785 | mPendingJankClassifications.pop_front(); |
| 786 | } |
| 787 | } |
| 788 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 789 | // ---------------------------------------------------------------------------- |
| 790 | // transaction |
| 791 | // ---------------------------------------------------------------------------- |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 792 | |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame^] | 793 | uint32_t Layer::doTransaction(uint32_t flags) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 794 | ATRACE_CALL(); |
| 795 | |
Robert Carr | 0758e5d | 2021-03-11 22:15:04 -0800 | [diff] [blame] | 796 | // TODO: This is unfortunate. |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 797 | mDrawingStateModified = mDrawingState.modified; |
| 798 | mDrawingState.modified = false; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 799 | |
Alec Mouri | b416efd | 2018-09-06 21:01:59 +0000 | [diff] [blame] | 800 | const State& s(getDrawingState()); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 801 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 802 | if (updateGeometry()) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 803 | // invalidate and recompute the visible regions if needed |
| 804 | flags |= Layer::eVisibleRegion; |
| 805 | } |
| 806 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 807 | if (s.sequence != mLastCommittedTxSequence) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 808 | // invalidate and recompute the visible regions if needed |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 809 | mLastCommittedTxSequence = s.sequence; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 810 | flags |= eVisibleRegion; |
| 811 | this->contentDirty = true; |
| 812 | |
| 813 | // we may use linear filtering, if the matrix scales us |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 814 | mNeedsFiltering = getActiveTransform(s).needsBilinearFiltering(); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 815 | } |
| 816 | |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 817 | if (!mPotentialCursor && (flags & Layer::eVisibleRegion)) { |
| 818 | mFlinger->mUpdateInputInfo = true; |
| 819 | } |
| 820 | |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame^] | 821 | commitTransaction(mDrawingState); |
Robert Carr | a125784 | 2020-01-31 13:48:28 -0800 | [diff] [blame] | 822 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 823 | return flags; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 824 | } |
| 825 | |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame^] | 826 | void Layer::commitTransaction(State&) { |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 827 | // Set the present state for all bufferlessSurfaceFramesTX to Presented. The |
| 828 | // bufferSurfaceFrameTX will be presented in latchBuffer. |
| 829 | for (auto& [token, surfaceFrame] : mDrawingState.bufferlessSurfaceFramesTX) { |
| 830 | if (surfaceFrame->getPresentState() != PresentState::Presented) { |
| 831 | // With applyPendingStates, we could end up having presented surfaceframes from previous |
| 832 | // states |
Vishnu Nair | 7fe69ed | 2023-02-13 10:13:26 -0800 | [diff] [blame] | 833 | surfaceFrame->setPresentState(PresentState::Presented, mLastLatchTime); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 834 | mFlinger->mFrameTimeline->addSurfaceFrame(surfaceFrame); |
| 835 | } |
| 836 | } |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 837 | mDrawingState.bufferlessSurfaceFramesTX.clear(); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 838 | } |
| 839 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 840 | uint32_t Layer::clearTransactionFlags(uint32_t mask) { |
| 841 | const auto flags = mTransactionFlags & mask; |
| 842 | mTransactionFlags &= ~mask; |
| 843 | return flags; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 844 | } |
| 845 | |
Dominik Laskowski | 9e168db | 2021-05-27 16:05:12 -0700 | [diff] [blame] | 846 | void Layer::setTransactionFlags(uint32_t mask) { |
| 847 | mTransactionFlags |= mask; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 848 | } |
| 849 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 850 | bool Layer::setChildLayer(const sp<Layer>& childLayer, int32_t z) { |
| 851 | ssize_t idx = mCurrentChildren.indexOf(childLayer); |
| 852 | if (idx < 0) { |
| 853 | return false; |
| 854 | } |
| 855 | if (childLayer->setLayer(z)) { |
| 856 | mCurrentChildren.removeAt(idx); |
| 857 | mCurrentChildren.add(childLayer); |
Robert Carr | 503d2bd | 2017-12-04 15:49:47 -0800 | [diff] [blame] | 858 | return true; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 859 | } |
Robert Carr | 503d2bd | 2017-12-04 15:49:47 -0800 | [diff] [blame] | 860 | return false; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 861 | } |
| 862 | |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 863 | bool Layer::setChildRelativeLayer(const sp<Layer>& childLayer, |
| 864 | const sp<IBinder>& relativeToHandle, int32_t relativeZ) { |
| 865 | ssize_t idx = mCurrentChildren.indexOf(childLayer); |
| 866 | if (idx < 0) { |
| 867 | return false; |
| 868 | } |
| 869 | if (childLayer->setRelativeLayer(relativeToHandle, relativeZ)) { |
| 870 | mCurrentChildren.removeAt(idx); |
| 871 | mCurrentChildren.add(childLayer); |
Robert Carr | 503d2bd | 2017-12-04 15:49:47 -0800 | [diff] [blame] | 872 | return true; |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 873 | } |
Robert Carr | 503d2bd | 2017-12-04 15:49:47 -0800 | [diff] [blame] | 874 | return false; |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 875 | } |
| 876 | |
Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 877 | bool Layer::setLayer(int32_t z) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 878 | if (mDrawingState.z == z && !usingRelativeZ(LayerVector::StateSet::Current)) return false; |
| 879 | mDrawingState.sequence++; |
| 880 | mDrawingState.z = z; |
| 881 | mDrawingState.modified = true; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 882 | |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 883 | mFlinger->mSomeChildrenChanged = true; |
| 884 | |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 885 | // Discard all relative layering. |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 886 | if (mDrawingState.zOrderRelativeOf != nullptr) { |
| 887 | sp<Layer> strongRelative = mDrawingState.zOrderRelativeOf.promote(); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 888 | if (strongRelative != nullptr) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 889 | strongRelative->removeZOrderRelative(wp<Layer>::fromExisting(this)); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 890 | } |
chaviw | 606e5cf | 2019-03-01 10:12:10 -0800 | [diff] [blame] | 891 | setZOrderRelativeOf(nullptr); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 892 | } |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 893 | setTransactionFlags(eTransactionNeeded); |
| 894 | return true; |
| 895 | } |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 896 | |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 897 | void Layer::removeZOrderRelative(const wp<Layer>& relative) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 898 | mDrawingState.zOrderRelatives.remove(relative); |
| 899 | mDrawingState.sequence++; |
| 900 | mDrawingState.modified = true; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 901 | setTransactionFlags(eTransactionNeeded); |
| 902 | } |
| 903 | |
| 904 | void Layer::addZOrderRelative(const wp<Layer>& relative) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 905 | mDrawingState.zOrderRelatives.add(relative); |
| 906 | mDrawingState.modified = true; |
| 907 | mDrawingState.sequence++; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 908 | setTransactionFlags(eTransactionNeeded); |
| 909 | } |
| 910 | |
chaviw | 606e5cf | 2019-03-01 10:12:10 -0800 | [diff] [blame] | 911 | void Layer::setZOrderRelativeOf(const wp<Layer>& relativeOf) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 912 | mDrawingState.zOrderRelativeOf = relativeOf; |
| 913 | mDrawingState.sequence++; |
| 914 | mDrawingState.modified = true; |
| 915 | mDrawingState.isRelativeOf = relativeOf != nullptr; |
chaviw | bdb8b80 | 2019-10-14 09:17:12 -0700 | [diff] [blame] | 916 | |
chaviw | 606e5cf | 2019-03-01 10:12:10 -0800 | [diff] [blame] | 917 | setTransactionFlags(eTransactionNeeded); |
| 918 | } |
| 919 | |
Robert Carr | 503d2bd | 2017-12-04 15:49:47 -0800 | [diff] [blame] | 920 | bool Layer::setRelativeLayer(const sp<IBinder>& relativeToHandle, int32_t relativeZ) { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 921 | sp<Layer> relative = LayerHandle::getLayer(relativeToHandle); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 922 | if (relative == nullptr) { |
| 923 | return false; |
| 924 | } |
| 925 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 926 | if (mDrawingState.z == relativeZ && usingRelativeZ(LayerVector::StateSet::Current) && |
| 927 | mDrawingState.zOrderRelativeOf == relative) { |
Robert Carr | 503d2bd | 2017-12-04 15:49:47 -0800 | [diff] [blame] | 928 | return false; |
| 929 | } |
| 930 | |
Robert Carr | 88b85e1 | 2022-03-21 15:47:35 -0700 | [diff] [blame] | 931 | if (CC_UNLIKELY(relative->usingRelativeZ(LayerVector::StateSet::Drawing)) && |
| 932 | (relative->mDrawingState.zOrderRelativeOf == this)) { |
| 933 | ALOGE("Detected relative layer loop between %s and %s", |
| 934 | mName.c_str(), relative->mName.c_str()); |
| 935 | ALOGE("Ignoring new call to set relative layer"); |
| 936 | return false; |
| 937 | } |
| 938 | |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 939 | mFlinger->mSomeChildrenChanged = true; |
| 940 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 941 | mDrawingState.sequence++; |
| 942 | mDrawingState.modified = true; |
| 943 | mDrawingState.z = relativeZ; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 944 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 945 | auto oldZOrderRelativeOf = mDrawingState.zOrderRelativeOf.promote(); |
chaviw | 9ab4bd1 | 2017-11-03 13:11:00 -0700 | [diff] [blame] | 946 | if (oldZOrderRelativeOf != nullptr) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 947 | oldZOrderRelativeOf->removeZOrderRelative(wp<Layer>::fromExisting(this)); |
chaviw | 9ab4bd1 | 2017-11-03 13:11:00 -0700 | [diff] [blame] | 948 | } |
chaviw | 606e5cf | 2019-03-01 10:12:10 -0800 | [diff] [blame] | 949 | setZOrderRelativeOf(relative); |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 950 | relative->addZOrderRelative(wp<Layer>::fromExisting(this)); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 951 | |
| 952 | setTransactionFlags(eTransactionNeeded); |
| 953 | |
| 954 | return true; |
| 955 | } |
| 956 | |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 957 | bool Layer::setTrustedOverlay(bool isTrustedOverlay) { |
| 958 | if (mDrawingState.isTrustedOverlay == isTrustedOverlay) return false; |
| 959 | mDrawingState.isTrustedOverlay = isTrustedOverlay; |
| 960 | mDrawingState.modified = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 961 | mFlinger->mUpdateInputInfo = true; |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 962 | setTransactionFlags(eTransactionNeeded); |
| 963 | return true; |
| 964 | } |
| 965 | |
| 966 | bool Layer::isTrustedOverlay() const { |
| 967 | if (getDrawingState().isTrustedOverlay) { |
| 968 | return true; |
| 969 | } |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 970 | const auto& p = mDrawingParent.promote(); |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 971 | return (p != nullptr) && p->isTrustedOverlay(); |
| 972 | } |
| 973 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 974 | bool Layer::setAlpha(float alpha) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 975 | if (mDrawingState.color.a == alpha) return false; |
| 976 | mDrawingState.sequence++; |
| 977 | mDrawingState.color.a = alpha; |
| 978 | mDrawingState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 979 | setTransactionFlags(eTransactionNeeded); |
| 980 | return true; |
| 981 | } |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 982 | |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 983 | bool Layer::setBackgroundColor(const half3& color, float alpha, ui::Dataspace dataspace) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 984 | if (!mDrawingState.bgColorLayer && alpha == 0) { |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 985 | return false; |
Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 986 | } |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 987 | mDrawingState.sequence++; |
| 988 | mDrawingState.modified = true; |
Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 989 | setTransactionFlags(eTransactionNeeded); |
| 990 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 991 | if (!mDrawingState.bgColorLayer && alpha != 0) { |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 992 | // create background color layer if one does not yet exist |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 993 | uint32_t flags = ISurfaceComposerClient::eFXSurfaceEffect; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 994 | std::string name = mName + "BackgroundColorLayer"; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 995 | mDrawingState.bgColorLayer = mFlinger->getFactory().createEffectLayer( |
Vishnu Nair | 7fb9e5a | 2021-11-08 12:44:05 -0800 | [diff] [blame] | 996 | LayerCreationArgs(mFlinger.get(), nullptr, std::move(name), flags, |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 997 | LayerMetadata())); |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 998 | |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 999 | // add to child list |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1000 | addChild(mDrawingState.bgColorLayer); |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1001 | mFlinger->mLayersAdded = true; |
| 1002 | // set up SF to handle added color layer |
| 1003 | if (isRemovedFromCurrentState()) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1004 | mDrawingState.bgColorLayer->onRemovedFromCurrentState(); |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1005 | } |
| 1006 | mFlinger->setTransactionFlags(eTransactionNeeded); |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1007 | } else if (mDrawingState.bgColorLayer && alpha == 0) { |
| 1008 | mDrawingState.bgColorLayer->reparent(nullptr); |
| 1009 | mDrawingState.bgColorLayer = nullptr; |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1010 | return true; |
| 1011 | } |
| 1012 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1013 | mDrawingState.bgColorLayer->setColor(color); |
| 1014 | mDrawingState.bgColorLayer->setLayer(std::numeric_limits<int32_t>::min()); |
| 1015 | mDrawingState.bgColorLayer->setAlpha(alpha); |
| 1016 | mDrawingState.bgColorLayer->setDataspace(dataspace); |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1017 | |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 1018 | return true; |
| 1019 | } |
| 1020 | |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1021 | bool Layer::setCornerRadius(float cornerRadius) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1022 | if (mDrawingState.cornerRadius == cornerRadius) return false; |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1023 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1024 | mDrawingState.sequence++; |
| 1025 | mDrawingState.cornerRadius = cornerRadius; |
| 1026 | mDrawingState.modified = true; |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1027 | setTransactionFlags(eTransactionNeeded); |
| 1028 | return true; |
| 1029 | } |
| 1030 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1031 | bool Layer::setBackgroundBlurRadius(int backgroundBlurRadius) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1032 | if (mDrawingState.backgroundBlurRadius == backgroundBlurRadius) return false; |
Vishnu Nair | b801a98 | 2021-11-02 15:12:08 -0700 | [diff] [blame] | 1033 | // If we start or stop drawing blur then the layer's visibility state may change so increment |
| 1034 | // the magic sequence number. |
| 1035 | if (mDrawingState.backgroundBlurRadius == 0 || backgroundBlurRadius == 0) { |
| 1036 | mDrawingState.sequence++; |
| 1037 | } |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1038 | mDrawingState.backgroundBlurRadius = backgroundBlurRadius; |
| 1039 | mDrawingState.modified = true; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1040 | setTransactionFlags(eTransactionNeeded); |
| 1041 | return true; |
| 1042 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1043 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1044 | bool Layer::setTransparentRegionHint(const Region& transparent) { |
Vishnu Nair | ea04b6f | 2022-08-19 21:28:17 +0000 | [diff] [blame] | 1045 | mDrawingState.sequence++; |
| 1046 | mDrawingState.transparentRegionHint = transparent; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1047 | mDrawingState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1048 | setTransactionFlags(eTransactionNeeded); |
| 1049 | return true; |
| 1050 | } |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 1051 | |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 1052 | bool Layer::setBlurRegions(const std::vector<BlurRegion>& blurRegions) { |
Vishnu Nair | b801a98 | 2021-11-02 15:12:08 -0700 | [diff] [blame] | 1053 | // If we start or stop drawing blur then the layer's visibility state may change so increment |
| 1054 | // the magic sequence number. |
| 1055 | if (mDrawingState.blurRegions.size() == 0 || blurRegions.size() == 0) { |
| 1056 | mDrawingState.sequence++; |
| 1057 | } |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1058 | mDrawingState.blurRegions = blurRegions; |
| 1059 | mDrawingState.modified = true; |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 1060 | setTransactionFlags(eTransactionNeeded); |
| 1061 | return true; |
| 1062 | } |
| 1063 | |
Vishnu Nair | f6eddb6 | 2021-01-27 22:02:11 -0800 | [diff] [blame] | 1064 | bool Layer::setFlags(uint32_t flags, uint32_t mask) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1065 | const uint32_t newFlags = (mDrawingState.flags & ~mask) | (flags & mask); |
| 1066 | if (mDrawingState.flags == newFlags) return false; |
| 1067 | mDrawingState.sequence++; |
| 1068 | mDrawingState.flags = newFlags; |
| 1069 | mDrawingState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1070 | setTransactionFlags(eTransactionNeeded); |
| 1071 | return true; |
| 1072 | } |
Robert Carr | 99e27f0 | 2016-06-16 15:18:02 -0700 | [diff] [blame] | 1073 | |
chaviw | 2571450 | 2021-02-11 10:01:08 -0800 | [diff] [blame] | 1074 | bool Layer::setCrop(const Rect& crop) { |
Vishnu Nair | ea04b6f | 2022-08-19 21:28:17 +0000 | [diff] [blame] | 1075 | if (mDrawingState.crop == crop) return false; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1076 | mDrawingState.sequence++; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1077 | mDrawingState.crop = crop; |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 1078 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1079 | mDrawingState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1080 | setTransactionFlags(eTransactionNeeded); |
| 1081 | return true; |
| 1082 | } |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 1083 | |
Evan Rosky | ef876c9 | 2019-01-25 17:46:06 -0800 | [diff] [blame] | 1084 | bool Layer::setMetadata(const LayerMetadata& data) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1085 | if (!mDrawingState.metadata.merge(data, true /* eraseEmpty */)) return false; |
| 1086 | mDrawingState.modified = true; |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 1087 | setTransactionFlags(eTransactionNeeded); |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 1088 | return true; |
Daniel Nicoara | 2f5f8a5 | 2016-12-20 16:11:58 -0500 | [diff] [blame] | 1089 | } |
| 1090 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 1091 | bool Layer::setLayerStack(ui::LayerStack layerStack) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1092 | if (mDrawingState.layerStack == layerStack) return false; |
| 1093 | mDrawingState.sequence++; |
| 1094 | mDrawingState.layerStack = layerStack; |
| 1095 | mDrawingState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1096 | setTransactionFlags(eTransactionNeeded); |
| 1097 | return true; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1098 | } |
| 1099 | |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 1100 | bool Layer::setColorSpaceAgnostic(const bool agnostic) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1101 | if (mDrawingState.colorSpaceAgnostic == agnostic) { |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 1102 | return false; |
| 1103 | } |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1104 | mDrawingState.sequence++; |
| 1105 | mDrawingState.colorSpaceAgnostic = agnostic; |
| 1106 | mDrawingState.modified = true; |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 1107 | setTransactionFlags(eTransactionNeeded); |
| 1108 | return true; |
| 1109 | } |
| 1110 | |
Sally Qi | 81d95e6 | 2022-03-21 19:41:33 -0700 | [diff] [blame] | 1111 | bool Layer::setDimmingEnabled(const bool dimmingEnabled) { |
| 1112 | if (mDrawingState.dimmingEnabled == dimmingEnabled) return false; |
| 1113 | |
| 1114 | mDrawingState.sequence++; |
| 1115 | mDrawingState.dimmingEnabled = dimmingEnabled; |
| 1116 | mDrawingState.modified = true; |
| 1117 | setTransactionFlags(eTransactionNeeded); |
| 1118 | return true; |
| 1119 | } |
| 1120 | |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 1121 | bool Layer::setFrameRateSelectionPriority(int32_t priority) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1122 | if (mDrawingState.frameRateSelectionPriority == priority) return false; |
| 1123 | mDrawingState.frameRateSelectionPriority = priority; |
| 1124 | mDrawingState.sequence++; |
| 1125 | mDrawingState.modified = true; |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 1126 | setTransactionFlags(eTransactionNeeded); |
| 1127 | return true; |
| 1128 | } |
| 1129 | |
| 1130 | int32_t Layer::getFrameRateSelectionPriority() const { |
| 1131 | // Check if layer has priority set. |
| 1132 | if (mDrawingState.frameRateSelectionPriority != PRIORITY_UNSET) { |
| 1133 | return mDrawingState.frameRateSelectionPriority; |
| 1134 | } |
| 1135 | // If not, search whether its parents have it set. |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 1136 | sp<Layer> parent = getParent(); |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 1137 | if (parent != nullptr) { |
| 1138 | return parent->getFrameRateSelectionPriority(); |
| 1139 | } |
| 1140 | |
| 1141 | return Layer::PRIORITY_UNSET; |
| 1142 | } |
| 1143 | |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 1144 | bool Layer::setDefaultFrameRateCompatibility(FrameRateCompatibility compatibility) { |
| 1145 | if (mDrawingState.defaultFrameRateCompatibility == compatibility) return false; |
| 1146 | mDrawingState.defaultFrameRateCompatibility = compatibility; |
| 1147 | mDrawingState.modified = true; |
| 1148 | mFlinger->mScheduler->setDefaultFrameRateCompatibility(this); |
| 1149 | setTransactionFlags(eTransactionNeeded); |
| 1150 | return true; |
| 1151 | } |
| 1152 | |
| 1153 | scheduler::LayerInfo::FrameRateCompatibility Layer::getDefaultFrameRateCompatibility() const { |
| 1154 | return mDrawingState.defaultFrameRateCompatibility; |
| 1155 | } |
| 1156 | |
Ady Abraham | aae5ed5 | 2020-06-26 09:32:43 -0700 | [diff] [blame] | 1157 | bool Layer::isLayerFocusedBasedOnPriority(int32_t priority) { |
| 1158 | return priority == PRIORITY_FOCUSED_WITH_MODE || priority == PRIORITY_FOCUSED_WITHOUT_MODE; |
| 1159 | }; |
| 1160 | |
Vishnu Nair | 73908d1 | 2022-10-24 21:46:42 -0700 | [diff] [blame] | 1161 | ui::LayerStack Layer::getLayerStack(LayerVector::StateSet state) const { |
| 1162 | bool useDrawing = state == LayerVector::StateSet::Drawing; |
| 1163 | const auto parent = useDrawing ? mDrawingParent.promote() : mCurrentParent.promote(); |
| 1164 | if (parent) { |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 1165 | return parent->getLayerStack(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1166 | } |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 1167 | return getDrawingState().layerStack; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1168 | } |
| 1169 | |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 1170 | bool Layer::setShadowRadius(float shadowRadius) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1171 | if (mDrawingState.shadowRadius == shadowRadius) { |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 1172 | return false; |
| 1173 | } |
| 1174 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1175 | mDrawingState.sequence++; |
| 1176 | mDrawingState.shadowRadius = shadowRadius; |
| 1177 | mDrawingState.modified = true; |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 1178 | setTransactionFlags(eTransactionNeeded); |
| 1179 | return true; |
| 1180 | } |
| 1181 | |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 1182 | bool Layer::setFixedTransformHint(ui::Transform::RotationFlags fixedTransformHint) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1183 | if (mDrawingState.fixedTransformHint == fixedTransformHint) { |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 1184 | return false; |
| 1185 | } |
| 1186 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1187 | mDrawingState.sequence++; |
| 1188 | mDrawingState.fixedTransformHint = fixedTransformHint; |
| 1189 | mDrawingState.modified = true; |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 1190 | setTransactionFlags(eTransactionNeeded); |
| 1191 | return true; |
| 1192 | } |
| 1193 | |
John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 1194 | bool Layer::setStretchEffect(const StretchEffect& effect) { |
| 1195 | StretchEffect temp = effect; |
| 1196 | temp.sanitize(); |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1197 | if (mDrawingState.stretchEffect == temp) { |
John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 1198 | return false; |
| 1199 | } |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1200 | mDrawingState.sequence++; |
| 1201 | mDrawingState.stretchEffect = temp; |
| 1202 | mDrawingState.modified = true; |
John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 1203 | setTransactionFlags(eTransactionNeeded); |
| 1204 | return true; |
| 1205 | } |
| 1206 | |
John Reck | c00c669 | 2021-02-16 11:37:33 -0500 | [diff] [blame] | 1207 | StretchEffect Layer::getStretchEffect() const { |
| 1208 | if (mDrawingState.stretchEffect.hasEffect()) { |
| 1209 | return mDrawingState.stretchEffect; |
| 1210 | } |
| 1211 | |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 1212 | sp<Layer> parent = getParent(); |
John Reck | c00c669 | 2021-02-16 11:37:33 -0500 | [diff] [blame] | 1213 | if (parent != nullptr) { |
| 1214 | auto effect = parent->getStretchEffect(); |
| 1215 | if (effect.hasEffect()) { |
| 1216 | // TODO(b/179047472): Map it? Or do we make the effect be in global space? |
| 1217 | return effect; |
| 1218 | } |
| 1219 | } |
| 1220 | return StretchEffect{}; |
| 1221 | } |
| 1222 | |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 1223 | bool Layer::enableBorder(bool shouldEnable, float width, const half4& color) { |
| 1224 | if (mBorderEnabled == shouldEnable && mBorderWidth == width && mBorderColor == color) { |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 1225 | return false; |
| 1226 | } |
| 1227 | mBorderEnabled = shouldEnable; |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 1228 | mBorderWidth = width; |
| 1229 | mBorderColor = color; |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 1230 | return true; |
| 1231 | } |
| 1232 | |
| 1233 | bool Layer::isBorderEnabled() { |
| 1234 | return mBorderEnabled; |
| 1235 | } |
| 1236 | |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 1237 | float Layer::getBorderWidth() { |
| 1238 | return mBorderWidth; |
| 1239 | } |
| 1240 | |
| 1241 | const half4& Layer::getBorderColor() { |
| 1242 | return mBorderColor; |
| 1243 | } |
| 1244 | |
Ady Abraham | a850c18 | 2021-08-04 13:04:37 -0700 | [diff] [blame] | 1245 | bool Layer::propagateFrameRateForLayerTree(FrameRate parentFrameRate, bool* transactionNeeded) { |
| 1246 | // The frame rate for layer tree is this layer's frame rate if present, or the parent frame rate |
| 1247 | const auto frameRate = [&] { |
| 1248 | if (mDrawingState.frameRate.rate.isValid() || |
| 1249 | mDrawingState.frameRate.type == FrameRateCompatibility::NoVote) { |
| 1250 | return mDrawingState.frameRate; |
| 1251 | } |
| 1252 | |
| 1253 | return parentFrameRate; |
| 1254 | }(); |
| 1255 | |
| 1256 | *transactionNeeded |= setFrameRateForLayerTree(frameRate); |
| 1257 | |
| 1258 | // The frame rate is propagated to the children |
| 1259 | bool childrenHaveFrameRate = false; |
| 1260 | for (const sp<Layer>& child : mCurrentChildren) { |
| 1261 | childrenHaveFrameRate |= |
| 1262 | child->propagateFrameRateForLayerTree(frameRate, transactionNeeded); |
| 1263 | } |
| 1264 | |
| 1265 | // If we don't have a valid frame rate, but the children do, we set this |
| 1266 | // layer as NoVote to allow the children to control the refresh rate |
| 1267 | if (!frameRate.rate.isValid() && frameRate.type != FrameRateCompatibility::NoVote && |
| 1268 | childrenHaveFrameRate) { |
| 1269 | *transactionNeeded |= |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 1270 | setFrameRateForLayerTree(FrameRate(Fps(), FrameRateCompatibility::NoVote)); |
Ady Abraham | a850c18 | 2021-08-04 13:04:37 -0700 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | // We return whether this layer ot its children has a vote. We ignore ExactOrMultiple votes for |
| 1274 | // the same reason we are allowing touch boost for those layers. See |
Ady Abraham | 6863606 | 2022-11-16 17:07:25 -0800 | [diff] [blame] | 1275 | // RefreshRateSelector::rankFrameRates for details. |
Ady Abraham | a850c18 | 2021-08-04 13:04:37 -0700 | [diff] [blame] | 1276 | const auto layerVotedWithDefaultCompatibility = |
| 1277 | frameRate.rate.isValid() && frameRate.type == FrameRateCompatibility::Default; |
| 1278 | const auto layerVotedWithNoVote = frameRate.type == FrameRateCompatibility::NoVote; |
| 1279 | const auto layerVotedWithExactCompatibility = |
| 1280 | frameRate.rate.isValid() && frameRate.type == FrameRateCompatibility::Exact; |
| 1281 | return layerVotedWithDefaultCompatibility || layerVotedWithNoVote || |
| 1282 | layerVotedWithExactCompatibility || childrenHaveFrameRate; |
| 1283 | } |
| 1284 | |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1285 | void Layer::updateTreeHasFrameRateVote() { |
Ady Abraham | a850c18 | 2021-08-04 13:04:37 -0700 | [diff] [blame] | 1286 | const auto root = [&]() -> sp<Layer> { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 1287 | sp<Layer> layer = sp<Layer>::fromExisting(this); |
Ady Abraham | a850c18 | 2021-08-04 13:04:37 -0700 | [diff] [blame] | 1288 | while (auto parent = layer->getParent()) { |
| 1289 | layer = parent; |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1290 | } |
Ady Abraham | a850c18 | 2021-08-04 13:04:37 -0700 | [diff] [blame] | 1291 | return layer; |
| 1292 | }(); |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1293 | |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1294 | bool transactionNeeded = false; |
Ady Abraham | a850c18 | 2021-08-04 13:04:37 -0700 | [diff] [blame] | 1295 | root->propagateFrameRateForLayerTree({}, &transactionNeeded); |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1296 | |
Ady Abraham | a850c18 | 2021-08-04 13:04:37 -0700 | [diff] [blame] | 1297 | // TODO(b/195668952): we probably don't need eTraversalNeeded here |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1298 | if (transactionNeeded) { |
| 1299 | mFlinger->setTransactionFlags(eTraversalNeeded); |
| 1300 | } |
| 1301 | } |
| 1302 | |
Ady Abraham | 71c437d | 2020-01-31 15:56:57 -0800 | [diff] [blame] | 1303 | bool Layer::setFrameRate(FrameRate frameRate) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1304 | if (mDrawingState.frameRate == frameRate) { |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 1305 | return false; |
| 1306 | } |
| 1307 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1308 | mDrawingState.sequence++; |
| 1309 | mDrawingState.frameRate = frameRate; |
| 1310 | mDrawingState.modified = true; |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1311 | |
| 1312 | updateTreeHasFrameRateVote(); |
| 1313 | |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 1314 | setTransactionFlags(eTransactionNeeded); |
| 1315 | return true; |
| 1316 | } |
| 1317 | |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1318 | void Layer::setFrameTimelineVsyncForBufferTransaction(const FrameTimelineInfo& info, |
| 1319 | nsecs_t postTime) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1320 | mDrawingState.postTime = postTime; |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1321 | |
| 1322 | // Check if one of the bufferlessSurfaceFramesTX contains the same vsyncId. This can happen if |
| 1323 | // there are two transactions with the same token, the first one without a buffer and the |
| 1324 | // second one with a buffer. We promote the bufferlessSurfaceFrame to a bufferSurfaceFrameTX |
| 1325 | // in that case. |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1326 | auto it = mDrawingState.bufferlessSurfaceFramesTX.find(info.vsyncId); |
| 1327 | if (it != mDrawingState.bufferlessSurfaceFramesTX.end()) { |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1328 | // Promote the bufferlessSurfaceFrame to a bufferSurfaceFrameTX |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1329 | mDrawingState.bufferSurfaceFrameTX = it->second; |
| 1330 | mDrawingState.bufferlessSurfaceFramesTX.erase(it); |
| 1331 | mDrawingState.bufferSurfaceFrameTX->promoteToBuffer(); |
| 1332 | mDrawingState.bufferSurfaceFrameTX->setActualQueueTime(postTime); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1333 | } else { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1334 | mDrawingState.bufferSurfaceFrameTX = |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1335 | createSurfaceFrameForBuffer(info, postTime, mTransactionName); |
| 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | void Layer::setFrameTimelineVsyncForBufferlessTransaction(const FrameTimelineInfo& info, |
| 1340 | nsecs_t postTime) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1341 | mDrawingState.frameTimelineInfo = info; |
| 1342 | mDrawingState.postTime = postTime; |
| 1343 | mDrawingState.modified = true; |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 1344 | setTransactionFlags(eTransactionNeeded); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1345 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1346 | if (const auto& bufferSurfaceFrameTX = mDrawingState.bufferSurfaceFrameTX; |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1347 | bufferSurfaceFrameTX != nullptr) { |
| 1348 | if (bufferSurfaceFrameTX->getToken() == info.vsyncId) { |
| 1349 | // BufferSurfaceFrame takes precedence over BufferlessSurfaceFrame. If the same token is |
| 1350 | // being used for BufferSurfaceFrame, don't create a new one. |
| 1351 | return; |
| 1352 | } |
| 1353 | } |
| 1354 | // For Transactions without a buffer, we create only one SurfaceFrame per vsyncId. If multiple |
| 1355 | // transactions use the same vsyncId, we just treat them as one SurfaceFrame (unless they are |
| 1356 | // targeting different vsyncs). |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1357 | auto it = mDrawingState.bufferlessSurfaceFramesTX.find(info.vsyncId); |
| 1358 | if (it == mDrawingState.bufferlessSurfaceFramesTX.end()) { |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1359 | auto surfaceFrame = createSurfaceFrameForTransaction(info, postTime); |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1360 | mDrawingState.bufferlessSurfaceFramesTX[info.vsyncId] = surfaceFrame; |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1361 | } else { |
| 1362 | if (it->second->getPresentState() == PresentState::Presented) { |
| 1363 | // If the SurfaceFrame was already presented, its safe to overwrite it since it must |
| 1364 | // have been from previous vsync. |
| 1365 | it->second = createSurfaceFrameForTransaction(info, postTime); |
| 1366 | } |
| 1367 | } |
| 1368 | } |
| 1369 | |
| 1370 | void Layer::addSurfaceFrameDroppedForBuffer( |
| 1371 | std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame) { |
Adithya Srinivasan | 061c14c | 2021-02-11 01:19:47 +0000 | [diff] [blame] | 1372 | surfaceFrame->setDropTime(systemTime()); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1373 | surfaceFrame->setPresentState(PresentState::Dropped); |
| 1374 | mFlinger->mFrameTimeline->addSurfaceFrame(surfaceFrame); |
| 1375 | } |
| 1376 | |
| 1377 | void Layer::addSurfaceFramePresentedForBuffer( |
| 1378 | std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame, nsecs_t acquireFenceTime, |
| 1379 | nsecs_t currentLatchTime) { |
| 1380 | surfaceFrame->setAcquireFenceTime(acquireFenceTime); |
| 1381 | surfaceFrame->setPresentState(PresentState::Presented, mLastLatchTime); |
| 1382 | mFlinger->mFrameTimeline->addSurfaceFrame(surfaceFrame); |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame^] | 1383 | updateLastLatchTime(currentLatchTime); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | std::shared_ptr<frametimeline::SurfaceFrame> Layer::createSurfaceFrameForTransaction( |
| 1387 | const FrameTimelineInfo& info, nsecs_t postTime) { |
| 1388 | auto surfaceFrame = |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1389 | mFlinger->mFrameTimeline->createSurfaceFrameForToken(info, mOwnerPid, mOwnerUid, |
| 1390 | getSequence(), mName, |
Adithya Srinivasan | 785addd | 2021-03-09 00:38:00 +0000 | [diff] [blame] | 1391 | mTransactionName, |
Adithya Srinivasan | 58069dc | 2021-06-04 20:37:02 +0000 | [diff] [blame] | 1392 | /*isBuffer*/ false, getGameMode()); |
Rachel Lee | ed511ef | 2021-10-11 15:09:51 -0700 | [diff] [blame] | 1393 | surfaceFrame->setActualStartTime(info.startTimeNanos); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1394 | // For Transactions, the post time is considered to be both queue and acquire fence time. |
| 1395 | surfaceFrame->setActualQueueTime(postTime); |
| 1396 | surfaceFrame->setAcquireFenceTime(postTime); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 1397 | const auto fps = mFlinger->mScheduler->getFrameRateOverride(getOwnerUid()); |
| 1398 | if (fps) { |
Alec Mouri | 819f630 | 2021-02-12 15:37:21 -0800 | [diff] [blame] | 1399 | surfaceFrame->setRenderRate(*fps); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 1400 | } |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1401 | onSurfaceFrameCreated(surfaceFrame); |
| 1402 | return surfaceFrame; |
| 1403 | } |
| 1404 | |
| 1405 | std::shared_ptr<frametimeline::SurfaceFrame> Layer::createSurfaceFrameForBuffer( |
| 1406 | const FrameTimelineInfo& info, nsecs_t queueTime, std::string debugName) { |
| 1407 | auto surfaceFrame = |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1408 | mFlinger->mFrameTimeline->createSurfaceFrameForToken(info, mOwnerPid, mOwnerUid, |
Adithya Srinivasan | 785addd | 2021-03-09 00:38:00 +0000 | [diff] [blame] | 1409 | getSequence(), mName, debugName, |
Adithya Srinivasan | 58069dc | 2021-06-04 20:37:02 +0000 | [diff] [blame] | 1410 | /*isBuffer*/ true, getGameMode()); |
Rachel Lee | ed511ef | 2021-10-11 15:09:51 -0700 | [diff] [blame] | 1411 | surfaceFrame->setActualStartTime(info.startTimeNanos); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1412 | // For buffers, acquire fence time will set during latch. |
| 1413 | surfaceFrame->setActualQueueTime(queueTime); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 1414 | const auto fps = mFlinger->mScheduler->getFrameRateOverride(getOwnerUid()); |
| 1415 | if (fps) { |
Alec Mouri | 819f630 | 2021-02-12 15:37:21 -0800 | [diff] [blame] | 1416 | surfaceFrame->setRenderRate(*fps); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 1417 | } |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1418 | onSurfaceFrameCreated(surfaceFrame); |
| 1419 | return surfaceFrame; |
Ady Abraham | 74e1756 | 2020-08-24 18:18:19 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
Ady Abraham | a850c18 | 2021-08-04 13:04:37 -0700 | [diff] [blame] | 1422 | bool Layer::setFrameRateForLayerTree(FrameRate frameRate) { |
| 1423 | if (mDrawingState.frameRateForLayerTree == frameRate) { |
| 1424 | return false; |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1425 | } |
| 1426 | |
Ady Abraham | a850c18 | 2021-08-04 13:04:37 -0700 | [diff] [blame] | 1427 | mDrawingState.frameRateForLayerTree = frameRate; |
Ady Abraham | f467f89 | 2020-07-31 16:01:53 -0700 | [diff] [blame] | 1428 | |
Ady Abraham | a850c18 | 2021-08-04 13:04:37 -0700 | [diff] [blame] | 1429 | // TODO(b/195668952): we probably don't need to dirty visible regions here |
| 1430 | // or even store frameRateForLayerTree in mDrawingState |
| 1431 | mDrawingState.sequence++; |
| 1432 | mDrawingState.modified = true; |
| 1433 | setTransactionFlags(eTransactionNeeded); |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1434 | |
Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 1435 | using LayerUpdateType = scheduler::LayerHistory::LayerUpdateType; |
| 1436 | mFlinger->mScheduler->recordLayerHistory(this, systemTime(), LayerUpdateType::SetFrameRate); |
Ady Abraham | a850c18 | 2021-08-04 13:04:37 -0700 | [diff] [blame] | 1437 | |
| 1438 | return true; |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 1439 | } |
| 1440 | |
Ady Abraham | 59fd8ff | 2021-04-15 20:13:30 -0700 | [diff] [blame] | 1441 | Layer::FrameRate Layer::getFrameRateForLayerTree() const { |
| 1442 | return getDrawingState().frameRateForLayerTree; |
| 1443 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1444 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1445 | bool Layer::isHiddenByPolicy() const { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1446 | const State& s(mDrawingState); |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 1447 | const auto& parent = mDrawingParent.promote(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1448 | if (parent != nullptr && parent->isHiddenByPolicy()) { |
| 1449 | return true; |
| 1450 | } |
Robert Carr | 1c5481e | 2019-07-01 14:42:27 -0700 | [diff] [blame] | 1451 | if (usingRelativeZ(LayerVector::StateSet::Drawing)) { |
| 1452 | auto zOrderRelativeOf = mDrawingState.zOrderRelativeOf.promote(); |
| 1453 | if (zOrderRelativeOf != nullptr) { |
| 1454 | if (zOrderRelativeOf->isHiddenByPolicy()) { |
| 1455 | return true; |
| 1456 | } |
| 1457 | } |
| 1458 | } |
Garfield Tan | 2c1782c | 2022-02-16 15:25:05 -0800 | [diff] [blame] | 1459 | if (CC_UNLIKELY(!isTransformValid())) { |
| 1460 | ALOGW("Hide layer %s because it has invalid transformation.", getDebugName()); |
| 1461 | return true; |
| 1462 | } |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1463 | return s.flags & layer_state_t::eLayerHidden; |
| 1464 | } |
| 1465 | |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 1466 | uint32_t Layer::getEffectiveUsage(uint32_t usage) const { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1467 | // TODO: should we do something special if mSecure is set? |
| 1468 | if (mProtectedByApp) { |
| 1469 | // need a hardware-protected path to external video sink |
| 1470 | usage |= GraphicBuffer::USAGE_PROTECTED; |
Jamie Gennis | 54cc83e | 2010-11-02 11:51:32 -0700 | [diff] [blame] | 1471 | } |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 1472 | if (mPotentialCursor) { |
| 1473 | usage |= GraphicBuffer::USAGE_CURSOR; |
| 1474 | } |
Jamie Gennis | 3599bf2 | 2011-08-10 11:48:07 -0700 | [diff] [blame] | 1475 | usage |= GraphicBuffer::USAGE_HW_COMPOSER; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1476 | return usage; |
Mathias Agopian | b5b7f26 | 2010-05-07 15:58:44 -0700 | [diff] [blame] | 1477 | } |
| 1478 | |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 1479 | void Layer::skipReportingTransformHint() { |
| 1480 | mSkipReportingTransformHint = true; |
| 1481 | } |
| 1482 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 1483 | void Layer::updateTransformHint(ui::Transform::RotationFlags transformHint) { |
| 1484 | if (mFlinger->mDebugDisableTransformHint || transformHint & ui::Transform::ROT_INVALID) { |
| 1485 | transformHint = ui::Transform::ROT_0; |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 1486 | } |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 1487 | |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 1488 | setTransformHint(transformHint); |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 1489 | } |
| 1490 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1491 | // ---------------------------------------------------------------------------- |
| 1492 | // debugging |
| 1493 | // ---------------------------------------------------------------------------- |
| 1494 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1495 | // TODO(marissaw): add new layer state info to layer debugging |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 1496 | gui::LayerDebugInfo Layer::getLayerDebugInfo(const DisplayDevice* display) const { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 1497 | using namespace std::string_literals; |
| 1498 | |
Huihong Luo | 05539a1 | 2022-02-23 10:29:40 -0800 | [diff] [blame] | 1499 | gui::LayerDebugInfo info; |
Alec Mouri | b416efd | 2018-09-06 21:01:59 +0000 | [diff] [blame] | 1500 | const State& ds = getDrawingState(); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1501 | info.mName = getName(); |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 1502 | sp<Layer> parent = mDrawingParent.promote(); |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 1503 | info.mParentName = parent ? parent->getName() : "none"s; |
chaviw | 8a01fa4 | 2019-08-19 12:39:31 -0700 | [diff] [blame] | 1504 | info.mType = getType(); |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 1505 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 1506 | info.mVisibleRegion = getVisibleRegion(display); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1507 | info.mSurfaceDamageRegion = surfaceDamageRegion; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 1508 | info.mLayerStack = getLayerStack().id; |
chaviw | 4e76553 | 2021-04-30 12:11:39 -0500 | [diff] [blame] | 1509 | info.mX = ds.transform.tx(); |
| 1510 | info.mY = ds.transform.ty(); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1511 | info.mZ = ds.z; |
chaviw | 2571450 | 2021-02-11 10:01:08 -0800 | [diff] [blame] | 1512 | info.mCrop = ds.crop; |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 1513 | info.mColor = ds.color; |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1514 | info.mFlags = ds.flags; |
| 1515 | info.mPixelFormat = getPixelFormat(); |
chaviw | 4244e03 | 2019-09-04 11:27:49 -0700 | [diff] [blame] | 1516 | info.mDataSpace = static_cast<android_dataspace>(getDataSpace()); |
chaviw | 4e76553 | 2021-04-30 12:11:39 -0500 | [diff] [blame] | 1517 | info.mMatrix[0][0] = ds.transform[0][0]; |
| 1518 | info.mMatrix[0][1] = ds.transform[0][1]; |
| 1519 | info.mMatrix[1][0] = ds.transform[1][0]; |
| 1520 | info.mMatrix[1][1] = ds.transform[1][1]; |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1521 | { |
chaviw | d62d306 | 2019-09-04 14:48:02 -0700 | [diff] [blame] | 1522 | sp<const GraphicBuffer> buffer = getBuffer(); |
David Sodman | 5b4cffc | 2017-11-23 13:20:29 -0800 | [diff] [blame] | 1523 | if (buffer != 0) { |
| 1524 | info.mActiveBufferWidth = buffer->getWidth(); |
| 1525 | info.mActiveBufferHeight = buffer->getHeight(); |
| 1526 | info.mActiveBufferStride = buffer->getStride(); |
| 1527 | info.mActiveBufferFormat = buffer->format; |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1528 | } else { |
| 1529 | info.mActiveBufferWidth = 0; |
| 1530 | info.mActiveBufferHeight = 0; |
| 1531 | info.mActiveBufferStride = 0; |
| 1532 | info.mActiveBufferFormat = 0; |
| 1533 | } |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1534 | } |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1535 | info.mNumQueuedFrames = getQueuedFrameCount(); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1536 | info.mIsOpaque = isOpaque(ds); |
| 1537 | info.mContentDirty = contentDirty; |
John Reck | c00c669 | 2021-02-16 11:37:33 -0500 | [diff] [blame] | 1538 | info.mStretchEffect = getStretchEffect(); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1539 | return info; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1540 | } |
Chia-I Wu | 83ce7c1 | 2017-10-19 15:18:55 -0700 | [diff] [blame] | 1541 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1542 | void Layer::miniDumpHeader(std::string& result) { |
Marin Shalamanov | 1876e2e | 2020-12-04 13:23:59 +0100 | [diff] [blame] | 1543 | result.append(kDumpTableRowLength, '-'); |
| 1544 | result.append("\n"); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1545 | result.append(" Layer name\n"); |
| 1546 | result.append(" Z | "); |
Ady Abraham | 8f1ee7f | 2019-04-05 10:32:50 -0700 | [diff] [blame] | 1547 | result.append(" Window Type | "); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1548 | result.append(" Comp Type | "); |
Yichi Chen | 6ca3519 | 2018-05-29 12:20:43 +0800 | [diff] [blame] | 1549 | result.append(" Transform | "); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1550 | result.append(" Disp Frame (LTRB) | "); |
Ady Abraham | be23e6a | 2020-05-04 14:51:16 -0700 | [diff] [blame] | 1551 | result.append(" Source Crop (LTRB) | "); |
Marin Shalamanov | 1876e2e | 2020-12-04 13:23:59 +0100 | [diff] [blame] | 1552 | result.append(" Frame Rate (Explicit) (Seamlessness) [Focused]\n"); |
| 1553 | result.append(kDumpTableRowLength, '-'); |
| 1554 | result.append("\n"); |
Ady Abraham | be23e6a | 2020-05-04 14:51:16 -0700 | [diff] [blame] | 1555 | } |
| 1556 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 1557 | void Layer::miniDump(std::string& result, const DisplayDevice& display) const { |
| 1558 | const auto outputLayer = findOutputLayerForDisplay(&display); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 1559 | if (!outputLayer) { |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1560 | return; |
| 1561 | } |
| 1562 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1563 | std::string name; |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1564 | if (mName.length() > 77) { |
| 1565 | std::string shortened; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 1566 | shortened.append(mName, 0, 36); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1567 | shortened.append("[...]"); |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 1568 | shortened.append(mName, mName.length() - 36); |
| 1569 | name = std::move(shortened); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1570 | } else { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 1571 | name = mName; |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1572 | } |
| 1573 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1574 | StringAppendF(&result, " %s\n", name.c_str()); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1575 | |
Alec Mouri | b416efd | 2018-09-06 21:01:59 +0000 | [diff] [blame] | 1576 | const State& layerState(getDrawingState()); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1577 | const auto& outputLayerState = outputLayer->getState(); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 1578 | |
Chia-I Wu | 1e04361 | 2018-03-01 09:45:09 -0800 | [diff] [blame] | 1579 | if (layerState.zOrderRelativeOf != nullptr || mDrawingParent != nullptr) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1580 | StringAppendF(&result, " rel %6d | ", layerState.z); |
Chia-I Wu | 1e04361 | 2018-03-01 09:45:09 -0800 | [diff] [blame] | 1581 | } else { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1582 | StringAppendF(&result, " %10d | ", layerState.z); |
Chia-I Wu | 1e04361 | 2018-03-01 09:45:09 -0800 | [diff] [blame] | 1583 | } |
Ady Abraham | 8f1ee7f | 2019-04-05 10:32:50 -0700 | [diff] [blame] | 1584 | StringAppendF(&result, " %10d | ", mWindowType); |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 1585 | StringAppendF(&result, "%10s | ", toString(getCompositionType(display)).c_str()); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1586 | StringAppendF(&result, "%10s | ", toString(outputLayerState.bufferTransform).c_str()); |
| 1587 | const Rect& frame = outputLayerState.displayFrame; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1588 | StringAppendF(&result, "%4d %4d %4d %4d | ", frame.left, frame.top, frame.right, frame.bottom); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1589 | const FloatRect& crop = outputLayerState.sourceCrop; |
Ady Abraham | be23e6a | 2020-05-04 14:51:16 -0700 | [diff] [blame] | 1590 | StringAppendF(&result, "%6.1f %6.1f %6.1f %6.1f | ", crop.left, crop.top, crop.right, |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1591 | crop.bottom); |
Ady Abraham | f467f89 | 2020-07-31 16:01:53 -0700 | [diff] [blame] | 1592 | const auto frameRate = getFrameRateForLayerTree(); |
| 1593 | if (frameRate.rate.isValid() || frameRate.type != FrameRateCompatibility::Default) { |
| 1594 | StringAppendF(&result, "%s %15s %17s", to_string(frameRate.rate).c_str(), |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 1595 | ftl::enum_string(frameRate.type).c_str(), |
| 1596 | ftl::enum_string(frameRate.seamlessness).c_str()); |
Ady Abraham | be23e6a | 2020-05-04 14:51:16 -0700 | [diff] [blame] | 1597 | } else { |
Marin Shalamanov | 1876e2e | 2020-12-04 13:23:59 +0100 | [diff] [blame] | 1598 | result.append(41, ' '); |
Ady Abraham | be23e6a | 2020-05-04 14:51:16 -0700 | [diff] [blame] | 1599 | } |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1600 | |
Ady Abraham | aae5ed5 | 2020-06-26 09:32:43 -0700 | [diff] [blame] | 1601 | const auto focused = isLayerFocusedBasedOnPriority(getFrameRateSelectionPriority()); |
| 1602 | StringAppendF(&result, " [%s]\n", focused ? "*" : " "); |
| 1603 | |
Marin Shalamanov | 1876e2e | 2020-12-04 13:23:59 +0100 | [diff] [blame] | 1604 | result.append(kDumpTableRowLength, '-'); |
| 1605 | result.append("\n"); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1606 | } |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1607 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1608 | void Layer::dumpFrameStats(std::string& result) const { |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 1609 | mFrameTracker.dumpStats(result); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1610 | } |
| 1611 | |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 1612 | void Layer::clearFrameStats() { |
| 1613 | mFrameTracker.clearStats(); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1614 | } |
| 1615 | |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 1616 | void Layer::logFrameStats() { |
| 1617 | mFrameTracker.logAndResetStats(mName); |
| 1618 | } |
| 1619 | |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 1620 | void Layer::getFrameStats(FrameStats* outStats) const { |
| 1621 | mFrameTracker.getStats(outStats); |
| 1622 | } |
| 1623 | |
Vishnu Nair | 76554eb | 2022-12-09 03:38:36 +0000 | [diff] [blame] | 1624 | void Layer::dumpOffscreenDebugInfo(std::string& result) const { |
| 1625 | std::string hasBuffer = hasBufferOrSidebandStream() ? " (contains buffer)" : ""; |
| 1626 | StringAppendF(&result, "Layer %s%s pid:%d uid:%d\n", getName().c_str(), hasBuffer.c_str(), |
Vishnu Nair | cb8be50 | 2022-10-12 19:03:23 +0000 | [diff] [blame] | 1627 | mOwnerPid, mOwnerUid); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 1628 | } |
| 1629 | |
Brian Anderson | 5ea5e59 | 2016-12-01 16:54:33 -0800 | [diff] [blame] | 1630 | void Layer::onDisconnect() { |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 1631 | const int32_t layerId = getSequence(); |
| 1632 | mFlinger->mTimeStats->onDestroy(layerId); |
| 1633 | mFlinger->mFrameTracer->onDestroy(layerId); |
Brian Anderson | 5ea5e59 | 2016-12-01 16:54:33 -0800 | [diff] [blame] | 1634 | } |
| 1635 | |
Chia-I Wu | 98f1c10 | 2017-05-30 14:54:08 -0700 | [diff] [blame] | 1636 | size_t Layer::getChildrenCount() const { |
| 1637 | size_t count = 0; |
| 1638 | for (const sp<Layer>& child : mCurrentChildren) { |
| 1639 | count += 1 + child->getChildrenCount(); |
| 1640 | } |
| 1641 | return count; |
| 1642 | } |
| 1643 | |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 1644 | void Layer::setGameModeForTree(GameMode gameMode) { |
| 1645 | const auto& currentState = getDrawingState(); |
Huihong Luo | d3d8f8e | 2022-03-08 14:48:46 -0800 | [diff] [blame] | 1646 | if (currentState.metadata.has(gui::METADATA_GAME_MODE)) { |
| 1647 | gameMode = |
| 1648 | static_cast<GameMode>(currentState.metadata.getInt32(gui::METADATA_GAME_MODE, 0)); |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 1649 | } |
| 1650 | setGameMode(gameMode); |
| 1651 | for (const sp<Layer>& child : mCurrentChildren) { |
| 1652 | child->setGameModeForTree(gameMode); |
| 1653 | } |
| 1654 | } |
| 1655 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1656 | void Layer::addChild(const sp<Layer>& layer) { |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 1657 | mFlinger->mSomeChildrenChanged = true; |
Robert Carr | 7f2ed8b | 2019-02-07 14:45:11 -0800 | [diff] [blame] | 1658 | setTransactionFlags(eTransactionNeeded); |
Robert Carr | 1323c95 | 2019-01-28 18:13:27 -0800 | [diff] [blame] | 1659 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1660 | mCurrentChildren.add(layer); |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 1661 | layer->setParent(sp<Layer>::fromExisting(this)); |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 1662 | layer->setGameModeForTree(mGameMode); |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1663 | updateTreeHasFrameRateVote(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | ssize_t Layer::removeChild(const sp<Layer>& layer) { |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 1667 | mFlinger->mSomeChildrenChanged = true; |
Robert Carr | 7f2ed8b | 2019-02-07 14:45:11 -0800 | [diff] [blame] | 1668 | setTransactionFlags(eTransactionNeeded); |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 1669 | |
Robert Carr | 1323c95 | 2019-01-28 18:13:27 -0800 | [diff] [blame] | 1670 | layer->setParent(nullptr); |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1671 | const auto removeResult = mCurrentChildren.remove(layer); |
| 1672 | |
| 1673 | updateTreeHasFrameRateVote(); |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 1674 | layer->setGameModeForTree(GameMode::Unsupported); |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1675 | layer->updateTreeHasFrameRateVote(); |
| 1676 | |
| 1677 | return removeResult; |
| 1678 | } |
| 1679 | |
Robert Carr | 15eae09 | 2018-03-23 13:43:53 -0700 | [diff] [blame] | 1680 | void Layer::setChildrenDrawingParent(const sp<Layer>& newParent) { |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 1681 | for (const sp<Layer>& child : mDrawingChildren) { |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 1682 | child->mDrawingParent = newParent; |
xinying1 | f4200e6 | 2022-04-26 14:41:30 +0800 | [diff] [blame] | 1683 | const float parentShadowRadius = |
| 1684 | newParent->canDrawShadows() ? 0.f : newParent->mEffectiveShadowRadius; |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 1685 | child->computeBounds(newParent->mBounds, newParent->mEffectiveTransform, |
xinying1 | f4200e6 | 2022-04-26 14:41:30 +0800 | [diff] [blame] | 1686 | parentShadowRadius); |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 1687 | } |
| 1688 | } |
| 1689 | |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 1690 | bool Layer::reparent(const sp<IBinder>& newParentHandle) { |
Robert Carr | 54cf5b1 | 2019-01-25 14:02:28 -0800 | [diff] [blame] | 1691 | sp<Layer> newParent; |
| 1692 | if (newParentHandle != nullptr) { |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 1693 | newParent = LayerHandle::getLayer(newParentHandle); |
Robert Carr | 54cf5b1 | 2019-01-25 14:02:28 -0800 | [diff] [blame] | 1694 | if (newParent == nullptr) { |
| 1695 | ALOGE("Unable to promote Layer handle"); |
| 1696 | return false; |
| 1697 | } |
| 1698 | if (newParent == this) { |
| 1699 | ALOGE("Invalid attempt to reparent Layer (%s) to itself", getName().c_str()); |
| 1700 | return false; |
| 1701 | } |
| 1702 | } |
| 1703 | |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 1704 | sp<Layer> parent = getParent(); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 1705 | if (parent != nullptr) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 1706 | parent->removeChild(sp<Layer>::fromExisting(this)); |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 1707 | } |
| 1708 | |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 1709 | if (newParentHandle != nullptr) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 1710 | newParent->addChild(sp<Layer>::fromExisting(this)); |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 1711 | if (!newParent->isRemovedFromCurrentState()) { |
| 1712 | addToCurrentState(); |
| 1713 | } else { |
| 1714 | onRemovedFromCurrentState(); |
| 1715 | } |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 1716 | } else { |
| 1717 | onRemovedFromCurrentState(); |
chaviw | 61626f2 | 2018-11-15 16:26:27 -0800 | [diff] [blame] | 1718 | } |
| 1719 | |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 1720 | return true; |
| 1721 | } |
| 1722 | |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 1723 | bool Layer::setColorTransform(const mat4& matrix) { |
Peiyong Lin | 747321c | 2018-10-01 10:03:11 -0700 | [diff] [blame] | 1724 | static const mat4 identityMatrix = mat4(); |
| 1725 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1726 | if (mDrawingState.colorTransform == matrix) { |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 1727 | return false; |
| 1728 | } |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1729 | ++mDrawingState.sequence; |
| 1730 | mDrawingState.colorTransform = matrix; |
| 1731 | mDrawingState.hasColorTransform = matrix != identityMatrix; |
| 1732 | mDrawingState.modified = true; |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 1733 | setTransactionFlags(eTransactionNeeded); |
| 1734 | return true; |
| 1735 | } |
| 1736 | |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 1737 | mat4 Layer::getColorTransform() const { |
| 1738 | mat4 colorTransform = mat4(getDrawingState().colorTransform); |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 1739 | if (sp<Layer> parent = mDrawingParent.promote(); parent != nullptr) { |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 1740 | colorTransform = parent->getColorTransform() * colorTransform; |
| 1741 | } |
| 1742 | return colorTransform; |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | bool Layer::hasColorTransform() const { |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 1746 | bool hasColorTransform = getDrawingState().hasColorTransform; |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 1747 | if (sp<Layer> parent = mDrawingParent.promote(); parent != nullptr) { |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 1748 | hasColorTransform = hasColorTransform || parent->hasColorTransform(); |
| 1749 | } |
| 1750 | return hasColorTransform; |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 1751 | } |
| 1752 | |
Chia-I Wu | 1148147 | 2018-05-04 10:43:19 -0700 | [diff] [blame] | 1753 | bool Layer::isLegacyDataSpace() const { |
| 1754 | // return true when no higher bits are set |
chaviw | 4244e03 | 2019-09-04 11:27:49 -0700 | [diff] [blame] | 1755 | return !(getDataSpace() & |
| 1756 | (ui::Dataspace::STANDARD_MASK | ui::Dataspace::TRANSFER_MASK | |
| 1757 | ui::Dataspace::RANGE_MASK)); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 1758 | } |
| 1759 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1760 | void Layer::setParent(const sp<Layer>& layer) { |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 1761 | mCurrentParent = layer; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1762 | } |
| 1763 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1764 | int32_t Layer::getZ(LayerVector::StateSet) const { |
| 1765 | return mDrawingState.z; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1766 | } |
| 1767 | |
Robert Carr | 1c5481e | 2019-07-01 14:42:27 -0700 | [diff] [blame] | 1768 | bool Layer::usingRelativeZ(LayerVector::StateSet stateSet) const { |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1769 | const bool useDrawing = stateSet == LayerVector::StateSet::Drawing; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1770 | const State& state = useDrawing ? mDrawingState : mDrawingState; |
chaviw | e5ac40f | 2019-09-24 16:36:55 -0700 | [diff] [blame] | 1771 | return state.isRelativeOf; |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1772 | } |
| 1773 | |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 1774 | __attribute__((no_sanitize("unsigned-integer-overflow"))) LayerVector Layer::makeTraversalList( |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1775 | LayerVector::StateSet stateSet, bool* outSkipRelativeZUsers) { |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1776 | LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid, |
| 1777 | "makeTraversalList received invalid stateSet"); |
| 1778 | const bool useDrawing = stateSet == LayerVector::StateSet::Drawing; |
| 1779 | const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1780 | const State& state = useDrawing ? mDrawingState : mDrawingState; |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1781 | |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1782 | if (state.zOrderRelatives.size() == 0) { |
| 1783 | *outSkipRelativeZUsers = true; |
| 1784 | return children; |
| 1785 | } |
| 1786 | |
chaviw | fd46261 | 2018-05-31 16:11:27 -0700 | [diff] [blame] | 1787 | LayerVector traverse(stateSet); |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1788 | for (const wp<Layer>& weakRelative : state.zOrderRelatives) { |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1789 | sp<Layer> strongRelative = weakRelative.promote(); |
| 1790 | if (strongRelative != nullptr) { |
| 1791 | traverse.add(strongRelative); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1792 | } |
| 1793 | } |
| 1794 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1795 | for (const sp<Layer>& child : children) { |
chaviw | e5ac40f | 2019-09-24 16:36:55 -0700 | [diff] [blame] | 1796 | if (child->usingRelativeZ(stateSet)) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 1797 | continue; |
| 1798 | } |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1799 | traverse.add(child); |
| 1800 | } |
| 1801 | |
| 1802 | return traverse; |
| 1803 | } |
| 1804 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1805 | /** |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1806 | * Negatively signed relatives are before 'this' in Z-order. |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1807 | */ |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1808 | void Layer::traverseInZOrder(LayerVector::StateSet stateSet, const LayerVector::Visitor& visitor) { |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1809 | // In the case we have other layers who are using a relative Z to us, makeTraversalList will |
| 1810 | // produce a new list for traversing, including our relatives, and not including our children |
| 1811 | // who are relatives of another surface. In the case that there are no relative Z, |
| 1812 | // makeTraversalList returns our children directly to avoid significant overhead. |
| 1813 | // However in this case we need to take the responsibility for filtering children which |
| 1814 | // are relatives of another surface here. |
| 1815 | bool skipRelativeZUsers = false; |
| 1816 | const LayerVector list = makeTraversalList(stateSet, &skipRelativeZUsers); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1817 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1818 | size_t i = 0; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1819 | for (; i < list.size(); i++) { |
| 1820 | const auto& relative = list[i]; |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1821 | if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) { |
| 1822 | continue; |
| 1823 | } |
| 1824 | |
chaviw | 301b1d8 | 2019-11-06 13:15:09 -0800 | [diff] [blame] | 1825 | if (relative->getZ(stateSet) >= 0) { |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1826 | break; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1827 | } |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1828 | relative->traverseInZOrder(stateSet, visitor); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1829 | } |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1830 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1831 | visitor(this); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1832 | for (; i < list.size(); i++) { |
| 1833 | const auto& relative = list[i]; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1834 | |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1835 | if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) { |
| 1836 | continue; |
| 1837 | } |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1838 | relative->traverseInZOrder(stateSet, visitor); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1839 | } |
| 1840 | } |
| 1841 | |
| 1842 | /** |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1843 | * Positively signed relatives are before 'this' in reverse Z-order. |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1844 | */ |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1845 | void Layer::traverseInReverseZOrder(LayerVector::StateSet stateSet, |
| 1846 | const LayerVector::Visitor& visitor) { |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1847 | // See traverseInZOrder for documentation. |
| 1848 | bool skipRelativeZUsers = false; |
| 1849 | LayerVector list = makeTraversalList(stateSet, &skipRelativeZUsers); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1850 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1851 | int32_t i = 0; |
Joel Galenson | bf32499 | 2017-11-06 11:04:12 -0800 | [diff] [blame] | 1852 | for (i = int32_t(list.size()) - 1; i >= 0; i--) { |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1853 | const auto& relative = list[i]; |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1854 | |
| 1855 | if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) { |
| 1856 | continue; |
| 1857 | } |
| 1858 | |
chaviw | 301b1d8 | 2019-11-06 13:15:09 -0800 | [diff] [blame] | 1859 | if (relative->getZ(stateSet) < 0) { |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1860 | break; |
| 1861 | } |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1862 | relative->traverseInReverseZOrder(stateSet, visitor); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1863 | } |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1864 | visitor(this); |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 1865 | for (; i >= 0; i--) { |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1866 | const auto& relative = list[i]; |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1867 | |
| 1868 | if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) { |
| 1869 | continue; |
| 1870 | } |
| 1871 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1872 | relative->traverseInReverseZOrder(stateSet, visitor); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1873 | } |
| 1874 | } |
| 1875 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 1876 | void Layer::traverse(LayerVector::StateSet state, const LayerVector::Visitor& visitor) { |
| 1877 | visitor(this); |
| 1878 | const LayerVector& children = |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1879 | state == LayerVector::StateSet::Drawing ? mDrawingChildren : mCurrentChildren; |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 1880 | for (const sp<Layer>& child : children) { |
| 1881 | child->traverse(state, visitor); |
| 1882 | } |
| 1883 | } |
| 1884 | |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1885 | LayerVector Layer::makeChildrenTraversalList(LayerVector::StateSet stateSet, |
| 1886 | const std::vector<Layer*>& layersInTree) { |
| 1887 | LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid, |
| 1888 | "makeTraversalList received invalid stateSet"); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 1889 | const bool useDrawing = stateSet == LayerVector::StateSet::Drawing; |
| 1890 | const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1891 | const State& state = useDrawing ? mDrawingState : mDrawingState; |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1892 | |
chaviw | fd46261 | 2018-05-31 16:11:27 -0700 | [diff] [blame] | 1893 | LayerVector traverse(stateSet); |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1894 | for (const wp<Layer>& weakRelative : state.zOrderRelatives) { |
| 1895 | sp<Layer> strongRelative = weakRelative.promote(); |
| 1896 | // Only add relative layers that are also descendents of the top most parent of the tree. |
| 1897 | // If a relative layer is not a descendent, then it should be ignored. |
| 1898 | if (std::binary_search(layersInTree.begin(), layersInTree.end(), strongRelative.get())) { |
| 1899 | traverse.add(strongRelative); |
| 1900 | } |
| 1901 | } |
| 1902 | |
| 1903 | for (const sp<Layer>& child : children) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1904 | const State& childState = useDrawing ? child->mDrawingState : child->mDrawingState; |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1905 | // If a layer has a relativeOf layer, only ignore if the layer it's relative to is a |
| 1906 | // descendent of the top most parent of the tree. If it's not a descendent, then just add |
| 1907 | // the child here since it won't be added later as a relative. |
| 1908 | if (std::binary_search(layersInTree.begin(), layersInTree.end(), |
| 1909 | childState.zOrderRelativeOf.promote().get())) { |
| 1910 | continue; |
| 1911 | } |
| 1912 | traverse.add(child); |
| 1913 | } |
| 1914 | |
| 1915 | return traverse; |
| 1916 | } |
| 1917 | |
| 1918 | void Layer::traverseChildrenInZOrderInner(const std::vector<Layer*>& layersInTree, |
| 1919 | LayerVector::StateSet stateSet, |
| 1920 | const LayerVector::Visitor& visitor) { |
| 1921 | const LayerVector list = makeChildrenTraversalList(stateSet, layersInTree); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 1922 | |
| 1923 | size_t i = 0; |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1924 | for (; i < list.size(); i++) { |
| 1925 | const auto& relative = list[i]; |
chaviw | 301b1d8 | 2019-11-06 13:15:09 -0800 | [diff] [blame] | 1926 | if (relative->getZ(stateSet) >= 0) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 1927 | break; |
| 1928 | } |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1929 | relative->traverseChildrenInZOrderInner(layersInTree, stateSet, visitor); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 1930 | } |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1931 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 1932 | visitor(this); |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1933 | for (; i < list.size(); i++) { |
| 1934 | const auto& relative = list[i]; |
| 1935 | relative->traverseChildrenInZOrderInner(layersInTree, stateSet, visitor); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 1936 | } |
| 1937 | } |
| 1938 | |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1939 | std::vector<Layer*> Layer::getLayersInTree(LayerVector::StateSet stateSet) { |
| 1940 | const bool useDrawing = stateSet == LayerVector::StateSet::Drawing; |
| 1941 | const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren; |
| 1942 | |
| 1943 | std::vector<Layer*> layersInTree = {this}; |
| 1944 | for (size_t i = 0; i < children.size(); i++) { |
| 1945 | const auto& child = children[i]; |
| 1946 | std::vector<Layer*> childLayers = child->getLayersInTree(stateSet); |
| 1947 | layersInTree.insert(layersInTree.end(), childLayers.cbegin(), childLayers.cend()); |
| 1948 | } |
| 1949 | |
| 1950 | return layersInTree; |
| 1951 | } |
| 1952 | |
| 1953 | void Layer::traverseChildrenInZOrder(LayerVector::StateSet stateSet, |
| 1954 | const LayerVector::Visitor& visitor) { |
| 1955 | std::vector<Layer*> layersInTree = getLayersInTree(stateSet); |
| 1956 | std::sort(layersInTree.begin(), layersInTree.end()); |
| 1957 | traverseChildrenInZOrderInner(layersInTree, stateSet, visitor); |
| 1958 | } |
| 1959 | |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 1960 | ui::Transform Layer::getTransform() const { |
Vishnu Nair | f0c2851 | 2019-02-08 12:40:28 -0800 | [diff] [blame] | 1961 | return mEffectiveTransform; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
Garfield Tan | 2c1782c | 2022-02-16 15:25:05 -0800 | [diff] [blame] | 1964 | bool Layer::isTransformValid() const { |
| 1965 | float transformDet = getTransform().det(); |
| 1966 | return transformDet != 0 && !isinf(transformDet) && !isnan(transformDet); |
| 1967 | } |
| 1968 | |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 1969 | half Layer::getAlpha() const { |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 1970 | const auto& p = mDrawingParent.promote(); |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1971 | |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 1972 | half parentAlpha = (p != nullptr) ? p->getAlpha() : 1.0_hf; |
| 1973 | return parentAlpha * getDrawingState().color.a; |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 1974 | } |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 1975 | |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 1976 | ui::Transform::RotationFlags Layer::getFixedTransformHint() const { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1977 | ui::Transform::RotationFlags fixedTransformHint = mDrawingState.fixedTransformHint; |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 1978 | if (fixedTransformHint != ui::Transform::ROT_INVALID) { |
| 1979 | return fixedTransformHint; |
| 1980 | } |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 1981 | const auto& p = mCurrentParent.promote(); |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 1982 | if (!p) return fixedTransformHint; |
| 1983 | return p->getFixedTransformHint(); |
| 1984 | } |
| 1985 | |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 1986 | half4 Layer::getColor() const { |
| 1987 | const half4 color(getDrawingState().color); |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1988 | return half4(color.r, color.g, color.b, getAlpha()); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 1989 | } |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 1990 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1991 | int32_t Layer::getBackgroundBlurRadius() const { |
Vishnu Nair | 29810f7 | 2022-07-01 16:38:41 +0000 | [diff] [blame] | 1992 | if (getDrawingState().backgroundBlurRadius == 0) { |
| 1993 | return 0; |
| 1994 | } |
Galia Peycheva | da7de0e | 2020-12-03 17:24:35 +0100 | [diff] [blame] | 1995 | |
Vishnu Nair | 29810f7 | 2022-07-01 16:38:41 +0000 | [diff] [blame] | 1996 | const auto& p = mDrawingParent.promote(); |
Galia Peycheva | da7de0e | 2020-12-03 17:24:35 +0100 | [diff] [blame] | 1997 | half parentAlpha = (p != nullptr) ? p->getAlpha() : 1.0_hf; |
| 1998 | return parentAlpha * getDrawingState().backgroundBlurRadius; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1999 | } |
| 2000 | |
Galia Peycheva | e0acf38 | 2021-04-12 21:22:34 +0200 | [diff] [blame] | 2001 | const std::vector<BlurRegion> Layer::getBlurRegions() const { |
| 2002 | auto regionsCopy(getDrawingState().blurRegions); |
Galia Peycheva | 3c28654 | 2021-06-17 15:21:28 +0200 | [diff] [blame] | 2003 | float layerAlpha = getAlpha(); |
Galia Peycheva | e0acf38 | 2021-04-12 21:22:34 +0200 | [diff] [blame] | 2004 | for (auto& region : regionsCopy) { |
| 2005 | region.alpha = region.alpha * layerAlpha; |
| 2006 | } |
| 2007 | return regionsCopy; |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 2008 | } |
| 2009 | |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 2010 | RoundedCornerState Layer::getRoundedCornerState() const { |
Vishnu Nair | 9dbf8e8 | 2021-09-16 16:24:47 -0700 | [diff] [blame] | 2011 | // Get parent settings |
| 2012 | RoundedCornerState parentSettings; |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 2013 | const auto& parent = mDrawingParent.promote(); |
| 2014 | if (parent != nullptr) { |
| 2015 | parentSettings = parent->getRoundedCornerState(); |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 2016 | if (parentSettings.hasRoundedCorners()) { |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 2017 | ui::Transform t = getActiveTransform(getDrawingState()); |
| 2018 | t = t.inverse(); |
Vishnu Nair | 9dbf8e8 | 2021-09-16 16:24:47 -0700 | [diff] [blame] | 2019 | parentSettings.cropRect = t.transform(parentSettings.cropRect); |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 2020 | parentSettings.radius.x *= t.getScaleX(); |
| 2021 | parentSettings.radius.y *= t.getScaleY(); |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 2022 | } |
| 2023 | } |
Vishnu Nair | 9dbf8e8 | 2021-09-16 16:24:47 -0700 | [diff] [blame] | 2024 | |
| 2025 | // Get layer settings |
| 2026 | Rect layerCropRect = getCroppedBufferSize(getDrawingState()); |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 2027 | const vec2 radius(getDrawingState().cornerRadius, getDrawingState().cornerRadius); |
Vishnu Nair | 9dbf8e8 | 2021-09-16 16:24:47 -0700 | [diff] [blame] | 2028 | RoundedCornerState layerSettings(layerCropRect.toFloatRect(), radius); |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 2029 | const bool layerSettingsValid = layerSettings.hasRoundedCorners() && layerCropRect.isValid(); |
Vishnu Nair | 9dbf8e8 | 2021-09-16 16:24:47 -0700 | [diff] [blame] | 2030 | |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 2031 | if (layerSettingsValid && parentSettings.hasRoundedCorners()) { |
Vishnu Nair | 9dbf8e8 | 2021-09-16 16:24:47 -0700 | [diff] [blame] | 2032 | // If the parent and the layer have rounded corner settings, use the parent settings if the |
| 2033 | // parent crop is entirely inside the layer crop. |
| 2034 | // This has limitations and cause rendering artifacts. See b/200300845 for correct fix. |
| 2035 | if (parentSettings.cropRect.left > layerCropRect.left && |
| 2036 | parentSettings.cropRect.top > layerCropRect.top && |
| 2037 | parentSettings.cropRect.right < layerCropRect.right && |
| 2038 | parentSettings.cropRect.bottom < layerCropRect.bottom) { |
| 2039 | return parentSettings; |
| 2040 | } else { |
| 2041 | return layerSettings; |
| 2042 | } |
Vishnu Nair | b184559 | 2021-10-07 12:17:57 -0700 | [diff] [blame] | 2043 | } else if (layerSettingsValid) { |
Vishnu Nair | 9dbf8e8 | 2021-09-16 16:24:47 -0700 | [diff] [blame] | 2044 | return layerSettings; |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 2045 | } else if (parentSettings.hasRoundedCorners()) { |
Vishnu Nair | 9dbf8e8 | 2021-09-16 16:24:47 -0700 | [diff] [blame] | 2046 | return parentSettings; |
| 2047 | } |
| 2048 | return {}; |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 2049 | } |
| 2050 | |
Robert Carr | 88b85e1 | 2022-03-21 15:47:35 -0700 | [diff] [blame] | 2051 | bool Layer::findInHierarchy(const sp<Layer>& l) { |
| 2052 | if (l == this) { |
| 2053 | return true; |
| 2054 | } |
| 2055 | for (auto& child : mDrawingChildren) { |
| 2056 | if (child->findInHierarchy(l)) { |
| 2057 | return true; |
| 2058 | } |
| 2059 | } |
| 2060 | return false; |
| 2061 | } |
| 2062 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 2063 | void Layer::commitChildList() { |
| 2064 | for (size_t i = 0; i < mCurrentChildren.size(); i++) { |
| 2065 | const auto& child = mCurrentChildren[i]; |
| 2066 | child->commitChildList(); |
| 2067 | } |
| 2068 | mDrawingChildren = mCurrentChildren; |
Chia-I Wu | e41dbe6 | 2017-06-13 14:10:56 -0700 | [diff] [blame] | 2069 | mDrawingParent = mCurrentParent; |
Robert Carr | 88b85e1 | 2022-03-21 15:47:35 -0700 | [diff] [blame] | 2070 | if (CC_UNLIKELY(usingRelativeZ(LayerVector::StateSet::Drawing))) { |
| 2071 | auto zOrderRelativeOf = mDrawingState.zOrderRelativeOf.promote(); |
| 2072 | if (zOrderRelativeOf == nullptr) return; |
| 2073 | if (findInHierarchy(zOrderRelativeOf)) { |
| 2074 | ALOGE("Detected Z ordering loop between %s and %s", mName.c_str(), |
| 2075 | zOrderRelativeOf->mName.c_str()); |
| 2076 | ALOGE("Severing rel Z loop, potentially dangerous"); |
| 2077 | mDrawingState.isRelativeOf = false; |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 2078 | zOrderRelativeOf->removeZOrderRelative(wp<Layer>::fromExisting(this)); |
Robert Carr | 88b85e1 | 2022-03-21 15:47:35 -0700 | [diff] [blame] | 2079 | } |
| 2080 | } |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 2081 | } |
| 2082 | |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 2083 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 2084 | void Layer::setInputInfo(const WindowInfo& info) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 2085 | mDrawingState.inputInfo = info; |
Vishnu Nair | 07e2a48 | 2022-10-18 19:18:16 +0000 | [diff] [blame] | 2086 | mDrawingState.touchableRegionCrop = |
| 2087 | LayerHandle::getLayer(info.touchableRegionCropHandle.promote()); |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 2088 | mDrawingState.modified = true; |
Arthur Hung | 9ed4339 | 2022-05-27 06:31:57 +0000 | [diff] [blame] | 2089 | mFlinger->mUpdateInputInfo = true; |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 2090 | setTransactionFlags(eTransactionNeeded); |
| 2091 | } |
| 2092 | |
Vishnu Nair | d8f5e9f | 2022-02-03 10:23:28 -0800 | [diff] [blame] | 2093 | LayerProto* Layer::writeToProto(LayersProto& layersProto, uint32_t traceFlags) { |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 2094 | LayerProto* layerProto = layersProto.add_layers(); |
Vishnu Nair | d8f5e9f | 2022-02-03 10:23:28 -0800 | [diff] [blame] | 2095 | writeToProtoDrawingState(layerProto); |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 2096 | writeToProtoCommonState(layerProto, LayerVector::StateSet::Drawing, traceFlags); |
| 2097 | |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 2098 | if (traceFlags & LayerTracing::TRACE_COMPOSITION) { |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2099 | ftl::FakeGuard guard(mFlinger->mStateLock); // Called from the main thread. |
| 2100 | |
Vishnu Nair | 60db8c0 | 2020-04-02 11:55:16 -0700 | [diff] [blame] | 2101 | // Only populate for the primary display. |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 2102 | if (const auto display = mFlinger->getDefaultDisplayDeviceLocked()) { |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 2103 | const auto compositionType = getCompositionType(*display); |
Vishnu Nair | 60db8c0 | 2020-04-02 11:55:16 -0700 | [diff] [blame] | 2104 | layerProto->set_hwc_composition_type(static_cast<HwcCompositionType>(compositionType)); |
Vishnu Nair | d8f5e9f | 2022-02-03 10:23:28 -0800 | [diff] [blame] | 2105 | LayerProtoHelper::writeToProto(getVisibleRegion(display.get()), |
| 2106 | [&]() { return layerProto->mutable_visible_region(); }); |
Vishnu Nair | 60db8c0 | 2020-04-02 11:55:16 -0700 | [diff] [blame] | 2107 | } |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 2108 | } |
| 2109 | |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 2110 | for (const sp<Layer>& layer : mDrawingChildren) { |
Vishnu Nair | d8f5e9f | 2022-02-03 10:23:28 -0800 | [diff] [blame] | 2111 | layer->writeToProto(layersProto, traceFlags); |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 2112 | } |
chaviw | 6d89e2d | 2020-01-14 14:42:01 -0800 | [diff] [blame] | 2113 | |
| 2114 | return layerProto; |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 2115 | } |
| 2116 | |
Vishnu Nair | d8f5e9f | 2022-02-03 10:23:28 -0800 | [diff] [blame] | 2117 | void Layer::writeToProtoDrawingState(LayerProto* layerInfo) { |
Vishnu Nair | 6b7c5c9 | 2020-09-29 17:27:05 -0700 | [diff] [blame] | 2118 | const ui::Transform transform = getTransform(); |
Vishnu Nair | d37343b | 2022-01-12 16:18:56 -0800 | [diff] [blame] | 2119 | auto buffer = getExternalTexture(); |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 2120 | if (buffer != nullptr) { |
Vishnu Nair | d37343b | 2022-01-12 16:18:56 -0800 | [diff] [blame] | 2121 | LayerProtoHelper::writeToProto(*buffer, |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 2122 | [&]() { return layerInfo->mutable_active_buffer(); }); |
| 2123 | LayerProtoHelper::writeToProtoDeprecated(ui::Transform(getBufferTransform()), |
| 2124 | layerInfo->mutable_buffer_transform()); |
| 2125 | } |
| 2126 | layerInfo->set_invalidate(contentDirty); |
| 2127 | layerInfo->set_is_protected(isProtected()); |
| 2128 | layerInfo->set_dataspace(dataspaceDetails(static_cast<android_dataspace>(getDataSpace()))); |
| 2129 | layerInfo->set_queued_frames(getQueuedFrameCount()); |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 2130 | layerInfo->set_curr_frame(mCurrentFrameNumber); |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 2131 | layerInfo->set_requested_corner_radius(getDrawingState().cornerRadius); |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 2132 | layerInfo->set_corner_radius( |
| 2133 | (getRoundedCornerState().radius.x + getRoundedCornerState().radius.y) / 2.0); |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 2134 | layerInfo->set_background_blur_radius(getBackgroundBlurRadius()); |
| 2135 | layerInfo->set_is_trusted_overlay(isTrustedOverlay()); |
| 2136 | LayerProtoHelper::writeToProtoDeprecated(transform, layerInfo->mutable_transform()); |
| 2137 | LayerProtoHelper::writePositionToProto(transform.tx(), transform.ty(), |
| 2138 | [&]() { return layerInfo->mutable_position(); }); |
| 2139 | LayerProtoHelper::writeToProto(mBounds, [&]() { return layerInfo->mutable_bounds(); }); |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 2140 | LayerProtoHelper::writeToProto(surfaceDamageRegion, |
| 2141 | [&]() { return layerInfo->mutable_damage_region(); }); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 2142 | |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 2143 | if (hasColorTransform()) { |
| 2144 | LayerProtoHelper::writeToProto(getColorTransform(), layerInfo->mutable_color_transform()); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 2145 | } |
| 2146 | |
Vishnu Nair | 60db8c0 | 2020-04-02 11:55:16 -0700 | [diff] [blame] | 2147 | LayerProtoHelper::writeToProto(mSourceBounds, |
| 2148 | [&]() { return layerInfo->mutable_source_bounds(); }); |
| 2149 | LayerProtoHelper::writeToProto(mScreenBounds, |
| 2150 | [&]() { return layerInfo->mutable_screen_bounds(); }); |
| 2151 | LayerProtoHelper::writeToProto(getRoundedCornerState().cropRect, |
| 2152 | [&]() { return layerInfo->mutable_corner_radius_crop(); }); |
| 2153 | layerInfo->set_shadow_radius(mEffectiveShadowRadius); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 2154 | } |
| 2155 | |
| 2156 | void Layer::writeToProtoCommonState(LayerProto* layerInfo, LayerVector::StateSet stateSet, |
chaviw | 4c34a09 | 2020-07-08 11:30:06 -0700 | [diff] [blame] | 2157 | uint32_t traceFlags) { |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 2158 | const bool useDrawing = stateSet == LayerVector::StateSet::Drawing; |
| 2159 | const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 2160 | const State& state = useDrawing ? mDrawingState : mDrawingState; |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 2161 | |
chaviw | 766c9c5 | 2021-02-10 17:36:47 -0800 | [diff] [blame] | 2162 | ui::Transform requestedTransform = state.transform; |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 2163 | |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 2164 | layerInfo->set_id(sequence); |
| 2165 | layerInfo->set_name(getName().c_str()); |
| 2166 | layerInfo->set_type(getType()); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 2167 | |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 2168 | for (const auto& child : children) { |
| 2169 | layerInfo->add_children(child->sequence); |
chaviw | adc40c2 | 2018-07-10 16:57:27 -0700 | [diff] [blame] | 2170 | } |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 2171 | |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 2172 | for (const wp<Layer>& weakRelative : state.zOrderRelatives) { |
| 2173 | sp<Layer> strongRelative = weakRelative.promote(); |
| 2174 | if (strongRelative != nullptr) { |
| 2175 | layerInfo->add_relatives(strongRelative->sequence); |
| 2176 | } |
| 2177 | } |
| 2178 | |
Vishnu Nair | ea04b6f | 2022-08-19 21:28:17 +0000 | [diff] [blame] | 2179 | LayerProtoHelper::writeToProto(state.transparentRegionHint, |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 2180 | [&]() { return layerInfo->mutable_transparent_region(); }); |
| 2181 | |
| 2182 | layerInfo->set_layer_stack(getLayerStack().id); |
| 2183 | layerInfo->set_z(state.z); |
| 2184 | |
| 2185 | LayerProtoHelper::writePositionToProto(requestedTransform.tx(), requestedTransform.ty(), [&]() { |
| 2186 | return layerInfo->mutable_requested_position(); |
| 2187 | }); |
| 2188 | |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 2189 | LayerProtoHelper::writeToProto(state.crop, [&]() { return layerInfo->mutable_crop(); }); |
| 2190 | |
| 2191 | layerInfo->set_is_opaque(isOpaque(state)); |
| 2192 | |
| 2193 | layerInfo->set_pixel_format(decodePixelFormat(getPixelFormat())); |
| 2194 | LayerProtoHelper::writeToProto(getColor(), [&]() { return layerInfo->mutable_color(); }); |
| 2195 | LayerProtoHelper::writeToProto(state.color, |
| 2196 | [&]() { return layerInfo->mutable_requested_color(); }); |
| 2197 | layerInfo->set_flags(state.flags); |
| 2198 | |
| 2199 | LayerProtoHelper::writeToProtoDeprecated(requestedTransform, |
| 2200 | layerInfo->mutable_requested_transform()); |
| 2201 | |
| 2202 | auto parent = useDrawing ? mDrawingParent.promote() : mCurrentParent.promote(); |
| 2203 | if (parent != nullptr) { |
| 2204 | layerInfo->set_parent(parent->sequence); |
| 2205 | } else { |
| 2206 | layerInfo->set_parent(-1); |
| 2207 | } |
| 2208 | |
| 2209 | auto zOrderRelativeOf = state.zOrderRelativeOf.promote(); |
| 2210 | if (zOrderRelativeOf != nullptr) { |
| 2211 | layerInfo->set_z_order_relative_of(zOrderRelativeOf->sequence); |
| 2212 | } else { |
| 2213 | layerInfo->set_z_order_relative_of(-1); |
| 2214 | } |
| 2215 | |
| 2216 | layerInfo->set_is_relative_of(state.isRelativeOf); |
| 2217 | |
| 2218 | layerInfo->set_owner_uid(mOwnerUid); |
| 2219 | |
Arthur Hung | 4cf2d8c | 2022-04-07 14:52:00 +0000 | [diff] [blame] | 2220 | if ((traceFlags & LayerTracing::TRACE_INPUT) && needsInputInfo()) { |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 2221 | WindowInfo info; |
chaviw | 4c34a09 | 2020-07-08 11:30:06 -0700 | [diff] [blame] | 2222 | if (useDrawing) { |
Prabir Pradhan | da0f62c | 2022-07-22 19:53:04 +0000 | [diff] [blame] | 2223 | info = fillInputInfo( |
| 2224 | InputDisplayArgs{.transform = &kIdentityTransform, .isSecure = true}); |
chaviw | 4c34a09 | 2020-07-08 11:30:06 -0700 | [diff] [blame] | 2225 | } else { |
| 2226 | info = state.inputInfo; |
| 2227 | } |
| 2228 | |
| 2229 | LayerProtoHelper::writeToProto(info, state.touchableRegionCrop, |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2230 | [&]() { return layerInfo->mutable_input_window_info(); }); |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 2231 | } |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2232 | |
Vishnu Nair | 00b9013 | 2021-11-05 14:03:40 -0700 | [diff] [blame] | 2233 | if (traceFlags & LayerTracing::TRACE_EXTRA) { |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2234 | auto protoMap = layerInfo->mutable_metadata(); |
| 2235 | for (const auto& entry : state.metadata.mMap) { |
| 2236 | (*protoMap)[entry.first] = std::string(entry.second.cbegin(), entry.second.cend()); |
| 2237 | } |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2238 | } |
Vishnu Nair | d2aaab1 | 2022-02-10 14:49:09 -0800 | [diff] [blame] | 2239 | |
| 2240 | LayerProtoHelper::writeToProto(state.destinationFrame, |
| 2241 | [&]() { return layerInfo->mutable_destination_frame(); }); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 2242 | } |
| 2243 | |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 2244 | bool Layer::isRemovedFromCurrentState() const { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 2245 | return mRemovedFromDrawingState; |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 2246 | } |
| 2247 | |
Prabir Pradhan | 33da946 | 2022-06-14 14:55:57 +0000 | [diff] [blame] | 2248 | // Applies the given transform to the region, while protecting against overflows caused by any |
| 2249 | // offsets. If applying the offset in the transform to any of the Rects in the region would result |
| 2250 | // in an overflow, they are not added to the output Region. |
| 2251 | static Region transformTouchableRegionSafely(const ui::Transform& t, const Region& r, |
| 2252 | const std::string& debugWindowName) { |
| 2253 | // Round the translation using the same rounding strategy used by ui::Transform. |
| 2254 | const auto tx = static_cast<int32_t>(t.tx() + 0.5); |
| 2255 | const auto ty = static_cast<int32_t>(t.ty() + 0.5); |
| 2256 | |
| 2257 | ui::Transform transformWithoutOffset = t; |
| 2258 | transformWithoutOffset.set(0.f, 0.f); |
| 2259 | |
| 2260 | const Region transformed = transformWithoutOffset.transform(r); |
| 2261 | |
| 2262 | // Apply the translation to each of the Rects in the region while discarding any that overflow. |
| 2263 | Region ret; |
| 2264 | for (const auto& rect : transformed) { |
| 2265 | Rect newRect; |
| 2266 | if (__builtin_add_overflow(rect.left, tx, &newRect.left) || |
| 2267 | __builtin_add_overflow(rect.top, ty, &newRect.top) || |
| 2268 | __builtin_add_overflow(rect.right, tx, &newRect.right) || |
| 2269 | __builtin_add_overflow(rect.bottom, ty, &newRect.bottom)) { |
| 2270 | ALOGE("Applying transform to touchable region of window '%s' resulted in an overflow.", |
| 2271 | debugWindowName.c_str()); |
| 2272 | continue; |
| 2273 | } |
| 2274 | ret.orSelf(newRect); |
| 2275 | } |
| 2276 | return ret; |
| 2277 | } |
| 2278 | |
Prabir Pradhan | c9589c1 | 2021-09-22 06:11:43 -0700 | [diff] [blame] | 2279 | void Layer::fillInputFrameInfo(WindowInfo& info, const ui::Transform& screenToDisplay) { |
| 2280 | Rect tmpBounds = getInputBounds(); |
| 2281 | if (!tmpBounds.isValid()) { |
Prabir Pradhan | 6fa425a | 2021-12-16 07:16:04 -0800 | [diff] [blame] | 2282 | info.touchableRegion.clear(); |
| 2283 | // A layer could have invalid input bounds and still expect to receive touch input if it has |
| 2284 | // replaceTouchableRegionWithCrop. For that case, the input transform needs to be calculated |
| 2285 | // correctly to determine the coordinate space for input events. Use an empty rect so that |
| 2286 | // the layer will receive input in its own layer space. |
Prabir Pradhan | c9589c1 | 2021-09-22 06:11:43 -0700 | [diff] [blame] | 2287 | tmpBounds = Rect::EMPTY_RECT; |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 2288 | } |
| 2289 | |
Prabir Pradhan | c9589c1 | 2021-09-22 06:11:43 -0700 | [diff] [blame] | 2290 | // InputDispatcher works in the display device's coordinate space. Here, we calculate the |
| 2291 | // frame and transform used for the layer, which determines the bounds and the coordinate space |
| 2292 | // within which the layer will receive input. |
| 2293 | // |
| 2294 | // The coordinate space within which each of the bounds are specified is explicitly documented |
| 2295 | // in the variable name. For example "inputBoundsInLayer" is specified in layer space. A |
| 2296 | // Transform converts one coordinate space to another, which is apparent in its naming. For |
| 2297 | // example, "layerToDisplay" transforms layer space to display space. |
| 2298 | // |
| 2299 | // Coordinate space definitions: |
| 2300 | // - display: The display device's coordinate space. Correlates to pixels on the display. |
| 2301 | // - screen: The post-rotation coordinate space for the display, a.k.a. logical display space. |
| 2302 | // - layer: The coordinate space of this layer. |
| 2303 | // - input: The coordinate space in which this layer will receive input events. This could be |
| 2304 | // different than layer space if a surfaceInset is used, which changes the origin |
| 2305 | // of the input space. |
| 2306 | const FloatRect inputBoundsInLayer = tmpBounds.toFloatRect(); |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 2307 | |
Prabir Pradhan | c9589c1 | 2021-09-22 06:11:43 -0700 | [diff] [blame] | 2308 | // Clamp surface inset to the input bounds. |
| 2309 | const auto surfaceInset = static_cast<float>(info.surfaceInset); |
| 2310 | const float xSurfaceInset = |
| 2311 | std::max(0.f, std::min(surfaceInset, inputBoundsInLayer.getWidth() / 2.f)); |
| 2312 | const float ySurfaceInset = |
| 2313 | std::max(0.f, std::min(surfaceInset, inputBoundsInLayer.getHeight() / 2.f)); |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 2314 | |
Prabir Pradhan | c9589c1 | 2021-09-22 06:11:43 -0700 | [diff] [blame] | 2315 | // Apply the insets to the input bounds. |
| 2316 | const FloatRect insetBoundsInLayer(inputBoundsInLayer.left + xSurfaceInset, |
| 2317 | inputBoundsInLayer.top + ySurfaceInset, |
| 2318 | inputBoundsInLayer.right - xSurfaceInset, |
| 2319 | inputBoundsInLayer.bottom - ySurfaceInset); |
Ady Abraham | 282f1d7 | 2019-07-24 18:05:56 -0700 | [diff] [blame] | 2320 | |
Prabir Pradhan | c9589c1 | 2021-09-22 06:11:43 -0700 | [diff] [blame] | 2321 | // Crop the input bounds to ensure it is within the parent's bounds. |
| 2322 | const FloatRect croppedInsetBoundsInLayer = mBounds.intersect(insetBoundsInLayer); |
Ady Abraham | 282f1d7 | 2019-07-24 18:05:56 -0700 | [diff] [blame] | 2323 | |
Prabir Pradhan | c9589c1 | 2021-09-22 06:11:43 -0700 | [diff] [blame] | 2324 | const ui::Transform layerToScreen = getInputTransform(); |
| 2325 | const ui::Transform layerToDisplay = screenToDisplay * layerToScreen; |
Vishnu Nair | 8033a49 | 2018-12-05 07:27:23 -0800 | [diff] [blame] | 2326 | |
Prabir Pradhan | c9589c1 | 2021-09-22 06:11:43 -0700 | [diff] [blame] | 2327 | const Rect roundedFrameInDisplay{layerToDisplay.transform(croppedInsetBoundsInLayer)}; |
| 2328 | info.frameLeft = roundedFrameInDisplay.left; |
| 2329 | info.frameTop = roundedFrameInDisplay.top; |
| 2330 | info.frameRight = roundedFrameInDisplay.right; |
| 2331 | info.frameBottom = roundedFrameInDisplay.bottom; |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 2332 | |
Prabir Pradhan | c9589c1 | 2021-09-22 06:11:43 -0700 | [diff] [blame] | 2333 | ui::Transform inputToLayer; |
| 2334 | inputToLayer.set(insetBoundsInLayer.left, insetBoundsInLayer.top); |
| 2335 | const ui::Transform inputToDisplay = layerToDisplay * inputToLayer; |
chaviw | 39cfa2e | 2020-11-04 14:19:02 -0800 | [diff] [blame] | 2336 | |
Prabir Pradhan | c9589c1 | 2021-09-22 06:11:43 -0700 | [diff] [blame] | 2337 | // InputDispatcher expects a display-to-input transform. |
| 2338 | info.transform = inputToDisplay.inverse(); |
| 2339 | |
| 2340 | // The touchable region is specified in the input coordinate space. Change it to display space. |
Prabir Pradhan | 33da946 | 2022-06-14 14:55:57 +0000 | [diff] [blame] | 2341 | info.touchableRegion = |
| 2342 | transformTouchableRegionSafely(inputToDisplay, info.touchableRegion, mName); |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 2343 | } |
| 2344 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 2345 | void Layer::fillTouchOcclusionMode(WindowInfo& info) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 2346 | sp<Layer> p = sp<Layer>::fromExisting(this); |
Bernardo Rufino | a9d0a53 | 2021-06-11 15:59:12 +0100 | [diff] [blame] | 2347 | while (p != nullptr && !p->hasInputInfo()) { |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 2348 | p = p->mDrawingParent.promote(); |
Bernardo Rufino | a9d0a53 | 2021-06-11 15:59:12 +0100 | [diff] [blame] | 2349 | } |
| 2350 | if (p != nullptr) { |
| 2351 | info.touchOcclusionMode = p->mDrawingState.inputInfo.touchOcclusionMode; |
| 2352 | } |
| 2353 | } |
| 2354 | |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 2355 | gui::DropInputMode Layer::getDropInputMode() const { |
| 2356 | gui::DropInputMode mode = mDrawingState.dropInputMode; |
| 2357 | if (mode == gui::DropInputMode::ALL) { |
| 2358 | return mode; |
| 2359 | } |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 2360 | sp<Layer> parent = mDrawingParent.promote(); |
| 2361 | if (parent) { |
| 2362 | gui::DropInputMode parentMode = parent->getDropInputMode(); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 2363 | if (parentMode != gui::DropInputMode::NONE) { |
| 2364 | return parentMode; |
| 2365 | } |
| 2366 | } |
| 2367 | return mode; |
| 2368 | } |
| 2369 | |
| 2370 | void Layer::handleDropInputMode(gui::WindowInfo& info) const { |
Prabir Pradhan | 51e7db0 | 2022-02-07 06:02:57 -0800 | [diff] [blame] | 2371 | if (mDrawingState.inputInfo.inputConfig.test(WindowInfo::InputConfig::NO_INPUT_CHANNEL)) { |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 2372 | return; |
| 2373 | } |
| 2374 | |
| 2375 | // Check if we need to drop input unconditionally |
| 2376 | gui::DropInputMode dropInputMode = getDropInputMode(); |
| 2377 | if (dropInputMode == gui::DropInputMode::ALL) { |
Prabir Pradhan | 51e7db0 | 2022-02-07 06:02:57 -0800 | [diff] [blame] | 2378 | info.inputConfig |= WindowInfo::InputConfig::DROP_INPUT; |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 2379 | ALOGV("Dropping input for %s as requested by policy.", getDebugName()); |
| 2380 | return; |
| 2381 | } |
| 2382 | |
| 2383 | // Check if we need to check if the window is obscured by parent |
| 2384 | if (dropInputMode != gui::DropInputMode::OBSCURED) { |
| 2385 | return; |
| 2386 | } |
| 2387 | |
| 2388 | // Check if the parent has set an alpha on the layer |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 2389 | sp<Layer> parent = mDrawingParent.promote(); |
| 2390 | if (parent && parent->getAlpha() != 1.0_hf) { |
Prabir Pradhan | 51e7db0 | 2022-02-07 06:02:57 -0800 | [diff] [blame] | 2391 | info.inputConfig |= WindowInfo::InputConfig::DROP_INPUT; |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 2392 | ALOGV("Dropping input for %s as requested by policy because alpha=%f", getDebugName(), |
| 2393 | static_cast<float>(getAlpha())); |
| 2394 | } |
| 2395 | |
| 2396 | // Check if the parent has cropped the buffer |
| 2397 | Rect bufferSize = getCroppedBufferSize(getDrawingState()); |
| 2398 | if (!bufferSize.isValid()) { |
Prabir Pradhan | 51e7db0 | 2022-02-07 06:02:57 -0800 | [diff] [blame] | 2399 | info.inputConfig |= WindowInfo::InputConfig::DROP_INPUT_IF_OBSCURED; |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 2400 | return; |
| 2401 | } |
| 2402 | |
| 2403 | // Screenbounds are the layer bounds cropped by parents, transformed to screenspace. |
| 2404 | // To check if the layer has been cropped, we take the buffer bounds, apply the local |
| 2405 | // layer crop and apply the same set of transforms to move to screenspace. If the bounds |
| 2406 | // match then the layer has not been cropped by its parents. |
| 2407 | Rect bufferInScreenSpace(getTransform().transform(bufferSize)); |
| 2408 | bool croppedByParent = bufferInScreenSpace != Rect{mScreenBounds}; |
| 2409 | |
| 2410 | if (croppedByParent) { |
Prabir Pradhan | 51e7db0 | 2022-02-07 06:02:57 -0800 | [diff] [blame] | 2411 | info.inputConfig |= WindowInfo::InputConfig::DROP_INPUT; |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 2412 | ALOGV("Dropping input for %s as requested by policy because buffer is cropped by parent", |
| 2413 | getDebugName()); |
| 2414 | } else { |
| 2415 | // If the layer is not obscured by its parents (by setting an alpha or crop), then only drop |
| 2416 | // input if the window is obscured. This check should be done in surfaceflinger but the |
| 2417 | // logic currently resides in inputflinger. So pass the if_obscured check to input to only |
| 2418 | // drop input events if the window is obscured. |
Prabir Pradhan | 51e7db0 | 2022-02-07 06:02:57 -0800 | [diff] [blame] | 2419 | info.inputConfig |= WindowInfo::InputConfig::DROP_INPUT_IF_OBSCURED; |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 2420 | } |
| 2421 | } |
| 2422 | |
Prabir Pradhan | da0f62c | 2022-07-22 19:53:04 +0000 | [diff] [blame] | 2423 | WindowInfo Layer::fillInputInfo(const InputDisplayArgs& displayArgs) { |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 2424 | if (!hasInputInfo()) { |
| 2425 | mDrawingState.inputInfo.name = getName(); |
| 2426 | mDrawingState.inputInfo.ownerUid = mOwnerUid; |
| 2427 | mDrawingState.inputInfo.ownerPid = mOwnerPid; |
Prabir Pradhan | 51e7db0 | 2022-02-07 06:02:57 -0800 | [diff] [blame] | 2428 | mDrawingState.inputInfo.inputConfig |= WindowInfo::InputConfig::NO_INPUT_CHANNEL; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 2429 | mDrawingState.inputInfo.displayId = getLayerStack().id; |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 2430 | } |
| 2431 | |
Prabir Pradhan | da0f62c | 2022-07-22 19:53:04 +0000 | [diff] [blame] | 2432 | const ui::Transform& displayTransform = |
| 2433 | displayArgs.transform != nullptr ? *displayArgs.transform : kIdentityTransform; |
| 2434 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 2435 | WindowInfo info = mDrawingState.inputInfo; |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 2436 | info.id = sequence; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 2437 | info.displayId = getLayerStack().id; |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 2438 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 2439 | fillInputFrameInfo(info, displayTransform); |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 2440 | |
Prabir Pradhan | da0f62c | 2022-07-22 19:53:04 +0000 | [diff] [blame] | 2441 | if (displayArgs.transform == nullptr) { |
| 2442 | // Do not let the window receive touches if it is not associated with a valid display |
| 2443 | // transform. We still allow the window to receive keys and prevent ANRs. |
| 2444 | info.inputConfig |= WindowInfo::InputConfig::NOT_TOUCHABLE; |
| 2445 | } |
| 2446 | |
Robert Carr | 5dc426e | 2020-06-10 14:29:14 -0700 | [diff] [blame] | 2447 | // For compatibility reasons we let layers which can receive input |
| 2448 | // receive input before they have actually submitted a buffer. Because |
| 2449 | // of this we use canReceiveInput instead of isVisible to check the |
| 2450 | // policy-visibility, ignoring the buffer state. However for layers with |
| 2451 | // hasInputInfo()==false we can use the real visibility state. |
| 2452 | // We are just using these layers for occlusion detection in |
| 2453 | // InputDispatcher, and obviously if they aren't visible they can't occlude |
| 2454 | // anything. |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 2455 | const bool visible = hasInputInfo() ? canReceiveInput() : isVisible(); |
| 2456 | info.setInputConfig(WindowInfo::InputConfig::NOT_VISIBLE, !visible); |
| 2457 | |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 2458 | info.alpha = getAlpha(); |
Bernardo Rufino | a9d0a53 | 2021-06-11 15:59:12 +0100 | [diff] [blame] | 2459 | fillTouchOcclusionMode(info); |
Vishnu Nair | a066d90 | 2021-09-13 18:40:17 -0700 | [diff] [blame] | 2460 | handleDropInputMode(info); |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 2461 | |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 2462 | // If the window will be blacked out on a display because the display does not have the secure |
| 2463 | // flag and the layer has the secure flag set, then drop input. |
Prabir Pradhan | da0f62c | 2022-07-22 19:53:04 +0000 | [diff] [blame] | 2464 | if (!displayArgs.isSecure && isSecure()) { |
Prabir Pradhan | 51e7db0 | 2022-02-07 06:02:57 -0800 | [diff] [blame] | 2465 | info.inputConfig |= WindowInfo::InputConfig::DROP_INPUT; |
Vishnu Nair | 16a938f | 2021-09-24 07:14:54 -0700 | [diff] [blame] | 2466 | } |
| 2467 | |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 2468 | auto cropLayer = mDrawingState.touchableRegionCrop.promote(); |
| 2469 | if (info.replaceTouchableRegionWithCrop) { |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 2470 | const Rect bounds(cropLayer ? cropLayer->mScreenBounds : mScreenBounds); |
| 2471 | info.touchableRegion = Region(displayTransform.transform(bounds)); |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 2472 | } else if (cropLayer != nullptr) { |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 2473 | info.touchableRegion = info.touchableRegion.intersect( |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 2474 | displayTransform.transform(Rect{cropLayer->mScreenBounds})); |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 2475 | } |
| 2476 | |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 2477 | // Inherit the trusted state from the parent hierarchy, but don't clobber the trusted state |
| 2478 | // if it was set by WM for a known system overlay |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 2479 | if (isTrustedOverlay()) { |
| 2480 | info.inputConfig |= WindowInfo::InputConfig::TRUSTED_OVERLAY; |
| 2481 | } |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 2482 | |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2483 | // If the layer is a clone, we need to crop the input region to cloned root to prevent |
| 2484 | // touches from going outside the cloned area. |
| 2485 | if (isClone()) { |
chaviw | 8577ea8 | 2022-06-01 16:32:26 -0500 | [diff] [blame] | 2486 | info.inputConfig |= WindowInfo::InputConfig::CLONE; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 2487 | if (const sp<Layer> clonedRoot = getClonedRoot()) { |
| 2488 | const Rect rect = displayTransform.transform(Rect{clonedRoot->mScreenBounds}); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2489 | info.touchableRegion = info.touchableRegion.intersect(rect); |
| 2490 | } |
| 2491 | } |
| 2492 | |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 2493 | return info; |
| 2494 | } |
| 2495 | |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2496 | sp<Layer> Layer::getClonedRoot() { |
| 2497 | if (mClonedChild != nullptr) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 2498 | return sp<Layer>::fromExisting(this); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2499 | } |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 2500 | if (mDrawingParent == nullptr || mDrawingParent.promote() == nullptr) { |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2501 | return nullptr; |
| 2502 | } |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 2503 | return mDrawingParent.promote()->getClonedRoot(); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2504 | } |
| 2505 | |
Robert Carr | edd1360 | 2020-04-13 17:24:34 -0700 | [diff] [blame] | 2506 | bool Layer::hasInputInfo() const { |
Linus Tufvesson | a185882 | 2022-03-04 09:32:07 +0000 | [diff] [blame] | 2507 | return mDrawingState.inputInfo.token != nullptr || |
| 2508 | mDrawingState.inputInfo.inputConfig.test(WindowInfo::InputConfig::NO_INPUT_CHANNEL); |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 2509 | } |
| 2510 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 2511 | compositionengine::OutputLayer* Layer::findOutputLayerForDisplay( |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 2512 | const DisplayDevice* display) const { |
| 2513 | if (!display) return nullptr; |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 2514 | return display->getCompositionDisplay()->getOutputLayerForLayer(getCompositionEngineLayerFE()); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 2515 | } |
| 2516 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 2517 | Region Layer::getVisibleRegion(const DisplayDevice* display) const { |
| 2518 | const auto outputLayer = findOutputLayerForDisplay(display); |
| 2519 | return outputLayer ? outputLayer->getState().visibleRegion : Region(); |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 2520 | } |
| 2521 | |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 2522 | void Layer::setInitialValuesForClone(const sp<Layer>& clonedFrom) { |
Vishnu Nair | 3bb11d0 | 2021-11-26 09:24:11 -0800 | [diff] [blame] | 2523 | cloneDrawingState(clonedFrom.get()); |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 2524 | mClonedFrom = clonedFrom; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 2525 | mPremultipliedAlpha = clonedFrom->mPremultipliedAlpha; |
| 2526 | mPotentialCursor = clonedFrom->mPotentialCursor; |
| 2527 | mProtectedByApp = clonedFrom->mProtectedByApp; |
| 2528 | updateCloneBufferInfo(); |
| 2529 | } |
| 2530 | |
| 2531 | void Layer::updateCloneBufferInfo() { |
| 2532 | if (!isClone() || !isClonedFromAlive()) { |
| 2533 | return; |
| 2534 | } |
| 2535 | |
| 2536 | sp<Layer> clonedFrom = getClonedFrom(); |
| 2537 | mBufferInfo = clonedFrom->mBufferInfo; |
| 2538 | mSidebandStream = clonedFrom->mSidebandStream; |
| 2539 | surfaceDamageRegion = clonedFrom->surfaceDamageRegion; |
| 2540 | mCurrentFrameNumber = clonedFrom->mCurrentFrameNumber.load(); |
| 2541 | mPreviousFrameNumber = clonedFrom->mPreviousFrameNumber; |
| 2542 | |
| 2543 | // After buffer info is updated, the drawingState from the real layer needs to be copied into |
| 2544 | // the cloned. This is because some properties of drawingState can change when latchBuffer is |
| 2545 | // called. However, copying the drawingState would also overwrite the cloned layer's relatives |
| 2546 | // and touchableRegionCrop. Therefore, temporarily store the relatives so they can be set in |
| 2547 | // the cloned drawingState again. |
| 2548 | wp<Layer> tmpZOrderRelativeOf = mDrawingState.zOrderRelativeOf; |
| 2549 | SortedVector<wp<Layer>> tmpZOrderRelatives = mDrawingState.zOrderRelatives; |
| 2550 | wp<Layer> tmpTouchableRegionCrop = mDrawingState.touchableRegionCrop; |
| 2551 | WindowInfo tmpInputInfo = mDrawingState.inputInfo; |
| 2552 | |
| 2553 | cloneDrawingState(clonedFrom.get()); |
| 2554 | |
| 2555 | mDrawingState.touchableRegionCrop = tmpTouchableRegionCrop; |
| 2556 | mDrawingState.zOrderRelativeOf = tmpZOrderRelativeOf; |
| 2557 | mDrawingState.zOrderRelatives = tmpZOrderRelatives; |
| 2558 | mDrawingState.inputInfo = tmpInputInfo; |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 2559 | } |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 2560 | |
| 2561 | void Layer::updateMirrorInfo() { |
| 2562 | if (mClonedChild == nullptr || !mClonedChild->isClonedFromAlive()) { |
| 2563 | // If mClonedChild is null, there is nothing to mirror. If isClonedFromAlive returns false, |
| 2564 | // it means that there is a clone, but the layer it was cloned from has been destroyed. In |
| 2565 | // that case, we want to delete the reference to the clone since we want it to get |
| 2566 | // destroyed. The root, this layer, will still be around since the client can continue |
| 2567 | // to hold a reference, but no cloned layers will be displayed. |
| 2568 | mClonedChild = nullptr; |
| 2569 | return; |
| 2570 | } |
| 2571 | |
| 2572 | std::map<sp<Layer>, sp<Layer>> clonedLayersMap; |
| 2573 | // If the real layer exists and is in current state, add the clone as a child of the root. |
| 2574 | // There's no need to remove from drawingState when the layer is offscreen since currentState is |
| 2575 | // copied to drawingState for the root layer. So the clonedChild is always removed from |
| 2576 | // drawingState and then needs to be added back each traversal. |
| 2577 | if (!mClonedChild->getClonedFrom()->isRemovedFromCurrentState()) { |
| 2578 | addChildToDrawing(mClonedChild); |
| 2579 | } |
| 2580 | |
| 2581 | mClonedChild->updateClonedDrawingState(clonedLayersMap); |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 2582 | mClonedChild->updateClonedChildren(sp<Layer>::fromExisting(this), clonedLayersMap); |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 2583 | mClonedChild->updateClonedRelatives(clonedLayersMap); |
| 2584 | } |
| 2585 | |
| 2586 | void Layer::updateClonedDrawingState(std::map<sp<Layer>, sp<Layer>>& clonedLayersMap) { |
| 2587 | // If the layer the clone was cloned from is alive, copy the content of the drawingState |
| 2588 | // to the clone. If the real layer is no longer alive, continue traversing the children |
| 2589 | // since we may be able to pull out other children that are still alive. |
| 2590 | if (isClonedFromAlive()) { |
| 2591 | sp<Layer> clonedFrom = getClonedFrom(); |
Vishnu Nair | 3bb11d0 | 2021-11-26 09:24:11 -0800 | [diff] [blame] | 2592 | cloneDrawingState(clonedFrom.get()); |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 2593 | clonedLayersMap.emplace(clonedFrom, sp<Layer>::fromExisting(this)); |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 2594 | } |
| 2595 | |
| 2596 | // The clone layer may have children in drawingState since they may have been created and |
| 2597 | // added from a previous request to updateMirorInfo. This is to ensure we don't recreate clones |
| 2598 | // that already exist, since we can just re-use them. |
| 2599 | // The drawingChildren will not get overwritten by the currentChildren since the clones are |
| 2600 | // not updated in the regular traversal. They are skipped since the root will lose the |
| 2601 | // reference to them when it copies its currentChildren to drawing. |
| 2602 | for (sp<Layer>& child : mDrawingChildren) { |
| 2603 | child->updateClonedDrawingState(clonedLayersMap); |
| 2604 | } |
| 2605 | } |
| 2606 | |
| 2607 | void Layer::updateClonedChildren(const sp<Layer>& mirrorRoot, |
| 2608 | std::map<sp<Layer>, sp<Layer>>& clonedLayersMap) { |
| 2609 | mDrawingChildren.clear(); |
| 2610 | |
| 2611 | if (!isClonedFromAlive()) { |
| 2612 | return; |
| 2613 | } |
| 2614 | |
| 2615 | sp<Layer> clonedFrom = getClonedFrom(); |
| 2616 | for (sp<Layer>& child : clonedFrom->mDrawingChildren) { |
| 2617 | if (child == mirrorRoot) { |
| 2618 | // This is to avoid cyclical mirroring. |
| 2619 | continue; |
| 2620 | } |
| 2621 | sp<Layer> clonedChild = clonedLayersMap[child]; |
| 2622 | if (clonedChild == nullptr) { |
| 2623 | clonedChild = child->createClone(); |
| 2624 | clonedLayersMap[child] = clonedChild; |
| 2625 | } |
| 2626 | addChildToDrawing(clonedChild); |
| 2627 | clonedChild->updateClonedChildren(mirrorRoot, clonedLayersMap); |
| 2628 | } |
| 2629 | } |
| 2630 | |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2631 | void Layer::updateClonedInputInfo(const std::map<sp<Layer>, sp<Layer>>& clonedLayersMap) { |
| 2632 | auto cropLayer = mDrawingState.touchableRegionCrop.promote(); |
| 2633 | if (cropLayer != nullptr) { |
| 2634 | if (clonedLayersMap.count(cropLayer) == 0) { |
| 2635 | // Real layer had a crop layer but it's not in the cloned hierarchy. Just set to |
| 2636 | // self as crop layer to avoid going outside bounds. |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 2637 | mDrawingState.touchableRegionCrop = wp<Layer>::fromExisting(this); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2638 | } else { |
| 2639 | const sp<Layer>& clonedCropLayer = clonedLayersMap.at(cropLayer); |
| 2640 | mDrawingState.touchableRegionCrop = clonedCropLayer; |
| 2641 | } |
| 2642 | } |
| 2643 | // Cloned layers shouldn't handle watch outside since their z order is not determined by |
| 2644 | // WM or the client. |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 2645 | mDrawingState.inputInfo.setInputConfig(WindowInfo::InputConfig::WATCH_OUTSIDE_TOUCH, false); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2646 | } |
| 2647 | |
| 2648 | void Layer::updateClonedRelatives(const std::map<sp<Layer>, sp<Layer>>& clonedLayersMap) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 2649 | mDrawingState.zOrderRelativeOf = wp<Layer>(); |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 2650 | mDrawingState.zOrderRelatives.clear(); |
| 2651 | |
| 2652 | if (!isClonedFromAlive()) { |
| 2653 | return; |
| 2654 | } |
| 2655 | |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2656 | const sp<Layer>& clonedFrom = getClonedFrom(); |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 2657 | for (wp<Layer>& relativeWeak : clonedFrom->mDrawingState.zOrderRelatives) { |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2658 | const sp<Layer>& relative = relativeWeak.promote(); |
| 2659 | if (clonedLayersMap.count(relative) > 0) { |
| 2660 | auto& clonedRelative = clonedLayersMap.at(relative); |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 2661 | mDrawingState.zOrderRelatives.add(clonedRelative); |
| 2662 | } |
| 2663 | } |
| 2664 | |
| 2665 | // Check if the relativeLayer for the real layer is part of the cloned hierarchy. |
| 2666 | // It's possible that the layer it's relative to is outside the requested cloned hierarchy. |
| 2667 | // In that case, we treat the layer as if the relativeOf has been removed. This way, it will |
| 2668 | // still traverse the children, but the layer with the missing relativeOf will not be shown |
| 2669 | // on screen. |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2670 | const sp<Layer>& relativeOf = clonedFrom->mDrawingState.zOrderRelativeOf.promote(); |
| 2671 | if (clonedLayersMap.count(relativeOf) > 0) { |
| 2672 | const sp<Layer>& clonedRelativeOf = clonedLayersMap.at(relativeOf); |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 2673 | mDrawingState.zOrderRelativeOf = clonedRelativeOf; |
| 2674 | } |
| 2675 | |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2676 | updateClonedInputInfo(clonedLayersMap); |
| 2677 | |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 2678 | for (sp<Layer>& child : mDrawingChildren) { |
| 2679 | child->updateClonedRelatives(clonedLayersMap); |
| 2680 | } |
| 2681 | } |
| 2682 | |
| 2683 | void Layer::addChildToDrawing(const sp<Layer>& layer) { |
| 2684 | mDrawingChildren.add(layer); |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 2685 | layer->mDrawingParent = sp<Layer>::fromExisting(this); |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 2686 | } |
| 2687 | |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 2688 | Layer::FrameRateCompatibility Layer::FrameRate::convertCompatibility(int8_t compatibility) { |
| 2689 | switch (compatibility) { |
| 2690 | case ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT: |
| 2691 | return FrameRateCompatibility::Default; |
| 2692 | case ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE: |
| 2693 | return FrameRateCompatibility::ExactOrMultiple; |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 2694 | case ANATIVEWINDOW_FRAME_RATE_EXACT: |
| 2695 | return FrameRateCompatibility::Exact; |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 2696 | case ANATIVEWINDOW_FRAME_RATE_MIN: |
| 2697 | return FrameRateCompatibility::Min; |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 2698 | case ANATIVEWINDOW_FRAME_RATE_NO_VOTE: |
| 2699 | return FrameRateCompatibility::NoVote; |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 2700 | default: |
| 2701 | LOG_ALWAYS_FATAL("Invalid frame rate compatibility value %d", compatibility); |
| 2702 | return FrameRateCompatibility::Default; |
| 2703 | } |
| 2704 | } |
| 2705 | |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 2706 | scheduler::Seamlessness Layer::FrameRate::convertChangeFrameRateStrategy(int8_t strategy) { |
| 2707 | switch (strategy) { |
| 2708 | case ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS: |
| 2709 | return Seamlessness::OnlySeamless; |
| 2710 | case ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS: |
| 2711 | return Seamlessness::SeamedAndSeamless; |
| 2712 | default: |
| 2713 | LOG_ALWAYS_FATAL("Invalid change frame sate strategy value %d", strategy); |
| 2714 | return Seamlessness::Default; |
| 2715 | } |
| 2716 | } |
| 2717 | |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 2718 | bool Layer::isInternalDisplayOverlay() const { |
chaviw | c5676c6 | 2020-09-18 15:01:04 -0700 | [diff] [blame] | 2719 | const State& s(mDrawingState); |
| 2720 | if (s.flags & layer_state_t::eLayerSkipScreenshot) { |
| 2721 | return true; |
| 2722 | } |
| 2723 | |
Rob Carr | c6d2d2b | 2021-10-25 16:51:49 +0000 | [diff] [blame] | 2724 | sp<Layer> parent = mDrawingParent.promote(); |
| 2725 | return parent && parent->isInternalDisplayOverlay(); |
chaviw | c5676c6 | 2020-09-18 15:01:04 -0700 | [diff] [blame] | 2726 | } |
| 2727 | |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 2728 | void Layer::setClonedChild(const sp<Layer>& clonedChild) { |
| 2729 | mClonedChild = clonedChild; |
| 2730 | mHadClonedChild = true; |
| 2731 | mFlinger->mNumClones++; |
| 2732 | } |
| 2733 | |
Vishnu Nair | 9cf4a4d | 2021-09-17 12:16:08 -0700 | [diff] [blame] | 2734 | bool Layer::setDropInputMode(gui::DropInputMode mode) { |
| 2735 | if (mDrawingState.dropInputMode == mode) { |
| 2736 | return false; |
| 2737 | } |
| 2738 | mDrawingState.dropInputMode = mode; |
| 2739 | return true; |
| 2740 | } |
| 2741 | |
Vishnu Nair | 3bb11d0 | 2021-11-26 09:24:11 -0800 | [diff] [blame] | 2742 | void Layer::cloneDrawingState(const Layer* from) { |
| 2743 | mDrawingState = from->mDrawingState; |
| 2744 | // Skip callback info since they are not applicable for cloned layers. |
| 2745 | mDrawingState.releaseBufferListener = nullptr; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 2746 | // TODO (b/238781169) currently broken for mirror layers because we do not |
| 2747 | // track release fences for mirror layers composed on other displays |
Vishnu Nair | 3bb11d0 | 2021-11-26 09:24:11 -0800 | [diff] [blame] | 2748 | mDrawingState.callbackHandles = {}; |
| 2749 | } |
| 2750 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 2751 | void Layer::callReleaseBufferCallback(const sp<ITransactionCompletedListener>& listener, |
| 2752 | const sp<GraphicBuffer>& buffer, uint64_t framenumber, |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 2753 | const sp<Fence>& releaseFence) { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 2754 | if (!listener) { |
| 2755 | return; |
| 2756 | } |
| 2757 | ATRACE_FORMAT_INSTANT("callReleaseBufferCallback %s - %" PRIu64, getDebugName(), framenumber); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 2758 | uint32_t currentMaxAcquiredBufferCount = |
| 2759 | mFlinger->getMaxAcquiredBufferCountForCurrentRefreshRate(mOwnerUid); |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 2760 | listener->onReleaseBuffer({buffer->getId(), framenumber}, |
| 2761 | releaseFence ? releaseFence : Fence::NO_FENCE, |
| 2762 | currentMaxAcquiredBufferCount); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 2763 | } |
| 2764 | |
| 2765 | void Layer::onLayerDisplayed(ftl::SharedFuture<FenceResult> futureFenceResult) { |
| 2766 | // If we are displayed on multiple displays in a single composition cycle then we would |
| 2767 | // need to do careful tracking to enable the use of the mLastClientCompositionFence. |
| 2768 | // For example we can only use it if all the displays are client comp, and we need |
| 2769 | // to merge all the client comp fences. We could do this, but for now we just |
| 2770 | // disable the optimization when a layer is composed on multiple displays. |
| 2771 | if (mClearClientCompositionFenceOnLayerDisplayed) { |
| 2772 | mLastClientCompositionFence = nullptr; |
| 2773 | } else { |
| 2774 | mClearClientCompositionFenceOnLayerDisplayed = true; |
| 2775 | } |
| 2776 | |
| 2777 | // The previous release fence notifies the client that SurfaceFlinger is done with the previous |
| 2778 | // buffer that was presented on this layer. The first transaction that came in this frame that |
| 2779 | // replaced the previous buffer on this layer needs this release fence, because the fence will |
| 2780 | // let the client know when that previous buffer is removed from the screen. |
| 2781 | // |
| 2782 | // Every other transaction on this layer does not need a release fence because no other |
| 2783 | // Transactions that were set on this layer this frame are going to have their preceding buffer |
| 2784 | // removed from the display this frame. |
| 2785 | // |
| 2786 | // For example, if we have 3 transactions this frame. The first transaction doesn't contain a |
| 2787 | // buffer so it doesn't need a previous release fence because the layer still needs the previous |
| 2788 | // buffer. The second transaction contains a buffer so it needs a previous release fence because |
| 2789 | // the previous buffer will be released this frame. The third transaction also contains a |
| 2790 | // buffer. It replaces the buffer in the second transaction. The buffer in the second |
| 2791 | // transaction will now no longer be presented so it is released immediately and the third |
| 2792 | // transaction doesn't need a previous release fence. |
| 2793 | sp<CallbackHandle> ch; |
| 2794 | for (auto& handle : mDrawingState.callbackHandles) { |
| 2795 | if (handle->releasePreviousBuffer && |
| 2796 | mDrawingState.releaseBufferEndpoint == handle->listener) { |
| 2797 | ch = handle; |
| 2798 | break; |
| 2799 | } |
| 2800 | } |
| 2801 | |
| 2802 | // Prevent tracing the same release multiple times. |
| 2803 | if (mPreviousFrameNumber != mPreviousReleasedFrameNumber) { |
| 2804 | mPreviousReleasedFrameNumber = mPreviousFrameNumber; |
| 2805 | } |
| 2806 | |
| 2807 | if (ch != nullptr) { |
| 2808 | ch->previousReleaseCallbackId = mPreviousReleaseCallbackId; |
| 2809 | ch->previousReleaseFences.emplace_back(std::move(futureFenceResult)); |
| 2810 | ch->name = mName; |
| 2811 | } |
| 2812 | } |
| 2813 | |
| 2814 | void Layer::onSurfaceFrameCreated( |
| 2815 | const std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame) { |
| 2816 | while (mPendingJankClassifications.size() >= kPendingClassificationMaxSurfaceFrames) { |
| 2817 | // Too many SurfaceFrames pending classification. The front of the deque is probably not |
| 2818 | // tracked by FrameTimeline and will never be presented. This will only result in a memory |
| 2819 | // leak. |
Pascal Muetschard | 5562626 | 2022-11-08 11:05:19 +0100 | [diff] [blame] | 2820 | if (hasBufferOrSidebandStreamInDrawing()) { |
| 2821 | // Only log for layers with a buffer, since we expect the jank data to be drained for |
| 2822 | // these, while there may be no jank listeners for bufferless layers. |
| 2823 | ALOGW("Removing the front of pending jank deque from layer - %s to prevent memory leak", |
| 2824 | mName.c_str()); |
| 2825 | std::string miniDump = mPendingJankClassifications.front()->miniDump(); |
| 2826 | ALOGD("Head SurfaceFrame mini dump\n%s", miniDump.c_str()); |
| 2827 | } |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 2828 | mPendingJankClassifications.pop_front(); |
| 2829 | } |
| 2830 | mPendingJankClassifications.emplace_back(surfaceFrame); |
| 2831 | } |
| 2832 | |
| 2833 | void Layer::releasePendingBuffer(nsecs_t dequeueReadyTime) { |
| 2834 | for (const auto& handle : mDrawingState.callbackHandles) { |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 2835 | handle->transformHint = mSkipReportingTransformHint |
| 2836 | ? std::nullopt |
| 2837 | : std::make_optional<uint32_t>(mTransformHint); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 2838 | handle->dequeueReadyTime = dequeueReadyTime; |
| 2839 | handle->currentMaxAcquiredBufferCount = |
| 2840 | mFlinger->getMaxAcquiredBufferCountForCurrentRefreshRate(mOwnerUid); |
| 2841 | ATRACE_FORMAT_INSTANT("releasePendingBuffer %s - %" PRIu64, getDebugName(), |
| 2842 | handle->previousReleaseCallbackId.framenumber); |
| 2843 | } |
| 2844 | |
| 2845 | for (auto& handle : mDrawingState.callbackHandles) { |
| 2846 | if (handle->releasePreviousBuffer && |
| 2847 | mDrawingState.releaseBufferEndpoint == handle->listener) { |
| 2848 | handle->previousReleaseCallbackId = mPreviousReleaseCallbackId; |
| 2849 | break; |
| 2850 | } |
| 2851 | } |
| 2852 | |
| 2853 | std::vector<JankData> jankData; |
Pascal Muetschard | f54181b | 2022-12-13 14:53:25 +0100 | [diff] [blame] | 2854 | transferAvailableJankData(mDrawingState.callbackHandles, jankData); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 2855 | mFlinger->getTransactionCallbackInvoker().addCallbackHandles(mDrawingState.callbackHandles, |
| 2856 | jankData); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 2857 | mDrawingState.callbackHandles = {}; |
| 2858 | } |
| 2859 | |
| 2860 | bool Layer::willPresentCurrentTransaction() const { |
| 2861 | // Returns true if the most recent Transaction applied to CurrentState will be presented. |
| 2862 | return (getSidebandStreamChanged() || getAutoRefresh() || |
| 2863 | (mDrawingState.modified && |
| 2864 | (mDrawingState.buffer != nullptr || mDrawingState.bgColorLayer != nullptr))); |
| 2865 | } |
| 2866 | |
| 2867 | bool Layer::setTransform(uint32_t transform) { |
| 2868 | if (mDrawingState.bufferTransform == transform) return false; |
| 2869 | mDrawingState.bufferTransform = transform; |
| 2870 | mDrawingState.modified = true; |
| 2871 | setTransactionFlags(eTransactionNeeded); |
| 2872 | return true; |
| 2873 | } |
| 2874 | |
| 2875 | bool Layer::setTransformToDisplayInverse(bool transformToDisplayInverse) { |
| 2876 | if (mDrawingState.transformToDisplayInverse == transformToDisplayInverse) return false; |
| 2877 | mDrawingState.sequence++; |
| 2878 | mDrawingState.transformToDisplayInverse = transformToDisplayInverse; |
| 2879 | mDrawingState.modified = true; |
| 2880 | setTransactionFlags(eTransactionNeeded); |
| 2881 | return true; |
| 2882 | } |
| 2883 | |
| 2884 | bool Layer::setBufferCrop(const Rect& bufferCrop) { |
| 2885 | if (mDrawingState.bufferCrop == bufferCrop) return false; |
| 2886 | |
| 2887 | mDrawingState.sequence++; |
| 2888 | mDrawingState.bufferCrop = bufferCrop; |
| 2889 | |
| 2890 | mDrawingState.modified = true; |
| 2891 | setTransactionFlags(eTransactionNeeded); |
| 2892 | return true; |
| 2893 | } |
| 2894 | |
| 2895 | bool Layer::setDestinationFrame(const Rect& destinationFrame) { |
| 2896 | if (mDrawingState.destinationFrame == destinationFrame) return false; |
| 2897 | |
| 2898 | mDrawingState.sequence++; |
| 2899 | mDrawingState.destinationFrame = destinationFrame; |
| 2900 | |
| 2901 | mDrawingState.modified = true; |
| 2902 | setTransactionFlags(eTransactionNeeded); |
| 2903 | return true; |
| 2904 | } |
| 2905 | |
| 2906 | // Translate destination frame into scale and position. If a destination frame is not set, use the |
| 2907 | // provided scale and position |
| 2908 | bool Layer::updateGeometry() { |
| 2909 | if ((mDrawingState.flags & layer_state_t::eIgnoreDestinationFrame) || |
| 2910 | mDrawingState.destinationFrame.isEmpty()) { |
| 2911 | // If destination frame is not set, use the requested transform set via |
| 2912 | // Layer::setPosition and Layer::setMatrix. |
| 2913 | return assignTransform(&mDrawingState.transform, mRequestedTransform); |
| 2914 | } |
| 2915 | |
| 2916 | Rect destRect = mDrawingState.destinationFrame; |
| 2917 | int32_t destW = destRect.width(); |
| 2918 | int32_t destH = destRect.height(); |
| 2919 | if (destRect.left < 0) { |
| 2920 | destRect.left = 0; |
| 2921 | destRect.right = destW; |
| 2922 | } |
| 2923 | if (destRect.top < 0) { |
| 2924 | destRect.top = 0; |
| 2925 | destRect.bottom = destH; |
| 2926 | } |
| 2927 | |
| 2928 | if (!mDrawingState.buffer) { |
| 2929 | ui::Transform t; |
| 2930 | t.set(destRect.left, destRect.top); |
| 2931 | return assignTransform(&mDrawingState.transform, t); |
| 2932 | } |
| 2933 | |
| 2934 | uint32_t bufferWidth = mDrawingState.buffer->getWidth(); |
| 2935 | uint32_t bufferHeight = mDrawingState.buffer->getHeight(); |
| 2936 | // Undo any transformations on the buffer. |
| 2937 | if (mDrawingState.bufferTransform & ui::Transform::ROT_90) { |
| 2938 | std::swap(bufferWidth, bufferHeight); |
| 2939 | } |
| 2940 | uint32_t invTransform = DisplayDevice::getPrimaryDisplayRotationFlags(); |
| 2941 | if (mDrawingState.transformToDisplayInverse) { |
| 2942 | if (invTransform & ui::Transform::ROT_90) { |
| 2943 | std::swap(bufferWidth, bufferHeight); |
| 2944 | } |
| 2945 | } |
| 2946 | |
| 2947 | float sx = destW / static_cast<float>(bufferWidth); |
| 2948 | float sy = destH / static_cast<float>(bufferHeight); |
| 2949 | ui::Transform t; |
| 2950 | t.set(sx, 0, 0, sy); |
| 2951 | t.set(destRect.left, destRect.top); |
| 2952 | return assignTransform(&mDrawingState.transform, t); |
| 2953 | } |
| 2954 | |
| 2955 | bool Layer::setMatrix(const layer_state_t::matrix22_t& matrix) { |
| 2956 | if (mRequestedTransform.dsdx() == matrix.dsdx && mRequestedTransform.dtdy() == matrix.dtdy && |
| 2957 | mRequestedTransform.dtdx() == matrix.dtdx && mRequestedTransform.dsdy() == matrix.dsdy) { |
| 2958 | return false; |
| 2959 | } |
| 2960 | |
| 2961 | mRequestedTransform.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy); |
| 2962 | |
| 2963 | mDrawingState.sequence++; |
| 2964 | mDrawingState.modified = true; |
| 2965 | setTransactionFlags(eTransactionNeeded); |
| 2966 | |
| 2967 | return true; |
| 2968 | } |
| 2969 | |
| 2970 | bool Layer::setPosition(float x, float y) { |
| 2971 | if (mRequestedTransform.tx() == x && mRequestedTransform.ty() == y) { |
| 2972 | return false; |
| 2973 | } |
| 2974 | |
| 2975 | mRequestedTransform.set(x, y); |
| 2976 | |
| 2977 | mDrawingState.sequence++; |
| 2978 | mDrawingState.modified = true; |
| 2979 | setTransactionFlags(eTransactionNeeded); |
| 2980 | |
| 2981 | return true; |
| 2982 | } |
| 2983 | |
| 2984 | bool Layer::setBuffer(std::shared_ptr<renderengine::ExternalTexture>& buffer, |
| 2985 | const BufferData& bufferData, nsecs_t postTime, nsecs_t desiredPresentTime, |
| 2986 | bool isAutoTimestamp, std::optional<nsecs_t> dequeueTime, |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 2987 | const FrameTimelineInfo& info) { |
Chavi Weingarten | 009619f | 2022-09-15 20:27:25 +0000 | [diff] [blame] | 2988 | ATRACE_FORMAT("setBuffer %s - hasBuffer=%s", getDebugName(), (buffer ? "true" : "false")); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 2989 | if (!buffer) { |
| 2990 | return false; |
| 2991 | } |
| 2992 | |
| 2993 | const bool frameNumberChanged = |
| 2994 | bufferData.flags.test(BufferData::BufferDataChange::frameNumberChanged); |
| 2995 | const uint64_t frameNumber = |
| 2996 | frameNumberChanged ? bufferData.frameNumber : mDrawingState.frameNumber + 1; |
Chavi Weingarten | 009619f | 2022-09-15 20:27:25 +0000 | [diff] [blame] | 2997 | ATRACE_FORMAT_INSTANT("setBuffer %s - %" PRIu64, getDebugName(), frameNumber); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 2998 | |
| 2999 | if (mDrawingState.buffer) { |
| 3000 | mReleasePreviousBuffer = true; |
| 3001 | if (!mBufferInfo.mBuffer || |
| 3002 | (!mDrawingState.buffer->hasSameBuffer(*mBufferInfo.mBuffer) || |
| 3003 | mDrawingState.frameNumber != mBufferInfo.mFrameNumber)) { |
| 3004 | // If mDrawingState has a buffer, and we are about to update again |
| 3005 | // before swapping to drawing state, then the first buffer will be |
| 3006 | // dropped and we should decrement the pending buffer count and |
| 3007 | // call any release buffer callbacks if set. |
| 3008 | callReleaseBufferCallback(mDrawingState.releaseBufferListener, |
| 3009 | mDrawingState.buffer->getBuffer(), mDrawingState.frameNumber, |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 3010 | mDrawingState.acquireFence); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3011 | decrementPendingBufferCount(); |
| 3012 | if (mDrawingState.bufferSurfaceFrameTX != nullptr && |
| 3013 | mDrawingState.bufferSurfaceFrameTX->getPresentState() != PresentState::Presented) { |
| 3014 | addSurfaceFrameDroppedForBuffer(mDrawingState.bufferSurfaceFrameTX); |
| 3015 | mDrawingState.bufferSurfaceFrameTX.reset(); |
| 3016 | } |
| 3017 | } else if (EARLY_RELEASE_ENABLED && mLastClientCompositionFence != nullptr) { |
| 3018 | callReleaseBufferCallback(mDrawingState.releaseBufferListener, |
| 3019 | mDrawingState.buffer->getBuffer(), mDrawingState.frameNumber, |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 3020 | mLastClientCompositionFence); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3021 | mLastClientCompositionFence = nullptr; |
| 3022 | } |
| 3023 | } |
| 3024 | |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 3025 | mDrawingState.producerId = bufferData.producerId; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3026 | mDrawingState.frameNumber = frameNumber; |
| 3027 | mDrawingState.releaseBufferListener = bufferData.releaseBufferListener; |
| 3028 | mDrawingState.buffer = std::move(buffer); |
| 3029 | mDrawingState.clientCacheId = bufferData.cachedBuffer; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3030 | mDrawingState.acquireFence = bufferData.flags.test(BufferData::BufferDataChange::fenceChanged) |
| 3031 | ? bufferData.acquireFence |
| 3032 | : Fence::NO_FENCE; |
| 3033 | mDrawingState.acquireFenceTime = std::make_unique<FenceTime>(mDrawingState.acquireFence); |
| 3034 | if (mDrawingState.acquireFenceTime->getSignalTime() == Fence::SIGNAL_TIME_PENDING) { |
| 3035 | // We latched this buffer unsiganled, so we need to pass the acquire fence |
| 3036 | // on the callback instead of just the acquire time, since it's unknown at |
| 3037 | // this point. |
| 3038 | mCallbackHandleAcquireTimeOrFence = mDrawingState.acquireFence; |
| 3039 | } else { |
| 3040 | mCallbackHandleAcquireTimeOrFence = mDrawingState.acquireFenceTime->getSignalTime(); |
| 3041 | } |
| 3042 | |
| 3043 | mDrawingState.modified = true; |
| 3044 | setTransactionFlags(eTransactionNeeded); |
| 3045 | |
| 3046 | const int32_t layerId = getSequence(); |
| 3047 | mFlinger->mTimeStats->setPostTime(layerId, mDrawingState.frameNumber, getName().c_str(), |
| 3048 | mOwnerUid, postTime, getGameMode()); |
| 3049 | mDrawingState.desiredPresentTime = desiredPresentTime; |
| 3050 | mDrawingState.isAutoTimestamp = isAutoTimestamp; |
| 3051 | |
| 3052 | const nsecs_t presentTime = [&] { |
| 3053 | if (!isAutoTimestamp) return desiredPresentTime; |
| 3054 | |
| 3055 | const auto prediction = |
| 3056 | mFlinger->mFrameTimeline->getTokenManager()->getPredictionsForToken(info.vsyncId); |
| 3057 | if (prediction.has_value()) return prediction->presentTime; |
| 3058 | |
| 3059 | return static_cast<nsecs_t>(0); |
| 3060 | }(); |
| 3061 | |
| 3062 | using LayerUpdateType = scheduler::LayerHistory::LayerUpdateType; |
| 3063 | mFlinger->mScheduler->recordLayerHistory(this, presentTime, LayerUpdateType::Buffer); |
| 3064 | |
| 3065 | setFrameTimelineVsyncForBufferTransaction(info, postTime); |
| 3066 | |
| 3067 | if (dequeueTime && *dequeueTime != 0) { |
| 3068 | const uint64_t bufferId = mDrawingState.buffer->getId(); |
| 3069 | mFlinger->mFrameTracer->traceNewLayer(layerId, getName().c_str()); |
| 3070 | mFlinger->mFrameTracer->traceTimestamp(layerId, bufferId, frameNumber, *dequeueTime, |
| 3071 | FrameTracer::FrameEvent::DEQUEUE); |
| 3072 | mFlinger->mFrameTracer->traceTimestamp(layerId, bufferId, frameNumber, postTime, |
| 3073 | FrameTracer::FrameEvent::QUEUE); |
| 3074 | } |
| 3075 | |
| 3076 | mDrawingState.releaseBufferEndpoint = bufferData.releaseBufferEndpoint; |
| 3077 | return true; |
| 3078 | } |
| 3079 | |
| 3080 | bool Layer::setDataspace(ui::Dataspace dataspace) { |
| 3081 | mDrawingState.dataspaceRequested = true; |
| 3082 | if (mDrawingState.dataspace == dataspace) return false; |
| 3083 | mDrawingState.dataspace = dataspace; |
| 3084 | mDrawingState.modified = true; |
| 3085 | setTransactionFlags(eTransactionNeeded); |
| 3086 | return true; |
| 3087 | } |
| 3088 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3089 | bool Layer::setExtendedRangeBrightness(float currentBufferRatio, float desiredRatio) { |
| 3090 | if (mDrawingState.currentSdrHdrRatio == currentBufferRatio && |
| 3091 | mDrawingState.desiredSdrHdrRatio == desiredRatio) |
| 3092 | return false; |
| 3093 | mDrawingState.currentSdrHdrRatio = currentBufferRatio; |
| 3094 | mDrawingState.desiredSdrHdrRatio = desiredRatio; |
| 3095 | mDrawingState.modified = true; |
| 3096 | setTransactionFlags(eTransactionNeeded); |
| 3097 | return true; |
| 3098 | } |
| 3099 | |
Alec Mouri | f4af03e | 2023-02-11 00:25:24 +0000 | [diff] [blame] | 3100 | bool Layer::setCachingHint(gui::CachingHint cachingHint) { |
| 3101 | if (mDrawingState.cachingHint == cachingHint) return false; |
| 3102 | mDrawingState.cachingHint = cachingHint; |
| 3103 | mDrawingState.modified = true; |
| 3104 | setTransactionFlags(eTransactionNeeded); |
| 3105 | return true; |
| 3106 | } |
| 3107 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3108 | bool Layer::setHdrMetadata(const HdrMetadata& hdrMetadata) { |
| 3109 | if (mDrawingState.hdrMetadata == hdrMetadata) return false; |
| 3110 | mDrawingState.hdrMetadata = hdrMetadata; |
| 3111 | mDrawingState.modified = true; |
| 3112 | setTransactionFlags(eTransactionNeeded); |
| 3113 | return true; |
| 3114 | } |
| 3115 | |
| 3116 | bool Layer::setSurfaceDamageRegion(const Region& surfaceDamage) { |
| 3117 | mDrawingState.surfaceDamageRegion = surfaceDamage; |
| 3118 | mDrawingState.modified = true; |
| 3119 | setTransactionFlags(eTransactionNeeded); |
| 3120 | return true; |
| 3121 | } |
| 3122 | |
| 3123 | bool Layer::setApi(int32_t api) { |
| 3124 | if (mDrawingState.api == api) return false; |
| 3125 | mDrawingState.api = api; |
| 3126 | mDrawingState.modified = true; |
| 3127 | setTransactionFlags(eTransactionNeeded); |
| 3128 | return true; |
| 3129 | } |
| 3130 | |
| 3131 | bool Layer::setSidebandStream(const sp<NativeHandle>& sidebandStream) { |
| 3132 | if (mDrawingState.sidebandStream == sidebandStream) return false; |
| 3133 | |
| 3134 | if (mDrawingState.sidebandStream != nullptr && sidebandStream == nullptr) { |
| 3135 | mFlinger->mTunnelModeEnabledReporter->decrementTunnelModeCount(); |
| 3136 | } else if (sidebandStream != nullptr) { |
| 3137 | mFlinger->mTunnelModeEnabledReporter->incrementTunnelModeCount(); |
| 3138 | } |
| 3139 | |
| 3140 | mDrawingState.sidebandStream = sidebandStream; |
| 3141 | mDrawingState.modified = true; |
| 3142 | setTransactionFlags(eTransactionNeeded); |
| 3143 | if (!mSidebandStreamChanged.exchange(true)) { |
| 3144 | // mSidebandStreamChanged was false |
| 3145 | mFlinger->onLayerUpdate(); |
| 3146 | } |
| 3147 | return true; |
| 3148 | } |
| 3149 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3150 | bool Layer::setTransactionCompletedListeners(const std::vector<sp<CallbackHandle>>& handles, |
| 3151 | bool willPresent) { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3152 | // If there is no handle, we will not send a callback so reset mReleasePreviousBuffer and return |
| 3153 | if (handles.empty()) { |
| 3154 | mReleasePreviousBuffer = false; |
| 3155 | return false; |
| 3156 | } |
| 3157 | |
Pascal Muetschard | 81cef29 | 2023-02-06 12:18:52 +0100 | [diff] [blame] | 3158 | std::deque<sp<CallbackHandle>> remainingHandles; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3159 | for (const auto& handle : handles) { |
| 3160 | // If this transaction set a buffer on this layer, release its previous buffer |
| 3161 | handle->releasePreviousBuffer = mReleasePreviousBuffer; |
| 3162 | |
| 3163 | // If this layer will be presented in this frame |
| 3164 | if (willPresent) { |
| 3165 | // If this transaction set an acquire fence on this layer, set its acquire time |
| 3166 | handle->acquireTimeOrFence = mCallbackHandleAcquireTimeOrFence; |
| 3167 | handle->frameNumber = mDrawingState.frameNumber; |
| 3168 | |
| 3169 | // Store so latched time and release fence can be set |
| 3170 | mDrawingState.callbackHandles.push_back(handle); |
| 3171 | |
| 3172 | } else { // If this layer will NOT need to be relatched and presented this frame |
Pascal Muetschard | 81cef29 | 2023-02-06 12:18:52 +0100 | [diff] [blame] | 3173 | // Queue this handle to be notified below. |
| 3174 | remainingHandles.push_back(handle); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3175 | } |
| 3176 | } |
| 3177 | |
Pascal Muetschard | 81cef29 | 2023-02-06 12:18:52 +0100 | [diff] [blame] | 3178 | if (!remainingHandles.empty()) { |
| 3179 | // Notify the transaction completed threads these handles are done. These are only the |
| 3180 | // handles that were not added to the mDrawingState, which will be notified later. |
| 3181 | std::vector<JankData> jankData; |
| 3182 | transferAvailableJankData(remainingHandles, jankData); |
| 3183 | mFlinger->getTransactionCallbackInvoker().addCallbackHandles(remainingHandles, jankData); |
| 3184 | } |
| 3185 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3186 | mReleasePreviousBuffer = false; |
| 3187 | mCallbackHandleAcquireTimeOrFence = -1; |
| 3188 | |
| 3189 | return willPresent; |
| 3190 | } |
| 3191 | |
| 3192 | Rect Layer::getBufferSize(const State& /*s*/) const { |
| 3193 | // for buffer state layers we use the display frame size as the buffer size. |
| 3194 | |
| 3195 | if (mBufferInfo.mBuffer == nullptr) { |
| 3196 | return Rect::INVALID_RECT; |
| 3197 | } |
| 3198 | |
| 3199 | uint32_t bufWidth = mBufferInfo.mBuffer->getWidth(); |
| 3200 | uint32_t bufHeight = mBufferInfo.mBuffer->getHeight(); |
| 3201 | |
| 3202 | // Undo any transformations on the buffer and return the result. |
| 3203 | if (mBufferInfo.mTransform & ui::Transform::ROT_90) { |
| 3204 | std::swap(bufWidth, bufHeight); |
| 3205 | } |
| 3206 | |
| 3207 | if (getTransformToDisplayInverse()) { |
| 3208 | uint32_t invTransform = DisplayDevice::getPrimaryDisplayRotationFlags(); |
| 3209 | if (invTransform & ui::Transform::ROT_90) { |
| 3210 | std::swap(bufWidth, bufHeight); |
| 3211 | } |
| 3212 | } |
| 3213 | |
| 3214 | return Rect(0, 0, static_cast<int32_t>(bufWidth), static_cast<int32_t>(bufHeight)); |
| 3215 | } |
| 3216 | |
| 3217 | FloatRect Layer::computeSourceBounds(const FloatRect& parentBounds) const { |
| 3218 | if (mBufferInfo.mBuffer == nullptr) { |
| 3219 | return parentBounds; |
| 3220 | } |
| 3221 | |
| 3222 | return getBufferSize(getDrawingState()).toFloatRect(); |
| 3223 | } |
| 3224 | |
| 3225 | bool Layer::fenceHasSignaled() const { |
| 3226 | if (SurfaceFlinger::enableLatchUnsignaledConfig != LatchUnsignaledConfig::Disabled) { |
| 3227 | return true; |
| 3228 | } |
| 3229 | |
| 3230 | const bool fenceSignaled = |
| 3231 | getDrawingState().acquireFence->getStatus() == Fence::Status::Signaled; |
| 3232 | if (!fenceSignaled) { |
| 3233 | mFlinger->mTimeStats->incrementLatchSkipped(getSequence(), |
| 3234 | TimeStats::LatchSkipReason::LateAcquire); |
| 3235 | } |
| 3236 | |
| 3237 | return fenceSignaled; |
| 3238 | } |
| 3239 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3240 | void Layer::onPreComposition(nsecs_t refreshStartTime) { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3241 | for (const auto& handle : mDrawingState.callbackHandles) { |
| 3242 | handle->refreshStartTime = refreshStartTime; |
| 3243 | } |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3244 | } |
| 3245 | |
| 3246 | void Layer::setAutoRefresh(bool autoRefresh) { |
| 3247 | mDrawingState.autoRefresh = autoRefresh; |
| 3248 | } |
| 3249 | |
| 3250 | bool Layer::latchSidebandStream(bool& recomputeVisibleRegions) { |
| 3251 | // We need to update the sideband stream if the layer has both a buffer and a sideband stream. |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 3252 | auto* snapshot = editLayerSnapshot(); |
| 3253 | snapshot->sidebandStreamHasFrame = hasFrameUpdate() && mSidebandStream.get(); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3254 | |
| 3255 | if (mSidebandStreamChanged.exchange(false)) { |
| 3256 | const State& s(getDrawingState()); |
| 3257 | // mSidebandStreamChanged was true |
| 3258 | mSidebandStream = s.sidebandStream; |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 3259 | snapshot->sidebandStream = mSidebandStream; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3260 | if (mSidebandStream != nullptr) { |
| 3261 | setTransactionFlags(eTransactionNeeded); |
| 3262 | mFlinger->setTransactionFlags(eTraversalNeeded); |
| 3263 | } |
| 3264 | recomputeVisibleRegions = true; |
| 3265 | |
| 3266 | return true; |
| 3267 | } |
| 3268 | return false; |
| 3269 | } |
| 3270 | |
| 3271 | bool Layer::hasFrameUpdate() const { |
| 3272 | const State& c(getDrawingState()); |
| 3273 | return (mDrawingStateModified || mDrawingState.modified) && |
| 3274 | (c.buffer != nullptr || c.bgColorLayer != nullptr); |
| 3275 | } |
| 3276 | |
| 3277 | void Layer::updateTexImage(nsecs_t latchTime) { |
| 3278 | const State& s(getDrawingState()); |
| 3279 | |
| 3280 | if (!s.buffer) { |
| 3281 | if (s.bgColorLayer) { |
| 3282 | for (auto& handle : mDrawingState.callbackHandles) { |
| 3283 | handle->latchTime = latchTime; |
| 3284 | } |
| 3285 | } |
| 3286 | return; |
| 3287 | } |
| 3288 | |
| 3289 | for (auto& handle : mDrawingState.callbackHandles) { |
| 3290 | if (handle->frameNumber == mDrawingState.frameNumber) { |
| 3291 | handle->latchTime = latchTime; |
| 3292 | } |
| 3293 | } |
| 3294 | |
| 3295 | const int32_t layerId = getSequence(); |
| 3296 | const uint64_t bufferId = mDrawingState.buffer->getId(); |
| 3297 | const uint64_t frameNumber = mDrawingState.frameNumber; |
| 3298 | const auto acquireFence = std::make_shared<FenceTime>(mDrawingState.acquireFence); |
| 3299 | mFlinger->mTimeStats->setAcquireFence(layerId, frameNumber, acquireFence); |
| 3300 | mFlinger->mTimeStats->setLatchTime(layerId, frameNumber, latchTime); |
| 3301 | |
| 3302 | mFlinger->mFrameTracer->traceFence(layerId, bufferId, frameNumber, acquireFence, |
| 3303 | FrameTracer::FrameEvent::ACQUIRE_FENCE); |
| 3304 | mFlinger->mFrameTracer->traceTimestamp(layerId, bufferId, frameNumber, latchTime, |
| 3305 | FrameTracer::FrameEvent::LATCH); |
| 3306 | |
| 3307 | auto& bufferSurfaceFrame = mDrawingState.bufferSurfaceFrameTX; |
| 3308 | if (bufferSurfaceFrame != nullptr && |
| 3309 | bufferSurfaceFrame->getPresentState() != PresentState::Presented) { |
| 3310 | // Update only if the bufferSurfaceFrame wasn't already presented. A Presented |
| 3311 | // bufferSurfaceFrame could be seen here if a pending state was applied successfully and we |
| 3312 | // are processing the next state. |
| 3313 | addSurfaceFramePresentedForBuffer(bufferSurfaceFrame, |
| 3314 | mDrawingState.acquireFenceTime->getSignalTime(), |
| 3315 | latchTime); |
| 3316 | mDrawingState.bufferSurfaceFrameTX.reset(); |
| 3317 | } |
| 3318 | |
| 3319 | std::deque<sp<CallbackHandle>> remainingHandles; |
| 3320 | mFlinger->getTransactionCallbackInvoker() |
| 3321 | .addOnCommitCallbackHandles(mDrawingState.callbackHandles, remainingHandles); |
| 3322 | mDrawingState.callbackHandles = remainingHandles; |
| 3323 | |
| 3324 | mDrawingStateModified = false; |
| 3325 | } |
| 3326 | |
| 3327 | void Layer::gatherBufferInfo() { |
| 3328 | if (!mBufferInfo.mBuffer || !mDrawingState.buffer->hasSameBuffer(*mBufferInfo.mBuffer)) { |
| 3329 | decrementPendingBufferCount(); |
| 3330 | } |
| 3331 | |
| 3332 | mPreviousReleaseCallbackId = {getCurrentBufferId(), mBufferInfo.mFrameNumber}; |
| 3333 | mBufferInfo.mBuffer = mDrawingState.buffer; |
| 3334 | mBufferInfo.mFence = mDrawingState.acquireFence; |
| 3335 | mBufferInfo.mFrameNumber = mDrawingState.frameNumber; |
| 3336 | mBufferInfo.mPixelFormat = |
| 3337 | !mBufferInfo.mBuffer ? PIXEL_FORMAT_NONE : mBufferInfo.mBuffer->getPixelFormat(); |
| 3338 | mBufferInfo.mFrameLatencyNeeded = true; |
| 3339 | mBufferInfo.mDesiredPresentTime = mDrawingState.desiredPresentTime; |
| 3340 | mBufferInfo.mFenceTime = std::make_shared<FenceTime>(mDrawingState.acquireFence); |
| 3341 | mBufferInfo.mFence = mDrawingState.acquireFence; |
| 3342 | mBufferInfo.mTransform = mDrawingState.bufferTransform; |
| 3343 | auto lastDataspace = mBufferInfo.mDataspace; |
| 3344 | mBufferInfo.mDataspace = translateDataspace(mDrawingState.dataspace); |
| 3345 | if (lastDataspace != mBufferInfo.mDataspace) { |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3346 | mFlinger->mHdrLayerInfoChanged = true; |
| 3347 | } |
| 3348 | if (mBufferInfo.mDesiredSdrHdrRatio != mDrawingState.desiredSdrHdrRatio) { |
| 3349 | mBufferInfo.mDesiredSdrHdrRatio = mDrawingState.desiredSdrHdrRatio; |
| 3350 | mFlinger->mHdrLayerInfoChanged = true; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3351 | } |
| 3352 | mBufferInfo.mCrop = computeBufferCrop(mDrawingState); |
| 3353 | mBufferInfo.mScaleMode = NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW; |
| 3354 | mBufferInfo.mSurfaceDamage = mDrawingState.surfaceDamageRegion; |
| 3355 | mBufferInfo.mHdrMetadata = mDrawingState.hdrMetadata; |
| 3356 | mBufferInfo.mApi = mDrawingState.api; |
| 3357 | mBufferInfo.mTransformToDisplayInverse = mDrawingState.transformToDisplayInverse; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3358 | } |
| 3359 | |
| 3360 | Rect Layer::computeBufferCrop(const State& s) { |
| 3361 | if (s.buffer && !s.bufferCrop.isEmpty()) { |
| 3362 | Rect bufferCrop; |
| 3363 | s.buffer->getBounds().intersect(s.bufferCrop, &bufferCrop); |
| 3364 | return bufferCrop; |
| 3365 | } else if (s.buffer) { |
| 3366 | return s.buffer->getBounds(); |
| 3367 | } else { |
| 3368 | return s.bufferCrop; |
| 3369 | } |
| 3370 | } |
| 3371 | |
| 3372 | sp<Layer> Layer::createClone() { |
| 3373 | LayerCreationArgs args(mFlinger.get(), nullptr, mName + " (Mirror)", 0, LayerMetadata()); |
| 3374 | args.textureName = mTextureName; |
Patrick Williams | 83f36b2 | 2022-09-14 17:57:35 +0000 | [diff] [blame] | 3375 | sp<Layer> layer = mFlinger->getFactory().createBufferStateLayer(args); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3376 | layer->setInitialValuesForClone(sp<Layer>::fromExisting(this)); |
| 3377 | return layer; |
| 3378 | } |
| 3379 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3380 | void Layer::decrementPendingBufferCount() { |
| 3381 | int32_t pendingBuffers = --mPendingBufferTransactions; |
| 3382 | tracePendingBufferCount(pendingBuffers); |
| 3383 | } |
| 3384 | |
| 3385 | void Layer::tracePendingBufferCount(int32_t pendingBuffers) { |
| 3386 | ATRACE_INT(mBlastTransactionName.c_str(), pendingBuffers); |
| 3387 | } |
| 3388 | |
| 3389 | /* |
| 3390 | * We don't want to send the layer's transform to input, but rather the |
| 3391 | * parent's transform. This is because Layer's transform is |
| 3392 | * information about how the buffer is placed on screen. The parent's |
| 3393 | * transform makes more sense to send since it's information about how the |
| 3394 | * layer is placed on screen. This transform is used by input to determine |
| 3395 | * how to go from screen space back to window space. |
| 3396 | */ |
| 3397 | ui::Transform Layer::getInputTransform() const { |
| 3398 | if (!hasBufferOrSidebandStream()) { |
| 3399 | return getTransform(); |
| 3400 | } |
| 3401 | sp<Layer> parent = mDrawingParent.promote(); |
| 3402 | if (parent == nullptr) { |
| 3403 | return ui::Transform(); |
| 3404 | } |
| 3405 | |
| 3406 | return parent->getTransform(); |
| 3407 | } |
| 3408 | |
| 3409 | /** |
| 3410 | * Similar to getInputTransform, we need to update the bounds to include the transform. |
| 3411 | * This is because bounds don't include the buffer transform, where the input assumes |
| 3412 | * that's already included. |
| 3413 | */ |
| 3414 | Rect Layer::getInputBounds() const { |
| 3415 | if (!hasBufferOrSidebandStream()) { |
| 3416 | return getCroppedBufferSize(getDrawingState()); |
| 3417 | } |
| 3418 | |
| 3419 | Rect bufferBounds = getCroppedBufferSize(getDrawingState()); |
| 3420 | if (mDrawingState.transform.getType() == ui::Transform::IDENTITY || !bufferBounds.isValid()) { |
| 3421 | return bufferBounds; |
| 3422 | } |
| 3423 | return mDrawingState.transform.transform(bufferBounds); |
| 3424 | } |
| 3425 | |
| 3426 | bool Layer::simpleBufferUpdate(const layer_state_t& s) const { |
| 3427 | const uint64_t requiredFlags = layer_state_t::eBufferChanged; |
| 3428 | |
| 3429 | const uint64_t deniedFlags = layer_state_t::eProducerDisconnect | layer_state_t::eLayerChanged | |
| 3430 | layer_state_t::eRelativeLayerChanged | layer_state_t::eTransparentRegionChanged | |
| 3431 | layer_state_t::eFlagsChanged | layer_state_t::eBlurRegionsChanged | |
| 3432 | layer_state_t::eLayerStackChanged | layer_state_t::eAutoRefreshChanged | |
| 3433 | layer_state_t::eReparent; |
| 3434 | |
| 3435 | const uint64_t allowedFlags = layer_state_t::eHasListenerCallbacksChanged | |
| 3436 | layer_state_t::eFrameRateSelectionPriority | layer_state_t::eFrameRateChanged | |
| 3437 | layer_state_t::eSurfaceDamageRegionChanged | layer_state_t::eApiChanged | |
| 3438 | layer_state_t::eMetadataChanged | layer_state_t::eDropInputModeChanged | |
| 3439 | layer_state_t::eInputInfoChanged; |
| 3440 | |
| 3441 | if ((s.what & requiredFlags) != requiredFlags) { |
| 3442 | ALOGV("%s: false [missing required flags 0x%" PRIx64 "]", __func__, |
| 3443 | (s.what | requiredFlags) & ~s.what); |
| 3444 | return false; |
| 3445 | } |
| 3446 | |
| 3447 | if (s.what & deniedFlags) { |
| 3448 | ALOGV("%s: false [has denied flags 0x%" PRIx64 "]", __func__, s.what & deniedFlags); |
| 3449 | return false; |
| 3450 | } |
| 3451 | |
| 3452 | if (s.what & allowedFlags) { |
| 3453 | ALOGV("%s: [has allowed flags 0x%" PRIx64 "]", __func__, s.what & allowedFlags); |
| 3454 | } |
| 3455 | |
| 3456 | if (s.what & layer_state_t::ePositionChanged) { |
| 3457 | if (mRequestedTransform.tx() != s.x || mRequestedTransform.ty() != s.y) { |
| 3458 | ALOGV("%s: false [ePositionChanged changed]", __func__); |
| 3459 | return false; |
| 3460 | } |
| 3461 | } |
| 3462 | |
| 3463 | if (s.what & layer_state_t::eAlphaChanged) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 3464 | if (mDrawingState.color.a != s.color.a) { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3465 | ALOGV("%s: false [eAlphaChanged changed]", __func__); |
| 3466 | return false; |
| 3467 | } |
| 3468 | } |
| 3469 | |
| 3470 | if (s.what & layer_state_t::eColorTransformChanged) { |
| 3471 | if (mDrawingState.colorTransform != s.colorTransform) { |
| 3472 | ALOGV("%s: false [eColorTransformChanged changed]", __func__); |
| 3473 | return false; |
| 3474 | } |
| 3475 | } |
| 3476 | |
| 3477 | if (s.what & layer_state_t::eBackgroundColorChanged) { |
| 3478 | if (mDrawingState.bgColorLayer || s.bgColorAlpha != 0) { |
| 3479 | ALOGV("%s: false [eBackgroundColorChanged changed]", __func__); |
| 3480 | return false; |
| 3481 | } |
| 3482 | } |
| 3483 | |
| 3484 | if (s.what & layer_state_t::eMatrixChanged) { |
| 3485 | if (mRequestedTransform.dsdx() != s.matrix.dsdx || |
| 3486 | mRequestedTransform.dtdy() != s.matrix.dtdy || |
| 3487 | mRequestedTransform.dtdx() != s.matrix.dtdx || |
| 3488 | mRequestedTransform.dsdy() != s.matrix.dsdy) { |
| 3489 | ALOGV("%s: false [eMatrixChanged changed]", __func__); |
| 3490 | return false; |
| 3491 | } |
| 3492 | } |
| 3493 | |
| 3494 | if (s.what & layer_state_t::eCornerRadiusChanged) { |
| 3495 | if (mDrawingState.cornerRadius != s.cornerRadius) { |
| 3496 | ALOGV("%s: false [eCornerRadiusChanged changed]", __func__); |
| 3497 | return false; |
| 3498 | } |
| 3499 | } |
| 3500 | |
| 3501 | if (s.what & layer_state_t::eBackgroundBlurRadiusChanged) { |
| 3502 | if (mDrawingState.backgroundBlurRadius != static_cast<int>(s.backgroundBlurRadius)) { |
| 3503 | ALOGV("%s: false [eBackgroundBlurRadiusChanged changed]", __func__); |
| 3504 | return false; |
| 3505 | } |
| 3506 | } |
| 3507 | |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 3508 | if (s.what & layer_state_t::eBufferTransformChanged) { |
| 3509 | if (mDrawingState.bufferTransform != s.bufferTransform) { |
| 3510 | ALOGV("%s: false [eBufferTransformChanged changed]", __func__); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3511 | return false; |
| 3512 | } |
| 3513 | } |
| 3514 | |
| 3515 | if (s.what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 3516 | if (mDrawingState.transformToDisplayInverse != s.transformToDisplayInverse) { |
| 3517 | ALOGV("%s: false [eTransformToDisplayInverseChanged changed]", __func__); |
| 3518 | return false; |
| 3519 | } |
| 3520 | } |
| 3521 | |
| 3522 | if (s.what & layer_state_t::eCropChanged) { |
| 3523 | if (mDrawingState.crop != s.crop) { |
| 3524 | ALOGV("%s: false [eCropChanged changed]", __func__); |
| 3525 | return false; |
| 3526 | } |
| 3527 | } |
| 3528 | |
| 3529 | if (s.what & layer_state_t::eDataspaceChanged) { |
| 3530 | if (mDrawingState.dataspace != s.dataspace) { |
| 3531 | ALOGV("%s: false [eDataspaceChanged changed]", __func__); |
| 3532 | return false; |
| 3533 | } |
| 3534 | } |
| 3535 | |
| 3536 | if (s.what & layer_state_t::eHdrMetadataChanged) { |
| 3537 | if (mDrawingState.hdrMetadata != s.hdrMetadata) { |
| 3538 | ALOGV("%s: false [eHdrMetadataChanged changed]", __func__); |
| 3539 | return false; |
| 3540 | } |
| 3541 | } |
| 3542 | |
| 3543 | if (s.what & layer_state_t::eSidebandStreamChanged) { |
| 3544 | if (mDrawingState.sidebandStream != s.sidebandStream) { |
| 3545 | ALOGV("%s: false [eSidebandStreamChanged changed]", __func__); |
| 3546 | return false; |
| 3547 | } |
| 3548 | } |
| 3549 | |
| 3550 | if (s.what & layer_state_t::eColorSpaceAgnosticChanged) { |
| 3551 | if (mDrawingState.colorSpaceAgnostic != s.colorSpaceAgnostic) { |
| 3552 | ALOGV("%s: false [eColorSpaceAgnosticChanged changed]", __func__); |
| 3553 | return false; |
| 3554 | } |
| 3555 | } |
| 3556 | |
| 3557 | if (s.what & layer_state_t::eShadowRadiusChanged) { |
| 3558 | if (mDrawingState.shadowRadius != s.shadowRadius) { |
| 3559 | ALOGV("%s: false [eShadowRadiusChanged changed]", __func__); |
| 3560 | return false; |
| 3561 | } |
| 3562 | } |
| 3563 | |
| 3564 | if (s.what & layer_state_t::eFixedTransformHintChanged) { |
| 3565 | if (mDrawingState.fixedTransformHint != s.fixedTransformHint) { |
| 3566 | ALOGV("%s: false [eFixedTransformHintChanged changed]", __func__); |
| 3567 | return false; |
| 3568 | } |
| 3569 | } |
| 3570 | |
| 3571 | if (s.what & layer_state_t::eTrustedOverlayChanged) { |
| 3572 | if (mDrawingState.isTrustedOverlay != s.isTrustedOverlay) { |
| 3573 | ALOGV("%s: false [eTrustedOverlayChanged changed]", __func__); |
| 3574 | return false; |
| 3575 | } |
| 3576 | } |
| 3577 | |
| 3578 | if (s.what & layer_state_t::eStretchChanged) { |
| 3579 | StretchEffect temp = s.stretchEffect; |
| 3580 | temp.sanitize(); |
| 3581 | if (mDrawingState.stretchEffect != temp) { |
| 3582 | ALOGV("%s: false [eStretchChanged changed]", __func__); |
| 3583 | return false; |
| 3584 | } |
| 3585 | } |
| 3586 | |
| 3587 | if (s.what & layer_state_t::eBufferCropChanged) { |
| 3588 | if (mDrawingState.bufferCrop != s.bufferCrop) { |
| 3589 | ALOGV("%s: false [eBufferCropChanged changed]", __func__); |
| 3590 | return false; |
| 3591 | } |
| 3592 | } |
| 3593 | |
| 3594 | if (s.what & layer_state_t::eDestinationFrameChanged) { |
| 3595 | if (mDrawingState.destinationFrame != s.destinationFrame) { |
| 3596 | ALOGV("%s: false [eDestinationFrameChanged changed]", __func__); |
| 3597 | return false; |
| 3598 | } |
| 3599 | } |
| 3600 | |
| 3601 | if (s.what & layer_state_t::eDimmingEnabledChanged) { |
| 3602 | if (mDrawingState.dimmingEnabled != s.dimmingEnabled) { |
| 3603 | ALOGV("%s: false [eDimmingEnabledChanged changed]", __func__); |
| 3604 | return false; |
| 3605 | } |
| 3606 | } |
| 3607 | |
John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 3608 | if (s.what & layer_state_t::eExtendedRangeBrightnessChanged) { |
| 3609 | if (mDrawingState.currentSdrHdrRatio != s.currentSdrHdrRatio || |
| 3610 | mDrawingState.desiredSdrHdrRatio != s.desiredSdrHdrRatio) { |
| 3611 | ALOGV("%s: false [eDimmingEnabledChanged changed]", __func__); |
| 3612 | return false; |
| 3613 | } |
| 3614 | } |
| 3615 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3616 | ALOGV("%s: true", __func__); |
| 3617 | return true; |
| 3618 | } |
| 3619 | |
| 3620 | bool Layer::isHdrY410() const { |
| 3621 | // pixel format is HDR Y410 masquerading as RGBA_1010102 |
| 3622 | return (mBufferInfo.mDataspace == ui::Dataspace::BT2020_ITU_PQ && |
| 3623 | mBufferInfo.mApi == NATIVE_WINDOW_API_MEDIA && |
| 3624 | mBufferInfo.mPixelFormat == HAL_PIXEL_FORMAT_RGBA_1010102); |
| 3625 | } |
| 3626 | |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 3627 | sp<LayerFE> Layer::getCompositionEngineLayerFE() const { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3628 | // There's no need to get a CE Layer if the layer isn't going to draw anything. |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3629 | return hasSomethingToDraw() ? mLegacyLayerFE : nullptr; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3630 | } |
| 3631 | |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 3632 | const LayerSnapshot* Layer::getLayerSnapshot() const { |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 3633 | return mSnapshot.get(); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3634 | } |
| 3635 | |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 3636 | LayerSnapshot* Layer::editLayerSnapshot() { |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 3637 | return mSnapshot.get(); |
| 3638 | } |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 3639 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3640 | std::unique_ptr<frontend::LayerSnapshot> Layer::stealLayerSnapshot() { |
| 3641 | return std::move(mSnapshot); |
| 3642 | } |
| 3643 | |
| 3644 | void Layer::updateLayerSnapshot(std::unique_ptr<frontend::LayerSnapshot> snapshot) { |
| 3645 | mSnapshot = std::move(snapshot); |
| 3646 | } |
| 3647 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3648 | const compositionengine::LayerFECompositionState* Layer::getCompositionState() const { |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 3649 | return mSnapshot.get(); |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3650 | } |
| 3651 | |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 3652 | sp<LayerFE> Layer::copyCompositionEngineLayerFE() const { |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3653 | auto result = mFlinger->getFactory().createLayerFE(mName); |
Patrick Williams | 7584c6a | 2022-10-29 02:10:58 +0000 | [diff] [blame] | 3654 | result->mSnapshot = std::make_unique<LayerSnapshot>(*mSnapshot); |
| 3655 | return result; |
| 3656 | } |
| 3657 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 3658 | sp<LayerFE> Layer::getCompositionEngineLayerFE( |
| 3659 | const frontend::LayerHierarchy::TraversalPath& path) { |
| 3660 | for (auto& [p, layerFE] : mLayerFEs) { |
| 3661 | if (p == path) { |
| 3662 | return layerFE; |
| 3663 | } |
| 3664 | } |
| 3665 | auto layerFE = mFlinger->getFactory().createLayerFE(mName); |
| 3666 | mLayerFEs.emplace_back(path, layerFE); |
| 3667 | return layerFE; |
| 3668 | } |
| 3669 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3670 | void Layer::useSurfaceDamage() { |
| 3671 | if (mFlinger->mForceFullDamage) { |
| 3672 | surfaceDamageRegion = Region::INVALID_REGION; |
| 3673 | } else { |
| 3674 | surfaceDamageRegion = mBufferInfo.mSurfaceDamage; |
| 3675 | } |
| 3676 | } |
| 3677 | |
| 3678 | void Layer::useEmptyDamage() { |
| 3679 | surfaceDamageRegion.clear(); |
| 3680 | } |
| 3681 | |
| 3682 | bool Layer::isOpaque(const Layer::State& s) const { |
| 3683 | // if we don't have a buffer or sidebandStream yet, we're translucent regardless of the |
| 3684 | // layer's opaque flag. |
| 3685 | if (!hasSomethingToDraw()) { |
| 3686 | return false; |
| 3687 | } |
| 3688 | |
| 3689 | // if the layer has the opaque flag, then we're always opaque |
| 3690 | if ((s.flags & layer_state_t::eLayerOpaque) == layer_state_t::eLayerOpaque) { |
| 3691 | return true; |
| 3692 | } |
| 3693 | |
| 3694 | // If the buffer has no alpha channel, then we are opaque |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 3695 | if (hasBufferOrSidebandStream() && LayerSnapshot::isOpaqueFormat(getPixelFormat())) { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3696 | return true; |
| 3697 | } |
| 3698 | |
| 3699 | // Lastly consider the layer opaque if drawing a color with alpha == 1.0 |
| 3700 | return fillsColor() && getAlpha() == 1.0_hf; |
| 3701 | } |
| 3702 | |
| 3703 | bool Layer::canReceiveInput() const { |
| 3704 | return !isHiddenByPolicy() && (mBufferInfo.mBuffer == nullptr || getAlpha() > 0.0f); |
| 3705 | } |
| 3706 | |
| 3707 | bool Layer::isVisible() const { |
| 3708 | if (!hasSomethingToDraw()) { |
| 3709 | return false; |
| 3710 | } |
| 3711 | |
| 3712 | if (isHiddenByPolicy()) { |
| 3713 | return false; |
| 3714 | } |
| 3715 | |
| 3716 | return getAlpha() > 0.0f || hasBlur(); |
| 3717 | } |
| 3718 | |
| 3719 | void Layer::onPostComposition(const DisplayDevice* display, |
| 3720 | const std::shared_ptr<FenceTime>& glDoneFence, |
| 3721 | const std::shared_ptr<FenceTime>& presentFence, |
| 3722 | const CompositorTiming& compositorTiming) { |
| 3723 | // mFrameLatencyNeeded is true when a new frame was latched for the |
| 3724 | // composition. |
| 3725 | if (!mBufferInfo.mFrameLatencyNeeded) return; |
| 3726 | |
| 3727 | for (const auto& handle : mDrawingState.callbackHandles) { |
| 3728 | handle->gpuCompositionDoneFence = glDoneFence; |
| 3729 | handle->compositorTiming = compositorTiming; |
| 3730 | } |
| 3731 | |
| 3732 | // Update mFrameTracker. |
| 3733 | nsecs_t desiredPresentTime = mBufferInfo.mDesiredPresentTime; |
| 3734 | mFrameTracker.setDesiredPresentTime(desiredPresentTime); |
| 3735 | |
| 3736 | const int32_t layerId = getSequence(); |
| 3737 | mFlinger->mTimeStats->setDesiredTime(layerId, mCurrentFrameNumber, desiredPresentTime); |
| 3738 | |
| 3739 | const auto outputLayer = findOutputLayerForDisplay(display); |
| 3740 | if (outputLayer && outputLayer->requiresClientComposition()) { |
| 3741 | nsecs_t clientCompositionTimestamp = outputLayer->getState().clientCompositionTimestamp; |
| 3742 | mFlinger->mFrameTracer->traceTimestamp(layerId, getCurrentBufferId(), mCurrentFrameNumber, |
| 3743 | clientCompositionTimestamp, |
| 3744 | FrameTracer::FrameEvent::FALLBACK_COMPOSITION); |
| 3745 | // Update the SurfaceFrames in the drawing state |
| 3746 | if (mDrawingState.bufferSurfaceFrameTX) { |
| 3747 | mDrawingState.bufferSurfaceFrameTX->setGpuComposition(); |
| 3748 | } |
| 3749 | for (auto& [token, surfaceFrame] : mDrawingState.bufferlessSurfaceFramesTX) { |
| 3750 | surfaceFrame->setGpuComposition(); |
| 3751 | } |
| 3752 | } |
| 3753 | |
| 3754 | std::shared_ptr<FenceTime> frameReadyFence = mBufferInfo.mFenceTime; |
| 3755 | if (frameReadyFence->isValid()) { |
| 3756 | mFrameTracker.setFrameReadyFence(std::move(frameReadyFence)); |
| 3757 | } else { |
| 3758 | // There was no fence for this frame, so assume that it was ready |
| 3759 | // to be presented at the desired present time. |
| 3760 | mFrameTracker.setFrameReadyTime(desiredPresentTime); |
| 3761 | } |
| 3762 | |
| 3763 | if (display) { |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 3764 | const Fps refreshRate = display->refreshRateSelector().getActiveMode().fps; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3765 | const std::optional<Fps> renderRate = |
| 3766 | mFlinger->mScheduler->getFrameRateOverride(getOwnerUid()); |
| 3767 | |
| 3768 | const auto vote = frameRateToSetFrameRateVotePayload(mDrawingState.frameRate); |
| 3769 | const auto gameMode = getGameMode(); |
| 3770 | |
| 3771 | if (presentFence->isValid()) { |
| 3772 | mFlinger->mTimeStats->setPresentFence(layerId, mCurrentFrameNumber, presentFence, |
| 3773 | refreshRate, renderRate, vote, gameMode); |
| 3774 | mFlinger->mFrameTracer->traceFence(layerId, getCurrentBufferId(), mCurrentFrameNumber, |
| 3775 | presentFence, |
| 3776 | FrameTracer::FrameEvent::PRESENT_FENCE); |
| 3777 | mFrameTracker.setActualPresentFence(std::shared_ptr<FenceTime>(presentFence)); |
| 3778 | } else if (const auto displayId = PhysicalDisplayId::tryCast(display->getId()); |
| 3779 | displayId && mFlinger->getHwComposer().isConnected(*displayId)) { |
Dominik Laskowski | dc2bb80 | 2022-09-28 16:02:59 -0400 | [diff] [blame] | 3780 | // The HWC doesn't support present fences, so use the present timestamp instead. |
| 3781 | const nsecs_t presentTimestamp = |
| 3782 | mFlinger->getHwComposer().getPresentTimestamp(*displayId); |
| 3783 | |
| 3784 | const nsecs_t now = systemTime(CLOCK_MONOTONIC); |
| 3785 | const nsecs_t vsyncPeriod = display->getVsyncPeriodFromHWC(); |
| 3786 | const nsecs_t actualPresentTime = now - ((now - presentTimestamp) % vsyncPeriod); |
| 3787 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3788 | mFlinger->mTimeStats->setPresentTime(layerId, mCurrentFrameNumber, actualPresentTime, |
| 3789 | refreshRate, renderRate, vote, gameMode); |
| 3790 | mFlinger->mFrameTracer->traceTimestamp(layerId, getCurrentBufferId(), |
| 3791 | mCurrentFrameNumber, actualPresentTime, |
| 3792 | FrameTracer::FrameEvent::PRESENT_FENCE); |
| 3793 | mFrameTracker.setActualPresentTime(actualPresentTime); |
| 3794 | } |
| 3795 | } |
| 3796 | |
| 3797 | mFrameTracker.advanceFrame(); |
| 3798 | mBufferInfo.mFrameLatencyNeeded = false; |
| 3799 | } |
| 3800 | |
| 3801 | bool Layer::latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime) { |
| 3802 | ATRACE_FORMAT_INSTANT("latchBuffer %s - %" PRIu64, getDebugName(), |
| 3803 | getDrawingState().frameNumber); |
| 3804 | |
| 3805 | bool refreshRequired = latchSidebandStream(recomputeVisibleRegions); |
| 3806 | |
| 3807 | if (refreshRequired) { |
| 3808 | return refreshRequired; |
| 3809 | } |
| 3810 | |
| 3811 | // If the head buffer's acquire fence hasn't signaled yet, return and |
| 3812 | // try again later |
| 3813 | if (!fenceHasSignaled()) { |
| 3814 | ATRACE_NAME("!fenceHasSignaled()"); |
| 3815 | mFlinger->onLayerUpdate(); |
| 3816 | return false; |
| 3817 | } |
| 3818 | |
| 3819 | updateTexImage(latchTime); |
| 3820 | if (mDrawingState.buffer == nullptr) { |
| 3821 | return false; |
| 3822 | } |
| 3823 | |
| 3824 | // Capture the old state of the layer for comparisons later |
| 3825 | BufferInfo oldBufferInfo = mBufferInfo; |
| 3826 | const bool oldOpacity = isOpaque(mDrawingState); |
| 3827 | mPreviousFrameNumber = mCurrentFrameNumber; |
| 3828 | mCurrentFrameNumber = mDrawingState.frameNumber; |
| 3829 | gatherBufferInfo(); |
| 3830 | |
| 3831 | if (oldBufferInfo.mBuffer == nullptr) { |
| 3832 | // the first time we receive a buffer, we need to trigger a |
| 3833 | // geometry invalidation. |
| 3834 | recomputeVisibleRegions = true; |
| 3835 | } |
| 3836 | |
| 3837 | if ((mBufferInfo.mCrop != oldBufferInfo.mCrop) || |
| 3838 | (mBufferInfo.mTransform != oldBufferInfo.mTransform) || |
| 3839 | (mBufferInfo.mScaleMode != oldBufferInfo.mScaleMode) || |
| 3840 | (mBufferInfo.mTransformToDisplayInverse != oldBufferInfo.mTransformToDisplayInverse)) { |
| 3841 | recomputeVisibleRegions = true; |
| 3842 | } |
| 3843 | |
| 3844 | if (oldBufferInfo.mBuffer != nullptr) { |
| 3845 | uint32_t bufWidth = mBufferInfo.mBuffer->getWidth(); |
| 3846 | uint32_t bufHeight = mBufferInfo.mBuffer->getHeight(); |
| 3847 | if (bufWidth != oldBufferInfo.mBuffer->getWidth() || |
| 3848 | bufHeight != oldBufferInfo.mBuffer->getHeight()) { |
| 3849 | recomputeVisibleRegions = true; |
| 3850 | } |
| 3851 | } |
| 3852 | |
| 3853 | if (oldOpacity != isOpaque(mDrawingState)) { |
| 3854 | recomputeVisibleRegions = true; |
| 3855 | } |
| 3856 | |
| 3857 | return true; |
| 3858 | } |
| 3859 | |
| 3860 | bool Layer::hasReadyFrame() const { |
| 3861 | return hasFrameUpdate() || getSidebandStreamChanged() || getAutoRefresh(); |
| 3862 | } |
| 3863 | |
| 3864 | bool Layer::isProtected() const { |
| 3865 | return (mBufferInfo.mBuffer != nullptr) && |
| 3866 | (mBufferInfo.mBuffer->getUsage() & GRALLOC_USAGE_PROTECTED); |
| 3867 | } |
| 3868 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3869 | void Layer::latchAndReleaseBuffer() { |
| 3870 | if (hasReadyFrame()) { |
| 3871 | bool ignored = false; |
| 3872 | latchBuffer(ignored, systemTime()); |
| 3873 | } |
| 3874 | releasePendingBuffer(systemTime()); |
| 3875 | } |
| 3876 | |
| 3877 | PixelFormat Layer::getPixelFormat() const { |
| 3878 | return mBufferInfo.mPixelFormat; |
| 3879 | } |
| 3880 | |
| 3881 | bool Layer::getTransformToDisplayInverse() const { |
| 3882 | return mBufferInfo.mTransformToDisplayInverse; |
| 3883 | } |
| 3884 | |
| 3885 | Rect Layer::getBufferCrop() const { |
| 3886 | // this is the crop rectangle that applies to the buffer |
| 3887 | // itself (as opposed to the window) |
| 3888 | if (!mBufferInfo.mCrop.isEmpty()) { |
| 3889 | // if the buffer crop is defined, we use that |
| 3890 | return mBufferInfo.mCrop; |
| 3891 | } else if (mBufferInfo.mBuffer != nullptr) { |
| 3892 | // otherwise we use the whole buffer |
| 3893 | return mBufferInfo.mBuffer->getBounds(); |
| 3894 | } else { |
| 3895 | // if we don't have a buffer yet, we use an empty/invalid crop |
| 3896 | return Rect(); |
| 3897 | } |
| 3898 | } |
| 3899 | |
| 3900 | uint32_t Layer::getBufferTransform() const { |
| 3901 | return mBufferInfo.mTransform; |
| 3902 | } |
| 3903 | |
| 3904 | ui::Dataspace Layer::getDataSpace() const { |
| 3905 | return mDrawingState.dataspaceRequested ? getRequestedDataSpace() : ui::Dataspace::UNKNOWN; |
| 3906 | } |
| 3907 | |
| 3908 | ui::Dataspace Layer::getRequestedDataSpace() const { |
| 3909 | return hasBufferOrSidebandStream() ? mBufferInfo.mDataspace : mDrawingState.dataspace; |
| 3910 | } |
| 3911 | |
| 3912 | ui::Dataspace Layer::translateDataspace(ui::Dataspace dataspace) { |
| 3913 | ui::Dataspace updatedDataspace = dataspace; |
| 3914 | // translate legacy dataspaces to modern dataspaces |
| 3915 | switch (dataspace) { |
| 3916 | case ui::Dataspace::SRGB: |
| 3917 | updatedDataspace = ui::Dataspace::V0_SRGB; |
| 3918 | break; |
| 3919 | case ui::Dataspace::SRGB_LINEAR: |
| 3920 | updatedDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 3921 | break; |
| 3922 | case ui::Dataspace::JFIF: |
| 3923 | updatedDataspace = ui::Dataspace::V0_JFIF; |
| 3924 | break; |
| 3925 | case ui::Dataspace::BT601_625: |
| 3926 | updatedDataspace = ui::Dataspace::V0_BT601_625; |
| 3927 | break; |
| 3928 | case ui::Dataspace::BT601_525: |
| 3929 | updatedDataspace = ui::Dataspace::V0_BT601_525; |
| 3930 | break; |
| 3931 | case ui::Dataspace::BT709: |
| 3932 | updatedDataspace = ui::Dataspace::V0_BT709; |
| 3933 | break; |
| 3934 | default: |
| 3935 | break; |
| 3936 | } |
| 3937 | |
| 3938 | return updatedDataspace; |
| 3939 | } |
| 3940 | |
| 3941 | sp<GraphicBuffer> Layer::getBuffer() const { |
| 3942 | return mBufferInfo.mBuffer ? mBufferInfo.mBuffer->getBuffer() : nullptr; |
| 3943 | } |
| 3944 | |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3945 | void Layer::setTransformHint(ui::Transform::RotationFlags displayTransformHint) { |
| 3946 | mTransformHint = getFixedTransformHint(); |
| 3947 | if (mTransformHint == ui::Transform::ROT_INVALID) { |
| 3948 | mTransformHint = displayTransformHint; |
| 3949 | } |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 3950 | mSkipReportingTransformHint = false; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3951 | } |
| 3952 | |
| 3953 | const std::shared_ptr<renderengine::ExternalTexture>& Layer::getExternalTexture() const { |
| 3954 | return mBufferInfo.mBuffer; |
| 3955 | } |
| 3956 | |
| 3957 | bool Layer::setColor(const half3& color) { |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 3958 | if (mDrawingState.color.rgb == color) { |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3959 | return false; |
| 3960 | } |
| 3961 | |
| 3962 | mDrawingState.sequence++; |
Vishnu Nair | bbceb46 | 2022-10-10 04:52:13 +0000 | [diff] [blame] | 3963 | mDrawingState.color.rgb = color; |
Patrick Williams | bb25f80 | 2022-08-30 23:02:34 +0000 | [diff] [blame] | 3964 | mDrawingState.modified = true; |
| 3965 | setTransactionFlags(eTransactionNeeded); |
| 3966 | return true; |
| 3967 | } |
| 3968 | |
| 3969 | bool Layer::fillsColor() const { |
| 3970 | return !hasBufferOrSidebandStream() && mDrawingState.color.r >= 0.0_hf && |
| 3971 | mDrawingState.color.g >= 0.0_hf && mDrawingState.color.b >= 0.0_hf; |
| 3972 | } |
| 3973 | |
| 3974 | bool Layer::hasBlur() const { |
| 3975 | return getBackgroundBlurRadius() > 0 || getDrawingState().blurRegions.size() > 0; |
| 3976 | } |
| 3977 | |
Vishnu Nair | ba35410 | 2022-08-01 00:14:18 +0000 | [diff] [blame] | 3978 | void Layer::updateSnapshot(bool updateGeometry) { |
| 3979 | if (!getCompositionEngineLayerFE()) { |
| 3980 | return; |
| 3981 | } |
| 3982 | |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 3983 | auto* snapshot = editLayerSnapshot(); |
Vishnu Nair | ba35410 | 2022-08-01 00:14:18 +0000 | [diff] [blame] | 3984 | if (updateGeometry) { |
| 3985 | prepareBasicGeometryCompositionState(); |
| 3986 | prepareGeometryCompositionState(); |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 3987 | snapshot->roundedCorner = getRoundedCornerState(); |
| 3988 | snapshot->stretchEffect = getStretchEffect(); |
| 3989 | snapshot->transformedBounds = mScreenBounds; |
| 3990 | if (mEffectiveShadowRadius > 0.f) { |
| 3991 | snapshot->shadowSettings = mFlinger->mDrawingState.globalShadowSettings; |
| 3992 | |
| 3993 | // Note: this preserves existing behavior of shadowing the entire layer and not cropping |
| 3994 | // it if transparent regions are present. This may not be necessary since shadows are |
| 3995 | // typically cast by layers without transparent regions. |
| 3996 | snapshot->shadowSettings.boundaries = mBounds; |
| 3997 | |
| 3998 | const float casterAlpha = snapshot->alpha; |
| 3999 | const bool casterIsOpaque = |
| 4000 | ((mBufferInfo.mBuffer != nullptr) && isOpaque(mDrawingState)); |
| 4001 | |
| 4002 | // If the casting layer is translucent, we need to fill in the shadow underneath the |
| 4003 | // layer. Otherwise the generated shadow will only be shown around the casting layer. |
| 4004 | snapshot->shadowSettings.casterIsTranslucent = !casterIsOpaque || (casterAlpha < 1.0f); |
| 4005 | snapshot->shadowSettings.ambientColor *= casterAlpha; |
| 4006 | snapshot->shadowSettings.spotColor *= casterAlpha; |
| 4007 | } |
| 4008 | snapshot->shadowSettings.length = mEffectiveShadowRadius; |
Vishnu Nair | ba35410 | 2022-08-01 00:14:18 +0000 | [diff] [blame] | 4009 | } |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 4010 | snapshot->contentOpaque = isOpaque(mDrawingState); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 4011 | snapshot->layerOpaqueFlagSet = |
| 4012 | (mDrawingState.flags & layer_state_t::eLayerOpaque) == layer_state_t::eLayerOpaque; |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 4013 | snapshot->isHdrY410 = isHdrY410(); |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 4014 | sp<Layer> p = mDrawingParent.promote(); |
| 4015 | if (p != nullptr) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 4016 | snapshot->parentTransform = p->getTransform(); |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 4017 | } else { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 4018 | snapshot->parentTransform.reset(); |
Vishnu Nair | bedb44b | 2022-08-02 21:47:40 +0000 | [diff] [blame] | 4019 | } |
| 4020 | snapshot->bufferSize = getBufferSize(mDrawingState); |
| 4021 | snapshot->externalTexture = mBufferInfo.mBuffer; |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4022 | snapshot->hasReadyFrame = hasReadyFrame(); |
Chavi Weingarten | 545da0e | 2023-02-09 14:55:57 +0000 | [diff] [blame] | 4023 | snapshot->isInternalDisplayOverlay = isInternalDisplayOverlay(); |
Vishnu Nair | ba35410 | 2022-08-01 00:14:18 +0000 | [diff] [blame] | 4024 | preparePerFrameCompositionState(); |
| 4025 | } |
| 4026 | |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 4027 | void Layer::updateChildrenSnapshots(bool updateGeometry) { |
| 4028 | for (const sp<Layer>& child : mDrawingChildren) { |
| 4029 | child->updateSnapshot(updateGeometry); |
| 4030 | child->updateChildrenSnapshots(updateGeometry); |
| 4031 | } |
| 4032 | } |
| 4033 | |
Vishnu Nair | 0a4fb00 | 2022-08-08 02:40:42 +0000 | [diff] [blame] | 4034 | void Layer::updateMetadataSnapshot(const LayerMetadata& parentMetadata) { |
| 4035 | mSnapshot->layerMetadata = parentMetadata; |
| 4036 | mSnapshot->layerMetadata.merge(mDrawingState.metadata); |
| 4037 | for (const sp<Layer>& child : mDrawingChildren) { |
| 4038 | child->updateMetadataSnapshot(mSnapshot->layerMetadata); |
| 4039 | } |
| 4040 | } |
| 4041 | |
| 4042 | void Layer::updateRelativeMetadataSnapshot(const LayerMetadata& relativeLayerMetadata, |
| 4043 | std::unordered_set<Layer*>& visited) { |
| 4044 | if (visited.find(this) != visited.end()) { |
| 4045 | ALOGW("Cycle containing layer %s detected in z-order relatives", getDebugName()); |
| 4046 | return; |
| 4047 | } |
| 4048 | visited.insert(this); |
| 4049 | |
| 4050 | mSnapshot->relativeLayerMetadata = relativeLayerMetadata; |
| 4051 | |
| 4052 | if (mDrawingState.zOrderRelatives.empty()) { |
| 4053 | return; |
| 4054 | } |
| 4055 | LayerMetadata childRelativeLayerMetadata = mSnapshot->relativeLayerMetadata; |
| 4056 | childRelativeLayerMetadata.merge(mSnapshot->layerMetadata); |
| 4057 | for (wp<Layer> weakRelative : mDrawingState.zOrderRelatives) { |
| 4058 | sp<Layer> relative = weakRelative.promote(); |
| 4059 | if (!relative) { |
| 4060 | continue; |
| 4061 | } |
| 4062 | relative->updateRelativeMetadataSnapshot(childRelativeLayerMetadata, visited); |
| 4063 | } |
| 4064 | } |
| 4065 | |
Chavi Weingarten | 076acac | 2023-01-19 17:20:43 +0000 | [diff] [blame] | 4066 | void Layer::setTrustedPresentationInfo(TrustedPresentationThresholds const& thresholds, |
| 4067 | TrustedPresentationListener const& listener) { |
| 4068 | bool hadTrustedPresentationListener = hasTrustedPresentationListener(); |
| 4069 | mTrustedPresentationListener = listener; |
| 4070 | mTrustedPresentationThresholds = thresholds; |
| 4071 | bool haveTrustedPresentationListener = hasTrustedPresentationListener(); |
| 4072 | if (!hadTrustedPresentationListener && haveTrustedPresentationListener) { |
| 4073 | mFlinger->mNumTrustedPresentationListeners++; |
| 4074 | } else if (hadTrustedPresentationListener && !haveTrustedPresentationListener) { |
| 4075 | mFlinger->mNumTrustedPresentationListeners--; |
| 4076 | } |
| 4077 | } |
| 4078 | |
Vishnu Nair | a156f48 | 2023-02-22 00:23:38 +0000 | [diff] [blame^] | 4079 | void Layer::updateLastLatchTime(nsecs_t latchTime) { |
| 4080 | mLastLatchTime = latchTime; |
| 4081 | } |
| 4082 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 4083 | // --------------------------------------------------------------------------- |
| 4084 | |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 4085 | std::ostream& operator<<(std::ostream& stream, const Layer::FrameRate& rate) { |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 4086 | return stream << "{rate=" << rate.rate << " type=" << ftl::enum_string(rate.type) |
| 4087 | << " seamlessness=" << ftl::enum_string(rate.seamlessness) << '}'; |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 4088 | } |
| 4089 | |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 4090 | } // namespace android |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 4091 | |
| 4092 | #if defined(__gl_h_) |
| 4093 | #error "don't include gl/gl.h in this file" |
| 4094 | #endif |
| 4095 | |
| 4096 | #if defined(__gl2_h_) |
| 4097 | #error "don't include gl2/gl2.h in this file" |
| 4098 | #endif |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 4099 | |
| 4100 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 4101 | #pragma clang diagnostic pop // ignored "-Wconversion" |