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