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