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