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