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