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