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