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