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