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> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 32 | #include <compositionengine/Display.h> |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 33 | #include <compositionengine/LayerFECompositionState.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 34 | #include <compositionengine/OutputLayer.h> |
| 35 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 36 | #include <cutils/compiler.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 37 | #include <cutils/native_handle.h> |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 38 | #include <cutils/properties.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 39 | #include <gui/BufferItem.h> |
| 40 | #include <gui/LayerDebugInfo.h> |
| 41 | #include <gui/Surface.h> |
Alec Mouri | e60041e | 2019-06-14 18:59:51 -0700 | [diff] [blame] | 42 | #include <math.h> |
chaviw | 250bcbb | 2020-08-05 11:17:54 -0700 | [diff] [blame] | 43 | #include <private/android_filesystem_config.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 44 | #include <renderengine/RenderEngine.h> |
Alec Mouri | e60041e | 2019-06-14 18:59:51 -0700 | [diff] [blame] | 45 | #include <stdint.h> |
| 46 | #include <stdlib.h> |
| 47 | #include <sys/types.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 48 | #include <ui/DebugUtils.h> |
| 49 | #include <ui/GraphicBuffer.h> |
| 50 | #include <ui/PixelFormat.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | #include <utils/Errors.h> |
| 52 | #include <utils/Log.h> |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 53 | #include <utils/NativeHandle.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | #include <utils/StopWatch.h> |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 55 | #include <utils/Trace.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | |
Alec Mouri | e60041e | 2019-06-14 18:59:51 -0700 | [diff] [blame] | 57 | #include <algorithm> |
| 58 | #include <mutex> |
| 59 | #include <sstream> |
| 60 | |
Yiwei Zhang | 60d1a19 | 2018-03-07 14:52:28 -0800 | [diff] [blame] | 61 | #include "BufferLayer.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 62 | #include "Colorizer.h" |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 63 | #include "DisplayDevice.h" |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 64 | #include "DisplayHardware/HWComposer.h" |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 65 | #include "EffectLayer.h" |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 66 | #include "FrameTimeline.h" |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 67 | #include "FrameTracer/FrameTracer.h" |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 68 | #include "LayerProtoHelper.h" |
Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 69 | #include "LayerRejecter.h" |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 70 | #include "MonitoredProducer.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | #include "SurfaceFlinger.h" |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 72 | #include "TimeStats/TimeStats.h" |
Robert Carr | 3e2a299 | 2021-06-11 13:42:55 -0700 | [diff] [blame] | 73 | #include "TunnelModeEnabledReporter.h" |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 74 | #include "input/InputWindow.h" |
Ramakant Singh | 54ec1eb | 2020-03-26 15:35:26 +0530 | [diff] [blame] | 75 | #include "QtiGralloc.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 |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | |
Ramakant Singh | 54ec1eb | 2020-03-26 15:35:26 +0530 | [diff] [blame] | 79 | using android::hardware::graphics::common::V1_0::BufferUsage; |
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; |
| 83 | } // namespace |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 85 | using base::StringAppendF; |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 86 | using namespace android::flag_operators; |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 87 | using PresentState = frametimeline::SurfaceFrame::PresentState; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 88 | |
Lloyd Pique | f1c675b | 2018-09-12 20:45:39 -0700 | [diff] [blame] | 89 | std::atomic<int32_t> Layer::sSequence{1}; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 90 | |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 91 | Layer::Layer(const LayerCreationArgs& args) |
Ady Abraham | 8f1ee7f | 2019-04-05 10:32:50 -0700 | [diff] [blame] | 92 | : mFlinger(args.flinger), |
| 93 | mName(args.name), |
| 94 | mClientRef(args.client), |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 95 | mWindowType(static_cast<InputWindowInfo::Type>( |
| 96 | args.metadata.getInt32(METADATA_WINDOW_TYPE, 0))) { |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 97 | uint32_t layerFlags = 0; |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 98 | if (args.flags & ISurfaceComposerClient::eHidden) layerFlags |= layer_state_t::eLayerHidden; |
| 99 | if (args.flags & ISurfaceComposerClient::eOpaque) layerFlags |= layer_state_t::eLayerOpaque; |
| 100 | if (args.flags & ISurfaceComposerClient::eSecure) layerFlags |= layer_state_t::eLayerSecure; |
chaviw | c5676c6 | 2020-09-18 15:01:04 -0700 | [diff] [blame] | 101 | if (args.flags & ISurfaceComposerClient::eSkipScreenshot) |
| 102 | layerFlags |= layer_state_t::eLayerSkipScreenshot; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 103 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 104 | mDrawingState.active_legacy.w = args.w; |
| 105 | mDrawingState.active_legacy.h = args.h; |
| 106 | mDrawingState.flags = layerFlags; |
| 107 | mDrawingState.active_legacy.transform.set(0, 0); |
| 108 | mDrawingState.crop.makeInvalid(); |
| 109 | mDrawingState.requestedCrop = mDrawingState.crop; |
| 110 | mDrawingState.z = 0; |
| 111 | mDrawingState.color.a = 1.0f; |
| 112 | mDrawingState.layerStack = 0; |
| 113 | mDrawingState.sequence = 0; |
| 114 | mDrawingState.requested_legacy = mDrawingState.active_legacy; |
| 115 | mDrawingState.width = UINT32_MAX; |
| 116 | mDrawingState.height = UINT32_MAX; |
| 117 | mDrawingState.transform.set(0, 0); |
| 118 | mDrawingState.frameNumber = 0; |
| 119 | mDrawingState.bufferTransform = 0; |
| 120 | mDrawingState.transformToDisplayInverse = false; |
| 121 | mDrawingState.crop.makeInvalid(); |
| 122 | mDrawingState.acquireFence = sp<Fence>::make(-1); |
| 123 | mDrawingState.acquireFenceTime = std::make_shared<FenceTime>(mDrawingState.acquireFence); |
| 124 | mDrawingState.dataspace = ui::Dataspace::UNKNOWN; |
| 125 | mDrawingState.hdrMetadata.validTypes = 0; |
| 126 | mDrawingState.surfaceDamageRegion = Region::INVALID_REGION; |
| 127 | mDrawingState.cornerRadius = 0.0f; |
| 128 | mDrawingState.backgroundBlurRadius = 0; |
| 129 | mDrawingState.api = -1; |
| 130 | mDrawingState.hasColorTransform = false; |
| 131 | mDrawingState.colorSpaceAgnostic = false; |
| 132 | mDrawingState.frameRateSelectionPriority = PRIORITY_UNSET; |
| 133 | mDrawingState.metadata = args.metadata; |
| 134 | mDrawingState.shadowRadius = 0.f; |
| 135 | mDrawingState.fixedTransformHint = ui::Transform::ROT_INVALID; |
| 136 | mDrawingState.frameTimelineInfo = {}; |
| 137 | mDrawingState.postTime = -1; |
| 138 | mDrawingState.destinationFrame.makeInvalid(); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 139 | |
Vishnu Nair | c43a23c | 2020-05-29 14:32:27 -0700 | [diff] [blame] | 140 | if (args.flags & ISurfaceComposerClient::eNoColorFill) { |
| 141 | // Set an invalid color so there is no color fill. |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 142 | mDrawingState.color.r = -1.0_hf; |
| 143 | mDrawingState.color.g = -1.0_hf; |
| 144 | mDrawingState.color.b = -1.0_hf; |
Vishnu Nair | c43a23c | 2020-05-29 14:32:27 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 147 | CompositorTiming compositorTiming; |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 148 | args.flinger->getCompositorTiming(&compositorTiming); |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 149 | mFrameEventHistory.initializeCompositorTiming(compositorTiming); |
Jorim Jaggi | bd6480f | 2018-08-10 14:37:31 +0200 | [diff] [blame] | 150 | mFrameTracker.setDisplayRefreshPeriod(compositorTiming.interval); |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 151 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 152 | mCallingPid = args.callingPid; |
| 153 | mCallingUid = args.callingUid; |
chaviw | 250bcbb | 2020-08-05 11:17:54 -0700 | [diff] [blame] | 154 | |
| 155 | if (mCallingUid == AID_GRAPHICS || mCallingUid == AID_SYSTEM) { |
| 156 | // If the system didn't send an ownerUid, use the callingUid for the ownerUid. |
| 157 | mOwnerUid = args.metadata.getInt32(METADATA_OWNER_UID, mCallingUid); |
Adithya Srinivasan | 9febda8 | 2020-10-19 10:49:41 -0700 | [diff] [blame] | 158 | mOwnerPid = args.metadata.getInt32(METADATA_OWNER_PID, mCallingPid); |
chaviw | 250bcbb | 2020-08-05 11:17:54 -0700 | [diff] [blame] | 159 | } else { |
| 160 | // A create layer request from a non system request cannot specify the owner uid |
| 161 | mOwnerUid = mCallingUid; |
Adithya Srinivasan | 9febda8 | 2020-10-19 10:49:41 -0700 | [diff] [blame] | 162 | mOwnerPid = mCallingPid; |
chaviw | 250bcbb | 2020-08-05 11:17:54 -0700 | [diff] [blame] | 163 | } |
Dominik Laskowski | 7584836 | 2019-11-11 17:57:20 -0800 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | void Layer::onFirstRef() { |
| 167 | mFlinger->onLayerFirstRef(this); |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 168 | } |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 169 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 170 | Layer::~Layer() { |
David Sodman | 577c896 | 2017-12-08 14:50:53 -0800 | [diff] [blame] | 171 | sp<Client> c(mClientRef.promote()); |
| 172 | if (c != 0) { |
| 173 | c->detachLayer(this); |
| 174 | } |
| 175 | |
Jorim Jaggi | 10c985e | 2018-10-23 11:17:45 +0000 | [diff] [blame] | 176 | mFrameTracker.logAndResetStats(mName); |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 177 | mFlinger->onLayerDestroyed(this); |
Robert Carr | 3e2a299 | 2021-06-11 13:42:55 -0700 | [diff] [blame] | 178 | |
| 179 | if (mDrawingState.sidebandStream != nullptr) { |
| 180 | mFlinger->mTunnelModeEnabledReporter->decrementTunnelModeCount(); |
| 181 | } |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 182 | if (mHadClonedChild) { |
| 183 | mFlinger->mNumClones--; |
| 184 | } |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 187 | LayerCreationArgs::LayerCreationArgs(SurfaceFlinger* flinger, sp<Client> client, std::string name, |
| 188 | uint32_t w, uint32_t h, uint32_t flags, LayerMetadata metadata) |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 189 | : flinger(flinger), |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 190 | client(std::move(client)), |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 191 | name(std::move(name)), |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 192 | w(w), |
| 193 | h(h), |
| 194 | flags(flags), |
| 195 | metadata(std::move(metadata)) { |
| 196 | IPCThreadState* ipc = IPCThreadState::self(); |
| 197 | callingPid = ipc->getCallingPid(); |
| 198 | callingUid = ipc->getCallingUid(); |
| 199 | } |
| 200 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 201 | // --------------------------------------------------------------------------- |
| 202 | // callbacks |
| 203 | // --------------------------------------------------------------------------- |
| 204 | |
David Sodman | eb085e0 | 2017-10-05 18:49:04 -0700 | [diff] [blame] | 205 | /* |
| 206 | * onLayerDisplayed is only meaningful for BufferLayer, but, is called through |
| 207 | * Layer. So, the implementation is done in BufferLayer. When called on a |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 208 | * EffectLayer object, it's essentially a NOP. |
David Sodman | eb085e0 | 2017-10-05 18:49:04 -0700 | [diff] [blame] | 209 | */ |
David Sodman | eb085e0 | 2017-10-05 18:49:04 -0700 | [diff] [blame] | 210 | void Layer::onLayerDisplayed(const sp<Fence>& /*releaseFence*/) {} |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 211 | |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 212 | void Layer::removeRelativeZ(const std::vector<Layer*>& layersInTree) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 213 | if (mDrawingState.zOrderRelativeOf == nullptr) { |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 214 | return; |
| 215 | } |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 216 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 217 | sp<Layer> strongRelative = mDrawingState.zOrderRelativeOf.promote(); |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 218 | if (strongRelative == nullptr) { |
| 219 | setZOrderRelativeOf(nullptr); |
| 220 | return; |
| 221 | } |
| 222 | |
| 223 | if (!std::binary_search(layersInTree.begin(), layersInTree.end(), strongRelative.get())) { |
| 224 | strongRelative->removeZOrderRelative(this); |
| 225 | mFlinger->setTransactionFlags(eTraversalNeeded); |
chaviw | 606e5cf | 2019-03-01 10:12:10 -0800 | [diff] [blame] | 226 | setZOrderRelativeOf(nullptr); |
Robert Carr | 5edb1ad | 2017-04-25 10:54:24 -0700 | [diff] [blame] | 227 | } |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | void Layer::removeFromCurrentState() { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 231 | if (!mRemovedFromDrawingState) { |
| 232 | mRemovedFromDrawingState = true; |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 233 | mFlinger->mScheduler->deregisterLayer(this); |
| 234 | } |
Rob Carr | 4bba370 | 2018-10-08 21:53:30 +0000 | [diff] [blame] | 235 | |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 236 | mFlinger->markLayerPendingRemovalLocked(this); |
Chia-I Wu | c665702 | 2017-08-15 11:18:17 -0700 | [diff] [blame] | 237 | } |
Chia-I Wu | 3851225 | 2017-05-17 14:36:16 -0700 | [diff] [blame] | 238 | |
chaviw | 68d4dab | 2020-06-08 15:07:32 -0700 | [diff] [blame] | 239 | sp<Layer> Layer::getRootLayer() { |
| 240 | sp<Layer> parent = getParent(); |
| 241 | if (parent == nullptr) { |
| 242 | return this; |
| 243 | } |
| 244 | return parent->getRootLayer(); |
| 245 | } |
| 246 | |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 247 | void Layer::onRemovedFromCurrentState() { |
chaviw | 68d4dab | 2020-06-08 15:07:32 -0700 | [diff] [blame] | 248 | // Use the root layer since we want to maintain the hierarchy for the entire subtree. |
| 249 | auto layersInTree = getRootLayer()->getLayersInTree(LayerVector::StateSet::Current); |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 250 | std::sort(layersInTree.begin(), layersInTree.end()); |
chaviw | 68d4dab | 2020-06-08 15:07:32 -0700 | [diff] [blame] | 251 | |
| 252 | traverse(LayerVector::StateSet::Current, [&](Layer* layer) { |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 253 | layer->removeFromCurrentState(); |
| 254 | layer->removeRelativeZ(layersInTree); |
chaviw | 68d4dab | 2020-06-08 15:07:32 -0700 | [diff] [blame] | 255 | }); |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 256 | } |
| 257 | |
chaviw | 61626f2 | 2018-11-15 16:26:27 -0800 | [diff] [blame] | 258 | void Layer::addToCurrentState() { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 259 | if (mRemovedFromDrawingState) { |
| 260 | mRemovedFromDrawingState = false; |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 261 | mFlinger->mScheduler->registerLayer(this); |
Robert Carr | 867be37 | 2021-06-29 17:36:02 -0700 | [diff] [blame] | 262 | mFlinger->removeFromOffscreenLayers(this); |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 263 | } |
chaviw | 61626f2 | 2018-11-15 16:26:27 -0800 | [diff] [blame] | 264 | |
| 265 | for (const auto& child : mCurrentChildren) { |
| 266 | child->addToCurrentState(); |
| 267 | } |
| 268 | } |
| 269 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 270 | // --------------------------------------------------------------------------- |
| 271 | // set-up |
| 272 | // --------------------------------------------------------------------------- |
| 273 | |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 274 | bool Layer::getPremultipledAlpha() const { |
| 275 | return mPremultipliedAlpha; |
| 276 | } |
| 277 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 278 | sp<IBinder> Layer::getHandle() { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 279 | Mutex::Autolock _l(mLock); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 280 | if (mGetHandleCalled) { |
| 281 | ALOGE("Get handle called twice" ); |
| 282 | return nullptr; |
| 283 | } |
| 284 | mGetHandleCalled = true; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 285 | return new Handle(mFlinger, this); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | // --------------------------------------------------------------------------- |
| 289 | // h/w composer set-up |
| 290 | // --------------------------------------------------------------------------- |
| 291 | |
Mathias Agopian | f3e85d4 | 2013-05-10 18:01:12 -0700 | [diff] [blame] | 292 | static Rect reduce(const Rect& win, const Region& exclude) { |
| 293 | if (CC_LIKELY(exclude.isEmpty())) { |
| 294 | return win; |
| 295 | } |
| 296 | if (exclude.isRect()) { |
| 297 | return win.reduce(exclude.getBounds()); |
| 298 | } |
| 299 | return Region(win).subtract(exclude).getBounds(); |
| 300 | } |
| 301 | |
Dan Stoza | 80d6116 | 2017-12-20 15:57:52 -0800 | [diff] [blame] | 302 | static FloatRect reduce(const FloatRect& win, const Region& exclude) { |
| 303 | if (CC_LIKELY(exclude.isEmpty())) { |
| 304 | return win; |
| 305 | } |
| 306 | // Convert through Rect (by rounding) for lack of FloatRegion |
| 307 | return Region(Rect{win}).subtract(exclude).getBounds().toFloatRect(); |
| 308 | } |
| 309 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 310 | Rect Layer::getScreenBounds(bool reduceTransparentRegion) const { |
Vishnu Nair | f0c2851 | 2019-02-08 12:40:28 -0800 | [diff] [blame] | 311 | if (!reduceTransparentRegion) { |
| 312 | return Rect{mScreenBounds}; |
| 313 | } |
| 314 | |
| 315 | FloatRect bounds = getBounds(); |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 316 | ui::Transform t = getTransform(); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 317 | // Transform to screen space. |
| 318 | bounds = t.transform(bounds); |
| 319 | return Rect{bounds}; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 322 | FloatRect Layer::getBounds() const { |
Alec Mouri | b416efd | 2018-09-06 21:01:59 +0000 | [diff] [blame] | 323 | const State& s(getDrawingState()); |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 324 | return getBounds(getActiveTransparentRegion(s)); |
Michael Lentine | 6c925ed | 2014-09-26 17:55:01 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Vishnu Nair | f0c2851 | 2019-02-08 12:40:28 -0800 | [diff] [blame] | 327 | FloatRect Layer::getBounds(const Region& activeTransparentRegion) const { |
| 328 | // Subtract the transparent region and snap to the bounds. |
| 329 | return reduce(mBounds, activeTransparentRegion); |
| 330 | } |
| 331 | |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 332 | void Layer::computeBounds(FloatRect parentBounds, ui::Transform parentTransform, |
| 333 | float parentShadowRadius) { |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 334 | const State& s(getDrawingState()); |
| 335 | |
| 336 | // Calculate effective layer transform |
| 337 | mEffectiveTransform = parentTransform * getActiveTransform(s); |
| 338 | |
| 339 | // Transform parent bounds to layer space |
| 340 | parentBounds = getActiveTransform(s).inverse().transform(parentBounds); |
| 341 | |
Vishnu Nair | c652ff8 | 2019-03-15 12:48:54 -0700 | [diff] [blame] | 342 | // Calculate source bounds |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 343 | mSourceBounds = computeSourceBounds(parentBounds); |
| 344 | |
| 345 | // Calculate bounds by croping diplay frame with layer crop and parent bounds |
| 346 | FloatRect bounds = mSourceBounds; |
| 347 | const Rect layerCrop = getCrop(s); |
| 348 | if (!layerCrop.isEmpty()) { |
| 349 | bounds = mSourceBounds.intersect(layerCrop.toFloatRect()); |
| 350 | } |
| 351 | bounds = bounds.intersect(parentBounds); |
| 352 | |
| 353 | mBounds = bounds; |
| 354 | mScreenBounds = mEffectiveTransform.transform(mBounds); |
Vishnu Nair | c652ff8 | 2019-03-15 12:48:54 -0700 | [diff] [blame] | 355 | |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 356 | // Use the layer's own shadow radius if set. Otherwise get the radius from |
| 357 | // parent. |
| 358 | if (s.shadowRadius > 0.f) { |
| 359 | mEffectiveShadowRadius = s.shadowRadius; |
| 360 | } else { |
| 361 | mEffectiveShadowRadius = parentShadowRadius; |
| 362 | } |
| 363 | |
| 364 | // Shadow radius is passed down to only one layer so if the layer can draw shadows, |
| 365 | // don't pass it to its children. |
| 366 | const float childShadowRadius = canDrawShadows() ? 0.f : mEffectiveShadowRadius; |
| 367 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 368 | for (const sp<Layer>& child : mDrawingChildren) { |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 369 | child->computeBounds(mBounds, mEffectiveTransform, childShadowRadius); |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 370 | } |
| 371 | } |
| 372 | |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 373 | Rect Layer::getCroppedBufferSize(const State& s) const { |
| 374 | Rect size = getBufferSize(s); |
| 375 | Rect crop = getCrop(s); |
| 376 | if (!crop.isEmpty() && size.isValid()) { |
| 377 | size.intersect(crop, &size); |
| 378 | } else if (!crop.isEmpty()) { |
| 379 | size = crop; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 380 | } |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 381 | return size; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 382 | } |
| 383 | |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 384 | void Layer::setupRoundedCornersCropCoordinates(Rect win, |
| 385 | const FloatRect& roundedCornersCrop) const { |
| 386 | // Translate win by the rounded corners rect coordinates, to have all values in |
| 387 | // layer coordinate space. |
| 388 | win.left -= roundedCornersCrop.left; |
| 389 | win.right -= roundedCornersCrop.left; |
| 390 | win.top -= roundedCornersCrop.top; |
| 391 | win.bottom -= roundedCornersCrop.top; |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 394 | void Layer::prepareBasicGeometryCompositionState() { |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 395 | const auto& drawingState{getDrawingState()}; |
| 396 | const uint32_t layerStack = getLayerStack(); |
| 397 | const auto alpha = static_cast<float>(getAlpha()); |
| 398 | const bool opaque = isOpaque(drawingState); |
| 399 | const bool usesRoundedCorners = getRoundedCornerState().radius != 0.f; |
| 400 | |
| 401 | auto blendMode = Hwc2::IComposerClient::BlendMode::NONE; |
| 402 | if (!opaque || alpha != 1.0f) { |
| 403 | blendMode = mPremultipliedAlpha ? Hwc2::IComposerClient::BlendMode::PREMULTIPLIED |
| 404 | : Hwc2::IComposerClient::BlendMode::COVERAGE; |
| 405 | } |
| 406 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 407 | auto* compositionState = editCompositionState(); |
| 408 | compositionState->layerStackId = |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 409 | (layerStack != ~0u) ? std::make_optional(layerStack) : std::nullopt; |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 410 | compositionState->internalOnly = getPrimaryDisplayOnly(); |
| 411 | compositionState->isVisible = isVisible(); |
| 412 | compositionState->isOpaque = opaque && !usesRoundedCorners && alpha == 1.f; |
| 413 | compositionState->shadowRadius = mEffectiveShadowRadius; |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 414 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 415 | compositionState->contentDirty = contentDirty; |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 416 | contentDirty = false; |
| 417 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 418 | compositionState->geomLayerBounds = mBounds; |
| 419 | compositionState->geomLayerTransform = getTransform(); |
| 420 | compositionState->geomInverseLayerTransform = compositionState->geomLayerTransform.inverse(); |
| 421 | compositionState->transparentRegionHint = getActiveTransparentRegion(drawingState); |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 422 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 423 | compositionState->blendMode = static_cast<Hwc2::IComposerClient::BlendMode>(blendMode); |
| 424 | compositionState->alpha = alpha; |
| 425 | compositionState->backgroundBlurRadius = drawingState.backgroundBlurRadius; |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 426 | compositionState->blurRegions = drawingState.blurRegions; |
John Reck | c00c669 | 2021-02-16 11:37:33 -0500 | [diff] [blame] | 427 | compositionState->stretchEffect = getStretchEffect(); |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 428 | } |
| 429 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 430 | void Layer::prepareGeometryCompositionState() { |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 431 | const auto& drawingState{getDrawingState()}; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 432 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 433 | int type = drawingState.metadata.getInt32(METADATA_WINDOW_TYPE, 0); |
| 434 | int appId = drawingState.metadata.getInt32(METADATA_OWNER_UID, 0); |
Chia-I Wu | e41dbe6 | 2017-06-13 14:10:56 -0700 | [diff] [blame] | 435 | sp<Layer> parent = mDrawingParent.promote(); |
Albert Chaulk | 2a58963 | 2017-05-04 16:59:44 -0400 | [diff] [blame] | 436 | if (parent.get()) { |
| 437 | auto& parentState = parent->getDrawingState(); |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 438 | const int parentType = parentState.metadata.getInt32(METADATA_WINDOW_TYPE, 0); |
| 439 | const int parentAppId = parentState.metadata.getInt32(METADATA_OWNER_UID, 0); |
Jiwen 'Steve' Cai | 736c74e | 2019-05-28 18:33:22 -0700 | [diff] [blame] | 440 | if (parentType > 0 && parentAppId > 0) { |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 441 | type = parentType; |
| 442 | appId = parentAppId; |
rongliu | cfb187b | 2018-03-14 12:26:23 -0700 | [diff] [blame] | 443 | } |
Albert Chaulk | 2a58963 | 2017-05-04 16:59:44 -0400 | [diff] [blame] | 444 | } |
| 445 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 446 | auto* compositionState = editCompositionState(); |
David Sodman | 1509411 | 2018-10-11 09:39:37 -0700 | [diff] [blame] | 447 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 448 | compositionState->geomBufferSize = getBufferSize(drawingState); |
| 449 | compositionState->geomContentCrop = getBufferCrop(); |
| 450 | compositionState->geomCrop = getCrop(drawingState); |
| 451 | compositionState->geomBufferTransform = getBufferTransform(); |
| 452 | compositionState->geomBufferUsesDisplayInverseTransform = getTransformToDisplayInverse(); |
| 453 | compositionState->geomUsesSourceCrop = usesSourceCrop(); |
| 454 | compositionState->isSecure = isSecure(); |
Ramakant Singh | 54ec1eb | 2020-03-26 15:35:26 +0530 | [diff] [blame] | 455 | compositionState->isSecureDisplay = isSecureDisplay(); |
| 456 | compositionState->isSecureCamera = isSecureCamera(); |
Ramakant Singh | 3e6a04a | 2020-05-30 20:37:11 +0530 | [diff] [blame] | 457 | compositionState->isScreenshot = isScreenshot(); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 458 | |
Ray Zhang | 49d5d0d | 2020-03-27 19:53:33 +0800 | [diff] [blame] | 459 | compositionState->layerClass = mLayerClass; |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 460 | |
| 461 | compositionState->metadata.clear(); |
| 462 | const auto& supportedMetadata = mFlinger->getHwComposer().getSupportedLayerGenericMetadata(); |
| 463 | for (const auto& [key, mandatory] : supportedMetadata) { |
| 464 | const auto& genericLayerMetadataCompatibilityMap = |
| 465 | mFlinger->getGenericLayerMetadataKeyMap(); |
| 466 | auto compatIter = genericLayerMetadataCompatibilityMap.find(key); |
| 467 | if (compatIter == std::end(genericLayerMetadataCompatibilityMap)) { |
| 468 | continue; |
| 469 | } |
| 470 | const uint32_t id = compatIter->second; |
| 471 | |
| 472 | auto it = drawingState.metadata.mMap.find(id); |
| 473 | if (it == std::end(drawingState.metadata.mMap)) { |
| 474 | continue; |
| 475 | } |
| 476 | |
| 477 | compositionState->metadata |
| 478 | .emplace(key, compositionengine::GenericLayerMetadataEntry{mandatory, it->second}); |
| 479 | } |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 480 | } |
David Sodman | ba34049 | 2018-08-05 21:51:33 -0700 | [diff] [blame] | 481 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 482 | void Layer::preparePerFrameCompositionState() { |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 483 | const auto& drawingState{getDrawingState()}; |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 484 | auto* compositionState = editCompositionState(); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 485 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 486 | compositionState->forceClientComposition = false; |
| 487 | |
| 488 | compositionState->isColorspaceAgnostic = isColorSpaceAgnostic(); |
| 489 | compositionState->dataspace = getDataSpace(); |
| 490 | compositionState->colorTransform = getColorTransform(); |
| 491 | compositionState->colorTransformIsIdentity = !hasColorTransform(); |
| 492 | compositionState->surfaceDamage = surfaceDamageRegion; |
| 493 | compositionState->hasProtectedContent = isProtected(); |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 494 | |
| 495 | const bool usesRoundedCorners = getRoundedCornerState().radius != 0.f; |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 496 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 497 | compositionState->isOpaque = |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 498 | isOpaque(drawingState) && !usesRoundedCorners && getAlpha() == 1.0_hf; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 499 | |
| 500 | // 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] | 501 | // Rounded corners no longer force client composition, since we may use a |
| 502 | // hole punch so that the layer will appear to have rounded corners. |
| 503 | if (isHdrY410() || drawShadows() || drawingState.blurRegions.size() > 0 || |
John Reck | c00c669 | 2021-02-16 11:37:33 -0500 | [diff] [blame] | 504 | compositionState->stretchEffect.hasEffect()) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 505 | compositionState->forceClientComposition = true; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 509 | void Layer::prepareCursorCompositionState() { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 510 | const State& drawingState{getDrawingState()}; |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 511 | auto* compositionState = editCompositionState(); |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 512 | |
| 513 | // Apply the layer's transform, followed by the display's global transform |
| 514 | // Here we're guaranteed that the layer's transform preserves rects |
| 515 | Rect win = getCroppedBufferSize(drawingState); |
| 516 | // Subtract the transparent region and snap to the bounds |
| 517 | Rect bounds = reduce(win, getActiveTransparentRegion(drawingState)); |
| 518 | Rect frame(getTransform().transform(bounds)); |
| 519 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 520 | compositionState->cursorFrame = frame; |
| 521 | } |
| 522 | |
| 523 | sp<compositionengine::LayerFE> Layer::asLayerFE() const { |
| 524 | return const_cast<compositionengine::LayerFE*>( |
| 525 | static_cast<const compositionengine::LayerFE*>(this)); |
| 526 | } |
| 527 | |
| 528 | sp<compositionengine::LayerFE> Layer::getCompositionEngineLayerFE() const { |
| 529 | return nullptr; |
| 530 | } |
| 531 | |
| 532 | compositionengine::LayerFECompositionState* Layer::editCompositionState() { |
| 533 | return nullptr; |
| 534 | } |
| 535 | |
| 536 | const compositionengine::LayerFECompositionState* Layer::getCompositionState() const { |
| 537 | return nullptr; |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 538 | } |
| 539 | |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 540 | bool Layer::onPreComposition(nsecs_t) { |
| 541 | return false; |
| 542 | } |
| 543 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 544 | void Layer::prepareCompositionState(compositionengine::LayerFE::StateSubset subset) { |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 545 | using StateSubset = compositionengine::LayerFE::StateSubset; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 546 | |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 547 | switch (subset) { |
| 548 | case StateSubset::BasicGeometry: |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 549 | prepareBasicGeometryCompositionState(); |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 550 | break; |
| 551 | |
| 552 | case StateSubset::GeometryAndContent: |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 553 | prepareBasicGeometryCompositionState(); |
| 554 | prepareGeometryCompositionState(); |
| 555 | preparePerFrameCompositionState(); |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 556 | break; |
| 557 | |
| 558 | case StateSubset::Content: |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 559 | preparePerFrameCompositionState(); |
| 560 | break; |
| 561 | |
| 562 | case StateSubset::Cursor: |
| 563 | prepareCursorCompositionState(); |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 564 | break; |
| 565 | } |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 566 | } |
Mathias Agopian | 29a367b | 2011-07-12 14:51:45 -0700 | [diff] [blame] | 567 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 568 | const char* Layer::getDebugName() const { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 569 | return mName.c_str(); |
David Sodman | 4b7c4bc | 2017-11-17 12:13:59 -0800 | [diff] [blame] | 570 | } |
| 571 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 572 | // --------------------------------------------------------------------------- |
| 573 | // drawing... |
| 574 | // --------------------------------------------------------------------------- |
| 575 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 576 | std::optional<compositionengine::LayerFE::LayerSettings> Layer::prepareClientComposition( |
Galia Peycheva | 66eaf4a | 2020-11-09 13:17:57 +0100 | [diff] [blame] | 577 | compositionengine::LayerFE::ClientCompositionTargetSettings& targetSettings) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 578 | if (!getCompositionState()) { |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 579 | return {}; |
| 580 | } |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 581 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 582 | FloatRect bounds = getBounds(); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 583 | half alpha = getAlpha(); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 584 | |
| 585 | compositionengine::LayerFE::LayerSettings layerSettings; |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 586 | layerSettings.geometry.boundaries = bounds; |
chaviw | c6ad8af | 2020-08-03 11:33:30 -0700 | [diff] [blame] | 587 | layerSettings.geometry.positionTransform = getTransform().asMatrix4(); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 588 | |
Derek Sollenberger | c31985e | 2021-05-18 16:38:17 -0400 | [diff] [blame] | 589 | // skip drawing content if the targetSettings indicate the content will be occluded |
Ady Abraham | baa6cf5 | 2021-07-13 14:02:19 -0700 | [diff] [blame] | 590 | const bool drawContent = targetSettings.realContentIsVisible || targetSettings.clearContent; |
| 591 | layerSettings.skipContentDraw = !drawContent; |
Derek Sollenberger | c31985e | 2021-05-18 16:38:17 -0400 | [diff] [blame] | 592 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 593 | if (hasColorTransform()) { |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 594 | layerSettings.colorTransform = getColorTransform(); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | const auto roundedCornerState = getRoundedCornerState(); |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 598 | layerSettings.geometry.roundedCornersRadius = roundedCornerState.radius; |
| 599 | layerSettings.geometry.roundedCornersCrop = roundedCornerState.cropRect; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 600 | |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 601 | layerSettings.alpha = alpha; |
chaviw | 4244e03 | 2019-09-04 11:27:49 -0700 | [diff] [blame] | 602 | layerSettings.sourceDataspace = getDataSpace(); |
Alec Mouri | f54453c | 2021-05-13 16:28:28 -0700 | [diff] [blame] | 603 | switch (targetSettings.blurSetting) { |
| 604 | case LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled: |
| 605 | layerSettings.backgroundBlurRadius = getBackgroundBlurRadius(); |
| 606 | layerSettings.blurRegions = getBlurRegions(); |
| 607 | layerSettings.blurRegionTransform = |
| 608 | getActiveTransform(getDrawingState()).inverse().asMatrix4(); |
| 609 | break; |
| 610 | case LayerFE::ClientCompositionTargetSettings::BlurSetting::BackgroundBlurOnly: |
| 611 | layerSettings.backgroundBlurRadius = getBackgroundBlurRadius(); |
| 612 | break; |
| 613 | case LayerFE::ClientCompositionTargetSettings::BlurSetting::BlurRegionsOnly: |
| 614 | layerSettings.blurRegions = getBlurRegions(); |
| 615 | layerSettings.blurRegionTransform = |
| 616 | getActiveTransform(getDrawingState()).inverse().asMatrix4(); |
| 617 | break; |
| 618 | case LayerFE::ClientCompositionTargetSettings::BlurSetting::Disabled: |
| 619 | default: |
| 620 | break; |
Galia Peycheva | 66eaf4a | 2020-11-09 13:17:57 +0100 | [diff] [blame] | 621 | } |
Nader Jawad | 2dfc98b | 2021-04-08 20:35:39 -0700 | [diff] [blame] | 622 | layerSettings.stretchEffect = getStretchEffect(); |
Ana Krulec | 6eab17a | 2020-12-09 15:52:36 -0800 | [diff] [blame] | 623 | // Record the name of the layer for debugging further down the stack. |
| 624 | layerSettings.name = getName(); |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 625 | return layerSettings; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 626 | } |
| 627 | |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 628 | void Layer::prepareClearClientComposition(LayerFE::LayerSettings& layerSettings, |
| 629 | bool blackout) const { |
| 630 | layerSettings.source.buffer.buffer = nullptr; |
| 631 | layerSettings.source.solidColor = half3(0.0, 0.0, 0.0); |
| 632 | layerSettings.disableBlending = true; |
Vishnu Nair | 3b653e7 | 2020-02-24 16:40:50 -0800 | [diff] [blame] | 633 | layerSettings.bufferId = 0; |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 634 | layerSettings.frameNumber = 0; |
| 635 | |
| 636 | // If layer is blacked out, force alpha to 1 so that we draw a black color layer. |
| 637 | layerSettings.alpha = blackout ? 1.0f : 0.0f; |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 638 | layerSettings.name = getName(); |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 639 | } |
| 640 | |
Derek Sollenberger | c31985e | 2021-05-18 16:38:17 -0400 | [diff] [blame] | 641 | // TODO(b/188891810): This method now only ever returns 0 or 1 layers so we should return |
| 642 | // std::optional instead of a vector. Additionally, we should consider removing |
| 643 | // this method entirely in favor of calling prepareClientComposition directly. |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 644 | std::vector<compositionengine::LayerFE::LayerSettings> Layer::prepareClientCompositionList( |
| 645 | compositionengine::LayerFE::ClientCompositionTargetSettings& targetSettings) { |
| 646 | std::optional<compositionengine::LayerFE::LayerSettings> layerSettings = |
| 647 | prepareClientComposition(targetSettings); |
| 648 | // Nothing to render. |
| 649 | if (!layerSettings) { |
| 650 | return {}; |
| 651 | } |
| 652 | |
| 653 | // HWC requests to clear this layer. |
| 654 | if (targetSettings.clearContent) { |
| 655 | prepareClearClientComposition(*layerSettings, false /* blackout */); |
| 656 | return {*layerSettings}; |
| 657 | } |
| 658 | |
Derek Sollenberger | c31985e | 2021-05-18 16:38:17 -0400 | [diff] [blame] | 659 | // set the shadow for the layer if needed |
| 660 | prepareShadowClientComposition(*layerSettings, targetSettings.viewport); |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 661 | |
Derek Sollenberger | c31985e | 2021-05-18 16:38:17 -0400 | [diff] [blame] | 662 | return {*layerSettings}; |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 663 | } |
| 664 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 665 | Hwc2::IComposerClient::Composition Layer::getCompositionType(const DisplayDevice& display) const { |
| 666 | const auto outputLayer = findOutputLayerForDisplay(&display); |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 667 | if (outputLayer == nullptr) { |
| 668 | return Hwc2::IComposerClient::Composition::INVALID; |
| 669 | } |
| 670 | if (outputLayer->getState().hwc) { |
| 671 | return (*outputLayer->getState().hwc).hwcCompositionType; |
| 672 | } else { |
| 673 | return Hwc2::IComposerClient::Composition::CLIENT; |
| 674 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 675 | } |
| 676 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 677 | // ---------------------------------------------------------------------------- |
| 678 | // local state |
| 679 | // ---------------------------------------------------------------------------- |
| 680 | |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 681 | bool Layer::isSecure() const { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 682 | const State& s(mDrawingState); |
Garfield Tan | de619fa | 2020-10-02 17:13:53 -0700 | [diff] [blame] | 683 | if (s.flags & layer_state_t::eLayerSecure) { |
| 684 | return true; |
| 685 | } |
| 686 | |
| 687 | const auto p = mDrawingParent.promote(); |
| 688 | return (p != nullptr) ? p->isSecure() : false; |
Dan Stoza | 2311608 | 2015-06-18 14:58:39 -0700 | [diff] [blame] | 689 | } |
| 690 | |
Ramakant Singh | 54ec1eb | 2020-03-26 15:35:26 +0530 | [diff] [blame] | 691 | bool Layer::isSecureDisplay() const { |
| 692 | sp<const GraphicBuffer> buffer = getBuffer(); |
| 693 | return buffer && (buffer->getUsage() & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY); |
| 694 | } |
| 695 | |
| 696 | bool Layer::isSecureCamera() const { |
| 697 | sp<const GraphicBuffer> buffer = getBuffer(); |
| 698 | bool protected_buffer = buffer && (buffer->getUsage() & BufferUsage::PROTECTED); |
| 699 | bool camera_output = buffer && (buffer->getUsage() & BufferUsage::CAMERA_OUTPUT); |
| 700 | return protected_buffer && camera_output; |
| 701 | } |
Ramakant Singh | 3e6a04a | 2020-05-30 20:37:11 +0530 | [diff] [blame] | 702 | |
| 703 | bool Layer::isScreenshot() const { |
Mathew Joseph Karimpanal | 1370fca | 2021-11-22 14:37:38 +0530 | [diff] [blame] | 704 | return (isScreenshotName(getName())); |
Ramakant Singh | 3e6a04a | 2020-05-30 20:37:11 +0530 | [diff] [blame] | 705 | } |
Mathew Joseph Karimpanal | 1370fca | 2021-11-22 14:37:38 +0530 | [diff] [blame] | 706 | |
| 707 | bool Layer::isScreenshotName(std::string layer_name) { |
| 708 | return ((layer_name.find("ScreenshotSurface") != std::string::npos) || |
| 709 | (layer_name.find("RotationLayer") != std::string::npos) || |
| 710 | (layer_name.find("BackColorSurface") != std::string::npos)); |
| 711 | } |
| 712 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 713 | // ---------------------------------------------------------------------------- |
| 714 | // transaction |
| 715 | // ---------------------------------------------------------------------------- |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 716 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 717 | uint32_t Layer::doTransaction(uint32_t flags) { |
| 718 | ATRACE_CALL(); |
| 719 | |
Robert Carr | 0758e5d | 2021-03-11 22:15:04 -0800 | [diff] [blame] | 720 | // TODO: This is unfortunate. |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 721 | mDrawingStateModified = mDrawingState.modified; |
| 722 | mDrawingState.modified = false; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 723 | |
Alec Mouri | b416efd | 2018-09-06 21:01:59 +0000 | [diff] [blame] | 724 | const State& s(getDrawingState()); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 725 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 726 | if (updateGeometry()) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 727 | // invalidate and recompute the visible regions if needed |
| 728 | flags |= Layer::eVisibleRegion; |
| 729 | } |
| 730 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 731 | if (s.sequence != mLastCommittedTxSequence) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 732 | // invalidate and recompute the visible regions if needed |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 733 | mLastCommittedTxSequence = s.sequence; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 734 | flags |= eVisibleRegion; |
| 735 | this->contentDirty = true; |
| 736 | |
| 737 | // we may use linear filtering, if the matrix scales us |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 738 | mNeedsFiltering = getActiveTransform(s).needsBilinearFiltering(); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 739 | } |
| 740 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 741 | commitTransaction(mDrawingState); |
Robert Carr | a125784 | 2020-01-31 13:48:28 -0800 | [diff] [blame] | 742 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 743 | return flags; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 744 | } |
| 745 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 746 | void Layer::commitTransaction(State&) { |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 747 | // Set the present state for all bufferlessSurfaceFramesTX to Presented. The |
| 748 | // bufferSurfaceFrameTX will be presented in latchBuffer. |
| 749 | for (auto& [token, surfaceFrame] : mDrawingState.bufferlessSurfaceFramesTX) { |
| 750 | if (surfaceFrame->getPresentState() != PresentState::Presented) { |
| 751 | // With applyPendingStates, we could end up having presented surfaceframes from previous |
| 752 | // states |
| 753 | surfaceFrame->setPresentState(PresentState::Presented); |
| 754 | mFlinger->mFrameTimeline->addSurfaceFrame(surfaceFrame); |
| 755 | } |
| 756 | } |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 757 | mDrawingState.bufferlessSurfaceFramesTX.clear(); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 758 | } |
| 759 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 760 | uint32_t Layer::getTransactionFlags(uint32_t flags) { |
Robert Carr | 38d2500 | 2021-06-11 14:30:09 -0700 | [diff] [blame] | 761 | auto ret = mTransactionFlags & flags; |
| 762 | mTransactionFlags &= ~flags; |
| 763 | return ret; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | uint32_t Layer::setTransactionFlags(uint32_t flags) { |
Robert Carr | 38d2500 | 2021-06-11 14:30:09 -0700 | [diff] [blame] | 767 | return mTransactionFlags |= flags; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 768 | } |
| 769 | |
chaviw | 214c89d | 2019-09-04 16:03:53 -0700 | [diff] [blame] | 770 | bool Layer::setPosition(float x, float y) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 771 | if (mDrawingState.transform.tx() == x && mDrawingState.transform.ty() == y) return false; |
| 772 | mDrawingState.sequence++; |
| 773 | mDrawingState.transform.set(x, y); |
Robert Carr | 69663fb | 2016-03-27 19:59:19 -0700 | [diff] [blame] | 774 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 775 | mDrawingState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 776 | setTransactionFlags(eTransactionNeeded); |
| 777 | return true; |
| 778 | } |
Robert Carr | 82364e3 | 2016-05-15 11:27:47 -0700 | [diff] [blame] | 779 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 780 | bool Layer::setChildLayer(const sp<Layer>& childLayer, int32_t z) { |
| 781 | ssize_t idx = mCurrentChildren.indexOf(childLayer); |
| 782 | if (idx < 0) { |
| 783 | return false; |
| 784 | } |
| 785 | if (childLayer->setLayer(z)) { |
| 786 | mCurrentChildren.removeAt(idx); |
| 787 | mCurrentChildren.add(childLayer); |
Robert Carr | 503d2bd | 2017-12-04 15:49:47 -0800 | [diff] [blame] | 788 | return true; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 789 | } |
Robert Carr | 503d2bd | 2017-12-04 15:49:47 -0800 | [diff] [blame] | 790 | return false; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 791 | } |
| 792 | |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 793 | bool Layer::setChildRelativeLayer(const sp<Layer>& childLayer, |
| 794 | const sp<IBinder>& relativeToHandle, int32_t relativeZ) { |
| 795 | ssize_t idx = mCurrentChildren.indexOf(childLayer); |
| 796 | if (idx < 0) { |
| 797 | return false; |
| 798 | } |
| 799 | if (childLayer->setRelativeLayer(relativeToHandle, relativeZ)) { |
| 800 | mCurrentChildren.removeAt(idx); |
| 801 | mCurrentChildren.add(childLayer); |
Robert Carr | 503d2bd | 2017-12-04 15:49:47 -0800 | [diff] [blame] | 802 | return true; |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 803 | } |
Robert Carr | 503d2bd | 2017-12-04 15:49:47 -0800 | [diff] [blame] | 804 | return false; |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 805 | } |
| 806 | |
Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 807 | bool Layer::setLayer(int32_t z) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 808 | if (mDrawingState.z == z && !usingRelativeZ(LayerVector::StateSet::Current)) return false; |
| 809 | mDrawingState.sequence++; |
| 810 | mDrawingState.z = z; |
| 811 | mDrawingState.modified = true; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 812 | |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 813 | mFlinger->mSomeChildrenChanged = true; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 814 | |
| 815 | // Discard all relative layering. |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 816 | if (mDrawingState.zOrderRelativeOf != nullptr) { |
| 817 | sp<Layer> strongRelative = mDrawingState.zOrderRelativeOf.promote(); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 818 | if (strongRelative != nullptr) { |
| 819 | strongRelative->removeZOrderRelative(this); |
| 820 | } |
chaviw | 606e5cf | 2019-03-01 10:12:10 -0800 | [diff] [blame] | 821 | setZOrderRelativeOf(nullptr); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 822 | } |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 823 | setTransactionFlags(eTransactionNeeded); |
| 824 | return true; |
| 825 | } |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 826 | |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 827 | void Layer::removeZOrderRelative(const wp<Layer>& relative) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 828 | mDrawingState.zOrderRelatives.remove(relative); |
| 829 | mDrawingState.sequence++; |
| 830 | mDrawingState.modified = true; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 831 | setTransactionFlags(eTransactionNeeded); |
| 832 | } |
| 833 | |
| 834 | void Layer::addZOrderRelative(const wp<Layer>& relative) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 835 | mDrawingState.zOrderRelatives.add(relative); |
| 836 | mDrawingState.modified = true; |
| 837 | mDrawingState.sequence++; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 838 | setTransactionFlags(eTransactionNeeded); |
| 839 | } |
| 840 | |
chaviw | 606e5cf | 2019-03-01 10:12:10 -0800 | [diff] [blame] | 841 | void Layer::setZOrderRelativeOf(const wp<Layer>& relativeOf) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 842 | mDrawingState.zOrderRelativeOf = relativeOf; |
| 843 | mDrawingState.sequence++; |
| 844 | mDrawingState.modified = true; |
| 845 | mDrawingState.isRelativeOf = relativeOf != nullptr; |
chaviw | bdb8b80 | 2019-10-14 09:17:12 -0700 | [diff] [blame] | 846 | |
chaviw | 606e5cf | 2019-03-01 10:12:10 -0800 | [diff] [blame] | 847 | setTransactionFlags(eTransactionNeeded); |
| 848 | } |
| 849 | |
Robert Carr | 503d2bd | 2017-12-04 15:49:47 -0800 | [diff] [blame] | 850 | bool Layer::setRelativeLayer(const sp<IBinder>& relativeToHandle, int32_t relativeZ) { |
Vishnu Nair | a8c7c54 | 2021-07-20 18:49:42 -0700 | [diff] [blame] | 851 | sp<Layer> relative = fromHandle(relativeToHandle).promote(); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 852 | if (relative == nullptr) { |
| 853 | return false; |
| 854 | } |
| 855 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 856 | if (mDrawingState.z == relativeZ && usingRelativeZ(LayerVector::StateSet::Current) && |
| 857 | mDrawingState.zOrderRelativeOf == relative) { |
Robert Carr | 503d2bd | 2017-12-04 15:49:47 -0800 | [diff] [blame] | 858 | return false; |
| 859 | } |
| 860 | |
Robert Carr | a70e91c | 2021-06-11 13:59:52 -0700 | [diff] [blame] | 861 | mFlinger->mSomeChildrenChanged = true; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 862 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 863 | mDrawingState.sequence++; |
| 864 | mDrawingState.modified = true; |
| 865 | mDrawingState.z = relativeZ; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 866 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 867 | auto oldZOrderRelativeOf = mDrawingState.zOrderRelativeOf.promote(); |
chaviw | 9ab4bd1 | 2017-11-03 13:11:00 -0700 | [diff] [blame] | 868 | if (oldZOrderRelativeOf != nullptr) { |
| 869 | oldZOrderRelativeOf->removeZOrderRelative(this); |
| 870 | } |
chaviw | 606e5cf | 2019-03-01 10:12:10 -0800 | [diff] [blame] | 871 | setZOrderRelativeOf(relative); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 872 | relative->addZOrderRelative(this); |
| 873 | |
| 874 | setTransactionFlags(eTransactionNeeded); |
| 875 | |
| 876 | return true; |
| 877 | } |
| 878 | |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 879 | bool Layer::setTrustedOverlay(bool isTrustedOverlay) { |
| 880 | if (mDrawingState.isTrustedOverlay == isTrustedOverlay) return false; |
| 881 | mDrawingState.isTrustedOverlay = isTrustedOverlay; |
| 882 | mDrawingState.modified = true; |
| 883 | mFlinger->mInputInfoChanged = true; |
| 884 | setTransactionFlags(eTransactionNeeded); |
| 885 | return true; |
| 886 | } |
| 887 | |
| 888 | bool Layer::isTrustedOverlay() const { |
| 889 | if (getDrawingState().isTrustedOverlay) { |
| 890 | return true; |
| 891 | } |
| 892 | const auto& p = mDrawingParent.promote(); |
| 893 | return (p != nullptr) && p->isTrustedOverlay(); |
| 894 | } |
| 895 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 896 | bool Layer::setSize(uint32_t w, uint32_t h) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 897 | if (mDrawingState.requested_legacy.w == w && mDrawingState.requested_legacy.h == h) |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 898 | return false; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 899 | mDrawingState.requested_legacy.w = w; |
| 900 | mDrawingState.requested_legacy.h = h; |
| 901 | mDrawingState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 902 | setTransactionFlags(eTransactionNeeded); |
Vishnu Nair | d01c443 | 2018-08-13 10:38:47 -0700 | [diff] [blame] | 903 | |
| 904 | // record the new size, from this point on, when the client request |
| 905 | // a buffer, it'll get the new size. |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 906 | setDefaultBufferSize(mDrawingState.requested_legacy.w, mDrawingState.requested_legacy.h); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 907 | return true; |
| 908 | } |
chaviw | 4e76553 | 2021-04-30 12:11:39 -0500 | [diff] [blame] | 909 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 910 | bool Layer::setAlpha(float alpha) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 911 | if (mDrawingState.color.a == alpha) return false; |
| 912 | mDrawingState.sequence++; |
| 913 | mDrawingState.color.a = alpha; |
| 914 | mDrawingState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 915 | setTransactionFlags(eTransactionNeeded); |
| 916 | return true; |
| 917 | } |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 918 | |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 919 | bool Layer::setBackgroundColor(const half3& color, float alpha, ui::Dataspace dataspace) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 920 | if (!mDrawingState.bgColorLayer && alpha == 0) { |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 921 | return false; |
Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 922 | } |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 923 | mDrawingState.sequence++; |
| 924 | mDrawingState.modified = true; |
Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 925 | setTransactionFlags(eTransactionNeeded); |
| 926 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 927 | if (!mDrawingState.bgColorLayer && alpha != 0) { |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 928 | // create background color layer if one does not yet exist |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 929 | uint32_t flags = ISurfaceComposerClient::eFXSurfaceEffect; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 930 | std::string name = mName + "BackgroundColorLayer"; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 931 | mDrawingState.bgColorLayer = mFlinger->getFactory().createEffectLayer( |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 932 | LayerCreationArgs(mFlinger.get(), nullptr, std::move(name), 0, 0, flags, |
| 933 | LayerMetadata())); |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 934 | |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 935 | // add to child list |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 936 | addChild(mDrawingState.bgColorLayer); |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 937 | mFlinger->mLayersAdded = true; |
| 938 | // set up SF to handle added color layer |
| 939 | if (isRemovedFromCurrentState()) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 940 | mDrawingState.bgColorLayer->onRemovedFromCurrentState(); |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 941 | } |
| 942 | mFlinger->setTransactionFlags(eTransactionNeeded); |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 943 | } else if (mDrawingState.bgColorLayer && alpha == 0) { |
| 944 | mDrawingState.bgColorLayer->reparent(nullptr); |
| 945 | mDrawingState.bgColorLayer = nullptr; |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 946 | return true; |
| 947 | } |
| 948 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 949 | mDrawingState.bgColorLayer->setColor(color); |
| 950 | mDrawingState.bgColorLayer->setLayer(std::numeric_limits<int32_t>::min()); |
| 951 | mDrawingState.bgColorLayer->setAlpha(alpha); |
| 952 | mDrawingState.bgColorLayer->setDataspace(dataspace); |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 953 | |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 954 | return true; |
| 955 | } |
| 956 | |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 957 | bool Layer::setCornerRadius(float cornerRadius) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 958 | if (mDrawingState.cornerRadius == cornerRadius) return false; |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 959 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 960 | mDrawingState.sequence++; |
| 961 | mDrawingState.cornerRadius = cornerRadius; |
| 962 | mDrawingState.modified = true; |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 963 | setTransactionFlags(eTransactionNeeded); |
| 964 | return true; |
| 965 | } |
| 966 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 967 | bool Layer::setBackgroundBlurRadius(int backgroundBlurRadius) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 968 | if (mDrawingState.backgroundBlurRadius == backgroundBlurRadius) return false; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 969 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 970 | mDrawingState.sequence++; |
| 971 | mDrawingState.backgroundBlurRadius = backgroundBlurRadius; |
| 972 | mDrawingState.modified = true; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 973 | setTransactionFlags(eTransactionNeeded); |
| 974 | return true; |
| 975 | } |
| 976 | |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 977 | bool Layer::setMatrix(const layer_state_t::matrix22_t& matrix, |
| 978 | bool allowNonRectPreservingTransforms) { |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 979 | ui::Transform t; |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 980 | t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy); |
| 981 | |
| 982 | if (!allowNonRectPreservingTransforms && !t.preserveRects()) { |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 983 | ALOGW("Attempt to set rotation matrix without permission ACCESS_SURFACE_FLINGER nor " |
| 984 | "ROTATE_SURFACE_FLINGER ignored"); |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 985 | return false; |
| 986 | } |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 987 | mDrawingState.sequence++; |
| 988 | mDrawingState.transform.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy); |
| 989 | mDrawingState.modified = true; |
| 990 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 991 | setTransactionFlags(eTransactionNeeded); |
| 992 | return true; |
| 993 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 994 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 995 | bool Layer::setTransparentRegionHint(const Region& transparent) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 996 | mDrawingState.requestedTransparentRegion_legacy = transparent; |
| 997 | mDrawingState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 998 | setTransactionFlags(eTransactionNeeded); |
| 999 | return true; |
| 1000 | } |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 1001 | |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 1002 | bool Layer::setBlurRegions(const std::vector<BlurRegion>& blurRegions) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1003 | mDrawingState.blurRegions = blurRegions; |
| 1004 | mDrawingState.modified = true; |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 1005 | setTransactionFlags(eTransactionNeeded); |
| 1006 | return true; |
| 1007 | } |
| 1008 | |
Vishnu Nair | f6eddb6 | 2021-01-27 22:02:11 -0800 | [diff] [blame] | 1009 | bool Layer::setFlags(uint32_t flags, uint32_t mask) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1010 | const uint32_t newFlags = (mDrawingState.flags & ~mask) | (flags & mask); |
| 1011 | if (mDrawingState.flags == newFlags) return false; |
| 1012 | mDrawingState.sequence++; |
| 1013 | mDrawingState.flags = newFlags; |
| 1014 | mDrawingState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1015 | setTransactionFlags(eTransactionNeeded); |
| 1016 | return true; |
| 1017 | } |
Robert Carr | 99e27f0 | 2016-06-16 15:18:02 -0700 | [diff] [blame] | 1018 | |
chaviw | 2571450 | 2021-02-11 10:01:08 -0800 | [diff] [blame] | 1019 | bool Layer::setCrop(const Rect& crop) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1020 | if (mDrawingState.requestedCrop == crop) return false; |
| 1021 | mDrawingState.sequence++; |
| 1022 | mDrawingState.requestedCrop = crop; |
| 1023 | mDrawingState.crop = crop; |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 1024 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1025 | mDrawingState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1026 | setTransactionFlags(eTransactionNeeded); |
| 1027 | return true; |
| 1028 | } |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 1029 | |
Evan Rosky | ef876c9 | 2019-01-25 17:46:06 -0800 | [diff] [blame] | 1030 | bool Layer::setMetadata(const LayerMetadata& data) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1031 | if (!mDrawingState.metadata.merge(data, true /* eraseEmpty */)) return false; |
| 1032 | mDrawingState.modified = true; |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 1033 | setTransactionFlags(eTransactionNeeded); |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 1034 | return true; |
Daniel Nicoara | 2f5f8a5 | 2016-12-20 16:11:58 -0500 | [diff] [blame] | 1035 | } |
| 1036 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1037 | bool Layer::setLayerStack(uint32_t layerStack) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1038 | if (mDrawingState.layerStack == layerStack) return false; |
| 1039 | mDrawingState.sequence++; |
| 1040 | mDrawingState.layerStack = layerStack; |
| 1041 | mDrawingState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1042 | setTransactionFlags(eTransactionNeeded); |
| 1043 | return true; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1044 | } |
| 1045 | |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 1046 | bool Layer::setColorSpaceAgnostic(const bool agnostic) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1047 | if (mDrawingState.colorSpaceAgnostic == agnostic) { |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 1048 | return false; |
| 1049 | } |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1050 | mDrawingState.sequence++; |
| 1051 | mDrawingState.colorSpaceAgnostic = agnostic; |
| 1052 | mDrawingState.modified = true; |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 1053 | setTransactionFlags(eTransactionNeeded); |
| 1054 | return true; |
| 1055 | } |
| 1056 | |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 1057 | bool Layer::setFrameRateSelectionPriority(int32_t priority) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1058 | if (mDrawingState.frameRateSelectionPriority == priority) return false; |
| 1059 | mDrawingState.frameRateSelectionPriority = priority; |
| 1060 | mDrawingState.sequence++; |
| 1061 | mDrawingState.modified = true; |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 1062 | setTransactionFlags(eTransactionNeeded); |
| 1063 | return true; |
| 1064 | } |
| 1065 | |
| 1066 | int32_t Layer::getFrameRateSelectionPriority() const { |
| 1067 | // Check if layer has priority set. |
| 1068 | if (mDrawingState.frameRateSelectionPriority != PRIORITY_UNSET) { |
Rajat Yadav | 70b5c42 | 2021-04-08 17:45:47 +0530 | [diff] [blame] | 1069 | mPriority = mDrawingState.frameRateSelectionPriority; |
| 1070 | return mPriority; |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 1071 | } |
| 1072 | // If not, search whether its parents have it set. |
| 1073 | sp<Layer> parent = getParent(); |
| 1074 | if (parent != nullptr) { |
Rajat Yadav | 70b5c42 | 2021-04-08 17:45:47 +0530 | [diff] [blame] | 1075 | mPriority = parent->getFrameRateSelectionPriority(); |
| 1076 | return mPriority; |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | return Layer::PRIORITY_UNSET; |
| 1080 | } |
| 1081 | |
Rajat Yadav | 70b5c42 | 2021-04-08 17:45:47 +0530 | [diff] [blame] | 1082 | int32_t Layer::getPriority() { |
| 1083 | return mPriority; |
| 1084 | } |
| 1085 | |
Ady Abraham | aae5ed5 | 2020-06-26 09:32:43 -0700 | [diff] [blame] | 1086 | bool Layer::isLayerFocusedBasedOnPriority(int32_t priority) { |
| 1087 | return priority == PRIORITY_FOCUSED_WITH_MODE || priority == PRIORITY_FOCUSED_WITHOUT_MODE; |
| 1088 | }; |
| 1089 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1090 | uint32_t Layer::getLayerStack() const { |
Chia-I Wu | e41dbe6 | 2017-06-13 14:10:56 -0700 | [diff] [blame] | 1091 | auto p = mDrawingParent.promote(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1092 | if (p == nullptr) { |
| 1093 | return getDrawingState().layerStack; |
| 1094 | } |
| 1095 | return p->getLayerStack(); |
| 1096 | } |
| 1097 | |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 1098 | bool Layer::setShadowRadius(float shadowRadius) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1099 | if (mDrawingState.shadowRadius == shadowRadius) { |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 1100 | return false; |
| 1101 | } |
| 1102 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1103 | mDrawingState.sequence++; |
| 1104 | mDrawingState.shadowRadius = shadowRadius; |
| 1105 | mDrawingState.modified = true; |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 1106 | setTransactionFlags(eTransactionNeeded); |
| 1107 | return true; |
| 1108 | } |
| 1109 | |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 1110 | bool Layer::setFixedTransformHint(ui::Transform::RotationFlags fixedTransformHint) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1111 | if (mDrawingState.fixedTransformHint == fixedTransformHint) { |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 1112 | return false; |
| 1113 | } |
| 1114 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1115 | mDrawingState.sequence++; |
| 1116 | mDrawingState.fixedTransformHint = fixedTransformHint; |
| 1117 | mDrawingState.modified = true; |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 1118 | setTransactionFlags(eTransactionNeeded); |
| 1119 | return true; |
| 1120 | } |
| 1121 | |
John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 1122 | bool Layer::setStretchEffect(const StretchEffect& effect) { |
| 1123 | StretchEffect temp = effect; |
| 1124 | temp.sanitize(); |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1125 | if (mDrawingState.stretchEffect == temp) { |
John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 1126 | return false; |
| 1127 | } |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1128 | mDrawingState.sequence++; |
| 1129 | mDrawingState.stretchEffect = temp; |
| 1130 | mDrawingState.modified = true; |
John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 1131 | setTransactionFlags(eTransactionNeeded); |
| 1132 | return true; |
| 1133 | } |
| 1134 | |
John Reck | c00c669 | 2021-02-16 11:37:33 -0500 | [diff] [blame] | 1135 | StretchEffect Layer::getStretchEffect() const { |
| 1136 | if (mDrawingState.stretchEffect.hasEffect()) { |
| 1137 | return mDrawingState.stretchEffect; |
| 1138 | } |
| 1139 | |
| 1140 | sp<Layer> parent = getParent(); |
| 1141 | if (parent != nullptr) { |
| 1142 | auto effect = parent->getStretchEffect(); |
| 1143 | if (effect.hasEffect()) { |
| 1144 | // TODO(b/179047472): Map it? Or do we make the effect be in global space? |
| 1145 | return effect; |
| 1146 | } |
| 1147 | } |
| 1148 | return StretchEffect{}; |
| 1149 | } |
| 1150 | |
Ady Abraham | a850c18 | 2021-08-04 13:04:37 -0700 | [diff] [blame] | 1151 | bool Layer::propagateFrameRateForLayerTree(FrameRate parentFrameRate, bool* transactionNeeded) { |
| 1152 | // The frame rate for layer tree is this layer's frame rate if present, or the parent frame rate |
| 1153 | const auto frameRate = [&] { |
| 1154 | if (mDrawingState.frameRate.rate.isValid() || |
| 1155 | mDrawingState.frameRate.type == FrameRateCompatibility::NoVote) { |
| 1156 | return mDrawingState.frameRate; |
| 1157 | } |
| 1158 | |
| 1159 | return parentFrameRate; |
| 1160 | }(); |
| 1161 | |
| 1162 | *transactionNeeded |= setFrameRateForLayerTree(frameRate); |
| 1163 | |
| 1164 | // The frame rate is propagated to the children |
| 1165 | bool childrenHaveFrameRate = false; |
| 1166 | for (const sp<Layer>& child : mCurrentChildren) { |
| 1167 | childrenHaveFrameRate |= |
| 1168 | child->propagateFrameRateForLayerTree(frameRate, transactionNeeded); |
| 1169 | } |
| 1170 | |
| 1171 | // If we don't have a valid frame rate, but the children do, we set this |
| 1172 | // layer as NoVote to allow the children to control the refresh rate |
| 1173 | if (!frameRate.rate.isValid() && frameRate.type != FrameRateCompatibility::NoVote && |
| 1174 | childrenHaveFrameRate) { |
| 1175 | *transactionNeeded |= |
| 1176 | setFrameRateForLayerTree(FrameRate(Fps(0.0f), FrameRateCompatibility::NoVote)); |
| 1177 | } |
| 1178 | |
| 1179 | // We return whether this layer ot its children has a vote. We ignore ExactOrMultiple votes for |
| 1180 | // the same reason we are allowing touch boost for those layers. See |
| 1181 | // RefreshRateConfigs::getBestRefreshRate for more details. |
| 1182 | const auto layerVotedWithDefaultCompatibility = |
| 1183 | frameRate.rate.isValid() && frameRate.type == FrameRateCompatibility::Default; |
| 1184 | const auto layerVotedWithNoVote = frameRate.type == FrameRateCompatibility::NoVote; |
| 1185 | const auto layerVotedWithExactCompatibility = |
| 1186 | frameRate.rate.isValid() && frameRate.type == FrameRateCompatibility::Exact; |
| 1187 | return layerVotedWithDefaultCompatibility || layerVotedWithNoVote || |
| 1188 | layerVotedWithExactCompatibility || childrenHaveFrameRate; |
| 1189 | } |
| 1190 | |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1191 | void Layer::updateTreeHasFrameRateVote() { |
Ady Abraham | a850c18 | 2021-08-04 13:04:37 -0700 | [diff] [blame] | 1192 | const auto root = [&]() -> sp<Layer> { |
| 1193 | sp<Layer> layer = this; |
| 1194 | while (auto parent = layer->getParent()) { |
| 1195 | layer = parent; |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1196 | } |
Ady Abraham | a850c18 | 2021-08-04 13:04:37 -0700 | [diff] [blame] | 1197 | return layer; |
| 1198 | }(); |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1199 | |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1200 | bool transactionNeeded = false; |
Ady Abraham | a850c18 | 2021-08-04 13:04:37 -0700 | [diff] [blame] | 1201 | root->propagateFrameRateForLayerTree({}, &transactionNeeded); |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1202 | |
Ady Abraham | a850c18 | 2021-08-04 13:04:37 -0700 | [diff] [blame] | 1203 | // TODO(b/195668952): we probably don't need eTraversalNeeded here |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1204 | if (transactionNeeded) { |
| 1205 | mFlinger->setTransactionFlags(eTraversalNeeded); |
| 1206 | } |
| 1207 | } |
| 1208 | |
Ady Abraham | 71c437d | 2020-01-31 15:56:57 -0800 | [diff] [blame] | 1209 | bool Layer::setFrameRate(FrameRate frameRate) { |
Ana Krulec | 3803b8d | 2020-02-03 16:35:46 -0800 | [diff] [blame] | 1210 | if (!mFlinger->useFrameRateApi) { |
| 1211 | return false; |
| 1212 | } |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1213 | if (mDrawingState.frameRate == frameRate) { |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 1214 | return false; |
| 1215 | } |
| 1216 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1217 | mDrawingState.sequence++; |
| 1218 | mDrawingState.frameRate = frameRate; |
| 1219 | mDrawingState.modified = true; |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1220 | |
| 1221 | updateTreeHasFrameRateVote(); |
| 1222 | |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 1223 | setTransactionFlags(eTransactionNeeded); |
| 1224 | return true; |
| 1225 | } |
| 1226 | |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1227 | void Layer::setFrameTimelineVsyncForBufferTransaction(const FrameTimelineInfo& info, |
| 1228 | nsecs_t postTime) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1229 | mDrawingState.postTime = postTime; |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1230 | |
| 1231 | // Check if one of the bufferlessSurfaceFramesTX contains the same vsyncId. This can happen if |
| 1232 | // there are two transactions with the same token, the first one without a buffer and the |
| 1233 | // second one with a buffer. We promote the bufferlessSurfaceFrame to a bufferSurfaceFrameTX |
| 1234 | // in that case. |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1235 | auto it = mDrawingState.bufferlessSurfaceFramesTX.find(info.vsyncId); |
| 1236 | if (it != mDrawingState.bufferlessSurfaceFramesTX.end()) { |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1237 | // Promote the bufferlessSurfaceFrame to a bufferSurfaceFrameTX |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1238 | mDrawingState.bufferSurfaceFrameTX = it->second; |
| 1239 | mDrawingState.bufferlessSurfaceFramesTX.erase(it); |
| 1240 | mDrawingState.bufferSurfaceFrameTX->promoteToBuffer(); |
| 1241 | mDrawingState.bufferSurfaceFrameTX->setActualQueueTime(postTime); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1242 | } else { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1243 | mDrawingState.bufferSurfaceFrameTX = |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1244 | createSurfaceFrameForBuffer(info, postTime, mTransactionName); |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | void Layer::setFrameTimelineVsyncForBufferlessTransaction(const FrameTimelineInfo& info, |
| 1249 | nsecs_t postTime) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1250 | mDrawingState.frameTimelineInfo = info; |
| 1251 | mDrawingState.postTime = postTime; |
| 1252 | mDrawingState.modified = true; |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 1253 | setTransactionFlags(eTransactionNeeded); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1254 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1255 | if (const auto& bufferSurfaceFrameTX = mDrawingState.bufferSurfaceFrameTX; |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1256 | bufferSurfaceFrameTX != nullptr) { |
| 1257 | if (bufferSurfaceFrameTX->getToken() == info.vsyncId) { |
| 1258 | // BufferSurfaceFrame takes precedence over BufferlessSurfaceFrame. If the same token is |
| 1259 | // being used for BufferSurfaceFrame, don't create a new one. |
| 1260 | return; |
| 1261 | } |
| 1262 | } |
| 1263 | // For Transactions without a buffer, we create only one SurfaceFrame per vsyncId. If multiple |
| 1264 | // transactions use the same vsyncId, we just treat them as one SurfaceFrame (unless they are |
| 1265 | // targeting different vsyncs). |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1266 | auto it = mDrawingState.bufferlessSurfaceFramesTX.find(info.vsyncId); |
| 1267 | if (it == mDrawingState.bufferlessSurfaceFramesTX.end()) { |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1268 | auto surfaceFrame = createSurfaceFrameForTransaction(info, postTime); |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1269 | mDrawingState.bufferlessSurfaceFramesTX[info.vsyncId] = surfaceFrame; |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1270 | } else { |
| 1271 | if (it->second->getPresentState() == PresentState::Presented) { |
| 1272 | // If the SurfaceFrame was already presented, its safe to overwrite it since it must |
| 1273 | // have been from previous vsync. |
| 1274 | it->second = createSurfaceFrameForTransaction(info, postTime); |
| 1275 | } |
| 1276 | } |
| 1277 | } |
| 1278 | |
| 1279 | void Layer::addSurfaceFrameDroppedForBuffer( |
| 1280 | std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame) { |
Adithya Srinivasan | 061c14c | 2021-02-11 01:19:47 +0000 | [diff] [blame] | 1281 | surfaceFrame->setDropTime(systemTime()); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1282 | surfaceFrame->setPresentState(PresentState::Dropped); |
| 1283 | mFlinger->mFrameTimeline->addSurfaceFrame(surfaceFrame); |
| 1284 | } |
| 1285 | |
| 1286 | void Layer::addSurfaceFramePresentedForBuffer( |
| 1287 | std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame, nsecs_t acquireFenceTime, |
| 1288 | nsecs_t currentLatchTime) { |
| 1289 | surfaceFrame->setAcquireFenceTime(acquireFenceTime); |
| 1290 | surfaceFrame->setPresentState(PresentState::Presented, mLastLatchTime); |
| 1291 | mFlinger->mFrameTimeline->addSurfaceFrame(surfaceFrame); |
| 1292 | mLastLatchTime = currentLatchTime; |
| 1293 | } |
| 1294 | |
| 1295 | std::shared_ptr<frametimeline::SurfaceFrame> Layer::createSurfaceFrameForTransaction( |
| 1296 | const FrameTimelineInfo& info, nsecs_t postTime) { |
| 1297 | auto surfaceFrame = |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1298 | mFlinger->mFrameTimeline->createSurfaceFrameForToken(info, mOwnerPid, mOwnerUid, |
| 1299 | getSequence(), mName, |
Adithya Srinivasan | 785addd | 2021-03-09 00:38:00 +0000 | [diff] [blame] | 1300 | mTransactionName, |
Adithya Srinivasan | 58069dc | 2021-06-04 20:37:02 +0000 | [diff] [blame] | 1301 | /*isBuffer*/ false, getGameMode()); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1302 | // For Transactions, the post time is considered to be both queue and acquire fence time. |
| 1303 | surfaceFrame->setActualQueueTime(postTime); |
| 1304 | surfaceFrame->setAcquireFenceTime(postTime); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 1305 | const auto fps = mFlinger->mScheduler->getFrameRateOverride(getOwnerUid()); |
| 1306 | if (fps) { |
Alec Mouri | 819f630 | 2021-02-12 15:37:21 -0800 | [diff] [blame] | 1307 | surfaceFrame->setRenderRate(*fps); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 1308 | } |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1309 | onSurfaceFrameCreated(surfaceFrame); |
| 1310 | return surfaceFrame; |
| 1311 | } |
| 1312 | |
| 1313 | std::shared_ptr<frametimeline::SurfaceFrame> Layer::createSurfaceFrameForBuffer( |
| 1314 | const FrameTimelineInfo& info, nsecs_t queueTime, std::string debugName) { |
| 1315 | auto surfaceFrame = |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1316 | mFlinger->mFrameTimeline->createSurfaceFrameForToken(info, mOwnerPid, mOwnerUid, |
Adithya Srinivasan | 785addd | 2021-03-09 00:38:00 +0000 | [diff] [blame] | 1317 | getSequence(), mName, debugName, |
Adithya Srinivasan | 58069dc | 2021-06-04 20:37:02 +0000 | [diff] [blame] | 1318 | /*isBuffer*/ true, getGameMode()); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1319 | // For buffers, acquire fence time will set during latch. |
| 1320 | surfaceFrame->setActualQueueTime(queueTime); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 1321 | const auto fps = mFlinger->mScheduler->getFrameRateOverride(getOwnerUid()); |
| 1322 | if (fps) { |
Alec Mouri | 819f630 | 2021-02-12 15:37:21 -0800 | [diff] [blame] | 1323 | surfaceFrame->setRenderRate(*fps); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 1324 | } |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1325 | // TODO(b/178542907): Implement onSurfaceFrameCreated for BQLayer as well. |
| 1326 | onSurfaceFrameCreated(surfaceFrame); |
| 1327 | return surfaceFrame; |
Ady Abraham | 74e1756 | 2020-08-24 18:18:19 -0700 | [diff] [blame] | 1328 | } |
| 1329 | |
Ady Abraham | a850c18 | 2021-08-04 13:04:37 -0700 | [diff] [blame] | 1330 | bool Layer::setFrameRateForLayerTree(FrameRate frameRate) { |
| 1331 | if (mDrawingState.frameRateForLayerTree == frameRate) { |
| 1332 | return false; |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1333 | } |
| 1334 | |
Ady Abraham | a850c18 | 2021-08-04 13:04:37 -0700 | [diff] [blame] | 1335 | mDrawingState.frameRateForLayerTree = frameRate; |
Ady Abraham | f467f89 | 2020-07-31 16:01:53 -0700 | [diff] [blame] | 1336 | |
Ady Abraham | a850c18 | 2021-08-04 13:04:37 -0700 | [diff] [blame] | 1337 | // TODO(b/195668952): we probably don't need to dirty visible regions here |
| 1338 | // or even store frameRateForLayerTree in mDrawingState |
| 1339 | mDrawingState.sequence++; |
| 1340 | mDrawingState.modified = true; |
| 1341 | setTransactionFlags(eTransactionNeeded); |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1342 | |
Ady Abraham | a850c18 | 2021-08-04 13:04:37 -0700 | [diff] [blame] | 1343 | mFlinger->mScheduler->recordLayerHistory(this, systemTime(), |
| 1344 | LayerHistory::LayerUpdateType::SetFrameRate); |
| 1345 | |
| 1346 | return true; |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 1347 | } |
| 1348 | |
Ady Abraham | 59fd8ff | 2021-04-15 20:13:30 -0700 | [diff] [blame] | 1349 | Layer::FrameRate Layer::getFrameRateForLayerTree() const { |
| 1350 | return getDrawingState().frameRateForLayerTree; |
| 1351 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1352 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1353 | bool Layer::isHiddenByPolicy() const { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1354 | const State& s(mDrawingState); |
Chia-I Wu | e41dbe6 | 2017-06-13 14:10:56 -0700 | [diff] [blame] | 1355 | const auto& parent = mDrawingParent.promote(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1356 | if (parent != nullptr && parent->isHiddenByPolicy()) { |
| 1357 | return true; |
| 1358 | } |
Robert Carr | 1c5481e | 2019-07-01 14:42:27 -0700 | [diff] [blame] | 1359 | if (usingRelativeZ(LayerVector::StateSet::Drawing)) { |
| 1360 | auto zOrderRelativeOf = mDrawingState.zOrderRelativeOf.promote(); |
| 1361 | if (zOrderRelativeOf != nullptr) { |
| 1362 | if (zOrderRelativeOf->isHiddenByPolicy()) { |
| 1363 | return true; |
| 1364 | } |
| 1365 | } |
| 1366 | } |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1367 | return s.flags & layer_state_t::eLayerHidden; |
| 1368 | } |
| 1369 | |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 1370 | uint32_t Layer::getEffectiveUsage(uint32_t usage) const { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1371 | // TODO: should we do something special if mSecure is set? |
| 1372 | if (mProtectedByApp) { |
| 1373 | // need a hardware-protected path to external video sink |
| 1374 | usage |= GraphicBuffer::USAGE_PROTECTED; |
Jamie Gennis | 54cc83e | 2010-11-02 11:51:32 -0700 | [diff] [blame] | 1375 | } |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 1376 | if (mPotentialCursor) { |
| 1377 | usage |= GraphicBuffer::USAGE_CURSOR; |
| 1378 | } |
Jamie Gennis | 3599bf2 | 2011-08-10 11:48:07 -0700 | [diff] [blame] | 1379 | usage |= GraphicBuffer::USAGE_HW_COMPOSER; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1380 | return usage; |
Mathias Agopian | b5b7f26 | 2010-05-07 15:58:44 -0700 | [diff] [blame] | 1381 | } |
| 1382 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 1383 | void Layer::updateTransformHint(ui::Transform::RotationFlags transformHint) { |
| 1384 | if (mFlinger->mDebugDisableTransformHint || transformHint & ui::Transform::ROT_INVALID) { |
| 1385 | transformHint = ui::Transform::ROT_0; |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 1386 | } |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 1387 | |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 1388 | setTransformHint(transformHint); |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 1389 | } |
| 1390 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1391 | // ---------------------------------------------------------------------------- |
| 1392 | // debugging |
| 1393 | // ---------------------------------------------------------------------------- |
| 1394 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1395 | // TODO(marissaw): add new layer state info to layer debugging |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 1396 | LayerDebugInfo Layer::getLayerDebugInfo(const DisplayDevice* display) const { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 1397 | using namespace std::string_literals; |
| 1398 | |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1399 | LayerDebugInfo info; |
Alec Mouri | b416efd | 2018-09-06 21:01:59 +0000 | [diff] [blame] | 1400 | const State& ds = getDrawingState(); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1401 | info.mName = getName(); |
Vishnu Nair | 43bccf8 | 2020-06-05 10:53:37 -0700 | [diff] [blame] | 1402 | sp<Layer> parent = mDrawingParent.promote(); |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 1403 | info.mParentName = parent ? parent->getName() : "none"s; |
chaviw | 8a01fa4 | 2019-08-19 12:39:31 -0700 | [diff] [blame] | 1404 | info.mType = getType(); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1405 | info.mTransparentRegion = ds.activeTransparentRegion_legacy; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 1406 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 1407 | info.mVisibleRegion = getVisibleRegion(display); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1408 | info.mSurfaceDamageRegion = surfaceDamageRegion; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1409 | info.mLayerStack = getLayerStack(); |
chaviw | 4e76553 | 2021-04-30 12:11:39 -0500 | [diff] [blame] | 1410 | info.mX = ds.transform.tx(); |
| 1411 | info.mY = ds.transform.ty(); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1412 | info.mZ = ds.z; |
chaviw | 4e76553 | 2021-04-30 12:11:39 -0500 | [diff] [blame] | 1413 | info.mWidth = ds.width; |
| 1414 | info.mHeight = ds.height; |
chaviw | 2571450 | 2021-02-11 10:01:08 -0800 | [diff] [blame] | 1415 | info.mCrop = ds.crop; |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 1416 | info.mColor = ds.color; |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1417 | info.mFlags = ds.flags; |
| 1418 | info.mPixelFormat = getPixelFormat(); |
chaviw | 4244e03 | 2019-09-04 11:27:49 -0700 | [diff] [blame] | 1419 | info.mDataSpace = static_cast<android_dataspace>(getDataSpace()); |
chaviw | 4e76553 | 2021-04-30 12:11:39 -0500 | [diff] [blame] | 1420 | info.mMatrix[0][0] = ds.transform[0][0]; |
| 1421 | info.mMatrix[0][1] = ds.transform[0][1]; |
| 1422 | info.mMatrix[1][0] = ds.transform[1][0]; |
| 1423 | info.mMatrix[1][1] = ds.transform[1][1]; |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1424 | { |
chaviw | d62d306 | 2019-09-04 14:48:02 -0700 | [diff] [blame] | 1425 | sp<const GraphicBuffer> buffer = getBuffer(); |
David Sodman | 5b4cffc | 2017-11-23 13:20:29 -0800 | [diff] [blame] | 1426 | if (buffer != 0) { |
| 1427 | info.mActiveBufferWidth = buffer->getWidth(); |
| 1428 | info.mActiveBufferHeight = buffer->getHeight(); |
| 1429 | info.mActiveBufferStride = buffer->getStride(); |
| 1430 | info.mActiveBufferFormat = buffer->format; |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1431 | } else { |
| 1432 | info.mActiveBufferWidth = 0; |
| 1433 | info.mActiveBufferHeight = 0; |
| 1434 | info.mActiveBufferStride = 0; |
| 1435 | info.mActiveBufferFormat = 0; |
| 1436 | } |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1437 | } |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1438 | info.mNumQueuedFrames = getQueuedFrameCount(); |
| 1439 | info.mRefreshPending = isBufferLatched(); |
| 1440 | info.mIsOpaque = isOpaque(ds); |
| 1441 | info.mContentDirty = contentDirty; |
John Reck | c00c669 | 2021-02-16 11:37:33 -0500 | [diff] [blame] | 1442 | info.mStretchEffect = getStretchEffect(); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1443 | return info; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1444 | } |
Chia-I Wu | 83ce7c1 | 2017-10-19 15:18:55 -0700 | [diff] [blame] | 1445 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1446 | void Layer::miniDumpHeader(std::string& result) { |
Marin Shalamanov | 1876e2e | 2020-12-04 13:23:59 +0100 | [diff] [blame] | 1447 | result.append(kDumpTableRowLength, '-'); |
| 1448 | result.append("\n"); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1449 | result.append(" Layer name\n"); |
| 1450 | result.append(" Z | "); |
Ady Abraham | 8f1ee7f | 2019-04-05 10:32:50 -0700 | [diff] [blame] | 1451 | result.append(" Window Type | "); |
Ray Zhang | 49d5d0d | 2020-03-27 19:53:33 +0800 | [diff] [blame] | 1452 | result.append(" Layer Class | "); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1453 | result.append(" Comp Type | "); |
Yichi Chen | 6ca3519 | 2018-05-29 12:20:43 +0800 | [diff] [blame] | 1454 | result.append(" Transform | "); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1455 | result.append(" Disp Frame (LTRB) | "); |
Ady Abraham | be23e6a | 2020-05-04 14:51:16 -0700 | [diff] [blame] | 1456 | result.append(" Source Crop (LTRB) | "); |
Marin Shalamanov | 1876e2e | 2020-12-04 13:23:59 +0100 | [diff] [blame] | 1457 | result.append(" Frame Rate (Explicit) (Seamlessness) [Focused]\n"); |
| 1458 | result.append(kDumpTableRowLength, '-'); |
| 1459 | result.append("\n"); |
Ady Abraham | be23e6a | 2020-05-04 14:51:16 -0700 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | std::string Layer::frameRateCompatibilityString(Layer::FrameRateCompatibility compatibility) { |
| 1463 | switch (compatibility) { |
| 1464 | case FrameRateCompatibility::Default: |
| 1465 | return "Default"; |
| 1466 | case FrameRateCompatibility::ExactOrMultiple: |
| 1467 | return "ExactOrMultiple"; |
| 1468 | case FrameRateCompatibility::NoVote: |
| 1469 | return "NoVote"; |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 1470 | case FrameRateCompatibility::Exact: |
| 1471 | return "Exact"; |
Ady Abraham | be23e6a | 2020-05-04 14:51:16 -0700 | [diff] [blame] | 1472 | } |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1473 | } |
| 1474 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 1475 | void Layer::miniDump(std::string& result, const DisplayDevice& display) const { |
| 1476 | const auto outputLayer = findOutputLayerForDisplay(&display); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 1477 | if (!outputLayer) { |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1478 | return; |
| 1479 | } |
| 1480 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1481 | std::string name; |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1482 | if (mName.length() > 77) { |
| 1483 | std::string shortened; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 1484 | shortened.append(mName, 0, 36); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1485 | shortened.append("[...]"); |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 1486 | shortened.append(mName, mName.length() - 36); |
| 1487 | name = std::move(shortened); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1488 | } else { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 1489 | name = mName; |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1490 | } |
| 1491 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1492 | StringAppendF(&result, " %s\n", name.c_str()); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1493 | |
Alec Mouri | b416efd | 2018-09-06 21:01:59 +0000 | [diff] [blame] | 1494 | const State& layerState(getDrawingState()); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1495 | const auto& outputLayerState = outputLayer->getState(); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 1496 | |
Chia-I Wu | 1e04361 | 2018-03-01 09:45:09 -0800 | [diff] [blame] | 1497 | if (layerState.zOrderRelativeOf != nullptr || mDrawingParent != nullptr) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1498 | StringAppendF(&result, " rel %6d | ", layerState.z); |
Chia-I Wu | 1e04361 | 2018-03-01 09:45:09 -0800 | [diff] [blame] | 1499 | } else { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1500 | StringAppendF(&result, " %10d | ", layerState.z); |
Chia-I Wu | 1e04361 | 2018-03-01 09:45:09 -0800 | [diff] [blame] | 1501 | } |
Ady Abraham | 8f1ee7f | 2019-04-05 10:32:50 -0700 | [diff] [blame] | 1502 | StringAppendF(&result, " %10d | ", mWindowType); |
Ray Zhang | 49d5d0d | 2020-03-27 19:53:33 +0800 | [diff] [blame] | 1503 | StringAppendF(&result, " %10d | ", mLayerClass); |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 1504 | StringAppendF(&result, "%10s | ", toString(getCompositionType(display)).c_str()); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1505 | StringAppendF(&result, "%10s | ", toString(outputLayerState.bufferTransform).c_str()); |
| 1506 | const Rect& frame = outputLayerState.displayFrame; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1507 | 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] | 1508 | const FloatRect& crop = outputLayerState.sourceCrop; |
Ady Abraham | be23e6a | 2020-05-04 14:51:16 -0700 | [diff] [blame] | 1509 | 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] | 1510 | crop.bottom); |
Ady Abraham | f467f89 | 2020-07-31 16:01:53 -0700 | [diff] [blame] | 1511 | const auto frameRate = getFrameRateForLayerTree(); |
| 1512 | if (frameRate.rate.isValid() || frameRate.type != FrameRateCompatibility::Default) { |
| 1513 | StringAppendF(&result, "%s %15s %17s", to_string(frameRate.rate).c_str(), |
| 1514 | frameRateCompatibilityString(frameRate.type).c_str(), |
| 1515 | toString(frameRate.seamlessness).c_str()); |
Ady Abraham | be23e6a | 2020-05-04 14:51:16 -0700 | [diff] [blame] | 1516 | } else { |
Marin Shalamanov | 1876e2e | 2020-12-04 13:23:59 +0100 | [diff] [blame] | 1517 | result.append(41, ' '); |
Ady Abraham | be23e6a | 2020-05-04 14:51:16 -0700 | [diff] [blame] | 1518 | } |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1519 | |
Ady Abraham | aae5ed5 | 2020-06-26 09:32:43 -0700 | [diff] [blame] | 1520 | const auto focused = isLayerFocusedBasedOnPriority(getFrameRateSelectionPriority()); |
| 1521 | StringAppendF(&result, " [%s]\n", focused ? "*" : " "); |
| 1522 | |
Marin Shalamanov | 1876e2e | 2020-12-04 13:23:59 +0100 | [diff] [blame] | 1523 | result.append(kDumpTableRowLength, '-'); |
| 1524 | result.append("\n"); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1525 | } |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1526 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1527 | void Layer::dumpFrameStats(std::string& result) const { |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 1528 | mFrameTracker.dumpStats(result); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1529 | } |
| 1530 | |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 1531 | void Layer::clearFrameStats() { |
| 1532 | mFrameTracker.clearStats(); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1533 | } |
| 1534 | |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 1535 | void Layer::logFrameStats() { |
| 1536 | mFrameTracker.logAndResetStats(mName); |
| 1537 | } |
| 1538 | |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 1539 | void Layer::getFrameStats(FrameStats* outStats) const { |
| 1540 | mFrameTracker.getStats(outStats); |
| 1541 | } |
| 1542 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1543 | void Layer::dumpFrameEvents(std::string& result) { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 1544 | StringAppendF(&result, "- Layer %s (%s, %p)\n", getName().c_str(), getType(), this); |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 1545 | Mutex::Autolock lock(mFrameEventHistoryMutex); |
| 1546 | mFrameEventHistory.checkFencesForCompletion(); |
| 1547 | mFrameEventHistory.dump(result); |
| 1548 | } |
Pablo Ceballos | 40845df | 2016-01-25 17:41:15 -0800 | [diff] [blame] | 1549 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 1550 | void Layer::dumpCallingUidPid(std::string& result) const { |
chaviw | 250bcbb | 2020-08-05 11:17:54 -0700 | [diff] [blame] | 1551 | StringAppendF(&result, "Layer %s (%s) callingPid:%d callingUid:%d ownerUid:%d\n", |
| 1552 | getName().c_str(), getType(), mCallingPid, mCallingUid, mOwnerUid); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 1553 | } |
| 1554 | |
Brian Anderson | 5ea5e59 | 2016-12-01 16:54:33 -0800 | [diff] [blame] | 1555 | void Layer::onDisconnect() { |
| 1556 | Mutex::Autolock lock(mFrameEventHistoryMutex); |
| 1557 | mFrameEventHistory.onDisconnect(); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 1558 | const int32_t layerId = getSequence(); |
| 1559 | mFlinger->mTimeStats->onDestroy(layerId); |
| 1560 | mFlinger->mFrameTracer->onDestroy(layerId); |
Brian Anderson | 5ea5e59 | 2016-12-01 16:54:33 -0800 | [diff] [blame] | 1561 | } |
| 1562 | |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1563 | void Layer::addAndGetFrameTimestamps(const NewFrameEventsEntry* newTimestamps, |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 1564 | FrameEventHistoryDelta* outDelta) { |
Yiwei Zhang | faf3ded | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 1565 | if (newTimestamps) { |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 1566 | mFlinger->mTimeStats->setPostTime(getSequence(), newTimestamps->frameNumber, |
Adithya Srinivasan | 58069dc | 2021-06-04 20:37:02 +0000 | [diff] [blame] | 1567 | getName().c_str(), mOwnerUid, newTimestamps->postedTime, |
| 1568 | getGameMode()); |
Yiwei Zhang | 487340f | 2019-11-18 17:42:12 -0800 | [diff] [blame] | 1569 | mFlinger->mTimeStats->setAcquireFence(getSequence(), newTimestamps->frameNumber, |
| 1570 | newTimestamps->acquireFence); |
Yiwei Zhang | faf3ded | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 1571 | } |
| 1572 | |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 1573 | Mutex::Autolock lock(mFrameEventHistoryMutex); |
| 1574 | if (newTimestamps) { |
Brian Anderson | fbc80ae | 2017-05-26 16:23:54 -0700 | [diff] [blame] | 1575 | // If there are any unsignaled fences in the aquire timeline at this |
| 1576 | // point, the previously queued frame hasn't been latched yet. Go ahead |
| 1577 | // and try to get the signal time here so the syscall is taken out of |
| 1578 | // the main thread's critical path. |
| 1579 | mAcquireTimeline.updateSignalTimes(); |
| 1580 | // Push the new fence after updating since it's likely still pending. |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 1581 | mAcquireTimeline.push(newTimestamps->acquireFence); |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 1582 | mFrameEventHistory.addQueue(*newTimestamps); |
| 1583 | } |
| 1584 | |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1585 | if (outDelta) { |
| 1586 | mFrameEventHistory.getAndResetDelta(outDelta); |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 1587 | } |
Pablo Ceballos | 40845df | 2016-01-25 17:41:15 -0800 | [diff] [blame] | 1588 | } |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 1589 | |
Chia-I Wu | 98f1c10 | 2017-05-30 14:54:08 -0700 | [diff] [blame] | 1590 | size_t Layer::getChildrenCount() const { |
| 1591 | size_t count = 0; |
| 1592 | for (const sp<Layer>& child : mCurrentChildren) { |
| 1593 | count += 1 + child->getChildrenCount(); |
| 1594 | } |
| 1595 | return count; |
| 1596 | } |
| 1597 | |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 1598 | void Layer::setGameModeForTree(int parentGameMode) { |
| 1599 | int gameMode = parentGameMode; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1600 | auto& currentState = getDrawingState(); |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 1601 | if (currentState.metadata.has(METADATA_GAME_MODE)) { |
| 1602 | gameMode = currentState.metadata.getInt32(METADATA_GAME_MODE, 0); |
| 1603 | } |
| 1604 | setGameMode(gameMode); |
| 1605 | for (const sp<Layer>& child : mCurrentChildren) { |
| 1606 | child->setGameModeForTree(gameMode); |
| 1607 | } |
| 1608 | } |
| 1609 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1610 | void Layer::addChild(const sp<Layer>& layer) { |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 1611 | mFlinger->mSomeChildrenChanged = true; |
Robert Carr | 7f2ed8b | 2019-02-07 14:45:11 -0800 | [diff] [blame] | 1612 | setTransactionFlags(eTransactionNeeded); |
Robert Carr | 1323c95 | 2019-01-28 18:13:27 -0800 | [diff] [blame] | 1613 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1614 | mCurrentChildren.add(layer); |
| 1615 | layer->setParent(this); |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 1616 | layer->setGameModeForTree(mGameMode); |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1617 | updateTreeHasFrameRateVote(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | ssize_t Layer::removeChild(const sp<Layer>& layer) { |
Robert Carr | e450fb5 | 2021-06-11 13:21:09 -0700 | [diff] [blame] | 1621 | mFlinger->mSomeChildrenChanged = true; |
Robert Carr | 7f2ed8b | 2019-02-07 14:45:11 -0800 | [diff] [blame] | 1622 | setTransactionFlags(eTransactionNeeded); |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 1623 | |
Robert Carr | 1323c95 | 2019-01-28 18:13:27 -0800 | [diff] [blame] | 1624 | layer->setParent(nullptr); |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1625 | const auto removeResult = mCurrentChildren.remove(layer); |
| 1626 | |
| 1627 | updateTreeHasFrameRateVote(); |
Adithya Srinivasan | ac977e6 | 2021-05-21 22:50:56 +0000 | [diff] [blame] | 1628 | layer->setGameModeForTree(0); |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1629 | layer->updateTreeHasFrameRateVote(); |
| 1630 | |
| 1631 | return removeResult; |
| 1632 | } |
| 1633 | |
Robert Carr | 15eae09 | 2018-03-23 13:43:53 -0700 | [diff] [blame] | 1634 | void Layer::setChildrenDrawingParent(const sp<Layer>& newParent) { |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 1635 | for (const sp<Layer>& child : mDrawingChildren) { |
| 1636 | child->mDrawingParent = newParent; |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 1637 | child->computeBounds(newParent->mBounds, newParent->mEffectiveTransform, |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 1638 | newParent->mEffectiveShadowRadius); |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 1639 | } |
| 1640 | } |
| 1641 | |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 1642 | bool Layer::reparent(const sp<IBinder>& newParentHandle) { |
Robert Carr | 54cf5b1 | 2019-01-25 14:02:28 -0800 | [diff] [blame] | 1643 | sp<Layer> newParent; |
| 1644 | if (newParentHandle != nullptr) { |
Vishnu Nair | a8c7c54 | 2021-07-20 18:49:42 -0700 | [diff] [blame] | 1645 | newParent = fromHandle(newParentHandle).promote(); |
Robert Carr | 54cf5b1 | 2019-01-25 14:02:28 -0800 | [diff] [blame] | 1646 | if (newParent == nullptr) { |
| 1647 | ALOGE("Unable to promote Layer handle"); |
| 1648 | return false; |
| 1649 | } |
| 1650 | if (newParent == this) { |
| 1651 | ALOGE("Invalid attempt to reparent Layer (%s) to itself", getName().c_str()); |
| 1652 | return false; |
| 1653 | } |
| 1654 | } |
| 1655 | |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 1656 | sp<Layer> parent = getParent(); |
| 1657 | if (parent != nullptr) { |
| 1658 | parent->removeChild(this); |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 1659 | } |
| 1660 | |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 1661 | if (newParentHandle != nullptr) { |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 1662 | newParent->addChild(this); |
| 1663 | if (!newParent->isRemovedFromCurrentState()) { |
| 1664 | addToCurrentState(); |
| 1665 | } else { |
| 1666 | onRemovedFromCurrentState(); |
| 1667 | } |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 1668 | } else { |
| 1669 | onRemovedFromCurrentState(); |
chaviw | 61626f2 | 2018-11-15 16:26:27 -0800 | [diff] [blame] | 1670 | } |
| 1671 | |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 1672 | return true; |
| 1673 | } |
| 1674 | |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 1675 | bool Layer::setColorTransform(const mat4& matrix) { |
Peiyong Lin | 747321c | 2018-10-01 10:03:11 -0700 | [diff] [blame] | 1676 | static const mat4 identityMatrix = mat4(); |
| 1677 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1678 | if (mDrawingState.colorTransform == matrix) { |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 1679 | return false; |
| 1680 | } |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1681 | ++mDrawingState.sequence; |
| 1682 | mDrawingState.colorTransform = matrix; |
| 1683 | mDrawingState.hasColorTransform = matrix != identityMatrix; |
| 1684 | mDrawingState.modified = true; |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 1685 | setTransactionFlags(eTransactionNeeded); |
| 1686 | return true; |
| 1687 | } |
| 1688 | |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 1689 | mat4 Layer::getColorTransform() const { |
| 1690 | mat4 colorTransform = mat4(getDrawingState().colorTransform); |
| 1691 | if (sp<Layer> parent = mDrawingParent.promote(); parent != nullptr) { |
| 1692 | colorTransform = parent->getColorTransform() * colorTransform; |
| 1693 | } |
| 1694 | return colorTransform; |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 1695 | } |
| 1696 | |
| 1697 | bool Layer::hasColorTransform() const { |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 1698 | bool hasColorTransform = getDrawingState().hasColorTransform; |
| 1699 | if (sp<Layer> parent = mDrawingParent.promote(); parent != nullptr) { |
| 1700 | hasColorTransform = hasColorTransform || parent->hasColorTransform(); |
| 1701 | } |
| 1702 | return hasColorTransform; |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 1703 | } |
| 1704 | |
Chia-I Wu | 1148147 | 2018-05-04 10:43:19 -0700 | [diff] [blame] | 1705 | bool Layer::isLegacyDataSpace() const { |
| 1706 | // return true when no higher bits are set |
chaviw | 4244e03 | 2019-09-04 11:27:49 -0700 | [diff] [blame] | 1707 | return !(getDataSpace() & |
| 1708 | (ui::Dataspace::STANDARD_MASK | ui::Dataspace::TRANSFER_MASK | |
| 1709 | ui::Dataspace::RANGE_MASK)); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 1710 | } |
| 1711 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1712 | void Layer::setParent(const sp<Layer>& layer) { |
Chia-I Wu | e41dbe6 | 2017-06-13 14:10:56 -0700 | [diff] [blame] | 1713 | mCurrentParent = layer; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1716 | int32_t Layer::getZ(LayerVector::StateSet) const { |
| 1717 | return mDrawingState.z; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1718 | } |
| 1719 | |
Robert Carr | 1c5481e | 2019-07-01 14:42:27 -0700 | [diff] [blame] | 1720 | bool Layer::usingRelativeZ(LayerVector::StateSet stateSet) const { |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1721 | const bool useDrawing = stateSet == LayerVector::StateSet::Drawing; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1722 | const State& state = useDrawing ? mDrawingState : mDrawingState; |
chaviw | e5ac40f | 2019-09-24 16:36:55 -0700 | [diff] [blame] | 1723 | return state.isRelativeOf; |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1724 | } |
| 1725 | |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 1726 | __attribute__((no_sanitize("unsigned-integer-overflow"))) LayerVector Layer::makeTraversalList( |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1727 | LayerVector::StateSet stateSet, bool* outSkipRelativeZUsers) { |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1728 | LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid, |
| 1729 | "makeTraversalList received invalid stateSet"); |
| 1730 | const bool useDrawing = stateSet == LayerVector::StateSet::Drawing; |
| 1731 | const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1732 | const State& state = useDrawing ? mDrawingState : mDrawingState; |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1733 | |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1734 | if (state.zOrderRelatives.size() == 0) { |
| 1735 | *outSkipRelativeZUsers = true; |
| 1736 | return children; |
| 1737 | } |
| 1738 | |
chaviw | fd46261 | 2018-05-31 16:11:27 -0700 | [diff] [blame] | 1739 | LayerVector traverse(stateSet); |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1740 | for (const wp<Layer>& weakRelative : state.zOrderRelatives) { |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1741 | sp<Layer> strongRelative = weakRelative.promote(); |
| 1742 | if (strongRelative != nullptr) { |
| 1743 | traverse.add(strongRelative); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1744 | } |
| 1745 | } |
| 1746 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1747 | for (const sp<Layer>& child : children) { |
chaviw | e5ac40f | 2019-09-24 16:36:55 -0700 | [diff] [blame] | 1748 | if (child->usingRelativeZ(stateSet)) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 1749 | continue; |
| 1750 | } |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1751 | traverse.add(child); |
| 1752 | } |
| 1753 | |
| 1754 | return traverse; |
| 1755 | } |
| 1756 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1757 | /** |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1758 | * Negatively signed relatives are before 'this' in Z-order. |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1759 | */ |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1760 | void Layer::traverseInZOrder(LayerVector::StateSet stateSet, const LayerVector::Visitor& visitor) { |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1761 | // In the case we have other layers who are using a relative Z to us, makeTraversalList will |
| 1762 | // produce a new list for traversing, including our relatives, and not including our children |
| 1763 | // who are relatives of another surface. In the case that there are no relative Z, |
| 1764 | // makeTraversalList returns our children directly to avoid significant overhead. |
| 1765 | // However in this case we need to take the responsibility for filtering children which |
| 1766 | // are relatives of another surface here. |
| 1767 | bool skipRelativeZUsers = false; |
| 1768 | const LayerVector list = makeTraversalList(stateSet, &skipRelativeZUsers); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1769 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1770 | size_t i = 0; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1771 | for (; i < list.size(); i++) { |
| 1772 | const auto& relative = list[i]; |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1773 | if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) { |
| 1774 | continue; |
| 1775 | } |
| 1776 | |
chaviw | 301b1d8 | 2019-11-06 13:15:09 -0800 | [diff] [blame] | 1777 | if (relative->getZ(stateSet) >= 0) { |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1778 | break; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1779 | } |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1780 | relative->traverseInZOrder(stateSet, visitor); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1781 | } |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1782 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1783 | visitor(this); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1784 | for (; i < list.size(); i++) { |
| 1785 | const auto& relative = list[i]; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1786 | |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1787 | if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) { |
| 1788 | continue; |
| 1789 | } |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1790 | relative->traverseInZOrder(stateSet, visitor); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1791 | } |
| 1792 | } |
| 1793 | |
| 1794 | /** |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1795 | * Positively signed relatives are before 'this' in reverse Z-order. |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1796 | */ |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1797 | void Layer::traverseInReverseZOrder(LayerVector::StateSet stateSet, |
| 1798 | const LayerVector::Visitor& visitor) { |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1799 | // See traverseInZOrder for documentation. |
| 1800 | bool skipRelativeZUsers = false; |
| 1801 | LayerVector list = makeTraversalList(stateSet, &skipRelativeZUsers); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1802 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1803 | int32_t i = 0; |
Joel Galenson | bf32499 | 2017-11-06 11:04:12 -0800 | [diff] [blame] | 1804 | for (i = int32_t(list.size()) - 1; i >= 0; i--) { |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1805 | const auto& relative = list[i]; |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1806 | |
| 1807 | if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) { |
| 1808 | continue; |
| 1809 | } |
| 1810 | |
chaviw | 301b1d8 | 2019-11-06 13:15:09 -0800 | [diff] [blame] | 1811 | if (relative->getZ(stateSet) < 0) { |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1812 | break; |
| 1813 | } |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1814 | relative->traverseInReverseZOrder(stateSet, visitor); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1815 | } |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1816 | visitor(this); |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 1817 | for (; i >= 0; i--) { |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1818 | const auto& relative = list[i]; |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1819 | |
| 1820 | if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) { |
| 1821 | continue; |
| 1822 | } |
| 1823 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1824 | relative->traverseInReverseZOrder(stateSet, visitor); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1825 | } |
| 1826 | } |
| 1827 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 1828 | void Layer::traverse(LayerVector::StateSet state, const LayerVector::Visitor& visitor) { |
| 1829 | visitor(this); |
| 1830 | const LayerVector& children = |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1831 | state == LayerVector::StateSet::Drawing ? mDrawingChildren : mCurrentChildren; |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 1832 | for (const sp<Layer>& child : children) { |
| 1833 | child->traverse(state, visitor); |
| 1834 | } |
| 1835 | } |
| 1836 | |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1837 | LayerVector Layer::makeChildrenTraversalList(LayerVector::StateSet stateSet, |
| 1838 | const std::vector<Layer*>& layersInTree) { |
| 1839 | LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid, |
| 1840 | "makeTraversalList received invalid stateSet"); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 1841 | const bool useDrawing = stateSet == LayerVector::StateSet::Drawing; |
| 1842 | const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1843 | const State& state = useDrawing ? mDrawingState : mDrawingState; |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1844 | |
chaviw | fd46261 | 2018-05-31 16:11:27 -0700 | [diff] [blame] | 1845 | LayerVector traverse(stateSet); |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1846 | for (const wp<Layer>& weakRelative : state.zOrderRelatives) { |
| 1847 | sp<Layer> strongRelative = weakRelative.promote(); |
| 1848 | // Only add relative layers that are also descendents of the top most parent of the tree. |
| 1849 | // If a relative layer is not a descendent, then it should be ignored. |
| 1850 | if (std::binary_search(layersInTree.begin(), layersInTree.end(), strongRelative.get())) { |
| 1851 | traverse.add(strongRelative); |
| 1852 | } |
| 1853 | } |
| 1854 | |
| 1855 | for (const sp<Layer>& child : children) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1856 | const State& childState = useDrawing ? child->mDrawingState : child->mDrawingState; |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1857 | // If a layer has a relativeOf layer, only ignore if the layer it's relative to is a |
| 1858 | // descendent of the top most parent of the tree. If it's not a descendent, then just add |
| 1859 | // the child here since it won't be added later as a relative. |
| 1860 | if (std::binary_search(layersInTree.begin(), layersInTree.end(), |
| 1861 | childState.zOrderRelativeOf.promote().get())) { |
| 1862 | continue; |
| 1863 | } |
| 1864 | traverse.add(child); |
| 1865 | } |
| 1866 | |
| 1867 | return traverse; |
| 1868 | } |
| 1869 | |
| 1870 | void Layer::traverseChildrenInZOrderInner(const std::vector<Layer*>& layersInTree, |
| 1871 | LayerVector::StateSet stateSet, |
| 1872 | const LayerVector::Visitor& visitor) { |
| 1873 | const LayerVector list = makeChildrenTraversalList(stateSet, layersInTree); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 1874 | |
| 1875 | size_t i = 0; |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1876 | for (; i < list.size(); i++) { |
| 1877 | const auto& relative = list[i]; |
chaviw | 301b1d8 | 2019-11-06 13:15:09 -0800 | [diff] [blame] | 1878 | if (relative->getZ(stateSet) >= 0) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 1879 | break; |
| 1880 | } |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1881 | relative->traverseChildrenInZOrderInner(layersInTree, stateSet, visitor); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 1882 | } |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1883 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 1884 | visitor(this); |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1885 | for (; i < list.size(); i++) { |
| 1886 | const auto& relative = list[i]; |
| 1887 | relative->traverseChildrenInZOrderInner(layersInTree, stateSet, visitor); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 1888 | } |
| 1889 | } |
| 1890 | |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1891 | std::vector<Layer*> Layer::getLayersInTree(LayerVector::StateSet stateSet) { |
| 1892 | const bool useDrawing = stateSet == LayerVector::StateSet::Drawing; |
| 1893 | const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren; |
| 1894 | |
| 1895 | std::vector<Layer*> layersInTree = {this}; |
| 1896 | for (size_t i = 0; i < children.size(); i++) { |
| 1897 | const auto& child = children[i]; |
| 1898 | std::vector<Layer*> childLayers = child->getLayersInTree(stateSet); |
| 1899 | layersInTree.insert(layersInTree.end(), childLayers.cbegin(), childLayers.cend()); |
| 1900 | } |
| 1901 | |
| 1902 | return layersInTree; |
| 1903 | } |
| 1904 | |
| 1905 | void Layer::traverseChildrenInZOrder(LayerVector::StateSet stateSet, |
| 1906 | const LayerVector::Visitor& visitor) { |
| 1907 | std::vector<Layer*> layersInTree = getLayersInTree(stateSet); |
| 1908 | std::sort(layersInTree.begin(), layersInTree.end()); |
| 1909 | traverseChildrenInZOrderInner(layersInTree, stateSet, visitor); |
| 1910 | } |
| 1911 | |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 1912 | ui::Transform Layer::getTransform() const { |
Vishnu Nair | f0c2851 | 2019-02-08 12:40:28 -0800 | [diff] [blame] | 1913 | return mEffectiveTransform; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1914 | } |
| 1915 | |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 1916 | half Layer::getAlpha() const { |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 1917 | const auto& p = mDrawingParent.promote(); |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1918 | |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 1919 | half parentAlpha = (p != nullptr) ? p->getAlpha() : 1.0_hf; |
| 1920 | return parentAlpha * getDrawingState().color.a; |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 1921 | } |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 1922 | |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 1923 | ui::Transform::RotationFlags Layer::getFixedTransformHint() const { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 1924 | ui::Transform::RotationFlags fixedTransformHint = mDrawingState.fixedTransformHint; |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 1925 | if (fixedTransformHint != ui::Transform::ROT_INVALID) { |
| 1926 | return fixedTransformHint; |
| 1927 | } |
| 1928 | const auto& p = mCurrentParent.promote(); |
| 1929 | if (!p) return fixedTransformHint; |
| 1930 | return p->getFixedTransformHint(); |
| 1931 | } |
| 1932 | |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 1933 | half4 Layer::getColor() const { |
| 1934 | const half4 color(getDrawingState().color); |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1935 | return half4(color.r, color.g, color.b, getAlpha()); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 1936 | } |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 1937 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1938 | int32_t Layer::getBackgroundBlurRadius() const { |
Galia Peycheva | da7de0e | 2020-12-03 17:24:35 +0100 | [diff] [blame] | 1939 | const auto& p = mDrawingParent.promote(); |
| 1940 | |
| 1941 | half parentAlpha = (p != nullptr) ? p->getAlpha() : 1.0_hf; |
| 1942 | return parentAlpha * getDrawingState().backgroundBlurRadius; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1943 | } |
| 1944 | |
Galia Peycheva | e0acf38 | 2021-04-12 21:22:34 +0200 | [diff] [blame] | 1945 | const std::vector<BlurRegion> Layer::getBlurRegions() const { |
| 1946 | auto regionsCopy(getDrawingState().blurRegions); |
Galia Peycheva | 3c28654 | 2021-06-17 15:21:28 +0200 | [diff] [blame] | 1947 | float layerAlpha = getAlpha(); |
Galia Peycheva | e0acf38 | 2021-04-12 21:22:34 +0200 | [diff] [blame] | 1948 | for (auto& region : regionsCopy) { |
| 1949 | region.alpha = region.alpha * layerAlpha; |
| 1950 | } |
| 1951 | return regionsCopy; |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 1952 | } |
| 1953 | |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1954 | Layer::RoundedCornerState Layer::getRoundedCornerState() const { |
| 1955 | const auto& p = mDrawingParent.promote(); |
| 1956 | if (p != nullptr) { |
Peiyong Lin | 27016a9 | 2019-03-29 17:36:08 +0000 | [diff] [blame] | 1957 | RoundedCornerState parentState = p->getRoundedCornerState(); |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1958 | if (parentState.radius > 0) { |
| 1959 | ui::Transform t = getActiveTransform(getDrawingState()); |
| 1960 | t = t.inverse(); |
| 1961 | parentState.cropRect = t.transform(parentState.cropRect); |
| 1962 | // The rounded corners shader only accepts 1 corner radius for performance reasons, |
| 1963 | // but a transform matrix can define horizontal and vertical scales. |
| 1964 | // Let's take the average between both of them and pass into the shader, practically we |
| 1965 | // never do this type of transformation on windows anyway. |
Lucas Dupin | eab7ea0 | 2020-06-03 17:27:28 -0700 | [diff] [blame] | 1966 | auto scaleX = sqrtf(t[0][0] * t[0][0] + t[0][1] * t[0][1]); |
| 1967 | auto scaleY = sqrtf(t[1][0] * t[1][0] + t[1][1] * t[1][1]); |
| 1968 | parentState.radius *= (scaleX + scaleY) / 2.0f; |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1969 | return parentState; |
| 1970 | } |
| 1971 | } |
| 1972 | const float radius = getDrawingState().cornerRadius; |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 1973 | return radius > 0 && getCroppedBufferSize(getDrawingState()).isValid() |
| 1974 | ? RoundedCornerState(getCroppedBufferSize(getDrawingState()).toFloatRect(), radius) |
Peiyong Lin | b9ff23e | 2019-04-08 11:04:59 -0700 | [diff] [blame] | 1975 | : RoundedCornerState(); |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1976 | } |
| 1977 | |
Derek Sollenberger | c31985e | 2021-05-18 16:38:17 -0400 | [diff] [blame] | 1978 | void Layer::prepareShadowClientComposition(LayerFE::LayerSettings& caster, |
| 1979 | const Rect& layerStackRect) { |
Vishnu Nair | 08f6eae | 2019-11-26 14:01:39 -0800 | [diff] [blame] | 1980 | renderengine::ShadowSettings state = mFlinger->mDrawingState.globalShadowSettings; |
| 1981 | |
Derek Sollenberger | c31985e | 2021-05-18 16:38:17 -0400 | [diff] [blame] | 1982 | // Note: this preserves existing behavior of shadowing the entire layer and not cropping it if |
| 1983 | // transparent regions are present. This may not be necessary since shadows are only cast by |
| 1984 | // SurfaceFlinger's EffectLayers, which do not typically use transparent regions. |
| 1985 | state.boundaries = mBounds; |
| 1986 | |
Vishnu Nair | 08f6eae | 2019-11-26 14:01:39 -0800 | [diff] [blame] | 1987 | // Shift the spot light x-position to the middle of the display and then |
| 1988 | // offset it by casting layer's screen pos. |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 1989 | state.lightPos.x = (layerStackRect.width() / 2.f) - mScreenBounds.left; |
Vishnu Nair | 08f6eae | 2019-11-26 14:01:39 -0800 | [diff] [blame] | 1990 | state.lightPos.y -= mScreenBounds.top; |
| 1991 | |
| 1992 | state.length = mEffectiveShadowRadius; |
Derek Sollenberger | c31985e | 2021-05-18 16:38:17 -0400 | [diff] [blame] | 1993 | |
| 1994 | if (state.length > 0.f) { |
| 1995 | const float casterAlpha = caster.alpha; |
| 1996 | const bool casterIsOpaque = |
| 1997 | ((caster.source.buffer.buffer != nullptr) && caster.source.buffer.isOpaque); |
| 1998 | |
| 1999 | // If the casting layer is translucent, we need to fill in the shadow underneath the layer. |
| 2000 | // Otherwise the generated shadow will only be shown around the casting layer. |
| 2001 | state.casterIsTranslucent = !casterIsOpaque || (casterAlpha < 1.0f); |
| 2002 | state.ambientColor *= casterAlpha; |
| 2003 | state.spotColor *= casterAlpha; |
| 2004 | |
| 2005 | if (state.ambientColor.a > 0.f && state.spotColor.a > 0.f) { |
| 2006 | caster.shadow = state; |
| 2007 | } |
| 2008 | } |
Vishnu Nair | 08f6eae | 2019-11-26 14:01:39 -0800 | [diff] [blame] | 2009 | } |
| 2010 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 2011 | void Layer::commitChildList() { |
| 2012 | for (size_t i = 0; i < mCurrentChildren.size(); i++) { |
| 2013 | const auto& child = mCurrentChildren[i]; |
| 2014 | child->commitChildList(); |
| 2015 | } |
| 2016 | mDrawingChildren = mCurrentChildren; |
Chia-I Wu | e41dbe6 | 2017-06-13 14:10:56 -0700 | [diff] [blame] | 2017 | mDrawingParent = mCurrentParent; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 2018 | } |
| 2019 | |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 2020 | |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 2021 | void Layer::setInputInfo(const InputWindowInfo& info) { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 2022 | mDrawingState.inputInfo = info; |
Vishnu Nair | a8c7c54 | 2021-07-20 18:49:42 -0700 | [diff] [blame] | 2023 | mDrawingState.touchableRegionCrop = fromHandle(info.touchableRegionCropHandle.promote()); |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 2024 | mDrawingState.modified = true; |
Robert Carr | bf14dbb | 2021-06-11 13:26:56 -0700 | [diff] [blame] | 2025 | mFlinger->mInputInfoChanged = true; |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 2026 | setTransactionFlags(eTransactionNeeded); |
| 2027 | } |
| 2028 | |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 2029 | LayerProto* Layer::writeToProto(LayersProto& layersProto, uint32_t traceFlags, |
chaviw | 4c34a09 | 2020-07-08 11:30:06 -0700 | [diff] [blame] | 2030 | const DisplayDevice* display) { |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 2031 | LayerProto* layerProto = layersProto.add_layers(); |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 2032 | writeToProtoDrawingState(layerProto, traceFlags, display); |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 2033 | writeToProtoCommonState(layerProto, LayerVector::StateSet::Drawing, traceFlags); |
| 2034 | |
Vishnu Nair | 60db8c0 | 2020-04-02 11:55:16 -0700 | [diff] [blame] | 2035 | if (traceFlags & SurfaceTracing::TRACE_COMPOSITION) { |
| 2036 | // Only populate for the primary display. |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 2037 | if (display) { |
| 2038 | const Hwc2::IComposerClient::Composition compositionType = getCompositionType(*display); |
Vishnu Nair | 60db8c0 | 2020-04-02 11:55:16 -0700 | [diff] [blame] | 2039 | layerProto->set_hwc_composition_type(static_cast<HwcCompositionType>(compositionType)); |
| 2040 | } |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 2041 | } |
| 2042 | |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 2043 | for (const sp<Layer>& layer : mDrawingChildren) { |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 2044 | layer->writeToProto(layersProto, traceFlags, display); |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 2045 | } |
chaviw | 6d89e2d | 2020-01-14 14:42:01 -0800 | [diff] [blame] | 2046 | |
| 2047 | return layerProto; |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 2048 | } |
| 2049 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 2050 | void Layer::writeToProtoDrawingState(LayerProto* layerInfo, uint32_t traceFlags, |
chaviw | 4c34a09 | 2020-07-08 11:30:06 -0700 | [diff] [blame] | 2051 | const DisplayDevice* display) { |
Vishnu Nair | 6b7c5c9 | 2020-09-29 17:27:05 -0700 | [diff] [blame] | 2052 | const ui::Transform transform = getTransform(); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 2053 | |
| 2054 | if (traceFlags & SurfaceTracing::TRACE_CRITICAL) { |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 2055 | |
chaviw | d62d306 | 2019-09-04 14:48:02 -0700 | [diff] [blame] | 2056 | auto buffer = getBuffer(); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 2057 | if (buffer != nullptr) { |
| 2058 | LayerProtoHelper::writeToProto(buffer, |
| 2059 | [&]() { return layerInfo->mutable_active_buffer(); }); |
chaviw | 4244e03 | 2019-09-04 11:27:49 -0700 | [diff] [blame] | 2060 | LayerProtoHelper::writeToProto(ui::Transform(getBufferTransform()), |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 2061 | layerInfo->mutable_buffer_transform()); |
| 2062 | } |
| 2063 | layerInfo->set_invalidate(contentDirty); |
| 2064 | layerInfo->set_is_protected(isProtected()); |
chaviw | 4244e03 | 2019-09-04 11:27:49 -0700 | [diff] [blame] | 2065 | layerInfo->set_dataspace(dataspaceDetails(static_cast<android_dataspace>(getDataSpace()))); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 2066 | layerInfo->set_queued_frames(getQueuedFrameCount()); |
| 2067 | layerInfo->set_refresh_pending(isBufferLatched()); |
| 2068 | layerInfo->set_curr_frame(mCurrentFrameNumber); |
| 2069 | layerInfo->set_effective_scaling_mode(getEffectiveScalingMode()); |
| 2070 | |
| 2071 | layerInfo->set_corner_radius(getRoundedCornerState().radius); |
Ana Krulec | e766cc8 | 2020-04-27 13:49:13 -0700 | [diff] [blame] | 2072 | layerInfo->set_background_blur_radius(getBackgroundBlurRadius()); |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 2073 | layerInfo->set_is_trusted_overlay(isTrustedOverlay()); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 2074 | LayerProtoHelper::writeToProto(transform, layerInfo->mutable_transform()); |
| 2075 | LayerProtoHelper::writePositionToProto(transform.tx(), transform.ty(), |
| 2076 | [&]() { return layerInfo->mutable_position(); }); |
| 2077 | LayerProtoHelper::writeToProto(mBounds, [&]() { return layerInfo->mutable_bounds(); }); |
Vishnu Nair | 60db8c0 | 2020-04-02 11:55:16 -0700 | [diff] [blame] | 2078 | if (traceFlags & SurfaceTracing::TRACE_COMPOSITION) { |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 2079 | LayerProtoHelper::writeToProto(getVisibleRegion(display), |
Vishnu Nair | 60db8c0 | 2020-04-02 11:55:16 -0700 | [diff] [blame] | 2080 | [&]() { return layerInfo->mutable_visible_region(); }); |
| 2081 | } |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 2082 | LayerProtoHelper::writeToProto(surfaceDamageRegion, |
| 2083 | [&]() { return layerInfo->mutable_damage_region(); }); |
chaviw | ddeae26 | 2020-01-06 10:31:23 -0800 | [diff] [blame] | 2084 | |
| 2085 | if (hasColorTransform()) { |
| 2086 | LayerProtoHelper::writeToProto(getColorTransform(), |
| 2087 | layerInfo->mutable_color_transform()); |
| 2088 | } |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 2089 | } |
| 2090 | |
Vishnu Nair | 60db8c0 | 2020-04-02 11:55:16 -0700 | [diff] [blame] | 2091 | LayerProtoHelper::writeToProto(mSourceBounds, |
| 2092 | [&]() { return layerInfo->mutable_source_bounds(); }); |
| 2093 | LayerProtoHelper::writeToProto(mScreenBounds, |
| 2094 | [&]() { return layerInfo->mutable_screen_bounds(); }); |
| 2095 | LayerProtoHelper::writeToProto(getRoundedCornerState().cropRect, |
| 2096 | [&]() { return layerInfo->mutable_corner_radius_crop(); }); |
| 2097 | layerInfo->set_shadow_radius(mEffectiveShadowRadius); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 2098 | } |
| 2099 | |
| 2100 | void Layer::writeToProtoCommonState(LayerProto* layerInfo, LayerVector::StateSet stateSet, |
chaviw | 4c34a09 | 2020-07-08 11:30:06 -0700 | [diff] [blame] | 2101 | uint32_t traceFlags) { |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 2102 | const bool useDrawing = stateSet == LayerVector::StateSet::Drawing; |
| 2103 | const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren; |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 2104 | const State& state = useDrawing ? mDrawingState : mDrawingState; |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 2105 | |
chaviw | 766c9c5 | 2021-02-10 17:36:47 -0800 | [diff] [blame] | 2106 | ui::Transform requestedTransform = state.transform; |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 2107 | |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2108 | if (traceFlags & SurfaceTracing::TRACE_CRITICAL) { |
| 2109 | layerInfo->set_id(sequence); |
| 2110 | layerInfo->set_name(getName().c_str()); |
chaviw | 8a01fa4 | 2019-08-19 12:39:31 -0700 | [diff] [blame] | 2111 | layerInfo->set_type(getType()); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 2112 | |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2113 | for (const auto& child : children) { |
| 2114 | layerInfo->add_children(child->sequence); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 2115 | } |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 2116 | |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2117 | for (const wp<Layer>& weakRelative : state.zOrderRelatives) { |
| 2118 | sp<Layer> strongRelative = weakRelative.promote(); |
| 2119 | if (strongRelative != nullptr) { |
| 2120 | layerInfo->add_relatives(strongRelative->sequence); |
| 2121 | } |
chaviw | adc40c2 | 2018-07-10 16:57:27 -0700 | [diff] [blame] | 2122 | } |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2123 | |
| 2124 | LayerProtoHelper::writeToProto(state.activeTransparentRegion_legacy, |
| 2125 | [&]() { return layerInfo->mutable_transparent_region(); }); |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2126 | |
| 2127 | layerInfo->set_layer_stack(getLayerStack()); |
| 2128 | layerInfo->set_z(state.z); |
| 2129 | |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2130 | LayerProtoHelper::writePositionToProto(requestedTransform.tx(), requestedTransform.ty(), |
| 2131 | [&]() { |
| 2132 | return layerInfo->mutable_requested_position(); |
| 2133 | }); |
| 2134 | |
chaviw | 766c9c5 | 2021-02-10 17:36:47 -0800 | [diff] [blame] | 2135 | LayerProtoHelper::writeSizeToProto(state.width, state.height, |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2136 | [&]() { return layerInfo->mutable_size(); }); |
| 2137 | |
chaviw | 766c9c5 | 2021-02-10 17:36:47 -0800 | [diff] [blame] | 2138 | LayerProtoHelper::writeToProto(state.crop, [&]() { return layerInfo->mutable_crop(); }); |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2139 | |
| 2140 | layerInfo->set_is_opaque(isOpaque(state)); |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2141 | |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2142 | |
| 2143 | layerInfo->set_pixel_format(decodePixelFormat(getPixelFormat())); |
| 2144 | LayerProtoHelper::writeToProto(getColor(), [&]() { return layerInfo->mutable_color(); }); |
| 2145 | LayerProtoHelper::writeToProto(state.color, |
| 2146 | [&]() { return layerInfo->mutable_requested_color(); }); |
| 2147 | layerInfo->set_flags(state.flags); |
| 2148 | |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2149 | LayerProtoHelper::writeToProto(requestedTransform, |
| 2150 | layerInfo->mutable_requested_transform()); |
| 2151 | |
| 2152 | auto parent = useDrawing ? mDrawingParent.promote() : mCurrentParent.promote(); |
| 2153 | if (parent != nullptr) { |
| 2154 | layerInfo->set_parent(parent->sequence); |
| 2155 | } else { |
| 2156 | layerInfo->set_parent(-1); |
| 2157 | } |
| 2158 | |
| 2159 | auto zOrderRelativeOf = state.zOrderRelativeOf.promote(); |
| 2160 | if (zOrderRelativeOf != nullptr) { |
| 2161 | layerInfo->set_z_order_relative_of(zOrderRelativeOf->sequence); |
| 2162 | } else { |
| 2163 | layerInfo->set_z_order_relative_of(-1); |
| 2164 | } |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 2165 | |
| 2166 | layerInfo->set_is_relative_of(state.isRelativeOf); |
chaviw | 250bcbb | 2020-08-05 11:17:54 -0700 | [diff] [blame] | 2167 | |
| 2168 | layerInfo->set_owner_uid(mOwnerUid); |
chaviw | adc40c2 | 2018-07-10 16:57:27 -0700 | [diff] [blame] | 2169 | } |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 2170 | |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2171 | if (traceFlags & SurfaceTracing::TRACE_INPUT) { |
chaviw | 4c34a09 | 2020-07-08 11:30:06 -0700 | [diff] [blame] | 2172 | InputWindowInfo info; |
| 2173 | if (useDrawing) { |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 2174 | info = fillInputInfo({nullptr}); |
chaviw | 4c34a09 | 2020-07-08 11:30:06 -0700 | [diff] [blame] | 2175 | } else { |
| 2176 | info = state.inputInfo; |
| 2177 | } |
| 2178 | |
| 2179 | LayerProtoHelper::writeToProto(info, state.touchableRegionCrop, |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2180 | [&]() { return layerInfo->mutable_input_window_info(); }); |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 2181 | } |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2182 | |
| 2183 | if (traceFlags & SurfaceTracing::TRACE_EXTRA) { |
| 2184 | auto protoMap = layerInfo->mutable_metadata(); |
| 2185 | for (const auto& entry : state.metadata.mMap) { |
| 2186 | (*protoMap)[entry.first] = std::string(entry.second.cbegin(), entry.second.cend()); |
| 2187 | } |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2188 | } |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 2189 | } |
| 2190 | |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 2191 | bool Layer::isRemovedFromCurrentState() const { |
Robert Carr | 6a16031 | 2021-05-17 12:08:20 -0700 | [diff] [blame] | 2192 | return mRemovedFromDrawingState; |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 2193 | } |
| 2194 | |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 2195 | ui::Transform Layer::getInputTransform() const { |
| 2196 | return getTransform(); |
| 2197 | } |
| 2198 | |
| 2199 | Rect Layer::getInputBounds() const { |
| 2200 | return getCroppedBufferSize(getDrawingState()); |
| 2201 | } |
| 2202 | |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 2203 | void Layer::fillInputFrameInfo(InputWindowInfo& info, const ui::Transform& toPhysicalDisplay) { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 2204 | // Transform layer size to screen space and inset it by surface insets. |
Tiger Huang | 85b8c5e | 2019-01-17 18:34:54 +0800 | [diff] [blame] | 2205 | // If this is a portal window, set the touchableRegion to the layerBounds. |
| 2206 | Rect layerBounds = info.portalToDisplayId == ADISPLAY_ID_NONE |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 2207 | ? getInputBounds() |
Tiger Huang | 85b8c5e | 2019-01-17 18:34:54 +0800 | [diff] [blame] | 2208 | : info.touchableRegion.getBounds(); |
Arthur Hung | d20b270 | 2019-01-14 18:16:16 +0800 | [diff] [blame] | 2209 | if (!layerBounds.isValid()) { |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 2210 | layerBounds = getInputBounds(); |
Arthur Hung | d20b270 | 2019-01-14 18:16:16 +0800 | [diff] [blame] | 2211 | } |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 2212 | |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 2213 | if (!layerBounds.isValid()) { |
| 2214 | // If the layer bounds is empty, set the frame to empty and clear the transform |
| 2215 | info.frameLeft = 0; |
| 2216 | info.frameTop = 0; |
| 2217 | info.frameRight = 0; |
| 2218 | info.frameBottom = 0; |
| 2219 | info.transform.reset(); |
| 2220 | return; |
| 2221 | } |
| 2222 | |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 2223 | ui::Transform layerToDisplay = getInputTransform(); |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 2224 | // Transform that takes window coordinates to unrotated display coordinates |
| 2225 | ui::Transform t = toPhysicalDisplay * layerToDisplay; |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 2226 | int32_t xSurfaceInset = info.surfaceInset; |
| 2227 | int32_t ySurfaceInset = info.surfaceInset; |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 2228 | // Bring screenBounds into unrotated space |
| 2229 | Rect screenBounds = toPhysicalDisplay.transform(Rect{mScreenBounds}); |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 2230 | |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 2231 | const float xScale = t.getScaleX(); |
| 2232 | const float yScale = t.getScaleY(); |
| 2233 | if (xScale != 1.0f || yScale != 1.0f) { |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 2234 | xSurfaceInset = std::round(xSurfaceInset * xScale); |
| 2235 | ySurfaceInset = std::round(ySurfaceInset * yScale); |
| 2236 | } |
| 2237 | |
Peiyong Lin | 74861ad | 2020-10-14 11:55:33 -0700 | [diff] [blame] | 2238 | // Transform the layer bounds from layer coordinate space to display coordinate space. |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 2239 | Rect transformedLayerBounds = t.transform(layerBounds); |
Ady Abraham | 282f1d7 | 2019-07-24 18:05:56 -0700 | [diff] [blame] | 2240 | |
| 2241 | // clamp inset to layer bounds |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 2242 | xSurfaceInset = (xSurfaceInset >= 0) |
| 2243 | ? std::min(xSurfaceInset, transformedLayerBounds.getWidth() / 2) |
| 2244 | : 0; |
| 2245 | ySurfaceInset = (ySurfaceInset >= 0) |
| 2246 | ? std::min(ySurfaceInset, transformedLayerBounds.getHeight() / 2) |
| 2247 | : 0; |
Ady Abraham | 282f1d7 | 2019-07-24 18:05:56 -0700 | [diff] [blame] | 2248 | |
Robert Carr | a724230 | 2020-09-01 18:26:29 -0700 | [diff] [blame] | 2249 | // inset while protecting from overflow TODO(b/161235021): What is going wrong |
| 2250 | // in the overflow scenario? |
| 2251 | { |
| 2252 | int32_t tmp; |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 2253 | if (!__builtin_add_overflow(transformedLayerBounds.left, xSurfaceInset, &tmp)) |
| 2254 | transformedLayerBounds.left = tmp; |
| 2255 | if (!__builtin_sub_overflow(transformedLayerBounds.right, xSurfaceInset, &tmp)) |
| 2256 | transformedLayerBounds.right = tmp; |
| 2257 | if (!__builtin_add_overflow(transformedLayerBounds.top, ySurfaceInset, &tmp)) |
| 2258 | transformedLayerBounds.top = tmp; |
| 2259 | if (!__builtin_sub_overflow(transformedLayerBounds.bottom, ySurfaceInset, &tmp)) |
| 2260 | transformedLayerBounds.bottom = tmp; |
Robert Carr | a724230 | 2020-09-01 18:26:29 -0700 | [diff] [blame] | 2261 | } |
Vishnu Nair | 8033a49 | 2018-12-05 07:27:23 -0800 | [diff] [blame] | 2262 | |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 2263 | // Compute the correct transform to send to input. This will allow it to transform the |
| 2264 | // input coordinates from display space into window space. Therefore, it needs to use the |
| 2265 | // final layer frame to create the inverse transform. Since surface insets are added later, |
| 2266 | // along with the overflow, the best way to ensure we get the correct transform is to use |
| 2267 | // the final frame calculated. |
| 2268 | // 1. Take the original transform set on the window and get the inverse transform. This is |
| 2269 | // used to get the final bounds in display space (ignorning the transform). Apply the |
Peiyong Lin | 74861ad | 2020-10-14 11:55:33 -0700 | [diff] [blame] | 2270 | // inverse transform on the layerBounds to get the untransformed frame (in layer space) |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 2271 | // 2. Take the top and left of the untransformed frame to get the real position on screen. |
| 2272 | // Apply the layer transform on top/left so it includes any scale or rotation. These will |
| 2273 | // be the new translation values for the transform. |
| 2274 | // 3. Update the translation of the original transform to the new translation values. |
| 2275 | // 4. Send the inverse transform to input so the coordinates can be transformed back into |
| 2276 | // window space. |
| 2277 | ui::Transform inverseTransform = t.inverse(); |
| 2278 | Rect nonTransformedBounds = inverseTransform.transform(transformedLayerBounds); |
| 2279 | vec2 translation = t.transform(nonTransformedBounds.left, nonTransformedBounds.top); |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 2280 | ui::Transform inputTransform(t); |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 2281 | inputTransform.set(translation.x, translation.y); |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 2282 | info.transform = inputTransform.inverse(); |
| 2283 | |
chaviw | 39cfa2e | 2020-11-04 14:19:02 -0800 | [diff] [blame] | 2284 | // We need to send the layer bounds cropped to the screenbounds since the layer can be cropped. |
| 2285 | // The frame should be the area the user sees on screen since it's used for occlusion |
| 2286 | // detection. |
chaviw | 39cfa2e | 2020-11-04 14:19:02 -0800 | [diff] [blame] | 2287 | transformedLayerBounds.intersect(screenBounds, &transformedLayerBounds); |
| 2288 | info.frameLeft = transformedLayerBounds.left; |
| 2289 | info.frameTop = transformedLayerBounds.top; |
| 2290 | info.frameRight = transformedLayerBounds.right; |
| 2291 | info.frameBottom = transformedLayerBounds.bottom; |
| 2292 | |
Vishnu Nair | 8033a49 | 2018-12-05 07:27:23 -0800 | [diff] [blame] | 2293 | // Position the touchable region relative to frame screen location and restrict it to frame |
| 2294 | // bounds. |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 2295 | info.touchableRegion = inputTransform.transform(info.touchableRegion); |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 2296 | } |
| 2297 | |
Bernardo Rufino | a9d0a53 | 2021-06-11 15:59:12 +0100 | [diff] [blame] | 2298 | void Layer::fillTouchOcclusionMode(InputWindowInfo& info) { |
| 2299 | sp<Layer> p = this; |
| 2300 | while (p != nullptr && !p->hasInputInfo()) { |
| 2301 | p = p->mDrawingParent.promote(); |
| 2302 | } |
| 2303 | if (p != nullptr) { |
| 2304 | info.touchOcclusionMode = p->mDrawingState.inputInfo.touchOcclusionMode; |
| 2305 | } |
| 2306 | } |
| 2307 | |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 2308 | InputWindowInfo Layer::fillInputInfo(const sp<DisplayDevice>& display) { |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 2309 | if (!hasInputInfo()) { |
| 2310 | mDrawingState.inputInfo.name = getName(); |
| 2311 | mDrawingState.inputInfo.ownerUid = mOwnerUid; |
| 2312 | mDrawingState.inputInfo.ownerPid = mOwnerPid; |
| 2313 | mDrawingState.inputInfo.inputFeatures = InputWindowInfo::Feature::NO_INPUT_CHANNEL; |
| 2314 | mDrawingState.inputInfo.flags = InputWindowInfo::Flag::NOT_TOUCH_MODAL; |
| 2315 | mDrawingState.inputInfo.displayId = getLayerStack(); |
| 2316 | } |
| 2317 | |
| 2318 | InputWindowInfo info = mDrawingState.inputInfo; |
| 2319 | info.id = sequence; |
| 2320 | |
| 2321 | if (info.displayId == ADISPLAY_ID_NONE) { |
| 2322 | info.displayId = getLayerStack(); |
| 2323 | } |
| 2324 | |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 2325 | // Transform that goes from "logical(rotated)" display to physical/unrotated display. |
| 2326 | // This is for when inputflinger operates in physical display-space. |
| 2327 | ui::Transform toPhysicalDisplay; |
| 2328 | if (display) { |
| 2329 | toPhysicalDisplay = display->getTransform(); |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 2330 | info.displayWidth = display->getWidth(); |
| 2331 | info.displayHeight = display->getHeight(); |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 2332 | } |
| 2333 | fillInputFrameInfo(info, toPhysicalDisplay); |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 2334 | |
Robert Carr | 5dc426e | 2020-06-10 14:29:14 -0700 | [diff] [blame] | 2335 | // For compatibility reasons we let layers which can receive input |
| 2336 | // receive input before they have actually submitted a buffer. Because |
| 2337 | // of this we use canReceiveInput instead of isVisible to check the |
| 2338 | // policy-visibility, ignoring the buffer state. However for layers with |
| 2339 | // hasInputInfo()==false we can use the real visibility state. |
| 2340 | // We are just using these layers for occlusion detection in |
| 2341 | // InputDispatcher, and obviously if they aren't visible they can't occlude |
| 2342 | // anything. |
| 2343 | info.visible = hasInputInfo() ? canReceiveInput() : isVisible(); |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 2344 | info.alpha = getAlpha(); |
Bernardo Rufino | a9d0a53 | 2021-06-11 15:59:12 +0100 | [diff] [blame] | 2345 | fillTouchOcclusionMode(info); |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 2346 | |
| 2347 | auto cropLayer = mDrawingState.touchableRegionCrop.promote(); |
| 2348 | if (info.replaceTouchableRegionWithCrop) { |
| 2349 | if (cropLayer == nullptr) { |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 2350 | info.touchableRegion = Region(toPhysicalDisplay.transform(Rect{mScreenBounds})); |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 2351 | } else { |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 2352 | info.touchableRegion = |
| 2353 | Region(toPhysicalDisplay.transform(Rect{cropLayer->mScreenBounds})); |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 2354 | } |
| 2355 | } else if (cropLayer != nullptr) { |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 2356 | info.touchableRegion = info.touchableRegion.intersect( |
| 2357 | toPhysicalDisplay.transform(Rect{cropLayer->mScreenBounds})); |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 2358 | } |
| 2359 | |
Winson Chung | a30f7c9 | 2021-06-29 15:42:56 -0700 | [diff] [blame] | 2360 | // Inherit the trusted state from the parent hierarchy, but don't clobber the trusted state |
| 2361 | // if it was set by WM for a known system overlay |
| 2362 | info.trustedOverlay = info.trustedOverlay || isTrustedOverlay(); |
| 2363 | |
| 2364 | |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2365 | // If the layer is a clone, we need to crop the input region to cloned root to prevent |
| 2366 | // touches from going outside the cloned area. |
| 2367 | if (isClone()) { |
| 2368 | sp<Layer> clonedRoot = getClonedRoot(); |
| 2369 | if (clonedRoot != nullptr) { |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 2370 | Rect rect = toPhysicalDisplay.transform(Rect{clonedRoot->mScreenBounds}); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2371 | info.touchableRegion = info.touchableRegion.intersect(rect); |
| 2372 | } |
| 2373 | } |
| 2374 | |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 2375 | return info; |
| 2376 | } |
| 2377 | |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2378 | sp<Layer> Layer::getClonedRoot() { |
| 2379 | if (mClonedChild != nullptr) { |
| 2380 | return this; |
| 2381 | } |
| 2382 | if (mDrawingParent == nullptr || mDrawingParent.promote() == nullptr) { |
| 2383 | return nullptr; |
| 2384 | } |
| 2385 | return mDrawingParent.promote()->getClonedRoot(); |
| 2386 | } |
| 2387 | |
Robert Carr | edd1360 | 2020-04-13 17:24:34 -0700 | [diff] [blame] | 2388 | bool Layer::hasInputInfo() const { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 2389 | return mDrawingState.inputInfo.token != nullptr; |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 2390 | } |
| 2391 | |
chaviw | 3e727cd | 2019-01-31 13:41:05 -0800 | [diff] [blame] | 2392 | bool Layer::canReceiveInput() const { |
Vishnu Nair | 82353e9 | 2019-09-12 12:38:47 -0700 | [diff] [blame] | 2393 | return !isHiddenByPolicy(); |
chaviw | 3e727cd | 2019-01-31 13:41:05 -0800 | [diff] [blame] | 2394 | } |
| 2395 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 2396 | compositionengine::OutputLayer* Layer::findOutputLayerForDisplay( |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 2397 | const DisplayDevice* display) const { |
| 2398 | if (!display) return nullptr; |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 2399 | return display->getCompositionDisplay()->getOutputLayerForLayer(getCompositionEngineLayerFE()); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 2400 | } |
| 2401 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 2402 | Region Layer::getVisibleRegion(const DisplayDevice* display) const { |
| 2403 | const auto outputLayer = findOutputLayerForDisplay(display); |
| 2404 | return outputLayer ? outputLayer->getState().visibleRegion : Region(); |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 2405 | } |
| 2406 | |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 2407 | void Layer::setInitialValuesForClone(const sp<Layer>& clonedFrom) { |
| 2408 | // copy drawing state from cloned layer |
| 2409 | mDrawingState = clonedFrom->mDrawingState; |
| 2410 | mClonedFrom = clonedFrom; |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 2411 | } |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 2412 | |
| 2413 | void Layer::updateMirrorInfo() { |
| 2414 | if (mClonedChild == nullptr || !mClonedChild->isClonedFromAlive()) { |
| 2415 | // If mClonedChild is null, there is nothing to mirror. If isClonedFromAlive returns false, |
| 2416 | // it means that there is a clone, but the layer it was cloned from has been destroyed. In |
| 2417 | // that case, we want to delete the reference to the clone since we want it to get |
| 2418 | // destroyed. The root, this layer, will still be around since the client can continue |
| 2419 | // to hold a reference, but no cloned layers will be displayed. |
| 2420 | mClonedChild = nullptr; |
| 2421 | return; |
| 2422 | } |
| 2423 | |
| 2424 | std::map<sp<Layer>, sp<Layer>> clonedLayersMap; |
| 2425 | // If the real layer exists and is in current state, add the clone as a child of the root. |
| 2426 | // There's no need to remove from drawingState when the layer is offscreen since currentState is |
| 2427 | // copied to drawingState for the root layer. So the clonedChild is always removed from |
| 2428 | // drawingState and then needs to be added back each traversal. |
| 2429 | if (!mClonedChild->getClonedFrom()->isRemovedFromCurrentState()) { |
| 2430 | addChildToDrawing(mClonedChild); |
| 2431 | } |
| 2432 | |
| 2433 | mClonedChild->updateClonedDrawingState(clonedLayersMap); |
| 2434 | mClonedChild->updateClonedChildren(this, clonedLayersMap); |
| 2435 | mClonedChild->updateClonedRelatives(clonedLayersMap); |
| 2436 | } |
| 2437 | |
| 2438 | void Layer::updateClonedDrawingState(std::map<sp<Layer>, sp<Layer>>& clonedLayersMap) { |
| 2439 | // If the layer the clone was cloned from is alive, copy the content of the drawingState |
| 2440 | // to the clone. If the real layer is no longer alive, continue traversing the children |
| 2441 | // since we may be able to pull out other children that are still alive. |
| 2442 | if (isClonedFromAlive()) { |
| 2443 | sp<Layer> clonedFrom = getClonedFrom(); |
| 2444 | mDrawingState = clonedFrom->mDrawingState; |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 2445 | clonedLayersMap.emplace(clonedFrom, this); |
| 2446 | } |
| 2447 | |
| 2448 | // The clone layer may have children in drawingState since they may have been created and |
| 2449 | // added from a previous request to updateMirorInfo. This is to ensure we don't recreate clones |
| 2450 | // that already exist, since we can just re-use them. |
| 2451 | // The drawingChildren will not get overwritten by the currentChildren since the clones are |
| 2452 | // not updated in the regular traversal. They are skipped since the root will lose the |
| 2453 | // reference to them when it copies its currentChildren to drawing. |
| 2454 | for (sp<Layer>& child : mDrawingChildren) { |
| 2455 | child->updateClonedDrawingState(clonedLayersMap); |
| 2456 | } |
| 2457 | } |
| 2458 | |
| 2459 | void Layer::updateClonedChildren(const sp<Layer>& mirrorRoot, |
| 2460 | std::map<sp<Layer>, sp<Layer>>& clonedLayersMap) { |
| 2461 | mDrawingChildren.clear(); |
| 2462 | |
| 2463 | if (!isClonedFromAlive()) { |
| 2464 | return; |
| 2465 | } |
| 2466 | |
| 2467 | sp<Layer> clonedFrom = getClonedFrom(); |
| 2468 | for (sp<Layer>& child : clonedFrom->mDrawingChildren) { |
| 2469 | if (child == mirrorRoot) { |
| 2470 | // This is to avoid cyclical mirroring. |
| 2471 | continue; |
| 2472 | } |
| 2473 | sp<Layer> clonedChild = clonedLayersMap[child]; |
| 2474 | if (clonedChild == nullptr) { |
| 2475 | clonedChild = child->createClone(); |
| 2476 | clonedLayersMap[child] = clonedChild; |
| 2477 | } |
| 2478 | addChildToDrawing(clonedChild); |
| 2479 | clonedChild->updateClonedChildren(mirrorRoot, clonedLayersMap); |
| 2480 | } |
| 2481 | } |
| 2482 | |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2483 | void Layer::updateClonedInputInfo(const std::map<sp<Layer>, sp<Layer>>& clonedLayersMap) { |
| 2484 | auto cropLayer = mDrawingState.touchableRegionCrop.promote(); |
| 2485 | if (cropLayer != nullptr) { |
| 2486 | if (clonedLayersMap.count(cropLayer) == 0) { |
| 2487 | // Real layer had a crop layer but it's not in the cloned hierarchy. Just set to |
| 2488 | // self as crop layer to avoid going outside bounds. |
| 2489 | mDrawingState.touchableRegionCrop = this; |
| 2490 | } else { |
| 2491 | const sp<Layer>& clonedCropLayer = clonedLayersMap.at(cropLayer); |
| 2492 | mDrawingState.touchableRegionCrop = clonedCropLayer; |
| 2493 | } |
| 2494 | } |
| 2495 | // Cloned layers shouldn't handle watch outside since their z order is not determined by |
| 2496 | // WM or the client. |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 2497 | mDrawingState.inputInfo.flags &= ~InputWindowInfo::Flag::WATCH_OUTSIDE_TOUCH; |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2498 | } |
| 2499 | |
| 2500 | void Layer::updateClonedRelatives(const std::map<sp<Layer>, sp<Layer>>& clonedLayersMap) { |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 2501 | mDrawingState.zOrderRelativeOf = nullptr; |
| 2502 | mDrawingState.zOrderRelatives.clear(); |
| 2503 | |
| 2504 | if (!isClonedFromAlive()) { |
| 2505 | return; |
| 2506 | } |
| 2507 | |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2508 | const sp<Layer>& clonedFrom = getClonedFrom(); |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 2509 | for (wp<Layer>& relativeWeak : clonedFrom->mDrawingState.zOrderRelatives) { |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2510 | const sp<Layer>& relative = relativeWeak.promote(); |
| 2511 | if (clonedLayersMap.count(relative) > 0) { |
| 2512 | auto& clonedRelative = clonedLayersMap.at(relative); |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 2513 | mDrawingState.zOrderRelatives.add(clonedRelative); |
| 2514 | } |
| 2515 | } |
| 2516 | |
| 2517 | // Check if the relativeLayer for the real layer is part of the cloned hierarchy. |
| 2518 | // It's possible that the layer it's relative to is outside the requested cloned hierarchy. |
| 2519 | // In that case, we treat the layer as if the relativeOf has been removed. This way, it will |
| 2520 | // still traverse the children, but the layer with the missing relativeOf will not be shown |
| 2521 | // on screen. |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2522 | const sp<Layer>& relativeOf = clonedFrom->mDrawingState.zOrderRelativeOf.promote(); |
| 2523 | if (clonedLayersMap.count(relativeOf) > 0) { |
| 2524 | const sp<Layer>& clonedRelativeOf = clonedLayersMap.at(relativeOf); |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 2525 | mDrawingState.zOrderRelativeOf = clonedRelativeOf; |
| 2526 | } |
| 2527 | |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2528 | updateClonedInputInfo(clonedLayersMap); |
| 2529 | |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 2530 | for (sp<Layer>& child : mDrawingChildren) { |
| 2531 | child->updateClonedRelatives(clonedLayersMap); |
| 2532 | } |
| 2533 | } |
| 2534 | |
| 2535 | void Layer::addChildToDrawing(const sp<Layer>& layer) { |
| 2536 | mDrawingChildren.add(layer); |
| 2537 | layer->mDrawingParent = this; |
| 2538 | } |
| 2539 | |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 2540 | Layer::FrameRateCompatibility Layer::FrameRate::convertCompatibility(int8_t compatibility) { |
| 2541 | switch (compatibility) { |
| 2542 | case ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT: |
| 2543 | return FrameRateCompatibility::Default; |
| 2544 | case ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE: |
| 2545 | return FrameRateCompatibility::ExactOrMultiple; |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 2546 | case ANATIVEWINDOW_FRAME_RATE_EXACT: |
| 2547 | return FrameRateCompatibility::Exact; |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 2548 | default: |
| 2549 | LOG_ALWAYS_FATAL("Invalid frame rate compatibility value %d", compatibility); |
| 2550 | return FrameRateCompatibility::Default; |
| 2551 | } |
| 2552 | } |
| 2553 | |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 2554 | scheduler::Seamlessness Layer::FrameRate::convertChangeFrameRateStrategy(int8_t strategy) { |
| 2555 | switch (strategy) { |
| 2556 | case ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS: |
| 2557 | return Seamlessness::OnlySeamless; |
| 2558 | case ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS: |
| 2559 | return Seamlessness::SeamedAndSeamless; |
| 2560 | default: |
| 2561 | LOG_ALWAYS_FATAL("Invalid change frame sate strategy value %d", strategy); |
| 2562 | return Seamlessness::Default; |
| 2563 | } |
| 2564 | } |
| 2565 | |
chaviw | c5676c6 | 2020-09-18 15:01:04 -0700 | [diff] [blame] | 2566 | bool Layer::getPrimaryDisplayOnly() const { |
| 2567 | const State& s(mDrawingState); |
| 2568 | if (s.flags & layer_state_t::eLayerSkipScreenshot) { |
| 2569 | return true; |
| 2570 | } |
| 2571 | |
| 2572 | sp<Layer> parent = mDrawingParent.promote(); |
| 2573 | return parent == nullptr ? false : parent->getPrimaryDisplayOnly(); |
| 2574 | } |
| 2575 | |
binzhang | 174ac1e | 2021-06-28 14:17:33 +0800 | [diff] [blame] | 2576 | nsecs_t Layer::getPreviousGfxInfo() { |
| 2577 | return mFrameTracker.getPreviousGfxInfo(); |
| 2578 | } |
| 2579 | |
Robert Carr | 6a0382d | 2021-07-01 15:57:17 -0700 | [diff] [blame] | 2580 | void Layer::setClonedChild(const sp<Layer>& clonedChild) { |
| 2581 | mClonedChild = clonedChild; |
| 2582 | mHadClonedChild = true; |
| 2583 | mFlinger->mNumClones++; |
| 2584 | } |
| 2585 | |
Vishnu Nair | a8c7c54 | 2021-07-20 18:49:42 -0700 | [diff] [blame] | 2586 | const String16 Layer::Handle::kDescriptor = String16("android.Layer.Handle"); |
| 2587 | |
| 2588 | wp<Layer> Layer::fromHandle(const sp<IBinder>& handleBinder) { |
| 2589 | if (handleBinder == nullptr) { |
| 2590 | return nullptr; |
| 2591 | } |
| 2592 | |
| 2593 | BBinder* b = handleBinder->localBinder(); |
| 2594 | if (b == nullptr || b->getInterfaceDescriptor() != Handle::kDescriptor) { |
| 2595 | return nullptr; |
| 2596 | } |
| 2597 | |
| 2598 | // We can safely cast this binder since its local and we verified its interface descriptor. |
| 2599 | sp<Handle> handle = static_cast<Handle*>(handleBinder.get()); |
| 2600 | return handle->owner; |
| 2601 | } |
| 2602 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2603 | // --------------------------------------------------------------------------- |
| 2604 | |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 2605 | std::ostream& operator<<(std::ostream& stream, const Layer::FrameRate& rate) { |
| 2606 | return stream << "{rate=" << rate.rate |
| 2607 | << " type=" << Layer::frameRateCompatibilityString(rate.type) |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 2608 | << " seamlessness=" << toString(rate.seamlessness) << "}"; |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 2609 | } |
| 2610 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2611 | }; // namespace android |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 2612 | |
| 2613 | #if defined(__gl_h_) |
| 2614 | #error "don't include gl/gl.h in this file" |
| 2615 | #endif |
| 2616 | |
| 2617 | #if defined(__gl2_h_) |
| 2618 | #error "don't include gl2/gl2.h in this file" |
| 2619 | #endif |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 2620 | |
| 2621 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 2622 | #pragma clang diagnostic pop // ignored "-Wconversion" |