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