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