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