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