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