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 | |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wconversion" |
| 20 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 21 | //#define LOG_NDEBUG 0 |
| 22 | #undef LOG_TAG |
| 23 | #define LOG_TAG "Layer" |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 24 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 25 | |
Alec Mouri | e60041e | 2019-06-14 18:59:51 -0700 | [diff] [blame] | 26 | #include "Layer.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 28 | #include <android-base/properties.h> |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 29 | #include <android-base/stringprintf.h> |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 30 | #include <android/native_window.h> |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 31 | #include <binder/IPCThreadState.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 32 | #include <compositionengine/Display.h> |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 33 | #include <compositionengine/LayerFECompositionState.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 34 | #include <compositionengine/OutputLayer.h> |
| 35 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 36 | #include <cutils/compiler.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 37 | #include <cutils/native_handle.h> |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 38 | #include <cutils/properties.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 39 | #include <gui/BufferItem.h> |
| 40 | #include <gui/LayerDebugInfo.h> |
| 41 | #include <gui/Surface.h> |
Alec Mouri | e60041e | 2019-06-14 18:59:51 -0700 | [diff] [blame] | 42 | #include <math.h> |
chaviw | 250bcbb | 2020-08-05 11:17:54 -0700 | [diff] [blame] | 43 | #include <private/android_filesystem_config.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 44 | #include <renderengine/RenderEngine.h> |
Alec Mouri | e60041e | 2019-06-14 18:59:51 -0700 | [diff] [blame] | 45 | #include <stdint.h> |
| 46 | #include <stdlib.h> |
| 47 | #include <sys/types.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 48 | #include <ui/DebugUtils.h> |
| 49 | #include <ui/GraphicBuffer.h> |
| 50 | #include <ui/PixelFormat.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | #include <utils/Errors.h> |
| 52 | #include <utils/Log.h> |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 53 | #include <utils/NativeHandle.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | #include <utils/StopWatch.h> |
Jamie Gennis | 1c8e95c | 2012-02-23 19:27:23 -0800 | [diff] [blame] | 55 | #include <utils/Trace.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | |
Alec Mouri | e60041e | 2019-06-14 18:59:51 -0700 | [diff] [blame] | 57 | #include <algorithm> |
| 58 | #include <mutex> |
| 59 | #include <sstream> |
| 60 | |
Yiwei Zhang | 60d1a19 | 2018-03-07 14:52:28 -0800 | [diff] [blame] | 61 | #include "BufferLayer.h" |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 62 | #include "Colorizer.h" |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 63 | #include "DisplayDevice.h" |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 64 | #include "DisplayHardware/HWComposer.h" |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 65 | #include "EffectLayer.h" |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 66 | #include "FrameTimeline.h" |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 67 | #include "FrameTracer/FrameTracer.h" |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 68 | #include "LayerProtoHelper.h" |
Fabien Sanglard | 7b1563a | 2016-10-13 12:05:28 -0700 | [diff] [blame] | 69 | #include "LayerRejecter.h" |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 70 | #include "MonitoredProducer.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | #include "SurfaceFlinger.h" |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 72 | #include "TimeStats/TimeStats.h" |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 73 | #include "input/InputWindow.h" |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 74 | |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 75 | #define DEBUG_RESIZE 0 |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | namespace android { |
Marin Shalamanov | 1876e2e | 2020-12-04 13:23:59 +0100 | [diff] [blame] | 78 | namespace { |
| 79 | constexpr int kDumpTableRowLength = 159; |
| 80 | } // namespace |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 82 | using base::StringAppendF; |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 83 | using namespace android::flag_operators; |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 84 | using PresentState = frametimeline::SurfaceFrame::PresentState; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 85 | |
Lloyd Pique | f1c675b | 2018-09-12 20:45:39 -0700 | [diff] [blame] | 86 | std::atomic<int32_t> Layer::sSequence{1}; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 87 | |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 88 | Layer::Layer(const LayerCreationArgs& args) |
Ady Abraham | 8f1ee7f | 2019-04-05 10:32:50 -0700 | [diff] [blame] | 89 | : mFlinger(args.flinger), |
| 90 | mName(args.name), |
| 91 | mClientRef(args.client), |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 92 | mWindowType(static_cast<InputWindowInfo::Type>( |
| 93 | args.metadata.getInt32(METADATA_WINDOW_TYPE, 0))) { |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 94 | uint32_t layerFlags = 0; |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 95 | if (args.flags & ISurfaceComposerClient::eHidden) layerFlags |= layer_state_t::eLayerHidden; |
| 96 | if (args.flags & ISurfaceComposerClient::eOpaque) layerFlags |= layer_state_t::eLayerOpaque; |
| 97 | if (args.flags & ISurfaceComposerClient::eSecure) layerFlags |= layer_state_t::eLayerSecure; |
chaviw | c5676c6 | 2020-09-18 15:01:04 -0700 | [diff] [blame] | 98 | if (args.flags & ISurfaceComposerClient::eSkipScreenshot) |
| 99 | layerFlags |= layer_state_t::eLayerSkipScreenshot; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 100 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 101 | mCurrentState.active_legacy.w = args.w; |
| 102 | mCurrentState.active_legacy.h = args.h; |
| 103 | mCurrentState.flags = layerFlags; |
| 104 | mCurrentState.active_legacy.transform.set(0, 0); |
chaviw | 2571450 | 2021-02-11 10:01:08 -0800 | [diff] [blame] | 105 | mCurrentState.crop.makeInvalid(); |
| 106 | mCurrentState.requestedCrop = mCurrentState.crop; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 107 | mCurrentState.z = 0; |
| 108 | mCurrentState.color.a = 1.0f; |
| 109 | mCurrentState.layerStack = 0; |
| 110 | mCurrentState.sequence = 0; |
| 111 | mCurrentState.requested_legacy = mCurrentState.active_legacy; |
chaviw | 766c9c5 | 2021-02-10 17:36:47 -0800 | [diff] [blame] | 112 | mCurrentState.width = UINT32_MAX; |
| 113 | mCurrentState.height = UINT32_MAX; |
| 114 | mCurrentState.transform.set(0, 0); |
Valerie Hau | 134651a | 2020-01-28 16:21:22 -0800 | [diff] [blame] | 115 | mCurrentState.frameNumber = 0; |
chaviw | 766c9c5 | 2021-02-10 17:36:47 -0800 | [diff] [blame] | 116 | mCurrentState.bufferTransform = 0; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 117 | mCurrentState.transformToDisplayInverse = false; |
| 118 | mCurrentState.crop.makeInvalid(); |
Ady Abraham | 6c1b7ac | 2021-03-31 16:56:03 -0700 | [diff] [blame] | 119 | mCurrentState.acquireFence = sp<Fence>::make(-1); |
| 120 | mCurrentState.acquireFenceTime = std::make_shared<FenceTime>(mCurrentState.acquireFence); |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 121 | mCurrentState.dataspace = ui::Dataspace::UNKNOWN; |
| 122 | mCurrentState.hdrMetadata.validTypes = 0; |
Marissa Wall | 7e0a01f | 2019-08-14 14:29:25 -0700 | [diff] [blame] | 123 | mCurrentState.surfaceDamageRegion = Region::INVALID_REGION; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 124 | mCurrentState.cornerRadius = 0.0f; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 125 | mCurrentState.backgroundBlurRadius = 0; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 126 | mCurrentState.api = -1; |
| 127 | mCurrentState.hasColorTransform = false; |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 128 | mCurrentState.colorSpaceAgnostic = false; |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 129 | mCurrentState.frameRateSelectionPriority = PRIORITY_UNSET; |
Evan Rosky | a1f1e15 | 2019-01-24 16:17:46 -0800 | [diff] [blame] | 130 | mCurrentState.metadata = args.metadata; |
Vishnu Nair | f37dcfb | 2019-11-16 07:37:09 -0800 | [diff] [blame] | 131 | mCurrentState.shadowRadius = 0.f; |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 132 | mCurrentState.fixedTransformHint = ui::Transform::ROT_INVALID; |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 133 | mCurrentState.frameTimelineInfo = {}; |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 134 | mCurrentState.postTime = -1; |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 135 | mCurrentState.destinationFrame.makeInvalid(); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 136 | |
Vishnu Nair | c43a23c | 2020-05-29 14:32:27 -0700 | [diff] [blame] | 137 | if (args.flags & ISurfaceComposerClient::eNoColorFill) { |
| 138 | // Set an invalid color so there is no color fill. |
| 139 | mCurrentState.color.r = -1.0_hf; |
| 140 | mCurrentState.color.g = -1.0_hf; |
| 141 | mCurrentState.color.b = -1.0_hf; |
| 142 | } |
| 143 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 144 | // drawing state & current state are identical |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 145 | mDrawingState = mCurrentState; |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 146 | |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 147 | CompositorTiming compositorTiming; |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 148 | args.flinger->getCompositorTiming(&compositorTiming); |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 149 | mFrameEventHistory.initializeCompositorTiming(compositorTiming); |
Jorim Jaggi | bd6480f | 2018-08-10 14:37:31 +0200 | [diff] [blame] | 150 | mFrameTracker.setDisplayRefreshPeriod(compositorTiming.interval); |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 151 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 152 | mCallingPid = args.callingPid; |
| 153 | mCallingUid = args.callingUid; |
chaviw | 250bcbb | 2020-08-05 11:17:54 -0700 | [diff] [blame] | 154 | |
| 155 | if (mCallingUid == AID_GRAPHICS || mCallingUid == AID_SYSTEM) { |
| 156 | // If the system didn't send an ownerUid, use the callingUid for the ownerUid. |
| 157 | mOwnerUid = args.metadata.getInt32(METADATA_OWNER_UID, mCallingUid); |
Adithya Srinivasan | 9febda8 | 2020-10-19 10:49:41 -0700 | [diff] [blame] | 158 | mOwnerPid = args.metadata.getInt32(METADATA_OWNER_PID, mCallingPid); |
chaviw | 250bcbb | 2020-08-05 11:17:54 -0700 | [diff] [blame] | 159 | } else { |
| 160 | // A create layer request from a non system request cannot specify the owner uid |
| 161 | mOwnerUid = mCallingUid; |
Adithya Srinivasan | 9febda8 | 2020-10-19 10:49:41 -0700 | [diff] [blame] | 162 | mOwnerPid = mCallingPid; |
chaviw | 250bcbb | 2020-08-05 11:17:54 -0700 | [diff] [blame] | 163 | } |
Dominik Laskowski | 7584836 | 2019-11-11 17:57:20 -0800 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | void Layer::onFirstRef() { |
| 167 | mFlinger->onLayerFirstRef(this); |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 168 | } |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 169 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 170 | Layer::~Layer() { |
David Sodman | 577c896 | 2017-12-08 14:50:53 -0800 | [diff] [blame] | 171 | sp<Client> c(mClientRef.promote()); |
| 172 | if (c != 0) { |
| 173 | c->detachLayer(this); |
| 174 | } |
| 175 | |
Jorim Jaggi | 10c985e | 2018-10-23 11:17:45 +0000 | [diff] [blame] | 176 | mFrameTracker.logAndResetStats(mName); |
chaviw | 74d90ad | 2019-04-26 14:45:26 -0700 | [diff] [blame] | 177 | mFlinger->onLayerDestroyed(this); |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 180 | LayerCreationArgs::LayerCreationArgs(SurfaceFlinger* flinger, sp<Client> client, std::string name, |
| 181 | uint32_t w, uint32_t h, uint32_t flags, LayerMetadata metadata) |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 182 | : flinger(flinger), |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 183 | client(std::move(client)), |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 184 | name(std::move(name)), |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 185 | w(w), |
| 186 | h(h), |
| 187 | flags(flags), |
| 188 | metadata(std::move(metadata)) { |
| 189 | IPCThreadState* ipc = IPCThreadState::self(); |
| 190 | callingPid = ipc->getCallingPid(); |
| 191 | callingUid = ipc->getCallingUid(); |
| 192 | } |
| 193 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 194 | // --------------------------------------------------------------------------- |
| 195 | // callbacks |
| 196 | // --------------------------------------------------------------------------- |
| 197 | |
David Sodman | eb085e0 | 2017-10-05 18:49:04 -0700 | [diff] [blame] | 198 | /* |
| 199 | * onLayerDisplayed is only meaningful for BufferLayer, but, is called through |
| 200 | * Layer. So, the implementation is done in BufferLayer. When called on a |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 201 | * EffectLayer object, it's essentially a NOP. |
David Sodman | eb085e0 | 2017-10-05 18:49:04 -0700 | [diff] [blame] | 202 | */ |
David Sodman | eb085e0 | 2017-10-05 18:49:04 -0700 | [diff] [blame] | 203 | void Layer::onLayerDisplayed(const sp<Fence>& /*releaseFence*/) {} |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 204 | |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 205 | void Layer::removeRelativeZ(const std::vector<Layer*>& layersInTree) { |
| 206 | if (mCurrentState.zOrderRelativeOf == nullptr) { |
| 207 | return; |
| 208 | } |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 209 | |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 210 | sp<Layer> strongRelative = mCurrentState.zOrderRelativeOf.promote(); |
| 211 | if (strongRelative == nullptr) { |
| 212 | setZOrderRelativeOf(nullptr); |
| 213 | return; |
| 214 | } |
| 215 | |
| 216 | if (!std::binary_search(layersInTree.begin(), layersInTree.end(), strongRelative.get())) { |
| 217 | strongRelative->removeZOrderRelative(this); |
| 218 | mFlinger->setTransactionFlags(eTraversalNeeded); |
chaviw | 606e5cf | 2019-03-01 10:12:10 -0800 | [diff] [blame] | 219 | setZOrderRelativeOf(nullptr); |
Robert Carr | 5edb1ad | 2017-04-25 10:54:24 -0700 | [diff] [blame] | 220 | } |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | void Layer::removeFromCurrentState() { |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 224 | if (!mRemovedFromCurrentState) { |
| 225 | mRemovedFromCurrentState = true; |
| 226 | mFlinger->mScheduler->deregisterLayer(this); |
| 227 | } |
Rob Carr | 4bba370 | 2018-10-08 21:53:30 +0000 | [diff] [blame] | 228 | |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 229 | mFlinger->markLayerPendingRemovalLocked(this); |
Chia-I Wu | c665702 | 2017-08-15 11:18:17 -0700 | [diff] [blame] | 230 | } |
Chia-I Wu | 3851225 | 2017-05-17 14:36:16 -0700 | [diff] [blame] | 231 | |
chaviw | 68d4dab | 2020-06-08 15:07:32 -0700 | [diff] [blame] | 232 | sp<Layer> Layer::getRootLayer() { |
| 233 | sp<Layer> parent = getParent(); |
| 234 | if (parent == nullptr) { |
| 235 | return this; |
| 236 | } |
| 237 | return parent->getRootLayer(); |
| 238 | } |
| 239 | |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 240 | void Layer::onRemovedFromCurrentState() { |
chaviw | 68d4dab | 2020-06-08 15:07:32 -0700 | [diff] [blame] | 241 | // Use the root layer since we want to maintain the hierarchy for the entire subtree. |
| 242 | auto layersInTree = getRootLayer()->getLayersInTree(LayerVector::StateSet::Current); |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 243 | std::sort(layersInTree.begin(), layersInTree.end()); |
chaviw | 68d4dab | 2020-06-08 15:07:32 -0700 | [diff] [blame] | 244 | |
| 245 | traverse(LayerVector::StateSet::Current, [&](Layer* layer) { |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 246 | layer->removeFromCurrentState(); |
| 247 | layer->removeRelativeZ(layersInTree); |
chaviw | 68d4dab | 2020-06-08 15:07:32 -0700 | [diff] [blame] | 248 | }); |
Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 249 | } |
| 250 | |
chaviw | 61626f2 | 2018-11-15 16:26:27 -0800 | [diff] [blame] | 251 | void Layer::addToCurrentState() { |
Ady Abraham | be09aad | 2021-05-03 18:59:38 -0700 | [diff] [blame] | 252 | if (mRemovedFromCurrentState) { |
| 253 | mRemovedFromCurrentState = false; |
| 254 | mFlinger->mScheduler->registerLayer(this); |
| 255 | } |
chaviw | 61626f2 | 2018-11-15 16:26:27 -0800 | [diff] [blame] | 256 | |
| 257 | for (const auto& child : mCurrentChildren) { |
| 258 | child->addToCurrentState(); |
| 259 | } |
| 260 | } |
| 261 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 262 | // --------------------------------------------------------------------------- |
| 263 | // set-up |
| 264 | // --------------------------------------------------------------------------- |
| 265 | |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 266 | bool Layer::getPremultipledAlpha() const { |
| 267 | return mPremultipliedAlpha; |
| 268 | } |
| 269 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 270 | sp<IBinder> Layer::getHandle() { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 271 | Mutex::Autolock _l(mLock); |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 272 | if (mGetHandleCalled) { |
| 273 | ALOGE("Get handle called twice" ); |
| 274 | return nullptr; |
| 275 | } |
| 276 | mGetHandleCalled = true; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 277 | return new Handle(mFlinger, this); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | // --------------------------------------------------------------------------- |
| 281 | // h/w composer set-up |
| 282 | // --------------------------------------------------------------------------- |
| 283 | |
Mathias Agopian | f3e85d4 | 2013-05-10 18:01:12 -0700 | [diff] [blame] | 284 | static Rect reduce(const Rect& win, const Region& exclude) { |
| 285 | if (CC_LIKELY(exclude.isEmpty())) { |
| 286 | return win; |
| 287 | } |
| 288 | if (exclude.isRect()) { |
| 289 | return win.reduce(exclude.getBounds()); |
| 290 | } |
| 291 | return Region(win).subtract(exclude).getBounds(); |
| 292 | } |
| 293 | |
Dan Stoza | 80d6116 | 2017-12-20 15:57:52 -0800 | [diff] [blame] | 294 | static FloatRect reduce(const FloatRect& win, const Region& exclude) { |
| 295 | if (CC_LIKELY(exclude.isEmpty())) { |
| 296 | return win; |
| 297 | } |
| 298 | // Convert through Rect (by rounding) for lack of FloatRegion |
| 299 | return Region(Rect{win}).subtract(exclude).getBounds().toFloatRect(); |
| 300 | } |
| 301 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 302 | Rect Layer::getScreenBounds(bool reduceTransparentRegion) const { |
Vishnu Nair | f0c2851 | 2019-02-08 12:40:28 -0800 | [diff] [blame] | 303 | if (!reduceTransparentRegion) { |
| 304 | return Rect{mScreenBounds}; |
| 305 | } |
| 306 | |
| 307 | FloatRect bounds = getBounds(); |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 308 | ui::Transform t = getTransform(); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 309 | // Transform to screen space. |
| 310 | bounds = t.transform(bounds); |
| 311 | return Rect{bounds}; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 314 | FloatRect Layer::getBounds() const { |
Alec Mouri | b416efd | 2018-09-06 21:01:59 +0000 | [diff] [blame] | 315 | const State& s(getDrawingState()); |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 316 | return getBounds(getActiveTransparentRegion(s)); |
Michael Lentine | 6c925ed | 2014-09-26 17:55:01 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Vishnu Nair | f0c2851 | 2019-02-08 12:40:28 -0800 | [diff] [blame] | 319 | FloatRect Layer::getBounds(const Region& activeTransparentRegion) const { |
| 320 | // Subtract the transparent region and snap to the bounds. |
| 321 | return reduce(mBounds, activeTransparentRegion); |
| 322 | } |
| 323 | |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 324 | void Layer::computeBounds(FloatRect parentBounds, ui::Transform parentTransform, |
| 325 | float parentShadowRadius) { |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 326 | const State& s(getDrawingState()); |
| 327 | |
| 328 | // Calculate effective layer transform |
| 329 | mEffectiveTransform = parentTransform * getActiveTransform(s); |
| 330 | |
| 331 | // Transform parent bounds to layer space |
| 332 | parentBounds = getActiveTransform(s).inverse().transform(parentBounds); |
| 333 | |
Vishnu Nair | c652ff8 | 2019-03-15 12:48:54 -0700 | [diff] [blame] | 334 | // Calculate source bounds |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 335 | mSourceBounds = computeSourceBounds(parentBounds); |
| 336 | |
| 337 | // Calculate bounds by croping diplay frame with layer crop and parent bounds |
| 338 | FloatRect bounds = mSourceBounds; |
| 339 | const Rect layerCrop = getCrop(s); |
| 340 | if (!layerCrop.isEmpty()) { |
| 341 | bounds = mSourceBounds.intersect(layerCrop.toFloatRect()); |
| 342 | } |
| 343 | bounds = bounds.intersect(parentBounds); |
| 344 | |
| 345 | mBounds = bounds; |
| 346 | mScreenBounds = mEffectiveTransform.transform(mBounds); |
Vishnu Nair | c652ff8 | 2019-03-15 12:48:54 -0700 | [diff] [blame] | 347 | |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 348 | // Use the layer's own shadow radius if set. Otherwise get the radius from |
| 349 | // parent. |
| 350 | if (s.shadowRadius > 0.f) { |
| 351 | mEffectiveShadowRadius = s.shadowRadius; |
| 352 | } else { |
| 353 | mEffectiveShadowRadius = parentShadowRadius; |
| 354 | } |
| 355 | |
| 356 | // Shadow radius is passed down to only one layer so if the layer can draw shadows, |
| 357 | // don't pass it to its children. |
| 358 | const float childShadowRadius = canDrawShadows() ? 0.f : mEffectiveShadowRadius; |
| 359 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 360 | for (const sp<Layer>& child : mDrawingChildren) { |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 361 | child->computeBounds(mBounds, mEffectiveTransform, childShadowRadius); |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 365 | Rect Layer::getCroppedBufferSize(const State& s) const { |
| 366 | Rect size = getBufferSize(s); |
| 367 | Rect crop = getCrop(s); |
| 368 | if (!crop.isEmpty() && size.isValid()) { |
| 369 | size.intersect(crop, &size); |
| 370 | } else if (!crop.isEmpty()) { |
| 371 | size = crop; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 372 | } |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 373 | return size; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 374 | } |
| 375 | |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 376 | void Layer::setupRoundedCornersCropCoordinates(Rect win, |
| 377 | const FloatRect& roundedCornersCrop) const { |
| 378 | // Translate win by the rounded corners rect coordinates, to have all values in |
| 379 | // layer coordinate space. |
| 380 | win.left -= roundedCornersCrop.left; |
| 381 | win.right -= roundedCornersCrop.left; |
| 382 | win.top -= roundedCornersCrop.top; |
| 383 | win.bottom -= roundedCornersCrop.top; |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 384 | } |
| 385 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 386 | void Layer::prepareBasicGeometryCompositionState() { |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 387 | const auto& drawingState{getDrawingState()}; |
| 388 | const uint32_t layerStack = getLayerStack(); |
| 389 | const auto alpha = static_cast<float>(getAlpha()); |
| 390 | const bool opaque = isOpaque(drawingState); |
| 391 | const bool usesRoundedCorners = getRoundedCornerState().radius != 0.f; |
| 392 | |
| 393 | auto blendMode = Hwc2::IComposerClient::BlendMode::NONE; |
| 394 | if (!opaque || alpha != 1.0f) { |
| 395 | blendMode = mPremultipliedAlpha ? Hwc2::IComposerClient::BlendMode::PREMULTIPLIED |
| 396 | : Hwc2::IComposerClient::BlendMode::COVERAGE; |
| 397 | } |
| 398 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 399 | auto* compositionState = editCompositionState(); |
| 400 | compositionState->layerStackId = |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 401 | (layerStack != ~0u) ? std::make_optional(layerStack) : std::nullopt; |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 402 | compositionState->internalOnly = getPrimaryDisplayOnly(); |
| 403 | compositionState->isVisible = isVisible(); |
| 404 | compositionState->isOpaque = opaque && !usesRoundedCorners && alpha == 1.f; |
| 405 | compositionState->shadowRadius = mEffectiveShadowRadius; |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 406 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 407 | compositionState->contentDirty = contentDirty; |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 408 | contentDirty = false; |
| 409 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 410 | compositionState->geomLayerBounds = mBounds; |
| 411 | compositionState->geomLayerTransform = getTransform(); |
| 412 | compositionState->geomInverseLayerTransform = compositionState->geomLayerTransform.inverse(); |
| 413 | compositionState->transparentRegionHint = getActiveTransparentRegion(drawingState); |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 414 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 415 | compositionState->blendMode = static_cast<Hwc2::IComposerClient::BlendMode>(blendMode); |
| 416 | compositionState->alpha = alpha; |
| 417 | compositionState->backgroundBlurRadius = drawingState.backgroundBlurRadius; |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 418 | compositionState->blurRegions = drawingState.blurRegions; |
John Reck | c00c669 | 2021-02-16 11:37:33 -0500 | [diff] [blame] | 419 | compositionState->stretchEffect = getStretchEffect(); |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 420 | } |
| 421 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 422 | void Layer::prepareGeometryCompositionState() { |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 423 | const auto& drawingState{getDrawingState()}; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 424 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 425 | int type = drawingState.metadata.getInt32(METADATA_WINDOW_TYPE, 0); |
| 426 | int appId = drawingState.metadata.getInt32(METADATA_OWNER_UID, 0); |
Chia-I Wu | e41dbe6 | 2017-06-13 14:10:56 -0700 | [diff] [blame] | 427 | sp<Layer> parent = mDrawingParent.promote(); |
Albert Chaulk | 2a58963 | 2017-05-04 16:59:44 -0400 | [diff] [blame] | 428 | if (parent.get()) { |
| 429 | auto& parentState = parent->getDrawingState(); |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 430 | const int parentType = parentState.metadata.getInt32(METADATA_WINDOW_TYPE, 0); |
| 431 | const int parentAppId = parentState.metadata.getInt32(METADATA_OWNER_UID, 0); |
Jiwen 'Steve' Cai | 736c74e | 2019-05-28 18:33:22 -0700 | [diff] [blame] | 432 | if (parentType > 0 && parentAppId > 0) { |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 433 | type = parentType; |
| 434 | appId = parentAppId; |
rongliu | cfb187b | 2018-03-14 12:26:23 -0700 | [diff] [blame] | 435 | } |
Albert Chaulk | 2a58963 | 2017-05-04 16:59:44 -0400 | [diff] [blame] | 436 | } |
| 437 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 438 | auto* compositionState = editCompositionState(); |
David Sodman | 1509411 | 2018-10-11 09:39:37 -0700 | [diff] [blame] | 439 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 440 | compositionState->geomBufferSize = getBufferSize(drawingState); |
| 441 | compositionState->geomContentCrop = getBufferCrop(); |
| 442 | compositionState->geomCrop = getCrop(drawingState); |
| 443 | compositionState->geomBufferTransform = getBufferTransform(); |
| 444 | compositionState->geomBufferUsesDisplayInverseTransform = getTransformToDisplayInverse(); |
| 445 | compositionState->geomUsesSourceCrop = usesSourceCrop(); |
| 446 | compositionState->isSecure = isSecure(); |
| 447 | |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 448 | compositionState->metadata.clear(); |
| 449 | const auto& supportedMetadata = mFlinger->getHwComposer().getSupportedLayerGenericMetadata(); |
| 450 | for (const auto& [key, mandatory] : supportedMetadata) { |
| 451 | const auto& genericLayerMetadataCompatibilityMap = |
| 452 | mFlinger->getGenericLayerMetadataKeyMap(); |
| 453 | auto compatIter = genericLayerMetadataCompatibilityMap.find(key); |
| 454 | if (compatIter == std::end(genericLayerMetadataCompatibilityMap)) { |
| 455 | continue; |
| 456 | } |
| 457 | const uint32_t id = compatIter->second; |
| 458 | |
| 459 | auto it = drawingState.metadata.mMap.find(id); |
| 460 | if (it == std::end(drawingState.metadata.mMap)) { |
| 461 | continue; |
| 462 | } |
| 463 | |
| 464 | compositionState->metadata |
| 465 | .emplace(key, compositionengine::GenericLayerMetadataEntry{mandatory, it->second}); |
| 466 | } |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 467 | } |
David Sodman | ba34049 | 2018-08-05 21:51:33 -0700 | [diff] [blame] | 468 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 469 | void Layer::preparePerFrameCompositionState() { |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 470 | const auto& drawingState{getDrawingState()}; |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 471 | auto* compositionState = editCompositionState(); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 472 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 473 | compositionState->forceClientComposition = false; |
| 474 | |
| 475 | compositionState->isColorspaceAgnostic = isColorSpaceAgnostic(); |
| 476 | compositionState->dataspace = getDataSpace(); |
| 477 | compositionState->colorTransform = getColorTransform(); |
| 478 | compositionState->colorTransformIsIdentity = !hasColorTransform(); |
| 479 | compositionState->surfaceDamage = surfaceDamageRegion; |
| 480 | compositionState->hasProtectedContent = isProtected(); |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 481 | |
| 482 | const bool usesRoundedCorners = getRoundedCornerState().radius != 0.f; |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 483 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 484 | compositionState->isOpaque = |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 485 | isOpaque(drawingState) && !usesRoundedCorners && getAlpha() == 1.0_hf; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 486 | |
| 487 | // Force client composition for special cases known only to the front-end. |
Leon Scroggins III | d305ef2 | 2021-04-06 09:53:26 -0400 | [diff] [blame] | 488 | // Rounded corners no longer force client composition, since we may use a |
| 489 | // hole punch so that the layer will appear to have rounded corners. |
| 490 | if (isHdrY410() || drawShadows() || drawingState.blurRegions.size() > 0 || |
John Reck | c00c669 | 2021-02-16 11:37:33 -0500 | [diff] [blame] | 491 | compositionState->stretchEffect.hasEffect()) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 492 | compositionState->forceClientComposition = true; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 493 | } |
| 494 | } |
| 495 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 496 | void Layer::prepareCursorCompositionState() { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 497 | const State& drawingState{getDrawingState()}; |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 498 | auto* compositionState = editCompositionState(); |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 499 | |
| 500 | // Apply the layer's transform, followed by the display's global transform |
| 501 | // Here we're guaranteed that the layer's transform preserves rects |
| 502 | Rect win = getCroppedBufferSize(drawingState); |
| 503 | // Subtract the transparent region and snap to the bounds |
| 504 | Rect bounds = reduce(win, getActiveTransparentRegion(drawingState)); |
| 505 | Rect frame(getTransform().transform(bounds)); |
| 506 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 507 | compositionState->cursorFrame = frame; |
| 508 | } |
| 509 | |
| 510 | sp<compositionengine::LayerFE> Layer::asLayerFE() const { |
| 511 | return const_cast<compositionengine::LayerFE*>( |
| 512 | static_cast<const compositionengine::LayerFE*>(this)); |
| 513 | } |
| 514 | |
| 515 | sp<compositionengine::LayerFE> Layer::getCompositionEngineLayerFE() const { |
| 516 | return nullptr; |
| 517 | } |
| 518 | |
| 519 | compositionengine::LayerFECompositionState* Layer::editCompositionState() { |
| 520 | return nullptr; |
| 521 | } |
| 522 | |
| 523 | const compositionengine::LayerFECompositionState* Layer::getCompositionState() const { |
| 524 | return nullptr; |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 525 | } |
| 526 | |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 527 | bool Layer::onPreComposition(nsecs_t) { |
| 528 | return false; |
| 529 | } |
| 530 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 531 | void Layer::prepareCompositionState(compositionengine::LayerFE::StateSubset subset) { |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 532 | using StateSubset = compositionengine::LayerFE::StateSubset; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 533 | |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 534 | switch (subset) { |
| 535 | case StateSubset::BasicGeometry: |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 536 | prepareBasicGeometryCompositionState(); |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 537 | break; |
| 538 | |
| 539 | case StateSubset::GeometryAndContent: |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 540 | prepareBasicGeometryCompositionState(); |
| 541 | prepareGeometryCompositionState(); |
| 542 | preparePerFrameCompositionState(); |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 543 | break; |
| 544 | |
| 545 | case StateSubset::Content: |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 546 | preparePerFrameCompositionState(); |
| 547 | break; |
| 548 | |
| 549 | case StateSubset::Cursor: |
| 550 | prepareCursorCompositionState(); |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 551 | break; |
| 552 | } |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 553 | } |
Mathias Agopian | 29a367b | 2011-07-12 14:51:45 -0700 | [diff] [blame] | 554 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 555 | const char* Layer::getDebugName() const { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 556 | return mName.c_str(); |
David Sodman | 4b7c4bc | 2017-11-17 12:13:59 -0800 | [diff] [blame] | 557 | } |
| 558 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 559 | // --------------------------------------------------------------------------- |
| 560 | // drawing... |
| 561 | // --------------------------------------------------------------------------- |
| 562 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 563 | std::optional<compositionengine::LayerFE::LayerSettings> Layer::prepareClientComposition( |
Galia Peycheva | 66eaf4a | 2020-11-09 13:17:57 +0100 | [diff] [blame] | 564 | compositionengine::LayerFE::ClientCompositionTargetSettings& targetSettings) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 565 | if (!getCompositionState()) { |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 566 | return {}; |
| 567 | } |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 568 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 569 | FloatRect bounds = getBounds(); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 570 | half alpha = getAlpha(); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 571 | |
| 572 | compositionengine::LayerFE::LayerSettings layerSettings; |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 573 | layerSettings.geometry.boundaries = bounds; |
chaviw | c6ad8af | 2020-08-03 11:33:30 -0700 | [diff] [blame] | 574 | layerSettings.geometry.positionTransform = getTransform().asMatrix4(); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 575 | |
Derek Sollenberger | c31985e | 2021-05-18 16:38:17 -0400 | [diff] [blame] | 576 | // skip drawing content if the targetSettings indicate the content will be occluded |
| 577 | layerSettings.skipContentDraw = !targetSettings.realContentIsVisible; |
| 578 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 579 | if (hasColorTransform()) { |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 580 | layerSettings.colorTransform = getColorTransform(); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | const auto roundedCornerState = getRoundedCornerState(); |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 584 | layerSettings.geometry.roundedCornersRadius = roundedCornerState.radius; |
| 585 | layerSettings.geometry.roundedCornersCrop = roundedCornerState.cropRect; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 586 | |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 587 | layerSettings.alpha = alpha; |
chaviw | 4244e03 | 2019-09-04 11:27:49 -0700 | [diff] [blame] | 588 | layerSettings.sourceDataspace = getDataSpace(); |
Galia Peycheva | 66eaf4a | 2020-11-09 13:17:57 +0100 | [diff] [blame] | 589 | if (!targetSettings.disableBlurs) { |
| 590 | layerSettings.backgroundBlurRadius = getBackgroundBlurRadius(); |
| 591 | layerSettings.blurRegions = getBlurRegions(); |
Derek Sollenberger | 39feade | 2021-04-27 16:08:40 -0400 | [diff] [blame] | 592 | layerSettings.blurRegionTransform = |
| 593 | getActiveTransform(getDrawingState()).inverse().asMatrix4(); |
Galia Peycheva | 66eaf4a | 2020-11-09 13:17:57 +0100 | [diff] [blame] | 594 | } |
Nader Jawad | 2dfc98b | 2021-04-08 20:35:39 -0700 | [diff] [blame] | 595 | layerSettings.stretchEffect = getStretchEffect(); |
Ana Krulec | 6eab17a | 2020-12-09 15:52:36 -0800 | [diff] [blame] | 596 | // Record the name of the layer for debugging further down the stack. |
| 597 | layerSettings.name = getName(); |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 598 | return layerSettings; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 599 | } |
| 600 | |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 601 | void Layer::prepareClearClientComposition(LayerFE::LayerSettings& layerSettings, |
| 602 | bool blackout) const { |
| 603 | layerSettings.source.buffer.buffer = nullptr; |
| 604 | layerSettings.source.solidColor = half3(0.0, 0.0, 0.0); |
| 605 | layerSettings.disableBlending = true; |
Vishnu Nair | 3b653e7 | 2020-02-24 16:40:50 -0800 | [diff] [blame] | 606 | layerSettings.bufferId = 0; |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 607 | layerSettings.frameNumber = 0; |
| 608 | |
| 609 | // If layer is blacked out, force alpha to 1 so that we draw a black color layer. |
| 610 | layerSettings.alpha = blackout ? 1.0f : 0.0f; |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 611 | layerSettings.name = getName(); |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 612 | } |
| 613 | |
Derek Sollenberger | c31985e | 2021-05-18 16:38:17 -0400 | [diff] [blame] | 614 | // TODO(b/188891810): This method now only ever returns 0 or 1 layers so we should return |
| 615 | // std::optional instead of a vector. Additionally, we should consider removing |
| 616 | // this method entirely in favor of calling prepareClientComposition directly. |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 617 | std::vector<compositionengine::LayerFE::LayerSettings> Layer::prepareClientCompositionList( |
| 618 | compositionengine::LayerFE::ClientCompositionTargetSettings& targetSettings) { |
| 619 | std::optional<compositionengine::LayerFE::LayerSettings> layerSettings = |
| 620 | prepareClientComposition(targetSettings); |
| 621 | // Nothing to render. |
| 622 | if (!layerSettings) { |
| 623 | return {}; |
| 624 | } |
| 625 | |
| 626 | // HWC requests to clear this layer. |
| 627 | if (targetSettings.clearContent) { |
| 628 | prepareClearClientComposition(*layerSettings, false /* blackout */); |
| 629 | return {*layerSettings}; |
| 630 | } |
| 631 | |
Derek Sollenberger | c31985e | 2021-05-18 16:38:17 -0400 | [diff] [blame] | 632 | // set the shadow for the layer if needed |
| 633 | prepareShadowClientComposition(*layerSettings, targetSettings.viewport); |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 634 | |
Derek Sollenberger | c31985e | 2021-05-18 16:38:17 -0400 | [diff] [blame] | 635 | return {*layerSettings}; |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 636 | } |
| 637 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 638 | Hwc2::IComposerClient::Composition Layer::getCompositionType(const DisplayDevice& display) const { |
| 639 | const auto outputLayer = findOutputLayerForDisplay(&display); |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 640 | if (outputLayer == nullptr) { |
| 641 | return Hwc2::IComposerClient::Composition::INVALID; |
| 642 | } |
| 643 | if (outputLayer->getState().hwc) { |
| 644 | return (*outputLayer->getState().hwc).hwcCompositionType; |
| 645 | } else { |
| 646 | return Hwc2::IComposerClient::Composition::CLIENT; |
| 647 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 648 | } |
| 649 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 650 | // ---------------------------------------------------------------------------- |
| 651 | // local state |
| 652 | // ---------------------------------------------------------------------------- |
| 653 | |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 654 | bool Layer::isSecure() const { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 655 | const State& s(mDrawingState); |
Garfield Tan | de619fa | 2020-10-02 17:13:53 -0700 | [diff] [blame] | 656 | if (s.flags & layer_state_t::eLayerSecure) { |
| 657 | return true; |
| 658 | } |
| 659 | |
| 660 | const auto p = mDrawingParent.promote(); |
| 661 | return (p != nullptr) ? p->isSecure() : false; |
Dan Stoza | 2311608 | 2015-06-18 14:58:39 -0700 | [diff] [blame] | 662 | } |
| 663 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 664 | // ---------------------------------------------------------------------------- |
| 665 | // transaction |
| 666 | // ---------------------------------------------------------------------------- |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 667 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 668 | uint32_t Layer::doTransactionResize(uint32_t flags, State* stateToCommit) { |
Alec Mouri | b416efd | 2018-09-06 21:01:59 +0000 | [diff] [blame] | 669 | const State& s(getDrawingState()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 670 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 671 | const bool sizeChanged = (stateToCommit->requested_legacy.w != s.requested_legacy.w) || |
| 672 | (stateToCommit->requested_legacy.h != s.requested_legacy.h); |
Mathias Agopian | a138f89 | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 673 | |
David Sodman | eb085e0 | 2017-10-05 18:49:04 -0700 | [diff] [blame] | 674 | if (sizeChanged) { |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 675 | // 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] | 676 | ALOGD_IF(DEBUG_RESIZE, |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 677 | "doTransaction: geometry (layer=%p '%s'), tr=%02x, scalingMode=%d\n" |
| 678 | " current={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n" |
| 679 | " requested={ wh={%4u,%4u} }}\n" |
| 680 | " drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n" |
| 681 | " requested={ wh={%4u,%4u} }}\n", |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 682 | this, getName().c_str(), getBufferTransform(), getEffectiveScalingMode(), |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 683 | stateToCommit->active_legacy.w, stateToCommit->active_legacy.h, |
chaviw | 2571450 | 2021-02-11 10:01:08 -0800 | [diff] [blame] | 684 | stateToCommit->crop.left, stateToCommit->crop.top, stateToCommit->crop.right, |
| 685 | stateToCommit->crop.bottom, stateToCommit->crop.getWidth(), |
| 686 | stateToCommit->crop.getHeight(), stateToCommit->requested_legacy.w, |
| 687 | stateToCommit->requested_legacy.h, s.active_legacy.w, s.active_legacy.h, |
| 688 | s.crop.left, s.crop.top, s.crop.right, s.crop.bottom, s.crop.getWidth(), |
| 689 | s.crop.getHeight(), s.requested_legacy.w, s.requested_legacy.h); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 690 | } |
Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 691 | |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 692 | // Don't let Layer::doTransaction update the drawing state |
| 693 | // if we have a pending resize, unless we are in fixed-size mode. |
| 694 | // the drawing state will be updated only once we receive a buffer |
| 695 | // with the correct size. |
| 696 | // |
| 697 | // In particular, we want to make sure the clip (which is part |
| 698 | // of the geometry state) is latched together with the size but is |
| 699 | // latched immediately when no resizing is involved. |
| 700 | // |
| 701 | // If a sideband stream is attached, however, we want to skip this |
| 702 | // optimization so that transactions aren't missed when a buffer |
| 703 | // never arrives |
| 704 | // |
| 705 | // In the case that we don't have a buffer we ignore other factors |
| 706 | // and avoid entering the resizePending state. At a high level the |
| 707 | // resizePending state is to avoid applying the state of the new buffer |
| 708 | // to the old buffer. However in the state where we don't have an old buffer |
| 709 | // there is no such concern but we may still be being used as a parent layer. |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 710 | const bool resizePending = |
| 711 | ((stateToCommit->requested_legacy.w != stateToCommit->active_legacy.w) || |
| 712 | (stateToCommit->requested_legacy.h != stateToCommit->active_legacy.h)) && |
chaviw | d62d306 | 2019-09-04 14:48:02 -0700 | [diff] [blame] | 713 | (getBuffer() != nullptr); |
Mathias Agopian | 0cd545f | 2012-06-07 14:18:55 -0700 | [diff] [blame] | 714 | if (!isFixedSize()) { |
Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 715 | if (resizePending && mSidebandStream == nullptr) { |
Mathias Agopian | 0cd545f | 2012-06-07 14:18:55 -0700 | [diff] [blame] | 716 | flags |= eDontUpdateGeometryState; |
| 717 | } |
| 718 | } |
| 719 | |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 720 | // Here we apply various requested geometry states, depending on our |
| 721 | // latching configuration. See Layer.h for a detailed discussion of |
| 722 | // how geometry latching is controlled. |
| 723 | if (!(flags & eDontUpdateGeometryState)) { |
Alec Mouri | b416efd | 2018-09-06 21:01:59 +0000 | [diff] [blame] | 724 | State& editCurrentState(getCurrentState()); |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 725 | |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 726 | // There is an awkward asymmetry in the handling of the crop states in the position |
| 727 | // states, as can be seen below. Largely this arises from position and transform |
| 728 | // being stored in the same data structure while having different latching rules. |
| 729 | // b/38182305 |
| 730 | // |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 731 | // Careful that "stateToCommit" and editCurrentState may not begin as equivalent due to |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 732 | // applyPendingStates in the presence of deferred transactions. |
chaviw | 214c89d | 2019-09-04 16:03:53 -0700 | [diff] [blame] | 733 | editCurrentState.active_legacy = editCurrentState.requested_legacy; |
| 734 | stateToCommit->active_legacy = stateToCommit->requested_legacy; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 735 | } |
| 736 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 737 | return flags; |
| 738 | } |
| 739 | |
| 740 | uint32_t Layer::doTransaction(uint32_t flags) { |
| 741 | ATRACE_CALL(); |
| 742 | |
Robert Carr | 7f2ed8b | 2019-02-07 14:45:11 -0800 | [diff] [blame] | 743 | if (mChildrenChanged) { |
| 744 | flags |= eVisibleRegion; |
| 745 | mChildrenChanged = false; |
chaviw | 5aedec9 | 2018-10-22 10:40:38 -0700 | [diff] [blame] | 746 | } |
| 747 | |
Robert Carr | 0758e5d | 2021-03-11 22:15:04 -0800 | [diff] [blame] | 748 | // TODO: This is unfortunate. |
| 749 | mCurrentStateModified = mCurrentState.modified; |
| 750 | mCurrentState.modified = false; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 751 | |
Robert Carr | 0758e5d | 2021-03-11 22:15:04 -0800 | [diff] [blame] | 752 | flags = doTransactionResize(flags, &mCurrentState); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 753 | |
Alec Mouri | b416efd | 2018-09-06 21:01:59 +0000 | [diff] [blame] | 754 | const State& s(getDrawingState()); |
Robert Carr | 0758e5d | 2021-03-11 22:15:04 -0800 | [diff] [blame] | 755 | State& c(getCurrentState()); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 756 | |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 757 | // Translates dest frame into scale and position updates. This helps align geometry calculations |
| 758 | // for BufferStateLayer with other layers. This should ideally happen in the client once client |
| 759 | // has the display orientation details from WM. |
| 760 | updateGeometry(); |
| 761 | |
chaviw | 4e76553 | 2021-04-30 12:11:39 -0500 | [diff] [blame] | 762 | if (c.width != s.width || c.height != s.height || !(c.transform == s.transform)) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 763 | // invalidate and recompute the visible regions if needed |
| 764 | flags |= Layer::eVisibleRegion; |
| 765 | } |
| 766 | |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 767 | if (c.sequence != s.sequence) { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 768 | // invalidate and recompute the visible regions if needed |
| 769 | flags |= eVisibleRegion; |
| 770 | this->contentDirty = true; |
| 771 | |
| 772 | // we may use linear filtering, if the matrix scales us |
Marin Shalamanov | 043ba29 | 2020-09-10 13:35:20 +0200 | [diff] [blame] | 773 | mNeedsFiltering = getActiveTransform(c).needsBilinearFiltering(); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 774 | } |
| 775 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 776 | if (mCurrentState.inputInfoChanged) { |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 777 | flags |= eInputInfoChanged; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 778 | mCurrentState.inputInfoChanged = false; |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 779 | } |
| 780 | |
chaviw | 47dbd69 | 2020-10-26 17:50:12 -0700 | [diff] [blame] | 781 | // Add the callbacks from the drawing state into the current state. This is so when the current |
| 782 | // state gets copied to drawing, we don't lose the callback handles that are still in drawing. |
| 783 | for (auto& handle : s.callbackHandles) { |
| 784 | c.callbackHandles.push_back(handle); |
| 785 | } |
| 786 | |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 787 | // Allow BufferStateLayer to release any unlatched buffers in drawing state. |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 788 | bufferMayChange(c.buffer->getBuffer()); |
Vishnu Nair | 1506b18 | 2021-02-22 14:35:15 -0800 | [diff] [blame] | 789 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 790 | // Commit the transaction |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 791 | commitTransaction(c); |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 792 | mCurrentState.callbackHandles = {}; |
Robert Carr | a125784 | 2020-01-31 13:48:28 -0800 | [diff] [blame] | 793 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 794 | return flags; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 795 | } |
| 796 | |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 797 | void Layer::commitTransaction(State& stateToCommit) { |
Adithya Srinivasan | d11eb6b | 2021-03-09 18:46:28 +0000 | [diff] [blame] | 798 | if (auto& bufferSurfaceFrame = mDrawingState.bufferSurfaceFrameTX; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 799 | ((mDrawingState.buffer && stateToCommit.buffer && |
| 800 | mDrawingState.buffer->getBuffer() != stateToCommit.buffer->getBuffer()) || |
| 801 | (mDrawingState.buffer && !stateToCommit.buffer) || |
| 802 | (!mDrawingState.buffer && stateToCommit.buffer)) && |
| 803 | bufferSurfaceFrame != nullptr && |
Adithya Srinivasan | d11eb6b | 2021-03-09 18:46:28 +0000 | [diff] [blame] | 804 | bufferSurfaceFrame->getPresentState() != PresentState::Presented) { |
| 805 | // If the previous buffer was committed but not latched (refreshPending - happens during |
| 806 | // back to back invalidates), it gets silently dropped here. Mark the corresponding |
| 807 | // SurfaceFrame as dropped to prevent it from getting stuck in the pending classification |
| 808 | // list. |
| 809 | addSurfaceFrameDroppedForBuffer(bufferSurfaceFrame); |
| 810 | } |
Ady Abraham | 59fd8ff | 2021-04-15 20:13:30 -0700 | [diff] [blame] | 811 | const bool frameRateVoteChanged = |
| 812 | mDrawingState.frameRateForLayerTree != stateToCommit.frameRateForLayerTree; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 813 | mDrawingState = stateToCommit; |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 814 | |
Ady Abraham | 59fd8ff | 2021-04-15 20:13:30 -0700 | [diff] [blame] | 815 | if (frameRateVoteChanged) { |
| 816 | mFlinger->mScheduler->recordLayerHistory(this, systemTime(), |
| 817 | LayerHistory::LayerUpdateType::SetFrameRate); |
| 818 | } |
| 819 | |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 820 | // Set the present state for all bufferlessSurfaceFramesTX to Presented. The |
| 821 | // bufferSurfaceFrameTX will be presented in latchBuffer. |
| 822 | for (auto& [token, surfaceFrame] : mDrawingState.bufferlessSurfaceFramesTX) { |
| 823 | if (surfaceFrame->getPresentState() != PresentState::Presented) { |
| 824 | // With applyPendingStates, we could end up having presented surfaceframes from previous |
| 825 | // states |
| 826 | surfaceFrame->setPresentState(PresentState::Presented); |
| 827 | mFlinger->mFrameTimeline->addSurfaceFrame(surfaceFrame); |
| 828 | } |
| 829 | } |
| 830 | // Clear the surfaceFrames from the old state now that it has been copied into DrawingState. |
| 831 | stateToCommit.bufferSurfaceFrameTX.reset(); |
| 832 | stateToCommit.bufferlessSurfaceFramesTX.clear(); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 833 | } |
| 834 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 835 | uint32_t Layer::getTransactionFlags(uint32_t flags) { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 836 | return mTransactionFlags.fetch_and(~flags) & flags; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | uint32_t Layer::setTransactionFlags(uint32_t flags) { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 840 | return mTransactionFlags.fetch_or(flags); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 841 | } |
| 842 | |
chaviw | 214c89d | 2019-09-04 16:03:53 -0700 | [diff] [blame] | 843 | bool Layer::setPosition(float x, float y) { |
chaviw | 4e76553 | 2021-04-30 12:11:39 -0500 | [diff] [blame] | 844 | if (mCurrentState.transform.tx() == x && mCurrentState.transform.ty() == y) return false; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 845 | mCurrentState.sequence++; |
Robert Carr | 69663fb | 2016-03-27 19:59:19 -0700 | [diff] [blame] | 846 | |
| 847 | // We update the requested and active position simultaneously because |
| 848 | // we want to apply the position portion of the transform matrix immediately, |
| 849 | // but still delay scaling when resizing a SCALING_MODE_FREEZE layer. |
chaviw | 4e76553 | 2021-04-30 12:11:39 -0500 | [diff] [blame] | 850 | mCurrentState.transform.set(x, y); |
chaviw | 214c89d | 2019-09-04 16:03:53 -0700 | [diff] [blame] | 851 | // Here we directly update the active state |
| 852 | // unlike other setters, because we store it within |
| 853 | // the transform, but use different latching rules. |
| 854 | // b/38182305 |
chaviw | 4e76553 | 2021-04-30 12:11:39 -0500 | [diff] [blame] | 855 | mCurrentState.transform.set(x, y); |
Robert Carr | 69663fb | 2016-03-27 19:59:19 -0700 | [diff] [blame] | 856 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 857 | mCurrentState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 858 | setTransactionFlags(eTransactionNeeded); |
| 859 | return true; |
| 860 | } |
Robert Carr | 82364e3 | 2016-05-15 11:27:47 -0700 | [diff] [blame] | 861 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 862 | bool Layer::setChildLayer(const sp<Layer>& childLayer, int32_t z) { |
| 863 | ssize_t idx = mCurrentChildren.indexOf(childLayer); |
| 864 | if (idx < 0) { |
| 865 | return false; |
| 866 | } |
| 867 | if (childLayer->setLayer(z)) { |
| 868 | mCurrentChildren.removeAt(idx); |
| 869 | mCurrentChildren.add(childLayer); |
Robert Carr | 503d2bd | 2017-12-04 15:49:47 -0800 | [diff] [blame] | 870 | return true; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 871 | } |
Robert Carr | 503d2bd | 2017-12-04 15:49:47 -0800 | [diff] [blame] | 872 | return false; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 873 | } |
| 874 | |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 875 | bool Layer::setChildRelativeLayer(const sp<Layer>& childLayer, |
| 876 | const sp<IBinder>& relativeToHandle, int32_t relativeZ) { |
| 877 | ssize_t idx = mCurrentChildren.indexOf(childLayer); |
| 878 | if (idx < 0) { |
| 879 | return false; |
| 880 | } |
| 881 | if (childLayer->setRelativeLayer(relativeToHandle, relativeZ)) { |
| 882 | mCurrentChildren.removeAt(idx); |
| 883 | mCurrentChildren.add(childLayer); |
Robert Carr | 503d2bd | 2017-12-04 15:49:47 -0800 | [diff] [blame] | 884 | return true; |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 885 | } |
Robert Carr | 503d2bd | 2017-12-04 15:49:47 -0800 | [diff] [blame] | 886 | return false; |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 887 | } |
| 888 | |
Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 889 | bool Layer::setLayer(int32_t z) { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 890 | if (mCurrentState.z == z && !usingRelativeZ(LayerVector::StateSet::Current)) return false; |
| 891 | mCurrentState.sequence++; |
| 892 | mCurrentState.z = z; |
| 893 | mCurrentState.modified = true; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 894 | |
| 895 | // Discard all relative layering. |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 896 | if (mCurrentState.zOrderRelativeOf != nullptr) { |
| 897 | sp<Layer> strongRelative = mCurrentState.zOrderRelativeOf.promote(); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 898 | if (strongRelative != nullptr) { |
| 899 | strongRelative->removeZOrderRelative(this); |
| 900 | } |
chaviw | 606e5cf | 2019-03-01 10:12:10 -0800 | [diff] [blame] | 901 | setZOrderRelativeOf(nullptr); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 902 | } |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 903 | setTransactionFlags(eTransactionNeeded); |
| 904 | return true; |
| 905 | } |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 906 | |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 907 | void Layer::removeZOrderRelative(const wp<Layer>& relative) { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 908 | mCurrentState.zOrderRelatives.remove(relative); |
| 909 | mCurrentState.sequence++; |
| 910 | mCurrentState.modified = true; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 911 | setTransactionFlags(eTransactionNeeded); |
| 912 | } |
| 913 | |
| 914 | void Layer::addZOrderRelative(const wp<Layer>& relative) { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 915 | mCurrentState.zOrderRelatives.add(relative); |
| 916 | mCurrentState.modified = true; |
| 917 | mCurrentState.sequence++; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 918 | setTransactionFlags(eTransactionNeeded); |
| 919 | } |
| 920 | |
chaviw | 606e5cf | 2019-03-01 10:12:10 -0800 | [diff] [blame] | 921 | void Layer::setZOrderRelativeOf(const wp<Layer>& relativeOf) { |
| 922 | mCurrentState.zOrderRelativeOf = relativeOf; |
| 923 | mCurrentState.sequence++; |
| 924 | mCurrentState.modified = true; |
chaviw | bdb8b80 | 2019-10-14 09:17:12 -0700 | [diff] [blame] | 925 | mCurrentState.isRelativeOf = relativeOf != nullptr; |
| 926 | |
chaviw | 606e5cf | 2019-03-01 10:12:10 -0800 | [diff] [blame] | 927 | setTransactionFlags(eTransactionNeeded); |
| 928 | } |
| 929 | |
Robert Carr | 503d2bd | 2017-12-04 15:49:47 -0800 | [diff] [blame] | 930 | bool Layer::setRelativeLayer(const sp<IBinder>& relativeToHandle, int32_t relativeZ) { |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 931 | sp<Handle> handle = static_cast<Handle*>(relativeToHandle.get()); |
| 932 | if (handle == nullptr) { |
| 933 | return false; |
| 934 | } |
| 935 | sp<Layer> relative = handle->owner.promote(); |
| 936 | if (relative == nullptr) { |
| 937 | return false; |
| 938 | } |
| 939 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 940 | if (mCurrentState.z == relativeZ && usingRelativeZ(LayerVector::StateSet::Current) && |
| 941 | mCurrentState.zOrderRelativeOf == relative) { |
Robert Carr | 503d2bd | 2017-12-04 15:49:47 -0800 | [diff] [blame] | 942 | return false; |
| 943 | } |
| 944 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 945 | mCurrentState.sequence++; |
| 946 | mCurrentState.modified = true; |
| 947 | mCurrentState.z = relativeZ; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 948 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 949 | auto oldZOrderRelativeOf = mCurrentState.zOrderRelativeOf.promote(); |
chaviw | 9ab4bd1 | 2017-11-03 13:11:00 -0700 | [diff] [blame] | 950 | if (oldZOrderRelativeOf != nullptr) { |
| 951 | oldZOrderRelativeOf->removeZOrderRelative(this); |
| 952 | } |
chaviw | 606e5cf | 2019-03-01 10:12:10 -0800 | [diff] [blame] | 953 | setZOrderRelativeOf(relative); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 954 | relative->addZOrderRelative(this); |
| 955 | |
| 956 | setTransactionFlags(eTransactionNeeded); |
| 957 | |
| 958 | return true; |
| 959 | } |
| 960 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 961 | bool Layer::setSize(uint32_t w, uint32_t h) { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 962 | if (mCurrentState.requested_legacy.w == w && mCurrentState.requested_legacy.h == h) |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 963 | return false; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 964 | mCurrentState.requested_legacy.w = w; |
| 965 | mCurrentState.requested_legacy.h = h; |
| 966 | mCurrentState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 967 | setTransactionFlags(eTransactionNeeded); |
Vishnu Nair | d01c443 | 2018-08-13 10:38:47 -0700 | [diff] [blame] | 968 | |
| 969 | // record the new size, from this point on, when the client request |
| 970 | // a buffer, it'll get the new size. |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 971 | setDefaultBufferSize(mCurrentState.requested_legacy.w, mCurrentState.requested_legacy.h); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 972 | return true; |
| 973 | } |
chaviw | 4e76553 | 2021-04-30 12:11:39 -0500 | [diff] [blame] | 974 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 975 | bool Layer::setAlpha(float alpha) { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 976 | if (mCurrentState.color.a == alpha) return false; |
| 977 | mCurrentState.sequence++; |
| 978 | mCurrentState.color.a = alpha; |
| 979 | mCurrentState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 980 | setTransactionFlags(eTransactionNeeded); |
| 981 | return true; |
| 982 | } |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 983 | |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 984 | bool Layer::setBackgroundColor(const half3& color, float alpha, ui::Dataspace dataspace) { |
| 985 | if (!mCurrentState.bgColorLayer && alpha == 0) { |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 986 | return false; |
Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 987 | } |
| 988 | mCurrentState.sequence++; |
| 989 | mCurrentState.modified = true; |
| 990 | setTransactionFlags(eTransactionNeeded); |
| 991 | |
| 992 | if (!mCurrentState.bgColorLayer && alpha != 0) { |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 993 | // create background color layer if one does not yet exist |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 994 | uint32_t flags = ISurfaceComposerClient::eFXSurfaceEffect; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 995 | std::string name = mName + "BackgroundColorLayer"; |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 996 | mCurrentState.bgColorLayer = mFlinger->getFactory().createEffectLayer( |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 997 | LayerCreationArgs(mFlinger.get(), nullptr, std::move(name), 0, 0, flags, |
| 998 | LayerMetadata())); |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 999 | |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1000 | // add to child list |
| 1001 | addChild(mCurrentState.bgColorLayer); |
| 1002 | mFlinger->mLayersAdded = true; |
| 1003 | // set up SF to handle added color layer |
| 1004 | if (isRemovedFromCurrentState()) { |
| 1005 | mCurrentState.bgColorLayer->onRemovedFromCurrentState(); |
| 1006 | } |
| 1007 | mFlinger->setTransactionFlags(eTransactionNeeded); |
| 1008 | } else if (mCurrentState.bgColorLayer && alpha == 0) { |
| 1009 | mCurrentState.bgColorLayer->reparent(nullptr); |
| 1010 | mCurrentState.bgColorLayer = nullptr; |
| 1011 | return true; |
| 1012 | } |
| 1013 | |
| 1014 | mCurrentState.bgColorLayer->setColor(color); |
| 1015 | mCurrentState.bgColorLayer->setLayer(std::numeric_limits<int32_t>::min()); |
| 1016 | mCurrentState.bgColorLayer->setAlpha(alpha); |
| 1017 | mCurrentState.bgColorLayer->setDataspace(dataspace); |
| 1018 | |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 1019 | return true; |
| 1020 | } |
| 1021 | |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1022 | bool Layer::setCornerRadius(float cornerRadius) { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1023 | if (mCurrentState.cornerRadius == cornerRadius) return false; |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1024 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1025 | mCurrentState.sequence++; |
| 1026 | mCurrentState.cornerRadius = cornerRadius; |
| 1027 | mCurrentState.modified = true; |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1028 | setTransactionFlags(eTransactionNeeded); |
| 1029 | return true; |
| 1030 | } |
| 1031 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1032 | bool Layer::setBackgroundBlurRadius(int backgroundBlurRadius) { |
| 1033 | if (mCurrentState.backgroundBlurRadius == backgroundBlurRadius) return false; |
| 1034 | |
| 1035 | mCurrentState.sequence++; |
| 1036 | mCurrentState.backgroundBlurRadius = backgroundBlurRadius; |
| 1037 | mCurrentState.modified = true; |
| 1038 | setTransactionFlags(eTransactionNeeded); |
| 1039 | return true; |
| 1040 | } |
| 1041 | |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 1042 | bool Layer::setMatrix(const layer_state_t::matrix22_t& matrix, |
| 1043 | bool allowNonRectPreservingTransforms) { |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 1044 | ui::Transform t; |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 1045 | t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy); |
| 1046 | |
| 1047 | if (!allowNonRectPreservingTransforms && !t.preserveRects()) { |
Hongwei Wang | 46213ea | 2020-12-04 17:17:31 -0800 | [diff] [blame] | 1048 | ALOGW("Attempt to set rotation matrix without permission ACCESS_SURFACE_FLINGER nor " |
| 1049 | "ROTATE_SURFACE_FLINGER ignored"); |
Robert Carr | d4ae7f3 | 2018-06-07 16:10:57 -0700 | [diff] [blame] | 1050 | return false; |
| 1051 | } |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1052 | mCurrentState.sequence++; |
chaviw | 4e76553 | 2021-04-30 12:11:39 -0500 | [diff] [blame] | 1053 | mCurrentState.transform.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy); |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1054 | mCurrentState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1055 | setTransactionFlags(eTransactionNeeded); |
| 1056 | return true; |
| 1057 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1058 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1059 | bool Layer::setTransparentRegionHint(const Region& transparent) { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1060 | mCurrentState.requestedTransparentRegion_legacy = transparent; |
| 1061 | mCurrentState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1062 | setTransactionFlags(eTransactionNeeded); |
| 1063 | return true; |
| 1064 | } |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 1065 | |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 1066 | bool Layer::setBlurRegions(const std::vector<BlurRegion>& blurRegions) { |
| 1067 | mCurrentState.sequence++; |
| 1068 | mCurrentState.blurRegions = blurRegions; |
| 1069 | mCurrentState.modified = true; |
| 1070 | setTransactionFlags(eTransactionNeeded); |
| 1071 | return true; |
| 1072 | } |
| 1073 | |
Vishnu Nair | f6eddb6 | 2021-01-27 22:02:11 -0800 | [diff] [blame] | 1074 | bool Layer::setFlags(uint32_t flags, uint32_t mask) { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1075 | const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask); |
| 1076 | if (mCurrentState.flags == newFlags) return false; |
| 1077 | mCurrentState.sequence++; |
| 1078 | mCurrentState.flags = newFlags; |
| 1079 | mCurrentState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1080 | setTransactionFlags(eTransactionNeeded); |
| 1081 | return true; |
| 1082 | } |
Robert Carr | 99e27f0 | 2016-06-16 15:18:02 -0700 | [diff] [blame] | 1083 | |
chaviw | 2571450 | 2021-02-11 10:01:08 -0800 | [diff] [blame] | 1084 | bool Layer::setCrop(const Rect& crop) { |
| 1085 | if (mCurrentState.requestedCrop == crop) return false; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1086 | mCurrentState.sequence++; |
chaviw | 2571450 | 2021-02-11 10:01:08 -0800 | [diff] [blame] | 1087 | mCurrentState.requestedCrop = crop; |
| 1088 | mCurrentState.crop = crop; |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 1089 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1090 | mCurrentState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1091 | setTransactionFlags(eTransactionNeeded); |
| 1092 | return true; |
| 1093 | } |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 1094 | |
Evan Rosky | ef876c9 | 2019-01-25 17:46:06 -0800 | [diff] [blame] | 1095 | bool Layer::setMetadata(const LayerMetadata& data) { |
| 1096 | if (!mCurrentState.metadata.merge(data, true /* eraseEmpty */)) return false; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1097 | mCurrentState.modified = true; |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 1098 | setTransactionFlags(eTransactionNeeded); |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 1099 | return true; |
Daniel Nicoara | 2f5f8a5 | 2016-12-20 16:11:58 -0500 | [diff] [blame] | 1100 | } |
| 1101 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1102 | bool Layer::setLayerStack(uint32_t layerStack) { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1103 | if (mCurrentState.layerStack == layerStack) return false; |
| 1104 | mCurrentState.sequence++; |
| 1105 | mCurrentState.layerStack = layerStack; |
| 1106 | mCurrentState.modified = true; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1107 | setTransactionFlags(eTransactionNeeded); |
| 1108 | return true; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 1111 | bool Layer::setColorSpaceAgnostic(const bool agnostic) { |
| 1112 | if (mCurrentState.colorSpaceAgnostic == agnostic) { |
| 1113 | return false; |
| 1114 | } |
| 1115 | mCurrentState.sequence++; |
| 1116 | mCurrentState.colorSpaceAgnostic = agnostic; |
| 1117 | mCurrentState.modified = true; |
| 1118 | setTransactionFlags(eTransactionNeeded); |
| 1119 | return true; |
| 1120 | } |
| 1121 | |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 1122 | bool Layer::setFrameRateSelectionPriority(int32_t priority) { |
| 1123 | if (mCurrentState.frameRateSelectionPriority == priority) return false; |
| 1124 | mCurrentState.frameRateSelectionPriority = priority; |
| 1125 | mCurrentState.sequence++; |
| 1126 | mCurrentState.modified = true; |
| 1127 | setTransactionFlags(eTransactionNeeded); |
| 1128 | return true; |
| 1129 | } |
| 1130 | |
| 1131 | int32_t Layer::getFrameRateSelectionPriority() const { |
| 1132 | // Check if layer has priority set. |
| 1133 | if (mDrawingState.frameRateSelectionPriority != PRIORITY_UNSET) { |
| 1134 | return mDrawingState.frameRateSelectionPriority; |
| 1135 | } |
| 1136 | // If not, search whether its parents have it set. |
| 1137 | sp<Layer> parent = getParent(); |
| 1138 | if (parent != nullptr) { |
| 1139 | return parent->getFrameRateSelectionPriority(); |
| 1140 | } |
| 1141 | |
| 1142 | return Layer::PRIORITY_UNSET; |
| 1143 | } |
| 1144 | |
Ady Abraham | aae5ed5 | 2020-06-26 09:32:43 -0700 | [diff] [blame] | 1145 | bool Layer::isLayerFocusedBasedOnPriority(int32_t priority) { |
| 1146 | return priority == PRIORITY_FOCUSED_WITH_MODE || priority == PRIORITY_FOCUSED_WITHOUT_MODE; |
| 1147 | }; |
| 1148 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1149 | uint32_t Layer::getLayerStack() const { |
Chia-I Wu | e41dbe6 | 2017-06-13 14:10:56 -0700 | [diff] [blame] | 1150 | auto p = mDrawingParent.promote(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1151 | if (p == nullptr) { |
| 1152 | return getDrawingState().layerStack; |
| 1153 | } |
| 1154 | return p->getLayerStack(); |
| 1155 | } |
| 1156 | |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 1157 | bool Layer::setShadowRadius(float shadowRadius) { |
| 1158 | if (mCurrentState.shadowRadius == shadowRadius) { |
| 1159 | return false; |
| 1160 | } |
| 1161 | |
| 1162 | mCurrentState.sequence++; |
| 1163 | mCurrentState.shadowRadius = shadowRadius; |
| 1164 | mCurrentState.modified = true; |
| 1165 | setTransactionFlags(eTransactionNeeded); |
| 1166 | return true; |
| 1167 | } |
| 1168 | |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 1169 | bool Layer::setFixedTransformHint(ui::Transform::RotationFlags fixedTransformHint) { |
| 1170 | if (mCurrentState.fixedTransformHint == fixedTransformHint) { |
| 1171 | return false; |
| 1172 | } |
| 1173 | |
| 1174 | mCurrentState.sequence++; |
| 1175 | mCurrentState.fixedTransformHint = fixedTransformHint; |
| 1176 | mCurrentState.modified = true; |
| 1177 | setTransactionFlags(eTransactionNeeded); |
| 1178 | return true; |
| 1179 | } |
| 1180 | |
John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 1181 | bool Layer::setStretchEffect(const StretchEffect& effect) { |
| 1182 | StretchEffect temp = effect; |
| 1183 | temp.sanitize(); |
| 1184 | if (mCurrentState.stretchEffect == temp) { |
| 1185 | return false; |
| 1186 | } |
| 1187 | mCurrentState.sequence++; |
| 1188 | mCurrentState.stretchEffect = temp; |
| 1189 | mCurrentState.modified = true; |
| 1190 | setTransactionFlags(eTransactionNeeded); |
| 1191 | return true; |
| 1192 | } |
| 1193 | |
John Reck | c00c669 | 2021-02-16 11:37:33 -0500 | [diff] [blame] | 1194 | StretchEffect Layer::getStretchEffect() const { |
| 1195 | if (mDrawingState.stretchEffect.hasEffect()) { |
| 1196 | return mDrawingState.stretchEffect; |
| 1197 | } |
| 1198 | |
| 1199 | sp<Layer> parent = getParent(); |
| 1200 | if (parent != nullptr) { |
| 1201 | auto effect = parent->getStretchEffect(); |
| 1202 | if (effect.hasEffect()) { |
| 1203 | // TODO(b/179047472): Map it? Or do we make the effect be in global space? |
| 1204 | return effect; |
| 1205 | } |
| 1206 | } |
| 1207 | return StretchEffect{}; |
| 1208 | } |
| 1209 | |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1210 | void Layer::updateTreeHasFrameRateVote() { |
| 1211 | const auto traverseTree = [&](const LayerVector::Visitor& visitor) { |
| 1212 | auto parent = getParent(); |
| 1213 | while (parent) { |
| 1214 | visitor(parent.get()); |
| 1215 | parent = parent->getParent(); |
| 1216 | } |
| 1217 | |
| 1218 | traverse(LayerVector::StateSet::Current, visitor); |
| 1219 | }; |
| 1220 | |
| 1221 | // update parents and children about the vote |
Ady Abraham | 59fd8ff | 2021-04-15 20:13:30 -0700 | [diff] [blame] | 1222 | // First traverse the tree and count how many layers has votes. |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1223 | int layersWithVote = 0; |
Ady Abraham | 44e9f3b | 2021-02-16 15:22:58 -0800 | [diff] [blame] | 1224 | traverseTree([&layersWithVote](Layer* layer) { |
Marin Shalamanov | e8a663d | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 1225 | const auto layerVotedWithDefaultCompatibility = |
| 1226 | layer->mCurrentState.frameRate.rate.isValid() && |
Ady Abraham | 414e8b5 | 2020-05-21 15:36:04 -0700 | [diff] [blame] | 1227 | layer->mCurrentState.frameRate.type == FrameRateCompatibility::Default; |
| 1228 | const auto layerVotedWithNoVote = |
| 1229 | layer->mCurrentState.frameRate.type == FrameRateCompatibility::NoVote; |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 1230 | const auto layerVotedWithExactCompatibility = |
| 1231 | layer->mCurrentState.frameRate.type == FrameRateCompatibility::Exact; |
Ady Abraham | 414e8b5 | 2020-05-21 15:36:04 -0700 | [diff] [blame] | 1232 | |
| 1233 | // We do not count layers that are ExactOrMultiple for the same reason |
| 1234 | // we are allowing touch boost for those layers. See |
| 1235 | // RefreshRateConfigs::getBestRefreshRate for more details. |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 1236 | if (layerVotedWithDefaultCompatibility || layerVotedWithNoVote || |
| 1237 | layerVotedWithExactCompatibility) { |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1238 | layersWithVote++; |
| 1239 | } |
| 1240 | }); |
| 1241 | |
Ady Abraham | 59fd8ff | 2021-04-15 20:13:30 -0700 | [diff] [blame] | 1242 | // Now we can update the tree frame rate vote for each layer in the tree |
| 1243 | const bool treeHasFrameRateVote = layersWithVote > 0; |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1244 | bool transactionNeeded = false; |
Ady Abraham | 59fd8ff | 2021-04-15 20:13:30 -0700 | [diff] [blame] | 1245 | traverseTree([treeHasFrameRateVote, &transactionNeeded](Layer* layer) { |
| 1246 | transactionNeeded = layer->updateFrameRateForLayerTree(treeHasFrameRateVote); |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1247 | }); |
| 1248 | |
| 1249 | if (transactionNeeded) { |
| 1250 | mFlinger->setTransactionFlags(eTraversalNeeded); |
| 1251 | } |
| 1252 | } |
| 1253 | |
Ady Abraham | 71c437d | 2020-01-31 15:56:57 -0800 | [diff] [blame] | 1254 | bool Layer::setFrameRate(FrameRate frameRate) { |
Ana Krulec | 3803b8d | 2020-02-03 16:35:46 -0800 | [diff] [blame] | 1255 | if (!mFlinger->useFrameRateApi) { |
| 1256 | return false; |
| 1257 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 1258 | if (mCurrentState.frameRate == frameRate) { |
| 1259 | return false; |
| 1260 | } |
| 1261 | |
| 1262 | mCurrentState.sequence++; |
| 1263 | mCurrentState.frameRate = frameRate; |
| 1264 | mCurrentState.modified = true; |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1265 | |
| 1266 | updateTreeHasFrameRateVote(); |
| 1267 | |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 1268 | setTransactionFlags(eTransactionNeeded); |
| 1269 | return true; |
| 1270 | } |
| 1271 | |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1272 | void Layer::setFrameTimelineVsyncForBufferTransaction(const FrameTimelineInfo& info, |
| 1273 | nsecs_t postTime) { |
| 1274 | mCurrentState.postTime = postTime; |
| 1275 | |
| 1276 | // Check if one of the bufferlessSurfaceFramesTX contains the same vsyncId. This can happen if |
| 1277 | // there are two transactions with the same token, the first one without a buffer and the |
| 1278 | // second one with a buffer. We promote the bufferlessSurfaceFrame to a bufferSurfaceFrameTX |
| 1279 | // in that case. |
| 1280 | auto it = mCurrentState.bufferlessSurfaceFramesTX.find(info.vsyncId); |
| 1281 | if (it != mCurrentState.bufferlessSurfaceFramesTX.end()) { |
| 1282 | // Promote the bufferlessSurfaceFrame to a bufferSurfaceFrameTX |
| 1283 | mCurrentState.bufferSurfaceFrameTX = it->second; |
| 1284 | mCurrentState.bufferlessSurfaceFramesTX.erase(it); |
Adithya Srinivasan | 785addd | 2021-03-09 00:38:00 +0000 | [diff] [blame] | 1285 | mCurrentState.bufferSurfaceFrameTX->promoteToBuffer(); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1286 | mCurrentState.bufferSurfaceFrameTX->setActualQueueTime(postTime); |
| 1287 | } else { |
| 1288 | mCurrentState.bufferSurfaceFrameTX = |
| 1289 | createSurfaceFrameForBuffer(info, postTime, mTransactionName); |
| 1290 | } |
| 1291 | } |
| 1292 | |
| 1293 | void Layer::setFrameTimelineVsyncForBufferlessTransaction(const FrameTimelineInfo& info, |
| 1294 | nsecs_t postTime) { |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 1295 | mCurrentState.frameTimelineInfo = info; |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 1296 | mCurrentState.postTime = postTime; |
| 1297 | mCurrentState.modified = true; |
| 1298 | setTransactionFlags(eTransactionNeeded); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1299 | |
| 1300 | if (const auto& bufferSurfaceFrameTX = mCurrentState.bufferSurfaceFrameTX; |
| 1301 | bufferSurfaceFrameTX != nullptr) { |
| 1302 | if (bufferSurfaceFrameTX->getToken() == info.vsyncId) { |
| 1303 | // BufferSurfaceFrame takes precedence over BufferlessSurfaceFrame. If the same token is |
| 1304 | // being used for BufferSurfaceFrame, don't create a new one. |
| 1305 | return; |
| 1306 | } |
| 1307 | } |
| 1308 | // For Transactions without a buffer, we create only one SurfaceFrame per vsyncId. If multiple |
| 1309 | // transactions use the same vsyncId, we just treat them as one SurfaceFrame (unless they are |
| 1310 | // targeting different vsyncs). |
| 1311 | auto it = mCurrentState.bufferlessSurfaceFramesTX.find(info.vsyncId); |
| 1312 | if (it == mCurrentState.bufferlessSurfaceFramesTX.end()) { |
| 1313 | auto surfaceFrame = createSurfaceFrameForTransaction(info, postTime); |
| 1314 | mCurrentState.bufferlessSurfaceFramesTX[info.vsyncId] = surfaceFrame; |
| 1315 | } else { |
| 1316 | if (it->second->getPresentState() == PresentState::Presented) { |
| 1317 | // If the SurfaceFrame was already presented, its safe to overwrite it since it must |
| 1318 | // have been from previous vsync. |
| 1319 | it->second = createSurfaceFrameForTransaction(info, postTime); |
| 1320 | } |
| 1321 | } |
| 1322 | } |
| 1323 | |
| 1324 | void Layer::addSurfaceFrameDroppedForBuffer( |
| 1325 | std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame) { |
Adithya Srinivasan | 061c14c | 2021-02-11 01:19:47 +0000 | [diff] [blame] | 1326 | surfaceFrame->setDropTime(systemTime()); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1327 | surfaceFrame->setPresentState(PresentState::Dropped); |
| 1328 | mFlinger->mFrameTimeline->addSurfaceFrame(surfaceFrame); |
| 1329 | } |
| 1330 | |
| 1331 | void Layer::addSurfaceFramePresentedForBuffer( |
| 1332 | std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame, nsecs_t acquireFenceTime, |
| 1333 | nsecs_t currentLatchTime) { |
| 1334 | surfaceFrame->setAcquireFenceTime(acquireFenceTime); |
| 1335 | surfaceFrame->setPresentState(PresentState::Presented, mLastLatchTime); |
| 1336 | mFlinger->mFrameTimeline->addSurfaceFrame(surfaceFrame); |
| 1337 | mLastLatchTime = currentLatchTime; |
| 1338 | } |
| 1339 | |
| 1340 | std::shared_ptr<frametimeline::SurfaceFrame> Layer::createSurfaceFrameForTransaction( |
| 1341 | const FrameTimelineInfo& info, nsecs_t postTime) { |
| 1342 | auto surfaceFrame = |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1343 | mFlinger->mFrameTimeline->createSurfaceFrameForToken(info, mOwnerPid, mOwnerUid, |
| 1344 | getSequence(), mName, |
Adithya Srinivasan | 785addd | 2021-03-09 00:38:00 +0000 | [diff] [blame] | 1345 | mTransactionName, |
| 1346 | /*isBuffer*/ false); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1347 | // For Transactions, the post time is considered to be both queue and acquire fence time. |
| 1348 | surfaceFrame->setActualQueueTime(postTime); |
| 1349 | surfaceFrame->setAcquireFenceTime(postTime); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 1350 | const auto fps = mFlinger->mScheduler->getFrameRateOverride(getOwnerUid()); |
| 1351 | if (fps) { |
Alec Mouri | 819f630 | 2021-02-12 15:37:21 -0800 | [diff] [blame] | 1352 | surfaceFrame->setRenderRate(*fps); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 1353 | } |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1354 | onSurfaceFrameCreated(surfaceFrame); |
| 1355 | return surfaceFrame; |
| 1356 | } |
| 1357 | |
| 1358 | std::shared_ptr<frametimeline::SurfaceFrame> Layer::createSurfaceFrameForBuffer( |
| 1359 | const FrameTimelineInfo& info, nsecs_t queueTime, std::string debugName) { |
| 1360 | auto surfaceFrame = |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 1361 | mFlinger->mFrameTimeline->createSurfaceFrameForToken(info, mOwnerPid, mOwnerUid, |
Adithya Srinivasan | 785addd | 2021-03-09 00:38:00 +0000 | [diff] [blame] | 1362 | getSequence(), mName, debugName, |
| 1363 | /*isBuffer*/ true); |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1364 | // For buffers, acquire fence time will set during latch. |
| 1365 | surfaceFrame->setActualQueueTime(queueTime); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 1366 | const auto fps = mFlinger->mScheduler->getFrameRateOverride(getOwnerUid()); |
| 1367 | if (fps) { |
Alec Mouri | 819f630 | 2021-02-12 15:37:21 -0800 | [diff] [blame] | 1368 | surfaceFrame->setRenderRate(*fps); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 1369 | } |
Adithya Srinivasan | b9a7dab | 2021-01-14 23:49:46 +0000 | [diff] [blame] | 1370 | // TODO(b/178542907): Implement onSurfaceFrameCreated for BQLayer as well. |
| 1371 | onSurfaceFrameCreated(surfaceFrame); |
| 1372 | return surfaceFrame; |
Ady Abraham | 74e1756 | 2020-08-24 18:18:19 -0700 | [diff] [blame] | 1373 | } |
| 1374 | |
Ady Abraham | 59fd8ff | 2021-04-15 20:13:30 -0700 | [diff] [blame] | 1375 | bool Layer::updateFrameRateForLayerTree(bool treeHasFrameRateVote) { |
| 1376 | const auto updateCurrentState = [&](FrameRate frameRate) { |
| 1377 | if (mCurrentState.frameRateForLayerTree == frameRate) { |
| 1378 | return false; |
| 1379 | } |
| 1380 | mCurrentState.frameRateForLayerTree = frameRate; |
| 1381 | mCurrentState.sequence++; |
| 1382 | mCurrentState.modified = true; |
| 1383 | setTransactionFlags(eTransactionNeeded); |
| 1384 | return true; |
| 1385 | }; |
| 1386 | |
| 1387 | const auto frameRate = mCurrentState.frameRate; |
Marin Shalamanov | e8a663d | 2020-11-24 17:48:00 +0100 | [diff] [blame] | 1388 | if (frameRate.rate.isValid() || frameRate.type == FrameRateCompatibility::NoVote) { |
Ady Abraham | 59fd8ff | 2021-04-15 20:13:30 -0700 | [diff] [blame] | 1389 | return updateCurrentState(frameRate); |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1390 | } |
| 1391 | |
Ady Abraham | f467f89 | 2020-07-31 16:01:53 -0700 | [diff] [blame] | 1392 | // This layer doesn't have a frame rate. Check if its ancestors have a vote |
Ady Abraham | 59fd8ff | 2021-04-15 20:13:30 -0700 | [diff] [blame] | 1393 | for (sp<Layer> parent = getParent(); parent; parent = parent->getParent()) { |
| 1394 | if (parent->mCurrentState.frameRate.rate.isValid()) { |
| 1395 | return updateCurrentState(parent->mCurrentState.frameRate); |
Ady Abraham | f467f89 | 2020-07-31 16:01:53 -0700 | [diff] [blame] | 1396 | } |
| 1397 | } |
| 1398 | |
| 1399 | // This layer and its ancestors don't have a frame rate. If one of successors |
| 1400 | // has a vote, return a NoVote for successors to set the vote |
Ady Abraham | 59fd8ff | 2021-04-15 20:13:30 -0700 | [diff] [blame] | 1401 | if (treeHasFrameRateVote) { |
| 1402 | return updateCurrentState(FrameRate(Fps(0.0f), FrameRateCompatibility::NoVote)); |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1403 | } |
| 1404 | |
Ady Abraham | 59fd8ff | 2021-04-15 20:13:30 -0700 | [diff] [blame] | 1405 | return updateCurrentState(frameRate); |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 1406 | } |
| 1407 | |
Ady Abraham | 59fd8ff | 2021-04-15 20:13:30 -0700 | [diff] [blame] | 1408 | Layer::FrameRate Layer::getFrameRateForLayerTree() const { |
| 1409 | return getDrawingState().frameRateForLayerTree; |
| 1410 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1411 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1412 | bool Layer::isHiddenByPolicy() const { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1413 | const State& s(mDrawingState); |
Chia-I Wu | e41dbe6 | 2017-06-13 14:10:56 -0700 | [diff] [blame] | 1414 | const auto& parent = mDrawingParent.promote(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1415 | if (parent != nullptr && parent->isHiddenByPolicy()) { |
| 1416 | return true; |
| 1417 | } |
Robert Carr | 1c5481e | 2019-07-01 14:42:27 -0700 | [diff] [blame] | 1418 | if (usingRelativeZ(LayerVector::StateSet::Drawing)) { |
| 1419 | auto zOrderRelativeOf = mDrawingState.zOrderRelativeOf.promote(); |
| 1420 | if (zOrderRelativeOf != nullptr) { |
| 1421 | if (zOrderRelativeOf->isHiddenByPolicy()) { |
| 1422 | return true; |
| 1423 | } |
| 1424 | } |
| 1425 | } |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1426 | return s.flags & layer_state_t::eLayerHidden; |
| 1427 | } |
| 1428 | |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 1429 | uint32_t Layer::getEffectiveUsage(uint32_t usage) const { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1430 | // TODO: should we do something special if mSecure is set? |
| 1431 | if (mProtectedByApp) { |
| 1432 | // need a hardware-protected path to external video sink |
| 1433 | usage |= GraphicBuffer::USAGE_PROTECTED; |
Jamie Gennis | 54cc83e | 2010-11-02 11:51:32 -0700 | [diff] [blame] | 1434 | } |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 1435 | if (mPotentialCursor) { |
| 1436 | usage |= GraphicBuffer::USAGE_CURSOR; |
| 1437 | } |
Jamie Gennis | 3599bf2 | 2011-08-10 11:48:07 -0700 | [diff] [blame] | 1438 | usage |= GraphicBuffer::USAGE_HW_COMPOSER; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 1439 | return usage; |
Mathias Agopian | b5b7f26 | 2010-05-07 15:58:44 -0700 | [diff] [blame] | 1440 | } |
| 1441 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 1442 | void Layer::updateTransformHint(ui::Transform::RotationFlags transformHint) { |
| 1443 | if (mFlinger->mDebugDisableTransformHint || transformHint & ui::Transform::ROT_INVALID) { |
| 1444 | transformHint = ui::Transform::ROT_0; |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 1445 | } |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 1446 | |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 1447 | setTransformHint(transformHint); |
Mathias Agopian | a458364 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 1448 | } |
| 1449 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1450 | // ---------------------------------------------------------------------------- |
| 1451 | // debugging |
| 1452 | // ---------------------------------------------------------------------------- |
| 1453 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1454 | // TODO(marissaw): add new layer state info to layer debugging |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 1455 | LayerDebugInfo Layer::getLayerDebugInfo(const DisplayDevice* display) const { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 1456 | using namespace std::string_literals; |
| 1457 | |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1458 | LayerDebugInfo info; |
Alec Mouri | b416efd | 2018-09-06 21:01:59 +0000 | [diff] [blame] | 1459 | const State& ds = getDrawingState(); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1460 | info.mName = getName(); |
Vishnu Nair | 43bccf8 | 2020-06-05 10:53:37 -0700 | [diff] [blame] | 1461 | sp<Layer> parent = mDrawingParent.promote(); |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 1462 | info.mParentName = parent ? parent->getName() : "none"s; |
chaviw | 8a01fa4 | 2019-08-19 12:39:31 -0700 | [diff] [blame] | 1463 | info.mType = getType(); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1464 | info.mTransparentRegion = ds.activeTransparentRegion_legacy; |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 1465 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 1466 | info.mVisibleRegion = getVisibleRegion(display); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1467 | info.mSurfaceDamageRegion = surfaceDamageRegion; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1468 | info.mLayerStack = getLayerStack(); |
chaviw | 4e76553 | 2021-04-30 12:11:39 -0500 | [diff] [blame] | 1469 | info.mX = ds.transform.tx(); |
| 1470 | info.mY = ds.transform.ty(); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1471 | info.mZ = ds.z; |
chaviw | 4e76553 | 2021-04-30 12:11:39 -0500 | [diff] [blame] | 1472 | info.mWidth = ds.width; |
| 1473 | info.mHeight = ds.height; |
chaviw | 2571450 | 2021-02-11 10:01:08 -0800 | [diff] [blame] | 1474 | info.mCrop = ds.crop; |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 1475 | info.mColor = ds.color; |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1476 | info.mFlags = ds.flags; |
| 1477 | info.mPixelFormat = getPixelFormat(); |
chaviw | 4244e03 | 2019-09-04 11:27:49 -0700 | [diff] [blame] | 1478 | info.mDataSpace = static_cast<android_dataspace>(getDataSpace()); |
chaviw | 4e76553 | 2021-04-30 12:11:39 -0500 | [diff] [blame] | 1479 | info.mMatrix[0][0] = ds.transform[0][0]; |
| 1480 | info.mMatrix[0][1] = ds.transform[0][1]; |
| 1481 | info.mMatrix[1][0] = ds.transform[1][0]; |
| 1482 | info.mMatrix[1][1] = ds.transform[1][1]; |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1483 | { |
chaviw | d62d306 | 2019-09-04 14:48:02 -0700 | [diff] [blame] | 1484 | sp<const GraphicBuffer> buffer = getBuffer(); |
David Sodman | 5b4cffc | 2017-11-23 13:20:29 -0800 | [diff] [blame] | 1485 | if (buffer != 0) { |
| 1486 | info.mActiveBufferWidth = buffer->getWidth(); |
| 1487 | info.mActiveBufferHeight = buffer->getHeight(); |
| 1488 | info.mActiveBufferStride = buffer->getStride(); |
| 1489 | info.mActiveBufferFormat = buffer->format; |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1490 | } else { |
| 1491 | info.mActiveBufferWidth = 0; |
| 1492 | info.mActiveBufferHeight = 0; |
| 1493 | info.mActiveBufferStride = 0; |
| 1494 | info.mActiveBufferFormat = 0; |
| 1495 | } |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1496 | } |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1497 | info.mNumQueuedFrames = getQueuedFrameCount(); |
| 1498 | info.mRefreshPending = isBufferLatched(); |
| 1499 | info.mIsOpaque = isOpaque(ds); |
| 1500 | info.mContentDirty = contentDirty; |
John Reck | c00c669 | 2021-02-16 11:37:33 -0500 | [diff] [blame] | 1501 | info.mStretchEffect = getStretchEffect(); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 1502 | return info; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1503 | } |
Chia-I Wu | 83ce7c1 | 2017-10-19 15:18:55 -0700 | [diff] [blame] | 1504 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1505 | void Layer::miniDumpHeader(std::string& result) { |
Marin Shalamanov | 1876e2e | 2020-12-04 13:23:59 +0100 | [diff] [blame] | 1506 | result.append(kDumpTableRowLength, '-'); |
| 1507 | result.append("\n"); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1508 | result.append(" Layer name\n"); |
| 1509 | result.append(" Z | "); |
Ady Abraham | 8f1ee7f | 2019-04-05 10:32:50 -0700 | [diff] [blame] | 1510 | result.append(" Window Type | "); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1511 | result.append(" Comp Type | "); |
Yichi Chen | 6ca3519 | 2018-05-29 12:20:43 +0800 | [diff] [blame] | 1512 | result.append(" Transform | "); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1513 | result.append(" Disp Frame (LTRB) | "); |
Ady Abraham | be23e6a | 2020-05-04 14:51:16 -0700 | [diff] [blame] | 1514 | result.append(" Source Crop (LTRB) | "); |
Marin Shalamanov | 1876e2e | 2020-12-04 13:23:59 +0100 | [diff] [blame] | 1515 | result.append(" Frame Rate (Explicit) (Seamlessness) [Focused]\n"); |
| 1516 | result.append(kDumpTableRowLength, '-'); |
| 1517 | result.append("\n"); |
Ady Abraham | be23e6a | 2020-05-04 14:51:16 -0700 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | std::string Layer::frameRateCompatibilityString(Layer::FrameRateCompatibility compatibility) { |
| 1521 | switch (compatibility) { |
| 1522 | case FrameRateCompatibility::Default: |
| 1523 | return "Default"; |
| 1524 | case FrameRateCompatibility::ExactOrMultiple: |
| 1525 | return "ExactOrMultiple"; |
| 1526 | case FrameRateCompatibility::NoVote: |
| 1527 | return "NoVote"; |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 1528 | case FrameRateCompatibility::Exact: |
| 1529 | return "Exact"; |
Ady Abraham | be23e6a | 2020-05-04 14:51:16 -0700 | [diff] [blame] | 1530 | } |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1531 | } |
| 1532 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 1533 | void Layer::miniDump(std::string& result, const DisplayDevice& display) const { |
| 1534 | const auto outputLayer = findOutputLayerForDisplay(&display); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 1535 | if (!outputLayer) { |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1536 | return; |
| 1537 | } |
| 1538 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1539 | std::string name; |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1540 | if (mName.length() > 77) { |
| 1541 | std::string shortened; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 1542 | shortened.append(mName, 0, 36); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1543 | shortened.append("[...]"); |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 1544 | shortened.append(mName, mName.length() - 36); |
| 1545 | name = std::move(shortened); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1546 | } else { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 1547 | name = mName; |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1548 | } |
| 1549 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1550 | StringAppendF(&result, " %s\n", name.c_str()); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1551 | |
Alec Mouri | b416efd | 2018-09-06 21:01:59 +0000 | [diff] [blame] | 1552 | const State& layerState(getDrawingState()); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1553 | const auto& outputLayerState = outputLayer->getState(); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 1554 | |
Chia-I Wu | 1e04361 | 2018-03-01 09:45:09 -0800 | [diff] [blame] | 1555 | if (layerState.zOrderRelativeOf != nullptr || mDrawingParent != nullptr) { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1556 | StringAppendF(&result, " rel %6d | ", layerState.z); |
Chia-I Wu | 1e04361 | 2018-03-01 09:45:09 -0800 | [diff] [blame] | 1557 | } else { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1558 | StringAppendF(&result, " %10d | ", layerState.z); |
Chia-I Wu | 1e04361 | 2018-03-01 09:45:09 -0800 | [diff] [blame] | 1559 | } |
Ady Abraham | 8f1ee7f | 2019-04-05 10:32:50 -0700 | [diff] [blame] | 1560 | StringAppendF(&result, " %10d | ", mWindowType); |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 1561 | StringAppendF(&result, "%10s | ", toString(getCompositionType(display)).c_str()); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1562 | StringAppendF(&result, "%10s | ", toString(outputLayerState.bufferTransform).c_str()); |
| 1563 | const Rect& frame = outputLayerState.displayFrame; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1564 | StringAppendF(&result, "%4d %4d %4d %4d | ", frame.left, frame.top, frame.right, frame.bottom); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 1565 | const FloatRect& crop = outputLayerState.sourceCrop; |
Ady Abraham | be23e6a | 2020-05-04 14:51:16 -0700 | [diff] [blame] | 1566 | StringAppendF(&result, "%6.1f %6.1f %6.1f %6.1f | ", crop.left, crop.top, crop.right, |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1567 | crop.bottom); |
Ady Abraham | f467f89 | 2020-07-31 16:01:53 -0700 | [diff] [blame] | 1568 | const auto frameRate = getFrameRateForLayerTree(); |
| 1569 | if (frameRate.rate.isValid() || frameRate.type != FrameRateCompatibility::Default) { |
| 1570 | StringAppendF(&result, "%s %15s %17s", to_string(frameRate.rate).c_str(), |
| 1571 | frameRateCompatibilityString(frameRate.type).c_str(), |
| 1572 | toString(frameRate.seamlessness).c_str()); |
Ady Abraham | be23e6a | 2020-05-04 14:51:16 -0700 | [diff] [blame] | 1573 | } else { |
Marin Shalamanov | 1876e2e | 2020-12-04 13:23:59 +0100 | [diff] [blame] | 1574 | result.append(41, ' '); |
Ady Abraham | be23e6a | 2020-05-04 14:51:16 -0700 | [diff] [blame] | 1575 | } |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1576 | |
Ady Abraham | aae5ed5 | 2020-06-26 09:32:43 -0700 | [diff] [blame] | 1577 | const auto focused = isLayerFocusedBasedOnPriority(getFrameRateSelectionPriority()); |
| 1578 | StringAppendF(&result, " [%s]\n", focused ? "*" : " "); |
| 1579 | |
Marin Shalamanov | 1876e2e | 2020-12-04 13:23:59 +0100 | [diff] [blame] | 1580 | result.append(kDumpTableRowLength, '-'); |
| 1581 | result.append("\n"); |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1582 | } |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 1583 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1584 | void Layer::dumpFrameStats(std::string& result) const { |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 1585 | mFrameTracker.dumpStats(result); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1586 | } |
| 1587 | |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 1588 | void Layer::clearFrameStats() { |
| 1589 | mFrameTracker.clearStats(); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 1590 | } |
| 1591 | |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 1592 | void Layer::logFrameStats() { |
| 1593 | mFrameTracker.logAndResetStats(mName); |
| 1594 | } |
| 1595 | |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 1596 | void Layer::getFrameStats(FrameStats* outStats) const { |
| 1597 | mFrameTracker.getStats(outStats); |
| 1598 | } |
| 1599 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1600 | void Layer::dumpFrameEvents(std::string& result) { |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 1601 | StringAppendF(&result, "- Layer %s (%s, %p)\n", getName().c_str(), getType(), this); |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 1602 | Mutex::Autolock lock(mFrameEventHistoryMutex); |
| 1603 | mFrameEventHistory.checkFencesForCompletion(); |
| 1604 | mFrameEventHistory.dump(result); |
| 1605 | } |
Pablo Ceballos | 40845df | 2016-01-25 17:41:15 -0800 | [diff] [blame] | 1606 | |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 1607 | void Layer::dumpCallingUidPid(std::string& result) const { |
chaviw | 250bcbb | 2020-08-05 11:17:54 -0700 | [diff] [blame] | 1608 | StringAppendF(&result, "Layer %s (%s) callingPid:%d callingUid:%d ownerUid:%d\n", |
| 1609 | getName().c_str(), getType(), mCallingPid, mCallingUid, mOwnerUid); |
Vishnu Nair | 0f085c6 | 2019-08-30 08:49:12 -0700 | [diff] [blame] | 1610 | } |
| 1611 | |
Brian Anderson | 5ea5e59 | 2016-12-01 16:54:33 -0800 | [diff] [blame] | 1612 | void Layer::onDisconnect() { |
| 1613 | Mutex::Autolock lock(mFrameEventHistoryMutex); |
| 1614 | mFrameEventHistory.onDisconnect(); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 1615 | const int32_t layerId = getSequence(); |
| 1616 | mFlinger->mTimeStats->onDestroy(layerId); |
| 1617 | mFlinger->mFrameTracer->onDestroy(layerId); |
Brian Anderson | 5ea5e59 | 2016-12-01 16:54:33 -0800 | [diff] [blame] | 1618 | } |
| 1619 | |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1620 | void Layer::addAndGetFrameTimestamps(const NewFrameEventsEntry* newTimestamps, |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 1621 | FrameEventHistoryDelta* outDelta) { |
Yiwei Zhang | faf3ded | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 1622 | if (newTimestamps) { |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 1623 | mFlinger->mTimeStats->setPostTime(getSequence(), newTimestamps->frameNumber, |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 1624 | getName().c_str(), mOwnerUid, newTimestamps->postedTime); |
Yiwei Zhang | 487340f | 2019-11-18 17:42:12 -0800 | [diff] [blame] | 1625 | mFlinger->mTimeStats->setAcquireFence(getSequence(), newTimestamps->frameNumber, |
| 1626 | newTimestamps->acquireFence); |
Yiwei Zhang | faf3ded | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 1627 | } |
| 1628 | |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 1629 | Mutex::Autolock lock(mFrameEventHistoryMutex); |
| 1630 | if (newTimestamps) { |
Brian Anderson | fbc80ae | 2017-05-26 16:23:54 -0700 | [diff] [blame] | 1631 | // If there are any unsignaled fences in the aquire timeline at this |
| 1632 | // point, the previously queued frame hasn't been latched yet. Go ahead |
| 1633 | // and try to get the signal time here so the syscall is taken out of |
| 1634 | // the main thread's critical path. |
| 1635 | mAcquireTimeline.updateSignalTimes(); |
| 1636 | // Push the new fence after updating since it's likely still pending. |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 1637 | mAcquireTimeline.push(newTimestamps->acquireFence); |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 1638 | mFrameEventHistory.addQueue(*newTimestamps); |
| 1639 | } |
| 1640 | |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 1641 | if (outDelta) { |
| 1642 | mFrameEventHistory.getAndResetDelta(outDelta); |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 1643 | } |
Pablo Ceballos | 40845df | 2016-01-25 17:41:15 -0800 | [diff] [blame] | 1644 | } |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 1645 | |
Chia-I Wu | 98f1c10 | 2017-05-30 14:54:08 -0700 | [diff] [blame] | 1646 | size_t Layer::getChildrenCount() const { |
| 1647 | size_t count = 0; |
| 1648 | for (const sp<Layer>& child : mCurrentChildren) { |
| 1649 | count += 1 + child->getChildrenCount(); |
| 1650 | } |
| 1651 | return count; |
| 1652 | } |
| 1653 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1654 | void Layer::addChild(const sp<Layer>& layer) { |
Robert Carr | 1323c95 | 2019-01-28 18:13:27 -0800 | [diff] [blame] | 1655 | mChildrenChanged = true; |
Robert Carr | 7f2ed8b | 2019-02-07 14:45:11 -0800 | [diff] [blame] | 1656 | setTransactionFlags(eTransactionNeeded); |
Robert Carr | 1323c95 | 2019-01-28 18:13:27 -0800 | [diff] [blame] | 1657 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1658 | mCurrentChildren.add(layer); |
| 1659 | layer->setParent(this); |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1660 | updateTreeHasFrameRateVote(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1661 | } |
| 1662 | |
| 1663 | ssize_t Layer::removeChild(const sp<Layer>& layer) { |
Robert Carr | 1323c95 | 2019-01-28 18:13:27 -0800 | [diff] [blame] | 1664 | mChildrenChanged = true; |
Robert Carr | 7f2ed8b | 2019-02-07 14:45:11 -0800 | [diff] [blame] | 1665 | setTransactionFlags(eTransactionNeeded); |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 1666 | |
Robert Carr | 1323c95 | 2019-01-28 18:13:27 -0800 | [diff] [blame] | 1667 | layer->setParent(nullptr); |
Ady Abraham | 60e42ea | 2020-03-09 19:17:31 -0700 | [diff] [blame] | 1668 | const auto removeResult = mCurrentChildren.remove(layer); |
| 1669 | |
| 1670 | updateTreeHasFrameRateVote(); |
| 1671 | layer->updateTreeHasFrameRateVote(); |
| 1672 | |
| 1673 | return removeResult; |
| 1674 | } |
| 1675 | |
Robert Carr | 15eae09 | 2018-03-23 13:43:53 -0700 | [diff] [blame] | 1676 | void Layer::setChildrenDrawingParent(const sp<Layer>& newParent) { |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 1677 | for (const sp<Layer>& child : mDrawingChildren) { |
| 1678 | child->mDrawingParent = newParent; |
Vishnu Nair | 6bdec7d | 2021-05-10 15:01:13 -0700 | [diff] [blame] | 1679 | child->computeBounds(newParent->mBounds, newParent->mEffectiveTransform, |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 1680 | newParent->mEffectiveShadowRadius); |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 1681 | } |
| 1682 | } |
| 1683 | |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 1684 | bool Layer::reparent(const sp<IBinder>& newParentHandle) { |
Robert Carr | 54cf5b1 | 2019-01-25 14:02:28 -0800 | [diff] [blame] | 1685 | sp<Layer> newParent; |
| 1686 | if (newParentHandle != nullptr) { |
| 1687 | auto handle = static_cast<Handle*>(newParentHandle.get()); |
| 1688 | newParent = handle->owner.promote(); |
| 1689 | if (newParent == nullptr) { |
| 1690 | ALOGE("Unable to promote Layer handle"); |
| 1691 | return false; |
| 1692 | } |
| 1693 | if (newParent == this) { |
| 1694 | ALOGE("Invalid attempt to reparent Layer (%s) to itself", getName().c_str()); |
| 1695 | return false; |
| 1696 | } |
| 1697 | } |
| 1698 | |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 1699 | sp<Layer> parent = getParent(); |
| 1700 | if (parent != nullptr) { |
| 1701 | parent->removeChild(this); |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 1702 | } |
| 1703 | |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 1704 | if (newParentHandle != nullptr) { |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 1705 | newParent->addChild(this); |
| 1706 | if (!newParent->isRemovedFromCurrentState()) { |
| 1707 | addToCurrentState(); |
| 1708 | } else { |
| 1709 | onRemovedFromCurrentState(); |
| 1710 | } |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 1711 | } else { |
| 1712 | onRemovedFromCurrentState(); |
chaviw | 61626f2 | 2018-11-15 16:26:27 -0800 | [diff] [blame] | 1713 | } |
| 1714 | |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 1715 | return true; |
| 1716 | } |
| 1717 | |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 1718 | bool Layer::setColorTransform(const mat4& matrix) { |
Peiyong Lin | 747321c | 2018-10-01 10:03:11 -0700 | [diff] [blame] | 1719 | static const mat4 identityMatrix = mat4(); |
| 1720 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1721 | if (mCurrentState.colorTransform == matrix) { |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 1722 | return false; |
| 1723 | } |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1724 | ++mCurrentState.sequence; |
| 1725 | mCurrentState.colorTransform = matrix; |
| 1726 | mCurrentState.hasColorTransform = matrix != identityMatrix; |
| 1727 | mCurrentState.modified = true; |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 1728 | setTransactionFlags(eTransactionNeeded); |
| 1729 | return true; |
| 1730 | } |
| 1731 | |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 1732 | mat4 Layer::getColorTransform() const { |
| 1733 | mat4 colorTransform = mat4(getDrawingState().colorTransform); |
| 1734 | if (sp<Layer> parent = mDrawingParent.promote(); parent != nullptr) { |
| 1735 | colorTransform = parent->getColorTransform() * colorTransform; |
| 1736 | } |
| 1737 | return colorTransform; |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | bool Layer::hasColorTransform() const { |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 1741 | bool hasColorTransform = getDrawingState().hasColorTransform; |
| 1742 | if (sp<Layer> parent = mDrawingParent.promote(); parent != nullptr) { |
| 1743 | hasColorTransform = hasColorTransform || parent->hasColorTransform(); |
| 1744 | } |
| 1745 | return hasColorTransform; |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 1746 | } |
| 1747 | |
Chia-I Wu | 1148147 | 2018-05-04 10:43:19 -0700 | [diff] [blame] | 1748 | bool Layer::isLegacyDataSpace() const { |
| 1749 | // return true when no higher bits are set |
chaviw | 4244e03 | 2019-09-04 11:27:49 -0700 | [diff] [blame] | 1750 | return !(getDataSpace() & |
| 1751 | (ui::Dataspace::STANDARD_MASK | ui::Dataspace::TRANSFER_MASK | |
| 1752 | ui::Dataspace::RANGE_MASK)); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 1753 | } |
| 1754 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1755 | void Layer::setParent(const sp<Layer>& layer) { |
Chia-I Wu | e41dbe6 | 2017-06-13 14:10:56 -0700 | [diff] [blame] | 1756 | mCurrentParent = layer; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1757 | } |
| 1758 | |
chaviw | 301b1d8 | 2019-11-06 13:15:09 -0800 | [diff] [blame] | 1759 | int32_t Layer::getZ(LayerVector::StateSet stateSet) const { |
| 1760 | const bool useDrawing = stateSet == LayerVector::StateSet::Drawing; |
| 1761 | const State& state = useDrawing ? mDrawingState : mCurrentState; |
| 1762 | return state.z; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1763 | } |
| 1764 | |
Robert Carr | 1c5481e | 2019-07-01 14:42:27 -0700 | [diff] [blame] | 1765 | bool Layer::usingRelativeZ(LayerVector::StateSet stateSet) const { |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1766 | const bool useDrawing = stateSet == LayerVector::StateSet::Drawing; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1767 | const State& state = useDrawing ? mDrawingState : mCurrentState; |
chaviw | e5ac40f | 2019-09-24 16:36:55 -0700 | [diff] [blame] | 1768 | return state.isRelativeOf; |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1769 | } |
| 1770 | |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 1771 | __attribute__((no_sanitize("unsigned-integer-overflow"))) LayerVector Layer::makeTraversalList( |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1772 | LayerVector::StateSet stateSet, bool* outSkipRelativeZUsers) { |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1773 | LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid, |
| 1774 | "makeTraversalList received invalid stateSet"); |
| 1775 | const bool useDrawing = stateSet == LayerVector::StateSet::Drawing; |
| 1776 | const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1777 | const State& state = useDrawing ? mDrawingState : mCurrentState; |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1778 | |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1779 | if (state.zOrderRelatives.size() == 0) { |
| 1780 | *outSkipRelativeZUsers = true; |
| 1781 | return children; |
| 1782 | } |
| 1783 | |
chaviw | fd46261 | 2018-05-31 16:11:27 -0700 | [diff] [blame] | 1784 | LayerVector traverse(stateSet); |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1785 | for (const wp<Layer>& weakRelative : state.zOrderRelatives) { |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1786 | sp<Layer> strongRelative = weakRelative.promote(); |
| 1787 | if (strongRelative != nullptr) { |
| 1788 | traverse.add(strongRelative); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1789 | } |
| 1790 | } |
| 1791 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1792 | for (const sp<Layer>& child : children) { |
chaviw | e5ac40f | 2019-09-24 16:36:55 -0700 | [diff] [blame] | 1793 | if (child->usingRelativeZ(stateSet)) { |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 1794 | continue; |
| 1795 | } |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1796 | traverse.add(child); |
| 1797 | } |
| 1798 | |
| 1799 | return traverse; |
| 1800 | } |
| 1801 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1802 | /** |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1803 | * Negatively signed relatives are before 'this' in Z-order. |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1804 | */ |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1805 | void Layer::traverseInZOrder(LayerVector::StateSet stateSet, const LayerVector::Visitor& visitor) { |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1806 | // In the case we have other layers who are using a relative Z to us, makeTraversalList will |
| 1807 | // produce a new list for traversing, including our relatives, and not including our children |
| 1808 | // who are relatives of another surface. In the case that there are no relative Z, |
| 1809 | // makeTraversalList returns our children directly to avoid significant overhead. |
| 1810 | // However in this case we need to take the responsibility for filtering children which |
| 1811 | // are relatives of another surface here. |
| 1812 | bool skipRelativeZUsers = false; |
| 1813 | const LayerVector list = makeTraversalList(stateSet, &skipRelativeZUsers); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1814 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1815 | size_t i = 0; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1816 | for (; i < list.size(); i++) { |
| 1817 | const auto& relative = list[i]; |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1818 | if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) { |
| 1819 | continue; |
| 1820 | } |
| 1821 | |
chaviw | 301b1d8 | 2019-11-06 13:15:09 -0800 | [diff] [blame] | 1822 | if (relative->getZ(stateSet) >= 0) { |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1823 | break; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1824 | } |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1825 | relative->traverseInZOrder(stateSet, visitor); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1826 | } |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1827 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1828 | visitor(this); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1829 | for (; i < list.size(); i++) { |
| 1830 | const auto& relative = list[i]; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1831 | |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1832 | if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) { |
| 1833 | continue; |
| 1834 | } |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1835 | relative->traverseInZOrder(stateSet, visitor); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1836 | } |
| 1837 | } |
| 1838 | |
| 1839 | /** |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1840 | * Positively signed relatives are before 'this' in reverse Z-order. |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1841 | */ |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1842 | void Layer::traverseInReverseZOrder(LayerVector::StateSet stateSet, |
| 1843 | const LayerVector::Visitor& visitor) { |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1844 | // See traverseInZOrder for documentation. |
| 1845 | bool skipRelativeZUsers = false; |
| 1846 | LayerVector list = makeTraversalList(stateSet, &skipRelativeZUsers); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1847 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1848 | int32_t i = 0; |
Joel Galenson | bf32499 | 2017-11-06 11:04:12 -0800 | [diff] [blame] | 1849 | for (i = int32_t(list.size()) - 1; i >= 0; i--) { |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1850 | const auto& relative = list[i]; |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1851 | |
| 1852 | if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) { |
| 1853 | continue; |
| 1854 | } |
| 1855 | |
chaviw | 301b1d8 | 2019-11-06 13:15:09 -0800 | [diff] [blame] | 1856 | if (relative->getZ(stateSet) < 0) { |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1857 | break; |
| 1858 | } |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1859 | relative->traverseInReverseZOrder(stateSet, visitor); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1860 | } |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1861 | visitor(this); |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 1862 | for (; i >= 0; i--) { |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1863 | const auto& relative = list[i]; |
Robert Carr | 29abff8 | 2017-12-04 13:51:20 -0800 | [diff] [blame] | 1864 | |
| 1865 | if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) { |
| 1866 | continue; |
| 1867 | } |
| 1868 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1869 | relative->traverseInReverseZOrder(stateSet, visitor); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1870 | } |
| 1871 | } |
| 1872 | |
Edgar Arriaga | 844fa67 | 2020-01-16 14:21:42 -0800 | [diff] [blame] | 1873 | void Layer::traverse(LayerVector::StateSet state, const LayerVector::Visitor& visitor) { |
| 1874 | visitor(this); |
| 1875 | const LayerVector& children = |
| 1876 | state == LayerVector::StateSet::Drawing ? mDrawingChildren : mCurrentChildren; |
| 1877 | for (const sp<Layer>& child : children) { |
| 1878 | child->traverse(state, visitor); |
| 1879 | } |
| 1880 | } |
| 1881 | |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1882 | LayerVector Layer::makeChildrenTraversalList(LayerVector::StateSet stateSet, |
| 1883 | const std::vector<Layer*>& layersInTree) { |
| 1884 | LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid, |
| 1885 | "makeTraversalList received invalid stateSet"); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 1886 | const bool useDrawing = stateSet == LayerVector::StateSet::Drawing; |
| 1887 | const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1888 | const State& state = useDrawing ? mDrawingState : mCurrentState; |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1889 | |
chaviw | fd46261 | 2018-05-31 16:11:27 -0700 | [diff] [blame] | 1890 | LayerVector traverse(stateSet); |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1891 | for (const wp<Layer>& weakRelative : state.zOrderRelatives) { |
| 1892 | sp<Layer> strongRelative = weakRelative.promote(); |
| 1893 | // Only add relative layers that are also descendents of the top most parent of the tree. |
| 1894 | // If a relative layer is not a descendent, then it should be ignored. |
| 1895 | if (std::binary_search(layersInTree.begin(), layersInTree.end(), strongRelative.get())) { |
| 1896 | traverse.add(strongRelative); |
| 1897 | } |
| 1898 | } |
| 1899 | |
| 1900 | for (const sp<Layer>& child : children) { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1901 | const State& childState = useDrawing ? child->mDrawingState : child->mCurrentState; |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1902 | // If a layer has a relativeOf layer, only ignore if the layer it's relative to is a |
| 1903 | // descendent of the top most parent of the tree. If it's not a descendent, then just add |
| 1904 | // the child here since it won't be added later as a relative. |
| 1905 | if (std::binary_search(layersInTree.begin(), layersInTree.end(), |
| 1906 | childState.zOrderRelativeOf.promote().get())) { |
| 1907 | continue; |
| 1908 | } |
| 1909 | traverse.add(child); |
| 1910 | } |
| 1911 | |
| 1912 | return traverse; |
| 1913 | } |
| 1914 | |
| 1915 | void Layer::traverseChildrenInZOrderInner(const std::vector<Layer*>& layersInTree, |
| 1916 | LayerVector::StateSet stateSet, |
| 1917 | const LayerVector::Visitor& visitor) { |
| 1918 | const LayerVector list = makeChildrenTraversalList(stateSet, layersInTree); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 1919 | |
| 1920 | size_t i = 0; |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1921 | for (; i < list.size(); i++) { |
| 1922 | const auto& relative = list[i]; |
chaviw | 301b1d8 | 2019-11-06 13:15:09 -0800 | [diff] [blame] | 1923 | if (relative->getZ(stateSet) >= 0) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 1924 | break; |
| 1925 | } |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1926 | relative->traverseChildrenInZOrderInner(layersInTree, stateSet, visitor); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 1927 | } |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1928 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 1929 | visitor(this); |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1930 | for (; i < list.size(); i++) { |
| 1931 | const auto& relative = list[i]; |
| 1932 | relative->traverseChildrenInZOrderInner(layersInTree, stateSet, visitor); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 1933 | } |
| 1934 | } |
| 1935 | |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 1936 | std::vector<Layer*> Layer::getLayersInTree(LayerVector::StateSet stateSet) { |
| 1937 | const bool useDrawing = stateSet == LayerVector::StateSet::Drawing; |
| 1938 | const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren; |
| 1939 | |
| 1940 | std::vector<Layer*> layersInTree = {this}; |
| 1941 | for (size_t i = 0; i < children.size(); i++) { |
| 1942 | const auto& child = children[i]; |
| 1943 | std::vector<Layer*> childLayers = child->getLayersInTree(stateSet); |
| 1944 | layersInTree.insert(layersInTree.end(), childLayers.cbegin(), childLayers.cend()); |
| 1945 | } |
| 1946 | |
| 1947 | return layersInTree; |
| 1948 | } |
| 1949 | |
| 1950 | void Layer::traverseChildrenInZOrder(LayerVector::StateSet stateSet, |
| 1951 | const LayerVector::Visitor& visitor) { |
| 1952 | std::vector<Layer*> layersInTree = getLayersInTree(stateSet); |
| 1953 | std::sort(layersInTree.begin(), layersInTree.end()); |
| 1954 | traverseChildrenInZOrderInner(layersInTree, stateSet, visitor); |
| 1955 | } |
| 1956 | |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 1957 | ui::Transform Layer::getTransform() const { |
Vishnu Nair | f0c2851 | 2019-02-08 12:40:28 -0800 | [diff] [blame] | 1958 | return mEffectiveTransform; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1959 | } |
| 1960 | |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 1961 | half Layer::getAlpha() const { |
Ady Abraham | 8372988 | 2018-12-07 12:26:48 -0800 | [diff] [blame] | 1962 | const auto& p = mDrawingParent.promote(); |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1963 | |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 1964 | half parentAlpha = (p != nullptr) ? p->getAlpha() : 1.0_hf; |
| 1965 | return parentAlpha * getDrawingState().color.a; |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 1966 | } |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 1967 | |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 1968 | ui::Transform::RotationFlags Layer::getFixedTransformHint() const { |
| 1969 | ui::Transform::RotationFlags fixedTransformHint = mCurrentState.fixedTransformHint; |
| 1970 | if (fixedTransformHint != ui::Transform::ROT_INVALID) { |
| 1971 | return fixedTransformHint; |
| 1972 | } |
| 1973 | const auto& p = mCurrentParent.promote(); |
| 1974 | if (!p) return fixedTransformHint; |
| 1975 | return p->getFixedTransformHint(); |
| 1976 | } |
| 1977 | |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 1978 | half4 Layer::getColor() const { |
| 1979 | const half4 color(getDrawingState().color); |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 1980 | return half4(color.r, color.g, color.b, getAlpha()); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 1981 | } |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 1982 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1983 | int32_t Layer::getBackgroundBlurRadius() const { |
Galia Peycheva | da7de0e | 2020-12-03 17:24:35 +0100 | [diff] [blame] | 1984 | const auto& p = mDrawingParent.promote(); |
| 1985 | |
| 1986 | half parentAlpha = (p != nullptr) ? p->getAlpha() : 1.0_hf; |
| 1987 | return parentAlpha * getDrawingState().backgroundBlurRadius; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1988 | } |
| 1989 | |
Galia Peycheva | e0acf38 | 2021-04-12 21:22:34 +0200 | [diff] [blame] | 1990 | const std::vector<BlurRegion> Layer::getBlurRegions() const { |
| 1991 | auto regionsCopy(getDrawingState().blurRegions); |
| 1992 | int layerAlpha = getAlpha(); |
| 1993 | for (auto& region : regionsCopy) { |
| 1994 | region.alpha = region.alpha * layerAlpha; |
| 1995 | } |
| 1996 | return regionsCopy; |
Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 1997 | } |
| 1998 | |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1999 | Layer::RoundedCornerState Layer::getRoundedCornerState() const { |
| 2000 | const auto& p = mDrawingParent.promote(); |
| 2001 | if (p != nullptr) { |
Peiyong Lin | 27016a9 | 2019-03-29 17:36:08 +0000 | [diff] [blame] | 2002 | RoundedCornerState parentState = p->getRoundedCornerState(); |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 2003 | if (parentState.radius > 0) { |
| 2004 | ui::Transform t = getActiveTransform(getDrawingState()); |
| 2005 | t = t.inverse(); |
| 2006 | parentState.cropRect = t.transform(parentState.cropRect); |
| 2007 | // The rounded corners shader only accepts 1 corner radius for performance reasons, |
| 2008 | // but a transform matrix can define horizontal and vertical scales. |
| 2009 | // Let's take the average between both of them and pass into the shader, practically we |
| 2010 | // never do this type of transformation on windows anyway. |
Lucas Dupin | eab7ea0 | 2020-06-03 17:27:28 -0700 | [diff] [blame] | 2011 | auto scaleX = sqrtf(t[0][0] * t[0][0] + t[0][1] * t[0][1]); |
| 2012 | auto scaleY = sqrtf(t[1][0] * t[1][0] + t[1][1] * t[1][1]); |
| 2013 | parentState.radius *= (scaleX + scaleY) / 2.0f; |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 2014 | return parentState; |
| 2015 | } |
| 2016 | } |
| 2017 | const float radius = getDrawingState().cornerRadius; |
Chavi Weingarten | a5aedbd | 2021-04-09 13:37:33 +0000 | [diff] [blame] | 2018 | return radius > 0 && getCroppedBufferSize(getDrawingState()).isValid() |
| 2019 | ? RoundedCornerState(getCroppedBufferSize(getDrawingState()).toFloatRect(), radius) |
Peiyong Lin | b9ff23e | 2019-04-08 11:04:59 -0700 | [diff] [blame] | 2020 | : RoundedCornerState(); |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 2021 | } |
| 2022 | |
Derek Sollenberger | c31985e | 2021-05-18 16:38:17 -0400 | [diff] [blame] | 2023 | void Layer::prepareShadowClientComposition(LayerFE::LayerSettings& caster, |
| 2024 | const Rect& layerStackRect) { |
Vishnu Nair | 08f6eae | 2019-11-26 14:01:39 -0800 | [diff] [blame] | 2025 | renderengine::ShadowSettings state = mFlinger->mDrawingState.globalShadowSettings; |
| 2026 | |
Derek Sollenberger | c31985e | 2021-05-18 16:38:17 -0400 | [diff] [blame] | 2027 | // Note: this preserves existing behavior of shadowing the entire layer and not cropping it if |
| 2028 | // transparent regions are present. This may not be necessary since shadows are only cast by |
| 2029 | // SurfaceFlinger's EffectLayers, which do not typically use transparent regions. |
| 2030 | state.boundaries = mBounds; |
| 2031 | |
Vishnu Nair | 08f6eae | 2019-11-26 14:01:39 -0800 | [diff] [blame] | 2032 | // Shift the spot light x-position to the middle of the display and then |
| 2033 | // offset it by casting layer's screen pos. |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 2034 | state.lightPos.x = (layerStackRect.width() / 2.f) - mScreenBounds.left; |
Vishnu Nair | 08f6eae | 2019-11-26 14:01:39 -0800 | [diff] [blame] | 2035 | state.lightPos.y -= mScreenBounds.top; |
| 2036 | |
| 2037 | state.length = mEffectiveShadowRadius; |
Derek Sollenberger | c31985e | 2021-05-18 16:38:17 -0400 | [diff] [blame] | 2038 | |
| 2039 | if (state.length > 0.f) { |
| 2040 | const float casterAlpha = caster.alpha; |
| 2041 | const bool casterIsOpaque = |
| 2042 | ((caster.source.buffer.buffer != nullptr) && caster.source.buffer.isOpaque); |
| 2043 | |
| 2044 | // If the casting layer is translucent, we need to fill in the shadow underneath the layer. |
| 2045 | // Otherwise the generated shadow will only be shown around the casting layer. |
| 2046 | state.casterIsTranslucent = !casterIsOpaque || (casterAlpha < 1.0f); |
| 2047 | state.ambientColor *= casterAlpha; |
| 2048 | state.spotColor *= casterAlpha; |
| 2049 | |
| 2050 | if (state.ambientColor.a > 0.f && state.spotColor.a > 0.f) { |
| 2051 | caster.shadow = state; |
| 2052 | } |
| 2053 | } |
Vishnu Nair | 08f6eae | 2019-11-26 14:01:39 -0800 | [diff] [blame] | 2054 | } |
| 2055 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 2056 | void Layer::commitChildList() { |
| 2057 | for (size_t i = 0; i < mCurrentChildren.size(); i++) { |
| 2058 | const auto& child = mCurrentChildren[i]; |
| 2059 | child->commitChildList(); |
| 2060 | } |
| 2061 | mDrawingChildren = mCurrentChildren; |
Chia-I Wu | e41dbe6 | 2017-06-13 14:10:56 -0700 | [diff] [blame] | 2062 | mDrawingParent = mCurrentParent; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 2063 | } |
| 2064 | |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 2065 | static wp<Layer> extractLayerFromBinder(const wp<IBinder>& weakBinderHandle) { |
| 2066 | if (weakBinderHandle == nullptr) { |
| 2067 | return nullptr; |
| 2068 | } |
| 2069 | sp<IBinder> binderHandle = weakBinderHandle.promote(); |
| 2070 | if (binderHandle == nullptr) { |
| 2071 | return nullptr; |
| 2072 | } |
| 2073 | sp<Layer::Handle> handle = static_cast<Layer::Handle*>(binderHandle.get()); |
| 2074 | if (handle == nullptr) { |
| 2075 | return nullptr; |
| 2076 | } |
| 2077 | return handle->owner; |
| 2078 | } |
| 2079 | |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 2080 | void Layer::setInputInfo(const InputWindowInfo& info) { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 2081 | mCurrentState.inputInfo = info; |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 2082 | mCurrentState.touchableRegionCrop = extractLayerFromBinder(info.touchableRegionCropHandle); |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 2083 | mCurrentState.modified = true; |
| 2084 | mCurrentState.inputInfoChanged = true; |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 2085 | setTransactionFlags(eTransactionNeeded); |
| 2086 | } |
| 2087 | |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 2088 | LayerProto* Layer::writeToProto(LayersProto& layersProto, uint32_t traceFlags, |
chaviw | 4c34a09 | 2020-07-08 11:30:06 -0700 | [diff] [blame] | 2089 | const DisplayDevice* display) { |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 2090 | LayerProto* layerProto = layersProto.add_layers(); |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 2091 | writeToProtoDrawingState(layerProto, traceFlags, display); |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 2092 | writeToProtoCommonState(layerProto, LayerVector::StateSet::Drawing, traceFlags); |
| 2093 | |
Vishnu Nair | 60db8c0 | 2020-04-02 11:55:16 -0700 | [diff] [blame] | 2094 | if (traceFlags & SurfaceTracing::TRACE_COMPOSITION) { |
| 2095 | // Only populate for the primary display. |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 2096 | if (display) { |
| 2097 | const Hwc2::IComposerClient::Composition compositionType = getCompositionType(*display); |
Vishnu Nair | 60db8c0 | 2020-04-02 11:55:16 -0700 | [diff] [blame] | 2098 | layerProto->set_hwc_composition_type(static_cast<HwcCompositionType>(compositionType)); |
| 2099 | } |
Alec Mouri | 6b9e991 | 2020-01-21 10:50:24 -0800 | [diff] [blame] | 2100 | } |
| 2101 | |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 2102 | for (const sp<Layer>& layer : mDrawingChildren) { |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 2103 | layer->writeToProto(layersProto, traceFlags, display); |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 2104 | } |
chaviw | 6d89e2d | 2020-01-14 14:42:01 -0800 | [diff] [blame] | 2105 | |
| 2106 | return layerProto; |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 2107 | } |
| 2108 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 2109 | void Layer::writeToProtoDrawingState(LayerProto* layerInfo, uint32_t traceFlags, |
chaviw | 4c34a09 | 2020-07-08 11:30:06 -0700 | [diff] [blame] | 2110 | const DisplayDevice* display) { |
Vishnu Nair | 6b7c5c9 | 2020-09-29 17:27:05 -0700 | [diff] [blame] | 2111 | const ui::Transform transform = getTransform(); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 2112 | |
| 2113 | if (traceFlags & SurfaceTracing::TRACE_CRITICAL) { |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 2114 | |
chaviw | d62d306 | 2019-09-04 14:48:02 -0700 | [diff] [blame] | 2115 | auto buffer = getBuffer(); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 2116 | if (buffer != nullptr) { |
| 2117 | LayerProtoHelper::writeToProto(buffer, |
| 2118 | [&]() { return layerInfo->mutable_active_buffer(); }); |
chaviw | 4244e03 | 2019-09-04 11:27:49 -0700 | [diff] [blame] | 2119 | LayerProtoHelper::writeToProto(ui::Transform(getBufferTransform()), |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 2120 | layerInfo->mutable_buffer_transform()); |
| 2121 | } |
| 2122 | layerInfo->set_invalidate(contentDirty); |
| 2123 | layerInfo->set_is_protected(isProtected()); |
chaviw | 4244e03 | 2019-09-04 11:27:49 -0700 | [diff] [blame] | 2124 | layerInfo->set_dataspace(dataspaceDetails(static_cast<android_dataspace>(getDataSpace()))); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 2125 | layerInfo->set_queued_frames(getQueuedFrameCount()); |
| 2126 | layerInfo->set_refresh_pending(isBufferLatched()); |
| 2127 | layerInfo->set_curr_frame(mCurrentFrameNumber); |
| 2128 | layerInfo->set_effective_scaling_mode(getEffectiveScalingMode()); |
| 2129 | |
| 2130 | layerInfo->set_corner_radius(getRoundedCornerState().radius); |
Ana Krulec | e766cc8 | 2020-04-27 13:49:13 -0700 | [diff] [blame] | 2131 | layerInfo->set_background_blur_radius(getBackgroundBlurRadius()); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 2132 | LayerProtoHelper::writeToProto(transform, layerInfo->mutable_transform()); |
| 2133 | LayerProtoHelper::writePositionToProto(transform.tx(), transform.ty(), |
| 2134 | [&]() { return layerInfo->mutable_position(); }); |
| 2135 | LayerProtoHelper::writeToProto(mBounds, [&]() { return layerInfo->mutable_bounds(); }); |
Vishnu Nair | 60db8c0 | 2020-04-02 11:55:16 -0700 | [diff] [blame] | 2136 | if (traceFlags & SurfaceTracing::TRACE_COMPOSITION) { |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 2137 | LayerProtoHelper::writeToProto(getVisibleRegion(display), |
Vishnu Nair | 60db8c0 | 2020-04-02 11:55:16 -0700 | [diff] [blame] | 2138 | [&]() { return layerInfo->mutable_visible_region(); }); |
| 2139 | } |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 2140 | LayerProtoHelper::writeToProto(surfaceDamageRegion, |
| 2141 | [&]() { return layerInfo->mutable_damage_region(); }); |
chaviw | ddeae26 | 2020-01-06 10:31:23 -0800 | [diff] [blame] | 2142 | |
| 2143 | if (hasColorTransform()) { |
| 2144 | LayerProtoHelper::writeToProto(getColorTransform(), |
| 2145 | layerInfo->mutable_color_transform()); |
| 2146 | } |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 2147 | } |
| 2148 | |
Vishnu Nair | 60db8c0 | 2020-04-02 11:55:16 -0700 | [diff] [blame] | 2149 | LayerProtoHelper::writeToProto(mSourceBounds, |
| 2150 | [&]() { return layerInfo->mutable_source_bounds(); }); |
| 2151 | LayerProtoHelper::writeToProto(mScreenBounds, |
| 2152 | [&]() { return layerInfo->mutable_screen_bounds(); }); |
| 2153 | LayerProtoHelper::writeToProto(getRoundedCornerState().cropRect, |
| 2154 | [&]() { return layerInfo->mutable_corner_radius_crop(); }); |
| 2155 | layerInfo->set_shadow_radius(mEffectiveShadowRadius); |
Vishnu Nair | 8406fd7 | 2019-07-30 11:29:31 -0700 | [diff] [blame] | 2156 | } |
| 2157 | |
| 2158 | void Layer::writeToProtoCommonState(LayerProto* layerInfo, LayerVector::StateSet stateSet, |
chaviw | 4c34a09 | 2020-07-08 11:30:06 -0700 | [diff] [blame] | 2159 | uint32_t traceFlags) { |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 2160 | const bool useDrawing = stateSet == LayerVector::StateSet::Drawing; |
| 2161 | const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren; |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 2162 | const State& state = useDrawing ? mDrawingState : mCurrentState; |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 2163 | |
chaviw | 766c9c5 | 2021-02-10 17:36:47 -0800 | [diff] [blame] | 2164 | ui::Transform requestedTransform = state.transform; |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 2165 | |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2166 | if (traceFlags & SurfaceTracing::TRACE_CRITICAL) { |
| 2167 | layerInfo->set_id(sequence); |
| 2168 | layerInfo->set_name(getName().c_str()); |
chaviw | 8a01fa4 | 2019-08-19 12:39:31 -0700 | [diff] [blame] | 2169 | layerInfo->set_type(getType()); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 2170 | |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2171 | for (const auto& child : children) { |
| 2172 | layerInfo->add_children(child->sequence); |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 2173 | } |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 2174 | |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2175 | for (const wp<Layer>& weakRelative : state.zOrderRelatives) { |
| 2176 | sp<Layer> strongRelative = weakRelative.promote(); |
| 2177 | if (strongRelative != nullptr) { |
| 2178 | layerInfo->add_relatives(strongRelative->sequence); |
| 2179 | } |
chaviw | adc40c2 | 2018-07-10 16:57:27 -0700 | [diff] [blame] | 2180 | } |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2181 | |
| 2182 | LayerProtoHelper::writeToProto(state.activeTransparentRegion_legacy, |
| 2183 | [&]() { return layerInfo->mutable_transparent_region(); }); |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2184 | |
| 2185 | layerInfo->set_layer_stack(getLayerStack()); |
| 2186 | layerInfo->set_z(state.z); |
| 2187 | |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2188 | LayerProtoHelper::writePositionToProto(requestedTransform.tx(), requestedTransform.ty(), |
| 2189 | [&]() { |
| 2190 | return layerInfo->mutable_requested_position(); |
| 2191 | }); |
| 2192 | |
chaviw | 766c9c5 | 2021-02-10 17:36:47 -0800 | [diff] [blame] | 2193 | LayerProtoHelper::writeSizeToProto(state.width, state.height, |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2194 | [&]() { return layerInfo->mutable_size(); }); |
| 2195 | |
chaviw | 766c9c5 | 2021-02-10 17:36:47 -0800 | [diff] [blame] | 2196 | LayerProtoHelper::writeToProto(state.crop, [&]() { return layerInfo->mutable_crop(); }); |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2197 | |
| 2198 | layerInfo->set_is_opaque(isOpaque(state)); |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2199 | |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2200 | |
| 2201 | layerInfo->set_pixel_format(decodePixelFormat(getPixelFormat())); |
| 2202 | LayerProtoHelper::writeToProto(getColor(), [&]() { return layerInfo->mutable_color(); }); |
| 2203 | LayerProtoHelper::writeToProto(state.color, |
| 2204 | [&]() { return layerInfo->mutable_requested_color(); }); |
| 2205 | layerInfo->set_flags(state.flags); |
| 2206 | |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2207 | LayerProtoHelper::writeToProto(requestedTransform, |
| 2208 | layerInfo->mutable_requested_transform()); |
| 2209 | |
| 2210 | auto parent = useDrawing ? mDrawingParent.promote() : mCurrentParent.promote(); |
| 2211 | if (parent != nullptr) { |
| 2212 | layerInfo->set_parent(parent->sequence); |
| 2213 | } else { |
| 2214 | layerInfo->set_parent(-1); |
| 2215 | } |
| 2216 | |
| 2217 | auto zOrderRelativeOf = state.zOrderRelativeOf.promote(); |
| 2218 | if (zOrderRelativeOf != nullptr) { |
| 2219 | layerInfo->set_z_order_relative_of(zOrderRelativeOf->sequence); |
| 2220 | } else { |
| 2221 | layerInfo->set_z_order_relative_of(-1); |
| 2222 | } |
chaviw | 08f3cb2 | 2020-01-13 13:17:21 -0800 | [diff] [blame] | 2223 | |
| 2224 | layerInfo->set_is_relative_of(state.isRelativeOf); |
chaviw | 250bcbb | 2020-08-05 11:17:54 -0700 | [diff] [blame] | 2225 | |
| 2226 | layerInfo->set_owner_uid(mOwnerUid); |
chaviw | adc40c2 | 2018-07-10 16:57:27 -0700 | [diff] [blame] | 2227 | } |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 2228 | |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2229 | if (traceFlags & SurfaceTracing::TRACE_INPUT) { |
chaviw | 4c34a09 | 2020-07-08 11:30:06 -0700 | [diff] [blame] | 2230 | InputWindowInfo info; |
| 2231 | if (useDrawing) { |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 2232 | info = fillInputInfo({nullptr}); |
chaviw | 4c34a09 | 2020-07-08 11:30:06 -0700 | [diff] [blame] | 2233 | } else { |
| 2234 | info = state.inputInfo; |
| 2235 | } |
| 2236 | |
| 2237 | LayerProtoHelper::writeToProto(info, state.touchableRegionCrop, |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2238 | [&]() { return layerInfo->mutable_input_window_info(); }); |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 2239 | } |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2240 | |
| 2241 | if (traceFlags & SurfaceTracing::TRACE_EXTRA) { |
| 2242 | auto protoMap = layerInfo->mutable_metadata(); |
| 2243 | for (const auto& entry : state.metadata.mMap) { |
| 2244 | (*protoMap)[entry.first] = std::string(entry.second.cbegin(), entry.second.cend()); |
| 2245 | } |
Vishnu Nair | 9245d3b | 2019-03-22 13:38:56 -0700 | [diff] [blame] | 2246 | } |
chaviw | 1d04428 | 2017-09-27 12:19:28 -0700 | [diff] [blame] | 2247 | } |
| 2248 | |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 2249 | bool Layer::isRemovedFromCurrentState() const { |
| 2250 | return mRemovedFromCurrentState; |
| 2251 | } |
| 2252 | |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 2253 | ui::Transform Layer::getInputTransform() const { |
| 2254 | return getTransform(); |
| 2255 | } |
| 2256 | |
| 2257 | Rect Layer::getInputBounds() const { |
| 2258 | return getCroppedBufferSize(getDrawingState()); |
| 2259 | } |
| 2260 | |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 2261 | void Layer::fillInputFrameInfo(InputWindowInfo& info, const ui::Transform& toPhysicalDisplay) { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 2262 | // Transform layer size to screen space and inset it by surface insets. |
Tiger Huang | 85b8c5e | 2019-01-17 18:34:54 +0800 | [diff] [blame] | 2263 | // If this is a portal window, set the touchableRegion to the layerBounds. |
| 2264 | Rect layerBounds = info.portalToDisplayId == ADISPLAY_ID_NONE |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 2265 | ? getInputBounds() |
Tiger Huang | 85b8c5e | 2019-01-17 18:34:54 +0800 | [diff] [blame] | 2266 | : info.touchableRegion.getBounds(); |
Arthur Hung | d20b270 | 2019-01-14 18:16:16 +0800 | [diff] [blame] | 2267 | if (!layerBounds.isValid()) { |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 2268 | layerBounds = getInputBounds(); |
Arthur Hung | d20b270 | 2019-01-14 18:16:16 +0800 | [diff] [blame] | 2269 | } |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 2270 | |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 2271 | if (!layerBounds.isValid()) { |
| 2272 | // If the layer bounds is empty, set the frame to empty and clear the transform |
| 2273 | info.frameLeft = 0; |
| 2274 | info.frameTop = 0; |
| 2275 | info.frameRight = 0; |
| 2276 | info.frameBottom = 0; |
| 2277 | info.transform.reset(); |
| 2278 | return; |
| 2279 | } |
| 2280 | |
chaviw | 39d0147 | 2021-04-08 14:26:24 -0500 | [diff] [blame] | 2281 | ui::Transform layerToDisplay = getInputTransform(); |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 2282 | // Transform that takes window coordinates to unrotated display coordinates |
| 2283 | ui::Transform t = toPhysicalDisplay * layerToDisplay; |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 2284 | int32_t xSurfaceInset = info.surfaceInset; |
| 2285 | int32_t ySurfaceInset = info.surfaceInset; |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 2286 | // Bring screenBounds into unrotated space |
| 2287 | Rect screenBounds = toPhysicalDisplay.transform(Rect{mScreenBounds}); |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 2288 | |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 2289 | const float xScale = t.getScaleX(); |
| 2290 | const float yScale = t.getScaleY(); |
| 2291 | if (xScale != 1.0f || yScale != 1.0f) { |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 2292 | xSurfaceInset = std::round(xSurfaceInset * xScale); |
| 2293 | ySurfaceInset = std::round(ySurfaceInset * yScale); |
| 2294 | } |
| 2295 | |
Peiyong Lin | 74861ad | 2020-10-14 11:55:33 -0700 | [diff] [blame] | 2296 | // Transform the layer bounds from layer coordinate space to display coordinate space. |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 2297 | Rect transformedLayerBounds = t.transform(layerBounds); |
Ady Abraham | 282f1d7 | 2019-07-24 18:05:56 -0700 | [diff] [blame] | 2298 | |
| 2299 | // clamp inset to layer bounds |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 2300 | xSurfaceInset = (xSurfaceInset >= 0) |
| 2301 | ? std::min(xSurfaceInset, transformedLayerBounds.getWidth() / 2) |
| 2302 | : 0; |
| 2303 | ySurfaceInset = (ySurfaceInset >= 0) |
| 2304 | ? std::min(ySurfaceInset, transformedLayerBounds.getHeight() / 2) |
| 2305 | : 0; |
Ady Abraham | 282f1d7 | 2019-07-24 18:05:56 -0700 | [diff] [blame] | 2306 | |
Robert Carr | a724230 | 2020-09-01 18:26:29 -0700 | [diff] [blame] | 2307 | // inset while protecting from overflow TODO(b/161235021): What is going wrong |
| 2308 | // in the overflow scenario? |
| 2309 | { |
| 2310 | int32_t tmp; |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 2311 | if (!__builtin_add_overflow(transformedLayerBounds.left, xSurfaceInset, &tmp)) |
| 2312 | transformedLayerBounds.left = tmp; |
| 2313 | if (!__builtin_sub_overflow(transformedLayerBounds.right, xSurfaceInset, &tmp)) |
| 2314 | transformedLayerBounds.right = tmp; |
| 2315 | if (!__builtin_add_overflow(transformedLayerBounds.top, ySurfaceInset, &tmp)) |
| 2316 | transformedLayerBounds.top = tmp; |
| 2317 | if (!__builtin_sub_overflow(transformedLayerBounds.bottom, ySurfaceInset, &tmp)) |
| 2318 | transformedLayerBounds.bottom = tmp; |
Robert Carr | a724230 | 2020-09-01 18:26:29 -0700 | [diff] [blame] | 2319 | } |
Vishnu Nair | 8033a49 | 2018-12-05 07:27:23 -0800 | [diff] [blame] | 2320 | |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 2321 | // Compute the correct transform to send to input. This will allow it to transform the |
| 2322 | // input coordinates from display space into window space. Therefore, it needs to use the |
| 2323 | // final layer frame to create the inverse transform. Since surface insets are added later, |
| 2324 | // along with the overflow, the best way to ensure we get the correct transform is to use |
| 2325 | // the final frame calculated. |
| 2326 | // 1. Take the original transform set on the window and get the inverse transform. This is |
| 2327 | // used to get the final bounds in display space (ignorning the transform). Apply the |
Peiyong Lin | 74861ad | 2020-10-14 11:55:33 -0700 | [diff] [blame] | 2328 | // inverse transform on the layerBounds to get the untransformed frame (in layer space) |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 2329 | // 2. Take the top and left of the untransformed frame to get the real position on screen. |
| 2330 | // Apply the layer transform on top/left so it includes any scale or rotation. These will |
| 2331 | // be the new translation values for the transform. |
| 2332 | // 3. Update the translation of the original transform to the new translation values. |
| 2333 | // 4. Send the inverse transform to input so the coordinates can be transformed back into |
| 2334 | // window space. |
| 2335 | ui::Transform inverseTransform = t.inverse(); |
| 2336 | Rect nonTransformedBounds = inverseTransform.transform(transformedLayerBounds); |
| 2337 | vec2 translation = t.transform(nonTransformedBounds.left, nonTransformedBounds.top); |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 2338 | ui::Transform inputTransform(t); |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 2339 | inputTransform.set(translation.x, translation.y); |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 2340 | info.transform = inputTransform.inverse(); |
| 2341 | |
chaviw | 39cfa2e | 2020-11-04 14:19:02 -0800 | [diff] [blame] | 2342 | // We need to send the layer bounds cropped to the screenbounds since the layer can be cropped. |
| 2343 | // The frame should be the area the user sees on screen since it's used for occlusion |
| 2344 | // detection. |
chaviw | 39cfa2e | 2020-11-04 14:19:02 -0800 | [diff] [blame] | 2345 | transformedLayerBounds.intersect(screenBounds, &transformedLayerBounds); |
| 2346 | info.frameLeft = transformedLayerBounds.left; |
| 2347 | info.frameTop = transformedLayerBounds.top; |
| 2348 | info.frameRight = transformedLayerBounds.right; |
| 2349 | info.frameBottom = transformedLayerBounds.bottom; |
| 2350 | |
Vishnu Nair | 8033a49 | 2018-12-05 07:27:23 -0800 | [diff] [blame] | 2351 | // Position the touchable region relative to frame screen location and restrict it to frame |
| 2352 | // bounds. |
chaviw | 44a6d2b | 2020-09-08 17:14:16 -0700 | [diff] [blame] | 2353 | info.touchableRegion = inputTransform.transform(info.touchableRegion); |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 2354 | } |
| 2355 | |
Bernardo Rufino | a9d0a53 | 2021-06-11 15:59:12 +0100 | [diff] [blame^] | 2356 | void Layer::fillTouchOcclusionMode(InputWindowInfo& info) { |
| 2357 | sp<Layer> p = this; |
| 2358 | while (p != nullptr && !p->hasInputInfo()) { |
| 2359 | p = p->mDrawingParent.promote(); |
| 2360 | } |
| 2361 | if (p != nullptr) { |
| 2362 | info.touchOcclusionMode = p->mDrawingState.inputInfo.touchOcclusionMode; |
| 2363 | } |
| 2364 | } |
| 2365 | |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 2366 | InputWindowInfo Layer::fillInputInfo(const sp<DisplayDevice>& display) { |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 2367 | if (!hasInputInfo()) { |
| 2368 | mDrawingState.inputInfo.name = getName(); |
| 2369 | mDrawingState.inputInfo.ownerUid = mOwnerUid; |
| 2370 | mDrawingState.inputInfo.ownerPid = mOwnerPid; |
| 2371 | mDrawingState.inputInfo.inputFeatures = InputWindowInfo::Feature::NO_INPUT_CHANNEL; |
| 2372 | mDrawingState.inputInfo.flags = InputWindowInfo::Flag::NOT_TOUCH_MODAL; |
| 2373 | mDrawingState.inputInfo.displayId = getLayerStack(); |
| 2374 | } |
| 2375 | |
| 2376 | InputWindowInfo info = mDrawingState.inputInfo; |
| 2377 | info.id = sequence; |
| 2378 | |
| 2379 | if (info.displayId == ADISPLAY_ID_NONE) { |
| 2380 | info.displayId = getLayerStack(); |
| 2381 | } |
| 2382 | |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 2383 | // Transform that goes from "logical(rotated)" display to physical/unrotated display. |
| 2384 | // This is for when inputflinger operates in physical display-space. |
| 2385 | ui::Transform toPhysicalDisplay; |
| 2386 | if (display) { |
| 2387 | toPhysicalDisplay = display->getTransform(); |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 2388 | info.displayWidth = display->getWidth(); |
| 2389 | info.displayHeight = display->getHeight(); |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 2390 | } |
| 2391 | fillInputFrameInfo(info, toPhysicalDisplay); |
chaviw | 7e72caf | 2020-12-02 16:50:43 -0800 | [diff] [blame] | 2392 | |
Robert Carr | 5dc426e | 2020-06-10 14:29:14 -0700 | [diff] [blame] | 2393 | // For compatibility reasons we let layers which can receive input |
| 2394 | // receive input before they have actually submitted a buffer. Because |
| 2395 | // of this we use canReceiveInput instead of isVisible to check the |
| 2396 | // policy-visibility, ignoring the buffer state. However for layers with |
| 2397 | // hasInputInfo()==false we can use the real visibility state. |
| 2398 | // We are just using these layers for occlusion detection in |
| 2399 | // InputDispatcher, and obviously if they aren't visible they can't occlude |
| 2400 | // anything. |
| 2401 | info.visible = hasInputInfo() ? canReceiveInput() : isVisible(); |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 2402 | info.alpha = getAlpha(); |
Bernardo Rufino | a9d0a53 | 2021-06-11 15:59:12 +0100 | [diff] [blame^] | 2403 | fillTouchOcclusionMode(info); |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 2404 | |
| 2405 | auto cropLayer = mDrawingState.touchableRegionCrop.promote(); |
| 2406 | if (info.replaceTouchableRegionWithCrop) { |
| 2407 | if (cropLayer == nullptr) { |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 2408 | info.touchableRegion = Region(toPhysicalDisplay.transform(Rect{mScreenBounds})); |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 2409 | } else { |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 2410 | info.touchableRegion = |
| 2411 | Region(toPhysicalDisplay.transform(Rect{cropLayer->mScreenBounds})); |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 2412 | } |
| 2413 | } else if (cropLayer != nullptr) { |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 2414 | info.touchableRegion = info.touchableRegion.intersect( |
| 2415 | toPhysicalDisplay.transform(Rect{cropLayer->mScreenBounds})); |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 2416 | } |
| 2417 | |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2418 | // If the layer is a clone, we need to crop the input region to cloned root to prevent |
| 2419 | // touches from going outside the cloned area. |
| 2420 | if (isClone()) { |
| 2421 | sp<Layer> clonedRoot = getClonedRoot(); |
| 2422 | if (clonedRoot != nullptr) { |
[1;3C | 2b9fc25 | 2021-02-04 16:16:50 -0800 | [diff] [blame] | 2423 | Rect rect = toPhysicalDisplay.transform(Rect{clonedRoot->mScreenBounds}); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2424 | info.touchableRegion = info.touchableRegion.intersect(rect); |
| 2425 | } |
| 2426 | } |
| 2427 | |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 2428 | return info; |
| 2429 | } |
| 2430 | |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2431 | sp<Layer> Layer::getClonedRoot() { |
| 2432 | if (mClonedChild != nullptr) { |
| 2433 | return this; |
| 2434 | } |
| 2435 | if (mDrawingParent == nullptr || mDrawingParent.promote() == nullptr) { |
| 2436 | return nullptr; |
| 2437 | } |
| 2438 | return mDrawingParent.promote()->getClonedRoot(); |
| 2439 | } |
| 2440 | |
Robert Carr | edd1360 | 2020-04-13 17:24:34 -0700 | [diff] [blame] | 2441 | bool Layer::hasInputInfo() const { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 2442 | return mDrawingState.inputInfo.token != nullptr; |
Robert Carr | 720e506 | 2018-07-30 17:45:14 -0700 | [diff] [blame] | 2443 | } |
| 2444 | |
chaviw | 3e727cd | 2019-01-31 13:41:05 -0800 | [diff] [blame] | 2445 | bool Layer::canReceiveInput() const { |
Vishnu Nair | 82353e9 | 2019-09-12 12:38:47 -0700 | [diff] [blame] | 2446 | return !isHiddenByPolicy(); |
chaviw | 3e727cd | 2019-01-31 13:41:05 -0800 | [diff] [blame] | 2447 | } |
| 2448 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 2449 | compositionengine::OutputLayer* Layer::findOutputLayerForDisplay( |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 2450 | const DisplayDevice* display) const { |
| 2451 | if (!display) return nullptr; |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 2452 | return display->getCompositionDisplay()->getOutputLayerForLayer(getCompositionEngineLayerFE()); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 2453 | } |
| 2454 | |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 2455 | Region Layer::getVisibleRegion(const DisplayDevice* display) const { |
| 2456 | const auto outputLayer = findOutputLayerForDisplay(display); |
| 2457 | return outputLayer ? outputLayer->getState().visibleRegion : Region(); |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 2458 | } |
| 2459 | |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 2460 | void Layer::setInitialValuesForClone(const sp<Layer>& clonedFrom) { |
| 2461 | // copy drawing state from cloned layer |
| 2462 | mDrawingState = clonedFrom->mDrawingState; |
| 2463 | mClonedFrom = clonedFrom; |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 2464 | } |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 2465 | |
| 2466 | void Layer::updateMirrorInfo() { |
| 2467 | if (mClonedChild == nullptr || !mClonedChild->isClonedFromAlive()) { |
| 2468 | // If mClonedChild is null, there is nothing to mirror. If isClonedFromAlive returns false, |
| 2469 | // it means that there is a clone, but the layer it was cloned from has been destroyed. In |
| 2470 | // that case, we want to delete the reference to the clone since we want it to get |
| 2471 | // destroyed. The root, this layer, will still be around since the client can continue |
| 2472 | // to hold a reference, but no cloned layers will be displayed. |
| 2473 | mClonedChild = nullptr; |
| 2474 | return; |
| 2475 | } |
| 2476 | |
| 2477 | std::map<sp<Layer>, sp<Layer>> clonedLayersMap; |
| 2478 | // If the real layer exists and is in current state, add the clone as a child of the root. |
| 2479 | // There's no need to remove from drawingState when the layer is offscreen since currentState is |
| 2480 | // copied to drawingState for the root layer. So the clonedChild is always removed from |
| 2481 | // drawingState and then needs to be added back each traversal. |
| 2482 | if (!mClonedChild->getClonedFrom()->isRemovedFromCurrentState()) { |
| 2483 | addChildToDrawing(mClonedChild); |
| 2484 | } |
| 2485 | |
| 2486 | mClonedChild->updateClonedDrawingState(clonedLayersMap); |
| 2487 | mClonedChild->updateClonedChildren(this, clonedLayersMap); |
| 2488 | mClonedChild->updateClonedRelatives(clonedLayersMap); |
| 2489 | } |
| 2490 | |
| 2491 | void Layer::updateClonedDrawingState(std::map<sp<Layer>, sp<Layer>>& clonedLayersMap) { |
| 2492 | // If the layer the clone was cloned from is alive, copy the content of the drawingState |
| 2493 | // to the clone. If the real layer is no longer alive, continue traversing the children |
| 2494 | // since we may be able to pull out other children that are still alive. |
| 2495 | if (isClonedFromAlive()) { |
| 2496 | sp<Layer> clonedFrom = getClonedFrom(); |
| 2497 | mDrawingState = clonedFrom->mDrawingState; |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 2498 | clonedLayersMap.emplace(clonedFrom, this); |
| 2499 | } |
| 2500 | |
| 2501 | // The clone layer may have children in drawingState since they may have been created and |
| 2502 | // added from a previous request to updateMirorInfo. This is to ensure we don't recreate clones |
| 2503 | // that already exist, since we can just re-use them. |
| 2504 | // The drawingChildren will not get overwritten by the currentChildren since the clones are |
| 2505 | // not updated in the regular traversal. They are skipped since the root will lose the |
| 2506 | // reference to them when it copies its currentChildren to drawing. |
| 2507 | for (sp<Layer>& child : mDrawingChildren) { |
| 2508 | child->updateClonedDrawingState(clonedLayersMap); |
| 2509 | } |
| 2510 | } |
| 2511 | |
| 2512 | void Layer::updateClonedChildren(const sp<Layer>& mirrorRoot, |
| 2513 | std::map<sp<Layer>, sp<Layer>>& clonedLayersMap) { |
| 2514 | mDrawingChildren.clear(); |
| 2515 | |
| 2516 | if (!isClonedFromAlive()) { |
| 2517 | return; |
| 2518 | } |
| 2519 | |
| 2520 | sp<Layer> clonedFrom = getClonedFrom(); |
| 2521 | for (sp<Layer>& child : clonedFrom->mDrawingChildren) { |
| 2522 | if (child == mirrorRoot) { |
| 2523 | // This is to avoid cyclical mirroring. |
| 2524 | continue; |
| 2525 | } |
| 2526 | sp<Layer> clonedChild = clonedLayersMap[child]; |
| 2527 | if (clonedChild == nullptr) { |
| 2528 | clonedChild = child->createClone(); |
| 2529 | clonedLayersMap[child] = clonedChild; |
| 2530 | } |
| 2531 | addChildToDrawing(clonedChild); |
| 2532 | clonedChild->updateClonedChildren(mirrorRoot, clonedLayersMap); |
| 2533 | } |
| 2534 | } |
| 2535 | |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2536 | void Layer::updateClonedInputInfo(const std::map<sp<Layer>, sp<Layer>>& clonedLayersMap) { |
| 2537 | auto cropLayer = mDrawingState.touchableRegionCrop.promote(); |
| 2538 | if (cropLayer != nullptr) { |
| 2539 | if (clonedLayersMap.count(cropLayer) == 0) { |
| 2540 | // Real layer had a crop layer but it's not in the cloned hierarchy. Just set to |
| 2541 | // self as crop layer to avoid going outside bounds. |
| 2542 | mDrawingState.touchableRegionCrop = this; |
| 2543 | } else { |
| 2544 | const sp<Layer>& clonedCropLayer = clonedLayersMap.at(cropLayer); |
| 2545 | mDrawingState.touchableRegionCrop = clonedCropLayer; |
| 2546 | } |
| 2547 | } |
| 2548 | // Cloned layers shouldn't handle watch outside since their z order is not determined by |
| 2549 | // WM or the client. |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 2550 | mDrawingState.inputInfo.flags &= ~InputWindowInfo::Flag::WATCH_OUTSIDE_TOUCH; |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2551 | } |
| 2552 | |
| 2553 | void Layer::updateClonedRelatives(const std::map<sp<Layer>, sp<Layer>>& clonedLayersMap) { |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 2554 | mDrawingState.zOrderRelativeOf = nullptr; |
| 2555 | mDrawingState.zOrderRelatives.clear(); |
| 2556 | |
| 2557 | if (!isClonedFromAlive()) { |
| 2558 | return; |
| 2559 | } |
| 2560 | |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2561 | const sp<Layer>& clonedFrom = getClonedFrom(); |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 2562 | for (wp<Layer>& relativeWeak : clonedFrom->mDrawingState.zOrderRelatives) { |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2563 | const sp<Layer>& relative = relativeWeak.promote(); |
| 2564 | if (clonedLayersMap.count(relative) > 0) { |
| 2565 | auto& clonedRelative = clonedLayersMap.at(relative); |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 2566 | mDrawingState.zOrderRelatives.add(clonedRelative); |
| 2567 | } |
| 2568 | } |
| 2569 | |
| 2570 | // Check if the relativeLayer for the real layer is part of the cloned hierarchy. |
| 2571 | // It's possible that the layer it's relative to is outside the requested cloned hierarchy. |
| 2572 | // In that case, we treat the layer as if the relativeOf has been removed. This way, it will |
| 2573 | // still traverse the children, but the layer with the missing relativeOf will not be shown |
| 2574 | // on screen. |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2575 | const sp<Layer>& relativeOf = clonedFrom->mDrawingState.zOrderRelativeOf.promote(); |
| 2576 | if (clonedLayersMap.count(relativeOf) > 0) { |
| 2577 | const sp<Layer>& clonedRelativeOf = clonedLayersMap.at(relativeOf); |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 2578 | mDrawingState.zOrderRelativeOf = clonedRelativeOf; |
| 2579 | } |
| 2580 | |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 2581 | updateClonedInputInfo(clonedLayersMap); |
| 2582 | |
chaviw | 74b0317 | 2019-08-19 11:09:03 -0700 | [diff] [blame] | 2583 | for (sp<Layer>& child : mDrawingChildren) { |
| 2584 | child->updateClonedRelatives(clonedLayersMap); |
| 2585 | } |
| 2586 | } |
| 2587 | |
| 2588 | void Layer::addChildToDrawing(const sp<Layer>& layer) { |
| 2589 | mDrawingChildren.add(layer); |
| 2590 | layer->mDrawingParent = this; |
| 2591 | } |
| 2592 | |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 2593 | Layer::FrameRateCompatibility Layer::FrameRate::convertCompatibility(int8_t compatibility) { |
| 2594 | switch (compatibility) { |
| 2595 | case ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT: |
| 2596 | return FrameRateCompatibility::Default; |
| 2597 | case ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE: |
| 2598 | return FrameRateCompatibility::ExactOrMultiple; |
Ady Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 2599 | case ANATIVEWINDOW_FRAME_RATE_EXACT: |
| 2600 | return FrameRateCompatibility::Exact; |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 2601 | default: |
| 2602 | LOG_ALWAYS_FATAL("Invalid frame rate compatibility value %d", compatibility); |
| 2603 | return FrameRateCompatibility::Default; |
| 2604 | } |
| 2605 | } |
| 2606 | |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 2607 | scheduler::Seamlessness Layer::FrameRate::convertChangeFrameRateStrategy(int8_t strategy) { |
| 2608 | switch (strategy) { |
| 2609 | case ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS: |
| 2610 | return Seamlessness::OnlySeamless; |
| 2611 | case ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS: |
| 2612 | return Seamlessness::SeamedAndSeamless; |
| 2613 | default: |
| 2614 | LOG_ALWAYS_FATAL("Invalid change frame sate strategy value %d", strategy); |
| 2615 | return Seamlessness::Default; |
| 2616 | } |
| 2617 | } |
| 2618 | |
chaviw | c5676c6 | 2020-09-18 15:01:04 -0700 | [diff] [blame] | 2619 | bool Layer::getPrimaryDisplayOnly() const { |
| 2620 | const State& s(mDrawingState); |
| 2621 | if (s.flags & layer_state_t::eLayerSkipScreenshot) { |
| 2622 | return true; |
| 2623 | } |
| 2624 | |
| 2625 | sp<Layer> parent = mDrawingParent.promote(); |
| 2626 | return parent == nullptr ? false : parent->getPrimaryDisplayOnly(); |
| 2627 | } |
| 2628 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 2629 | // --------------------------------------------------------------------------- |
| 2630 | |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 2631 | std::ostream& operator<<(std::ostream& stream, const Layer::FrameRate& rate) { |
| 2632 | return stream << "{rate=" << rate.rate |
| 2633 | << " type=" << Layer::frameRateCompatibilityString(rate.type) |
Marin Shalamanov | 53fc11d | 2020-11-20 14:00:13 +0100 | [diff] [blame] | 2634 | << " seamlessness=" << toString(rate.seamlessness) << "}"; |
Marin Shalamanov | 4608442 | 2020-10-13 12:33:42 +0200 | [diff] [blame] | 2635 | } |
| 2636 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2637 | }; // namespace android |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 2638 | |
| 2639 | #if defined(__gl_h_) |
| 2640 | #error "don't include gl/gl.h in this file" |
| 2641 | #endif |
| 2642 | |
| 2643 | #if defined(__gl2_h_) |
| 2644 | #error "don't include gl2/gl2.h in this file" |
| 2645 | #endif |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 2646 | |
| 2647 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 2648 | #pragma clang diagnostic pop // ignored "-Wconversion" |