blob: 91be71e3909eba443edd643a4037a5e53b90dfc8 [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
Dan Stoza9e56aa02015-11-02 13:00:03 -080017//#define LOG_NDEBUG 0
18#undef LOG_TAG
19#define LOG_TAG "Layer"
Jamie Gennis1c8e95c2012-02-23 19:27:23 -080020#define ATRACE_TAG ATRACE_TAG_GRAPHICS
21
Mathias Agopian13127d82013-03-05 17:47:11 -080022#include <math.h>
David Sodman41fdfc92017-11-06 16:09:56 -080023#include <stdint.h>
24#include <stdlib.h>
25#include <sys/types.h>
chaviw4b129c22018-04-09 16:19:43 -070026#include <algorithm>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027
Yiwei Zhang5434a782018-12-05 18:06:32 -080028#include <android-base/stringprintf.h>
29
Mathias Agopiana67932f2011-04-20 14:20:59 -070030#include <cutils/compiler.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070031#include <cutils/native_handle.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070032#include <cutils/properties.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033
34#include <utils/Errors.h>
35#include <utils/Log.h>
Jesse Hall399184a2014-03-03 15:42:54 -080036#include <utils/NativeHandle.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037#include <utils/StopWatch.h>
Jamie Gennis1c8e95c2012-02-23 19:27:23 -080038#include <utils/Trace.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080039
Courtney Goeltzenleuchter36c44dc2017-04-14 09:33:16 -060040#include <ui/DebugUtils.h>
Mathias Agopian3330b202009-10-05 17:07:12 -070041#include <ui/GraphicBuffer.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042#include <ui/PixelFormat.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080043
Dan Stoza6b9454d2014-11-07 16:00:59 -080044#include <gui/BufferItem.h>
Kalle Raitaa099a242017-01-11 11:17:29 -080045#include <gui/LayerDebugInfo.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080046#include <gui/Surface.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080047
Yiwei Zhang60d1a192018-03-07 14:52:28 -080048#include "BufferLayer.h"
Mathias Agopian3e25fd82013-04-22 17:52:16 +020049#include "Colorizer.h"
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070050#include "DisplayDevice.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051#include "Layer.h"
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070052#include "LayerRejecter.h"
Dan Stozab9b08832014-03-13 11:55:57 -070053#include "MonitoredProducer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080054#include "SurfaceFlinger.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080055
Mathias Agopian1b031492012-06-20 17:51:20 -070056#include "DisplayHardware/HWComposer.h"
Yiwei Zhang7e666a52018-11-15 13:33:42 -080057#include "TimeStats/TimeStats.h"
Mathias Agopian1b031492012-06-20 17:51:20 -070058
Peiyong Lincbc184f2018-08-22 13:24:10 -070059#include <renderengine/RenderEngine.h>
Mathias Agopian875d8e12013-06-07 15:35:48 -070060
Dan Stozac5da2712016-07-20 15:38:12 -070061#include <mutex>
chaviw1d044282017-09-27 12:19:28 -070062#include "LayerProtoHelper.h"
Dan Stozac5da2712016-07-20 15:38:12 -070063
David Sodman41fdfc92017-11-06 16:09:56 -080064#define DEBUG_RESIZE 0
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080065
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080066namespace android {
67
Yiwei Zhang5434a782018-12-05 18:06:32 -080068using base::StringAppendF;
69
Lloyd Piquef1c675b2018-09-12 20:45:39 -070070std::atomic<int32_t> Layer::sSequence{1};
Mathias Agopian13127d82013-03-05 17:47:11 -080071
Lloyd Pique42ab75e2018-09-12 20:46:03 -070072Layer::Layer(const LayerCreationArgs& args)
73 : mFlinger(args.flinger),
74 mName(args.name),
75 mClientRef(args.client),
76 mBE{this, args.name.string()} {
Mathias Agopiana67932f2011-04-20 14:20:59 -070077 mCurrentCrop.makeInvalid();
Mathias Agopian4d9b8222013-03-12 17:11:48 -070078
79 uint32_t layerFlags = 0;
Lloyd Pique42ab75e2018-09-12 20:46:03 -070080 if (args.flags & ISurfaceComposerClient::eHidden) layerFlags |= layer_state_t::eLayerHidden;
81 if (args.flags & ISurfaceComposerClient::eOpaque) layerFlags |= layer_state_t::eLayerOpaque;
82 if (args.flags & ISurfaceComposerClient::eSecure) layerFlags |= layer_state_t::eLayerSecure;
Mathias Agopian4d9b8222013-03-12 17:11:48 -070083
Dan Stozaf7ba41a2017-05-10 15:11:11 -070084 mTransactionName = String8("TX - ") + mName;
Mathias Agopian4d9b8222013-03-12 17:11:48 -070085
Lloyd Pique42ab75e2018-09-12 20:46:03 -070086 mCurrentState.active_legacy.w = args.w;
87 mCurrentState.active_legacy.h = args.h;
David Sodman0c69cad2017-08-21 12:12:51 -070088 mCurrentState.flags = layerFlags;
Marissa Wallf58c14b2018-07-24 10:50:43 -070089 mCurrentState.active_legacy.transform.set(0, 0);
90 mCurrentState.crop_legacy.makeInvalid();
Marissa Wallf58c14b2018-07-24 10:50:43 -070091 mCurrentState.requestedCrop_legacy = mCurrentState.crop_legacy;
Mathias Agopian4d9b8222013-03-12 17:11:48 -070092 mCurrentState.z = 0;
chaviw13fdc492017-06-27 12:40:18 -070093 mCurrentState.color.a = 1.0f;
Mathias Agopian4d9b8222013-03-12 17:11:48 -070094 mCurrentState.layerStack = 0;
Mathias Agopian4d9b8222013-03-12 17:11:48 -070095 mCurrentState.sequence = 0;
Marissa Wallf58c14b2018-07-24 10:50:43 -070096 mCurrentState.requested_legacy = mCurrentState.active_legacy;
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -050097 mCurrentState.appId = 0;
98 mCurrentState.type = 0;
Marissa Wall861616d2018-10-22 12:52:23 -070099 mCurrentState.active.w = UINT32_MAX;
100 mCurrentState.active.h = UINT32_MAX;
Marissa Wall61c58622018-07-18 10:12:20 -0700101 mCurrentState.active.transform.set(0, 0);
102 mCurrentState.transform = 0;
103 mCurrentState.transformToDisplayInverse = false;
104 mCurrentState.crop.makeInvalid();
105 mCurrentState.acquireFence = new Fence(-1);
106 mCurrentState.dataspace = ui::Dataspace::UNKNOWN;
107 mCurrentState.hdrMetadata.validTypes = 0;
108 mCurrentState.surfaceDamageRegion.clear();
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700109 mCurrentState.cornerRadius = 0.0f;
Marissa Wall61c58622018-07-18 10:12:20 -0700110 mCurrentState.api = -1;
Peiyong Lin747321c2018-10-01 10:03:11 -0700111 mCurrentState.hasColorTransform = false;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700112
113 // drawing state & current state are identical
114 mDrawingState = mCurrentState;
Jamie Gennis6547ff42013-07-16 20:12:42 -0700115
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800116 CompositorTiming compositorTiming;
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700117 args.flinger->getCompositorTiming(&compositorTiming);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800118 mFrameEventHistory.initializeCompositorTiming(compositorTiming);
Jorim Jaggibd6480f2018-08-10 14:37:31 +0200119 mFrameTracker.setDisplayRefreshPeriod(compositorTiming.interval);
Robert Carr2e102c92018-10-23 12:11:15 -0700120
121 mFlinger->onLayerCreated();
Dan Stoza436ccf32018-06-21 12:10:12 -0700122}
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700123
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700124Layer::~Layer() {
David Sodman577c8962017-12-08 14:50:53 -0800125 sp<Client> c(mClientRef.promote());
126 if (c != 0) {
127 c->detachLayer(this);
128 }
129
Jorim Jaggi10c985e2018-10-23 11:17:45 +0000130 mFrameTracker.logAndResetStats(mName);
Robert Carr2e102c92018-10-23 12:11:15 -0700131
chaviw61626f22018-11-15 16:26:27 -0800132 destroyAllHwcLayersPlusChildren();
Robert Carr2e102c92018-10-23 12:11:15 -0700133
134 mFlinger->onLayerDestroyed();
Mathias Agopian96f08192010-06-02 23:28:45 -0700135}
136
Mathias Agopian13127d82013-03-05 17:47:11 -0800137// ---------------------------------------------------------------------------
138// callbacks
139// ---------------------------------------------------------------------------
140
David Sodmaneb085e02017-10-05 18:49:04 -0700141/*
142 * onLayerDisplayed is only meaningful for BufferLayer, but, is called through
143 * Layer. So, the implementation is done in BufferLayer. When called on a
144 * ColorLayer object, it's essentially a NOP.
145 */
David Sodmaneb085e02017-10-05 18:49:04 -0700146void Layer::onLayerDisplayed(const sp<Fence>& /*releaseFence*/) {}
Mathias Agopian13127d82013-03-05 17:47:11 -0800147
Chia-I Wuc6657022017-08-15 11:18:17 -0700148void Layer::onRemovedFromCurrentState() {
Robert Carr2e102c92018-10-23 12:11:15 -0700149 mRemovedFromCurrentState = true;
150
Chia-I Wuc6657022017-08-15 11:18:17 -0700151 // the layer is removed from SF mCurrentState to mLayersPendingRemoval
Robert Carr5edb1ad2017-04-25 10:54:24 -0700152 if (mCurrentState.zOrderRelativeOf != nullptr) {
153 sp<Layer> strongRelative = mCurrentState.zOrderRelativeOf.promote();
154 if (strongRelative != nullptr) {
155 strongRelative->removeZOrderRelative(this);
Chia-I Wuc6657022017-08-15 11:18:17 -0700156 mFlinger->setTransactionFlags(eTraversalNeeded);
Robert Carr5edb1ad2017-04-25 10:54:24 -0700157 }
158 mCurrentState.zOrderRelativeOf = nullptr;
159 }
Rob Carr4bba3702018-10-08 21:53:30 +0000160
Robert Carr2e102c92018-10-23 12:11:15 -0700161 // Since we are no longer reachable from CurrentState SurfaceFlinger
162 // will no longer invoke doTransaction for us, and so we will
163 // never finish applying transactions. We signal the sync point
164 // now so that another layer will not become indefinitely
165 // blocked.
166 for (auto& point: mRemoteSyncPoints) {
167 point->setTransactionApplied();
168 }
169 mRemoteSyncPoints.clear();
170
171 {
172 Mutex::Autolock syncLock(mLocalSyncPointMutex);
173 for (auto& point : mLocalSyncPoints) {
174 point->setFrameAvailable();
175 }
176 mLocalSyncPoints.clear();
177 }
178
Chia-I Wuc6657022017-08-15 11:18:17 -0700179 for (const auto& child : mCurrentChildren) {
180 child->onRemovedFromCurrentState();
181 }
182}
Chia-I Wu38512252017-05-17 14:36:16 -0700183
chaviw61626f22018-11-15 16:26:27 -0800184void Layer::addToCurrentState() {
185 mRemovedFromCurrentState = false;
186
187 for (const auto& child : mCurrentChildren) {
188 child->addToCurrentState();
189 }
190}
191
Mathias Agopian13127d82013-03-05 17:47:11 -0800192// ---------------------------------------------------------------------------
193// set-up
194// ---------------------------------------------------------------------------
195
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700196const String8& Layer::getName() const {
Mathias Agopian13127d82013-03-05 17:47:11 -0800197 return mName;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800198}
199
chaviw13fdc492017-06-27 12:40:18 -0700200bool Layer::getPremultipledAlpha() const {
201 return mPremultipliedAlpha;
202}
203
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700204sp<IBinder> Layer::getHandle() {
Mathias Agopian13127d82013-03-05 17:47:11 -0800205 Mutex::Autolock _l(mLock);
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700206 return new Handle(mFlinger, this);
Mathias Agopian13127d82013-03-05 17:47:11 -0800207}
208
209// ---------------------------------------------------------------------------
210// h/w composer set-up
211// ---------------------------------------------------------------------------
212
Dominik Laskowski075d3172018-05-24 15:50:06 -0700213bool Layer::createHwcLayer(HWComposer* hwc, DisplayId displayId) {
Dominik Laskowski34157762018-10-31 13:07:19 -0700214 LOG_ALWAYS_FATAL_IF(hasHwcLayer(displayId), "Already have a layer for display %s",
215 to_string(displayId).c_str());
David Sodmanb8aaea12017-12-14 15:54:51 -0800216 auto layer = std::shared_ptr<HWC2::Layer>(
217 hwc->createLayer(displayId),
218 [hwc, displayId](HWC2::Layer* layer) {
219 hwc->destroyLayer(displayId, layer); });
Steven Thomasb02664d2017-07-26 18:48:28 -0700220 if (!layer) {
221 return false;
222 }
Dominik Laskowski7e045462018-05-30 13:02:02 -0700223 LayerBE::HWCInfo& hwcInfo = getBE().mHwcLayers[displayId];
Steven Thomasb02664d2017-07-26 18:48:28 -0700224 hwcInfo.hwc = hwc;
225 hwcInfo.layer = layer;
David Sodmanf6a38932018-05-25 15:27:50 -0700226 layer->setLayerDestroyedListener(
Dominik Laskowski7e045462018-05-30 13:02:02 -0700227 [this, displayId](HWC2::Layer* /*layer*/) { getBE().mHwcLayers.erase(displayId); });
Steven Thomasb02664d2017-07-26 18:48:28 -0700228 return true;
229}
230
Dominik Laskowski075d3172018-05-24 15:50:06 -0700231bool Layer::destroyHwcLayer(DisplayId displayId) {
Dominik Laskowski34157762018-10-31 13:07:19 -0700232 if (!hasHwcLayer(displayId)) {
Chia-I Wu83806892017-11-16 10:50:20 -0800233 return false;
Steven Thomasb02664d2017-07-26 18:48:28 -0700234 }
Dominik Laskowski7e045462018-05-30 13:02:02 -0700235 auto& hwcInfo = getBE().mHwcLayers[displayId];
David Sodman41fdfc92017-11-06 16:09:56 -0800236 LOG_ALWAYS_FATAL_IF(hwcInfo.layer == nullptr, "Attempt to destroy null layer");
Steven Thomasb02664d2017-07-26 18:48:28 -0700237 LOG_ALWAYS_FATAL_IF(hwcInfo.hwc == nullptr, "Missing HWComposer");
David Sodmanb8aaea12017-12-14 15:54:51 -0800238 hwcInfo.layer = nullptr;
239
Chia-I Wu83806892017-11-16 10:50:20 -0800240 return true;
Steven Thomasb02664d2017-07-26 18:48:28 -0700241}
242
chaviw61626f22018-11-15 16:26:27 -0800243void Layer::destroyHwcLayersForAllDisplays() {
David Sodman6f65f3e2017-11-03 14:28:09 -0700244 size_t numLayers = getBE().mHwcLayers.size();
Steven Thomasb02664d2017-07-26 18:48:28 -0700245 for (size_t i = 0; i < numLayers; ++i) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700246 LOG_ALWAYS_FATAL_IF(getBE().mHwcLayers.empty(), "destroyAllHwcLayers failed");
247 destroyHwcLayer(getBE().mHwcLayers.begin()->first);
Steven Thomasb02664d2017-07-26 18:48:28 -0700248 }
chaviw61626f22018-11-15 16:26:27 -0800249}
250
251void Layer::destroyAllHwcLayersPlusChildren() {
252 destroyHwcLayersForAllDisplays();
David Sodman6f65f3e2017-11-03 14:28:09 -0700253 LOG_ALWAYS_FATAL_IF(!getBE().mHwcLayers.empty(),
David Sodman41fdfc92017-11-06 16:09:56 -0800254 "All hardware composer layers should have been destroyed");
Robert Carr2e102c92018-10-23 12:11:15 -0700255
256 for (const sp<Layer>& child : mDrawingChildren) {
chaviw61626f22018-11-15 16:26:27 -0800257 child->destroyAllHwcLayersPlusChildren();
Robert Carr2e102c92018-10-23 12:11:15 -0700258 }
Steven Thomasb02664d2017-07-26 18:48:28 -0700259}
Steven Thomasb02664d2017-07-26 18:48:28 -0700260
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800261Rect Layer::getContentCrop() const {
262 // this is the crop rectangle that applies to the buffer
263 // itself (as opposed to the window)
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700264 Rect crop;
265 if (!mCurrentCrop.isEmpty()) {
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800266 // if the buffer crop is defined, we use that
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700267 crop = mCurrentCrop;
Peiyong Lin566a3b42018-01-09 18:22:43 -0800268 } else if (getBE().compositionInfo.mBuffer != nullptr) {
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800269 // otherwise we use the whole buffer
David Sodman0cc69182017-11-17 12:12:07 -0800270 crop = getBE().compositionInfo.mBuffer->getBounds();
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700271 } else {
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800272 // if we don't have a buffer yet, we use an empty/invalid crop
Mathias Agopian4fec8732012-06-29 14:12:52 -0700273 crop.makeInvalid();
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700274 }
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700275 return crop;
276}
277
Mathias Agopianf3e85d42013-05-10 18:01:12 -0700278static Rect reduce(const Rect& win, const Region& exclude) {
279 if (CC_LIKELY(exclude.isEmpty())) {
280 return win;
281 }
282 if (exclude.isRect()) {
283 return win.reduce(exclude.getBounds());
284 }
285 return Region(win).subtract(exclude).getBounds();
286}
287
Dan Stoza80d61162017-12-20 15:57:52 -0800288static FloatRect reduce(const FloatRect& win, const Region& exclude) {
289 if (CC_LIKELY(exclude.isEmpty())) {
290 return win;
291 }
292 // Convert through Rect (by rounding) for lack of FloatRegion
293 return Region(Rect{win}).subtract(exclude).getBounds().toFloatRect();
294}
295
Vishnu Nair51625fa2018-12-06 13:54:33 -0800296Rect Layer::computeScreenBounds(bool reduceTransparentRegion) const {
297 const State& s(getDrawingState());
298 Region transparentRegion = reduceTransparentRegion ? getActiveTransparentRegion(s) : Region();
299 FloatRect bounds = computeBounds(transparentRegion);
Peiyong Linefefaac2018-08-17 12:27:51 -0700300 ui::Transform t = getTransform();
Vishnu Nair60356342018-11-13 13:00:45 -0800301 // Transform to screen space.
302 bounds = t.transform(bounds);
303 return Rect{bounds};
Robert Carr1f0a16a2016-10-24 16:27:39 -0700304}
305
Dan Stoza80d61162017-12-20 15:57:52 -0800306FloatRect Layer::computeBounds() const {
Alec Mourib416efd2018-09-06 21:01:59 +0000307 const State& s(getDrawingState());
Marissa Wall61c58622018-07-18 10:12:20 -0700308 return computeBounds(getActiveTransparentRegion(s));
Michael Lentine6c925ed2014-09-26 17:55:01 -0700309}
310
Dan Stoza80d61162017-12-20 15:57:52 -0800311FloatRect Layer::computeBounds(const Region& activeTransparentRegion) const {
Alec Mourib416efd2018-09-06 21:01:59 +0000312 const State& s(getDrawingState());
Vishnu Nair60356342018-11-13 13:00:45 -0800313 Rect bounds = getCroppedBufferSize(s);
314 FloatRect floatBounds = bounds.toFloatRect();
315 if (bounds.isValid()) {
316 // Layer has bounds. Pass in our bounds as a special case. Then pass on to our parents so
317 // that they can clip it.
318 floatBounds = cropChildBounds(floatBounds);
319 } else {
320 // Layer does not have bounds, so we fill to our parent bounds. This is done by getting our
321 // parent bounds and inverting the transform to get the maximum bounds we can have that
322 // will fit within our parent bounds.
323 const auto& p = mDrawingParent.promote();
324 if (p != nullptr) {
325 ui::Transform t = s.active_legacy.transform;
326 // When calculating the parent bounds for purposes of clipping, we don't need to
327 // constrain the parent to its transparent region. The transparent region is an
328 // optimization based on the buffer contents of the layer, but does not affect the
329 // space allocated to it by policy, and thus children should be allowed to extend into
330 // the parent's transparent region.
331 // One of the main uses is a parent window with a child sitting behind the parent
332 // window, marked by a transparent region. When computing the parent bounds from the
333 // parent's perspective we pass in the transparent region to reduce buffer allocation
334 // size. When computing the parent bounds from the child's perspective, we pass in an
335 // empty transparent region in order to extend into the the parent bounds.
336 floatBounds = p->computeBounds(Region());
337 // Transform back to layer space.
338 floatBounds = t.inverse().transform(floatBounds);
339 }
340 }
Robert Carrb5d3d262016-03-25 15:08:13 -0700341
Vishnu Nair60356342018-11-13 13:00:45 -0800342 // Subtract the transparent region and snap to the bounds.
343 return reduce(floatBounds, activeTransparentRegion);
344}
345
346FloatRect Layer::cropChildBounds(const FloatRect& childBounds) const {
347 const State& s(getDrawingState());
348 Rect bounds = getCroppedBufferSize(s);
349 FloatRect croppedBounds = childBounds;
350
351 // If the layer has bounds, then crop the passed in child bounds and pass
352 // it to our parents so they can crop it as well. If the layer has no bounds,
353 // then pass on the child bounds.
354 if (bounds.isValid()) {
355 croppedBounds = croppedBounds.intersect(bounds.toFloatRect());
Mathias Agopian13127d82013-03-05 17:47:11 -0800356 }
Robert Carr1f0a16a2016-10-24 16:27:39 -0700357
Chia-I Wue41dbe62017-06-13 14:10:56 -0700358 const auto& p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700359 if (p != nullptr) {
Vishnu Nair60356342018-11-13 13:00:45 -0800360 // Transform to parent space and allow parent layer to crop the
361 // child bounds as well.
362 ui::Transform t = s.active_legacy.transform;
363 croppedBounds = t.transform(croppedBounds);
364 croppedBounds = p->cropChildBounds(croppedBounds);
365 croppedBounds = t.inverse().transform(croppedBounds);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700366 }
Vishnu Nair60356342018-11-13 13:00:45 -0800367 return croppedBounds;
368}
Robert Carr1f0a16a2016-10-24 16:27:39 -0700369
Vishnu Nair60356342018-11-13 13:00:45 -0800370Rect Layer::getCroppedBufferSize(const State& s) const {
371 Rect size = getBufferSize(s);
372 Rect crop = getCrop(s);
373 if (!crop.isEmpty() && size.isValid()) {
374 size.intersect(crop, &size);
375 } else if (!crop.isEmpty()) {
376 size = crop;
Robert Carr1f0a16a2016-10-24 16:27:39 -0700377 }
Vishnu Nair60356342018-11-13 13:00:45 -0800378 return size;
Mathias Agopian13127d82013-03-05 17:47:11 -0800379}
380
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700381Rect Layer::computeInitialCrop(const sp<const DisplayDevice>& display) const {
Robert Carrb5d3d262016-03-25 15:08:13 -0700382 // the crop is the area of the window that gets cropped, but not
Mathias Agopian13127d82013-03-05 17:47:11 -0800383 // scaled in any ways.
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700384 const State& s(getDrawingState());
Mathias Agopian13127d82013-03-05 17:47:11 -0800385
386 // apply the projection's clipping to the window crop in
387 // layerstack space, and convert-back to layer space.
Mathias Agopian6b442672013-07-09 21:24:52 -0700388 // if there are no window scaling involved, this operation will map to full
389 // pixels in the buffer.
Mathias Agopian0e8f1442013-08-20 21:41:07 -0700390
Vishnu Nairfb5594c2018-11-28 12:38:35 -0800391 FloatRect activeCropFloat = computeBounds();
Peiyong Linefefaac2018-08-17 12:27:51 -0700392 ui::Transform t = getTransform();
Vishnu Nairfb5594c2018-11-28 12:38:35 -0800393 // Transform to screen space.
394 activeCropFloat = t.transform(activeCropFloat);
395 activeCropFloat = activeCropFloat.intersect(display->getViewport().toFloatRect());
396 // Back to layer space to work with the content crop.
397 activeCropFloat = t.inverse().transform(activeCropFloat);
398 // This needs to be here as transform.transform(Rect) computes the
399 // transformed rect and then takes the bounding box of the result before
400 // returning. This means
401 // transform.inverse().transform(transform.transform(Rect)) != Rect
402 // in which case we need to make sure the final rect is clipped to the
403 // display bounds.
404 Rect activeCrop{activeCropFloat};
405 if (!activeCrop.intersect(getBufferSize(s), &activeCrop)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000406 activeCrop.clear();
407 }
Robert Carr1f0a16a2016-10-24 16:27:39 -0700408 return activeCrop;
409}
410
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700411void Layer::setupRoundedCornersCropCoordinates(Rect win,
412 const FloatRect& roundedCornersCrop) const {
413 // Translate win by the rounded corners rect coordinates, to have all values in
414 // layer coordinate space.
415 win.left -= roundedCornersCrop.left;
416 win.right -= roundedCornersCrop.left;
417 win.top -= roundedCornersCrop.top;
418 win.bottom -= roundedCornersCrop.top;
419
420 renderengine::Mesh::VertexArray<vec2> cropCoords(getBE().mMesh.getCropCoordArray<vec2>());
421 cropCoords[0] = vec2(win.left, win.top);
422 cropCoords[1] = vec2(win.left, win.top + win.getHeight());
423 cropCoords[2] = vec2(win.right, win.top + win.getHeight());
424 cropCoords[3] = vec2(win.right, win.top);
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700425}
426
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700427FloatRect Layer::computeCrop(const sp<const DisplayDevice>& display) const {
Robert Carr1f0a16a2016-10-24 16:27:39 -0700428 // the content crop is the area of the content that gets scaled to the
429 // layer's size. This is in buffer space.
Dan Stoza5a423ea2017-02-16 14:10:39 -0800430 FloatRect crop = getContentCrop().toFloatRect();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700431
432 // In addition there is a WM-specified crop we pull from our drawing state.
433 const State& s(getDrawingState());
434
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700435 Rect activeCrop = computeInitialCrop(display);
Vishnu Nairfb5594c2018-11-28 12:38:35 -0800436 Rect bufferSize = getBufferSize(s);
Mathias Agopianf3e85d42013-05-10 18:01:12 -0700437
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000438 // Transform the window crop to match the buffer coordinate system,
439 // which means using the inverse of the current transform set on the
440 // SurfaceFlingerConsumer.
441 uint32_t invTransform = mCurrentTransform;
Robert Carrcae605c2017-03-29 12:10:31 -0700442 if (getTransformToDisplayInverse()) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000443 /*
Pablo Ceballos021623b2016-04-15 17:31:51 -0700444 * the code below applies the primary display's inverse transform to the
445 * buffer
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000446 */
David Sodman41fdfc92017-11-06 16:09:56 -0800447 uint32_t invTransformOrient = DisplayDevice::getPrimaryDisplayOrientationTransform();
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000448 // calculate the inverse transform
449 if (invTransformOrient & NATIVE_WINDOW_TRANSFORM_ROT_90) {
David Sodman41fdfc92017-11-06 16:09:56 -0800450 invTransformOrient ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H;
Mathias Agopian13127d82013-03-05 17:47:11 -0800451 }
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000452 // and apply to the current transform
Peiyong Linefefaac2018-08-17 12:27:51 -0700453 invTransform = (ui::Transform(invTransformOrient) *
454 ui::Transform(invTransform)).getOrientation();
Mathias Agopian13127d82013-03-05 17:47:11 -0800455 }
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000456
Vishnu Nairfb5594c2018-11-28 12:38:35 -0800457 int winWidth = bufferSize.getWidth();
458 int winHeight = bufferSize.getHeight();
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000459 if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
460 // If the activeCrop has been rotate the ends are rotated but not
461 // the space itself so when transforming ends back we can't rely on
462 // a modification of the axes of rotation. To account for this we
463 // need to reorient the inverse rotation in terms of the current
464 // axes of rotation.
465 bool is_h_flipped = (invTransform & NATIVE_WINDOW_TRANSFORM_FLIP_H) != 0;
466 bool is_v_flipped = (invTransform & NATIVE_WINDOW_TRANSFORM_FLIP_V) != 0;
467 if (is_h_flipped == is_v_flipped) {
David Sodman41fdfc92017-11-06 16:09:56 -0800468 invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H;
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000469 }
Vishnu Nairfb5594c2018-11-28 12:38:35 -0800470 std::swap(winWidth, winHeight);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000471 }
Vishnu Nairfb5594c2018-11-28 12:38:35 -0800472 const Rect winCrop =
473 activeCrop.transform(invTransform, bufferSize.getWidth(), bufferSize.getHeight());
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000474
475 // below, crop is intersected with winCrop expressed in crop's coordinate space
David Sodman41fdfc92017-11-06 16:09:56 -0800476 float xScale = crop.getWidth() / float(winWidth);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000477 float yScale = crop.getHeight() / float(winHeight);
478
David Sodman41fdfc92017-11-06 16:09:56 -0800479 float insetL = winCrop.left * xScale;
480 float insetT = winCrop.top * yScale;
481 float insetR = (winWidth - winCrop.right) * xScale;
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000482 float insetB = (winHeight - winCrop.bottom) * yScale;
483
David Sodman41fdfc92017-11-06 16:09:56 -0800484 crop.left += insetL;
485 crop.top += insetT;
486 crop.right -= insetR;
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000487 crop.bottom -= insetB;
488
Mathias Agopian13127d82013-03-05 17:47:11 -0800489 return crop;
490}
491
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700492void Layer::setGeometry(const sp<const DisplayDevice>& display, uint32_t z) {
Dominik Laskowski7e045462018-05-30 13:02:02 -0700493 const auto displayId = display->getId();
Dominik Laskowski075d3172018-05-24 15:50:06 -0700494 LOG_ALWAYS_FATAL_IF(!displayId);
Dominik Laskowski34157762018-10-31 13:07:19 -0700495 RETURN_IF_NO_HWC_LAYER(*displayId);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700496 auto& hwcInfo = getBE().mHwcLayers[*displayId];
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700497
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700498 // enable this layer
Dan Stoza9e56aa02015-11-02 13:00:03 -0800499 hwcInfo.forceClientComposition = false;
500
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700501 if (isSecure() && !display->isSecure()) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800502 hwcInfo.forceClientComposition = true;
503 }
504
David Sodman15094112018-10-11 09:39:37 -0700505 auto& hwcLayer = hwcInfo.layer;
506
Mathias Agopian13127d82013-03-05 17:47:11 -0800507 // this gives us only the "orientation" component of the transform
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700508 const State& s(getDrawingState());
Vishnu Nairfb5594c2018-11-28 12:38:35 -0800509 const int bufferWidth = getBufferSize(s).getWidth();
510 const int bufferHeight = getBufferSize(s).getHeight();
David Revemanecf0fa52017-03-03 11:32:44 -0500511 auto blendMode = HWC2::BlendMode::None;
Robert Carr6452f122017-03-21 10:41:29 -0700512 if (!isOpaque(s) || getAlpha() != 1.0f) {
David Sodman41fdfc92017-11-06 16:09:56 -0800513 blendMode =
514 mPremultipliedAlpha ? HWC2::BlendMode::Premultiplied : HWC2::BlendMode::Coverage;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800515 }
David Sodman15094112018-10-11 09:39:37 -0700516 auto error = hwcLayer->setBlendMode(blendMode);
517 ALOGE_IF(error != HWC2::Error::None,
518 "[%s] Failed to set blend mode %s:"
519 " %s (%d)",
520 mName.string(), to_string(blendMode).c_str(), to_string(error).c_str(),
521 static_cast<int32_t>(error));
David Sodmanba340492018-08-05 21:51:33 -0700522 getBE().compositionInfo.hwc.blendMode = blendMode;
Mathias Agopian13127d82013-03-05 17:47:11 -0800523
524 // apply the layer's transform, followed by the display's global transform
525 // here we're guaranteed that the layer's transform preserves rects
Marissa Wall61c58622018-07-18 10:12:20 -0700526 Region activeTransparentRegion(getActiveTransparentRegion(s));
Peiyong Linefefaac2018-08-17 12:27:51 -0700527 ui::Transform t = getTransform();
Marissa Wall61c58622018-07-18 10:12:20 -0700528 Rect activeCrop = getCrop(s);
529 if (!activeCrop.isEmpty()) {
Robert Carr1f0a16a2016-10-24 16:27:39 -0700530 activeCrop = t.transform(activeCrop);
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700531 if (!activeCrop.intersect(display->getViewport(), &activeCrop)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000532 activeCrop.clear();
533 }
Robert Carr1f0a16a2016-10-24 16:27:39 -0700534 activeCrop = t.inverse().transform(activeCrop, true);
Michael Lentine28ea2172014-11-19 18:32:37 -0800535 // This needs to be here as transform.transform(Rect) computes the
536 // transformed rect and then takes the bounding box of the result before
537 // returning. This means
538 // transform.inverse().transform(transform.transform(Rect)) != Rect
539 // in which case we need to make sure the final rect is clipped to the
540 // display bounds.
Vishnu Nairfb5594c2018-11-28 12:38:35 -0800541 if (!activeCrop.intersect(Rect(bufferWidth, bufferHeight), &activeCrop)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000542 activeCrop.clear();
543 }
Michael Lentine6c925ed2014-09-26 17:55:01 -0700544 // mark regions outside the crop as transparent
Vishnu Nairfb5594c2018-11-28 12:38:35 -0800545 activeTransparentRegion.orSelf(Rect(0, 0, bufferWidth, activeCrop.top));
546 activeTransparentRegion.orSelf(Rect(0, activeCrop.bottom, bufferWidth, bufferHeight));
David Sodman41fdfc92017-11-06 16:09:56 -0800547 activeTransparentRegion.orSelf(Rect(0, activeCrop.top, activeCrop.left, activeCrop.bottom));
548 activeTransparentRegion.orSelf(
Vishnu Nairfb5594c2018-11-28 12:38:35 -0800549 Rect(activeCrop.right, activeCrop.top, bufferWidth, activeCrop.bottom));
Michael Lentine6c925ed2014-09-26 17:55:01 -0700550 }
Robert Carr1f0a16a2016-10-24 16:27:39 -0700551
Dan Stoza80d61162017-12-20 15:57:52 -0800552 // computeBounds returns a FloatRect to provide more accuracy during the
553 // transformation. We then round upon constructing 'frame'.
554 Rect frame{t.transform(computeBounds(activeTransparentRegion))};
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700555 if (!frame.intersect(display->getViewport(), &frame)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000556 frame.clear();
557 }
Peiyong Linefefaac2018-08-17 12:27:51 -0700558 const ui::Transform& tr = display->getTransform();
Dan Stoza9e56aa02015-11-02 13:00:03 -0800559 Rect transformedFrame = tr.transform(frame);
David Sodman15094112018-10-11 09:39:37 -0700560 error = hwcLayer->setDisplayFrame(transformedFrame);
561 if (error != HWC2::Error::None) {
562 ALOGE("[%s] Failed to set display frame [%d, %d, %d, %d]: %s (%d)", mName.string(),
563 transformedFrame.left, transformedFrame.top, transformedFrame.right,
564 transformedFrame.bottom, to_string(error).c_str(), static_cast<int32_t>(error));
565 } else {
566 hwcInfo.displayFrame = transformedFrame;
567 }
David Sodmanba340492018-08-05 21:51:33 -0700568 getBE().compositionInfo.hwc.displayFrame = transformedFrame;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800569
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700570 FloatRect sourceCrop = computeCrop(display);
David Sodman15094112018-10-11 09:39:37 -0700571 error = hwcLayer->setSourceCrop(sourceCrop);
572 if (error != HWC2::Error::None) {
573 ALOGE("[%s] Failed to set source crop [%.3f, %.3f, %.3f, %.3f]: "
574 "%s (%d)",
575 mName.string(), sourceCrop.left, sourceCrop.top, sourceCrop.right, sourceCrop.bottom,
576 to_string(error).c_str(), static_cast<int32_t>(error));
577 } else {
578 hwcInfo.sourceCrop = sourceCrop;
579 }
David Sodmanba340492018-08-05 21:51:33 -0700580 getBE().compositionInfo.hwc.sourceCrop = sourceCrop;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800581
chaviw13fdc492017-06-27 12:40:18 -0700582 float alpha = static_cast<float>(getAlpha());
David Sodman15094112018-10-11 09:39:37 -0700583 error = hwcLayer->setPlaneAlpha(alpha);
584 ALOGE_IF(error != HWC2::Error::None,
585 "[%s] Failed to set plane alpha %.3f: "
586 "%s (%d)",
587 mName.string(), alpha, to_string(error).c_str(), static_cast<int32_t>(error));
David Sodmanba340492018-08-05 21:51:33 -0700588 getBE().compositionInfo.hwc.alpha = alpha;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800589
David Sodman15094112018-10-11 09:39:37 -0700590 error = hwcLayer->setZOrder(z);
591 ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set Z %u: %s (%d)", mName.string(), z,
592 to_string(error).c_str(), static_cast<int32_t>(error));
David Sodmanba340492018-08-05 21:51:33 -0700593 getBE().compositionInfo.hwc.z = z;
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -0500594
Albert Chaulk2a589632017-05-04 16:59:44 -0400595 int type = s.type;
596 int appId = s.appId;
Chia-I Wue41dbe62017-06-13 14:10:56 -0700597 sp<Layer> parent = mDrawingParent.promote();
Albert Chaulk2a589632017-05-04 16:59:44 -0400598 if (parent.get()) {
599 auto& parentState = parent->getDrawingState();
rongliucfb187b2018-03-14 12:26:23 -0700600 if (parentState.type >= 0 || parentState.appId >= 0) {
601 type = parentState.type;
602 appId = parentState.appId;
603 }
Albert Chaulk2a589632017-05-04 16:59:44 -0400604 }
605
David Sodman15094112018-10-11 09:39:37 -0700606 error = hwcLayer->setInfo(type, appId);
607 ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set info (%d)", mName.string(),
608 static_cast<int32_t>(error));
609
David Sodmanba340492018-08-05 21:51:33 -0700610 getBE().compositionInfo.hwc.type = type;
611 getBE().compositionInfo.hwc.appId = appId;
612
Mathias Agopian29a367b2011-07-12 14:51:45 -0700613 /*
614 * Transformations are applied in this order:
615 * 1) buffer orientation/flip/mirror
616 * 2) state transformation (window manager)
617 * 3) layer orientation (screen orientation)
618 * (NOTE: the matrices are multiplied in reverse order)
619 */
620
Peiyong Linefefaac2018-08-17 12:27:51 -0700621 const ui::Transform bufferOrientation(mCurrentTransform);
622 ui::Transform transform(tr * t * bufferOrientation);
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700623
Robert Carrcae605c2017-03-29 12:10:31 -0700624 if (getTransformToDisplayInverse()) {
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700625 /*
Pablo Ceballos021623b2016-04-15 17:31:51 -0700626 * the code below applies the primary display's inverse transform to the
627 * buffer
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700628 */
David Sodman41fdfc92017-11-06 16:09:56 -0800629 uint32_t invTransform = DisplayDevice::getPrimaryDisplayOrientationTransform();
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700630 // calculate the inverse transform
631 if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
David Sodman41fdfc92017-11-06 16:09:56 -0800632 invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700633 }
Robert Carrcae605c2017-03-29 12:10:31 -0700634
635 /*
636 * Here we cancel out the orientation component of the WM transform.
637 * The scaling and translate components are already included in our bounds
638 * computation so it's enough to just omit it in the composition.
639 * See comment in onDraw with ref to b/36727915 for why.
640 */
Peiyong Linefefaac2018-08-17 12:27:51 -0700641 transform = ui::Transform(invTransform) * tr * bufferOrientation;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700642 }
Mathias Agopian29a367b2011-07-12 14:51:45 -0700643
644 // this gives us only the "orientation" component of the transform
Mathias Agopian13127d82013-03-05 17:47:11 -0800645 const uint32_t orientation = transform.getOrientation();
Peiyong Linefefaac2018-08-17 12:27:51 -0700646 if (orientation & ui::Transform::ROT_INVALID) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800647 // we can only handle simple transformation
Lloyd Pique074e8122018-07-26 12:57:23 -0700648 hwcInfo.forceClientComposition = true;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700649 getBE().mHwcLayers[*displayId].compositionType = HWC2::Composition::Client;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800650 } else {
651 auto transform = static_cast<HWC2::Transform>(orientation);
Yiwei Zhang7124ad32018-02-21 13:02:45 -0800652 hwcInfo.transform = transform;
David Sodman15094112018-10-11 09:39:37 -0700653 auto error = hwcLayer->setTransform(transform);
654 ALOGE_IF(error != HWC2::Error::None,
655 "[%s] Failed to set transform %s: "
656 "%s (%d)",
657 mName.string(), to_string(transform).c_str(), to_string(error).c_str(),
658 static_cast<int32_t>(error));
David Sodmanba340492018-08-05 21:51:33 -0700659 getBE().compositionInfo.hwc.transform = transform;
David Sodman4b7c4bc2017-11-17 12:13:59 -0800660 }
661}
662
Dominik Laskowski075d3172018-05-24 15:50:06 -0700663void Layer::forceClientComposition(DisplayId displayId) {
Dominik Laskowski34157762018-10-31 13:07:19 -0700664 RETURN_IF_NO_HWC_LAYER(displayId);
Dominik Laskowski7e045462018-05-30 13:02:02 -0700665 getBE().mHwcLayers[displayId].forceClientComposition = true;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800666}
Dan Stozaee44edd2015-03-23 15:50:23 -0700667
Dominik Laskowski075d3172018-05-24 15:50:06 -0700668bool Layer::getForceClientComposition(DisplayId displayId) {
Dominik Laskowski34157762018-10-31 13:07:19 -0700669 RETURN_IF_NO_HWC_LAYER(displayId, false);
Dominik Laskowski7e045462018-05-30 13:02:02 -0700670 return getBE().mHwcLayers[displayId].forceClientComposition;
chaviwc9232ed2017-11-14 15:31:15 -0800671}
672
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700673void Layer::updateCursorPosition(const sp<const DisplayDevice>& display) {
Dominik Laskowski7e045462018-05-30 13:02:02 -0700674 const auto displayId = display->getId();
Dominik Laskowski34157762018-10-31 13:07:19 -0700675 LOG_ALWAYS_FATAL_IF(!displayId);
676 if (!hasHwcLayer(*displayId) || getCompositionType(displayId) != HWC2::Composition::Cursor) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800677 return;
678 }
679
680 // This gives us only the "orientation" component of the transform
681 const State& s(getCurrentState());
682
683 // Apply the layer's transform, followed by the display's global transform
684 // Here we're guaranteed that the layer's transform preserves rects
Vishnu Nairfb5594c2018-11-28 12:38:35 -0800685 Rect win = getCroppedBufferSize(s);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800686 // Subtract the transparent region and snap to the bounds
Marissa Wall61c58622018-07-18 10:12:20 -0700687 Rect bounds = reduce(win, getActiveTransparentRegion(s));
Robert Carr1f0a16a2016-10-24 16:27:39 -0700688 Rect frame(getTransform().transform(bounds));
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700689 frame.intersect(display->getViewport(), &frame);
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700690 auto& displayTransform = display->getTransform();
Dan Stoza9e56aa02015-11-02 13:00:03 -0800691 auto position = displayTransform.transform(frame);
692
Dominik Laskowski7e045462018-05-30 13:02:02 -0700693 auto error =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700694 getBE().mHwcLayers[*displayId].layer->setCursorPosition(position.left, position.top);
695
David Sodman41fdfc92017-11-06 16:09:56 -0800696 ALOGE_IF(error != HWC2::Error::None,
697 "[%s] Failed to set cursor position "
698 "to (%d, %d): %s (%d)",
699 mName.string(), position.left, position.top, to_string(error).c_str(),
700 static_cast<int32_t>(error));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800701}
Riley Andrews03414a12014-07-01 14:22:59 -0700702
Mathias Agopian13127d82013-03-05 17:47:11 -0800703// ---------------------------------------------------------------------------
704// drawing...
705// ---------------------------------------------------------------------------
706
Marissa Wall61c58622018-07-18 10:12:20 -0700707void Layer::draw(const RenderArea& renderArea, const Region& clip) {
chaviwa76b2712017-09-20 12:02:26 -0700708 onDraw(renderArea, clip, false);
Mathias Agopian13127d82013-03-05 17:47:11 -0800709}
710
Marissa Wall61c58622018-07-18 10:12:20 -0700711void Layer::draw(const RenderArea& renderArea, bool useIdentityTransform) {
chaviwa76b2712017-09-20 12:02:26 -0700712 onDraw(renderArea, Region(renderArea.getBounds()), useIdentityTransform);
Mathias Agopian13127d82013-03-05 17:47:11 -0800713}
714
David Sodman41fdfc92017-11-06 16:09:56 -0800715void Layer::clearWithOpenGL(const RenderArea& renderArea, float red, float green, float blue,
716 float alpha) const {
Lloyd Pique144e1162017-12-20 16:44:52 -0800717 auto& engine(mFlinger->getRenderEngine());
David Sodman9eeae692017-11-02 10:53:32 -0700718 computeGeometry(renderArea, getBE().mMesh, false);
Mathias Agopian19733a32013-08-28 18:13:56 -0700719 engine.setupFillWithColor(red, green, blue, alpha);
David Sodman9eeae692017-11-02 10:53:32 -0700720 engine.drawMesh(getBE().mMesh);
Mathias Agopian13127d82013-03-05 17:47:11 -0800721}
722
David Sodmanc1498e62018-09-12 14:36:26 -0700723void Layer::clearWithOpenGL(const RenderArea& renderArea) const {
724 clearWithOpenGL(renderArea, 0, 0, 0, 0);
725}
726
Dominik Laskowski075d3172018-05-24 15:50:06 -0700727void Layer::setCompositionType(DisplayId displayId, HWC2::Composition type, bool callIntoHwc) {
Dominik Laskowski7e045462018-05-30 13:02:02 -0700728 if (getBE().mHwcLayers.count(displayId) == 0) {
Chia-I Wu30505fb2018-03-26 16:20:31 -0700729 ALOGE("setCompositionType called without a valid HWC layer");
730 return;
David Sodman15094112018-10-11 09:39:37 -0700731 }
732 auto& hwcInfo = getBE().mHwcLayers[displayId];
733 auto& hwcLayer = hwcInfo.layer;
734 ALOGV("setCompositionType(%" PRIx64 ", %s, %d)", (hwcLayer)->getId(), to_string(type).c_str(),
735 static_cast<int>(callIntoHwc));
736 if (hwcInfo.compositionType != type) {
737 ALOGV(" actually setting");
738 hwcInfo.compositionType = type;
739 if (callIntoHwc) {
740 auto error = (hwcLayer)->setCompositionType(type);
741 ALOGE_IF(error != HWC2::Error::None,
742 "[%s] Failed to set "
743 "composition type %s: %s (%d)",
744 mName.string(), to_string(type).c_str(), to_string(error).c_str(),
745 static_cast<int32_t>(error));
Chia-I Wu30505fb2018-03-26 16:20:31 -0700746 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800747 }
748}
749
Dominik Laskowski075d3172018-05-24 15:50:06 -0700750HWC2::Composition Layer::getCompositionType(const std::optional<DisplayId>& displayId) const {
751 if (!displayId) {
Dan Stozaec0f7172016-07-21 11:09:40 -0700752 // If we're querying the composition type for a display that does not
753 // have a HWC counterpart, then it will always be Client
754 return HWC2::Composition::Client;
755 }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700756 if (getBE().mHwcLayers.count(*displayId) == 0) {
757 ALOGE("getCompositionType called with an invalid HWC layer");
758 return HWC2::Composition::Invalid;
759 }
760 return getBE().mHwcLayers.at(*displayId).compositionType;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800761}
762
Dominik Laskowski075d3172018-05-24 15:50:06 -0700763void Layer::setClearClientTarget(DisplayId displayId, bool clear) {
Dominik Laskowski7e045462018-05-30 13:02:02 -0700764 if (getBE().mHwcLayers.count(displayId) == 0) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800765 ALOGE("setClearClientTarget called without a valid HWC layer");
766 return;
767 }
Dominik Laskowski7e045462018-05-30 13:02:02 -0700768 getBE().mHwcLayers[displayId].clearClientTarget = clear;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800769}
770
Dominik Laskowski075d3172018-05-24 15:50:06 -0700771bool Layer::getClearClientTarget(DisplayId displayId) const {
Dominik Laskowski7e045462018-05-30 13:02:02 -0700772 if (getBE().mHwcLayers.count(displayId) == 0) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800773 ALOGE("getClearClientTarget called without a valid HWC layer");
774 return false;
775 }
Dominik Laskowski7e045462018-05-30 13:02:02 -0700776 return getBE().mHwcLayers.at(displayId).clearClientTarget;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800777}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800778
Dan Stozacac35382016-01-27 12:21:06 -0800779bool Layer::addSyncPoint(const std::shared_ptr<SyncPoint>& point) {
780 if (point->getFrameNumber() <= mCurrentFrameNumber) {
781 // Don't bother with a SyncPoint, since we've already latched the
782 // relevant frame
783 return false;
Dan Stoza7dde5992015-05-22 09:51:44 -0700784 }
Robert Carr2e102c92018-10-23 12:11:15 -0700785 if (isRemovedFromCurrentState()) {
786 return false;
787 }
Dan Stoza7dde5992015-05-22 09:51:44 -0700788
Dan Stozacac35382016-01-27 12:21:06 -0800789 Mutex::Autolock lock(mLocalSyncPointMutex);
790 mLocalSyncPoints.push_back(point);
791 return true;
Dan Stoza7dde5992015-05-22 09:51:44 -0700792}
793
Mathias Agopian13127d82013-03-05 17:47:11 -0800794// ----------------------------------------------------------------------------
795// local state
796// ----------------------------------------------------------------------------
797
Peiyong Lin833074a2018-08-28 11:53:54 -0700798void Layer::computeGeometry(const RenderArea& renderArea,
799 renderengine::Mesh& mesh,
chaviwa76b2712017-09-20 12:02:26 -0700800 bool useIdentityTransform) const {
Peiyong Linefefaac2018-08-17 12:27:51 -0700801 const ui::Transform renderAreaTransform(renderArea.getTransform());
Dan Stoza80d61162017-12-20 15:57:52 -0800802 FloatRect win = computeBounds();
Mathias Agopian3f844832013-08-07 21:24:32 -0700803
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000804 vec2 lt = vec2(win.left, win.top);
805 vec2 lb = vec2(win.left, win.bottom);
806 vec2 rb = vec2(win.right, win.bottom);
807 vec2 rt = vec2(win.right, win.top);
808
Peiyong Linefefaac2018-08-17 12:27:51 -0700809 ui::Transform layerTransform = getTransform();
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000810 if (!useIdentityTransform) {
Robert Carr1f0a16a2016-10-24 16:27:39 -0700811 lt = layerTransform.transform(lt);
812 lb = layerTransform.transform(lb);
813 rb = layerTransform.transform(rb);
814 rt = layerTransform.transform(rt);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000815 }
816
Peiyong Lin833074a2018-08-28 11:53:54 -0700817 renderengine::Mesh::VertexArray<vec2> position(mesh.getPositionArray<vec2>());
chaviwa76b2712017-09-20 12:02:26 -0700818 position[0] = renderAreaTransform.transform(lt);
819 position[1] = renderAreaTransform.transform(lb);
820 position[2] = renderAreaTransform.transform(rb);
821 position[3] = renderAreaTransform.transform(rt);
Mathias Agopian13127d82013-03-05 17:47:11 -0800822}
Eric Hassoldac45e6b2011-02-10 14:41:26 -0800823
David Sodman41fdfc92017-11-06 16:09:56 -0800824bool Layer::isSecure() const {
Alec Mourib416efd2018-09-06 21:01:59 +0000825 const State& s(mDrawingState);
Dan Stoza23116082015-06-18 14:58:39 -0700826 return (s.flags & layer_state_t::eLayerSecure);
827}
828
Mathias Agopian13127d82013-03-05 17:47:11 -0800829void Layer::setVisibleRegion(const Region& visibleRegion) {
830 // always called from main thread
831 this->visibleRegion = visibleRegion;
832}
833
834void Layer::setCoveredRegion(const Region& coveredRegion) {
835 // always called from main thread
836 this->coveredRegion = coveredRegion;
837}
838
David Sodman41fdfc92017-11-06 16:09:56 -0800839void Layer::setVisibleNonTransparentRegion(const Region& setVisibleNonTransparentRegion) {
Mathias Agopian13127d82013-03-05 17:47:11 -0800840 // always called from main thread
841 this->visibleNonTransparentRegion = setVisibleNonTransparentRegion;
842}
843
Robert Carre5f4f692018-01-12 13:12:28 -0800844void Layer::clearVisibilityRegions() {
845 visibleRegion.clear();
846 visibleNonTransparentRegion.clear();
847 coveredRegion.clear();
848}
849
Mathias Agopian13127d82013-03-05 17:47:11 -0800850// ----------------------------------------------------------------------------
851// transaction
852// ----------------------------------------------------------------------------
853
Dan Stoza7dde5992015-05-22 09:51:44 -0700854void Layer::pushPendingState() {
855 if (!mCurrentState.modified) {
856 return;
857 }
858
Dan Stoza7dde5992015-05-22 09:51:44 -0700859 // If this transaction is waiting on the receipt of a frame, generate a sync
860 // point and send it to the remote layer.
Robert Carr2e102c92018-10-23 12:11:15 -0700861 // We don't allow installing sync points after we are removed from the current state
862 // as we won't be able to signal our end.
863 if (mCurrentState.barrierLayer_legacy != nullptr && !isRemovedFromCurrentState()) {
Marissa Wallf58c14b2018-07-24 10:50:43 -0700864 sp<Layer> barrierLayer = mCurrentState.barrierLayer_legacy.promote();
Robert Carr0d480722017-01-10 16:42:54 -0800865 if (barrierLayer == nullptr) {
866 ALOGE("[%s] Unable to promote barrier Layer.", mName.string());
Dan Stoza7dde5992015-05-22 09:51:44 -0700867 // If we can't promote the layer we are intended to wait on,
868 // then it is expired or otherwise invalid. Allow this transaction
869 // to be applied as per normal (no synchronization).
Marissa Wallf58c14b2018-07-24 10:50:43 -0700870 mCurrentState.barrierLayer_legacy = nullptr;
Pablo Ceballos3bddd5b2015-11-19 14:39:14 -0800871 } else {
Marissa Wallf58c14b2018-07-24 10:50:43 -0700872 auto syncPoint = std::make_shared<SyncPoint>(mCurrentState.frameNumber_legacy);
Robert Carr0d480722017-01-10 16:42:54 -0800873 if (barrierLayer->addSyncPoint(syncPoint)) {
Dan Stozacac35382016-01-27 12:21:06 -0800874 mRemoteSyncPoints.push_back(std::move(syncPoint));
875 } else {
876 // We already missed the frame we're supposed to synchronize
877 // on, so go ahead and apply the state update
Marissa Wallf58c14b2018-07-24 10:50:43 -0700878 mCurrentState.barrierLayer_legacy = nullptr;
Dan Stozacac35382016-01-27 12:21:06 -0800879 }
Dan Stoza7dde5992015-05-22 09:51:44 -0700880 }
881
Dan Stoza7dde5992015-05-22 09:51:44 -0700882 // Wake us up to check if the frame has been received
883 setTransactionFlags(eTransactionNeeded);
Dan Stozaf5702ff2016-11-02 16:27:47 -0700884 mFlinger->setTransactionFlags(eTraversalNeeded);
Dan Stoza7dde5992015-05-22 09:51:44 -0700885 }
886 mPendingStates.push_back(mCurrentState);
Dan Stozaf7ba41a2017-05-10 15:11:11 -0700887 ATRACE_INT(mTransactionName.string(), mPendingStates.size());
Dan Stoza7dde5992015-05-22 09:51:44 -0700888}
889
Pablo Ceballos05289c22016-04-14 15:49:55 -0700890void Layer::popPendingState(State* stateToCommit) {
Pablo Ceballos05289c22016-04-14 15:49:55 -0700891 *stateToCommit = mPendingStates[0];
Dan Stoza7dde5992015-05-22 09:51:44 -0700892
893 mPendingStates.removeAt(0);
Dan Stozaf7ba41a2017-05-10 15:11:11 -0700894 ATRACE_INT(mTransactionName.string(), mPendingStates.size());
Dan Stoza7dde5992015-05-22 09:51:44 -0700895}
896
Pablo Ceballos05289c22016-04-14 15:49:55 -0700897bool Layer::applyPendingStates(State* stateToCommit) {
Dan Stoza7dde5992015-05-22 09:51:44 -0700898 bool stateUpdateAvailable = false;
899 while (!mPendingStates.empty()) {
Marissa Wallf58c14b2018-07-24 10:50:43 -0700900 if (mPendingStates[0].barrierLayer_legacy != nullptr) {
Dan Stoza7dde5992015-05-22 09:51:44 -0700901 if (mRemoteSyncPoints.empty()) {
902 // If we don't have a sync point for this, apply it anyway. It
903 // will be visually wrong, but it should keep us from getting
904 // into too much trouble.
905 ALOGE("[%s] No local sync point found", mName.string());
Pablo Ceballos05289c22016-04-14 15:49:55 -0700906 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -0700907 stateUpdateAvailable = true;
908 continue;
909 }
910
Marissa Wallf58c14b2018-07-24 10:50:43 -0700911 if (mRemoteSyncPoints.front()->getFrameNumber() !=
912 mPendingStates[0].frameNumber_legacy) {
David Sodman41fdfc92017-11-06 16:09:56 -0800913 ALOGE("[%s] Unexpected sync point frame number found", mName.string());
Dan Stozacac35382016-01-27 12:21:06 -0800914
915 // Signal our end of the sync point and then dispose of it
916 mRemoteSyncPoints.front()->setTransactionApplied();
917 mRemoteSyncPoints.pop_front();
918 continue;
919 }
920
Dan Stoza7dde5992015-05-22 09:51:44 -0700921 if (mRemoteSyncPoints.front()->frameIsAvailable()) {
922 // Apply the state update
Pablo Ceballos05289c22016-04-14 15:49:55 -0700923 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -0700924 stateUpdateAvailable = true;
925
926 // Signal our end of the sync point and then dispose of it
927 mRemoteSyncPoints.front()->setTransactionApplied();
928 mRemoteSyncPoints.pop_front();
Dan Stoza792e5292016-02-11 11:43:58 -0800929 } else {
930 break;
Dan Stoza7dde5992015-05-22 09:51:44 -0700931 }
Dan Stoza7dde5992015-05-22 09:51:44 -0700932 } else {
Pablo Ceballos05289c22016-04-14 15:49:55 -0700933 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -0700934 stateUpdateAvailable = true;
935 }
936 }
937
938 // If we still have pending updates, wake SurfaceFlinger back up and point
939 // it at this layer so we can process them
940 if (!mPendingStates.empty()) {
941 setTransactionFlags(eTransactionNeeded);
942 mFlinger->setTransactionFlags(eTraversalNeeded);
943 }
944
945 mCurrentState.modified = false;
946 return stateUpdateAvailable;
947}
948
Marissa Wall61c58622018-07-18 10:12:20 -0700949uint32_t Layer::doTransactionResize(uint32_t flags, State* stateToCommit) {
Alec Mourib416efd2018-09-06 21:01:59 +0000950 const State& s(getDrawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800951
Marissa Wall61c58622018-07-18 10:12:20 -0700952 const bool sizeChanged = (stateToCommit->requested_legacy.w != s.requested_legacy.w) ||
953 (stateToCommit->requested_legacy.h != s.requested_legacy.h);
Mathias Agopiana138f892010-05-21 17:24:35 -0700954
David Sodmaneb085e02017-10-05 18:49:04 -0700955 if (sizeChanged) {
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700956 // the size changed, we need to ask our client to request a new buffer
Steve Block9d453682011-12-20 16:23:08 +0000957 ALOGD_IF(DEBUG_RESIZE,
David Sodman41fdfc92017-11-06 16:09:56 -0800958 "doTransaction: geometry (layer=%p '%s'), tr=%02x, scalingMode=%d\n"
959 " current={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
960 " requested={ wh={%4u,%4u} }}\n"
961 " drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
962 " requested={ wh={%4u,%4u} }}\n",
Marissa Wallf58c14b2018-07-24 10:50:43 -0700963 this, getName().string(), mCurrentTransform, getEffectiveScalingMode(),
Marissa Wall61c58622018-07-18 10:12:20 -0700964 stateToCommit->active_legacy.w, stateToCommit->active_legacy.h,
965 stateToCommit->crop_legacy.left, stateToCommit->crop_legacy.top,
966 stateToCommit->crop_legacy.right, stateToCommit->crop_legacy.bottom,
967 stateToCommit->crop_legacy.getWidth(), stateToCommit->crop_legacy.getHeight(),
968 stateToCommit->requested_legacy.w, stateToCommit->requested_legacy.h,
Marissa Wallf58c14b2018-07-24 10:50:43 -0700969 s.active_legacy.w, s.active_legacy.h, s.crop_legacy.left, s.crop_legacy.top,
970 s.crop_legacy.right, s.crop_legacy.bottom, s.crop_legacy.getWidth(),
971 s.crop_legacy.getHeight(), s.requested_legacy.w, s.requested_legacy.h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800972 }
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700973
Robert Carre392b552017-09-19 12:16:05 -0700974 // Don't let Layer::doTransaction update the drawing state
975 // if we have a pending resize, unless we are in fixed-size mode.
976 // the drawing state will be updated only once we receive a buffer
977 // with the correct size.
978 //
979 // In particular, we want to make sure the clip (which is part
980 // of the geometry state) is latched together with the size but is
981 // latched immediately when no resizing is involved.
982 //
983 // If a sideband stream is attached, however, we want to skip this
984 // optimization so that transactions aren't missed when a buffer
985 // never arrives
986 //
987 // In the case that we don't have a buffer we ignore other factors
988 // and avoid entering the resizePending state. At a high level the
989 // resizePending state is to avoid applying the state of the new buffer
990 // to the old buffer. However in the state where we don't have an old buffer
991 // there is no such concern but we may still be being used as a parent layer.
Marissa Wall61c58622018-07-18 10:12:20 -0700992 const bool resizePending =
993 ((stateToCommit->requested_legacy.w != stateToCommit->active_legacy.w) ||
994 (stateToCommit->requested_legacy.h != stateToCommit->active_legacy.h)) &&
David Sodman0cc69182017-11-17 12:12:07 -0800995 (getBE().compositionInfo.mBuffer != nullptr);
Mathias Agopian0cd545f2012-06-07 14:18:55 -0700996 if (!isFixedSize()) {
David Sodman0cc69182017-11-17 12:12:07 -0800997 if (resizePending && getBE().compositionInfo.hwc.sidebandStream == nullptr) {
Mathias Agopian0cd545f2012-06-07 14:18:55 -0700998 flags |= eDontUpdateGeometryState;
999 }
1000 }
1001
Robert Carr7bf247e2017-05-18 14:02:49 -07001002 // Here we apply various requested geometry states, depending on our
1003 // latching configuration. See Layer.h for a detailed discussion of
1004 // how geometry latching is controlled.
1005 if (!(flags & eDontUpdateGeometryState)) {
Alec Mourib416efd2018-09-06 21:01:59 +00001006 State& editCurrentState(getCurrentState());
Robert Carr7bf247e2017-05-18 14:02:49 -07001007
1008 // If mFreezeGeometryUpdates is true we are in the setGeometryAppliesWithResize
1009 // mode, which causes attributes which normally latch regardless of scaling mode,
1010 // to be delayed. We copy the requested state to the active state making sure
1011 // to respect these rules (again see Layer.h for a detailed discussion).
1012 //
1013 // There is an awkward asymmetry in the handling of the crop states in the position
1014 // states, as can be seen below. Largely this arises from position and transform
1015 // being stored in the same data structure while having different latching rules.
1016 // b/38182305
1017 //
Marissa Wall61c58622018-07-18 10:12:20 -07001018 // Careful that "stateToCommit" and editCurrentState may not begin as equivalent due to
Robert Carr7bf247e2017-05-18 14:02:49 -07001019 // applyPendingStates in the presence of deferred transactions.
1020 if (mFreezeGeometryUpdates) {
Marissa Wall61c58622018-07-18 10:12:20 -07001021 float tx = stateToCommit->active_legacy.transform.tx();
1022 float ty = stateToCommit->active_legacy.transform.ty();
1023 stateToCommit->active_legacy = stateToCommit->requested_legacy;
1024 stateToCommit->active_legacy.transform.set(tx, ty);
1025 editCurrentState.active_legacy = stateToCommit->active_legacy;
Robert Carr82364e32016-05-15 11:27:47 -07001026 } else {
Marissa Wallf58c14b2018-07-24 10:50:43 -07001027 editCurrentState.active_legacy = editCurrentState.requested_legacy;
Marissa Wall61c58622018-07-18 10:12:20 -07001028 stateToCommit->active_legacy = stateToCommit->requested_legacy;
Robert Carr82364e32016-05-15 11:27:47 -07001029 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001030 }
1031
Marissa Wall61c58622018-07-18 10:12:20 -07001032 return flags;
1033}
1034
1035uint32_t Layer::doTransaction(uint32_t flags) {
1036 ATRACE_CALL();
1037
chaviw5aedec92018-10-22 10:40:38 -07001038 if (mLayerDetached) {
1039 return 0;
1040 }
1041
Marissa Wall61c58622018-07-18 10:12:20 -07001042 pushPendingState();
Alec Mourib416efd2018-09-06 21:01:59 +00001043 State c = getCurrentState();
Marissa Wall61c58622018-07-18 10:12:20 -07001044 if (!applyPendingStates(&c)) {
1045 return 0;
1046 }
1047
1048 flags = doTransactionResize(flags, &c);
1049
Alec Mourib416efd2018-09-06 21:01:59 +00001050 const State& s(getDrawingState());
Marissa Wall61c58622018-07-18 10:12:20 -07001051
1052 if (getActiveGeometry(c) != getActiveGeometry(s)) {
Mathias Agopian13127d82013-03-05 17:47:11 -08001053 // invalidate and recompute the visible regions if needed
1054 flags |= Layer::eVisibleRegion;
1055 }
1056
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001057 if (c.sequence != s.sequence) {
Mathias Agopian13127d82013-03-05 17:47:11 -08001058 // invalidate and recompute the visible regions if needed
1059 flags |= eVisibleRegion;
1060 this->contentDirty = true;
1061
1062 // we may use linear filtering, if the matrix scales us
Marissa Wall61c58622018-07-18 10:12:20 -07001063 const uint8_t type = getActiveTransform(c).getType();
Peiyong Linefefaac2018-08-17 12:27:51 -07001064 mNeedsFiltering = (!getActiveTransform(c).preserveRects() || type >= ui::Transform::SCALE);
Mathias Agopian13127d82013-03-05 17:47:11 -08001065 }
1066
Dan Stozac8145172016-04-28 16:29:06 -07001067 // If the layer is hidden, signal and clear out all local sync points so
1068 // that transactions for layers depending on this layer's frames becoming
1069 // visible are not blocked
1070 if (c.flags & layer_state_t::eLayerHidden) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001071 clearSyncPoints();
Dan Stozac8145172016-04-28 16:29:06 -07001072 }
1073
Robert Carr720e5062018-07-30 17:45:14 -07001074 if (mCurrentState.inputInfoChanged) {
1075 flags |= eInputInfoChanged;
1076 mCurrentState.inputInfoChanged = false;
1077 }
1078
Mathias Agopian13127d82013-03-05 17:47:11 -08001079 // Commit the transaction
Pablo Ceballos05289c22016-04-14 15:49:55 -07001080 commitTransaction(c);
Marissa Walle2ffb422018-10-12 11:33:52 -07001081 mCurrentState.callbackHandles = {};
Mathias Agopian13127d82013-03-05 17:47:11 -08001082 return flags;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001083}
1084
Pablo Ceballos05289c22016-04-14 15:49:55 -07001085void Layer::commitTransaction(const State& stateToCommit) {
1086 mDrawingState = stateToCommit;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001087}
1088
Mathias Agopian13127d82013-03-05 17:47:11 -08001089uint32_t Layer::getTransactionFlags(uint32_t flags) {
Lloyd Piquef1c675b2018-09-12 20:45:39 -07001090 return mTransactionFlags.fetch_and(~flags) & flags;
Mathias Agopian13127d82013-03-05 17:47:11 -08001091}
1092
1093uint32_t Layer::setTransactionFlags(uint32_t flags) {
Lloyd Piquef1c675b2018-09-12 20:45:39 -07001094 return mTransactionFlags.fetch_or(flags);
Mathias Agopian13127d82013-03-05 17:47:11 -08001095}
1096
Robert Carr82364e32016-05-15 11:27:47 -07001097bool Layer::setPosition(float x, float y, bool immediate) {
Marissa Wallf58c14b2018-07-24 10:50:43 -07001098 if (mCurrentState.requested_legacy.transform.tx() == x &&
1099 mCurrentState.requested_legacy.transform.ty() == y)
Mathias Agopian13127d82013-03-05 17:47:11 -08001100 return false;
1101 mCurrentState.sequence++;
Robert Carr69663fb2016-03-27 19:59:19 -07001102
1103 // We update the requested and active position simultaneously because
1104 // we want to apply the position portion of the transform matrix immediately,
1105 // but still delay scaling when resizing a SCALING_MODE_FREEZE layer.
Marissa Wallf58c14b2018-07-24 10:50:43 -07001106 mCurrentState.requested_legacy.transform.set(x, y);
Robert Carr7bf247e2017-05-18 14:02:49 -07001107 if (immediate && !mFreezeGeometryUpdates) {
1108 // Here we directly update the active state
1109 // unlike other setters, because we store it within
1110 // the transform, but use different latching rules.
1111 // b/38182305
Marissa Wallf58c14b2018-07-24 10:50:43 -07001112 mCurrentState.active_legacy.transform.set(x, y);
Robert Carr82364e32016-05-15 11:27:47 -07001113 }
Robert Carr7bf247e2017-05-18 14:02:49 -07001114 mFreezeGeometryUpdates = mFreezeGeometryUpdates || !immediate;
Robert Carr69663fb2016-03-27 19:59:19 -07001115
Dan Stoza7dde5992015-05-22 09:51:44 -07001116 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001117 setTransactionFlags(eTransactionNeeded);
1118 return true;
1119}
Robert Carr82364e32016-05-15 11:27:47 -07001120
Robert Carr1f0a16a2016-10-24 16:27:39 -07001121bool Layer::setChildLayer(const sp<Layer>& childLayer, int32_t z) {
1122 ssize_t idx = mCurrentChildren.indexOf(childLayer);
1123 if (idx < 0) {
1124 return false;
1125 }
1126 if (childLayer->setLayer(z)) {
1127 mCurrentChildren.removeAt(idx);
1128 mCurrentChildren.add(childLayer);
Robert Carr503d2bd2017-12-04 15:49:47 -08001129 return true;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001130 }
Robert Carr503d2bd2017-12-04 15:49:47 -08001131 return false;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001132}
1133
Robert Carr503c7042017-09-27 15:06:08 -07001134bool Layer::setChildRelativeLayer(const sp<Layer>& childLayer,
1135 const sp<IBinder>& relativeToHandle, int32_t relativeZ) {
1136 ssize_t idx = mCurrentChildren.indexOf(childLayer);
1137 if (idx < 0) {
1138 return false;
1139 }
1140 if (childLayer->setRelativeLayer(relativeToHandle, relativeZ)) {
1141 mCurrentChildren.removeAt(idx);
1142 mCurrentChildren.add(childLayer);
Robert Carr503d2bd2017-12-04 15:49:47 -08001143 return true;
Robert Carr503c7042017-09-27 15:06:08 -07001144 }
Robert Carr503d2bd2017-12-04 15:49:47 -08001145 return false;
Robert Carr503c7042017-09-27 15:06:08 -07001146}
1147
Robert Carrae060832016-11-28 10:51:00 -08001148bool Layer::setLayer(int32_t z) {
Robert Carr503d2bd2017-12-04 15:49:47 -08001149 if (mCurrentState.z == z && !usingRelativeZ(LayerVector::StateSet::Current)) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001150 mCurrentState.sequence++;
1151 mCurrentState.z = z;
Dan Stoza7dde5992015-05-22 09:51:44 -07001152 mCurrentState.modified = true;
Robert Carrdb66e622017-04-10 16:55:57 -07001153
1154 // Discard all relative layering.
1155 if (mCurrentState.zOrderRelativeOf != nullptr) {
1156 sp<Layer> strongRelative = mCurrentState.zOrderRelativeOf.promote();
1157 if (strongRelative != nullptr) {
1158 strongRelative->removeZOrderRelative(this);
1159 }
1160 mCurrentState.zOrderRelativeOf = nullptr;
1161 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001162 setTransactionFlags(eTransactionNeeded);
1163 return true;
1164}
Robert Carr1f0a16a2016-10-24 16:27:39 -07001165
Robert Carrdb66e622017-04-10 16:55:57 -07001166void Layer::removeZOrderRelative(const wp<Layer>& relative) {
1167 mCurrentState.zOrderRelatives.remove(relative);
1168 mCurrentState.sequence++;
1169 mCurrentState.modified = true;
1170 setTransactionFlags(eTransactionNeeded);
1171}
1172
1173void Layer::addZOrderRelative(const wp<Layer>& relative) {
1174 mCurrentState.zOrderRelatives.add(relative);
1175 mCurrentState.modified = true;
1176 mCurrentState.sequence++;
1177 setTransactionFlags(eTransactionNeeded);
1178}
1179
Robert Carr503d2bd2017-12-04 15:49:47 -08001180bool Layer::setRelativeLayer(const sp<IBinder>& relativeToHandle, int32_t relativeZ) {
Robert Carrdb66e622017-04-10 16:55:57 -07001181 sp<Handle> handle = static_cast<Handle*>(relativeToHandle.get());
1182 if (handle == nullptr) {
1183 return false;
1184 }
1185 sp<Layer> relative = handle->owner.promote();
1186 if (relative == nullptr) {
1187 return false;
1188 }
1189
Robert Carr503d2bd2017-12-04 15:49:47 -08001190 if (mCurrentState.z == relativeZ && usingRelativeZ(LayerVector::StateSet::Current) &&
1191 mCurrentState.zOrderRelativeOf == relative) {
1192 return false;
1193 }
1194
Robert Carrdb66e622017-04-10 16:55:57 -07001195 mCurrentState.sequence++;
1196 mCurrentState.modified = true;
Robert Carr503d2bd2017-12-04 15:49:47 -08001197 mCurrentState.z = relativeZ;
Robert Carrdb66e622017-04-10 16:55:57 -07001198
chaviw9ab4bd12017-11-03 13:11:00 -07001199 auto oldZOrderRelativeOf = mCurrentState.zOrderRelativeOf.promote();
1200 if (oldZOrderRelativeOf != nullptr) {
1201 oldZOrderRelativeOf->removeZOrderRelative(this);
1202 }
Robert Carrdb66e622017-04-10 16:55:57 -07001203 mCurrentState.zOrderRelativeOf = relative;
1204 relative->addZOrderRelative(this);
1205
1206 setTransactionFlags(eTransactionNeeded);
1207
1208 return true;
1209}
1210
Mathias Agopian13127d82013-03-05 17:47:11 -08001211bool Layer::setSize(uint32_t w, uint32_t h) {
Marissa Wallf58c14b2018-07-24 10:50:43 -07001212 if (mCurrentState.requested_legacy.w == w && mCurrentState.requested_legacy.h == h)
1213 return false;
1214 mCurrentState.requested_legacy.w = w;
1215 mCurrentState.requested_legacy.h = h;
Dan Stoza7dde5992015-05-22 09:51:44 -07001216 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001217 setTransactionFlags(eTransactionNeeded);
Vishnu Naird01c4432018-08-13 10:38:47 -07001218
1219 // record the new size, from this point on, when the client request
1220 // a buffer, it'll get the new size.
1221 setDefaultBufferSize(mCurrentState.requested_legacy.w, mCurrentState.requested_legacy.h);
Mathias Agopian13127d82013-03-05 17:47:11 -08001222 return true;
1223}
Dan Stoza9e56aa02015-11-02 13:00:03 -08001224bool Layer::setAlpha(float alpha) {
David Sodman41fdfc92017-11-06 16:09:56 -08001225 if (mCurrentState.color.a == alpha) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001226 mCurrentState.sequence++;
chaviw13fdc492017-06-27 12:40:18 -07001227 mCurrentState.color.a = alpha;
Dan Stoza7dde5992015-05-22 09:51:44 -07001228 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001229 setTransactionFlags(eTransactionNeeded);
1230 return true;
1231}
chaviw13fdc492017-06-27 12:40:18 -07001232
1233bool Layer::setColor(const half3& color) {
David Sodman41fdfc92017-11-06 16:09:56 -08001234 if (color.r == mCurrentState.color.r && color.g == mCurrentState.color.g &&
1235 color.b == mCurrentState.color.b)
chaviw13fdc492017-06-27 12:40:18 -07001236 return false;
1237
1238 mCurrentState.sequence++;
1239 mCurrentState.color.r = color.r;
1240 mCurrentState.color.g = color.g;
1241 mCurrentState.color.b = color.b;
1242 mCurrentState.modified = true;
1243 setTransactionFlags(eTransactionNeeded);
1244 return true;
1245}
1246
Lucas Dupin1b6531c2018-07-05 17:18:21 -07001247bool Layer::setCornerRadius(float cornerRadius) {
1248 if (mCurrentState.cornerRadius == cornerRadius)
1249 return false;
1250
1251 mCurrentState.sequence++;
1252 mCurrentState.cornerRadius = cornerRadius;
1253 mCurrentState.modified = true;
1254 setTransactionFlags(eTransactionNeeded);
1255 return true;
1256}
1257
Robert Carrd4ae7f32018-06-07 16:10:57 -07001258bool Layer::setMatrix(const layer_state_t::matrix22_t& matrix,
1259 bool allowNonRectPreservingTransforms) {
Peiyong Linefefaac2018-08-17 12:27:51 -07001260 ui::Transform t;
Robert Carrd4ae7f32018-06-07 16:10:57 -07001261 t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
1262
1263 if (!allowNonRectPreservingTransforms && !t.preserveRects()) {
1264 ALOGW("Attempt to set rotation matrix without permission ACCESS_SURFACE_FLINGER ignored");
1265 return false;
1266 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001267 mCurrentState.sequence++;
Marissa Wallf58c14b2018-07-24 10:50:43 -07001268 mCurrentState.requested_legacy.transform.set(matrix.dsdx, matrix.dtdy, matrix.dtdx,
1269 matrix.dsdy);
Dan Stoza7dde5992015-05-22 09:51:44 -07001270 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001271 setTransactionFlags(eTransactionNeeded);
1272 return true;
1273}
Marissa Wall61c58622018-07-18 10:12:20 -07001274
Mathias Agopian13127d82013-03-05 17:47:11 -08001275bool Layer::setTransparentRegionHint(const Region& transparent) {
Marissa Wallf58c14b2018-07-24 10:50:43 -07001276 mCurrentState.requestedTransparentRegion_legacy = transparent;
Dan Stoza7dde5992015-05-22 09:51:44 -07001277 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001278 setTransactionFlags(eTransactionNeeded);
1279 return true;
1280}
1281bool Layer::setFlags(uint8_t flags, uint8_t mask) {
1282 const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask);
David Sodman41fdfc92017-11-06 16:09:56 -08001283 if (mCurrentState.flags == newFlags) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001284 mCurrentState.sequence++;
1285 mCurrentState.flags = newFlags;
Dan Stoza7dde5992015-05-22 09:51:44 -07001286 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001287 setTransactionFlags(eTransactionNeeded);
1288 return true;
1289}
Robert Carr99e27f02016-06-16 15:18:02 -07001290
Marissa Wallf58c14b2018-07-24 10:50:43 -07001291bool Layer::setCrop_legacy(const Rect& crop, bool immediate) {
1292 if (mCurrentState.requestedCrop_legacy == crop) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001293 mCurrentState.sequence++;
Marissa Wallf58c14b2018-07-24 10:50:43 -07001294 mCurrentState.requestedCrop_legacy = crop;
Robert Carr7bf247e2017-05-18 14:02:49 -07001295 if (immediate && !mFreezeGeometryUpdates) {
Marissa Wallf58c14b2018-07-24 10:50:43 -07001296 mCurrentState.crop_legacy = crop;
Robert Carr99e27f02016-06-16 15:18:02 -07001297 }
Robert Carr7bf247e2017-05-18 14:02:49 -07001298 mFreezeGeometryUpdates = mFreezeGeometryUpdates || !immediate;
1299
Dan Stoza7dde5992015-05-22 09:51:44 -07001300 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001301 setTransactionFlags(eTransactionNeeded);
1302 return true;
1303}
Robert Carr8d5227b2017-03-16 15:41:03 -07001304
Robert Carrc3574f72016-03-24 12:19:32 -07001305bool Layer::setOverrideScalingMode(int32_t scalingMode) {
David Sodman41fdfc92017-11-06 16:09:56 -08001306 if (scalingMode == mOverrideScalingMode) return false;
Robert Carrc3574f72016-03-24 12:19:32 -07001307 mOverrideScalingMode = scalingMode;
Robert Carr82364e32016-05-15 11:27:47 -07001308 setTransactionFlags(eTransactionNeeded);
Robert Carrc3574f72016-03-24 12:19:32 -07001309 return true;
1310}
1311
rongliucfb187b2018-03-14 12:26:23 -07001312void Layer::setInfo(int32_t type, int32_t appId) {
David Sodman41fdfc92017-11-06 16:09:56 -08001313 mCurrentState.appId = appId;
1314 mCurrentState.type = type;
1315 mCurrentState.modified = true;
1316 setTransactionFlags(eTransactionNeeded);
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -05001317}
1318
Mathias Agopian13127d82013-03-05 17:47:11 -08001319bool Layer::setLayerStack(uint32_t layerStack) {
David Sodman41fdfc92017-11-06 16:09:56 -08001320 if (mCurrentState.layerStack == layerStack) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001321 mCurrentState.sequence++;
1322 mCurrentState.layerStack = layerStack;
Dan Stoza7dde5992015-05-22 09:51:44 -07001323 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001324 setTransactionFlags(eTransactionNeeded);
1325 return true;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001326}
1327
Robert Carr1f0a16a2016-10-24 16:27:39 -07001328uint32_t Layer::getLayerStack() const {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001329 auto p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001330 if (p == nullptr) {
1331 return getDrawingState().layerStack;
1332 }
1333 return p->getLayerStack();
1334}
1335
Marissa Wallf58c14b2018-07-24 10:50:43 -07001336void Layer::deferTransactionUntil_legacy(const sp<Layer>& barrierLayer, uint64_t frameNumber) {
1337 mCurrentState.barrierLayer_legacy = barrierLayer;
1338 mCurrentState.frameNumber_legacy = frameNumber;
Dan Stoza7dde5992015-05-22 09:51:44 -07001339 // We don't set eTransactionNeeded, because just receiving a deferral
1340 // request without any other state updates shouldn't actually induce a delay
1341 mCurrentState.modified = true;
1342 pushPendingState();
Marissa Wallf58c14b2018-07-24 10:50:43 -07001343 mCurrentState.barrierLayer_legacy = nullptr;
1344 mCurrentState.frameNumber_legacy = 0;
Dan Stoza7dde5992015-05-22 09:51:44 -07001345 mCurrentState.modified = false;
Robert Carr0d480722017-01-10 16:42:54 -08001346}
1347
Marissa Wallf58c14b2018-07-24 10:50:43 -07001348void Layer::deferTransactionUntil_legacy(const sp<IBinder>& barrierHandle, uint64_t frameNumber) {
Robert Carr0d480722017-01-10 16:42:54 -08001349 sp<Handle> handle = static_cast<Handle*>(barrierHandle.get());
Marissa Wallf58c14b2018-07-24 10:50:43 -07001350 deferTransactionUntil_legacy(handle->owner.promote(), frameNumber);
Dan Stoza7dde5992015-05-22 09:51:44 -07001351}
1352
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001353// ----------------------------------------------------------------------------
1354// pageflip handling...
1355// ----------------------------------------------------------------------------
1356
Robert Carr1f0a16a2016-10-24 16:27:39 -07001357bool Layer::isHiddenByPolicy() const {
Alec Mourib416efd2018-09-06 21:01:59 +00001358 const State& s(mDrawingState);
Chia-I Wue41dbe62017-06-13 14:10:56 -07001359 const auto& parent = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001360 if (parent != nullptr && parent->isHiddenByPolicy()) {
1361 return true;
1362 }
1363 return s.flags & layer_state_t::eLayerHidden;
1364}
1365
David Sodman41fdfc92017-11-06 16:09:56 -08001366uint32_t Layer::getEffectiveUsage(uint32_t usage) const {
Mathias Agopiana67932f2011-04-20 14:20:59 -07001367 // TODO: should we do something special if mSecure is set?
1368 if (mProtectedByApp) {
1369 // need a hardware-protected path to external video sink
1370 usage |= GraphicBuffer::USAGE_PROTECTED;
Jamie Gennis54cc83e2010-11-02 11:51:32 -07001371 }
Riley Andrews03414a12014-07-01 14:22:59 -07001372 if (mPotentialCursor) {
1373 usage |= GraphicBuffer::USAGE_CURSOR;
1374 }
Jamie Gennis3599bf22011-08-10 11:48:07 -07001375 usage |= GraphicBuffer::USAGE_HW_COMPOSER;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001376 return usage;
Mathias Agopianb5b7f262010-05-07 15:58:44 -07001377}
1378
Dominik Laskowskia2edf612018-06-01 13:15:16 -07001379void Layer::updateTransformHint(const sp<const DisplayDevice>& display) const {
Mathias Agopiana4583642011-08-23 18:03:18 -07001380 uint32_t orientation = 0;
Vishnu Nairf2deb822018-11-12 17:53:48 -08001381 // Disable setting transform hint if the debug flag is set or if the
1382 // getTransformToDisplayInverse flag is set and the client wants to submit buffers
1383 // in one orientation.
1384 if (!mFlinger->mDebugDisableTransformHint && !getTransformToDisplayInverse()) {
Mathias Agopian84300952012-11-21 16:02:13 -08001385 // The transform hint is used to improve performance, but we can
1386 // only have a single transform hint, it cannot
Mathias Agopian4fec8732012-06-29 14:12:52 -07001387 // apply to all displays.
Peiyong Linefefaac2018-08-17 12:27:51 -07001388 const ui::Transform& planeTransform = display->getTransform();
Mathias Agopian4fec8732012-06-29 14:12:52 -07001389 orientation = planeTransform.getOrientation();
Peiyong Linefefaac2018-08-17 12:27:51 -07001390 if (orientation & ui::Transform::ROT_INVALID) {
Mathias Agopiana4583642011-08-23 18:03:18 -07001391 orientation = 0;
1392 }
1393 }
David Sodmaneb085e02017-10-05 18:49:04 -07001394 setTransformHint(orientation);
Mathias Agopiana4583642011-08-23 18:03:18 -07001395}
1396
Mathias Agopian13127d82013-03-05 17:47:11 -08001397// ----------------------------------------------------------------------------
1398// debugging
1399// ----------------------------------------------------------------------------
1400
Marissa Wall61c58622018-07-18 10:12:20 -07001401// TODO(marissaw): add new layer state info to layer debugging
Kalle Raitaa099a242017-01-11 11:17:29 -08001402LayerDebugInfo Layer::getLayerDebugInfo() const {
1403 LayerDebugInfo info;
Alec Mourib416efd2018-09-06 21:01:59 +00001404 const State& ds = getDrawingState();
Kalle Raitaa099a242017-01-11 11:17:29 -08001405 info.mName = getName();
chaviw1acbec72017-07-27 15:28:26 -07001406 sp<Layer> parent = getParent();
Kalle Raitaa099a242017-01-11 11:17:29 -08001407 info.mParentName = (parent == nullptr ? std::string("none") : parent->getName().string());
Yiwei Zhang5434a782018-12-05 18:06:32 -08001408 info.mType = std::string(getTypeId());
Marissa Wallf58c14b2018-07-24 10:50:43 -07001409 info.mTransparentRegion = ds.activeTransparentRegion_legacy;
Kalle Raitaa099a242017-01-11 11:17:29 -08001410 info.mVisibleRegion = visibleRegion;
1411 info.mSurfaceDamageRegion = surfaceDamageRegion;
1412 info.mLayerStack = getLayerStack();
Marissa Wallf58c14b2018-07-24 10:50:43 -07001413 info.mX = ds.active_legacy.transform.tx();
1414 info.mY = ds.active_legacy.transform.ty();
Kalle Raitaa099a242017-01-11 11:17:29 -08001415 info.mZ = ds.z;
Marissa Wallf58c14b2018-07-24 10:50:43 -07001416 info.mWidth = ds.active_legacy.w;
1417 info.mHeight = ds.active_legacy.h;
1418 info.mCrop = ds.crop_legacy;
chaviw13fdc492017-06-27 12:40:18 -07001419 info.mColor = ds.color;
Kalle Raitaa099a242017-01-11 11:17:29 -08001420 info.mFlags = ds.flags;
1421 info.mPixelFormat = getPixelFormat();
Chia-I Wu01591c92018-05-22 12:03:00 -07001422 info.mDataSpace = static_cast<android_dataspace>(mCurrentDataSpace);
Marissa Wallf58c14b2018-07-24 10:50:43 -07001423 info.mMatrix[0][0] = ds.active_legacy.transform[0][0];
1424 info.mMatrix[0][1] = ds.active_legacy.transform[0][1];
1425 info.mMatrix[1][0] = ds.active_legacy.transform[1][0];
1426 info.mMatrix[1][1] = ds.active_legacy.transform[1][1];
Kalle Raitaa099a242017-01-11 11:17:29 -08001427 {
David Sodman0cf8f8d2017-12-20 18:19:45 -08001428 sp<const GraphicBuffer> buffer = mActiveBuffer;
David Sodman5b4cffc2017-11-23 13:20:29 -08001429 if (buffer != 0) {
1430 info.mActiveBufferWidth = buffer->getWidth();
1431 info.mActiveBufferHeight = buffer->getHeight();
1432 info.mActiveBufferStride = buffer->getStride();
1433 info.mActiveBufferFormat = buffer->format;
Kalle Raitaa099a242017-01-11 11:17:29 -08001434 } else {
1435 info.mActiveBufferWidth = 0;
1436 info.mActiveBufferHeight = 0;
1437 info.mActiveBufferStride = 0;
1438 info.mActiveBufferFormat = 0;
1439 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001440 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001441 info.mNumQueuedFrames = getQueuedFrameCount();
1442 info.mRefreshPending = isBufferLatched();
1443 info.mIsOpaque = isOpaque(ds);
1444 info.mContentDirty = contentDirty;
1445 return info;
Mathias Agopian13127d82013-03-05 17:47:11 -08001446}
Chia-I Wu83ce7c12017-10-19 15:18:55 -07001447
Yiwei Zhang5434a782018-12-05 18:06:32 -08001448void Layer::miniDumpHeader(std::string& result) {
Yichi Chen6ca35192018-05-29 12:20:43 +08001449 result.append("-------------------------------");
1450 result.append("-------------------------------");
1451 result.append("-----------------------------\n");
Dan Stozae22aec72016-08-01 13:20:59 -07001452 result.append(" Layer name\n");
1453 result.append(" Z | ");
1454 result.append(" Comp Type | ");
Yichi Chen6ca35192018-05-29 12:20:43 +08001455 result.append(" Transform | ");
Dan Stozae22aec72016-08-01 13:20:59 -07001456 result.append(" Disp Frame (LTRB) | ");
1457 result.append(" Source Crop (LTRB)\n");
Yichi Chen6ca35192018-05-29 12:20:43 +08001458 result.append("-------------------------------");
1459 result.append("-------------------------------");
1460 result.append("-----------------------------\n");
Dan Stozae22aec72016-08-01 13:20:59 -07001461}
1462
Yiwei Zhang5434a782018-12-05 18:06:32 -08001463void Layer::miniDump(std::string& result, DisplayId displayId) const {
Dominik Laskowski34157762018-10-31 13:07:19 -07001464 if (!hasHwcLayer(displayId)) {
Dan Stozae22aec72016-08-01 13:20:59 -07001465 return;
1466 }
1467
Yiwei Zhang5434a782018-12-05 18:06:32 -08001468 std::string name;
Dan Stozae22aec72016-08-01 13:20:59 -07001469 if (mName.length() > 77) {
1470 std::string shortened;
1471 shortened.append(mName.string(), 36);
1472 shortened.append("[...]");
1473 shortened.append(mName.string() + (mName.length() - 36), 36);
Yiwei Zhang5434a782018-12-05 18:06:32 -08001474 name = shortened;
Dan Stozae22aec72016-08-01 13:20:59 -07001475 } else {
Yiwei Zhang5434a782018-12-05 18:06:32 -08001476 name = std::string(mName.string(), mName.size());
Dan Stozae22aec72016-08-01 13:20:59 -07001477 }
1478
Yiwei Zhang5434a782018-12-05 18:06:32 -08001479 StringAppendF(&result, " %s\n", name.c_str());
Dan Stozae22aec72016-08-01 13:20:59 -07001480
Alec Mourib416efd2018-09-06 21:01:59 +00001481 const State& layerState(getDrawingState());
Lloyd Pique074e8122018-07-26 12:57:23 -07001482 const LayerBE::HWCInfo& hwcInfo = getBE().mHwcLayers.at(displayId);
Chia-I Wu1e043612018-03-01 09:45:09 -08001483 if (layerState.zOrderRelativeOf != nullptr || mDrawingParent != nullptr) {
Yiwei Zhang5434a782018-12-05 18:06:32 -08001484 StringAppendF(&result, " rel %6d | ", layerState.z);
Chia-I Wu1e043612018-03-01 09:45:09 -08001485 } else {
Yiwei Zhang5434a782018-12-05 18:06:32 -08001486 StringAppendF(&result, " %10d | ", layerState.z);
Chia-I Wu1e043612018-03-01 09:45:09 -08001487 }
Yiwei Zhang5434a782018-12-05 18:06:32 -08001488 StringAppendF(&result, "%10s | ", to_string(getCompositionType(displayId)).c_str());
1489 StringAppendF(&result, "%10s | ", to_string(hwcInfo.transform).c_str());
Lloyd Pique074e8122018-07-26 12:57:23 -07001490 const Rect& frame = hwcInfo.displayFrame;
Yiwei Zhang5434a782018-12-05 18:06:32 -08001491 StringAppendF(&result, "%4d %4d %4d %4d | ", frame.left, frame.top, frame.right, frame.bottom);
Lloyd Pique074e8122018-07-26 12:57:23 -07001492 const FloatRect& crop = hwcInfo.sourceCrop;
Yiwei Zhang5434a782018-12-05 18:06:32 -08001493 StringAppendF(&result, "%6.1f %6.1f %6.1f %6.1f\n", crop.left, crop.top, crop.right,
1494 crop.bottom);
Dan Stozae22aec72016-08-01 13:20:59 -07001495
David Sodman7e4ae112018-02-09 15:02:28 -08001496 result.append("- - - - - - - - - - - - - - - -\n");
1497
1498 std::string compositionInfoStr;
1499 getBE().compositionInfo.dump(compositionInfoStr, "compositionInfo");
Yiwei Zhang5434a782018-12-05 18:06:32 -08001500 result.append(compositionInfoStr);
David Sodman7e4ae112018-02-09 15:02:28 -08001501
Yichi Chen6ca35192018-05-29 12:20:43 +08001502 result.append("- - - - - - - - - - - - - - - -");
1503 result.append("- - - - - - - - - - - - - - - -");
1504 result.append("- - - - - - - - - - - - - - -\n");
Dan Stozae22aec72016-08-01 13:20:59 -07001505}
Dan Stozae22aec72016-08-01 13:20:59 -07001506
Yiwei Zhang5434a782018-12-05 18:06:32 -08001507void Layer::dumpFrameStats(std::string& result) const {
Svetoslavd85084b2014-03-20 10:28:31 -07001508 mFrameTracker.dumpStats(result);
Mathias Agopian13127d82013-03-05 17:47:11 -08001509}
1510
Svetoslavd85084b2014-03-20 10:28:31 -07001511void Layer::clearFrameStats() {
1512 mFrameTracker.clearStats();
Mathias Agopian13127d82013-03-05 17:47:11 -08001513}
1514
Jamie Gennis6547ff42013-07-16 20:12:42 -07001515void Layer::logFrameStats() {
1516 mFrameTracker.logAndResetStats(mName);
1517}
1518
Svetoslavd85084b2014-03-20 10:28:31 -07001519void Layer::getFrameStats(FrameStats* outStats) const {
1520 mFrameTracker.getStats(outStats);
1521}
1522
Yiwei Zhang5434a782018-12-05 18:06:32 -08001523void Layer::dumpFrameEvents(std::string& result) {
1524 StringAppendF(&result, "- Layer %s (%s, %p)\n", getName().string(), getTypeId(), this);
Brian Andersond6927fb2016-07-23 23:37:30 -07001525 Mutex::Autolock lock(mFrameEventHistoryMutex);
1526 mFrameEventHistory.checkFencesForCompletion();
1527 mFrameEventHistory.dump(result);
1528}
Pablo Ceballos40845df2016-01-25 17:41:15 -08001529
Brian Anderson5ea5e592016-12-01 16:54:33 -08001530void Layer::onDisconnect() {
1531 Mutex::Autolock lock(mFrameEventHistoryMutex);
1532 mFrameEventHistory.onDisconnect();
Yiwei Zhangaf8ee942018-11-22 00:15:23 -08001533 mFlinger->mTimeStats->onDestroy(getSequence());
Brian Anderson5ea5e592016-12-01 16:54:33 -08001534}
1535
Brian Anderson3890c392016-07-25 12:48:08 -07001536void Layer::addAndGetFrameTimestamps(const NewFrameEventsEntry* newTimestamps,
David Sodman41fdfc92017-11-06 16:09:56 -08001537 FrameEventHistoryDelta* outDelta) {
Yiwei Zhangfaf3ded2018-05-02 17:37:17 -07001538 if (newTimestamps) {
Yiwei Zhang7e666a52018-11-15 13:33:42 -08001539 mFlinger->mTimeStats->setPostTime(getSequence(), newTimestamps->frameNumber,
1540 getName().c_str(), newTimestamps->postedTime);
Yiwei Zhangfaf3ded2018-05-02 17:37:17 -07001541 }
1542
Brian Andersond6927fb2016-07-23 23:37:30 -07001543 Mutex::Autolock lock(mFrameEventHistoryMutex);
1544 if (newTimestamps) {
Brian Andersonfbc80ae2017-05-26 16:23:54 -07001545 // If there are any unsignaled fences in the aquire timeline at this
1546 // point, the previously queued frame hasn't been latched yet. Go ahead
1547 // and try to get the signal time here so the syscall is taken out of
1548 // the main thread's critical path.
1549 mAcquireTimeline.updateSignalTimes();
1550 // Push the new fence after updating since it's likely still pending.
Brian Anderson3d4039d2016-09-23 16:31:30 -07001551 mAcquireTimeline.push(newTimestamps->acquireFence);
Brian Andersond6927fb2016-07-23 23:37:30 -07001552 mFrameEventHistory.addQueue(*newTimestamps);
1553 }
1554
Brian Anderson3890c392016-07-25 12:48:08 -07001555 if (outDelta) {
1556 mFrameEventHistory.getAndResetDelta(outDelta);
Brian Andersond6927fb2016-07-23 23:37:30 -07001557 }
Pablo Ceballos40845df2016-01-25 17:41:15 -08001558}
Dan Stozae77c7662016-05-13 11:37:28 -07001559
Chia-I Wu98f1c102017-05-30 14:54:08 -07001560size_t Layer::getChildrenCount() const {
1561 size_t count = 0;
1562 for (const sp<Layer>& child : mCurrentChildren) {
1563 count += 1 + child->getChildrenCount();
1564 }
1565 return count;
1566}
1567
Robert Carr1f0a16a2016-10-24 16:27:39 -07001568void Layer::addChild(const sp<Layer>& layer) {
1569 mCurrentChildren.add(layer);
1570 layer->setParent(this);
1571}
1572
1573ssize_t Layer::removeChild(const sp<Layer>& layer) {
1574 layer->setParent(nullptr);
1575 return mCurrentChildren.remove(layer);
1576}
1577
Robert Carr1db73f62016-12-21 12:58:51 -08001578bool Layer::reparentChildren(const sp<IBinder>& newParentHandle) {
1579 sp<Handle> handle = nullptr;
1580 sp<Layer> newParent = nullptr;
1581 if (newParentHandle == nullptr) {
1582 return false;
1583 }
1584 handle = static_cast<Handle*>(newParentHandle.get());
1585 newParent = handle->owner.promote();
1586 if (newParent == nullptr) {
1587 ALOGE("Unable to promote Layer handle");
1588 return false;
1589 }
1590
chaviw5aedec92018-10-22 10:40:38 -07001591 if (attachChildren()) {
1592 setTransactionFlags(eTransactionNeeded);
1593 }
Robert Carr1db73f62016-12-21 12:58:51 -08001594 for (const sp<Layer>& child : mCurrentChildren) {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001595 newParent->addChild(child);
Robert Carr1db73f62016-12-21 12:58:51 -08001596
1597 sp<Client> client(child->mClientRef.promote());
1598 if (client != nullptr) {
Robert Carr94c7d3d2018-04-24 12:30:47 -07001599 client->updateParent(newParent);
Robert Carr1db73f62016-12-21 12:58:51 -08001600 }
1601 }
1602 mCurrentChildren.clear();
1603
1604 return true;
1605}
1606
Robert Carr15eae092018-03-23 13:43:53 -07001607void Layer::setChildrenDrawingParent(const sp<Layer>& newParent) {
Robert Carr578038f2018-03-09 12:25:24 -08001608 for (const sp<Layer>& child : mDrawingChildren) {
1609 child->mDrawingParent = newParent;
1610 }
1611}
1612
chaviwf1961f72017-09-18 16:41:07 -07001613bool Layer::reparent(const sp<IBinder>& newParentHandle) {
1614 if (newParentHandle == nullptr) {
chaviw06178942017-07-27 10:25:59 -07001615 return false;
1616 }
1617
1618 auto handle = static_cast<Handle*>(newParentHandle.get());
1619 sp<Layer> newParent = handle->owner.promote();
1620 if (newParent == nullptr) {
1621 ALOGE("Unable to promote Layer handle");
1622 return false;
1623 }
1624
chaviwf1961f72017-09-18 16:41:07 -07001625 sp<Layer> parent = getParent();
1626 if (parent != nullptr) {
1627 parent->removeChild(this);
chaviw06178942017-07-27 10:25:59 -07001628 }
chaviwf1961f72017-09-18 16:41:07 -07001629 newParent->addChild(this);
chaviw06178942017-07-27 10:25:59 -07001630
chaviw61626f22018-11-15 16:26:27 -08001631 if (!newParent->isRemovedFromCurrentState()) {
1632 addToCurrentState();
1633 }
1634
chaviwf1961f72017-09-18 16:41:07 -07001635 sp<Client> client(mClientRef.promote());
chaviw06178942017-07-27 10:25:59 -07001636 sp<Client> newParentClient(newParent->mClientRef.promote());
1637
chaviwf1961f72017-09-18 16:41:07 -07001638 if (client != newParentClient) {
Robert Carr94c7d3d2018-04-24 12:30:47 -07001639 client->updateParent(newParent);
chaviw06178942017-07-27 10:25:59 -07001640 }
1641
chaviw5aedec92018-10-22 10:40:38 -07001642 if (mLayerDetached) {
1643 mLayerDetached = false;
1644 setTransactionFlags(eTransactionNeeded);
1645 }
1646 if (attachChildren()) {
1647 setTransactionFlags(eTransactionNeeded);
1648 }
chaviw06178942017-07-27 10:25:59 -07001649 return true;
1650}
1651
Robert Carr9524cb32017-02-13 11:32:32 -08001652bool Layer::detachChildren() {
Robert Carr7f619b22017-11-06 12:56:35 -08001653 for (const sp<Layer>& child : mCurrentChildren) {
chaviw161410b02017-07-27 10:46:08 -07001654 sp<Client> parentClient = mClientRef.promote();
Robert Carr9524cb32017-02-13 11:32:32 -08001655 sp<Client> client(child->mClientRef.promote());
chaviw161410b02017-07-27 10:46:08 -07001656 if (client != nullptr && parentClient != client) {
chaviw5aedec92018-10-22 10:40:38 -07001657 child->mLayerDetached = true;
Robert Carr7f619b22017-11-06 12:56:35 -08001658 child->detachChildren();
Robert Carr9524cb32017-02-13 11:32:32 -08001659 }
Robert Carr7f619b22017-11-06 12:56:35 -08001660 }
Robert Carr9524cb32017-02-13 11:32:32 -08001661
1662 return true;
1663}
1664
chaviw5aedec92018-10-22 10:40:38 -07001665bool Layer::attachChildren() {
1666 bool changed = false;
1667 for (const sp<Layer>& child : mCurrentChildren) {
1668 sp<Client> parentClient = mClientRef.promote();
1669 sp<Client> client(child->mClientRef.promote());
1670 if (client != nullptr && parentClient != client) {
1671 if (child->mLayerDetached) {
1672 child->mLayerDetached = false;
1673 changed = true;
1674 }
1675 changed |= child->attachChildren();
1676 }
1677 }
1678
1679 return changed;
1680}
1681
Peiyong Lind3788632018-09-18 16:01:31 -07001682bool Layer::setColorTransform(const mat4& matrix) {
Peiyong Lin747321c2018-10-01 10:03:11 -07001683 static const mat4 identityMatrix = mat4();
1684
Peiyong Lind3788632018-09-18 16:01:31 -07001685 if (mCurrentState.colorTransform == matrix) {
1686 return false;
1687 }
1688 ++mCurrentState.sequence;
1689 mCurrentState.colorTransform = matrix;
Peiyong Lin747321c2018-10-01 10:03:11 -07001690 mCurrentState.hasColorTransform = matrix != identityMatrix;
1691 mCurrentState.modified = true;
Peiyong Lind3788632018-09-18 16:01:31 -07001692 setTransactionFlags(eTransactionNeeded);
1693 return true;
1694}
1695
chaviwf66724d2018-11-28 16:35:21 -08001696mat4 Layer::getColorTransform() const {
1697 mat4 colorTransform = mat4(getDrawingState().colorTransform);
1698 if (sp<Layer> parent = mDrawingParent.promote(); parent != nullptr) {
1699 colorTransform = parent->getColorTransform() * colorTransform;
1700 }
1701 return colorTransform;
Peiyong Lind3788632018-09-18 16:01:31 -07001702}
1703
1704bool Layer::hasColorTransform() const {
chaviwf66724d2018-11-28 16:35:21 -08001705 bool hasColorTransform = getDrawingState().hasColorTransform;
1706 if (sp<Layer> parent = mDrawingParent.promote(); parent != nullptr) {
1707 hasColorTransform = hasColorTransform || parent->hasColorTransform();
1708 }
1709 return hasColorTransform;
Peiyong Lind3788632018-09-18 16:01:31 -07001710}
1711
Chia-I Wu11481472018-05-04 10:43:19 -07001712bool Layer::isLegacyDataSpace() const {
1713 // return true when no higher bits are set
Chia-I Wu01591c92018-05-22 12:03:00 -07001714 return !(mCurrentDataSpace & (ui::Dataspace::STANDARD_MASK |
Chia-I Wu11481472018-05-04 10:43:19 -07001715 ui::Dataspace::TRANSFER_MASK | ui::Dataspace::RANGE_MASK));
Peiyong Lindd9b2ae2018-03-01 16:22:45 -08001716}
1717
Robert Carr1f0a16a2016-10-24 16:27:39 -07001718void Layer::setParent(const sp<Layer>& layer) {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001719 mCurrentParent = layer;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001720}
1721
1722void Layer::clearSyncPoints() {
1723 for (const auto& child : mCurrentChildren) {
1724 child->clearSyncPoints();
1725 }
1726
1727 Mutex::Autolock lock(mLocalSyncPointMutex);
1728 for (auto& point : mLocalSyncPoints) {
1729 point->setFrameAvailable();
1730 }
1731 mLocalSyncPoints.clear();
1732}
1733
1734int32_t Layer::getZ() const {
1735 return mDrawingState.z;
1736}
1737
Robert Carr29abff82017-12-04 13:51:20 -08001738bool Layer::usingRelativeZ(LayerVector::StateSet stateSet) {
1739 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1740 const State& state = useDrawing ? mDrawingState : mCurrentState;
1741 return state.zOrderRelativeOf != nullptr;
1742}
1743
David Sodman41fdfc92017-11-06 16:09:56 -08001744__attribute__((no_sanitize("unsigned-integer-overflow"))) LayerVector Layer::makeTraversalList(
Robert Carr29abff82017-12-04 13:51:20 -08001745 LayerVector::StateSet stateSet, bool* outSkipRelativeZUsers) {
Dan Stoza412903f2017-04-27 13:42:17 -07001746 LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid,
1747 "makeTraversalList received invalid stateSet");
1748 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1749 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
1750 const State& state = useDrawing ? mDrawingState : mCurrentState;
1751
Robert Carr29abff82017-12-04 13:51:20 -08001752 if (state.zOrderRelatives.size() == 0) {
1753 *outSkipRelativeZUsers = true;
1754 return children;
1755 }
1756
chaviwfd462612018-05-31 16:11:27 -07001757 LayerVector traverse(stateSet);
Dan Stoza412903f2017-04-27 13:42:17 -07001758 for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
Robert Carrdb66e622017-04-10 16:55:57 -07001759 sp<Layer> strongRelative = weakRelative.promote();
1760 if (strongRelative != nullptr) {
1761 traverse.add(strongRelative);
Robert Carrdb66e622017-04-10 16:55:57 -07001762 }
1763 }
1764
Dan Stoza412903f2017-04-27 13:42:17 -07001765 for (const sp<Layer>& child : children) {
Robert Carr503c7042017-09-27 15:06:08 -07001766 const State& childState = useDrawing ? child->mDrawingState : child->mCurrentState;
1767 if (childState.zOrderRelativeOf != nullptr) {
1768 continue;
1769 }
Robert Carrdb66e622017-04-10 16:55:57 -07001770 traverse.add(child);
1771 }
1772
1773 return traverse;
1774}
1775
Robert Carr1f0a16a2016-10-24 16:27:39 -07001776/**
Robert Carrdb66e622017-04-10 16:55:57 -07001777 * Negatively signed relatives are before 'this' in Z-order.
Robert Carr1f0a16a2016-10-24 16:27:39 -07001778 */
Dan Stoza412903f2017-04-27 13:42:17 -07001779void Layer::traverseInZOrder(LayerVector::StateSet stateSet, const LayerVector::Visitor& visitor) {
Robert Carr29abff82017-12-04 13:51:20 -08001780 // In the case we have other layers who are using a relative Z to us, makeTraversalList will
1781 // produce a new list for traversing, including our relatives, and not including our children
1782 // who are relatives of another surface. In the case that there are no relative Z,
1783 // makeTraversalList returns our children directly to avoid significant overhead.
1784 // However in this case we need to take the responsibility for filtering children which
1785 // are relatives of another surface here.
1786 bool skipRelativeZUsers = false;
1787 const LayerVector list = makeTraversalList(stateSet, &skipRelativeZUsers);
Robert Carrdb66e622017-04-10 16:55:57 -07001788
Robert Carr1f0a16a2016-10-24 16:27:39 -07001789 size_t i = 0;
Robert Carrdb66e622017-04-10 16:55:57 -07001790 for (; i < list.size(); i++) {
1791 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001792 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1793 continue;
1794 }
1795
Robert Carrdb66e622017-04-10 16:55:57 -07001796 if (relative->getZ() >= 0) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001797 break;
Robert Carrdb66e622017-04-10 16:55:57 -07001798 }
Dan Stoza412903f2017-04-27 13:42:17 -07001799 relative->traverseInZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001800 }
Robert Carr29abff82017-12-04 13:51:20 -08001801
Dan Stoza412903f2017-04-27 13:42:17 -07001802 visitor(this);
Robert Carrdb66e622017-04-10 16:55:57 -07001803 for (; i < list.size(); i++) {
1804 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001805
1806 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1807 continue;
1808 }
Dan Stoza412903f2017-04-27 13:42:17 -07001809 relative->traverseInZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001810 }
1811}
1812
1813/**
Robert Carrdb66e622017-04-10 16:55:57 -07001814 * Positively signed relatives are before 'this' in reverse Z-order.
Robert Carr1f0a16a2016-10-24 16:27:39 -07001815 */
Dan Stoza412903f2017-04-27 13:42:17 -07001816void Layer::traverseInReverseZOrder(LayerVector::StateSet stateSet,
1817 const LayerVector::Visitor& visitor) {
Robert Carr29abff82017-12-04 13:51:20 -08001818 // See traverseInZOrder for documentation.
1819 bool skipRelativeZUsers = false;
1820 LayerVector list = makeTraversalList(stateSet, &skipRelativeZUsers);
Robert Carrdb66e622017-04-10 16:55:57 -07001821
Robert Carr1f0a16a2016-10-24 16:27:39 -07001822 int32_t i = 0;
Joel Galensonbf324992017-11-06 11:04:12 -08001823 for (i = int32_t(list.size()) - 1; i >= 0; i--) {
Robert Carrdb66e622017-04-10 16:55:57 -07001824 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001825
1826 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1827 continue;
1828 }
1829
Robert Carrdb66e622017-04-10 16:55:57 -07001830 if (relative->getZ() < 0) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001831 break;
1832 }
Dan Stoza412903f2017-04-27 13:42:17 -07001833 relative->traverseInReverseZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001834 }
Dan Stoza412903f2017-04-27 13:42:17 -07001835 visitor(this);
David Sodman41fdfc92017-11-06 16:09:56 -08001836 for (; i >= 0; i--) {
Robert Carrdb66e622017-04-10 16:55:57 -07001837 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001838
1839 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1840 continue;
1841 }
1842
Dan Stoza412903f2017-04-27 13:42:17 -07001843 relative->traverseInReverseZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001844 }
1845}
1846
chaviw4b129c22018-04-09 16:19:43 -07001847LayerVector Layer::makeChildrenTraversalList(LayerVector::StateSet stateSet,
1848 const std::vector<Layer*>& layersInTree) {
1849 LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid,
1850 "makeTraversalList received invalid stateSet");
chaviwa76b2712017-09-20 12:02:26 -07001851 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1852 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
chaviw4b129c22018-04-09 16:19:43 -07001853 const State& state = useDrawing ? mDrawingState : mCurrentState;
1854
chaviwfd462612018-05-31 16:11:27 -07001855 LayerVector traverse(stateSet);
chaviw4b129c22018-04-09 16:19:43 -07001856 for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
1857 sp<Layer> strongRelative = weakRelative.promote();
1858 // Only add relative layers that are also descendents of the top most parent of the tree.
1859 // If a relative layer is not a descendent, then it should be ignored.
1860 if (std::binary_search(layersInTree.begin(), layersInTree.end(), strongRelative.get())) {
1861 traverse.add(strongRelative);
1862 }
1863 }
1864
1865 for (const sp<Layer>& child : children) {
1866 const State& childState = useDrawing ? child->mDrawingState : child->mCurrentState;
1867 // If a layer has a relativeOf layer, only ignore if the layer it's relative to is a
1868 // descendent of the top most parent of the tree. If it's not a descendent, then just add
1869 // the child here since it won't be added later as a relative.
1870 if (std::binary_search(layersInTree.begin(), layersInTree.end(),
1871 childState.zOrderRelativeOf.promote().get())) {
1872 continue;
1873 }
1874 traverse.add(child);
1875 }
1876
1877 return traverse;
1878}
1879
1880void Layer::traverseChildrenInZOrderInner(const std::vector<Layer*>& layersInTree,
1881 LayerVector::StateSet stateSet,
1882 const LayerVector::Visitor& visitor) {
1883 const LayerVector list = makeChildrenTraversalList(stateSet, layersInTree);
chaviwa76b2712017-09-20 12:02:26 -07001884
1885 size_t i = 0;
chaviw4b129c22018-04-09 16:19:43 -07001886 for (; i < list.size(); i++) {
1887 const auto& relative = list[i];
chaviwa76b2712017-09-20 12:02:26 -07001888 if (relative->getZ() >= 0) {
1889 break;
1890 }
chaviw4b129c22018-04-09 16:19:43 -07001891 relative->traverseChildrenInZOrderInner(layersInTree, stateSet, visitor);
chaviwa76b2712017-09-20 12:02:26 -07001892 }
chaviw4b129c22018-04-09 16:19:43 -07001893
chaviwa76b2712017-09-20 12:02:26 -07001894 visitor(this);
chaviw4b129c22018-04-09 16:19:43 -07001895 for (; i < list.size(); i++) {
1896 const auto& relative = list[i];
1897 relative->traverseChildrenInZOrderInner(layersInTree, stateSet, visitor);
chaviwa76b2712017-09-20 12:02:26 -07001898 }
1899}
1900
chaviw4b129c22018-04-09 16:19:43 -07001901std::vector<Layer*> Layer::getLayersInTree(LayerVector::StateSet stateSet) {
1902 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1903 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
1904
1905 std::vector<Layer*> layersInTree = {this};
1906 for (size_t i = 0; i < children.size(); i++) {
1907 const auto& child = children[i];
1908 std::vector<Layer*> childLayers = child->getLayersInTree(stateSet);
1909 layersInTree.insert(layersInTree.end(), childLayers.cbegin(), childLayers.cend());
1910 }
1911
1912 return layersInTree;
1913}
1914
1915void Layer::traverseChildrenInZOrder(LayerVector::StateSet stateSet,
1916 const LayerVector::Visitor& visitor) {
1917 std::vector<Layer*> layersInTree = getLayersInTree(stateSet);
1918 std::sort(layersInTree.begin(), layersInTree.end());
1919 traverseChildrenInZOrderInner(layersInTree, stateSet, visitor);
1920}
1921
Peiyong Linefefaac2018-08-17 12:27:51 -07001922ui::Transform Layer::getTransform() const {
1923 ui::Transform t;
Chia-I Wue41dbe62017-06-13 14:10:56 -07001924 const auto& p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001925 if (p != nullptr) {
1926 t = p->getTransform();
Robert Carr9b429f42017-04-17 14:56:57 -07001927
1928 // If the parent is not using NATIVE_WINDOW_SCALING_MODE_FREEZE (e.g.
1929 // it isFixedSize) then there may be additional scaling not accounted
1930 // for in the transform. We need to mirror this scaling in child surfaces
1931 // or we will break the contract where WM can treat child surfaces as
1932 // pixels in the parent surface.
David Sodman0cc69182017-11-17 12:12:07 -08001933 if (p->isFixedSize() && p->getBE().compositionInfo.mBuffer != nullptr) {
Robert Carr1725eee2017-04-26 18:32:15 -07001934 int bufferWidth;
1935 int bufferHeight;
1936 if ((p->mCurrentTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) == 0) {
David Sodman0cc69182017-11-17 12:12:07 -08001937 bufferWidth = p->getBE().compositionInfo.mBuffer->getWidth();
1938 bufferHeight = p->getBE().compositionInfo.mBuffer->getHeight();
Robert Carr1725eee2017-04-26 18:32:15 -07001939 } else {
David Sodman0cc69182017-11-17 12:12:07 -08001940 bufferHeight = p->getBE().compositionInfo.mBuffer->getWidth();
1941 bufferWidth = p->getBE().compositionInfo.mBuffer->getHeight();
Robert Carr1725eee2017-04-26 18:32:15 -07001942 }
Marissa Wall61c58622018-07-18 10:12:20 -07001943 float sx = p->getActiveWidth(p->getDrawingState()) / static_cast<float>(bufferWidth);
1944 float sy = p->getActiveHeight(p->getDrawingState()) / static_cast<float>(bufferHeight);
Peiyong Linefefaac2018-08-17 12:27:51 -07001945 ui::Transform extraParentScaling;
Robert Carr9b429f42017-04-17 14:56:57 -07001946 extraParentScaling.set(sx, 0, 0, sy);
1947 t = t * extraParentScaling;
1948 }
Robert Carr1f0a16a2016-10-24 16:27:39 -07001949 }
Marissa Wall61c58622018-07-18 10:12:20 -07001950 return t * getActiveTransform(getDrawingState());
Robert Carr1f0a16a2016-10-24 16:27:39 -07001951}
1952
chaviw13fdc492017-06-27 12:40:18 -07001953half Layer::getAlpha() const {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001954 const auto& p = mDrawingParent.promote();
Robert Carr6452f122017-03-21 10:41:29 -07001955
chaviw13fdc492017-06-27 12:40:18 -07001956 half parentAlpha = (p != nullptr) ? p->getAlpha() : 1.0_hf;
1957 return parentAlpha * getDrawingState().color.a;
Robert Carr6452f122017-03-21 10:41:29 -07001958}
Robert Carr6452f122017-03-21 10:41:29 -07001959
chaviw13fdc492017-06-27 12:40:18 -07001960half4 Layer::getColor() const {
1961 const half4 color(getDrawingState().color);
1962 return half4(color.r, color.g, color.b, getAlpha());
Robert Carr6452f122017-03-21 10:41:29 -07001963}
Robert Carr6452f122017-03-21 10:41:29 -07001964
Lucas Dupin1b6531c2018-07-05 17:18:21 -07001965Layer::RoundedCornerState Layer::getRoundedCornerState() const {
1966 const auto& p = mDrawingParent.promote();
1967 if (p != nullptr) {
1968 RoundedCornerState parentState = p->getRoundedCornerState();
1969 if (parentState.radius > 0) {
1970 ui::Transform t = getActiveTransform(getDrawingState());
1971 t = t.inverse();
1972 parentState.cropRect = t.transform(parentState.cropRect);
1973 // The rounded corners shader only accepts 1 corner radius for performance reasons,
1974 // but a transform matrix can define horizontal and vertical scales.
1975 // Let's take the average between both of them and pass into the shader, practically we
1976 // never do this type of transformation on windows anyway.
1977 parentState.radius *= (t[0][0] + t[1][1]) / 2.0f;
1978 return parentState;
1979 }
1980 }
1981 const float radius = getDrawingState().cornerRadius;
1982 return radius > 0 ? RoundedCornerState(computeBounds(), radius) : RoundedCornerState();
1983}
1984
Robert Carr1f0a16a2016-10-24 16:27:39 -07001985void Layer::commitChildList() {
1986 for (size_t i = 0; i < mCurrentChildren.size(); i++) {
1987 const auto& child = mCurrentChildren[i];
1988 child->commitChildList();
1989 }
1990 mDrawingChildren = mCurrentChildren;
Chia-I Wue41dbe62017-06-13 14:10:56 -07001991 mDrawingParent = mCurrentParent;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001992}
1993
Robert Carr720e5062018-07-30 17:45:14 -07001994void Layer::setInputInfo(const InputWindowInfo& info) {
1995 mCurrentState.inputInfo = info;
1996 mCurrentState.modified = true;
1997 mCurrentState.inputInfoChanged = true;
1998 setTransactionFlags(eTransactionNeeded);
1999}
2000
chaviw1d044282017-09-27 12:19:28 -07002001void Layer::writeToProto(LayerProto* layerInfo, LayerVector::StateSet stateSet) {
2002 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
2003 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
2004 const State& state = useDrawing ? mDrawingState : mCurrentState;
2005
Peiyong Linefefaac2018-08-17 12:27:51 -07002006 ui::Transform requestedTransform = state.active_legacy.transform;
2007 ui::Transform transform = getTransform();
chaviw1d044282017-09-27 12:19:28 -07002008
2009 layerInfo->set_id(sequence);
2010 layerInfo->set_name(getName().c_str());
2011 layerInfo->set_type(String8(getTypeId()));
2012
2013 for (const auto& child : children) {
2014 layerInfo->add_children(child->sequence);
2015 }
2016
2017 for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
2018 sp<Layer> strongRelative = weakRelative.promote();
2019 if (strongRelative != nullptr) {
2020 layerInfo->add_relatives(strongRelative->sequence);
2021 }
2022 }
2023
Marissa Wallf58c14b2018-07-24 10:50:43 -07002024 LayerProtoHelper::writeToProto(state.activeTransparentRegion_legacy,
chaviw1d044282017-09-27 12:19:28 -07002025 layerInfo->mutable_transparent_region());
2026 LayerProtoHelper::writeToProto(visibleRegion, layerInfo->mutable_visible_region());
2027 LayerProtoHelper::writeToProto(surfaceDamageRegion, layerInfo->mutable_damage_region());
2028
2029 layerInfo->set_layer_stack(getLayerStack());
2030 layerInfo->set_z(state.z);
2031
2032 PositionProto* position = layerInfo->mutable_position();
2033 position->set_x(transform.tx());
2034 position->set_y(transform.ty());
2035
2036 PositionProto* requestedPosition = layerInfo->mutable_requested_position();
2037 requestedPosition->set_x(requestedTransform.tx());
2038 requestedPosition->set_y(requestedTransform.ty());
2039
2040 SizeProto* size = layerInfo->mutable_size();
Marissa Wallf58c14b2018-07-24 10:50:43 -07002041 size->set_w(state.active_legacy.w);
2042 size->set_h(state.active_legacy.h);
chaviw1d044282017-09-27 12:19:28 -07002043
Marissa Wallf58c14b2018-07-24 10:50:43 -07002044 LayerProtoHelper::writeToProto(state.crop_legacy, layerInfo->mutable_crop());
Lucas Dupin1b6531c2018-07-05 17:18:21 -07002045 layerInfo->set_corner_radius(getRoundedCornerState().radius);
chaviw1d044282017-09-27 12:19:28 -07002046
2047 layerInfo->set_is_opaque(isOpaque(state));
2048 layerInfo->set_invalidate(contentDirty);
Chia-I Wu01591c92018-05-22 12:03:00 -07002049
2050 // XXX (b/79210409) mCurrentDataSpace is not protected
2051 layerInfo->set_dataspace(dataspaceDetails(static_cast<android_dataspace>(mCurrentDataSpace)));
2052
chaviw1d044282017-09-27 12:19:28 -07002053 layerInfo->set_pixel_format(decodePixelFormat(getPixelFormat()));
2054 LayerProtoHelper::writeToProto(getColor(), layerInfo->mutable_color());
2055 LayerProtoHelper::writeToProto(state.color, layerInfo->mutable_requested_color());
2056 layerInfo->set_flags(state.flags);
2057
2058 LayerProtoHelper::writeToProto(transform, layerInfo->mutable_transform());
2059 LayerProtoHelper::writeToProto(requestedTransform, layerInfo->mutable_requested_transform());
2060
Jorim Jaggi8e0af362017-11-14 16:28:28 +01002061 auto parent = useDrawing ? mDrawingParent.promote() : mCurrentParent.promote();
chaviw1d044282017-09-27 12:19:28 -07002062 if (parent != nullptr) {
2063 layerInfo->set_parent(parent->sequence);
2064 }
2065
2066 auto zOrderRelativeOf = state.zOrderRelativeOf.promote();
2067 if (zOrderRelativeOf != nullptr) {
2068 layerInfo->set_z_order_relative_of(zOrderRelativeOf->sequence);
2069 }
2070
Chia-I Wu01591c92018-05-22 12:03:00 -07002071 // XXX getBE().compositionInfo.mBuffer is not protected
David Sodman0cc69182017-11-17 12:12:07 -08002072 auto buffer = getBE().compositionInfo.mBuffer;
David Sodman5b4cffc2017-11-23 13:20:29 -08002073 if (buffer != nullptr) {
2074 LayerProtoHelper::writeToProto(buffer, layerInfo->mutable_active_buffer());
Peiyong Linefefaac2018-08-17 12:27:51 -07002075 LayerProtoHelper::writeToProto(ui::Transform(mCurrentTransform),
Yichi Chen6ca35192018-05-29 12:20:43 +08002076 layerInfo->mutable_buffer_transform());
chaviw1d044282017-09-27 12:19:28 -07002077 }
2078
2079 layerInfo->set_queued_frames(getQueuedFrameCount());
2080 layerInfo->set_refresh_pending(isBufferLatched());
rongliucfb187b2018-03-14 12:26:23 -07002081 layerInfo->set_window_type(state.type);
2082 layerInfo->set_app_id(state.appId);
chaviwadc40c22018-07-10 16:57:27 -07002083 layerInfo->set_curr_frame(mCurrentFrameNumber);
Vishnu Nairf2deb822018-11-12 17:53:48 -08002084 layerInfo->set_effective_scaling_mode(getEffectiveScalingMode());
chaviwadc40c22018-07-10 16:57:27 -07002085
2086 for (const auto& pendingState : mPendingStates) {
Marissa Wallf58c14b2018-07-24 10:50:43 -07002087 auto barrierLayer = pendingState.barrierLayer_legacy.promote();
chaviwadc40c22018-07-10 16:57:27 -07002088 if (barrierLayer != nullptr) {
2089 BarrierLayerProto* barrierLayerProto = layerInfo->add_barrier_layer();
2090 barrierLayerProto->set_id(barrierLayer->sequence);
Marissa Wallf58c14b2018-07-24 10:50:43 -07002091 barrierLayerProto->set_frame_number(pendingState.frameNumber_legacy);
chaviwadc40c22018-07-10 16:57:27 -07002092 }
2093 }
chaviw1d044282017-09-27 12:19:28 -07002094}
2095
Dominik Laskowski075d3172018-05-24 15:50:06 -07002096void Layer::writeToProto(LayerProto* layerInfo, DisplayId displayId) {
Peiyong Lin91b1df22018-06-18 18:00:16 -07002097 if (!hasHwcLayer(displayId)) {
2098 return;
2099 }
2100
Yiwei Zhang7124ad32018-02-21 13:02:45 -08002101 writeToProto(layerInfo, LayerVector::StateSet::Drawing);
2102
Dominik Laskowski7e045462018-05-30 13:02:02 -07002103 const auto& hwcInfo = getBE().mHwcLayers.at(displayId);
Yiwei Zhang7124ad32018-02-21 13:02:45 -08002104
2105 const Rect& frame = hwcInfo.displayFrame;
2106 LayerProtoHelper::writeToProto(frame, layerInfo->mutable_hwc_frame());
2107
2108 const FloatRect& crop = hwcInfo.sourceCrop;
2109 LayerProtoHelper::writeToProto(crop, layerInfo->mutable_hwc_crop());
2110
2111 const int32_t transform = static_cast<int32_t>(hwcInfo.transform);
2112 layerInfo->set_hwc_transform(transform);
Yiwei Zhang60d1a192018-03-07 14:52:28 -08002113
2114 const int32_t compositionType = static_cast<int32_t>(hwcInfo.compositionType);
2115 layerInfo->set_hwc_composition_type(compositionType);
2116
2117 if (std::strcmp(getTypeId(), "BufferLayer") == 0 &&
2118 static_cast<BufferLayer*>(this)->isProtected()) {
2119 layerInfo->set_is_protected(true);
2120 } else {
2121 layerInfo->set_is_protected(false);
2122 }
Yiwei Zhang7124ad32018-02-21 13:02:45 -08002123}
2124
Robert Carr2e102c92018-10-23 12:11:15 -07002125bool Layer::isRemovedFromCurrentState() const {
2126 return mRemovedFromCurrentState;
2127}
2128
Robert Carr720e5062018-07-30 17:45:14 -07002129InputWindowInfo Layer::fillInputInfo(const Rect& screenBounds) {
2130 InputWindowInfo info = mDrawingState.inputInfo;
Robert Carr720e5062018-07-30 17:45:14 -07002131
Robert Carre07e1032018-11-26 12:55:53 -08002132 ui::Transform t = getTransform();
Riddle Hsu39d4aa52018-11-30 20:46:53 +08002133 const float xScale = t.sx();
2134 const float yScale = t.sy();
2135 if (xScale != 1.0f || yScale != 1.0f) {
2136 info.windowXScale *= 1.0f / xScale;
2137 info.windowYScale *= 1.0f / yScale;
2138 info.touchableRegion.scaleSelf(xScale, yScale);
2139 }
Robert Carre07e1032018-11-26 12:55:53 -08002140
Vishnu Nair8033a492018-12-05 07:27:23 -08002141 // Transform layer size to screen space and inset it by surface insets.
2142 Rect layerBounds = getCroppedBufferSize(getDrawingState());
2143 layerBounds = t.transform(layerBounds);
2144 layerBounds.inset(info.surfaceInset, info.surfaceInset, info.surfaceInset, info.surfaceInset);
2145
2146 // Intersect with screen bounds to shrink the frame by the surface insets. The surface insets
2147 // are not set on the screen bounds directly since the surface inset region may already be
2148 // cropped by a parent layer.
2149 Rect frame;
2150 screenBounds.intersect(layerBounds, &frame);
2151
2152 info.frameLeft = frame.left;
2153 info.frameTop = frame.top;
2154 info.frameRight = frame.right;
2155 info.frameBottom = frame.bottom;
2156
2157 // Position the touchable region relative to frame screen location and restrict it to frame
2158 // bounds.
2159 info.touchableRegion = info.touchableRegion.translate(info.frameLeft, info.frameTop);
Robert Carr720e5062018-07-30 17:45:14 -07002160 info.visible = isVisible();
2161 return info;
2162}
2163
2164bool Layer::hasInput() const {
Robert Carr5c8a0262018-10-03 16:30:44 -07002165 return mDrawingState.inputInfo.token != nullptr;
Robert Carr720e5062018-07-30 17:45:14 -07002166}
2167
Mathias Agopian13127d82013-03-05 17:47:11 -08002168// ---------------------------------------------------------------------------
2169
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002170}; // namespace android
Mathias Agopian3f844832013-08-07 21:24:32 -07002171
2172#if defined(__gl_h_)
2173#error "don't include gl/gl.h in this file"
2174#endif
2175
2176#if defined(__gl2_h_)
2177#error "don't include gl2/gl2.h in this file"
2178#endif