blob: f1bfebcc11bd0d1d70da815f261eae0000b6ae16 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
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 Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
Dan Stoza9e56aa02015-11-02 13:00:03 -080021//#define LOG_NDEBUG 0
22#undef LOG_TAG
23#define LOG_TAG "Layer"
Jamie Gennis1c8e95c2012-02-23 19:27:23 -080024#define ATRACE_TAG ATRACE_TAG_GRAPHICS
25
Alec Mourie60041e2019-06-14 18:59:51 -070026#include "Layer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027
[1;3C2b9fc252021-02-04 16:16:50 -080028#include <android-base/properties.h>
Yiwei Zhang5434a782018-12-05 18:06:32 -080029#include <android-base/stringprintf.h>
Steven Thomas62a4cf82020-01-31 12:04:03 -080030#include <android/native_window.h>
Vishnu Nair0f085c62019-08-30 08:49:12 -070031#include <binder/IPCThreadState.h>
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080032#include <compositionengine/Display.h>
Lloyd Piquea83776c2019-01-29 18:42:32 -080033#include <compositionengine/LayerFECompositionState.h>
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080034#include <compositionengine/OutputLayer.h>
35#include <compositionengine/impl/OutputLayerCompositionState.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070036#include <cutils/compiler.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070037#include <cutils/native_handle.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070038#include <cutils/properties.h>
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080039#include <gui/BufferItem.h>
40#include <gui/LayerDebugInfo.h>
41#include <gui/Surface.h>
Alec Mourie60041e2019-06-14 18:59:51 -070042#include <math.h>
chaviw250bcbb2020-08-05 11:17:54 -070043#include <private/android_filesystem_config.h>
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080044#include <renderengine/RenderEngine.h>
Alec Mourie60041e2019-06-14 18:59:51 -070045#include <stdint.h>
46#include <stdlib.h>
47#include <sys/types.h>
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080048#include <ui/DebugUtils.h>
49#include <ui/GraphicBuffer.h>
50#include <ui/PixelFormat.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051#include <utils/Errors.h>
52#include <utils/Log.h>
Jesse Hall399184a2014-03-03 15:42:54 -080053#include <utils/NativeHandle.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080054#include <utils/StopWatch.h>
Jamie Gennis1c8e95c2012-02-23 19:27:23 -080055#include <utils/Trace.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080056
Alec Mourie60041e2019-06-14 18:59:51 -070057#include <algorithm>
58#include <mutex>
59#include <sstream>
60
Yiwei Zhang60d1a192018-03-07 14:52:28 -080061#include "BufferLayer.h"
Mathias Agopian3e25fd82013-04-22 17:52:16 +020062#include "Colorizer.h"
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070063#include "DisplayDevice.h"
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080064#include "DisplayHardware/HWComposer.h"
Vishnu Nairfa247b12020-02-11 08:58:26 -080065#include "EffectLayer.h"
Ady Abraham22c7b5c2020-09-22 19:33:40 -070066#include "FrameTimeline.h"
Mikael Pessa90092f42019-08-26 17:22:04 -070067#include "FrameTracer/FrameTracer.h"
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080068#include "LayerProtoHelper.h"
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070069#include "LayerRejecter.h"
Dan Stozab9b08832014-03-13 11:55:57 -070070#include "MonitoredProducer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080071#include "SurfaceFlinger.h"
Yiwei Zhang7e666a52018-11-15 13:33:42 -080072#include "TimeStats/TimeStats.h"
Robert Carr3e2a2992021-06-11 13:42:55 -070073#include "TunnelModeEnabledReporter.h"
Mathias Agopian1b031492012-06-20 17:51:20 -070074
David Sodman41fdfc92017-11-06 16:09:56 -080075#define DEBUG_RESIZE 0
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080076
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080077namespace android {
Marin Shalamanov1876e2e2020-12-04 13:23:59 +010078namespace {
79constexpr int kDumpTableRowLength = 159;
80} // namespace
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080081
Yiwei Zhang5434a782018-12-05 18:06:32 -080082using base::StringAppendF;
Michael Wright44753b12020-07-08 13:48:11 +010083using namespace android::flag_operators;
Ady Abraham22c7b5c2020-09-22 19:33:40 -070084using PresentState = frametimeline::SurfaceFrame::PresentState;
chaviw3277faf2021-05-19 16:45:23 -050085using gui::WindowInfo;
Yiwei Zhang5434a782018-12-05 18:06:32 -080086
Lloyd Piquef1c675b2018-09-12 20:45:39 -070087std::atomic<int32_t> Layer::sSequence{1};
Mathias Agopian13127d82013-03-05 17:47:11 -080088
Lloyd Pique42ab75e2018-09-12 20:46:03 -070089Layer::Layer(const LayerCreationArgs& args)
Ady Abraham8f1ee7f2019-04-05 10:32:50 -070090 : mFlinger(args.flinger),
91 mName(args.name),
92 mClientRef(args.client),
chaviw3277faf2021-05-19 16:45:23 -050093 mWindowType(
94 static_cast<WindowInfo::Type>(args.metadata.getInt32(METADATA_WINDOW_TYPE, 0))) {
Mathias Agopian4d9b8222013-03-12 17:11:48 -070095 uint32_t layerFlags = 0;
Lloyd Pique42ab75e2018-09-12 20:46:03 -070096 if (args.flags & ISurfaceComposerClient::eHidden) layerFlags |= layer_state_t::eLayerHidden;
97 if (args.flags & ISurfaceComposerClient::eOpaque) layerFlags |= layer_state_t::eLayerOpaque;
98 if (args.flags & ISurfaceComposerClient::eSecure) layerFlags |= layer_state_t::eLayerSecure;
chaviwc5676c62020-09-18 15:01:04 -070099 if (args.flags & ISurfaceComposerClient::eSkipScreenshot)
100 layerFlags |= layer_state_t::eLayerSkipScreenshot;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700101
Robert Carr6a160312021-05-17 12:08:20 -0700102 mDrawingState.active_legacy.w = args.w;
103 mDrawingState.active_legacy.h = args.h;
104 mDrawingState.flags = layerFlags;
105 mDrawingState.active_legacy.transform.set(0, 0);
106 mDrawingState.crop.makeInvalid();
107 mDrawingState.requestedCrop = mDrawingState.crop;
108 mDrawingState.z = 0;
109 mDrawingState.color.a = 1.0f;
110 mDrawingState.layerStack = 0;
111 mDrawingState.sequence = 0;
112 mDrawingState.requested_legacy = mDrawingState.active_legacy;
113 mDrawingState.width = UINT32_MAX;
114 mDrawingState.height = UINT32_MAX;
115 mDrawingState.transform.set(0, 0);
116 mDrawingState.frameNumber = 0;
117 mDrawingState.bufferTransform = 0;
118 mDrawingState.transformToDisplayInverse = false;
119 mDrawingState.crop.makeInvalid();
120 mDrawingState.acquireFence = sp<Fence>::make(-1);
121 mDrawingState.acquireFenceTime = std::make_shared<FenceTime>(mDrawingState.acquireFence);
122 mDrawingState.dataspace = ui::Dataspace::UNKNOWN;
123 mDrawingState.hdrMetadata.validTypes = 0;
124 mDrawingState.surfaceDamageRegion = Region::INVALID_REGION;
125 mDrawingState.cornerRadius = 0.0f;
126 mDrawingState.backgroundBlurRadius = 0;
127 mDrawingState.api = -1;
128 mDrawingState.hasColorTransform = false;
129 mDrawingState.colorSpaceAgnostic = false;
130 mDrawingState.frameRateSelectionPriority = PRIORITY_UNSET;
131 mDrawingState.metadata = args.metadata;
132 mDrawingState.shadowRadius = 0.f;
133 mDrawingState.fixedTransformHint = ui::Transform::ROT_INVALID;
134 mDrawingState.frameTimelineInfo = {};
135 mDrawingState.postTime = -1;
136 mDrawingState.destinationFrame.makeInvalid();
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700137
Vishnu Nairc43a23c2020-05-29 14:32:27 -0700138 if (args.flags & ISurfaceComposerClient::eNoColorFill) {
139 // Set an invalid color so there is no color fill.
Robert Carr6a160312021-05-17 12:08:20 -0700140 mDrawingState.color.r = -1.0_hf;
141 mDrawingState.color.g = -1.0_hf;
142 mDrawingState.color.b = -1.0_hf;
Vishnu Nairc43a23c2020-05-29 14:32:27 -0700143 }
144
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800145 CompositorTiming compositorTiming;
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700146 args.flinger->getCompositorTiming(&compositorTiming);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800147 mFrameEventHistory.initializeCompositorTiming(compositorTiming);
Jorim Jaggibd6480f2018-08-10 14:37:31 +0200148 mFrameTracker.setDisplayRefreshPeriod(compositorTiming.interval);
Robert Carr2e102c92018-10-23 12:11:15 -0700149
Vishnu Nair0f085c62019-08-30 08:49:12 -0700150 mCallingPid = args.callingPid;
151 mCallingUid = args.callingUid;
chaviw250bcbb2020-08-05 11:17:54 -0700152
153 if (mCallingUid == AID_GRAPHICS || mCallingUid == AID_SYSTEM) {
154 // If the system didn't send an ownerUid, use the callingUid for the ownerUid.
155 mOwnerUid = args.metadata.getInt32(METADATA_OWNER_UID, mCallingUid);
Adithya Srinivasan9febda82020-10-19 10:49:41 -0700156 mOwnerPid = args.metadata.getInt32(METADATA_OWNER_PID, mCallingPid);
chaviw250bcbb2020-08-05 11:17:54 -0700157 } else {
158 // A create layer request from a non system request cannot specify the owner uid
159 mOwnerUid = mCallingUid;
Adithya Srinivasan9febda82020-10-19 10:49:41 -0700160 mOwnerPid = mCallingPid;
chaviw250bcbb2020-08-05 11:17:54 -0700161 }
Dominik Laskowski75848362019-11-11 17:57:20 -0800162}
163
164void Layer::onFirstRef() {
165 mFlinger->onLayerFirstRef(this);
Dan Stoza436ccf32018-06-21 12:10:12 -0700166}
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700167
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700168Layer::~Layer() {
David Sodman577c8962017-12-08 14:50:53 -0800169 sp<Client> c(mClientRef.promote());
170 if (c != 0) {
171 c->detachLayer(this);
172 }
173
Jorim Jaggi10c985e2018-10-23 11:17:45 +0000174 mFrameTracker.logAndResetStats(mName);
chaviw74d90ad2019-04-26 14:45:26 -0700175 mFlinger->onLayerDestroyed(this);
Robert Carr3e2a2992021-06-11 13:42:55 -0700176
177 if (mDrawingState.sidebandStream != nullptr) {
178 mFlinger->mTunnelModeEnabledReporter->decrementTunnelModeCount();
179 }
Mathias Agopian96f08192010-06-02 23:28:45 -0700180}
181
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700182LayerCreationArgs::LayerCreationArgs(SurfaceFlinger* flinger, sp<Client> client, std::string name,
183 uint32_t w, uint32_t h, uint32_t flags, LayerMetadata metadata)
Vishnu Nair0f085c62019-08-30 08:49:12 -0700184 : flinger(flinger),
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700185 client(std::move(client)),
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700186 name(std::move(name)),
Vishnu Nair0f085c62019-08-30 08:49:12 -0700187 w(w),
188 h(h),
189 flags(flags),
190 metadata(std::move(metadata)) {
191 IPCThreadState* ipc = IPCThreadState::self();
192 callingPid = ipc->getCallingPid();
193 callingUid = ipc->getCallingUid();
194}
195
Mathias Agopian13127d82013-03-05 17:47:11 -0800196// ---------------------------------------------------------------------------
197// callbacks
198// ---------------------------------------------------------------------------
199
David Sodmaneb085e02017-10-05 18:49:04 -0700200/*
201 * onLayerDisplayed is only meaningful for BufferLayer, but, is called through
202 * Layer. So, the implementation is done in BufferLayer. When called on a
Vishnu Nairfa247b12020-02-11 08:58:26 -0800203 * EffectLayer object, it's essentially a NOP.
David Sodmaneb085e02017-10-05 18:49:04 -0700204 */
David Sodmaneb085e02017-10-05 18:49:04 -0700205void Layer::onLayerDisplayed(const sp<Fence>& /*releaseFence*/) {}
Mathias Agopian13127d82013-03-05 17:47:11 -0800206
Vishnu Nairda9c85a2019-06-03 17:26:48 -0700207void Layer::removeRelativeZ(const std::vector<Layer*>& layersInTree) {
Robert Carr6a160312021-05-17 12:08:20 -0700208 if (mDrawingState.zOrderRelativeOf == nullptr) {
Vishnu Nairda9c85a2019-06-03 17:26:48 -0700209 return;
210 }
Robert Carr2e102c92018-10-23 12:11:15 -0700211
Robert Carr6a160312021-05-17 12:08:20 -0700212 sp<Layer> strongRelative = mDrawingState.zOrderRelativeOf.promote();
Vishnu Nairda9c85a2019-06-03 17:26:48 -0700213 if (strongRelative == nullptr) {
214 setZOrderRelativeOf(nullptr);
215 return;
216 }
217
218 if (!std::binary_search(layersInTree.begin(), layersInTree.end(), strongRelative.get())) {
219 strongRelative->removeZOrderRelative(this);
220 mFlinger->setTransactionFlags(eTraversalNeeded);
chaviw606e5cf2019-03-01 10:12:10 -0800221 setZOrderRelativeOf(nullptr);
Robert Carr5edb1ad2017-04-25 10:54:24 -0700222 }
Vishnu Nairda9c85a2019-06-03 17:26:48 -0700223}
224
225void Layer::removeFromCurrentState() {
Robert Carr6a160312021-05-17 12:08:20 -0700226 if (!mRemovedFromDrawingState) {
227 mRemovedFromDrawingState = true;
Ady Abrahambe09aad2021-05-03 18:59:38 -0700228 mFlinger->mScheduler->deregisterLayer(this);
229 }
Rob Carr4bba3702018-10-08 21:53:30 +0000230
Robert Carr6fb1a7e2018-12-11 12:07:25 -0800231 mFlinger->markLayerPendingRemovalLocked(this);
Chia-I Wuc6657022017-08-15 11:18:17 -0700232}
Chia-I Wu38512252017-05-17 14:36:16 -0700233
chaviw68d4dab2020-06-08 15:07:32 -0700234sp<Layer> Layer::getRootLayer() {
235 sp<Layer> parent = getParent();
236 if (parent == nullptr) {
237 return this;
238 }
239 return parent->getRootLayer();
240}
241
Vishnu Nairda9c85a2019-06-03 17:26:48 -0700242void Layer::onRemovedFromCurrentState() {
chaviw68d4dab2020-06-08 15:07:32 -0700243 // Use the root layer since we want to maintain the hierarchy for the entire subtree.
244 auto layersInTree = getRootLayer()->getLayersInTree(LayerVector::StateSet::Current);
Vishnu Nairda9c85a2019-06-03 17:26:48 -0700245 std::sort(layersInTree.begin(), layersInTree.end());
chaviw68d4dab2020-06-08 15:07:32 -0700246
247 traverse(LayerVector::StateSet::Current, [&](Layer* layer) {
Vishnu Nairda9c85a2019-06-03 17:26:48 -0700248 layer->removeFromCurrentState();
249 layer->removeRelativeZ(layersInTree);
chaviw68d4dab2020-06-08 15:07:32 -0700250 });
Vishnu Nairda9c85a2019-06-03 17:26:48 -0700251}
252
chaviw61626f22018-11-15 16:26:27 -0800253void Layer::addToCurrentState() {
Robert Carr6a160312021-05-17 12:08:20 -0700254 if (mRemovedFromDrawingState) {
255 mRemovedFromDrawingState = false;
Ady Abrahambe09aad2021-05-03 18:59:38 -0700256 mFlinger->mScheduler->registerLayer(this);
257 }
chaviw61626f22018-11-15 16:26:27 -0800258
259 for (const auto& child : mCurrentChildren) {
260 child->addToCurrentState();
261 }
262}
263
Mathias Agopian13127d82013-03-05 17:47:11 -0800264// ---------------------------------------------------------------------------
265// set-up
266// ---------------------------------------------------------------------------
267
chaviw13fdc492017-06-27 12:40:18 -0700268bool Layer::getPremultipledAlpha() const {
269 return mPremultipliedAlpha;
270}
271
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700272sp<IBinder> Layer::getHandle() {
Mathias Agopian13127d82013-03-05 17:47:11 -0800273 Mutex::Autolock _l(mLock);
Robert Carrc0df3122019-04-11 13:18:21 -0700274 if (mGetHandleCalled) {
275 ALOGE("Get handle called twice" );
276 return nullptr;
277 }
278 mGetHandleCalled = true;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700279 return new Handle(mFlinger, this);
Mathias Agopian13127d82013-03-05 17:47:11 -0800280}
281
282// ---------------------------------------------------------------------------
283// h/w composer set-up
284// ---------------------------------------------------------------------------
285
Mathias Agopianf3e85d42013-05-10 18:01:12 -0700286static Rect reduce(const Rect& win, const Region& exclude) {
287 if (CC_LIKELY(exclude.isEmpty())) {
288 return win;
289 }
290 if (exclude.isRect()) {
291 return win.reduce(exclude.getBounds());
292 }
293 return Region(win).subtract(exclude).getBounds();
294}
295
Dan Stoza80d61162017-12-20 15:57:52 -0800296static FloatRect reduce(const FloatRect& win, const Region& exclude) {
297 if (CC_LIKELY(exclude.isEmpty())) {
298 return win;
299 }
300 // Convert through Rect (by rounding) for lack of FloatRegion
301 return Region(Rect{win}).subtract(exclude).getBounds().toFloatRect();
302}
303
Vishnu Nair4351ad52019-02-11 14:13:02 -0800304Rect Layer::getScreenBounds(bool reduceTransparentRegion) const {
Vishnu Nairf0c28512019-02-08 12:40:28 -0800305 if (!reduceTransparentRegion) {
306 return Rect{mScreenBounds};
307 }
308
309 FloatRect bounds = getBounds();
Lloyd Pique0449b0f2018-12-20 16:23:45 -0800310 ui::Transform t = getTransform();
Vishnu Nair60356342018-11-13 13:00:45 -0800311 // Transform to screen space.
312 bounds = t.transform(bounds);
313 return Rect{bounds};
Robert Carr1f0a16a2016-10-24 16:27:39 -0700314}
315
Vishnu Nair4351ad52019-02-11 14:13:02 -0800316FloatRect Layer::getBounds() const {
Alec Mourib416efd2018-09-06 21:01:59 +0000317 const State& s(getDrawingState());
Vishnu Nair4351ad52019-02-11 14:13:02 -0800318 return getBounds(getActiveTransparentRegion(s));
Michael Lentine6c925ed2014-09-26 17:55:01 -0700319}
320
Vishnu Nairf0c28512019-02-08 12:40:28 -0800321FloatRect Layer::getBounds(const Region& activeTransparentRegion) const {
322 // Subtract the transparent region and snap to the bounds.
323 return reduce(mBounds, activeTransparentRegion);
324}
325
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700326void Layer::computeBounds(FloatRect parentBounds, ui::Transform parentTransform,
327 float parentShadowRadius) {
Vishnu Nair4351ad52019-02-11 14:13:02 -0800328 const State& s(getDrawingState());
329
330 // Calculate effective layer transform
331 mEffectiveTransform = parentTransform * getActiveTransform(s);
332
333 // Transform parent bounds to layer space
334 parentBounds = getActiveTransform(s).inverse().transform(parentBounds);
335
Vishnu Nairc652ff82019-03-15 12:48:54 -0700336 // Calculate source bounds
Vishnu Nair4351ad52019-02-11 14:13:02 -0800337 mSourceBounds = computeSourceBounds(parentBounds);
338
339 // Calculate bounds by croping diplay frame with layer crop and parent bounds
340 FloatRect bounds = mSourceBounds;
341 const Rect layerCrop = getCrop(s);
342 if (!layerCrop.isEmpty()) {
343 bounds = mSourceBounds.intersect(layerCrop.toFloatRect());
344 }
345 bounds = bounds.intersect(parentBounds);
346
347 mBounds = bounds;
348 mScreenBounds = mEffectiveTransform.transform(mBounds);
Vishnu Nairc652ff82019-03-15 12:48:54 -0700349
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700350 // Use the layer's own shadow radius if set. Otherwise get the radius from
351 // parent.
352 if (s.shadowRadius > 0.f) {
353 mEffectiveShadowRadius = s.shadowRadius;
354 } else {
355 mEffectiveShadowRadius = parentShadowRadius;
356 }
357
358 // Shadow radius is passed down to only one layer so if the layer can draw shadows,
359 // don't pass it to its children.
360 const float childShadowRadius = canDrawShadows() ? 0.f : mEffectiveShadowRadius;
361
Vishnu Nair4351ad52019-02-11 14:13:02 -0800362 for (const sp<Layer>& child : mDrawingChildren) {
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700363 child->computeBounds(mBounds, mEffectiveTransform, childShadowRadius);
Vishnu Nair4351ad52019-02-11 14:13:02 -0800364 }
365}
366
Vishnu Nair60356342018-11-13 13:00:45 -0800367Rect Layer::getCroppedBufferSize(const State& s) const {
368 Rect size = getBufferSize(s);
369 Rect crop = getCrop(s);
370 if (!crop.isEmpty() && size.isValid()) {
371 size.intersect(crop, &size);
372 } else if (!crop.isEmpty()) {
373 size = crop;
Robert Carr1f0a16a2016-10-24 16:27:39 -0700374 }
Vishnu Nair60356342018-11-13 13:00:45 -0800375 return size;
Mathias Agopian13127d82013-03-05 17:47:11 -0800376}
377
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700378void Layer::setupRoundedCornersCropCoordinates(Rect win,
379 const FloatRect& roundedCornersCrop) const {
380 // Translate win by the rounded corners rect coordinates, to have all values in
381 // layer coordinate space.
382 win.left -= roundedCornersCrop.left;
383 win.right -= roundedCornersCrop.left;
384 win.top -= roundedCornersCrop.top;
385 win.bottom -= roundedCornersCrop.top;
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700386}
387
Lloyd Piquede196652020-01-22 17:29:58 -0800388void Layer::prepareBasicGeometryCompositionState() {
Lloyd Piquec6687342019-03-07 21:34:57 -0800389 const auto& drawingState{getDrawingState()};
390 const uint32_t layerStack = getLayerStack();
391 const auto alpha = static_cast<float>(getAlpha());
392 const bool opaque = isOpaque(drawingState);
393 const bool usesRoundedCorners = getRoundedCornerState().radius != 0.f;
394
395 auto blendMode = Hwc2::IComposerClient::BlendMode::NONE;
396 if (!opaque || alpha != 1.0f) {
397 blendMode = mPremultipliedAlpha ? Hwc2::IComposerClient::BlendMode::PREMULTIPLIED
398 : Hwc2::IComposerClient::BlendMode::COVERAGE;
399 }
400
Lloyd Piquede196652020-01-22 17:29:58 -0800401 auto* compositionState = editCompositionState();
402 compositionState->layerStackId =
Lloyd Piquec6687342019-03-07 21:34:57 -0800403 (layerStack != ~0u) ? std::make_optional(layerStack) : std::nullopt;
Lloyd Piquede196652020-01-22 17:29:58 -0800404 compositionState->internalOnly = getPrimaryDisplayOnly();
405 compositionState->isVisible = isVisible();
406 compositionState->isOpaque = opaque && !usesRoundedCorners && alpha == 1.f;
407 compositionState->shadowRadius = mEffectiveShadowRadius;
Lloyd Piquec6687342019-03-07 21:34:57 -0800408
Lloyd Piquede196652020-01-22 17:29:58 -0800409 compositionState->contentDirty = contentDirty;
Lloyd Piquec6687342019-03-07 21:34:57 -0800410 contentDirty = false;
411
Lloyd Piquede196652020-01-22 17:29:58 -0800412 compositionState->geomLayerBounds = mBounds;
413 compositionState->geomLayerTransform = getTransform();
414 compositionState->geomInverseLayerTransform = compositionState->geomLayerTransform.inverse();
415 compositionState->transparentRegionHint = getActiveTransparentRegion(drawingState);
Lloyd Piquec6687342019-03-07 21:34:57 -0800416
Lloyd Piquede196652020-01-22 17:29:58 -0800417 compositionState->blendMode = static_cast<Hwc2::IComposerClient::BlendMode>(blendMode);
418 compositionState->alpha = alpha;
419 compositionState->backgroundBlurRadius = drawingState.backgroundBlurRadius;
Lucas Dupinc3800b82020-10-02 16:24:48 -0700420 compositionState->blurRegions = drawingState.blurRegions;
John Reckc00c6692021-02-16 11:37:33 -0500421 compositionState->stretchEffect = getStretchEffect();
Lloyd Piquec6687342019-03-07 21:34:57 -0800422}
423
Lloyd Piquede196652020-01-22 17:29:58 -0800424void Layer::prepareGeometryCompositionState() {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800425 const auto& drawingState{getDrawingState()};
Mathias Agopian13127d82013-03-05 17:47:11 -0800426
Lloyd Piquea83776c2019-01-29 18:42:32 -0800427 int type = drawingState.metadata.getInt32(METADATA_WINDOW_TYPE, 0);
428 int appId = drawingState.metadata.getInt32(METADATA_OWNER_UID, 0);
Chia-I Wue41dbe62017-06-13 14:10:56 -0700429 sp<Layer> parent = mDrawingParent.promote();
Albert Chaulk2a589632017-05-04 16:59:44 -0400430 if (parent.get()) {
431 auto& parentState = parent->getDrawingState();
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800432 const int parentType = parentState.metadata.getInt32(METADATA_WINDOW_TYPE, 0);
433 const int parentAppId = parentState.metadata.getInt32(METADATA_OWNER_UID, 0);
Jiwen 'Steve' Cai736c74e2019-05-28 18:33:22 -0700434 if (parentType > 0 && parentAppId > 0) {
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800435 type = parentType;
436 appId = parentAppId;
rongliucfb187b2018-03-14 12:26:23 -0700437 }
Albert Chaulk2a589632017-05-04 16:59:44 -0400438 }
439
Lloyd Piquede196652020-01-22 17:29:58 -0800440 auto* compositionState = editCompositionState();
David Sodman15094112018-10-11 09:39:37 -0700441
Lloyd Piquede196652020-01-22 17:29:58 -0800442 compositionState->geomBufferSize = getBufferSize(drawingState);
443 compositionState->geomContentCrop = getBufferCrop();
444 compositionState->geomCrop = getCrop(drawingState);
445 compositionState->geomBufferTransform = getBufferTransform();
446 compositionState->geomBufferUsesDisplayInverseTransform = getTransformToDisplayInverse();
447 compositionState->geomUsesSourceCrop = usesSourceCrop();
448 compositionState->isSecure = isSecure();
449
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800450 compositionState->metadata.clear();
451 const auto& supportedMetadata = mFlinger->getHwComposer().getSupportedLayerGenericMetadata();
452 for (const auto& [key, mandatory] : supportedMetadata) {
453 const auto& genericLayerMetadataCompatibilityMap =
454 mFlinger->getGenericLayerMetadataKeyMap();
455 auto compatIter = genericLayerMetadataCompatibilityMap.find(key);
456 if (compatIter == std::end(genericLayerMetadataCompatibilityMap)) {
457 continue;
458 }
459 const uint32_t id = compatIter->second;
460
461 auto it = drawingState.metadata.mMap.find(id);
462 if (it == std::end(drawingState.metadata.mMap)) {
463 continue;
464 }
465
466 compositionState->metadata
467 .emplace(key, compositionengine::GenericLayerMetadataEntry{mandatory, it->second});
468 }
Lloyd Piquea83776c2019-01-29 18:42:32 -0800469}
David Sodmanba340492018-08-05 21:51:33 -0700470
Lloyd Piquede196652020-01-22 17:29:58 -0800471void Layer::preparePerFrameCompositionState() {
Lloyd Pique688abd42019-02-15 15:42:24 -0800472 const auto& drawingState{getDrawingState()};
Lloyd Piquede196652020-01-22 17:29:58 -0800473 auto* compositionState = editCompositionState();
Lloyd Piquef5275482019-01-29 18:42:42 -0800474
Lloyd Piquede196652020-01-22 17:29:58 -0800475 compositionState->forceClientComposition = false;
476
477 compositionState->isColorspaceAgnostic = isColorSpaceAgnostic();
478 compositionState->dataspace = getDataSpace();
479 compositionState->colorTransform = getColorTransform();
480 compositionState->colorTransformIsIdentity = !hasColorTransform();
481 compositionState->surfaceDamage = surfaceDamageRegion;
482 compositionState->hasProtectedContent = isProtected();
Lloyd Pique688abd42019-02-15 15:42:24 -0800483
484 const bool usesRoundedCorners = getRoundedCornerState().radius != 0.f;
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700485
Lloyd Piquede196652020-01-22 17:29:58 -0800486 compositionState->isOpaque =
Lloyd Pique688abd42019-02-15 15:42:24 -0800487 isOpaque(drawingState) && !usesRoundedCorners && getAlpha() == 1.0_hf;
Lloyd Piquef5275482019-01-29 18:42:42 -0800488
489 // Force client composition for special cases known only to the front-end.
Leon Scroggins IIId305ef22021-04-06 09:53:26 -0400490 // Rounded corners no longer force client composition, since we may use a
491 // hole punch so that the layer will appear to have rounded corners.
492 if (isHdrY410() || drawShadows() || drawingState.blurRegions.size() > 0 ||
John Reckc00c6692021-02-16 11:37:33 -0500493 compositionState->stretchEffect.hasEffect()) {
Lloyd Piquede196652020-01-22 17:29:58 -0800494 compositionState->forceClientComposition = true;
Lloyd Piquef5275482019-01-29 18:42:42 -0800495 }
496}
497
Lloyd Piquede196652020-01-22 17:29:58 -0800498void Layer::prepareCursorCompositionState() {
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800499 const State& drawingState{getDrawingState()};
Lloyd Piquede196652020-01-22 17:29:58 -0800500 auto* compositionState = editCompositionState();
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800501
502 // Apply the layer's transform, followed by the display's global transform
503 // Here we're guaranteed that the layer's transform preserves rects
504 Rect win = getCroppedBufferSize(drawingState);
505 // Subtract the transparent region and snap to the bounds
506 Rect bounds = reduce(win, getActiveTransparentRegion(drawingState));
507 Rect frame(getTransform().transform(bounds));
508
Lloyd Piquede196652020-01-22 17:29:58 -0800509 compositionState->cursorFrame = frame;
510}
511
512sp<compositionengine::LayerFE> Layer::asLayerFE() const {
513 return const_cast<compositionengine::LayerFE*>(
514 static_cast<const compositionengine::LayerFE*>(this));
515}
516
517sp<compositionengine::LayerFE> Layer::getCompositionEngineLayerFE() const {
518 return nullptr;
519}
520
521compositionengine::LayerFECompositionState* Layer::editCompositionState() {
522 return nullptr;
523}
524
525const compositionengine::LayerFECompositionState* Layer::getCompositionState() const {
526 return nullptr;
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800527}
528
Lloyd Piquef16688f2019-02-19 17:47:57 -0800529bool Layer::onPreComposition(nsecs_t) {
530 return false;
531}
532
Lloyd Piquede196652020-01-22 17:29:58 -0800533void Layer::prepareCompositionState(compositionengine::LayerFE::StateSubset subset) {
Lloyd Piquec6687342019-03-07 21:34:57 -0800534 using StateSubset = compositionengine::LayerFE::StateSubset;
Lloyd Piquef5275482019-01-29 18:42:42 -0800535
Lloyd Piquec6687342019-03-07 21:34:57 -0800536 switch (subset) {
537 case StateSubset::BasicGeometry:
Lloyd Piquede196652020-01-22 17:29:58 -0800538 prepareBasicGeometryCompositionState();
Lloyd Piquec6687342019-03-07 21:34:57 -0800539 break;
540
541 case StateSubset::GeometryAndContent:
Lloyd Piquede196652020-01-22 17:29:58 -0800542 prepareBasicGeometryCompositionState();
543 prepareGeometryCompositionState();
544 preparePerFrameCompositionState();
Lloyd Piquec6687342019-03-07 21:34:57 -0800545 break;
546
547 case StateSubset::Content:
Lloyd Piquede196652020-01-22 17:29:58 -0800548 preparePerFrameCompositionState();
549 break;
550
551 case StateSubset::Cursor:
552 prepareCursorCompositionState();
Lloyd Piquec6687342019-03-07 21:34:57 -0800553 break;
554 }
Lloyd Piquea83776c2019-01-29 18:42:32 -0800555}
Mathias Agopian29a367b2011-07-12 14:51:45 -0700556
Lloyd Piquea83776c2019-01-29 18:42:32 -0800557const char* Layer::getDebugName() const {
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700558 return mName.c_str();
David Sodman4b7c4bc2017-11-17 12:13:59 -0800559}
560
Mathias Agopian13127d82013-03-05 17:47:11 -0800561// ---------------------------------------------------------------------------
562// drawing...
563// ---------------------------------------------------------------------------
564
Vishnu Nair9b079a22020-01-21 14:36:08 -0800565std::optional<compositionengine::LayerFE::LayerSettings> Layer::prepareClientComposition(
Galia Peycheva66eaf4a2020-11-09 13:17:57 +0100566 compositionengine::LayerFE::ClientCompositionTargetSettings& targetSettings) {
Lloyd Piquede196652020-01-22 17:29:58 -0800567 if (!getCompositionState()) {
Lloyd Piquef16688f2019-02-19 17:47:57 -0800568 return {};
569 }
Mathias Agopian13127d82013-03-05 17:47:11 -0800570
Vishnu Nair4351ad52019-02-11 14:13:02 -0800571 FloatRect bounds = getBounds();
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000572 half alpha = getAlpha();
Vishnu Nair9b079a22020-01-21 14:36:08 -0800573
574 compositionengine::LayerFE::LayerSettings layerSettings;
Lloyd Piquef16688f2019-02-19 17:47:57 -0800575 layerSettings.geometry.boundaries = bounds;
chaviwc6ad8af2020-08-03 11:33:30 -0700576 layerSettings.geometry.positionTransform = getTransform().asMatrix4();
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000577
Derek Sollenbergerc31985e2021-05-18 16:38:17 -0400578 // skip drawing content if the targetSettings indicate the content will be occluded
Lucas Dupin0fe42e52021-05-27 17:27:15 -0700579 layerSettings.skipContentDraw =
580 layerSettings.skipContentDraw || !targetSettings.realContentIsVisible;
Derek Sollenbergerc31985e2021-05-18 16:38:17 -0400581
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000582 if (hasColorTransform()) {
Lloyd Piquef16688f2019-02-19 17:47:57 -0800583 layerSettings.colorTransform = getColorTransform();
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000584 }
585
586 const auto roundedCornerState = getRoundedCornerState();
Lloyd Piquef16688f2019-02-19 17:47:57 -0800587 layerSettings.geometry.roundedCornersRadius = roundedCornerState.radius;
588 layerSettings.geometry.roundedCornersCrop = roundedCornerState.cropRect;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000589
Lloyd Piquef16688f2019-02-19 17:47:57 -0800590 layerSettings.alpha = alpha;
chaviw4244e032019-09-04 11:27:49 -0700591 layerSettings.sourceDataspace = getDataSpace();
Alec Mourif54453c2021-05-13 16:28:28 -0700592 switch (targetSettings.blurSetting) {
593 case LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled:
594 layerSettings.backgroundBlurRadius = getBackgroundBlurRadius();
595 layerSettings.blurRegions = getBlurRegions();
596 layerSettings.blurRegionTransform =
597 getActiveTransform(getDrawingState()).inverse().asMatrix4();
598 break;
599 case LayerFE::ClientCompositionTargetSettings::BlurSetting::BackgroundBlurOnly:
600 layerSettings.backgroundBlurRadius = getBackgroundBlurRadius();
601 break;
602 case LayerFE::ClientCompositionTargetSettings::BlurSetting::BlurRegionsOnly:
603 layerSettings.blurRegions = getBlurRegions();
604 layerSettings.blurRegionTransform =
605 getActiveTransform(getDrawingState()).inverse().asMatrix4();
606 break;
607 case LayerFE::ClientCompositionTargetSettings::BlurSetting::Disabled:
608 default:
609 break;
Galia Peycheva66eaf4a2020-11-09 13:17:57 +0100610 }
Nader Jawad2dfc98b2021-04-08 20:35:39 -0700611 layerSettings.stretchEffect = getStretchEffect();
Ana Krulec6eab17a2020-12-09 15:52:36 -0800612 // Record the name of the layer for debugging further down the stack.
613 layerSettings.name = getName();
Lloyd Piquef16688f2019-02-19 17:47:57 -0800614 return layerSettings;
Mathias Agopian13127d82013-03-05 17:47:11 -0800615}
616
Vishnu Nairb87d94f2020-02-13 09:17:36 -0800617void Layer::prepareClearClientComposition(LayerFE::LayerSettings& layerSettings,
618 bool blackout) const {
619 layerSettings.source.buffer.buffer = nullptr;
620 layerSettings.source.solidColor = half3(0.0, 0.0, 0.0);
621 layerSettings.disableBlending = true;
Vishnu Nair3b653e72020-02-24 16:40:50 -0800622 layerSettings.bufferId = 0;
Vishnu Nairb87d94f2020-02-13 09:17:36 -0800623 layerSettings.frameNumber = 0;
624
625 // If layer is blacked out, force alpha to 1 so that we draw a black color layer.
626 layerSettings.alpha = blackout ? 1.0f : 0.0f;
Alec Mouribd17b3b2020-12-17 11:08:30 -0800627 layerSettings.name = getName();
Vishnu Nairb87d94f2020-02-13 09:17:36 -0800628}
629
Derek Sollenbergerc31985e2021-05-18 16:38:17 -0400630// TODO(b/188891810): This method now only ever returns 0 or 1 layers so we should return
631// std::optional instead of a vector. Additionally, we should consider removing
632// this method entirely in favor of calling prepareClientComposition directly.
Vishnu Nairb87d94f2020-02-13 09:17:36 -0800633std::vector<compositionengine::LayerFE::LayerSettings> Layer::prepareClientCompositionList(
634 compositionengine::LayerFE::ClientCompositionTargetSettings& targetSettings) {
635 std::optional<compositionengine::LayerFE::LayerSettings> layerSettings =
636 prepareClientComposition(targetSettings);
637 // Nothing to render.
638 if (!layerSettings) {
639 return {};
640 }
641
642 // HWC requests to clear this layer.
643 if (targetSettings.clearContent) {
644 prepareClearClientComposition(*layerSettings, false /* blackout */);
645 return {*layerSettings};
646 }
647
Derek Sollenbergerc31985e2021-05-18 16:38:17 -0400648 // set the shadow for the layer if needed
649 prepareShadowClientComposition(*layerSettings, targetSettings.viewport);
Vishnu Nairb87d94f2020-02-13 09:17:36 -0800650
Derek Sollenbergerc31985e2021-05-18 16:38:17 -0400651 return {*layerSettings};
Vishnu Nairb87d94f2020-02-13 09:17:36 -0800652}
653
Dominik Laskowskib7251f42020-04-20 17:42:59 -0700654Hwc2::IComposerClient::Composition Layer::getCompositionType(const DisplayDevice& display) const {
655 const auto outputLayer = findOutputLayerForDisplay(&display);
Alec Mouri6b9e9912020-01-21 10:50:24 -0800656 if (outputLayer == nullptr) {
657 return Hwc2::IComposerClient::Composition::INVALID;
658 }
659 if (outputLayer->getState().hwc) {
660 return (*outputLayer->getState().hwc).hwcCompositionType;
661 } else {
662 return Hwc2::IComposerClient::Composition::CLIENT;
663 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800664}
665
Mathias Agopian13127d82013-03-05 17:47:11 -0800666// ----------------------------------------------------------------------------
667// local state
668// ----------------------------------------------------------------------------
669
David Sodman41fdfc92017-11-06 16:09:56 -0800670bool Layer::isSecure() const {
Lloyd Pique0449b0f2018-12-20 16:23:45 -0800671 const State& s(mDrawingState);
Garfield Tande619fa2020-10-02 17:13:53 -0700672 if (s.flags & layer_state_t::eLayerSecure) {
673 return true;
674 }
675
676 const auto p = mDrawingParent.promote();
677 return (p != nullptr) ? p->isSecure() : false;
Dan Stoza23116082015-06-18 14:58:39 -0700678}
679
Mathias Agopian13127d82013-03-05 17:47:11 -0800680// ----------------------------------------------------------------------------
681// transaction
682// ----------------------------------------------------------------------------
Ady Abraham83729882018-12-07 12:26:48 -0800683
Marissa Wall61c58622018-07-18 10:12:20 -0700684uint32_t Layer::doTransaction(uint32_t flags) {
685 ATRACE_CALL();
686
Robert Carr0758e5d2021-03-11 22:15:04 -0800687 // TODO: This is unfortunate.
Robert Carr6a160312021-05-17 12:08:20 -0700688 mDrawingStateModified = mDrawingState.modified;
689 mDrawingState.modified = false;
Marissa Wall61c58622018-07-18 10:12:20 -0700690
Alec Mourib416efd2018-09-06 21:01:59 +0000691 const State& s(getDrawingState());
Marissa Wall61c58622018-07-18 10:12:20 -0700692
Robert Carr6a160312021-05-17 12:08:20 -0700693 if (updateGeometry()) {
Mathias Agopian13127d82013-03-05 17:47:11 -0800694 // invalidate and recompute the visible regions if needed
695 flags |= Layer::eVisibleRegion;
696 }
697
Robert Carr6a160312021-05-17 12:08:20 -0700698 if (s.sequence != mLastCommittedTxSequence) {
Mathias Agopian13127d82013-03-05 17:47:11 -0800699 // invalidate and recompute the visible regions if needed
Robert Carr6a160312021-05-17 12:08:20 -0700700 mLastCommittedTxSequence = s.sequence;
Mathias Agopian13127d82013-03-05 17:47:11 -0800701 flags |= eVisibleRegion;
702 this->contentDirty = true;
703
704 // we may use linear filtering, if the matrix scales us
Robert Carr6a160312021-05-17 12:08:20 -0700705 mNeedsFiltering = getActiveTransform(s).needsBilinearFiltering();
Mathias Agopian13127d82013-03-05 17:47:11 -0800706 }
707
Robert Carr6a160312021-05-17 12:08:20 -0700708 commitTransaction(mDrawingState);
Robert Carra1257842020-01-31 13:48:28 -0800709
Mathias Agopian13127d82013-03-05 17:47:11 -0800710 return flags;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800711}
712
Robert Carr6a160312021-05-17 12:08:20 -0700713void Layer::commitTransaction(State&) {
Adithya Srinivasanb9a7dab2021-01-14 23:49:46 +0000714 // Set the present state for all bufferlessSurfaceFramesTX to Presented. The
715 // bufferSurfaceFrameTX will be presented in latchBuffer.
716 for (auto& [token, surfaceFrame] : mDrawingState.bufferlessSurfaceFramesTX) {
717 if (surfaceFrame->getPresentState() != PresentState::Presented) {
718 // With applyPendingStates, we could end up having presented surfaceframes from previous
719 // states
720 surfaceFrame->setPresentState(PresentState::Presented);
721 mFlinger->mFrameTimeline->addSurfaceFrame(surfaceFrame);
722 }
723 }
Robert Carr6a160312021-05-17 12:08:20 -0700724 mDrawingState.bufferlessSurfaceFramesTX.clear();
Mathias Agopiana67932f2011-04-20 14:20:59 -0700725}
726
Mathias Agopian13127d82013-03-05 17:47:11 -0800727uint32_t Layer::getTransactionFlags(uint32_t flags) {
Robert Carr38d25002021-06-11 14:30:09 -0700728 auto ret = mTransactionFlags & flags;
729 mTransactionFlags &= ~flags;
730 return ret;
Mathias Agopian13127d82013-03-05 17:47:11 -0800731}
732
733uint32_t Layer::setTransactionFlags(uint32_t flags) {
Robert Carr38d25002021-06-11 14:30:09 -0700734 return mTransactionFlags |= flags;
Mathias Agopian13127d82013-03-05 17:47:11 -0800735}
736
chaviw214c89d2019-09-04 16:03:53 -0700737bool Layer::setPosition(float x, float y) {
Robert Carr6a160312021-05-17 12:08:20 -0700738 if (mDrawingState.transform.tx() == x && mDrawingState.transform.ty() == y) return false;
739 mDrawingState.sequence++;
740 mDrawingState.transform.set(x, y);
Robert Carr69663fb2016-03-27 19:59:19 -0700741
Robert Carr6a160312021-05-17 12:08:20 -0700742 mDrawingState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -0800743 setTransactionFlags(eTransactionNeeded);
744 return true;
745}
Robert Carr82364e32016-05-15 11:27:47 -0700746
Robert Carr1f0a16a2016-10-24 16:27:39 -0700747bool Layer::setChildLayer(const sp<Layer>& childLayer, int32_t z) {
748 ssize_t idx = mCurrentChildren.indexOf(childLayer);
749 if (idx < 0) {
750 return false;
751 }
752 if (childLayer->setLayer(z)) {
753 mCurrentChildren.removeAt(idx);
754 mCurrentChildren.add(childLayer);
Robert Carr503d2bd2017-12-04 15:49:47 -0800755 return true;
Robert Carr1f0a16a2016-10-24 16:27:39 -0700756 }
Robert Carr503d2bd2017-12-04 15:49:47 -0800757 return false;
Robert Carr1f0a16a2016-10-24 16:27:39 -0700758}
759
Robert Carr503c7042017-09-27 15:06:08 -0700760bool Layer::setChildRelativeLayer(const sp<Layer>& childLayer,
761 const sp<IBinder>& relativeToHandle, int32_t relativeZ) {
762 ssize_t idx = mCurrentChildren.indexOf(childLayer);
763 if (idx < 0) {
764 return false;
765 }
766 if (childLayer->setRelativeLayer(relativeToHandle, relativeZ)) {
767 mCurrentChildren.removeAt(idx);
768 mCurrentChildren.add(childLayer);
Robert Carr503d2bd2017-12-04 15:49:47 -0800769 return true;
Robert Carr503c7042017-09-27 15:06:08 -0700770 }
Robert Carr503d2bd2017-12-04 15:49:47 -0800771 return false;
Robert Carr503c7042017-09-27 15:06:08 -0700772}
773
Robert Carrae060832016-11-28 10:51:00 -0800774bool Layer::setLayer(int32_t z) {
Robert Carr6a160312021-05-17 12:08:20 -0700775 if (mDrawingState.z == z && !usingRelativeZ(LayerVector::StateSet::Current)) return false;
776 mDrawingState.sequence++;
777 mDrawingState.z = z;
778 mDrawingState.modified = true;
Robert Carrdb66e622017-04-10 16:55:57 -0700779
Robert Carra70e91c2021-06-11 13:59:52 -0700780 mFlinger->mSomeChildrenChanged = true;
781
Robert Carrdb66e622017-04-10 16:55:57 -0700782 // Discard all relative layering.
Robert Carr6a160312021-05-17 12:08:20 -0700783 if (mDrawingState.zOrderRelativeOf != nullptr) {
784 sp<Layer> strongRelative = mDrawingState.zOrderRelativeOf.promote();
Robert Carrdb66e622017-04-10 16:55:57 -0700785 if (strongRelative != nullptr) {
786 strongRelative->removeZOrderRelative(this);
787 }
chaviw606e5cf2019-03-01 10:12:10 -0800788 setZOrderRelativeOf(nullptr);
Robert Carrdb66e622017-04-10 16:55:57 -0700789 }
Mathias Agopian13127d82013-03-05 17:47:11 -0800790 setTransactionFlags(eTransactionNeeded);
791 return true;
792}
Robert Carr1f0a16a2016-10-24 16:27:39 -0700793
Robert Carrdb66e622017-04-10 16:55:57 -0700794void Layer::removeZOrderRelative(const wp<Layer>& relative) {
Robert Carr6a160312021-05-17 12:08:20 -0700795 mDrawingState.zOrderRelatives.remove(relative);
796 mDrawingState.sequence++;
797 mDrawingState.modified = true;
Robert Carrdb66e622017-04-10 16:55:57 -0700798 setTransactionFlags(eTransactionNeeded);
799}
800
801void Layer::addZOrderRelative(const wp<Layer>& relative) {
Robert Carr6a160312021-05-17 12:08:20 -0700802 mDrawingState.zOrderRelatives.add(relative);
803 mDrawingState.modified = true;
804 mDrawingState.sequence++;
Robert Carrdb66e622017-04-10 16:55:57 -0700805 setTransactionFlags(eTransactionNeeded);
806}
807
chaviw606e5cf2019-03-01 10:12:10 -0800808void Layer::setZOrderRelativeOf(const wp<Layer>& relativeOf) {
Robert Carr6a160312021-05-17 12:08:20 -0700809 mDrawingState.zOrderRelativeOf = relativeOf;
810 mDrawingState.sequence++;
811 mDrawingState.modified = true;
812 mDrawingState.isRelativeOf = relativeOf != nullptr;
chaviwbdb8b802019-10-14 09:17:12 -0700813
chaviw606e5cf2019-03-01 10:12:10 -0800814 setTransactionFlags(eTransactionNeeded);
815}
816
Robert Carr503d2bd2017-12-04 15:49:47 -0800817bool Layer::setRelativeLayer(const sp<IBinder>& relativeToHandle, int32_t relativeZ) {
Robert Carrdb66e622017-04-10 16:55:57 -0700818 sp<Handle> handle = static_cast<Handle*>(relativeToHandle.get());
819 if (handle == nullptr) {
820 return false;
821 }
822 sp<Layer> relative = handle->owner.promote();
823 if (relative == nullptr) {
824 return false;
825 }
826
Robert Carr6a160312021-05-17 12:08:20 -0700827 if (mDrawingState.z == relativeZ && usingRelativeZ(LayerVector::StateSet::Current) &&
828 mDrawingState.zOrderRelativeOf == relative) {
Robert Carr503d2bd2017-12-04 15:49:47 -0800829 return false;
830 }
831
Robert Carra70e91c2021-06-11 13:59:52 -0700832 mFlinger->mSomeChildrenChanged = true;
833
Robert Carr6a160312021-05-17 12:08:20 -0700834 mDrawingState.sequence++;
835 mDrawingState.modified = true;
836 mDrawingState.z = relativeZ;
Robert Carrdb66e622017-04-10 16:55:57 -0700837
Robert Carr6a160312021-05-17 12:08:20 -0700838 auto oldZOrderRelativeOf = mDrawingState.zOrderRelativeOf.promote();
chaviw9ab4bd12017-11-03 13:11:00 -0700839 if (oldZOrderRelativeOf != nullptr) {
840 oldZOrderRelativeOf->removeZOrderRelative(this);
841 }
chaviw606e5cf2019-03-01 10:12:10 -0800842 setZOrderRelativeOf(relative);
Robert Carrdb66e622017-04-10 16:55:57 -0700843 relative->addZOrderRelative(this);
844
845 setTransactionFlags(eTransactionNeeded);
846
847 return true;
848}
849
Mathias Agopian13127d82013-03-05 17:47:11 -0800850bool Layer::setSize(uint32_t w, uint32_t h) {
Robert Carr6a160312021-05-17 12:08:20 -0700851 if (mDrawingState.requested_legacy.w == w && mDrawingState.requested_legacy.h == h)
Marissa Wallf58c14b2018-07-24 10:50:43 -0700852 return false;
Robert Carr6a160312021-05-17 12:08:20 -0700853 mDrawingState.requested_legacy.w = w;
854 mDrawingState.requested_legacy.h = h;
855 mDrawingState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -0800856 setTransactionFlags(eTransactionNeeded);
Vishnu Naird01c4432018-08-13 10:38:47 -0700857
858 // record the new size, from this point on, when the client request
859 // a buffer, it'll get the new size.
Robert Carr6a160312021-05-17 12:08:20 -0700860 setDefaultBufferSize(mDrawingState.requested_legacy.w, mDrawingState.requested_legacy.h);
Mathias Agopian13127d82013-03-05 17:47:11 -0800861 return true;
862}
chaviw4e765532021-04-30 12:11:39 -0500863
Dan Stoza9e56aa02015-11-02 13:00:03 -0800864bool Layer::setAlpha(float alpha) {
Robert Carr6a160312021-05-17 12:08:20 -0700865 if (mDrawingState.color.a == alpha) return false;
866 mDrawingState.sequence++;
867 mDrawingState.color.a = alpha;
868 mDrawingState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -0800869 setTransactionFlags(eTransactionNeeded);
870 return true;
871}
chaviw13fdc492017-06-27 12:40:18 -0700872
Valerie Haudd0b7572019-01-29 14:59:27 -0800873bool Layer::setBackgroundColor(const half3& color, float alpha, ui::Dataspace dataspace) {
Robert Carr6a160312021-05-17 12:08:20 -0700874 if (!mDrawingState.bgColorLayer && alpha == 0) {
chaviw13fdc492017-06-27 12:40:18 -0700875 return false;
Valerie Hauaa194562019-02-05 16:21:38 -0800876 }
Robert Carr6a160312021-05-17 12:08:20 -0700877 mDrawingState.sequence++;
878 mDrawingState.modified = true;
Valerie Hauaa194562019-02-05 16:21:38 -0800879 setTransactionFlags(eTransactionNeeded);
880
Robert Carr6a160312021-05-17 12:08:20 -0700881 if (!mDrawingState.bgColorLayer && alpha != 0) {
Valerie Haudd0b7572019-01-29 14:59:27 -0800882 // create background color layer if one does not yet exist
Vishnu Nairfa247b12020-02-11 08:58:26 -0800883 uint32_t flags = ISurfaceComposerClient::eFXSurfaceEffect;
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700884 std::string name = mName + "BackgroundColorLayer";
Robert Carr6a160312021-05-17 12:08:20 -0700885 mDrawingState.bgColorLayer = mFlinger->getFactory().createEffectLayer(
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700886 LayerCreationArgs(mFlinger.get(), nullptr, std::move(name), 0, 0, flags,
887 LayerMetadata()));
chaviw13fdc492017-06-27 12:40:18 -0700888
Valerie Haudd0b7572019-01-29 14:59:27 -0800889 // add to child list
Robert Carr6a160312021-05-17 12:08:20 -0700890 addChild(mDrawingState.bgColorLayer);
Valerie Haudd0b7572019-01-29 14:59:27 -0800891 mFlinger->mLayersAdded = true;
892 // set up SF to handle added color layer
893 if (isRemovedFromCurrentState()) {
Robert Carr6a160312021-05-17 12:08:20 -0700894 mDrawingState.bgColorLayer->onRemovedFromCurrentState();
Valerie Haudd0b7572019-01-29 14:59:27 -0800895 }
896 mFlinger->setTransactionFlags(eTransactionNeeded);
Robert Carr6a160312021-05-17 12:08:20 -0700897 } else if (mDrawingState.bgColorLayer && alpha == 0) {
898 mDrawingState.bgColorLayer->reparent(nullptr);
899 mDrawingState.bgColorLayer = nullptr;
Valerie Haudd0b7572019-01-29 14:59:27 -0800900 return true;
901 }
902
Robert Carr6a160312021-05-17 12:08:20 -0700903 mDrawingState.bgColorLayer->setColor(color);
904 mDrawingState.bgColorLayer->setLayer(std::numeric_limits<int32_t>::min());
905 mDrawingState.bgColorLayer->setAlpha(alpha);
906 mDrawingState.bgColorLayer->setDataspace(dataspace);
Valerie Haudd0b7572019-01-29 14:59:27 -0800907
chaviw13fdc492017-06-27 12:40:18 -0700908 return true;
909}
910
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700911bool Layer::setCornerRadius(float cornerRadius) {
Robert Carr6a160312021-05-17 12:08:20 -0700912 if (mDrawingState.cornerRadius == cornerRadius) return false;
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700913
Robert Carr6a160312021-05-17 12:08:20 -0700914 mDrawingState.sequence++;
915 mDrawingState.cornerRadius = cornerRadius;
916 mDrawingState.modified = true;
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700917 setTransactionFlags(eTransactionNeeded);
918 return true;
919}
920
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800921bool Layer::setBackgroundBlurRadius(int backgroundBlurRadius) {
Robert Carr6a160312021-05-17 12:08:20 -0700922 if (mDrawingState.backgroundBlurRadius == backgroundBlurRadius) return false;
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800923
Robert Carr6a160312021-05-17 12:08:20 -0700924 mDrawingState.sequence++;
925 mDrawingState.backgroundBlurRadius = backgroundBlurRadius;
926 mDrawingState.modified = true;
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800927 setTransactionFlags(eTransactionNeeded);
928 return true;
929}
930
Robert Carrd4ae7f32018-06-07 16:10:57 -0700931bool Layer::setMatrix(const layer_state_t::matrix22_t& matrix,
932 bool allowNonRectPreservingTransforms) {
Peiyong Linefefaac2018-08-17 12:27:51 -0700933 ui::Transform t;
Robert Carrd4ae7f32018-06-07 16:10:57 -0700934 t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
935
936 if (!allowNonRectPreservingTransforms && !t.preserveRects()) {
Hongwei Wang46213ea2020-12-04 17:17:31 -0800937 ALOGW("Attempt to set rotation matrix without permission ACCESS_SURFACE_FLINGER nor "
938 "ROTATE_SURFACE_FLINGER ignored");
Robert Carrd4ae7f32018-06-07 16:10:57 -0700939 return false;
940 }
Robert Carr6a160312021-05-17 12:08:20 -0700941 mDrawingState.sequence++;
942 mDrawingState.transform.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
943 mDrawingState.modified = true;
944
Mathias Agopian13127d82013-03-05 17:47:11 -0800945 setTransactionFlags(eTransactionNeeded);
946 return true;
947}
Marissa Wall61c58622018-07-18 10:12:20 -0700948
Mathias Agopian13127d82013-03-05 17:47:11 -0800949bool Layer::setTransparentRegionHint(const Region& transparent) {
Robert Carr6a160312021-05-17 12:08:20 -0700950 mDrawingState.requestedTransparentRegion_legacy = transparent;
951 mDrawingState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -0800952 setTransactionFlags(eTransactionNeeded);
953 return true;
954}
Ana Krulecc84d09b2019-11-02 23:10:29 +0100955
Lucas Dupinc3800b82020-10-02 16:24:48 -0700956bool Layer::setBlurRegions(const std::vector<BlurRegion>& blurRegions) {
Robert Carr6a160312021-05-17 12:08:20 -0700957 mDrawingState.sequence++;
958 mDrawingState.blurRegions = blurRegions;
959 mDrawingState.modified = true;
Lucas Dupinc3800b82020-10-02 16:24:48 -0700960 setTransactionFlags(eTransactionNeeded);
961 return true;
962}
963
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800964bool Layer::setFlags(uint32_t flags, uint32_t mask) {
Robert Carr6a160312021-05-17 12:08:20 -0700965 const uint32_t newFlags = (mDrawingState.flags & ~mask) | (flags & mask);
966 if (mDrawingState.flags == newFlags) return false;
967 mDrawingState.sequence++;
968 mDrawingState.flags = newFlags;
969 mDrawingState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -0800970 setTransactionFlags(eTransactionNeeded);
971 return true;
972}
Robert Carr99e27f02016-06-16 15:18:02 -0700973
chaviw25714502021-02-11 10:01:08 -0800974bool Layer::setCrop(const Rect& crop) {
Robert Carr6a160312021-05-17 12:08:20 -0700975 if (mDrawingState.requestedCrop == crop) return false;
976 mDrawingState.sequence++;
977 mDrawingState.requestedCrop = crop;
978 mDrawingState.crop = crop;
Robert Carr7bf247e2017-05-18 14:02:49 -0700979
Robert Carr6a160312021-05-17 12:08:20 -0700980 mDrawingState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -0800981 setTransactionFlags(eTransactionNeeded);
982 return true;
983}
Robert Carr8d5227b2017-03-16 15:41:03 -0700984
Evan Roskyef876c92019-01-25 17:46:06 -0800985bool Layer::setMetadata(const LayerMetadata& data) {
Robert Carr6a160312021-05-17 12:08:20 -0700986 if (!mDrawingState.metadata.merge(data, true /* eraseEmpty */)) return false;
987 mDrawingState.modified = true;
David Sodman41fdfc92017-11-06 16:09:56 -0800988 setTransactionFlags(eTransactionNeeded);
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800989 return true;
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -0500990}
991
Mathias Agopian13127d82013-03-05 17:47:11 -0800992bool Layer::setLayerStack(uint32_t layerStack) {
Robert Carr6a160312021-05-17 12:08:20 -0700993 if (mDrawingState.layerStack == layerStack) return false;
994 mDrawingState.sequence++;
995 mDrawingState.layerStack = layerStack;
996 mDrawingState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -0800997 setTransactionFlags(eTransactionNeeded);
998 return true;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700999}
1000
Peiyong Linc502cb72019-03-01 15:00:23 -08001001bool Layer::setColorSpaceAgnostic(const bool agnostic) {
Robert Carr6a160312021-05-17 12:08:20 -07001002 if (mDrawingState.colorSpaceAgnostic == agnostic) {
Peiyong Linc502cb72019-03-01 15:00:23 -08001003 return false;
1004 }
Robert Carr6a160312021-05-17 12:08:20 -07001005 mDrawingState.sequence++;
1006 mDrawingState.colorSpaceAgnostic = agnostic;
1007 mDrawingState.modified = true;
Peiyong Linc502cb72019-03-01 15:00:23 -08001008 setTransactionFlags(eTransactionNeeded);
1009 return true;
1010}
1011
Ana Krulecc84d09b2019-11-02 23:10:29 +01001012bool Layer::setFrameRateSelectionPriority(int32_t priority) {
Robert Carr6a160312021-05-17 12:08:20 -07001013 if (mDrawingState.frameRateSelectionPriority == priority) return false;
1014 mDrawingState.frameRateSelectionPriority = priority;
1015 mDrawingState.sequence++;
1016 mDrawingState.modified = true;
Ana Krulecc84d09b2019-11-02 23:10:29 +01001017 setTransactionFlags(eTransactionNeeded);
1018 return true;
1019}
1020
1021int32_t Layer::getFrameRateSelectionPriority() const {
1022 // Check if layer has priority set.
1023 if (mDrawingState.frameRateSelectionPriority != PRIORITY_UNSET) {
1024 return mDrawingState.frameRateSelectionPriority;
1025 }
1026 // If not, search whether its parents have it set.
1027 sp<Layer> parent = getParent();
1028 if (parent != nullptr) {
1029 return parent->getFrameRateSelectionPriority();
1030 }
1031
1032 return Layer::PRIORITY_UNSET;
1033}
1034
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001035bool Layer::isLayerFocusedBasedOnPriority(int32_t priority) {
1036 return priority == PRIORITY_FOCUSED_WITH_MODE || priority == PRIORITY_FOCUSED_WITHOUT_MODE;
1037};
1038
Robert Carr1f0a16a2016-10-24 16:27:39 -07001039uint32_t Layer::getLayerStack() const {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001040 auto p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001041 if (p == nullptr) {
1042 return getDrawingState().layerStack;
1043 }
1044 return p->getLayerStack();
1045}
1046
Vishnu Nairc97b8db2019-10-29 18:19:35 -07001047bool Layer::setShadowRadius(float shadowRadius) {
Robert Carr6a160312021-05-17 12:08:20 -07001048 if (mDrawingState.shadowRadius == shadowRadius) {
Vishnu Nairc97b8db2019-10-29 18:19:35 -07001049 return false;
1050 }
1051
Robert Carr6a160312021-05-17 12:08:20 -07001052 mDrawingState.sequence++;
1053 mDrawingState.shadowRadius = shadowRadius;
1054 mDrawingState.modified = true;
Vishnu Nairc97b8db2019-10-29 18:19:35 -07001055 setTransactionFlags(eTransactionNeeded);
1056 return true;
1057}
1058
Vishnu Nair6213bd92020-05-08 17:42:25 -07001059bool Layer::setFixedTransformHint(ui::Transform::RotationFlags fixedTransformHint) {
Robert Carr6a160312021-05-17 12:08:20 -07001060 if (mDrawingState.fixedTransformHint == fixedTransformHint) {
Vishnu Nair6213bd92020-05-08 17:42:25 -07001061 return false;
1062 }
1063
Robert Carr6a160312021-05-17 12:08:20 -07001064 mDrawingState.sequence++;
1065 mDrawingState.fixedTransformHint = fixedTransformHint;
1066 mDrawingState.modified = true;
Vishnu Nair6213bd92020-05-08 17:42:25 -07001067 setTransactionFlags(eTransactionNeeded);
1068 return true;
1069}
1070
John Reckcdb4ed72021-02-04 13:39:33 -05001071bool Layer::setStretchEffect(const StretchEffect& effect) {
1072 StretchEffect temp = effect;
1073 temp.sanitize();
Robert Carr6a160312021-05-17 12:08:20 -07001074 if (mDrawingState.stretchEffect == temp) {
John Reckcdb4ed72021-02-04 13:39:33 -05001075 return false;
1076 }
Robert Carr6a160312021-05-17 12:08:20 -07001077 mDrawingState.sequence++;
1078 mDrawingState.stretchEffect = temp;
1079 mDrawingState.modified = true;
John Reckcdb4ed72021-02-04 13:39:33 -05001080 setTransactionFlags(eTransactionNeeded);
1081 return true;
1082}
1083
John Reckc00c6692021-02-16 11:37:33 -05001084StretchEffect Layer::getStretchEffect() const {
1085 if (mDrawingState.stretchEffect.hasEffect()) {
1086 return mDrawingState.stretchEffect;
1087 }
1088
1089 sp<Layer> parent = getParent();
1090 if (parent != nullptr) {
1091 auto effect = parent->getStretchEffect();
1092 if (effect.hasEffect()) {
1093 // TODO(b/179047472): Map it? Or do we make the effect be in global space?
1094 return effect;
1095 }
1096 }
1097 return StretchEffect{};
1098}
1099
Ady Abraham60e42ea2020-03-09 19:17:31 -07001100void Layer::updateTreeHasFrameRateVote() {
1101 const auto traverseTree = [&](const LayerVector::Visitor& visitor) {
1102 auto parent = getParent();
1103 while (parent) {
1104 visitor(parent.get());
1105 parent = parent->getParent();
1106 }
1107
1108 traverse(LayerVector::StateSet::Current, visitor);
1109 };
1110
1111 // update parents and children about the vote
Ady Abraham59fd8ff2021-04-15 20:13:30 -07001112 // First traverse the tree and count how many layers has votes.
Ady Abraham60e42ea2020-03-09 19:17:31 -07001113 int layersWithVote = 0;
Ady Abraham44e9f3b2021-02-16 15:22:58 -08001114 traverseTree([&layersWithVote](Layer* layer) {
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001115 const auto layerVotedWithDefaultCompatibility =
Robert Carr6a160312021-05-17 12:08:20 -07001116 layer->mDrawingState.frameRate.rate.isValid() &&
1117 layer->mDrawingState.frameRate.type == FrameRateCompatibility::Default;
Ady Abraham414e8b52020-05-21 15:36:04 -07001118 const auto layerVotedWithNoVote =
Robert Carr6a160312021-05-17 12:08:20 -07001119 layer->mDrawingState.frameRate.type == FrameRateCompatibility::NoVote;
Ady Abrahamdd5bfa92021-01-07 17:56:08 -08001120 const auto layerVotedWithExactCompatibility =
Robert Carr6a160312021-05-17 12:08:20 -07001121 layer->mDrawingState.frameRate.type == FrameRateCompatibility::Exact;
Ady Abraham414e8b52020-05-21 15:36:04 -07001122
1123 // We do not count layers that are ExactOrMultiple for the same reason
1124 // we are allowing touch boost for those layers. See
1125 // RefreshRateConfigs::getBestRefreshRate for more details.
Ady Abrahamdd5bfa92021-01-07 17:56:08 -08001126 if (layerVotedWithDefaultCompatibility || layerVotedWithNoVote ||
1127 layerVotedWithExactCompatibility) {
Ady Abraham60e42ea2020-03-09 19:17:31 -07001128 layersWithVote++;
1129 }
1130 });
1131
Ady Abraham59fd8ff2021-04-15 20:13:30 -07001132 // Now we can update the tree frame rate vote for each layer in the tree
1133 const bool treeHasFrameRateVote = layersWithVote > 0;
Ady Abraham60e42ea2020-03-09 19:17:31 -07001134 bool transactionNeeded = false;
Robert Carr6a160312021-05-17 12:08:20 -07001135
Ady Abraham59fd8ff2021-04-15 20:13:30 -07001136 traverseTree([treeHasFrameRateVote, &transactionNeeded](Layer* layer) {
1137 transactionNeeded = layer->updateFrameRateForLayerTree(treeHasFrameRateVote);
Ady Abraham60e42ea2020-03-09 19:17:31 -07001138 });
1139
1140 if (transactionNeeded) {
1141 mFlinger->setTransactionFlags(eTraversalNeeded);
1142 }
1143}
1144
Ady Abraham71c437d2020-01-31 15:56:57 -08001145bool Layer::setFrameRate(FrameRate frameRate) {
Ana Krulec3803b8d2020-02-03 16:35:46 -08001146 if (!mFlinger->useFrameRateApi) {
1147 return false;
1148 }
Robert Carr6a160312021-05-17 12:08:20 -07001149 if (mDrawingState.frameRate == frameRate) {
Steven Thomas3172e202020-01-06 19:25:30 -08001150 return false;
1151 }
1152
Robert Carr6a160312021-05-17 12:08:20 -07001153 mDrawingState.sequence++;
1154 mDrawingState.frameRate = frameRate;
1155 mDrawingState.modified = true;
Ady Abraham60e42ea2020-03-09 19:17:31 -07001156
1157 updateTreeHasFrameRateVote();
1158
Steven Thomas3172e202020-01-06 19:25:30 -08001159 setTransactionFlags(eTransactionNeeded);
1160 return true;
1161}
1162
Adithya Srinivasanb9a7dab2021-01-14 23:49:46 +00001163void Layer::setFrameTimelineVsyncForBufferTransaction(const FrameTimelineInfo& info,
1164 nsecs_t postTime) {
Robert Carr6a160312021-05-17 12:08:20 -07001165 mDrawingState.postTime = postTime;
Adithya Srinivasanb9a7dab2021-01-14 23:49:46 +00001166
1167 // Check if one of the bufferlessSurfaceFramesTX contains the same vsyncId. This can happen if
1168 // there are two transactions with the same token, the first one without a buffer and the
1169 // second one with a buffer. We promote the bufferlessSurfaceFrame to a bufferSurfaceFrameTX
1170 // in that case.
Robert Carr6a160312021-05-17 12:08:20 -07001171 auto it = mDrawingState.bufferlessSurfaceFramesTX.find(info.vsyncId);
1172 if (it != mDrawingState.bufferlessSurfaceFramesTX.end()) {
Adithya Srinivasanb9a7dab2021-01-14 23:49:46 +00001173 // Promote the bufferlessSurfaceFrame to a bufferSurfaceFrameTX
Robert Carr6a160312021-05-17 12:08:20 -07001174 mDrawingState.bufferSurfaceFrameTX = it->second;
1175 mDrawingState.bufferlessSurfaceFramesTX.erase(it);
1176 mDrawingState.bufferSurfaceFrameTX->promoteToBuffer();
1177 mDrawingState.bufferSurfaceFrameTX->setActualQueueTime(postTime);
Adithya Srinivasanb9a7dab2021-01-14 23:49:46 +00001178 } else {
Robert Carr6a160312021-05-17 12:08:20 -07001179 mDrawingState.bufferSurfaceFrameTX =
Adithya Srinivasanb9a7dab2021-01-14 23:49:46 +00001180 createSurfaceFrameForBuffer(info, postTime, mTransactionName);
1181 }
1182}
1183
1184void Layer::setFrameTimelineVsyncForBufferlessTransaction(const FrameTimelineInfo& info,
1185 nsecs_t postTime) {
Robert Carr6a160312021-05-17 12:08:20 -07001186 mDrawingState.frameTimelineInfo = info;
1187 mDrawingState.postTime = postTime;
1188 mDrawingState.modified = true;
Ady Abraham22c7b5c2020-09-22 19:33:40 -07001189 setTransactionFlags(eTransactionNeeded);
Adithya Srinivasanb9a7dab2021-01-14 23:49:46 +00001190
Robert Carr6a160312021-05-17 12:08:20 -07001191 if (const auto& bufferSurfaceFrameTX = mDrawingState.bufferSurfaceFrameTX;
Adithya Srinivasanb9a7dab2021-01-14 23:49:46 +00001192 bufferSurfaceFrameTX != nullptr) {
1193 if (bufferSurfaceFrameTX->getToken() == info.vsyncId) {
1194 // BufferSurfaceFrame takes precedence over BufferlessSurfaceFrame. If the same token is
1195 // being used for BufferSurfaceFrame, don't create a new one.
1196 return;
1197 }
1198 }
1199 // For Transactions without a buffer, we create only one SurfaceFrame per vsyncId. If multiple
1200 // transactions use the same vsyncId, we just treat them as one SurfaceFrame (unless they are
1201 // targeting different vsyncs).
Robert Carr6a160312021-05-17 12:08:20 -07001202 auto it = mDrawingState.bufferlessSurfaceFramesTX.find(info.vsyncId);
1203 if (it == mDrawingState.bufferlessSurfaceFramesTX.end()) {
Adithya Srinivasanb9a7dab2021-01-14 23:49:46 +00001204 auto surfaceFrame = createSurfaceFrameForTransaction(info, postTime);
Robert Carr6a160312021-05-17 12:08:20 -07001205 mDrawingState.bufferlessSurfaceFramesTX[info.vsyncId] = surfaceFrame;
Adithya Srinivasanb9a7dab2021-01-14 23:49:46 +00001206 } else {
1207 if (it->second->getPresentState() == PresentState::Presented) {
1208 // If the SurfaceFrame was already presented, its safe to overwrite it since it must
1209 // have been from previous vsync.
1210 it->second = createSurfaceFrameForTransaction(info, postTime);
1211 }
1212 }
1213}
1214
1215void Layer::addSurfaceFrameDroppedForBuffer(
1216 std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame) {
Adithya Srinivasan061c14c2021-02-11 01:19:47 +00001217 surfaceFrame->setDropTime(systemTime());
Adithya Srinivasanb9a7dab2021-01-14 23:49:46 +00001218 surfaceFrame->setPresentState(PresentState::Dropped);
1219 mFlinger->mFrameTimeline->addSurfaceFrame(surfaceFrame);
1220}
1221
1222void Layer::addSurfaceFramePresentedForBuffer(
1223 std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame, nsecs_t acquireFenceTime,
1224 nsecs_t currentLatchTime) {
1225 surfaceFrame->setAcquireFenceTime(acquireFenceTime);
1226 surfaceFrame->setPresentState(PresentState::Presented, mLastLatchTime);
1227 mFlinger->mFrameTimeline->addSurfaceFrame(surfaceFrame);
1228 mLastLatchTime = currentLatchTime;
1229}
1230
1231std::shared_ptr<frametimeline::SurfaceFrame> Layer::createSurfaceFrameForTransaction(
1232 const FrameTimelineInfo& info, nsecs_t postTime) {
1233 auto surfaceFrame =
Alec Mouriadebf5c2021-01-05 12:57:36 -08001234 mFlinger->mFrameTimeline->createSurfaceFrameForToken(info, mOwnerPid, mOwnerUid,
1235 getSequence(), mName,
Adithya Srinivasan785addd2021-03-09 00:38:00 +00001236 mTransactionName,
Adithya Srinivasan58069dc2021-06-04 20:37:02 +00001237 /*isBuffer*/ false, getGameMode());
Adithya Srinivasanb9a7dab2021-01-14 23:49:46 +00001238 // For Transactions, the post time is considered to be both queue and acquire fence time.
1239 surfaceFrame->setActualQueueTime(postTime);
1240 surfaceFrame->setAcquireFenceTime(postTime);
Alec Mouri7d436ec2021-01-27 20:40:50 -08001241 const auto fps = mFlinger->mScheduler->getFrameRateOverride(getOwnerUid());
1242 if (fps) {
Alec Mouri819f6302021-02-12 15:37:21 -08001243 surfaceFrame->setRenderRate(*fps);
Alec Mouri7d436ec2021-01-27 20:40:50 -08001244 }
Adithya Srinivasanb9a7dab2021-01-14 23:49:46 +00001245 onSurfaceFrameCreated(surfaceFrame);
1246 return surfaceFrame;
1247}
1248
1249std::shared_ptr<frametimeline::SurfaceFrame> Layer::createSurfaceFrameForBuffer(
1250 const FrameTimelineInfo& info, nsecs_t queueTime, std::string debugName) {
1251 auto surfaceFrame =
Alec Mouriadebf5c2021-01-05 12:57:36 -08001252 mFlinger->mFrameTimeline->createSurfaceFrameForToken(info, mOwnerPid, mOwnerUid,
Adithya Srinivasan785addd2021-03-09 00:38:00 +00001253 getSequence(), mName, debugName,
Adithya Srinivasan58069dc2021-06-04 20:37:02 +00001254 /*isBuffer*/ true, getGameMode());
Adithya Srinivasanb9a7dab2021-01-14 23:49:46 +00001255 // For buffers, acquire fence time will set during latch.
1256 surfaceFrame->setActualQueueTime(queueTime);
Alec Mouri7d436ec2021-01-27 20:40:50 -08001257 const auto fps = mFlinger->mScheduler->getFrameRateOverride(getOwnerUid());
1258 if (fps) {
Alec Mouri819f6302021-02-12 15:37:21 -08001259 surfaceFrame->setRenderRate(*fps);
Alec Mouri7d436ec2021-01-27 20:40:50 -08001260 }
Adithya Srinivasanb9a7dab2021-01-14 23:49:46 +00001261 // TODO(b/178542907): Implement onSurfaceFrameCreated for BQLayer as well.
1262 onSurfaceFrameCreated(surfaceFrame);
1263 return surfaceFrame;
Ady Abraham74e17562020-08-24 18:18:19 -07001264}
1265
Ady Abraham59fd8ff2021-04-15 20:13:30 -07001266bool Layer::updateFrameRateForLayerTree(bool treeHasFrameRateVote) {
Robert Carr6a160312021-05-17 12:08:20 -07001267 const auto updateDrawingState = [&](FrameRate frameRate) {
1268 if (mDrawingState.frameRateForLayerTree == frameRate) {
Ady Abraham59fd8ff2021-04-15 20:13:30 -07001269 return false;
1270 }
Robert Carr6a160312021-05-17 12:08:20 -07001271
1272 mDrawingState.frameRateForLayerTree = frameRate;
1273 mDrawingState.sequence++;
1274 mDrawingState.modified = true;
Ady Abraham59fd8ff2021-04-15 20:13:30 -07001275 setTransactionFlags(eTransactionNeeded);
Robert Carr6a160312021-05-17 12:08:20 -07001276
1277 mFlinger->mScheduler->recordLayerHistory(this, systemTime(),
1278 LayerHistory::LayerUpdateType::SetFrameRate);
1279
Ady Abraham59fd8ff2021-04-15 20:13:30 -07001280 return true;
1281 };
1282
Robert Carr6a160312021-05-17 12:08:20 -07001283 const auto frameRate = mDrawingState.frameRate;
Marin Shalamanove8a663d2020-11-24 17:48:00 +01001284 if (frameRate.rate.isValid() || frameRate.type == FrameRateCompatibility::NoVote) {
Robert Carr6a160312021-05-17 12:08:20 -07001285 return updateDrawingState(frameRate);
Ady Abraham60e42ea2020-03-09 19:17:31 -07001286 }
1287
Ady Abrahamf467f892020-07-31 16:01:53 -07001288 // This layer doesn't have a frame rate. Check if its ancestors have a vote
Ady Abraham59fd8ff2021-04-15 20:13:30 -07001289 for (sp<Layer> parent = getParent(); parent; parent = parent->getParent()) {
Robert Carr6a160312021-05-17 12:08:20 -07001290 if (parent->mDrawingState.frameRate.rate.isValid()) {
1291 return updateDrawingState(parent->mDrawingState.frameRate);
Ady Abrahamf467f892020-07-31 16:01:53 -07001292 }
1293 }
1294
1295 // This layer and its ancestors don't have a frame rate. If one of successors
1296 // has a vote, return a NoVote for successors to set the vote
Ady Abraham59fd8ff2021-04-15 20:13:30 -07001297 if (treeHasFrameRateVote) {
Robert Carr6a160312021-05-17 12:08:20 -07001298 return updateDrawingState(FrameRate(Fps(0.0f), FrameRateCompatibility::NoVote));
Ady Abraham60e42ea2020-03-09 19:17:31 -07001299 }
1300
Robert Carr6a160312021-05-17 12:08:20 -07001301 return updateDrawingState(frameRate);
Steven Thomas3172e202020-01-06 19:25:30 -08001302}
1303
Ady Abraham59fd8ff2021-04-15 20:13:30 -07001304Layer::FrameRate Layer::getFrameRateForLayerTree() const {
1305 return getDrawingState().frameRateForLayerTree;
1306}
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001307
Robert Carr1f0a16a2016-10-24 16:27:39 -07001308bool Layer::isHiddenByPolicy() const {
Lloyd Pique0449b0f2018-12-20 16:23:45 -08001309 const State& s(mDrawingState);
Chia-I Wue41dbe62017-06-13 14:10:56 -07001310 const auto& parent = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001311 if (parent != nullptr && parent->isHiddenByPolicy()) {
1312 return true;
1313 }
Robert Carr1c5481e2019-07-01 14:42:27 -07001314 if (usingRelativeZ(LayerVector::StateSet::Drawing)) {
1315 auto zOrderRelativeOf = mDrawingState.zOrderRelativeOf.promote();
1316 if (zOrderRelativeOf != nullptr) {
1317 if (zOrderRelativeOf->isHiddenByPolicy()) {
1318 return true;
1319 }
1320 }
1321 }
Robert Carr1f0a16a2016-10-24 16:27:39 -07001322 return s.flags & layer_state_t::eLayerHidden;
1323}
1324
David Sodman41fdfc92017-11-06 16:09:56 -08001325uint32_t Layer::getEffectiveUsage(uint32_t usage) const {
Mathias Agopiana67932f2011-04-20 14:20:59 -07001326 // TODO: should we do something special if mSecure is set?
1327 if (mProtectedByApp) {
1328 // need a hardware-protected path to external video sink
1329 usage |= GraphicBuffer::USAGE_PROTECTED;
Jamie Gennis54cc83e2010-11-02 11:51:32 -07001330 }
Riley Andrews03414a12014-07-01 14:22:59 -07001331 if (mPotentialCursor) {
1332 usage |= GraphicBuffer::USAGE_CURSOR;
1333 }
Jamie Gennis3599bf22011-08-10 11:48:07 -07001334 usage |= GraphicBuffer::USAGE_HW_COMPOSER;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001335 return usage;
Mathias Agopianb5b7f262010-05-07 15:58:44 -07001336}
1337
Dominik Laskowskib7251f42020-04-20 17:42:59 -07001338void Layer::updateTransformHint(ui::Transform::RotationFlags transformHint) {
1339 if (mFlinger->mDebugDisableTransformHint || transformHint & ui::Transform::ROT_INVALID) {
1340 transformHint = ui::Transform::ROT_0;
Mathias Agopiana4583642011-08-23 18:03:18 -07001341 }
Dominik Laskowskib7251f42020-04-20 17:42:59 -07001342
Vishnu Nair6213bd92020-05-08 17:42:25 -07001343 setTransformHint(transformHint);
Mathias Agopiana4583642011-08-23 18:03:18 -07001344}
1345
Mathias Agopian13127d82013-03-05 17:47:11 -08001346// ----------------------------------------------------------------------------
1347// debugging
1348// ----------------------------------------------------------------------------
1349
Marissa Wall61c58622018-07-18 10:12:20 -07001350// TODO(marissaw): add new layer state info to layer debugging
Dominik Laskowskib7251f42020-04-20 17:42:59 -07001351LayerDebugInfo Layer::getLayerDebugInfo(const DisplayDevice* display) const {
Dominik Laskowski87a07e42019-10-10 20:38:02 -07001352 using namespace std::string_literals;
1353
Kalle Raitaa099a242017-01-11 11:17:29 -08001354 LayerDebugInfo info;
Alec Mourib416efd2018-09-06 21:01:59 +00001355 const State& ds = getDrawingState();
Kalle Raitaa099a242017-01-11 11:17:29 -08001356 info.mName = getName();
Vishnu Nair43bccf82020-06-05 10:53:37 -07001357 sp<Layer> parent = mDrawingParent.promote();
Dominik Laskowski87a07e42019-10-10 20:38:02 -07001358 info.mParentName = parent ? parent->getName() : "none"s;
chaviw8a01fa42019-08-19 12:39:31 -07001359 info.mType = getType();
Marissa Wallf58c14b2018-07-24 10:50:43 -07001360 info.mTransparentRegion = ds.activeTransparentRegion_legacy;
Lloyd Piquea2468662019-03-07 21:31:06 -08001361
Dominik Laskowskib7251f42020-04-20 17:42:59 -07001362 info.mVisibleRegion = getVisibleRegion(display);
Kalle Raitaa099a242017-01-11 11:17:29 -08001363 info.mSurfaceDamageRegion = surfaceDamageRegion;
Lloyd Pique0449b0f2018-12-20 16:23:45 -08001364 info.mLayerStack = getLayerStack();
chaviw4e765532021-04-30 12:11:39 -05001365 info.mX = ds.transform.tx();
1366 info.mY = ds.transform.ty();
Kalle Raitaa099a242017-01-11 11:17:29 -08001367 info.mZ = ds.z;
chaviw4e765532021-04-30 12:11:39 -05001368 info.mWidth = ds.width;
1369 info.mHeight = ds.height;
chaviw25714502021-02-11 10:01:08 -08001370 info.mCrop = ds.crop;
chaviw13fdc492017-06-27 12:40:18 -07001371 info.mColor = ds.color;
Kalle Raitaa099a242017-01-11 11:17:29 -08001372 info.mFlags = ds.flags;
1373 info.mPixelFormat = getPixelFormat();
chaviw4244e032019-09-04 11:27:49 -07001374 info.mDataSpace = static_cast<android_dataspace>(getDataSpace());
chaviw4e765532021-04-30 12:11:39 -05001375 info.mMatrix[0][0] = ds.transform[0][0];
1376 info.mMatrix[0][1] = ds.transform[0][1];
1377 info.mMatrix[1][0] = ds.transform[1][0];
1378 info.mMatrix[1][1] = ds.transform[1][1];
Kalle Raitaa099a242017-01-11 11:17:29 -08001379 {
chaviwd62d3062019-09-04 14:48:02 -07001380 sp<const GraphicBuffer> buffer = getBuffer();
David Sodman5b4cffc2017-11-23 13:20:29 -08001381 if (buffer != 0) {
1382 info.mActiveBufferWidth = buffer->getWidth();
1383 info.mActiveBufferHeight = buffer->getHeight();
1384 info.mActiveBufferStride = buffer->getStride();
1385 info.mActiveBufferFormat = buffer->format;
Kalle Raitaa099a242017-01-11 11:17:29 -08001386 } else {
1387 info.mActiveBufferWidth = 0;
1388 info.mActiveBufferHeight = 0;
1389 info.mActiveBufferStride = 0;
1390 info.mActiveBufferFormat = 0;
1391 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001392 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001393 info.mNumQueuedFrames = getQueuedFrameCount();
1394 info.mRefreshPending = isBufferLatched();
1395 info.mIsOpaque = isOpaque(ds);
1396 info.mContentDirty = contentDirty;
John Reckc00c6692021-02-16 11:37:33 -05001397 info.mStretchEffect = getStretchEffect();
Kalle Raitaa099a242017-01-11 11:17:29 -08001398 return info;
Mathias Agopian13127d82013-03-05 17:47:11 -08001399}
Chia-I Wu83ce7c12017-10-19 15:18:55 -07001400
Yiwei Zhang5434a782018-12-05 18:06:32 -08001401void Layer::miniDumpHeader(std::string& result) {
Marin Shalamanov1876e2e2020-12-04 13:23:59 +01001402 result.append(kDumpTableRowLength, '-');
1403 result.append("\n");
Dan Stozae22aec72016-08-01 13:20:59 -07001404 result.append(" Layer name\n");
1405 result.append(" Z | ");
Ady Abraham8f1ee7f2019-04-05 10:32:50 -07001406 result.append(" Window Type | ");
Dan Stozae22aec72016-08-01 13:20:59 -07001407 result.append(" Comp Type | ");
Yichi Chen6ca35192018-05-29 12:20:43 +08001408 result.append(" Transform | ");
Dan Stozae22aec72016-08-01 13:20:59 -07001409 result.append(" Disp Frame (LTRB) | ");
Ady Abrahambe23e6a2020-05-04 14:51:16 -07001410 result.append(" Source Crop (LTRB) | ");
Marin Shalamanov1876e2e2020-12-04 13:23:59 +01001411 result.append(" Frame Rate (Explicit) (Seamlessness) [Focused]\n");
1412 result.append(kDumpTableRowLength, '-');
1413 result.append("\n");
Ady Abrahambe23e6a2020-05-04 14:51:16 -07001414}
1415
1416std::string Layer::frameRateCompatibilityString(Layer::FrameRateCompatibility compatibility) {
1417 switch (compatibility) {
1418 case FrameRateCompatibility::Default:
1419 return "Default";
1420 case FrameRateCompatibility::ExactOrMultiple:
1421 return "ExactOrMultiple";
1422 case FrameRateCompatibility::NoVote:
1423 return "NoVote";
Ady Abrahamdd5bfa92021-01-07 17:56:08 -08001424 case FrameRateCompatibility::Exact:
1425 return "Exact";
Ady Abrahambe23e6a2020-05-04 14:51:16 -07001426 }
Dan Stozae22aec72016-08-01 13:20:59 -07001427}
1428
Dominik Laskowskib7251f42020-04-20 17:42:59 -07001429void Layer::miniDump(std::string& result, const DisplayDevice& display) const {
1430 const auto outputLayer = findOutputLayerForDisplay(&display);
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001431 if (!outputLayer) {
Dan Stozae22aec72016-08-01 13:20:59 -07001432 return;
1433 }
1434
Yiwei Zhang5434a782018-12-05 18:06:32 -08001435 std::string name;
Dan Stozae22aec72016-08-01 13:20:59 -07001436 if (mName.length() > 77) {
1437 std::string shortened;
Dominik Laskowski87a07e42019-10-10 20:38:02 -07001438 shortened.append(mName, 0, 36);
Dan Stozae22aec72016-08-01 13:20:59 -07001439 shortened.append("[...]");
Dominik Laskowski87a07e42019-10-10 20:38:02 -07001440 shortened.append(mName, mName.length() - 36);
1441 name = std::move(shortened);
Dan Stozae22aec72016-08-01 13:20:59 -07001442 } else {
Dominik Laskowski87a07e42019-10-10 20:38:02 -07001443 name = mName;
Dan Stozae22aec72016-08-01 13:20:59 -07001444 }
1445
Yiwei Zhang5434a782018-12-05 18:06:32 -08001446 StringAppendF(&result, " %s\n", name.c_str());
Dan Stozae22aec72016-08-01 13:20:59 -07001447
Alec Mourib416efd2018-09-06 21:01:59 +00001448 const State& layerState(getDrawingState());
Lloyd Piquede196652020-01-22 17:29:58 -08001449 const auto& outputLayerState = outputLayer->getState();
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001450
Chia-I Wu1e043612018-03-01 09:45:09 -08001451 if (layerState.zOrderRelativeOf != nullptr || mDrawingParent != nullptr) {
Yiwei Zhang5434a782018-12-05 18:06:32 -08001452 StringAppendF(&result, " rel %6d | ", layerState.z);
Chia-I Wu1e043612018-03-01 09:45:09 -08001453 } else {
Yiwei Zhang5434a782018-12-05 18:06:32 -08001454 StringAppendF(&result, " %10d | ", layerState.z);
Chia-I Wu1e043612018-03-01 09:45:09 -08001455 }
Ady Abraham8f1ee7f2019-04-05 10:32:50 -07001456 StringAppendF(&result, " %10d | ", mWindowType);
Dominik Laskowskib7251f42020-04-20 17:42:59 -07001457 StringAppendF(&result, "%10s | ", toString(getCompositionType(display)).c_str());
Lloyd Piquede196652020-01-22 17:29:58 -08001458 StringAppendF(&result, "%10s | ", toString(outputLayerState.bufferTransform).c_str());
1459 const Rect& frame = outputLayerState.displayFrame;
Yiwei Zhang5434a782018-12-05 18:06:32 -08001460 StringAppendF(&result, "%4d %4d %4d %4d | ", frame.left, frame.top, frame.right, frame.bottom);
Lloyd Piquede196652020-01-22 17:29:58 -08001461 const FloatRect& crop = outputLayerState.sourceCrop;
Ady Abrahambe23e6a2020-05-04 14:51:16 -07001462 StringAppendF(&result, "%6.1f %6.1f %6.1f %6.1f | ", crop.left, crop.top, crop.right,
Yiwei Zhang5434a782018-12-05 18:06:32 -08001463 crop.bottom);
Ady Abrahamf467f892020-07-31 16:01:53 -07001464 const auto frameRate = getFrameRateForLayerTree();
1465 if (frameRate.rate.isValid() || frameRate.type != FrameRateCompatibility::Default) {
1466 StringAppendF(&result, "%s %15s %17s", to_string(frameRate.rate).c_str(),
1467 frameRateCompatibilityString(frameRate.type).c_str(),
1468 toString(frameRate.seamlessness).c_str());
Ady Abrahambe23e6a2020-05-04 14:51:16 -07001469 } else {
Marin Shalamanov1876e2e2020-12-04 13:23:59 +01001470 result.append(41, ' ');
Ady Abrahambe23e6a2020-05-04 14:51:16 -07001471 }
Dan Stozae22aec72016-08-01 13:20:59 -07001472
Ady Abrahamaae5ed52020-06-26 09:32:43 -07001473 const auto focused = isLayerFocusedBasedOnPriority(getFrameRateSelectionPriority());
1474 StringAppendF(&result, " [%s]\n", focused ? "*" : " ");
1475
Marin Shalamanov1876e2e2020-12-04 13:23:59 +01001476 result.append(kDumpTableRowLength, '-');
1477 result.append("\n");
Dan Stozae22aec72016-08-01 13:20:59 -07001478}
Dan Stozae22aec72016-08-01 13:20:59 -07001479
Yiwei Zhang5434a782018-12-05 18:06:32 -08001480void Layer::dumpFrameStats(std::string& result) const {
Svetoslavd85084b2014-03-20 10:28:31 -07001481 mFrameTracker.dumpStats(result);
Mathias Agopian13127d82013-03-05 17:47:11 -08001482}
1483
Svetoslavd85084b2014-03-20 10:28:31 -07001484void Layer::clearFrameStats() {
1485 mFrameTracker.clearStats();
Mathias Agopian13127d82013-03-05 17:47:11 -08001486}
1487
Jamie Gennis6547ff42013-07-16 20:12:42 -07001488void Layer::logFrameStats() {
1489 mFrameTracker.logAndResetStats(mName);
1490}
1491
Svetoslavd85084b2014-03-20 10:28:31 -07001492void Layer::getFrameStats(FrameStats* outStats) const {
1493 mFrameTracker.getStats(outStats);
1494}
1495
Yiwei Zhang5434a782018-12-05 18:06:32 -08001496void Layer::dumpFrameEvents(std::string& result) {
Dominik Laskowski87a07e42019-10-10 20:38:02 -07001497 StringAppendF(&result, "- Layer %s (%s, %p)\n", getName().c_str(), getType(), this);
Brian Andersond6927fb2016-07-23 23:37:30 -07001498 Mutex::Autolock lock(mFrameEventHistoryMutex);
1499 mFrameEventHistory.checkFencesForCompletion();
1500 mFrameEventHistory.dump(result);
1501}
Pablo Ceballos40845df2016-01-25 17:41:15 -08001502
Vishnu Nair0f085c62019-08-30 08:49:12 -07001503void Layer::dumpCallingUidPid(std::string& result) const {
chaviw250bcbb2020-08-05 11:17:54 -07001504 StringAppendF(&result, "Layer %s (%s) callingPid:%d callingUid:%d ownerUid:%d\n",
1505 getName().c_str(), getType(), mCallingPid, mCallingUid, mOwnerUid);
Vishnu Nair0f085c62019-08-30 08:49:12 -07001506}
1507
Brian Anderson5ea5e592016-12-01 16:54:33 -08001508void Layer::onDisconnect() {
1509 Mutex::Autolock lock(mFrameEventHistoryMutex);
1510 mFrameEventHistory.onDisconnect();
Yiwei Zhang1a88c402019-11-18 10:43:58 -08001511 const int32_t layerId = getSequence();
1512 mFlinger->mTimeStats->onDestroy(layerId);
1513 mFlinger->mFrameTracer->onDestroy(layerId);
Brian Anderson5ea5e592016-12-01 16:54:33 -08001514}
1515
Brian Anderson3890c392016-07-25 12:48:08 -07001516void Layer::addAndGetFrameTimestamps(const NewFrameEventsEntry* newTimestamps,
David Sodman41fdfc92017-11-06 16:09:56 -08001517 FrameEventHistoryDelta* outDelta) {
Yiwei Zhangfaf3ded2018-05-02 17:37:17 -07001518 if (newTimestamps) {
Yiwei Zhang7e666a52018-11-15 13:33:42 -08001519 mFlinger->mTimeStats->setPostTime(getSequence(), newTimestamps->frameNumber,
Adithya Srinivasan58069dc2021-06-04 20:37:02 +00001520 getName().c_str(), mOwnerUid, newTimestamps->postedTime,
1521 getGameMode());
Yiwei Zhang487340f2019-11-18 17:42:12 -08001522 mFlinger->mTimeStats->setAcquireFence(getSequence(), newTimestamps->frameNumber,
1523 newTimestamps->acquireFence);
Yiwei Zhangfaf3ded2018-05-02 17:37:17 -07001524 }
1525
Brian Andersond6927fb2016-07-23 23:37:30 -07001526 Mutex::Autolock lock(mFrameEventHistoryMutex);
1527 if (newTimestamps) {
Brian Andersonfbc80ae2017-05-26 16:23:54 -07001528 // If there are any unsignaled fences in the aquire timeline at this
1529 // point, the previously queued frame hasn't been latched yet. Go ahead
1530 // and try to get the signal time here so the syscall is taken out of
1531 // the main thread's critical path.
1532 mAcquireTimeline.updateSignalTimes();
1533 // Push the new fence after updating since it's likely still pending.
Brian Anderson3d4039d2016-09-23 16:31:30 -07001534 mAcquireTimeline.push(newTimestamps->acquireFence);
Brian Andersond6927fb2016-07-23 23:37:30 -07001535 mFrameEventHistory.addQueue(*newTimestamps);
1536 }
1537
Brian Anderson3890c392016-07-25 12:48:08 -07001538 if (outDelta) {
1539 mFrameEventHistory.getAndResetDelta(outDelta);
Brian Andersond6927fb2016-07-23 23:37:30 -07001540 }
Pablo Ceballos40845df2016-01-25 17:41:15 -08001541}
Dan Stozae77c7662016-05-13 11:37:28 -07001542
Chia-I Wu98f1c102017-05-30 14:54:08 -07001543size_t Layer::getChildrenCount() const {
1544 size_t count = 0;
1545 for (const sp<Layer>& child : mCurrentChildren) {
1546 count += 1 + child->getChildrenCount();
1547 }
1548 return count;
1549}
1550
Adithya Srinivasanac977e62021-05-21 22:50:56 +00001551void Layer::setGameModeForTree(int parentGameMode) {
1552 int gameMode = parentGameMode;
Robert Carr6a160312021-05-17 12:08:20 -07001553 auto& currentState = getDrawingState();
Adithya Srinivasanac977e62021-05-21 22:50:56 +00001554 if (currentState.metadata.has(METADATA_GAME_MODE)) {
1555 gameMode = currentState.metadata.getInt32(METADATA_GAME_MODE, 0);
1556 }
1557 setGameMode(gameMode);
1558 for (const sp<Layer>& child : mCurrentChildren) {
1559 child->setGameModeForTree(gameMode);
1560 }
1561}
1562
Robert Carr1f0a16a2016-10-24 16:27:39 -07001563void Layer::addChild(const sp<Layer>& layer) {
Robert Carre450fb52021-06-11 13:21:09 -07001564 mFlinger->mSomeChildrenChanged = true;
Robert Carr7f2ed8b2019-02-07 14:45:11 -08001565 setTransactionFlags(eTransactionNeeded);
Robert Carr1323c952019-01-28 18:13:27 -08001566
Robert Carr1f0a16a2016-10-24 16:27:39 -07001567 mCurrentChildren.add(layer);
1568 layer->setParent(this);
Adithya Srinivasanac977e62021-05-21 22:50:56 +00001569 layer->setGameModeForTree(mGameMode);
Ady Abraham60e42ea2020-03-09 19:17:31 -07001570 updateTreeHasFrameRateVote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001571}
1572
1573ssize_t Layer::removeChild(const sp<Layer>& layer) {
Robert Carre450fb52021-06-11 13:21:09 -07001574 mFlinger->mSomeChildrenChanged = true;
Robert Carr7f2ed8b2019-02-07 14:45:11 -08001575 setTransactionFlags(eTransactionNeeded);
Robert Carr6fb1a7e2018-12-11 12:07:25 -08001576
Robert Carr1323c952019-01-28 18:13:27 -08001577 layer->setParent(nullptr);
Ady Abraham60e42ea2020-03-09 19:17:31 -07001578 const auto removeResult = mCurrentChildren.remove(layer);
1579
1580 updateTreeHasFrameRateVote();
Adithya Srinivasanac977e62021-05-21 22:50:56 +00001581 layer->setGameModeForTree(0);
Ady Abraham60e42ea2020-03-09 19:17:31 -07001582 layer->updateTreeHasFrameRateVote();
1583
1584 return removeResult;
1585}
1586
Robert Carr15eae092018-03-23 13:43:53 -07001587void Layer::setChildrenDrawingParent(const sp<Layer>& newParent) {
Robert Carr578038f2018-03-09 12:25:24 -08001588 for (const sp<Layer>& child : mDrawingChildren) {
1589 child->mDrawingParent = newParent;
Vishnu Nair6bdec7d2021-05-10 15:01:13 -07001590 child->computeBounds(newParent->mBounds, newParent->mEffectiveTransform,
Vishnu Nairc97b8db2019-10-29 18:19:35 -07001591 newParent->mEffectiveShadowRadius);
Robert Carr578038f2018-03-09 12:25:24 -08001592 }
1593}
1594
chaviwf1961f72017-09-18 16:41:07 -07001595bool Layer::reparent(const sp<IBinder>& newParentHandle) {
Robert Carr54cf5b12019-01-25 14:02:28 -08001596 sp<Layer> newParent;
1597 if (newParentHandle != nullptr) {
1598 auto handle = static_cast<Handle*>(newParentHandle.get());
1599 newParent = handle->owner.promote();
1600 if (newParent == nullptr) {
1601 ALOGE("Unable to promote Layer handle");
1602 return false;
1603 }
1604 if (newParent == this) {
1605 ALOGE("Invalid attempt to reparent Layer (%s) to itself", getName().c_str());
1606 return false;
1607 }
1608 }
1609
chaviwf1961f72017-09-18 16:41:07 -07001610 sp<Layer> parent = getParent();
1611 if (parent != nullptr) {
1612 parent->removeChild(this);
chaviw06178942017-07-27 10:25:59 -07001613 }
1614
Robert Carr6fb1a7e2018-12-11 12:07:25 -08001615 if (newParentHandle != nullptr) {
Robert Carr6fb1a7e2018-12-11 12:07:25 -08001616 newParent->addChild(this);
1617 if (!newParent->isRemovedFromCurrentState()) {
1618 addToCurrentState();
1619 } else {
1620 onRemovedFromCurrentState();
1621 }
Robert Carr6fb1a7e2018-12-11 12:07:25 -08001622 } else {
1623 onRemovedFromCurrentState();
chaviw61626f22018-11-15 16:26:27 -08001624 }
1625
chaviw06178942017-07-27 10:25:59 -07001626 return true;
1627}
1628
Peiyong Lind3788632018-09-18 16:01:31 -07001629bool Layer::setColorTransform(const mat4& matrix) {
Peiyong Lin747321c2018-10-01 10:03:11 -07001630 static const mat4 identityMatrix = mat4();
1631
Robert Carr6a160312021-05-17 12:08:20 -07001632 if (mDrawingState.colorTransform == matrix) {
Peiyong Lind3788632018-09-18 16:01:31 -07001633 return false;
1634 }
Robert Carr6a160312021-05-17 12:08:20 -07001635 ++mDrawingState.sequence;
1636 mDrawingState.colorTransform = matrix;
1637 mDrawingState.hasColorTransform = matrix != identityMatrix;
1638 mDrawingState.modified = true;
Peiyong Lind3788632018-09-18 16:01:31 -07001639 setTransactionFlags(eTransactionNeeded);
1640 return true;
1641}
1642
chaviwf66724d2018-11-28 16:35:21 -08001643mat4 Layer::getColorTransform() const {
1644 mat4 colorTransform = mat4(getDrawingState().colorTransform);
1645 if (sp<Layer> parent = mDrawingParent.promote(); parent != nullptr) {
1646 colorTransform = parent->getColorTransform() * colorTransform;
1647 }
1648 return colorTransform;
Peiyong Lind3788632018-09-18 16:01:31 -07001649}
1650
1651bool Layer::hasColorTransform() const {
chaviwf66724d2018-11-28 16:35:21 -08001652 bool hasColorTransform = getDrawingState().hasColorTransform;
1653 if (sp<Layer> parent = mDrawingParent.promote(); parent != nullptr) {
1654 hasColorTransform = hasColorTransform || parent->hasColorTransform();
1655 }
1656 return hasColorTransform;
Peiyong Lind3788632018-09-18 16:01:31 -07001657}
1658
Chia-I Wu11481472018-05-04 10:43:19 -07001659bool Layer::isLegacyDataSpace() const {
1660 // return true when no higher bits are set
chaviw4244e032019-09-04 11:27:49 -07001661 return !(getDataSpace() &
1662 (ui::Dataspace::STANDARD_MASK | ui::Dataspace::TRANSFER_MASK |
1663 ui::Dataspace::RANGE_MASK));
Peiyong Lindd9b2ae2018-03-01 16:22:45 -08001664}
1665
Robert Carr1f0a16a2016-10-24 16:27:39 -07001666void Layer::setParent(const sp<Layer>& layer) {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001667 mCurrentParent = layer;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001668}
1669
Robert Carr6a160312021-05-17 12:08:20 -07001670int32_t Layer::getZ(LayerVector::StateSet) const {
1671 return mDrawingState.z;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001672}
1673
Robert Carr1c5481e2019-07-01 14:42:27 -07001674bool Layer::usingRelativeZ(LayerVector::StateSet stateSet) const {
Robert Carr29abff82017-12-04 13:51:20 -08001675 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
Robert Carr6a160312021-05-17 12:08:20 -07001676 const State& state = useDrawing ? mDrawingState : mDrawingState;
chaviwe5ac40f2019-09-24 16:36:55 -07001677 return state.isRelativeOf;
Robert Carr29abff82017-12-04 13:51:20 -08001678}
1679
David Sodman41fdfc92017-11-06 16:09:56 -08001680__attribute__((no_sanitize("unsigned-integer-overflow"))) LayerVector Layer::makeTraversalList(
Robert Carr29abff82017-12-04 13:51:20 -08001681 LayerVector::StateSet stateSet, bool* outSkipRelativeZUsers) {
Dan Stoza412903f2017-04-27 13:42:17 -07001682 LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid,
1683 "makeTraversalList received invalid stateSet");
1684 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1685 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
Robert Carr6a160312021-05-17 12:08:20 -07001686 const State& state = useDrawing ? mDrawingState : mDrawingState;
Dan Stoza412903f2017-04-27 13:42:17 -07001687
Robert Carr29abff82017-12-04 13:51:20 -08001688 if (state.zOrderRelatives.size() == 0) {
1689 *outSkipRelativeZUsers = true;
1690 return children;
1691 }
1692
chaviwfd462612018-05-31 16:11:27 -07001693 LayerVector traverse(stateSet);
Dan Stoza412903f2017-04-27 13:42:17 -07001694 for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
Robert Carrdb66e622017-04-10 16:55:57 -07001695 sp<Layer> strongRelative = weakRelative.promote();
1696 if (strongRelative != nullptr) {
1697 traverse.add(strongRelative);
Robert Carrdb66e622017-04-10 16:55:57 -07001698 }
1699 }
1700
Dan Stoza412903f2017-04-27 13:42:17 -07001701 for (const sp<Layer>& child : children) {
chaviwe5ac40f2019-09-24 16:36:55 -07001702 if (child->usingRelativeZ(stateSet)) {
Robert Carr503c7042017-09-27 15:06:08 -07001703 continue;
1704 }
Robert Carrdb66e622017-04-10 16:55:57 -07001705 traverse.add(child);
1706 }
1707
1708 return traverse;
1709}
1710
Robert Carr1f0a16a2016-10-24 16:27:39 -07001711/**
Robert Carrdb66e622017-04-10 16:55:57 -07001712 * Negatively signed relatives are before 'this' in Z-order.
Robert Carr1f0a16a2016-10-24 16:27:39 -07001713 */
Dan Stoza412903f2017-04-27 13:42:17 -07001714void Layer::traverseInZOrder(LayerVector::StateSet stateSet, const LayerVector::Visitor& visitor) {
Robert Carr29abff82017-12-04 13:51:20 -08001715 // In the case we have other layers who are using a relative Z to us, makeTraversalList will
1716 // produce a new list for traversing, including our relatives, and not including our children
1717 // who are relatives of another surface. In the case that there are no relative Z,
1718 // makeTraversalList returns our children directly to avoid significant overhead.
1719 // However in this case we need to take the responsibility for filtering children which
1720 // are relatives of another surface here.
1721 bool skipRelativeZUsers = false;
1722 const LayerVector list = makeTraversalList(stateSet, &skipRelativeZUsers);
Robert Carrdb66e622017-04-10 16:55:57 -07001723
Robert Carr1f0a16a2016-10-24 16:27:39 -07001724 size_t i = 0;
Robert Carrdb66e622017-04-10 16:55:57 -07001725 for (; i < list.size(); i++) {
1726 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001727 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1728 continue;
1729 }
1730
chaviw301b1d82019-11-06 13:15:09 -08001731 if (relative->getZ(stateSet) >= 0) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001732 break;
Robert Carrdb66e622017-04-10 16:55:57 -07001733 }
Dan Stoza412903f2017-04-27 13:42:17 -07001734 relative->traverseInZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001735 }
Robert Carr29abff82017-12-04 13:51:20 -08001736
Dan Stoza412903f2017-04-27 13:42:17 -07001737 visitor(this);
Robert Carrdb66e622017-04-10 16:55:57 -07001738 for (; i < list.size(); i++) {
1739 const auto& relative = list[i];
Lloyd Pique0449b0f2018-12-20 16:23:45 -08001740
Robert Carr29abff82017-12-04 13:51:20 -08001741 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1742 continue;
1743 }
Dan Stoza412903f2017-04-27 13:42:17 -07001744 relative->traverseInZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001745 }
1746}
1747
1748/**
Robert Carrdb66e622017-04-10 16:55:57 -07001749 * Positively signed relatives are before 'this' in reverse Z-order.
Robert Carr1f0a16a2016-10-24 16:27:39 -07001750 */
Dan Stoza412903f2017-04-27 13:42:17 -07001751void Layer::traverseInReverseZOrder(LayerVector::StateSet stateSet,
1752 const LayerVector::Visitor& visitor) {
Robert Carr29abff82017-12-04 13:51:20 -08001753 // See traverseInZOrder for documentation.
1754 bool skipRelativeZUsers = false;
1755 LayerVector list = makeTraversalList(stateSet, &skipRelativeZUsers);
Robert Carrdb66e622017-04-10 16:55:57 -07001756
Robert Carr1f0a16a2016-10-24 16:27:39 -07001757 int32_t i = 0;
Joel Galensonbf324992017-11-06 11:04:12 -08001758 for (i = int32_t(list.size()) - 1; i >= 0; i--) {
Robert Carrdb66e622017-04-10 16:55:57 -07001759 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001760
1761 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1762 continue;
1763 }
1764
chaviw301b1d82019-11-06 13:15:09 -08001765 if (relative->getZ(stateSet) < 0) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001766 break;
1767 }
Dan Stoza412903f2017-04-27 13:42:17 -07001768 relative->traverseInReverseZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001769 }
Dan Stoza412903f2017-04-27 13:42:17 -07001770 visitor(this);
David Sodman41fdfc92017-11-06 16:09:56 -08001771 for (; i >= 0; i--) {
Robert Carrdb66e622017-04-10 16:55:57 -07001772 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001773
1774 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1775 continue;
1776 }
1777
Dan Stoza412903f2017-04-27 13:42:17 -07001778 relative->traverseInReverseZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001779 }
1780}
1781
Edgar Arriaga844fa672020-01-16 14:21:42 -08001782void Layer::traverse(LayerVector::StateSet state, const LayerVector::Visitor& visitor) {
1783 visitor(this);
1784 const LayerVector& children =
Robert Carr6a160312021-05-17 12:08:20 -07001785 state == LayerVector::StateSet::Drawing ? mDrawingChildren : mCurrentChildren;
Edgar Arriaga844fa672020-01-16 14:21:42 -08001786 for (const sp<Layer>& child : children) {
1787 child->traverse(state, visitor);
1788 }
1789}
1790
chaviw4b129c22018-04-09 16:19:43 -07001791LayerVector Layer::makeChildrenTraversalList(LayerVector::StateSet stateSet,
1792 const std::vector<Layer*>& layersInTree) {
1793 LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid,
1794 "makeTraversalList received invalid stateSet");
chaviwa76b2712017-09-20 12:02:26 -07001795 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1796 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
Robert Carr6a160312021-05-17 12:08:20 -07001797 const State& state = useDrawing ? mDrawingState : mDrawingState;
chaviw4b129c22018-04-09 16:19:43 -07001798
chaviwfd462612018-05-31 16:11:27 -07001799 LayerVector traverse(stateSet);
chaviw4b129c22018-04-09 16:19:43 -07001800 for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
1801 sp<Layer> strongRelative = weakRelative.promote();
1802 // Only add relative layers that are also descendents of the top most parent of the tree.
1803 // If a relative layer is not a descendent, then it should be ignored.
1804 if (std::binary_search(layersInTree.begin(), layersInTree.end(), strongRelative.get())) {
1805 traverse.add(strongRelative);
1806 }
1807 }
1808
1809 for (const sp<Layer>& child : children) {
Robert Carr6a160312021-05-17 12:08:20 -07001810 const State& childState = useDrawing ? child->mDrawingState : child->mDrawingState;
chaviw4b129c22018-04-09 16:19:43 -07001811 // If a layer has a relativeOf layer, only ignore if the layer it's relative to is a
1812 // descendent of the top most parent of the tree. If it's not a descendent, then just add
1813 // the child here since it won't be added later as a relative.
1814 if (std::binary_search(layersInTree.begin(), layersInTree.end(),
1815 childState.zOrderRelativeOf.promote().get())) {
1816 continue;
1817 }
1818 traverse.add(child);
1819 }
1820
1821 return traverse;
1822}
1823
1824void Layer::traverseChildrenInZOrderInner(const std::vector<Layer*>& layersInTree,
1825 LayerVector::StateSet stateSet,
1826 const LayerVector::Visitor& visitor) {
1827 const LayerVector list = makeChildrenTraversalList(stateSet, layersInTree);
chaviwa76b2712017-09-20 12:02:26 -07001828
1829 size_t i = 0;
chaviw4b129c22018-04-09 16:19:43 -07001830 for (; i < list.size(); i++) {
1831 const auto& relative = list[i];
chaviw301b1d82019-11-06 13:15:09 -08001832 if (relative->getZ(stateSet) >= 0) {
chaviwa76b2712017-09-20 12:02:26 -07001833 break;
1834 }
chaviw4b129c22018-04-09 16:19:43 -07001835 relative->traverseChildrenInZOrderInner(layersInTree, stateSet, visitor);
chaviwa76b2712017-09-20 12:02:26 -07001836 }
chaviw4b129c22018-04-09 16:19:43 -07001837
chaviwa76b2712017-09-20 12:02:26 -07001838 visitor(this);
chaviw4b129c22018-04-09 16:19:43 -07001839 for (; i < list.size(); i++) {
1840 const auto& relative = list[i];
1841 relative->traverseChildrenInZOrderInner(layersInTree, stateSet, visitor);
chaviwa76b2712017-09-20 12:02:26 -07001842 }
1843}
1844
chaviw4b129c22018-04-09 16:19:43 -07001845std::vector<Layer*> Layer::getLayersInTree(LayerVector::StateSet stateSet) {
1846 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1847 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
1848
1849 std::vector<Layer*> layersInTree = {this};
1850 for (size_t i = 0; i < children.size(); i++) {
1851 const auto& child = children[i];
1852 std::vector<Layer*> childLayers = child->getLayersInTree(stateSet);
1853 layersInTree.insert(layersInTree.end(), childLayers.cbegin(), childLayers.cend());
1854 }
1855
1856 return layersInTree;
1857}
1858
1859void Layer::traverseChildrenInZOrder(LayerVector::StateSet stateSet,
1860 const LayerVector::Visitor& visitor) {
1861 std::vector<Layer*> layersInTree = getLayersInTree(stateSet);
1862 std::sort(layersInTree.begin(), layersInTree.end());
1863 traverseChildrenInZOrderInner(layersInTree, stateSet, visitor);
1864}
1865
Peiyong Linefefaac2018-08-17 12:27:51 -07001866ui::Transform Layer::getTransform() const {
Vishnu Nairf0c28512019-02-08 12:40:28 -08001867 return mEffectiveTransform;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001868}
1869
chaviw13fdc492017-06-27 12:40:18 -07001870half Layer::getAlpha() const {
Ady Abraham83729882018-12-07 12:26:48 -08001871 const auto& p = mDrawingParent.promote();
Lloyd Pique0449b0f2018-12-20 16:23:45 -08001872
chaviw13fdc492017-06-27 12:40:18 -07001873 half parentAlpha = (p != nullptr) ? p->getAlpha() : 1.0_hf;
1874 return parentAlpha * getDrawingState().color.a;
Robert Carr6452f122017-03-21 10:41:29 -07001875}
Robert Carr6452f122017-03-21 10:41:29 -07001876
Vishnu Nair6213bd92020-05-08 17:42:25 -07001877ui::Transform::RotationFlags Layer::getFixedTransformHint() const {
Robert Carr6a160312021-05-17 12:08:20 -07001878 ui::Transform::RotationFlags fixedTransformHint = mDrawingState.fixedTransformHint;
Vishnu Nair6213bd92020-05-08 17:42:25 -07001879 if (fixedTransformHint != ui::Transform::ROT_INVALID) {
1880 return fixedTransformHint;
1881 }
1882 const auto& p = mCurrentParent.promote();
1883 if (!p) return fixedTransformHint;
1884 return p->getFixedTransformHint();
1885}
1886
chaviw13fdc492017-06-27 12:40:18 -07001887half4 Layer::getColor() const {
1888 const half4 color(getDrawingState().color);
Lloyd Pique0449b0f2018-12-20 16:23:45 -08001889 return half4(color.r, color.g, color.b, getAlpha());
Robert Carr6452f122017-03-21 10:41:29 -07001890}
Robert Carr6452f122017-03-21 10:41:29 -07001891
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08001892int32_t Layer::getBackgroundBlurRadius() const {
Galia Peychevada7de0e2020-12-03 17:24:35 +01001893 const auto& p = mDrawingParent.promote();
1894
1895 half parentAlpha = (p != nullptr) ? p->getAlpha() : 1.0_hf;
1896 return parentAlpha * getDrawingState().backgroundBlurRadius;
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08001897}
1898
Galia Peychevae0acf382021-04-12 21:22:34 +02001899const std::vector<BlurRegion> Layer::getBlurRegions() const {
1900 auto regionsCopy(getDrawingState().blurRegions);
Galia Peycheva3c286542021-06-17 15:21:28 +02001901 float layerAlpha = getAlpha();
Galia Peychevae0acf382021-04-12 21:22:34 +02001902 for (auto& region : regionsCopy) {
1903 region.alpha = region.alpha * layerAlpha;
1904 }
1905 return regionsCopy;
Lucas Dupinc3800b82020-10-02 16:24:48 -07001906}
1907
Lucas Dupin1b6531c2018-07-05 17:18:21 -07001908Layer::RoundedCornerState Layer::getRoundedCornerState() const {
1909 const auto& p = mDrawingParent.promote();
1910 if (p != nullptr) {
Peiyong Lin27016a92019-03-29 17:36:08 +00001911 RoundedCornerState parentState = p->getRoundedCornerState();
Lucas Dupin1b6531c2018-07-05 17:18:21 -07001912 if (parentState.radius > 0) {
1913 ui::Transform t = getActiveTransform(getDrawingState());
1914 t = t.inverse();
1915 parentState.cropRect = t.transform(parentState.cropRect);
1916 // The rounded corners shader only accepts 1 corner radius for performance reasons,
1917 // but a transform matrix can define horizontal and vertical scales.
1918 // Let's take the average between both of them and pass into the shader, practically we
1919 // never do this type of transformation on windows anyway.
Lucas Dupineab7ea02020-06-03 17:27:28 -07001920 auto scaleX = sqrtf(t[0][0] * t[0][0] + t[0][1] * t[0][1]);
1921 auto scaleY = sqrtf(t[1][0] * t[1][0] + t[1][1] * t[1][1]);
1922 parentState.radius *= (scaleX + scaleY) / 2.0f;
Lucas Dupin1b6531c2018-07-05 17:18:21 -07001923 return parentState;
1924 }
1925 }
1926 const float radius = getDrawingState().cornerRadius;
Chavi Weingartena5aedbd2021-04-09 13:37:33 +00001927 return radius > 0 && getCroppedBufferSize(getDrawingState()).isValid()
1928 ? RoundedCornerState(getCroppedBufferSize(getDrawingState()).toFloatRect(), radius)
Peiyong Linb9ff23e2019-04-08 11:04:59 -07001929 : RoundedCornerState();
Lucas Dupin1b6531c2018-07-05 17:18:21 -07001930}
1931
Derek Sollenbergerc31985e2021-05-18 16:38:17 -04001932void Layer::prepareShadowClientComposition(LayerFE::LayerSettings& caster,
1933 const Rect& layerStackRect) {
Vishnu Nair08f6eae2019-11-26 14:01:39 -08001934 renderengine::ShadowSettings state = mFlinger->mDrawingState.globalShadowSettings;
1935
Derek Sollenbergerc31985e2021-05-18 16:38:17 -04001936 // Note: this preserves existing behavior of shadowing the entire layer and not cropping it if
1937 // transparent regions are present. This may not be necessary since shadows are only cast by
1938 // SurfaceFlinger's EffectLayers, which do not typically use transparent regions.
1939 state.boundaries = mBounds;
1940
Vishnu Nair08f6eae2019-11-26 14:01:39 -08001941 // Shift the spot light x-position to the middle of the display and then
1942 // offset it by casting layer's screen pos.
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001943 state.lightPos.x = (layerStackRect.width() / 2.f) - mScreenBounds.left;
Vishnu Nair08f6eae2019-11-26 14:01:39 -08001944 state.lightPos.y -= mScreenBounds.top;
1945
1946 state.length = mEffectiveShadowRadius;
Derek Sollenbergerc31985e2021-05-18 16:38:17 -04001947
1948 if (state.length > 0.f) {
1949 const float casterAlpha = caster.alpha;
1950 const bool casterIsOpaque =
1951 ((caster.source.buffer.buffer != nullptr) && caster.source.buffer.isOpaque);
1952
1953 // If the casting layer is translucent, we need to fill in the shadow underneath the layer.
1954 // Otherwise the generated shadow will only be shown around the casting layer.
1955 state.casterIsTranslucent = !casterIsOpaque || (casterAlpha < 1.0f);
1956 state.ambientColor *= casterAlpha;
1957 state.spotColor *= casterAlpha;
1958
1959 if (state.ambientColor.a > 0.f && state.spotColor.a > 0.f) {
1960 caster.shadow = state;
1961 }
1962 }
Vishnu Nair08f6eae2019-11-26 14:01:39 -08001963}
1964
Robert Carr1f0a16a2016-10-24 16:27:39 -07001965void Layer::commitChildList() {
1966 for (size_t i = 0; i < mCurrentChildren.size(); i++) {
1967 const auto& child = mCurrentChildren[i];
1968 child->commitChildList();
1969 }
1970 mDrawingChildren = mCurrentChildren;
Chia-I Wue41dbe62017-06-13 14:10:56 -07001971 mDrawingParent = mCurrentParent;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001972}
1973
Vishnu Nair6fabeec2019-03-12 13:42:49 -07001974static wp<Layer> extractLayerFromBinder(const wp<IBinder>& weakBinderHandle) {
1975 if (weakBinderHandle == nullptr) {
1976 return nullptr;
1977 }
1978 sp<IBinder> binderHandle = weakBinderHandle.promote();
1979 if (binderHandle == nullptr) {
1980 return nullptr;
1981 }
1982 sp<Layer::Handle> handle = static_cast<Layer::Handle*>(binderHandle.get());
1983 if (handle == nullptr) {
1984 return nullptr;
1985 }
1986 return handle->owner;
1987}
1988
chaviw3277faf2021-05-19 16:45:23 -05001989void Layer::setInputInfo(const WindowInfo& info) {
Robert Carr6a160312021-05-17 12:08:20 -07001990 mDrawingState.inputInfo = info;
1991 mDrawingState.touchableRegionCrop = extractLayerFromBinder(info.touchableRegionCropHandle);
1992 mDrawingState.modified = true;
Robert Carrbf14dbb2021-06-11 13:26:56 -07001993 mFlinger->mInputInfoChanged = true;
Robert Carr720e5062018-07-30 17:45:14 -07001994 setTransactionFlags(eTransactionNeeded);
1995}
1996
Alec Mouri6b9e9912020-01-21 10:50:24 -08001997LayerProto* Layer::writeToProto(LayersProto& layersProto, uint32_t traceFlags,
chaviw4c34a092020-07-08 11:30:06 -07001998 const DisplayDevice* display) {
chaviw08f3cb22020-01-13 13:17:21 -08001999 LayerProto* layerProto = layersProto.add_layers();
Dominik Laskowskib7251f42020-04-20 17:42:59 -07002000 writeToProtoDrawingState(layerProto, traceFlags, display);
chaviw08f3cb22020-01-13 13:17:21 -08002001 writeToProtoCommonState(layerProto, LayerVector::StateSet::Drawing, traceFlags);
2002
Vishnu Nair60db8c02020-04-02 11:55:16 -07002003 if (traceFlags & SurfaceTracing::TRACE_COMPOSITION) {
2004 // Only populate for the primary display.
Dominik Laskowskib7251f42020-04-20 17:42:59 -07002005 if (display) {
2006 const Hwc2::IComposerClient::Composition compositionType = getCompositionType(*display);
Vishnu Nair60db8c02020-04-02 11:55:16 -07002007 layerProto->set_hwc_composition_type(static_cast<HwcCompositionType>(compositionType));
2008 }
Alec Mouri6b9e9912020-01-21 10:50:24 -08002009 }
2010
chaviw08f3cb22020-01-13 13:17:21 -08002011 for (const sp<Layer>& layer : mDrawingChildren) {
Dominik Laskowskib7251f42020-04-20 17:42:59 -07002012 layer->writeToProto(layersProto, traceFlags, display);
chaviw08f3cb22020-01-13 13:17:21 -08002013 }
chaviw6d89e2d2020-01-14 14:42:01 -08002014
2015 return layerProto;
chaviw08f3cb22020-01-13 13:17:21 -08002016}
2017
Dominik Laskowskib7251f42020-04-20 17:42:59 -07002018void Layer::writeToProtoDrawingState(LayerProto* layerInfo, uint32_t traceFlags,
chaviw4c34a092020-07-08 11:30:06 -07002019 const DisplayDevice* display) {
Vishnu Nair6b7c5c92020-09-29 17:27:05 -07002020 const ui::Transform transform = getTransform();
Vishnu Nair8406fd72019-07-30 11:29:31 -07002021
2022 if (traceFlags & SurfaceTracing::TRACE_CRITICAL) {
Vishnu Nair8406fd72019-07-30 11:29:31 -07002023
chaviwd62d3062019-09-04 14:48:02 -07002024 auto buffer = getBuffer();
Vishnu Nair8406fd72019-07-30 11:29:31 -07002025 if (buffer != nullptr) {
2026 LayerProtoHelper::writeToProto(buffer,
2027 [&]() { return layerInfo->mutable_active_buffer(); });
chaviw4244e032019-09-04 11:27:49 -07002028 LayerProtoHelper::writeToProto(ui::Transform(getBufferTransform()),
Vishnu Nair8406fd72019-07-30 11:29:31 -07002029 layerInfo->mutable_buffer_transform());
2030 }
2031 layerInfo->set_invalidate(contentDirty);
2032 layerInfo->set_is_protected(isProtected());
chaviw4244e032019-09-04 11:27:49 -07002033 layerInfo->set_dataspace(dataspaceDetails(static_cast<android_dataspace>(getDataSpace())));
Vishnu Nair8406fd72019-07-30 11:29:31 -07002034 layerInfo->set_queued_frames(getQueuedFrameCount());
2035 layerInfo->set_refresh_pending(isBufferLatched());
2036 layerInfo->set_curr_frame(mCurrentFrameNumber);
2037 layerInfo->set_effective_scaling_mode(getEffectiveScalingMode());
2038
2039 layerInfo->set_corner_radius(getRoundedCornerState().radius);
Ana Krulece766cc82020-04-27 13:49:13 -07002040 layerInfo->set_background_blur_radius(getBackgroundBlurRadius());
Vishnu Nair8406fd72019-07-30 11:29:31 -07002041 LayerProtoHelper::writeToProto(transform, layerInfo->mutable_transform());
2042 LayerProtoHelper::writePositionToProto(transform.tx(), transform.ty(),
2043 [&]() { return layerInfo->mutable_position(); });
2044 LayerProtoHelper::writeToProto(mBounds, [&]() { return layerInfo->mutable_bounds(); });
Vishnu Nair60db8c02020-04-02 11:55:16 -07002045 if (traceFlags & SurfaceTracing::TRACE_COMPOSITION) {
Dominik Laskowskib7251f42020-04-20 17:42:59 -07002046 LayerProtoHelper::writeToProto(getVisibleRegion(display),
Vishnu Nair60db8c02020-04-02 11:55:16 -07002047 [&]() { return layerInfo->mutable_visible_region(); });
2048 }
Vishnu Nair8406fd72019-07-30 11:29:31 -07002049 LayerProtoHelper::writeToProto(surfaceDamageRegion,
2050 [&]() { return layerInfo->mutable_damage_region(); });
chaviwddeae262020-01-06 10:31:23 -08002051
2052 if (hasColorTransform()) {
2053 LayerProtoHelper::writeToProto(getColorTransform(),
2054 layerInfo->mutable_color_transform());
2055 }
Vishnu Nair8406fd72019-07-30 11:29:31 -07002056 }
2057
Vishnu Nair60db8c02020-04-02 11:55:16 -07002058 LayerProtoHelper::writeToProto(mSourceBounds,
2059 [&]() { return layerInfo->mutable_source_bounds(); });
2060 LayerProtoHelper::writeToProto(mScreenBounds,
2061 [&]() { return layerInfo->mutable_screen_bounds(); });
2062 LayerProtoHelper::writeToProto(getRoundedCornerState().cropRect,
2063 [&]() { return layerInfo->mutable_corner_radius_crop(); });
2064 layerInfo->set_shadow_radius(mEffectiveShadowRadius);
Vishnu Nair8406fd72019-07-30 11:29:31 -07002065}
2066
2067void Layer::writeToProtoCommonState(LayerProto* layerInfo, LayerVector::StateSet stateSet,
chaviw4c34a092020-07-08 11:30:06 -07002068 uint32_t traceFlags) {
chaviw1d044282017-09-27 12:19:28 -07002069 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
2070 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
Robert Carr6a160312021-05-17 12:08:20 -07002071 const State& state = useDrawing ? mDrawingState : mDrawingState;
chaviw1d044282017-09-27 12:19:28 -07002072
chaviw766c9c52021-02-10 17:36:47 -08002073 ui::Transform requestedTransform = state.transform;
chaviw1d044282017-09-27 12:19:28 -07002074
Vishnu Nair9245d3b2019-03-22 13:38:56 -07002075 if (traceFlags & SurfaceTracing::TRACE_CRITICAL) {
2076 layerInfo->set_id(sequence);
2077 layerInfo->set_name(getName().c_str());
chaviw8a01fa42019-08-19 12:39:31 -07002078 layerInfo->set_type(getType());
chaviw1d044282017-09-27 12:19:28 -07002079
Vishnu Nair9245d3b2019-03-22 13:38:56 -07002080 for (const auto& child : children) {
2081 layerInfo->add_children(child->sequence);
chaviw1d044282017-09-27 12:19:28 -07002082 }
chaviw1d044282017-09-27 12:19:28 -07002083
Vishnu Nair9245d3b2019-03-22 13:38:56 -07002084 for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
2085 sp<Layer> strongRelative = weakRelative.promote();
2086 if (strongRelative != nullptr) {
2087 layerInfo->add_relatives(strongRelative->sequence);
2088 }
chaviwadc40c22018-07-10 16:57:27 -07002089 }
Vishnu Nair9245d3b2019-03-22 13:38:56 -07002090
2091 LayerProtoHelper::writeToProto(state.activeTransparentRegion_legacy,
2092 [&]() { return layerInfo->mutable_transparent_region(); });
Vishnu Nair9245d3b2019-03-22 13:38:56 -07002093
2094 layerInfo->set_layer_stack(getLayerStack());
2095 layerInfo->set_z(state.z);
2096
Vishnu Nair9245d3b2019-03-22 13:38:56 -07002097 LayerProtoHelper::writePositionToProto(requestedTransform.tx(), requestedTransform.ty(),
2098 [&]() {
2099 return layerInfo->mutable_requested_position();
2100 });
2101
chaviw766c9c52021-02-10 17:36:47 -08002102 LayerProtoHelper::writeSizeToProto(state.width, state.height,
Vishnu Nair9245d3b2019-03-22 13:38:56 -07002103 [&]() { return layerInfo->mutable_size(); });
2104
chaviw766c9c52021-02-10 17:36:47 -08002105 LayerProtoHelper::writeToProto(state.crop, [&]() { return layerInfo->mutable_crop(); });
Vishnu Nair9245d3b2019-03-22 13:38:56 -07002106
2107 layerInfo->set_is_opaque(isOpaque(state));
Vishnu Nair9245d3b2019-03-22 13:38:56 -07002108
Vishnu Nair9245d3b2019-03-22 13:38:56 -07002109
2110 layerInfo->set_pixel_format(decodePixelFormat(getPixelFormat()));
2111 LayerProtoHelper::writeToProto(getColor(), [&]() { return layerInfo->mutable_color(); });
2112 LayerProtoHelper::writeToProto(state.color,
2113 [&]() { return layerInfo->mutable_requested_color(); });
2114 layerInfo->set_flags(state.flags);
2115
Vishnu Nair9245d3b2019-03-22 13:38:56 -07002116 LayerProtoHelper::writeToProto(requestedTransform,
2117 layerInfo->mutable_requested_transform());
2118
2119 auto parent = useDrawing ? mDrawingParent.promote() : mCurrentParent.promote();
2120 if (parent != nullptr) {
2121 layerInfo->set_parent(parent->sequence);
2122 } else {
2123 layerInfo->set_parent(-1);
2124 }
2125
2126 auto zOrderRelativeOf = state.zOrderRelativeOf.promote();
2127 if (zOrderRelativeOf != nullptr) {
2128 layerInfo->set_z_order_relative_of(zOrderRelativeOf->sequence);
2129 } else {
2130 layerInfo->set_z_order_relative_of(-1);
2131 }
chaviw08f3cb22020-01-13 13:17:21 -08002132
2133 layerInfo->set_is_relative_of(state.isRelativeOf);
chaviw250bcbb2020-08-05 11:17:54 -07002134
2135 layerInfo->set_owner_uid(mOwnerUid);
chaviwadc40c22018-07-10 16:57:27 -07002136 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -08002137
Vishnu Nair9245d3b2019-03-22 13:38:56 -07002138 if (traceFlags & SurfaceTracing::TRACE_INPUT) {
chaviw3277faf2021-05-19 16:45:23 -05002139 WindowInfo info;
chaviw4c34a092020-07-08 11:30:06 -07002140 if (useDrawing) {
[1;3C2b9fc252021-02-04 16:16:50 -08002141 info = fillInputInfo({nullptr});
chaviw4c34a092020-07-08 11:30:06 -07002142 } else {
2143 info = state.inputInfo;
2144 }
2145
2146 LayerProtoHelper::writeToProto(info, state.touchableRegionCrop,
Vishnu Nair9245d3b2019-03-22 13:38:56 -07002147 [&]() { return layerInfo->mutable_input_window_info(); });
Evan Rosky1f6d6d52018-12-06 10:47:26 -08002148 }
Vishnu Nair9245d3b2019-03-22 13:38:56 -07002149
2150 if (traceFlags & SurfaceTracing::TRACE_EXTRA) {
2151 auto protoMap = layerInfo->mutable_metadata();
2152 for (const auto& entry : state.metadata.mMap) {
2153 (*protoMap)[entry.first] = std::string(entry.second.cbegin(), entry.second.cend());
2154 }
Vishnu Nair9245d3b2019-03-22 13:38:56 -07002155 }
chaviw1d044282017-09-27 12:19:28 -07002156}
2157
Robert Carr2e102c92018-10-23 12:11:15 -07002158bool Layer::isRemovedFromCurrentState() const {
Robert Carr6a160312021-05-17 12:08:20 -07002159 return mRemovedFromDrawingState;
Robert Carr2e102c92018-10-23 12:11:15 -07002160}
2161
chaviw39d01472021-04-08 14:26:24 -05002162ui::Transform Layer::getInputTransform() const {
2163 return getTransform();
2164}
2165
2166Rect Layer::getInputBounds() const {
2167 return getCroppedBufferSize(getDrawingState());
2168}
2169
chaviw3277faf2021-05-19 16:45:23 -05002170void Layer::fillInputFrameInfo(WindowInfo& info, const ui::Transform& toPhysicalDisplay) {
Lloyd Pique0449b0f2018-12-20 16:23:45 -08002171 // Transform layer size to screen space and inset it by surface insets.
Tiger Huang85b8c5e2019-01-17 18:34:54 +08002172 // If this is a portal window, set the touchableRegion to the layerBounds.
2173 Rect layerBounds = info.portalToDisplayId == ADISPLAY_ID_NONE
chaviw39d01472021-04-08 14:26:24 -05002174 ? getInputBounds()
Tiger Huang85b8c5e2019-01-17 18:34:54 +08002175 : info.touchableRegion.getBounds();
Arthur Hungd20b2702019-01-14 18:16:16 +08002176 if (!layerBounds.isValid()) {
chaviw39d01472021-04-08 14:26:24 -05002177 layerBounds = getInputBounds();
Arthur Hungd20b2702019-01-14 18:16:16 +08002178 }
chaviw1ff3d1e2020-07-01 15:53:47 -07002179
chaviw7e72caf2020-12-02 16:50:43 -08002180 if (!layerBounds.isValid()) {
2181 // If the layer bounds is empty, set the frame to empty and clear the transform
2182 info.frameLeft = 0;
2183 info.frameTop = 0;
2184 info.frameRight = 0;
2185 info.frameBottom = 0;
2186 info.transform.reset();
2187 return;
2188 }
2189
chaviw39d01472021-04-08 14:26:24 -05002190 ui::Transform layerToDisplay = getInputTransform();
[1;3C2b9fc252021-02-04 16:16:50 -08002191 // Transform that takes window coordinates to unrotated display coordinates
2192 ui::Transform t = toPhysicalDisplay * layerToDisplay;
chaviw7e72caf2020-12-02 16:50:43 -08002193 int32_t xSurfaceInset = info.surfaceInset;
2194 int32_t ySurfaceInset = info.surfaceInset;
[1;3C2b9fc252021-02-04 16:16:50 -08002195 // Bring screenBounds into unrotated space
2196 Rect screenBounds = toPhysicalDisplay.transform(Rect{mScreenBounds});
chaviw7e72caf2020-12-02 16:50:43 -08002197
chaviw1ff3d1e2020-07-01 15:53:47 -07002198 const float xScale = t.getScaleX();
2199 const float yScale = t.getScaleY();
2200 if (xScale != 1.0f || yScale != 1.0f) {
chaviw1ff3d1e2020-07-01 15:53:47 -07002201 xSurfaceInset = std::round(xSurfaceInset * xScale);
2202 ySurfaceInset = std::round(ySurfaceInset * yScale);
2203 }
2204
Peiyong Lin74861ad2020-10-14 11:55:33 -07002205 // Transform the layer bounds from layer coordinate space to display coordinate space.
chaviw44a6d2b2020-09-08 17:14:16 -07002206 Rect transformedLayerBounds = t.transform(layerBounds);
Ady Abraham282f1d72019-07-24 18:05:56 -07002207
2208 // clamp inset to layer bounds
chaviw44a6d2b2020-09-08 17:14:16 -07002209 xSurfaceInset = (xSurfaceInset >= 0)
2210 ? std::min(xSurfaceInset, transformedLayerBounds.getWidth() / 2)
2211 : 0;
2212 ySurfaceInset = (ySurfaceInset >= 0)
2213 ? std::min(ySurfaceInset, transformedLayerBounds.getHeight() / 2)
2214 : 0;
Ady Abraham282f1d72019-07-24 18:05:56 -07002215
Robert Carra7242302020-09-01 18:26:29 -07002216 // inset while protecting from overflow TODO(b/161235021): What is going wrong
2217 // in the overflow scenario?
2218 {
2219 int32_t tmp;
chaviw44a6d2b2020-09-08 17:14:16 -07002220 if (!__builtin_add_overflow(transformedLayerBounds.left, xSurfaceInset, &tmp))
2221 transformedLayerBounds.left = tmp;
2222 if (!__builtin_sub_overflow(transformedLayerBounds.right, xSurfaceInset, &tmp))
2223 transformedLayerBounds.right = tmp;
2224 if (!__builtin_add_overflow(transformedLayerBounds.top, ySurfaceInset, &tmp))
2225 transformedLayerBounds.top = tmp;
2226 if (!__builtin_sub_overflow(transformedLayerBounds.bottom, ySurfaceInset, &tmp))
2227 transformedLayerBounds.bottom = tmp;
Robert Carra7242302020-09-01 18:26:29 -07002228 }
Vishnu Nair8033a492018-12-05 07:27:23 -08002229
chaviw44a6d2b2020-09-08 17:14:16 -07002230 // Compute the correct transform to send to input. This will allow it to transform the
2231 // input coordinates from display space into window space. Therefore, it needs to use the
2232 // final layer frame to create the inverse transform. Since surface insets are added later,
2233 // along with the overflow, the best way to ensure we get the correct transform is to use
2234 // the final frame calculated.
2235 // 1. Take the original transform set on the window and get the inverse transform. This is
2236 // used to get the final bounds in display space (ignorning the transform). Apply the
Peiyong Lin74861ad2020-10-14 11:55:33 -07002237 // inverse transform on the layerBounds to get the untransformed frame (in layer space)
chaviw44a6d2b2020-09-08 17:14:16 -07002238 // 2. Take the top and left of the untransformed frame to get the real position on screen.
2239 // Apply the layer transform on top/left so it includes any scale or rotation. These will
2240 // be the new translation values for the transform.
2241 // 3. Update the translation of the original transform to the new translation values.
2242 // 4. Send the inverse transform to input so the coordinates can be transformed back into
2243 // window space.
2244 ui::Transform inverseTransform = t.inverse();
2245 Rect nonTransformedBounds = inverseTransform.transform(transformedLayerBounds);
2246 vec2 translation = t.transform(nonTransformedBounds.left, nonTransformedBounds.top);
chaviw1ff3d1e2020-07-01 15:53:47 -07002247 ui::Transform inputTransform(t);
chaviw44a6d2b2020-09-08 17:14:16 -07002248 inputTransform.set(translation.x, translation.y);
chaviw1ff3d1e2020-07-01 15:53:47 -07002249 info.transform = inputTransform.inverse();
2250
chaviw39cfa2e2020-11-04 14:19:02 -08002251 // We need to send the layer bounds cropped to the screenbounds since the layer can be cropped.
2252 // The frame should be the area the user sees on screen since it's used for occlusion
2253 // detection.
chaviw39cfa2e2020-11-04 14:19:02 -08002254 transformedLayerBounds.intersect(screenBounds, &transformedLayerBounds);
2255 info.frameLeft = transformedLayerBounds.left;
2256 info.frameTop = transformedLayerBounds.top;
2257 info.frameRight = transformedLayerBounds.right;
2258 info.frameBottom = transformedLayerBounds.bottom;
2259
Vishnu Nair8033a492018-12-05 07:27:23 -08002260 // Position the touchable region relative to frame screen location and restrict it to frame
2261 // bounds.
chaviw44a6d2b2020-09-08 17:14:16 -07002262 info.touchableRegion = inputTransform.transform(info.touchableRegion);
chaviw7e72caf2020-12-02 16:50:43 -08002263}
2264
chaviw3277faf2021-05-19 16:45:23 -05002265void Layer::fillTouchOcclusionMode(WindowInfo& info) {
Bernardo Rufinoa9d0a532021-06-11 15:59:12 +01002266 sp<Layer> p = this;
2267 while (p != nullptr && !p->hasInputInfo()) {
2268 p = p->mDrawingParent.promote();
2269 }
2270 if (p != nullptr) {
2271 info.touchOcclusionMode = p->mDrawingState.inputInfo.touchOcclusionMode;
2272 }
2273}
2274
chaviw3277faf2021-05-19 16:45:23 -05002275WindowInfo Layer::fillInputInfo(const sp<DisplayDevice>& display) {
chaviw7e72caf2020-12-02 16:50:43 -08002276 if (!hasInputInfo()) {
2277 mDrawingState.inputInfo.name = getName();
2278 mDrawingState.inputInfo.ownerUid = mOwnerUid;
2279 mDrawingState.inputInfo.ownerPid = mOwnerPid;
chaviw3277faf2021-05-19 16:45:23 -05002280 mDrawingState.inputInfo.inputFeatures = WindowInfo::Feature::NO_INPUT_CHANNEL;
2281 mDrawingState.inputInfo.flags = WindowInfo::Flag::NOT_TOUCH_MODAL;
chaviw7e72caf2020-12-02 16:50:43 -08002282 mDrawingState.inputInfo.displayId = getLayerStack();
2283 }
2284
chaviw3277faf2021-05-19 16:45:23 -05002285 WindowInfo info = mDrawingState.inputInfo;
chaviw7e72caf2020-12-02 16:50:43 -08002286 info.id = sequence;
2287
2288 if (info.displayId == ADISPLAY_ID_NONE) {
2289 info.displayId = getLayerStack();
2290 }
2291
[1;3C2b9fc252021-02-04 16:16:50 -08002292 // Transform that goes from "logical(rotated)" display to physical/unrotated display.
2293 // This is for when inputflinger operates in physical display-space.
2294 ui::Transform toPhysicalDisplay;
2295 if (display) {
2296 toPhysicalDisplay = display->getTransform();
Evan Rosky84f07f02021-04-16 10:42:42 -07002297 info.displayWidth = display->getWidth();
2298 info.displayHeight = display->getHeight();
[1;3C2b9fc252021-02-04 16:16:50 -08002299 }
2300 fillInputFrameInfo(info, toPhysicalDisplay);
chaviw7e72caf2020-12-02 16:50:43 -08002301
Robert Carr5dc426e2020-06-10 14:29:14 -07002302 // For compatibility reasons we let layers which can receive input
2303 // receive input before they have actually submitted a buffer. Because
2304 // of this we use canReceiveInput instead of isVisible to check the
2305 // policy-visibility, ignoring the buffer state. However for layers with
2306 // hasInputInfo()==false we can use the real visibility state.
2307 // We are just using these layers for occlusion detection in
2308 // InputDispatcher, and obviously if they aren't visible they can't occlude
2309 // anything.
2310 info.visible = hasInputInfo() ? canReceiveInput() : isVisible();
Bernardo Rufinoea97d182020-08-19 14:43:14 +01002311 info.alpha = getAlpha();
Bernardo Rufinoa9d0a532021-06-11 15:59:12 +01002312 fillTouchOcclusionMode(info);
Vishnu Nair6fabeec2019-03-12 13:42:49 -07002313
2314 auto cropLayer = mDrawingState.touchableRegionCrop.promote();
2315 if (info.replaceTouchableRegionWithCrop) {
2316 if (cropLayer == nullptr) {
[1;3C2b9fc252021-02-04 16:16:50 -08002317 info.touchableRegion = Region(toPhysicalDisplay.transform(Rect{mScreenBounds}));
Vishnu Nair6fabeec2019-03-12 13:42:49 -07002318 } else {
[1;3C2b9fc252021-02-04 16:16:50 -08002319 info.touchableRegion =
2320 Region(toPhysicalDisplay.transform(Rect{cropLayer->mScreenBounds}));
Vishnu Nair6fabeec2019-03-12 13:42:49 -07002321 }
2322 } else if (cropLayer != nullptr) {
[1;3C2b9fc252021-02-04 16:16:50 -08002323 info.touchableRegion = info.touchableRegion.intersect(
2324 toPhysicalDisplay.transform(Rect{cropLayer->mScreenBounds}));
Vishnu Nair6fabeec2019-03-12 13:42:49 -07002325 }
2326
chaviwaf87b3e2019-10-01 16:59:28 -07002327 // If the layer is a clone, we need to crop the input region to cloned root to prevent
2328 // touches from going outside the cloned area.
2329 if (isClone()) {
2330 sp<Layer> clonedRoot = getClonedRoot();
2331 if (clonedRoot != nullptr) {
[1;3C2b9fc252021-02-04 16:16:50 -08002332 Rect rect = toPhysicalDisplay.transform(Rect{clonedRoot->mScreenBounds});
chaviwaf87b3e2019-10-01 16:59:28 -07002333 info.touchableRegion = info.touchableRegion.intersect(rect);
2334 }
2335 }
2336
Robert Carr720e5062018-07-30 17:45:14 -07002337 return info;
2338}
2339
chaviwaf87b3e2019-10-01 16:59:28 -07002340sp<Layer> Layer::getClonedRoot() {
2341 if (mClonedChild != nullptr) {
2342 return this;
2343 }
2344 if (mDrawingParent == nullptr || mDrawingParent.promote() == nullptr) {
2345 return nullptr;
2346 }
2347 return mDrawingParent.promote()->getClonedRoot();
2348}
2349
Robert Carredd13602020-04-13 17:24:34 -07002350bool Layer::hasInputInfo() const {
Lloyd Pique0449b0f2018-12-20 16:23:45 -08002351 return mDrawingState.inputInfo.token != nullptr;
Robert Carr720e5062018-07-30 17:45:14 -07002352}
2353
chaviw3e727cd2019-01-31 13:41:05 -08002354bool Layer::canReceiveInput() const {
Vishnu Nair82353e92019-09-12 12:38:47 -07002355 return !isHiddenByPolicy();
chaviw3e727cd2019-01-31 13:41:05 -08002356}
2357
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08002358compositionengine::OutputLayer* Layer::findOutputLayerForDisplay(
Dominik Laskowskib7251f42020-04-20 17:42:59 -07002359 const DisplayDevice* display) const {
2360 if (!display) return nullptr;
Lloyd Piquede196652020-01-22 17:29:58 -08002361 return display->getCompositionDisplay()->getOutputLayerForLayer(getCompositionEngineLayerFE());
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08002362}
2363
Dominik Laskowskib7251f42020-04-20 17:42:59 -07002364Region Layer::getVisibleRegion(const DisplayDevice* display) const {
2365 const auto outputLayer = findOutputLayerForDisplay(display);
2366 return outputLayer ? outputLayer->getState().visibleRegion : Region();
Lloyd Piquea2468662019-03-07 21:31:06 -08002367}
2368
chaviwb4c6e582019-08-16 14:35:07 -07002369void Layer::setInitialValuesForClone(const sp<Layer>& clonedFrom) {
2370 // copy drawing state from cloned layer
2371 mDrawingState = clonedFrom->mDrawingState;
2372 mClonedFrom = clonedFrom;
chaviwb4c6e582019-08-16 14:35:07 -07002373}
chaviw74b03172019-08-19 11:09:03 -07002374
2375void Layer::updateMirrorInfo() {
2376 if (mClonedChild == nullptr || !mClonedChild->isClonedFromAlive()) {
2377 // If mClonedChild is null, there is nothing to mirror. If isClonedFromAlive returns false,
2378 // it means that there is a clone, but the layer it was cloned from has been destroyed. In
2379 // that case, we want to delete the reference to the clone since we want it to get
2380 // destroyed. The root, this layer, will still be around since the client can continue
2381 // to hold a reference, but no cloned layers will be displayed.
2382 mClonedChild = nullptr;
2383 return;
2384 }
2385
2386 std::map<sp<Layer>, sp<Layer>> clonedLayersMap;
2387 // If the real layer exists and is in current state, add the clone as a child of the root.
2388 // There's no need to remove from drawingState when the layer is offscreen since currentState is
2389 // copied to drawingState for the root layer. So the clonedChild is always removed from
2390 // drawingState and then needs to be added back each traversal.
2391 if (!mClonedChild->getClonedFrom()->isRemovedFromCurrentState()) {
2392 addChildToDrawing(mClonedChild);
2393 }
2394
2395 mClonedChild->updateClonedDrawingState(clonedLayersMap);
2396 mClonedChild->updateClonedChildren(this, clonedLayersMap);
2397 mClonedChild->updateClonedRelatives(clonedLayersMap);
2398}
2399
2400void Layer::updateClonedDrawingState(std::map<sp<Layer>, sp<Layer>>& clonedLayersMap) {
2401 // If the layer the clone was cloned from is alive, copy the content of the drawingState
2402 // to the clone. If the real layer is no longer alive, continue traversing the children
2403 // since we may be able to pull out other children that are still alive.
2404 if (isClonedFromAlive()) {
2405 sp<Layer> clonedFrom = getClonedFrom();
2406 mDrawingState = clonedFrom->mDrawingState;
chaviw74b03172019-08-19 11:09:03 -07002407 clonedLayersMap.emplace(clonedFrom, this);
2408 }
2409
2410 // The clone layer may have children in drawingState since they may have been created and
2411 // added from a previous request to updateMirorInfo. This is to ensure we don't recreate clones
2412 // that already exist, since we can just re-use them.
2413 // The drawingChildren will not get overwritten by the currentChildren since the clones are
2414 // not updated in the regular traversal. They are skipped since the root will lose the
2415 // reference to them when it copies its currentChildren to drawing.
2416 for (sp<Layer>& child : mDrawingChildren) {
2417 child->updateClonedDrawingState(clonedLayersMap);
2418 }
2419}
2420
2421void Layer::updateClonedChildren(const sp<Layer>& mirrorRoot,
2422 std::map<sp<Layer>, sp<Layer>>& clonedLayersMap) {
2423 mDrawingChildren.clear();
2424
2425 if (!isClonedFromAlive()) {
2426 return;
2427 }
2428
2429 sp<Layer> clonedFrom = getClonedFrom();
2430 for (sp<Layer>& child : clonedFrom->mDrawingChildren) {
2431 if (child == mirrorRoot) {
2432 // This is to avoid cyclical mirroring.
2433 continue;
2434 }
2435 sp<Layer> clonedChild = clonedLayersMap[child];
2436 if (clonedChild == nullptr) {
2437 clonedChild = child->createClone();
2438 clonedLayersMap[child] = clonedChild;
2439 }
2440 addChildToDrawing(clonedChild);
2441 clonedChild->updateClonedChildren(mirrorRoot, clonedLayersMap);
2442 }
2443}
2444
chaviwaf87b3e2019-10-01 16:59:28 -07002445void Layer::updateClonedInputInfo(const std::map<sp<Layer>, sp<Layer>>& clonedLayersMap) {
2446 auto cropLayer = mDrawingState.touchableRegionCrop.promote();
2447 if (cropLayer != nullptr) {
2448 if (clonedLayersMap.count(cropLayer) == 0) {
2449 // Real layer had a crop layer but it's not in the cloned hierarchy. Just set to
2450 // self as crop layer to avoid going outside bounds.
2451 mDrawingState.touchableRegionCrop = this;
2452 } else {
2453 const sp<Layer>& clonedCropLayer = clonedLayersMap.at(cropLayer);
2454 mDrawingState.touchableRegionCrop = clonedCropLayer;
2455 }
2456 }
2457 // Cloned layers shouldn't handle watch outside since their z order is not determined by
2458 // WM or the client.
chaviw3277faf2021-05-19 16:45:23 -05002459 mDrawingState.inputInfo.flags &= ~WindowInfo::Flag::WATCH_OUTSIDE_TOUCH;
chaviwaf87b3e2019-10-01 16:59:28 -07002460}
2461
2462void Layer::updateClonedRelatives(const std::map<sp<Layer>, sp<Layer>>& clonedLayersMap) {
chaviw74b03172019-08-19 11:09:03 -07002463 mDrawingState.zOrderRelativeOf = nullptr;
2464 mDrawingState.zOrderRelatives.clear();
2465
2466 if (!isClonedFromAlive()) {
2467 return;
2468 }
2469
chaviwaf87b3e2019-10-01 16:59:28 -07002470 const sp<Layer>& clonedFrom = getClonedFrom();
chaviw74b03172019-08-19 11:09:03 -07002471 for (wp<Layer>& relativeWeak : clonedFrom->mDrawingState.zOrderRelatives) {
chaviwaf87b3e2019-10-01 16:59:28 -07002472 const sp<Layer>& relative = relativeWeak.promote();
2473 if (clonedLayersMap.count(relative) > 0) {
2474 auto& clonedRelative = clonedLayersMap.at(relative);
chaviw74b03172019-08-19 11:09:03 -07002475 mDrawingState.zOrderRelatives.add(clonedRelative);
2476 }
2477 }
2478
2479 // Check if the relativeLayer for the real layer is part of the cloned hierarchy.
2480 // It's possible that the layer it's relative to is outside the requested cloned hierarchy.
2481 // In that case, we treat the layer as if the relativeOf has been removed. This way, it will
2482 // still traverse the children, but the layer with the missing relativeOf will not be shown
2483 // on screen.
chaviwaf87b3e2019-10-01 16:59:28 -07002484 const sp<Layer>& relativeOf = clonedFrom->mDrawingState.zOrderRelativeOf.promote();
2485 if (clonedLayersMap.count(relativeOf) > 0) {
2486 const sp<Layer>& clonedRelativeOf = clonedLayersMap.at(relativeOf);
chaviw74b03172019-08-19 11:09:03 -07002487 mDrawingState.zOrderRelativeOf = clonedRelativeOf;
2488 }
2489
chaviwaf87b3e2019-10-01 16:59:28 -07002490 updateClonedInputInfo(clonedLayersMap);
2491
chaviw74b03172019-08-19 11:09:03 -07002492 for (sp<Layer>& child : mDrawingChildren) {
2493 child->updateClonedRelatives(clonedLayersMap);
2494 }
2495}
2496
2497void Layer::addChildToDrawing(const sp<Layer>& layer) {
2498 mDrawingChildren.add(layer);
2499 layer->mDrawingParent = this;
2500}
2501
Steven Thomas62a4cf82020-01-31 12:04:03 -08002502Layer::FrameRateCompatibility Layer::FrameRate::convertCompatibility(int8_t compatibility) {
2503 switch (compatibility) {
2504 case ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT:
2505 return FrameRateCompatibility::Default;
2506 case ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE:
2507 return FrameRateCompatibility::ExactOrMultiple;
Ady Abrahamdd5bfa92021-01-07 17:56:08 -08002508 case ANATIVEWINDOW_FRAME_RATE_EXACT:
2509 return FrameRateCompatibility::Exact;
Steven Thomas62a4cf82020-01-31 12:04:03 -08002510 default:
2511 LOG_ALWAYS_FATAL("Invalid frame rate compatibility value %d", compatibility);
2512 return FrameRateCompatibility::Default;
2513 }
2514}
2515
Marin Shalamanovc5986772021-03-16 16:09:49 +01002516scheduler::Seamlessness Layer::FrameRate::convertChangeFrameRateStrategy(int8_t strategy) {
2517 switch (strategy) {
2518 case ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS:
2519 return Seamlessness::OnlySeamless;
2520 case ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS:
2521 return Seamlessness::SeamedAndSeamless;
2522 default:
2523 LOG_ALWAYS_FATAL("Invalid change frame sate strategy value %d", strategy);
2524 return Seamlessness::Default;
2525 }
2526}
2527
chaviwc5676c62020-09-18 15:01:04 -07002528bool Layer::getPrimaryDisplayOnly() const {
2529 const State& s(mDrawingState);
2530 if (s.flags & layer_state_t::eLayerSkipScreenshot) {
2531 return true;
2532 }
2533
2534 sp<Layer> parent = mDrawingParent.promote();
2535 return parent == nullptr ? false : parent->getPrimaryDisplayOnly();
2536}
2537
Mathias Agopian13127d82013-03-05 17:47:11 -08002538// ---------------------------------------------------------------------------
2539
Marin Shalamanov46084422020-10-13 12:33:42 +02002540std::ostream& operator<<(std::ostream& stream, const Layer::FrameRate& rate) {
2541 return stream << "{rate=" << rate.rate
2542 << " type=" << Layer::frameRateCompatibilityString(rate.type)
Marin Shalamanov53fc11d2020-11-20 14:00:13 +01002543 << " seamlessness=" << toString(rate.seamlessness) << "}";
Marin Shalamanov46084422020-10-13 12:33:42 +02002544}
2545
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002546}; // namespace android
Mathias Agopian3f844832013-08-07 21:24:32 -07002547
2548#if defined(__gl_h_)
2549#error "don't include gl/gl.h in this file"
2550#endif
2551
2552#if defined(__gl2_h_)
2553#error "don't include gl2/gl2.h in this file"
2554#endif
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08002555
2556// TODO(b/129481165): remove the #pragma below and fix conversion issues
2557#pragma clang diagnostic pop // ignored "-Wconversion"