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