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