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