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