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