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