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