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