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