blob: 13df1e21b439a77a84e1c24117ffcdb2e3318aeb [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>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080026
Mathias Agopiana67932f2011-04-20 14:20:59 -070027#include <cutils/compiler.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070028#include <cutils/native_handle.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070029#include <cutils/properties.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080030
31#include <utils/Errors.h>
32#include <utils/Log.h>
Jesse Hall399184a2014-03-03 15:42:54 -080033#include <utils/NativeHandle.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080034#include <utils/StopWatch.h>
Jamie Gennis1c8e95c2012-02-23 19:27:23 -080035#include <utils/Trace.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080036
Courtney Goeltzenleuchter36c44dc2017-04-14 09:33:16 -060037#include <ui/DebugUtils.h>
Mathias Agopian3330b202009-10-05 17:07:12 -070038#include <ui/GraphicBuffer.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080039#include <ui/PixelFormat.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080040
Dan Stoza6b9454d2014-11-07 16:00:59 -080041#include <gui/BufferItem.h>
Kalle Raitaa099a242017-01-11 11:17:29 -080042#include <gui/LayerDebugInfo.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080043#include <gui/Surface.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044
Mathias Agopian3e25fd82013-04-22 17:52:16 +020045#include "Colorizer.h"
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070046#include "DisplayDevice.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080047#include "Layer.h"
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070048#include "LayerRejecter.h"
Dan Stozab9b08832014-03-13 11:55:57 -070049#include "MonitoredProducer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080050#include "SurfaceFlinger.h"
David Sodman41fdfc92017-11-06 16:09:56 -080051#include "clz.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080052
Mathias Agopian1b031492012-06-20 17:51:20 -070053#include "DisplayHardware/HWComposer.h"
54
Mathias Agopian875d8e12013-06-07 15:35:48 -070055#include "RenderEngine/RenderEngine.h"
56
Dan Stozac5da2712016-07-20 15:38:12 -070057#include <mutex>
chaviw1d044282017-09-27 12:19:28 -070058#include "LayerProtoHelper.h"
Dan Stozac5da2712016-07-20 15:38:12 -070059
David Sodman41fdfc92017-11-06 16:09:56 -080060#define DEBUG_RESIZE 0
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080062namespace android {
63
David Sodman9eeae692017-11-02 10:53:32 -070064LayerBE::LayerBE()
David Sodman0cc69182017-11-17 12:12:07 -080065 : mMesh(Mesh::TRIANGLE_FAN, 4, 2, 2) {
David Sodman9eeae692017-11-02 10:53:32 -070066}
67
68
Mathias Agopian13127d82013-03-05 17:47:11 -080069int32_t Layer::sSequence = 1;
70
David Sodman41fdfc92017-11-06 16:09:56 -080071Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client, const String8& name, uint32_t w,
72 uint32_t h, uint32_t flags)
David Sodman0c69cad2017-08-21 12:12:51 -070073 : contentDirty(false),
Mathias Agopian13127d82013-03-05 17:47:11 -080074 sequence(uint32_t(android_atomic_inc(&sSequence))),
75 mFlinger(flinger),
Mathias Agopian13127d82013-03-05 17:47:11 -080076 mPremultipliedAlpha(true),
David Sodman0c69cad2017-08-21 12:12:51 -070077 mName(name),
Mathias Agopian13127d82013-03-05 17:47:11 -080078 mTransactionFlags(0),
Dan Stoza7dde5992015-05-22 09:51:44 -070079 mPendingStateMutex(),
80 mPendingStates(),
Mathias Agopiana67932f2011-04-20 14:20:59 -070081 mQueuedFrames(0),
Jesse Hall399184a2014-03-03 15:42:54 -080082 mSidebandStreamChanged(false),
Mathias Agopiana9347642017-02-13 16:42:28 -080083 mActiveBufferSlot(BufferQueue::INVALID_BUFFER_SLOT),
Mathias Agopiana67932f2011-04-20 14:20:59 -070084 mCurrentTransform(0),
Robert Carrc3574f72016-03-24 12:19:32 -070085 mOverrideScalingMode(-1),
Mathias Agopiana67932f2011-04-20 14:20:59 -070086 mCurrentOpacity(true),
Dan Stozacac35382016-01-27 12:21:06 -080087 mCurrentFrameNumber(0),
Mathias Agopian82d7ab62012-01-19 18:34:40 -080088 mFrameLatencyNeeded(false),
Mathias Agopian13127d82013-03-05 17:47:11 -080089 mFiltering(false),
90 mNeedsFiltering(false),
Mathias Agopian13127d82013-03-05 17:47:11 -080091 mProtectedByApp(false),
Riley Andrews03414a12014-07-01 14:22:59 -070092 mClientRef(client),
Dan Stozaa4650a52015-05-12 12:56:16 -070093 mPotentialCursor(false),
94 mQueueItemLock(),
95 mQueueItemCondition(),
96 mQueueItems(),
Dan Stoza65476f32015-05-14 09:27:25 -070097 mLastFrameNumberReceived(0),
Robert Carr82364e32016-05-15 11:27:47 -070098 mAutoRefresh(false),
David Sodman41fdfc92017-11-06 16:09:56 -080099 mFreezeGeometryUpdates(false) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800100
Mathias Agopiana67932f2011-04-20 14:20:59 -0700101 mCurrentCrop.makeInvalid();
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700102
103 uint32_t layerFlags = 0;
David Sodman41fdfc92017-11-06 16:09:56 -0800104 if (flags & ISurfaceComposerClient::eHidden) layerFlags |= layer_state_t::eLayerHidden;
105 if (flags & ISurfaceComposerClient::eOpaque) layerFlags |= layer_state_t::eLayerOpaque;
106 if (flags & ISurfaceComposerClient::eSecure) layerFlags |= layer_state_t::eLayerSecure;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700107
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700108 mName = name;
Dan Stozaf7ba41a2017-05-10 15:11:11 -0700109 mTransactionName = String8("TX - ") + mName;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700110
111 mCurrentState.active.w = w;
112 mCurrentState.active.h = h;
David Sodman0c69cad2017-08-21 12:12:51 -0700113 mCurrentState.flags = layerFlags;
Robert Carr3dcabfa2016-03-01 18:36:58 -0800114 mCurrentState.active.transform.set(0, 0);
Robert Carrb5d3d262016-03-25 15:08:13 -0700115 mCurrentState.crop.makeInvalid();
116 mCurrentState.finalCrop.makeInvalid();
Robert Carr7bf247e2017-05-18 14:02:49 -0700117 mCurrentState.requestedFinalCrop = mCurrentState.finalCrop;
118 mCurrentState.requestedCrop = mCurrentState.crop;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700119 mCurrentState.z = 0;
chaviw13fdc492017-06-27 12:40:18 -0700120 mCurrentState.color.a = 1.0f;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700121 mCurrentState.layerStack = 0;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700122 mCurrentState.sequence = 0;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700123 mCurrentState.requested = mCurrentState.active;
Courtney Goeltzenleuchterbb09b432016-11-30 13:51:28 -0700124 mCurrentState.dataSpace = HAL_DATASPACE_UNKNOWN;
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -0500125 mCurrentState.appId = 0;
126 mCurrentState.type = 0;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700127
128 // drawing state & current state are identical
129 mDrawingState = mCurrentState;
Jamie Gennis6547ff42013-07-16 20:12:42 -0700130
Dan Stoza9e56aa02015-11-02 13:00:03 -0800131 const auto& hwc = flinger->getHwComposer();
132 const auto& activeConfig = hwc.getActiveConfig(HWC_DISPLAY_PRIMARY);
133 nsecs_t displayPeriod = activeConfig->getVsyncPeriod();
Jamie Gennis6547ff42013-07-16 20:12:42 -0700134 mFrameTracker.setDisplayRefreshPeriod(displayPeriod);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800135
136 CompositorTiming compositorTiming;
137 flinger->getCompositorTiming(&compositorTiming);
138 mFrameEventHistory.initializeCompositorTiming(compositorTiming);
David Sodman9eeae692017-11-02 10:53:32 -0700139
Jamie Gennise8696a42012-01-15 18:54:57 -0800140}
141
David Sodman41fdfc92017-11-06 16:09:56 -0800142void Layer::onFirstRef() {}
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700143
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700144Layer::~Layer() {
David Sodman577c8962017-12-08 14:50:53 -0800145 sp<Client> c(mClientRef.promote());
146 if (c != 0) {
147 c->detachLayer(this);
148 }
149
150 for (auto& point : mRemoteSyncPoints) {
151 point->setTransactionApplied();
152 }
153 for (auto& point : mLocalSyncPoints) {
154 point->setFrameAvailable();
155 }
Jamie Gennis6547ff42013-07-16 20:12:42 -0700156 mFrameTracker.logAndResetStats(mName);
Mathias Agopian96f08192010-06-02 23:28:45 -0700157}
158
Mathias Agopian13127d82013-03-05 17:47:11 -0800159// ---------------------------------------------------------------------------
160// callbacks
161// ---------------------------------------------------------------------------
162
David Sodmaneb085e02017-10-05 18:49:04 -0700163/*
164 * onLayerDisplayed is only meaningful for BufferLayer, but, is called through
165 * Layer. So, the implementation is done in BufferLayer. When called on a
166 * ColorLayer object, it's essentially a NOP.
167 */
David Sodmaneb085e02017-10-05 18:49:04 -0700168void Layer::onLayerDisplayed(const sp<Fence>& /*releaseFence*/) {}
Mathias Agopian13127d82013-03-05 17:47:11 -0800169
Chia-I Wuc6657022017-08-15 11:18:17 -0700170void Layer::onRemovedFromCurrentState() {
171 // the layer is removed from SF mCurrentState to mLayersPendingRemoval
172
chaviw8b3871a2017-11-01 17:41:01 -0700173 mPendingRemoval = true;
174
Robert Carr5edb1ad2017-04-25 10:54:24 -0700175 if (mCurrentState.zOrderRelativeOf != nullptr) {
176 sp<Layer> strongRelative = mCurrentState.zOrderRelativeOf.promote();
177 if (strongRelative != nullptr) {
178 strongRelative->removeZOrderRelative(this);
Chia-I Wuc6657022017-08-15 11:18:17 -0700179 mFlinger->setTransactionFlags(eTraversalNeeded);
Robert Carr5edb1ad2017-04-25 10:54:24 -0700180 }
181 mCurrentState.zOrderRelativeOf = nullptr;
182 }
183
Chia-I Wuc6657022017-08-15 11:18:17 -0700184 for (const auto& child : mCurrentChildren) {
185 child->onRemovedFromCurrentState();
186 }
187}
Chia-I Wu38512252017-05-17 14:36:16 -0700188
Chia-I Wuc6657022017-08-15 11:18:17 -0700189void Layer::onRemoved() {
190 // the layer is removed from SF mLayersPendingRemoval
David Sodmaneb085e02017-10-05 18:49:04 -0700191 abandon();
Chia-I Wuc6657022017-08-15 11:18:17 -0700192
Steven Thomasb02664d2017-07-26 18:48:28 -0700193 destroyAllHwcLayers();
Chia-I Wu38512252017-05-17 14:36:16 -0700194
Robert Carr1f0a16a2016-10-24 16:27:39 -0700195 for (const auto& child : mCurrentChildren) {
196 child->onRemoved();
197 }
Mathias Agopian48d819a2009-09-10 19:41:18 -0700198}
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700199
Mathias Agopian13127d82013-03-05 17:47:11 -0800200// ---------------------------------------------------------------------------
201// set-up
202// ---------------------------------------------------------------------------
203
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700204const String8& Layer::getName() const {
Mathias Agopian13127d82013-03-05 17:47:11 -0800205 return mName;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800206}
207
chaviw13fdc492017-06-27 12:40:18 -0700208bool Layer::getPremultipledAlpha() const {
209 return mPremultipliedAlpha;
210}
211
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700212sp<IBinder> Layer::getHandle() {
Mathias Agopian13127d82013-03-05 17:47:11 -0800213 Mutex::Autolock _l(mLock);
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700214 return new Handle(mFlinger, this);
Mathias Agopian13127d82013-03-05 17:47:11 -0800215}
216
217// ---------------------------------------------------------------------------
218// h/w composer set-up
219// ---------------------------------------------------------------------------
220
Steven Thomasb02664d2017-07-26 18:48:28 -0700221bool Layer::createHwcLayer(HWComposer* hwc, int32_t hwcId) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700222 LOG_ALWAYS_FATAL_IF(getBE().mHwcLayers.count(hwcId) != 0,
David Sodman9eeae692017-11-02 10:53:32 -0700223 "Already have a layer for hwcId %d", hwcId);
Steven Thomasb02664d2017-07-26 18:48:28 -0700224 HWC2::Layer* layer = hwc->createLayer(hwcId);
225 if (!layer) {
226 return false;
227 }
David Sodman6f65f3e2017-11-03 14:28:09 -0700228 LayerBE::HWCInfo& hwcInfo = getBE().mHwcLayers[hwcId];
Steven Thomasb02664d2017-07-26 18:48:28 -0700229 hwcInfo.hwc = hwc;
230 hwcInfo.layer = layer;
231 layer->setLayerDestroyedListener(
David Sodman6f65f3e2017-11-03 14:28:09 -0700232 [this, hwcId](HWC2::Layer* /*layer*/) { getBE().mHwcLayers.erase(hwcId); });
Steven Thomasb02664d2017-07-26 18:48:28 -0700233 return true;
234}
235
Chia-I Wu83806892017-11-16 10:50:20 -0800236bool Layer::destroyHwcLayer(int32_t hwcId) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700237 if (getBE().mHwcLayers.count(hwcId) == 0) {
Chia-I Wu83806892017-11-16 10:50:20 -0800238 return false;
Steven Thomasb02664d2017-07-26 18:48:28 -0700239 }
David Sodman6f65f3e2017-11-03 14:28:09 -0700240 auto& hwcInfo = getBE().mHwcLayers[hwcId];
David Sodman41fdfc92017-11-06 16:09:56 -0800241 LOG_ALWAYS_FATAL_IF(hwcInfo.layer == nullptr, "Attempt to destroy null layer");
Steven Thomasb02664d2017-07-26 18:48:28 -0700242 LOG_ALWAYS_FATAL_IF(hwcInfo.hwc == nullptr, "Missing HWComposer");
243 hwcInfo.hwc->destroyLayer(hwcId, hwcInfo.layer);
244 // The layer destroyed listener should have cleared the entry from
245 // mHwcLayers. Verify that.
David Sodman6f65f3e2017-11-03 14:28:09 -0700246 LOG_ALWAYS_FATAL_IF(getBE().mHwcLayers.count(hwcId) != 0,
247 "Stale layer entry in getBE().mHwcLayers");
Chia-I Wu83806892017-11-16 10:50:20 -0800248 return true;
Steven Thomasb02664d2017-07-26 18:48:28 -0700249}
250
251void Layer::destroyAllHwcLayers() {
David Sodman6f65f3e2017-11-03 14:28:09 -0700252 size_t numLayers = getBE().mHwcLayers.size();
Steven Thomasb02664d2017-07-26 18:48:28 -0700253 for (size_t i = 0; i < numLayers; ++i) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700254 LOG_ALWAYS_FATAL_IF(getBE().mHwcLayers.empty(), "destroyAllHwcLayers failed");
255 destroyHwcLayer(getBE().mHwcLayers.begin()->first);
Steven Thomasb02664d2017-07-26 18:48:28 -0700256 }
David Sodman6f65f3e2017-11-03 14:28:09 -0700257 LOG_ALWAYS_FATAL_IF(!getBE().mHwcLayers.empty(),
David Sodman41fdfc92017-11-06 16:09:56 -0800258 "All hardware composer layers should have been destroyed");
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;
David Sodman0cc69182017-11-17 12:12:07 -0800268 } else if (getBE().compositionInfo.mBuffer != NULL) {
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
Robert Carr1f0a16a2016-10-24 16:27:39 -0700288Rect Layer::computeScreenBounds(bool reduceTransparentRegion) const {
289 const Layer::State& s(getDrawingState());
290 Rect win(s.active.w, s.active.h);
291
292 if (!s.crop.isEmpty()) {
293 win.intersect(s.crop, &win);
294 }
295
296 Transform t = getTransform();
297 win = t.transform(win);
298
Robert Carr41b08b52017-06-01 16:11:34 -0700299 if (!s.finalCrop.isEmpty()) {
300 win.intersect(s.finalCrop, &win);
301 }
302
Chia-I Wue41dbe62017-06-13 14:10:56 -0700303 const sp<Layer>& p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700304 // Now we need to calculate the parent bounds, so we can clip ourselves to those.
305 // When calculating the parent bounds for purposes of clipping,
306 // we don't need to constrain the parent to its transparent region.
307 // The transparent region is an optimization based on the
308 // buffer contents of the layer, but does not affect the space allocated to
309 // it by policy, and thus children should be allowed to extend into the
310 // parent's transparent region. In fact one of the main uses, is to reduce
311 // buffer allocation size in cases where a child window sits behind a main window
312 // (by marking the hole in the parent window as a transparent region)
313 if (p != nullptr) {
314 Rect bounds = p->computeScreenBounds(false);
315 bounds.intersect(win, &win);
316 }
317
318 if (reduceTransparentRegion) {
319 auto const screenTransparentRegion = t.transform(s.activeTransparentRegion);
320 win = reduce(win, screenTransparentRegion);
321 }
322
323 return win;
324}
325
Mathias Agopian13127d82013-03-05 17:47:11 -0800326Rect Layer::computeBounds() const {
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700327 const Layer::State& s(getDrawingState());
Michael Lentine6c925ed2014-09-26 17:55:01 -0700328 return computeBounds(s.activeTransparentRegion);
329}
330
331Rect Layer::computeBounds(const Region& activeTransparentRegion) const {
332 const Layer::State& s(getDrawingState());
Mathias Agopian13127d82013-03-05 17:47:11 -0800333 Rect win(s.active.w, s.active.h);
Robert Carrb5d3d262016-03-25 15:08:13 -0700334
335 if (!s.crop.isEmpty()) {
336 win.intersect(s.crop, &win);
Mathias Agopian13127d82013-03-05 17:47:11 -0800337 }
Robert Carr1f0a16a2016-10-24 16:27:39 -0700338
339 Rect bounds = win;
Chia-I Wue41dbe62017-06-13 14:10:56 -0700340 const auto& p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700341 if (p != nullptr) {
Robert Carrde9ec442017-02-08 17:43:36 -0800342 // Look in computeScreenBounds recursive call for explanation of
343 // why we pass false here.
344 bounds = p->computeScreenBounds(false /* reduceTransparentRegion */);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700345 }
346
347 Transform t = getTransform();
348 if (p != nullptr) {
349 win = t.transform(win);
350 win.intersect(bounds, &win);
351 win = t.inverse().transform(win);
352 }
353
Mathias Agopian6c7f25a2013-05-09 20:37:10 -0700354 // subtract the transparent region and snap to the bounds
Michael Lentine6c925ed2014-09-26 17:55:01 -0700355 return reduce(win, activeTransparentRegion);
Mathias Agopian13127d82013-03-05 17:47:11 -0800356}
357
Robert Carr1f0a16a2016-10-24 16:27:39 -0700358Rect Layer::computeInitialCrop(const sp<const DisplayDevice>& hw) const {
Robert Carrb5d3d262016-03-25 15:08:13 -0700359 // the crop is the area of the window that gets cropped, but not
Mathias Agopian13127d82013-03-05 17:47:11 -0800360 // scaled in any ways.
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700361 const State& s(getDrawingState());
Mathias Agopian13127d82013-03-05 17:47:11 -0800362
363 // apply the projection's clipping to the window crop in
364 // layerstack space, and convert-back to layer space.
Mathias Agopian6b442672013-07-09 21:24:52 -0700365 // if there are no window scaling involved, this operation will map to full
366 // pixels in the buffer.
367 // FIXME: the 3 lines below can produce slightly incorrect clipping when we have
368 // a viewport clipping and a window transform. we should use floating point to fix this.
Mathias Agopian0e8f1442013-08-20 21:41:07 -0700369
370 Rect activeCrop(s.active.w, s.active.h);
Robert Carrb5d3d262016-03-25 15:08:13 -0700371 if (!s.crop.isEmpty()) {
Chia-I Wudf7867f2017-07-20 14:24:37 -0700372 activeCrop.intersect(s.crop, &activeCrop);
Mathias Agopian0e8f1442013-08-20 21:41:07 -0700373 }
374
Robert Carr1f0a16a2016-10-24 16:27:39 -0700375 Transform t = getTransform();
376 activeCrop = t.transform(activeCrop);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000377 if (!activeCrop.intersect(hw->getViewport(), &activeCrop)) {
378 activeCrop.clear();
379 }
Robert Carrb5d3d262016-03-25 15:08:13 -0700380 if (!s.finalCrop.isEmpty()) {
David Sodman41fdfc92017-11-06 16:09:56 -0800381 if (!activeCrop.intersect(s.finalCrop, &activeCrop)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000382 activeCrop.clear();
383 }
384 }
chaviwb1154d12017-10-31 14:15:36 -0700385
386 const auto& p = mDrawingParent.promote();
387 if (p != nullptr) {
388 auto parentCrop = p->computeInitialCrop(hw);
389 activeCrop.intersect(parentCrop, &activeCrop);
390 }
391
Robert Carr1f0a16a2016-10-24 16:27:39 -0700392 return activeCrop;
393}
394
Dan Stoza5a423ea2017-02-16 14:10:39 -0800395FloatRect Layer::computeCrop(const sp<const DisplayDevice>& hw) const {
Robert Carr1f0a16a2016-10-24 16:27:39 -0700396 // the content crop is the area of the content that gets scaled to the
397 // layer's size. This is in buffer space.
Dan Stoza5a423ea2017-02-16 14:10:39 -0800398 FloatRect crop = getContentCrop().toFloatRect();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700399
400 // In addition there is a WM-specified crop we pull from our drawing state.
401 const State& s(getDrawingState());
402
403 // Screen space to make reduction to parent crop clearer.
404 Rect activeCrop = computeInitialCrop(hw);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700405 Transform t = getTransform();
406 // Back to layer space to work with the content crop.
407 activeCrop = t.inverse().transform(activeCrop);
Mathias Agopian13127d82013-03-05 17:47:11 -0800408
Michael Lentine28ea2172014-11-19 18:32:37 -0800409 // This needs to be here as transform.transform(Rect) computes the
410 // transformed rect and then takes the bounding box of the result before
411 // returning. This means
412 // transform.inverse().transform(transform.transform(Rect)) != Rect
413 // in which case we need to make sure the final rect is clipped to the
414 // display bounds.
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000415 if (!activeCrop.intersect(Rect(s.active.w, s.active.h), &activeCrop)) {
416 activeCrop.clear();
417 }
Mathias Agopian13127d82013-03-05 17:47:11 -0800418
Mathias Agopianf3e85d42013-05-10 18:01:12 -0700419 // subtract the transparent region and snap to the bounds
420 activeCrop = reduce(activeCrop, s.activeTransparentRegion);
421
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000422 // Transform the window crop to match the buffer coordinate system,
423 // which means using the inverse of the current transform set on the
424 // SurfaceFlingerConsumer.
425 uint32_t invTransform = mCurrentTransform;
Robert Carrcae605c2017-03-29 12:10:31 -0700426 if (getTransformToDisplayInverse()) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000427 /*
Pablo Ceballos021623b2016-04-15 17:31:51 -0700428 * the code below applies the primary display's inverse transform to the
429 * buffer
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000430 */
David Sodman41fdfc92017-11-06 16:09:56 -0800431 uint32_t invTransformOrient = DisplayDevice::getPrimaryDisplayOrientationTransform();
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000432 // calculate the inverse transform
433 if (invTransformOrient & NATIVE_WINDOW_TRANSFORM_ROT_90) {
David Sodman41fdfc92017-11-06 16:09:56 -0800434 invTransformOrient ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H;
Mathias Agopian13127d82013-03-05 17:47:11 -0800435 }
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000436 // and apply to the current transform
David Sodman41fdfc92017-11-06 16:09:56 -0800437 invTransform = (Transform(invTransformOrient) * Transform(invTransform)).getOrientation();
Mathias Agopian13127d82013-03-05 17:47:11 -0800438 }
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000439
440 int winWidth = s.active.w;
441 int winHeight = s.active.h;
442 if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
443 // If the activeCrop has been rotate the ends are rotated but not
444 // the space itself so when transforming ends back we can't rely on
445 // a modification of the axes of rotation. To account for this we
446 // need to reorient the inverse rotation in terms of the current
447 // axes of rotation.
448 bool is_h_flipped = (invTransform & NATIVE_WINDOW_TRANSFORM_FLIP_H) != 0;
449 bool is_v_flipped = (invTransform & NATIVE_WINDOW_TRANSFORM_FLIP_V) != 0;
450 if (is_h_flipped == is_v_flipped) {
David Sodman41fdfc92017-11-06 16:09:56 -0800451 invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H;
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000452 }
453 winWidth = s.active.h;
454 winHeight = s.active.w;
455 }
David Sodman41fdfc92017-11-06 16:09:56 -0800456 const Rect winCrop = activeCrop.transform(invTransform, s.active.w, s.active.h);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000457
458 // below, crop is intersected with winCrop expressed in crop's coordinate space
David Sodman41fdfc92017-11-06 16:09:56 -0800459 float xScale = crop.getWidth() / float(winWidth);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000460 float yScale = crop.getHeight() / float(winHeight);
461
David Sodman41fdfc92017-11-06 16:09:56 -0800462 float insetL = winCrop.left * xScale;
463 float insetT = winCrop.top * yScale;
464 float insetR = (winWidth - winCrop.right) * xScale;
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000465 float insetB = (winHeight - winCrop.bottom) * yScale;
466
David Sodman41fdfc92017-11-06 16:09:56 -0800467 crop.left += insetL;
468 crop.top += insetT;
469 crop.right -= insetR;
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000470 crop.bottom -= insetB;
471
Mathias Agopian13127d82013-03-05 17:47:11 -0800472 return crop;
473}
474
Robert Carrae060832016-11-28 10:51:00 -0800475void Layer::setGeometry(const sp<const DisplayDevice>& displayDevice, uint32_t z)
Mathias Agopiana350ff92010-08-10 17:14:02 -0700476{
Dan Stoza9e56aa02015-11-02 13:00:03 -0800477 const auto hwcId = displayDevice->getHwcDisplayId();
David Sodman6f65f3e2017-11-03 14:28:09 -0700478 auto& hwcInfo = getBE().mHwcLayers[hwcId];
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700479
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700480 // enable this layer
Dan Stoza9e56aa02015-11-02 13:00:03 -0800481 hwcInfo.forceClientComposition = false;
482
483 if (isSecure() && !displayDevice->isSecure()) {
484 hwcInfo.forceClientComposition = true;
485 }
486
487 auto& hwcLayer = hwcInfo.layer;
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700488
Mathias Agopian13127d82013-03-05 17:47:11 -0800489 // this gives us only the "orientation" component of the transform
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700490 const State& s(getDrawingState());
David Revemanecf0fa52017-03-03 11:32:44 -0500491 auto blendMode = HWC2::BlendMode::None;
Robert Carr6452f122017-03-21 10:41:29 -0700492 if (!isOpaque(s) || getAlpha() != 1.0f) {
David Sodman41fdfc92017-11-06 16:09:56 -0800493 blendMode =
494 mPremultipliedAlpha ? HWC2::BlendMode::Premultiplied : HWC2::BlendMode::Coverage;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800495 }
David Revemanecf0fa52017-03-03 11:32:44 -0500496 auto error = hwcLayer->setBlendMode(blendMode);
David Sodman41fdfc92017-11-06 16:09:56 -0800497 ALOGE_IF(error != HWC2::Error::None,
498 "[%s] Failed to set blend mode %s:"
499 " %s (%d)",
500 mName.string(), to_string(blendMode).c_str(), to_string(error).c_str(),
501 static_cast<int32_t>(error));
Mathias Agopian13127d82013-03-05 17:47:11 -0800502
503 // apply the layer's transform, followed by the display's global transform
504 // here we're guaranteed that the layer's transform preserves rects
Michael Lentine6c925ed2014-09-26 17:55:01 -0700505 Region activeTransparentRegion(s.activeTransparentRegion);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700506 Transform t = getTransform();
Robert Carrb5d3d262016-03-25 15:08:13 -0700507 if (!s.crop.isEmpty()) {
508 Rect activeCrop(s.crop);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700509 activeCrop = t.transform(activeCrop);
David Sodman41fdfc92017-11-06 16:09:56 -0800510 if (!activeCrop.intersect(displayDevice->getViewport(), &activeCrop)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000511 activeCrop.clear();
512 }
Robert Carr1f0a16a2016-10-24 16:27:39 -0700513 activeCrop = t.inverse().transform(activeCrop, true);
Michael Lentine28ea2172014-11-19 18:32:37 -0800514 // This needs to be here as transform.transform(Rect) computes the
515 // transformed rect and then takes the bounding box of the result before
516 // returning. This means
517 // transform.inverse().transform(transform.transform(Rect)) != Rect
518 // in which case we need to make sure the final rect is clipped to the
519 // display bounds.
David Sodman41fdfc92017-11-06 16:09:56 -0800520 if (!activeCrop.intersect(Rect(s.active.w, s.active.h), &activeCrop)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000521 activeCrop.clear();
522 }
Michael Lentine6c925ed2014-09-26 17:55:01 -0700523 // mark regions outside the crop as transparent
524 activeTransparentRegion.orSelf(Rect(0, 0, s.active.w, activeCrop.top));
David Sodman41fdfc92017-11-06 16:09:56 -0800525 activeTransparentRegion.orSelf(Rect(0, activeCrop.bottom, s.active.w, s.active.h));
526 activeTransparentRegion.orSelf(Rect(0, activeCrop.top, activeCrop.left, activeCrop.bottom));
527 activeTransparentRegion.orSelf(
528 Rect(activeCrop.right, activeCrop.top, s.active.w, activeCrop.bottom));
Michael Lentine6c925ed2014-09-26 17:55:01 -0700529 }
Robert Carr1f0a16a2016-10-24 16:27:39 -0700530
531 Rect frame(t.transform(computeBounds(activeTransparentRegion)));
Robert Carrb5d3d262016-03-25 15:08:13 -0700532 if (!s.finalCrop.isEmpty()) {
David Sodman41fdfc92017-11-06 16:09:56 -0800533 if (!frame.intersect(s.finalCrop, &frame)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000534 frame.clear();
535 }
536 }
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000537 if (!frame.intersect(displayDevice->getViewport(), &frame)) {
538 frame.clear();
539 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800540 const Transform& tr(displayDevice->getTransform());
541 Rect transformedFrame = tr.transform(frame);
David Revemanecf0fa52017-03-03 11:32:44 -0500542 error = hwcLayer->setDisplayFrame(transformedFrame);
Dan Stozae22aec72016-08-01 13:20:59 -0700543 if (error != HWC2::Error::None) {
David Sodman41fdfc92017-11-06 16:09:56 -0800544 ALOGE("[%s] Failed to set display frame [%d, %d, %d, %d]: %s (%d)", mName.string(),
545 transformedFrame.left, transformedFrame.top, transformedFrame.right,
546 transformedFrame.bottom, to_string(error).c_str(), static_cast<int32_t>(error));
Dan Stozae22aec72016-08-01 13:20:59 -0700547 } else {
548 hwcInfo.displayFrame = transformedFrame;
549 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800550
Dan Stoza5a423ea2017-02-16 14:10:39 -0800551 FloatRect sourceCrop = computeCrop(displayDevice);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800552 error = hwcLayer->setSourceCrop(sourceCrop);
Dan Stozae22aec72016-08-01 13:20:59 -0700553 if (error != HWC2::Error::None) {
554 ALOGE("[%s] Failed to set source crop [%.3f, %.3f, %.3f, %.3f]: "
David Sodman41fdfc92017-11-06 16:09:56 -0800555 "%s (%d)",
556 mName.string(), sourceCrop.left, sourceCrop.top, sourceCrop.right, sourceCrop.bottom,
557 to_string(error).c_str(), static_cast<int32_t>(error));
Dan Stozae22aec72016-08-01 13:20:59 -0700558 } else {
559 hwcInfo.sourceCrop = sourceCrop;
560 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800561
chaviw13fdc492017-06-27 12:40:18 -0700562 float alpha = static_cast<float>(getAlpha());
Robert Carr6452f122017-03-21 10:41:29 -0700563 error = hwcLayer->setPlaneAlpha(alpha);
David Sodman41fdfc92017-11-06 16:09:56 -0800564 ALOGE_IF(error != HWC2::Error::None,
565 "[%s] Failed to set plane alpha %.3f: "
566 "%s (%d)",
567 mName.string(), alpha, to_string(error).c_str(), static_cast<int32_t>(error));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800568
Robert Carrae060832016-11-28 10:51:00 -0800569 error = hwcLayer->setZOrder(z);
David Sodman41fdfc92017-11-06 16:09:56 -0800570 ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set Z %u: %s (%d)", mName.string(), z,
571 to_string(error).c_str(), static_cast<int32_t>(error));
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -0500572
Albert Chaulk2a589632017-05-04 16:59:44 -0400573 int type = s.type;
574 int appId = s.appId;
Chia-I Wue41dbe62017-06-13 14:10:56 -0700575 sp<Layer> parent = mDrawingParent.promote();
Albert Chaulk2a589632017-05-04 16:59:44 -0400576 if (parent.get()) {
577 auto& parentState = parent->getDrawingState();
578 type = parentState.type;
579 appId = parentState.appId;
580 }
581
582 error = hwcLayer->setInfo(type, appId);
David Sodman41fdfc92017-11-06 16:09:56 -0800583 ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set info (%d)", mName.string(),
584 static_cast<int32_t>(error));
Mathias Agopian9f8386e2013-01-29 18:56:42 -0800585
Mathias Agopian29a367b2011-07-12 14:51:45 -0700586 /*
587 * Transformations are applied in this order:
588 * 1) buffer orientation/flip/mirror
589 * 2) state transformation (window manager)
590 * 3) layer orientation (screen orientation)
591 * (NOTE: the matrices are multiplied in reverse order)
592 */
593
594 const Transform bufferOrientation(mCurrentTransform);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700595 Transform transform(tr * t * bufferOrientation);
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700596
Robert Carrcae605c2017-03-29 12:10:31 -0700597 if (getTransformToDisplayInverse()) {
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700598 /*
Pablo Ceballos021623b2016-04-15 17:31:51 -0700599 * the code below applies the primary display's inverse transform to the
600 * buffer
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700601 */
David Sodman41fdfc92017-11-06 16:09:56 -0800602 uint32_t invTransform = DisplayDevice::getPrimaryDisplayOrientationTransform();
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700603 // calculate the inverse transform
604 if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
David Sodman41fdfc92017-11-06 16:09:56 -0800605 invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700606 }
Robert Carrcae605c2017-03-29 12:10:31 -0700607
608 /*
609 * Here we cancel out the orientation component of the WM transform.
610 * The scaling and translate components are already included in our bounds
611 * computation so it's enough to just omit it in the composition.
612 * See comment in onDraw with ref to b/36727915 for why.
613 */
614 transform = Transform(invTransform) * tr * bufferOrientation;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700615 }
Mathias Agopian29a367b2011-07-12 14:51:45 -0700616
617 // this gives us only the "orientation" component of the transform
Mathias Agopian13127d82013-03-05 17:47:11 -0800618 const uint32_t orientation = transform.getOrientation();
Dan Stoza9e56aa02015-11-02 13:00:03 -0800619 if (orientation & Transform::ROT_INVALID) {
620 // we can only handle simple transformation
621 hwcInfo.forceClientComposition = true;
622 } else {
623 auto transform = static_cast<HWC2::Transform>(orientation);
624 auto error = hwcLayer->setTransform(transform);
David Sodman41fdfc92017-11-06 16:09:56 -0800625 ALOGE_IF(error != HWC2::Error::None,
626 "[%s] Failed to set transform %s: "
627 "%s (%d)",
628 mName.string(), to_string(transform).c_str(), to_string(error).c_str(),
629 static_cast<int32_t>(error));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800630 }
Mathias Agopiana350ff92010-08-10 17:14:02 -0700631}
632
Dan Stoza9e56aa02015-11-02 13:00:03 -0800633void Layer::forceClientComposition(int32_t hwcId) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700634 if (getBE().mHwcLayers.count(hwcId) == 0) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800635 ALOGE("forceClientComposition: no HWC layer found (%d)", hwcId);
636 return;
637 }
638
David Sodman6f65f3e2017-11-03 14:28:09 -0700639 getBE().mHwcLayers[hwcId].forceClientComposition = true;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800640}
Dan Stozaee44edd2015-03-23 15:50:23 -0700641
chaviwc9232ed2017-11-14 15:31:15 -0800642bool Layer::getForceClientComposition(int32_t hwcId) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700643 if (getBE().mHwcLayers.count(hwcId) == 0) {
chaviwc9232ed2017-11-14 15:31:15 -0800644 ALOGE("getForceClientComposition: no HWC layer found (%d)", hwcId);
645 return false;
646 }
647
David Sodman6f65f3e2017-11-03 14:28:09 -0700648 return getBE().mHwcLayers[hwcId].forceClientComposition;
chaviwc9232ed2017-11-14 15:31:15 -0800649}
650
Dan Stoza9e56aa02015-11-02 13:00:03 -0800651void Layer::updateCursorPosition(const sp<const DisplayDevice>& displayDevice) {
652 auto hwcId = displayDevice->getHwcDisplayId();
David Sodman6f65f3e2017-11-03 14:28:09 -0700653 if (getBE().mHwcLayers.count(hwcId) == 0 ||
David Sodman9eeae692017-11-02 10:53:32 -0700654 getCompositionType(hwcId) != HWC2::Composition::Cursor) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800655 return;
656 }
657
658 // This gives us only the "orientation" component of the transform
659 const State& s(getCurrentState());
660
661 // Apply the layer's transform, followed by the display's global transform
662 // Here we're guaranteed that the layer's transform preserves rects
663 Rect win(s.active.w, s.active.h);
Robert Carrb5d3d262016-03-25 15:08:13 -0700664 if (!s.crop.isEmpty()) {
665 win.intersect(s.crop, &win);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800666 }
667 // Subtract the transparent region and snap to the bounds
668 Rect bounds = reduce(win, s.activeTransparentRegion);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700669 Rect frame(getTransform().transform(bounds));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800670 frame.intersect(displayDevice->getViewport(), &frame);
Robert Carrb5d3d262016-03-25 15:08:13 -0700671 if (!s.finalCrop.isEmpty()) {
672 frame.intersect(s.finalCrop, &frame);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000673 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800674 auto& displayTransform(displayDevice->getTransform());
675 auto position = displayTransform.transform(frame);
676
David Sodman6f65f3e2017-11-03 14:28:09 -0700677 auto error = getBE().mHwcLayers[hwcId].layer->setCursorPosition(position.left,
David Sodman9eeae692017-11-02 10:53:32 -0700678 position.top);
David Sodman41fdfc92017-11-06 16:09:56 -0800679 ALOGE_IF(error != HWC2::Error::None,
680 "[%s] Failed to set cursor position "
681 "to (%d, %d): %s (%d)",
682 mName.string(), position.left, position.top, to_string(error).c_str(),
683 static_cast<int32_t>(error));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800684}
Riley Andrews03414a12014-07-01 14:22:59 -0700685
Mathias Agopian13127d82013-03-05 17:47:11 -0800686// ---------------------------------------------------------------------------
687// drawing...
688// ---------------------------------------------------------------------------
689
chaviwa76b2712017-09-20 12:02:26 -0700690void Layer::draw(const RenderArea& renderArea, const Region& clip) const {
691 onDraw(renderArea, clip, false);
Mathias Agopian13127d82013-03-05 17:47:11 -0800692}
693
chaviwa76b2712017-09-20 12:02:26 -0700694void Layer::draw(const RenderArea& renderArea, bool useIdentityTransform) const {
695 onDraw(renderArea, Region(renderArea.getBounds()), useIdentityTransform);
Mathias Agopian13127d82013-03-05 17:47:11 -0800696}
697
chaviwa76b2712017-09-20 12:02:26 -0700698void Layer::draw(const RenderArea& renderArea) const {
699 onDraw(renderArea, Region(renderArea.getBounds()), false);
Dan Stozac7014012014-02-14 15:03:43 -0800700}
701
David Sodman41fdfc92017-11-06 16:09:56 -0800702void Layer::clearWithOpenGL(const RenderArea& renderArea, float red, float green, float blue,
703 float alpha) const {
Mathias Agopian19733a32013-08-28 18:13:56 -0700704 RenderEngine& engine(mFlinger->getRenderEngine());
David Sodman9eeae692017-11-02 10:53:32 -0700705 computeGeometry(renderArea, getBE().mMesh, false);
Mathias Agopian19733a32013-08-28 18:13:56 -0700706 engine.setupFillWithColor(red, green, blue, alpha);
David Sodman9eeae692017-11-02 10:53:32 -0700707 engine.drawMesh(getBE().mMesh);
Mathias Agopian13127d82013-03-05 17:47:11 -0800708}
709
chaviwa76b2712017-09-20 12:02:26 -0700710void Layer::clearWithOpenGL(const RenderArea& renderArea) const {
David Sodman41fdfc92017-11-06 16:09:56 -0800711 clearWithOpenGL(renderArea, 0, 0, 0, 0);
Mathias Agopian13127d82013-03-05 17:47:11 -0800712}
713
David Sodman41fdfc92017-11-06 16:09:56 -0800714void Layer::setCompositionType(int32_t hwcId, HWC2::Composition type, bool callIntoHwc) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700715 if (getBE().mHwcLayers.count(hwcId) == 0) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800716 ALOGE("setCompositionType called without a valid HWC layer");
717 return;
718 }
David Sodman6f65f3e2017-11-03 14:28:09 -0700719 auto& hwcInfo = getBE().mHwcLayers[hwcId];
Dan Stoza9e56aa02015-11-02 13:00:03 -0800720 auto& hwcLayer = hwcInfo.layer;
David Sodman41fdfc92017-11-06 16:09:56 -0800721 ALOGV("setCompositionType(%" PRIx64 ", %s, %d)", hwcLayer->getId(), to_string(type).c_str(),
722 static_cast<int>(callIntoHwc));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800723 if (hwcInfo.compositionType != type) {
724 ALOGV(" actually setting");
725 hwcInfo.compositionType = type;
726 if (callIntoHwc) {
727 auto error = hwcLayer->setCompositionType(type);
David Sodman41fdfc92017-11-06 16:09:56 -0800728 ALOGE_IF(error != HWC2::Error::None,
729 "[%s] Failed to set "
730 "composition type %s: %s (%d)",
731 mName.string(), to_string(type).c_str(), to_string(error).c_str(),
732 static_cast<int32_t>(error));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800733 }
734 }
735}
736
737HWC2::Composition Layer::getCompositionType(int32_t hwcId) const {
Dan Stozaec0f7172016-07-21 11:09:40 -0700738 if (hwcId == DisplayDevice::DISPLAY_ID_INVALID) {
739 // If we're querying the composition type for a display that does not
740 // have a HWC counterpart, then it will always be Client
741 return HWC2::Composition::Client;
742 }
David Sodman6f65f3e2017-11-03 14:28:09 -0700743 if (getBE().mHwcLayers.count(hwcId) == 0) {
Dan Stozaec0f7172016-07-21 11:09:40 -0700744 ALOGE("getCompositionType called with an invalid HWC layer");
Dan Stoza9e56aa02015-11-02 13:00:03 -0800745 return HWC2::Composition::Invalid;
746 }
David Sodman6f65f3e2017-11-03 14:28:09 -0700747 return getBE().mHwcLayers.at(hwcId).compositionType;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800748}
749
750void Layer::setClearClientTarget(int32_t hwcId, bool clear) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700751 if (getBE().mHwcLayers.count(hwcId) == 0) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800752 ALOGE("setClearClientTarget called without a valid HWC layer");
753 return;
754 }
David Sodman6f65f3e2017-11-03 14:28:09 -0700755 getBE().mHwcLayers[hwcId].clearClientTarget = clear;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800756}
757
758bool Layer::getClearClientTarget(int32_t hwcId) const {
David Sodman6f65f3e2017-11-03 14:28:09 -0700759 if (getBE().mHwcLayers.count(hwcId) == 0) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800760 ALOGE("getClearClientTarget called without a valid HWC layer");
761 return false;
762 }
David Sodman6f65f3e2017-11-03 14:28:09 -0700763 return getBE().mHwcLayers.at(hwcId).clearClientTarget;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800764}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800765
Dan Stozacac35382016-01-27 12:21:06 -0800766bool Layer::addSyncPoint(const std::shared_ptr<SyncPoint>& point) {
767 if (point->getFrameNumber() <= mCurrentFrameNumber) {
768 // Don't bother with a SyncPoint, since we've already latched the
769 // relevant frame
770 return false;
Dan Stoza7dde5992015-05-22 09:51:44 -0700771 }
772
Dan Stozacac35382016-01-27 12:21:06 -0800773 Mutex::Autolock lock(mLocalSyncPointMutex);
774 mLocalSyncPoints.push_back(point);
775 return true;
Dan Stoza7dde5992015-05-22 09:51:44 -0700776}
777
Mathias Agopian13127d82013-03-05 17:47:11 -0800778void Layer::setFiltering(bool filtering) {
779 mFiltering = filtering;
780}
781
782bool Layer::getFiltering() const {
783 return mFiltering;
784}
785
Mathias Agopian13127d82013-03-05 17:47:11 -0800786// ----------------------------------------------------------------------------
787// local state
788// ----------------------------------------------------------------------------
789
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000790static void boundPoint(vec2* point, const Rect& crop) {
791 if (point->x < crop.left) {
792 point->x = crop.left;
793 }
794 if (point->x > crop.right) {
795 point->x = crop.right;
796 }
797 if (point->y < crop.top) {
798 point->y = crop.top;
799 }
800 if (point->y > crop.bottom) {
801 point->y = crop.bottom;
802 }
803}
804
chaviwa76b2712017-09-20 12:02:26 -0700805void Layer::computeGeometry(const RenderArea& renderArea, Mesh& mesh,
806 bool useIdentityTransform) const {
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700807 const Layer::State& s(getDrawingState());
chaviwa76b2712017-09-20 12:02:26 -0700808 const Transform renderAreaTransform(renderArea.getTransform());
809 const uint32_t height = renderArea.getHeight();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700810 Rect win = computeBounds();
Mathias Agopian3f844832013-08-07 21:24:32 -0700811
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000812 vec2 lt = vec2(win.left, win.top);
813 vec2 lb = vec2(win.left, win.bottom);
814 vec2 rb = vec2(win.right, win.bottom);
815 vec2 rt = vec2(win.right, win.top);
816
Robert Carr1f0a16a2016-10-24 16:27:39 -0700817 Transform layerTransform = getTransform();
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000818 if (!useIdentityTransform) {
Robert Carr1f0a16a2016-10-24 16:27:39 -0700819 lt = layerTransform.transform(lt);
820 lb = layerTransform.transform(lb);
821 rb = layerTransform.transform(rb);
822 rt = layerTransform.transform(rt);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000823 }
824
Robert Carrb5d3d262016-03-25 15:08:13 -0700825 if (!s.finalCrop.isEmpty()) {
826 boundPoint(&lt, s.finalCrop);
827 boundPoint(&lb, s.finalCrop);
828 boundPoint(&rb, s.finalCrop);
829 boundPoint(&rt, s.finalCrop);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000830 }
831
Mathias Agopianff2ed702013-09-01 21:36:12 -0700832 Mesh::VertexArray<vec2> position(mesh.getPositionArray<vec2>());
chaviwa76b2712017-09-20 12:02:26 -0700833 position[0] = renderAreaTransform.transform(lt);
834 position[1] = renderAreaTransform.transform(lb);
835 position[2] = renderAreaTransform.transform(rb);
836 position[3] = renderAreaTransform.transform(rt);
David Sodman41fdfc92017-11-06 16:09:56 -0800837 for (size_t i = 0; i < 4; i++) {
chaviwa76b2712017-09-20 12:02:26 -0700838 position[i].y = height - position[i].y;
Mathias Agopian13127d82013-03-05 17:47:11 -0800839 }
840}
Eric Hassoldac45e6b2011-02-10 14:41:26 -0800841
David Sodman41fdfc92017-11-06 16:09:56 -0800842bool Layer::isSecure() const {
Dan Stoza23116082015-06-18 14:58:39 -0700843 const Layer::State& s(mDrawingState);
844 return (s.flags & layer_state_t::eLayerSecure);
845}
846
Mathias Agopian13127d82013-03-05 17:47:11 -0800847void Layer::setVisibleRegion(const Region& visibleRegion) {
848 // always called from main thread
849 this->visibleRegion = visibleRegion;
850}
851
852void Layer::setCoveredRegion(const Region& coveredRegion) {
853 // always called from main thread
854 this->coveredRegion = coveredRegion;
855}
856
David Sodman41fdfc92017-11-06 16:09:56 -0800857void Layer::setVisibleNonTransparentRegion(const Region& setVisibleNonTransparentRegion) {
Mathias Agopian13127d82013-03-05 17:47:11 -0800858 // always called from main thread
859 this->visibleNonTransparentRegion = setVisibleNonTransparentRegion;
860}
861
862// ----------------------------------------------------------------------------
863// transaction
864// ----------------------------------------------------------------------------
865
Dan Stoza7dde5992015-05-22 09:51:44 -0700866void Layer::pushPendingState() {
867 if (!mCurrentState.modified) {
868 return;
869 }
870
Dan Stoza7dde5992015-05-22 09:51:44 -0700871 // If this transaction is waiting on the receipt of a frame, generate a sync
872 // point and send it to the remote layer.
Robert Carr0d480722017-01-10 16:42:54 -0800873 if (mCurrentState.barrierLayer != nullptr) {
874 sp<Layer> barrierLayer = mCurrentState.barrierLayer.promote();
875 if (barrierLayer == nullptr) {
876 ALOGE("[%s] Unable to promote barrier Layer.", mName.string());
Dan Stoza7dde5992015-05-22 09:51:44 -0700877 // If we can't promote the layer we are intended to wait on,
878 // then it is expired or otherwise invalid. Allow this transaction
879 // to be applied as per normal (no synchronization).
Robert Carr0d480722017-01-10 16:42:54 -0800880 mCurrentState.barrierLayer = nullptr;
Pablo Ceballos3bddd5b2015-11-19 14:39:14 -0800881 } else {
David Sodman41fdfc92017-11-06 16:09:56 -0800882 auto syncPoint = std::make_shared<SyncPoint>(mCurrentState.frameNumber);
Robert Carr0d480722017-01-10 16:42:54 -0800883 if (barrierLayer->addSyncPoint(syncPoint)) {
Dan Stozacac35382016-01-27 12:21:06 -0800884 mRemoteSyncPoints.push_back(std::move(syncPoint));
885 } else {
886 // We already missed the frame we're supposed to synchronize
887 // on, so go ahead and apply the state update
Robert Carr0d480722017-01-10 16:42:54 -0800888 mCurrentState.barrierLayer = nullptr;
Dan Stozacac35382016-01-27 12:21:06 -0800889 }
Dan Stoza7dde5992015-05-22 09:51:44 -0700890 }
891
Dan Stoza7dde5992015-05-22 09:51:44 -0700892 // Wake us up to check if the frame has been received
893 setTransactionFlags(eTransactionNeeded);
Dan Stozaf5702ff2016-11-02 16:27:47 -0700894 mFlinger->setTransactionFlags(eTraversalNeeded);
Dan Stoza7dde5992015-05-22 09:51:44 -0700895 }
896 mPendingStates.push_back(mCurrentState);
Dan Stozaf7ba41a2017-05-10 15:11:11 -0700897 ATRACE_INT(mTransactionName.string(), mPendingStates.size());
Dan Stoza7dde5992015-05-22 09:51:44 -0700898}
899
Pablo Ceballos05289c22016-04-14 15:49:55 -0700900void Layer::popPendingState(State* stateToCommit) {
901 auto oldFlags = stateToCommit->flags;
902 *stateToCommit = mPendingStates[0];
David Sodman41fdfc92017-11-06 16:09:56 -0800903 stateToCommit->flags =
904 (oldFlags & ~stateToCommit->mask) | (stateToCommit->flags & stateToCommit->mask);
Dan Stoza7dde5992015-05-22 09:51:44 -0700905
906 mPendingStates.removeAt(0);
Dan Stozaf7ba41a2017-05-10 15:11:11 -0700907 ATRACE_INT(mTransactionName.string(), mPendingStates.size());
Dan Stoza7dde5992015-05-22 09:51:44 -0700908}
909
Pablo Ceballos05289c22016-04-14 15:49:55 -0700910bool Layer::applyPendingStates(State* stateToCommit) {
Dan Stoza7dde5992015-05-22 09:51:44 -0700911 bool stateUpdateAvailable = false;
912 while (!mPendingStates.empty()) {
Robert Carr0d480722017-01-10 16:42:54 -0800913 if (mPendingStates[0].barrierLayer != nullptr) {
Dan Stoza7dde5992015-05-22 09:51:44 -0700914 if (mRemoteSyncPoints.empty()) {
915 // If we don't have a sync point for this, apply it anyway. It
916 // will be visually wrong, but it should keep us from getting
917 // into too much trouble.
918 ALOGE("[%s] No local sync point found", mName.string());
Pablo Ceballos05289c22016-04-14 15:49:55 -0700919 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -0700920 stateUpdateAvailable = true;
921 continue;
922 }
923
David Sodman41fdfc92017-11-06 16:09:56 -0800924 if (mRemoteSyncPoints.front()->getFrameNumber() != mPendingStates[0].frameNumber) {
925 ALOGE("[%s] Unexpected sync point frame number found", mName.string());
Dan Stozacac35382016-01-27 12:21:06 -0800926
927 // Signal our end of the sync point and then dispose of it
928 mRemoteSyncPoints.front()->setTransactionApplied();
929 mRemoteSyncPoints.pop_front();
930 continue;
931 }
932
Dan Stoza7dde5992015-05-22 09:51:44 -0700933 if (mRemoteSyncPoints.front()->frameIsAvailable()) {
934 // Apply the state update
Pablo Ceballos05289c22016-04-14 15:49:55 -0700935 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -0700936 stateUpdateAvailable = true;
937
938 // Signal our end of the sync point and then dispose of it
939 mRemoteSyncPoints.front()->setTransactionApplied();
940 mRemoteSyncPoints.pop_front();
Dan Stoza792e5292016-02-11 11:43:58 -0800941 } else {
942 break;
Dan Stoza7dde5992015-05-22 09:51:44 -0700943 }
Dan Stoza7dde5992015-05-22 09:51:44 -0700944 } else {
Pablo Ceballos05289c22016-04-14 15:49:55 -0700945 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -0700946 stateUpdateAvailable = true;
947 }
948 }
949
950 // If we still have pending updates, wake SurfaceFlinger back up and point
951 // it at this layer so we can process them
952 if (!mPendingStates.empty()) {
953 setTransactionFlags(eTransactionNeeded);
954 mFlinger->setTransactionFlags(eTraversalNeeded);
955 }
956
957 mCurrentState.modified = false;
958 return stateUpdateAvailable;
959}
960
Mathias Agopian13127d82013-03-05 17:47:11 -0800961uint32_t Layer::doTransaction(uint32_t flags) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800962 ATRACE_CALL();
963
Dan Stoza7dde5992015-05-22 09:51:44 -0700964 pushPendingState();
Pablo Ceballos05289c22016-04-14 15:49:55 -0700965 Layer::State c = getCurrentState();
966 if (!applyPendingStates(&c)) {
Dan Stoza7dde5992015-05-22 09:51:44 -0700967 return 0;
968 }
969
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700970 const Layer::State& s(getDrawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800971
David Sodman41fdfc92017-11-06 16:09:56 -0800972 const bool sizeChanged = (c.requested.w != s.requested.w) || (c.requested.h != s.requested.h);
Mathias Agopiana138f892010-05-21 17:24:35 -0700973
David Sodmaneb085e02017-10-05 18:49:04 -0700974 if (sizeChanged) {
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700975 // the size changed, we need to ask our client to request a new buffer
Steve Block9d453682011-12-20 16:23:08 +0000976 ALOGD_IF(DEBUG_RESIZE,
David Sodman41fdfc92017-11-06 16:09:56 -0800977 "doTransaction: geometry (layer=%p '%s'), tr=%02x, scalingMode=%d\n"
978 " current={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
979 " requested={ wh={%4u,%4u} }}\n"
980 " drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
981 " requested={ wh={%4u,%4u} }}\n",
David Sodman9eeae692017-11-02 10:53:32 -0700982 this, getName().string(), mCurrentTransform,
983 getEffectiveScalingMode(), c.active.w, c.active.h, c.crop.left, c.crop.top,
984 c.crop.right, c.crop.bottom, c.crop.getWidth(), c.crop.getHeight(), c.requested.w,
985 c.requested.h, s.active.w, s.active.h, s.crop.left, s.crop.top, s.crop.right,
986 s.crop.bottom, s.crop.getWidth(), s.crop.getHeight(), s.requested.w,
987 s.requested.h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800988
Jamie Gennis2a0d5b62011-09-26 16:54:44 -0700989 // record the new size, form this point on, when the client request
990 // a buffer, it'll get the new size.
David Sodmaneb085e02017-10-05 18:49:04 -0700991 setDefaultBufferSize(c.requested.w, c.requested.h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800992 }
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700993
Robert Carre392b552017-09-19 12:16:05 -0700994 // Don't let Layer::doTransaction update the drawing state
995 // if we have a pending resize, unless we are in fixed-size mode.
996 // the drawing state will be updated only once we receive a buffer
997 // with the correct size.
998 //
999 // In particular, we want to make sure the clip (which is part
1000 // of the geometry state) is latched together with the size but is
1001 // latched immediately when no resizing is involved.
1002 //
1003 // If a sideband stream is attached, however, we want to skip this
1004 // optimization so that transactions aren't missed when a buffer
1005 // never arrives
1006 //
1007 // In the case that we don't have a buffer we ignore other factors
1008 // and avoid entering the resizePending state. At a high level the
1009 // resizePending state is to avoid applying the state of the new buffer
1010 // to the old buffer. However in the state where we don't have an old buffer
1011 // there is no such concern but we may still be being used as a parent layer.
David Sodman41fdfc92017-11-06 16:09:56 -08001012 const bool resizePending = ((c.requested.w != c.active.w) || (c.requested.h != c.active.h)) &&
David Sodman0cc69182017-11-17 12:12:07 -08001013 (getBE().compositionInfo.mBuffer != nullptr);
Mathias Agopian0cd545f2012-06-07 14:18:55 -07001014 if (!isFixedSize()) {
David Sodman0cc69182017-11-17 12:12:07 -08001015 if (resizePending && getBE().compositionInfo.hwc.sidebandStream == nullptr) {
Mathias Agopian0cd545f2012-06-07 14:18:55 -07001016 flags |= eDontUpdateGeometryState;
1017 }
1018 }
1019
Robert Carr7bf247e2017-05-18 14:02:49 -07001020 // Here we apply various requested geometry states, depending on our
1021 // latching configuration. See Layer.h for a detailed discussion of
1022 // how geometry latching is controlled.
1023 if (!(flags & eDontUpdateGeometryState)) {
Pablo Ceballos7d052572016-06-02 17:46:05 -07001024 Layer::State& editCurrentState(getCurrentState());
Robert Carr7bf247e2017-05-18 14:02:49 -07001025
1026 // If mFreezeGeometryUpdates is true we are in the setGeometryAppliesWithResize
1027 // mode, which causes attributes which normally latch regardless of scaling mode,
1028 // to be delayed. We copy the requested state to the active state making sure
1029 // to respect these rules (again see Layer.h for a detailed discussion).
1030 //
1031 // There is an awkward asymmetry in the handling of the crop states in the position
1032 // states, as can be seen below. Largely this arises from position and transform
1033 // being stored in the same data structure while having different latching rules.
1034 // b/38182305
1035 //
1036 // Careful that "c" and editCurrentState may not begin as equivalent due to
1037 // applyPendingStates in the presence of deferred transactions.
1038 if (mFreezeGeometryUpdates) {
Robert Carr82364e32016-05-15 11:27:47 -07001039 float tx = c.active.transform.tx();
1040 float ty = c.active.transform.ty();
1041 c.active = c.requested;
1042 c.active.transform.set(tx, ty);
1043 editCurrentState.active = c.active;
1044 } else {
1045 editCurrentState.active = editCurrentState.requested;
1046 c.active = c.requested;
1047 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001048 }
1049
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001050 if (s.active != c.active) {
Mathias Agopian13127d82013-03-05 17:47:11 -08001051 // invalidate and recompute the visible regions if needed
1052 flags |= Layer::eVisibleRegion;
1053 }
1054
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001055 if (c.sequence != s.sequence) {
Mathias Agopian13127d82013-03-05 17:47:11 -08001056 // invalidate and recompute the visible regions if needed
1057 flags |= eVisibleRegion;
1058 this->contentDirty = true;
1059
1060 // we may use linear filtering, if the matrix scales us
Robert Carr3dcabfa2016-03-01 18:36:58 -08001061 const uint8_t type = c.active.transform.getType();
David Sodman41fdfc92017-11-06 16:09:56 -08001062 mNeedsFiltering = (!c.active.transform.preserveRects() || (type >= Transform::SCALE));
Mathias Agopian13127d82013-03-05 17:47:11 -08001063 }
1064
Dan Stozac8145172016-04-28 16:29:06 -07001065 // If the layer is hidden, signal and clear out all local sync points so
1066 // that transactions for layers depending on this layer's frames becoming
1067 // visible are not blocked
1068 if (c.flags & layer_state_t::eLayerHidden) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001069 clearSyncPoints();
Dan Stozac8145172016-04-28 16:29:06 -07001070 }
1071
Mathias Agopian13127d82013-03-05 17:47:11 -08001072 // Commit the transaction
Pablo Ceballos05289c22016-04-14 15:49:55 -07001073 commitTransaction(c);
Mathias Agopian13127d82013-03-05 17:47:11 -08001074 return flags;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001075}
1076
Pablo Ceballos05289c22016-04-14 15:49:55 -07001077void Layer::commitTransaction(const State& stateToCommit) {
1078 mDrawingState = stateToCommit;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001079}
1080
Mathias Agopian13127d82013-03-05 17:47:11 -08001081uint32_t Layer::getTransactionFlags(uint32_t flags) {
1082 return android_atomic_and(~flags, &mTransactionFlags) & flags;
1083}
1084
1085uint32_t Layer::setTransactionFlags(uint32_t flags) {
1086 return android_atomic_or(flags, &mTransactionFlags);
1087}
1088
Robert Carr82364e32016-05-15 11:27:47 -07001089bool Layer::setPosition(float x, float y, bool immediate) {
Robert Carr3dcabfa2016-03-01 18:36:58 -08001090 if (mCurrentState.requested.transform.tx() == x && mCurrentState.requested.transform.ty() == y)
Mathias Agopian13127d82013-03-05 17:47:11 -08001091 return false;
1092 mCurrentState.sequence++;
Robert Carr69663fb2016-03-27 19:59:19 -07001093
1094 // We update the requested and active position simultaneously because
1095 // we want to apply the position portion of the transform matrix immediately,
1096 // but still delay scaling when resizing a SCALING_MODE_FREEZE layer.
Robert Carr3dcabfa2016-03-01 18:36:58 -08001097 mCurrentState.requested.transform.set(x, y);
Robert Carr7bf247e2017-05-18 14:02:49 -07001098 if (immediate && !mFreezeGeometryUpdates) {
1099 // Here we directly update the active state
1100 // unlike other setters, because we store it within
1101 // the transform, but use different latching rules.
1102 // b/38182305
Robert Carr82364e32016-05-15 11:27:47 -07001103 mCurrentState.active.transform.set(x, y);
1104 }
Robert Carr7bf247e2017-05-18 14:02:49 -07001105 mFreezeGeometryUpdates = mFreezeGeometryUpdates || !immediate;
Robert Carr69663fb2016-03-27 19:59:19 -07001106
Dan Stoza7dde5992015-05-22 09:51:44 -07001107 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001108 setTransactionFlags(eTransactionNeeded);
1109 return true;
1110}
Robert Carr82364e32016-05-15 11:27:47 -07001111
Robert Carr1f0a16a2016-10-24 16:27:39 -07001112bool Layer::setChildLayer(const sp<Layer>& childLayer, int32_t z) {
1113 ssize_t idx = mCurrentChildren.indexOf(childLayer);
1114 if (idx < 0) {
1115 return false;
1116 }
1117 if (childLayer->setLayer(z)) {
1118 mCurrentChildren.removeAt(idx);
1119 mCurrentChildren.add(childLayer);
1120 }
1121 return true;
1122}
1123
Robert Carr503c7042017-09-27 15:06:08 -07001124bool Layer::setChildRelativeLayer(const sp<Layer>& childLayer,
1125 const sp<IBinder>& relativeToHandle, int32_t relativeZ) {
1126 ssize_t idx = mCurrentChildren.indexOf(childLayer);
1127 if (idx < 0) {
1128 return false;
1129 }
1130 if (childLayer->setRelativeLayer(relativeToHandle, relativeZ)) {
1131 mCurrentChildren.removeAt(idx);
1132 mCurrentChildren.add(childLayer);
1133 }
1134 return true;
1135}
1136
Robert Carrae060832016-11-28 10:51:00 -08001137bool Layer::setLayer(int32_t z) {
David Sodman41fdfc92017-11-06 16:09:56 -08001138 if (mCurrentState.z == z) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001139 mCurrentState.sequence++;
1140 mCurrentState.z = z;
Dan Stoza7dde5992015-05-22 09:51:44 -07001141 mCurrentState.modified = true;
Robert Carrdb66e622017-04-10 16:55:57 -07001142
1143 // Discard all relative layering.
1144 if (mCurrentState.zOrderRelativeOf != nullptr) {
1145 sp<Layer> strongRelative = mCurrentState.zOrderRelativeOf.promote();
1146 if (strongRelative != nullptr) {
1147 strongRelative->removeZOrderRelative(this);
1148 }
1149 mCurrentState.zOrderRelativeOf = nullptr;
1150 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001151 setTransactionFlags(eTransactionNeeded);
1152 return true;
1153}
Robert Carr1f0a16a2016-10-24 16:27:39 -07001154
Robert Carrdb66e622017-04-10 16:55:57 -07001155void Layer::removeZOrderRelative(const wp<Layer>& relative) {
1156 mCurrentState.zOrderRelatives.remove(relative);
1157 mCurrentState.sequence++;
1158 mCurrentState.modified = true;
1159 setTransactionFlags(eTransactionNeeded);
1160}
1161
1162void Layer::addZOrderRelative(const wp<Layer>& relative) {
1163 mCurrentState.zOrderRelatives.add(relative);
1164 mCurrentState.modified = true;
1165 mCurrentState.sequence++;
1166 setTransactionFlags(eTransactionNeeded);
1167}
1168
1169bool Layer::setRelativeLayer(const sp<IBinder>& relativeToHandle, int32_t z) {
1170 sp<Handle> handle = static_cast<Handle*>(relativeToHandle.get());
1171 if (handle == nullptr) {
1172 return false;
1173 }
1174 sp<Layer> relative = handle->owner.promote();
1175 if (relative == nullptr) {
1176 return false;
1177 }
1178
1179 mCurrentState.sequence++;
1180 mCurrentState.modified = true;
1181 mCurrentState.z = z;
1182
chaviw9ab4bd12017-11-03 13:11:00 -07001183 auto oldZOrderRelativeOf = mCurrentState.zOrderRelativeOf.promote();
1184 if (oldZOrderRelativeOf != nullptr) {
1185 oldZOrderRelativeOf->removeZOrderRelative(this);
1186 }
Robert Carrdb66e622017-04-10 16:55:57 -07001187 mCurrentState.zOrderRelativeOf = relative;
1188 relative->addZOrderRelative(this);
1189
1190 setTransactionFlags(eTransactionNeeded);
1191
1192 return true;
1193}
1194
Mathias Agopian13127d82013-03-05 17:47:11 -08001195bool Layer::setSize(uint32_t w, uint32_t h) {
David Sodman41fdfc92017-11-06 16:09:56 -08001196 if (mCurrentState.requested.w == w && mCurrentState.requested.h == h) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001197 mCurrentState.requested.w = w;
1198 mCurrentState.requested.h = h;
Dan Stoza7dde5992015-05-22 09:51:44 -07001199 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001200 setTransactionFlags(eTransactionNeeded);
1201 return true;
1202}
Dan Stoza9e56aa02015-11-02 13:00:03 -08001203bool Layer::setAlpha(float alpha) {
David Sodman41fdfc92017-11-06 16:09:56 -08001204 if (mCurrentState.color.a == alpha) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001205 mCurrentState.sequence++;
chaviw13fdc492017-06-27 12:40:18 -07001206 mCurrentState.color.a = alpha;
Dan Stoza7dde5992015-05-22 09:51:44 -07001207 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001208 setTransactionFlags(eTransactionNeeded);
1209 return true;
1210}
chaviw13fdc492017-06-27 12:40:18 -07001211
1212bool Layer::setColor(const half3& color) {
David Sodman41fdfc92017-11-06 16:09:56 -08001213 if (color.r == mCurrentState.color.r && color.g == mCurrentState.color.g &&
1214 color.b == mCurrentState.color.b)
chaviw13fdc492017-06-27 12:40:18 -07001215 return false;
1216
1217 mCurrentState.sequence++;
1218 mCurrentState.color.r = color.r;
1219 mCurrentState.color.g = color.g;
1220 mCurrentState.color.b = color.b;
1221 mCurrentState.modified = true;
1222 setTransactionFlags(eTransactionNeeded);
1223 return true;
1224}
1225
Mathias Agopian13127d82013-03-05 17:47:11 -08001226bool Layer::setMatrix(const layer_state_t::matrix22_t& matrix) {
1227 mCurrentState.sequence++;
David Sodman41fdfc92017-11-06 16:09:56 -08001228 mCurrentState.requested.transform.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
Dan Stoza7dde5992015-05-22 09:51:44 -07001229 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001230 setTransactionFlags(eTransactionNeeded);
1231 return true;
1232}
1233bool Layer::setTransparentRegionHint(const Region& transparent) {
Mathias Agopian2ca79392013-04-02 18:30:32 -07001234 mCurrentState.requestedTransparentRegion = transparent;
Dan Stoza7dde5992015-05-22 09:51:44 -07001235 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001236 setTransactionFlags(eTransactionNeeded);
1237 return true;
1238}
1239bool Layer::setFlags(uint8_t flags, uint8_t mask) {
1240 const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask);
David Sodman41fdfc92017-11-06 16:09:56 -08001241 if (mCurrentState.flags == newFlags) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001242 mCurrentState.sequence++;
1243 mCurrentState.flags = newFlags;
Dan Stoza7dde5992015-05-22 09:51:44 -07001244 mCurrentState.mask = mask;
1245 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001246 setTransactionFlags(eTransactionNeeded);
1247 return true;
1248}
Robert Carr99e27f02016-06-16 15:18:02 -07001249
1250bool Layer::setCrop(const Rect& crop, bool immediate) {
David Sodman41fdfc92017-11-06 16:09:56 -08001251 if (mCurrentState.requestedCrop == crop) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001252 mCurrentState.sequence++;
Robert Carr99e27f02016-06-16 15:18:02 -07001253 mCurrentState.requestedCrop = crop;
Robert Carr7bf247e2017-05-18 14:02:49 -07001254 if (immediate && !mFreezeGeometryUpdates) {
Robert Carr99e27f02016-06-16 15:18:02 -07001255 mCurrentState.crop = crop;
1256 }
Robert Carr7bf247e2017-05-18 14:02:49 -07001257 mFreezeGeometryUpdates = mFreezeGeometryUpdates || !immediate;
1258
Dan Stoza7dde5992015-05-22 09:51:44 -07001259 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001260 setTransactionFlags(eTransactionNeeded);
1261 return true;
1262}
Robert Carr8d5227b2017-03-16 15:41:03 -07001263
1264bool Layer::setFinalCrop(const Rect& crop, bool immediate) {
David Sodman41fdfc92017-11-06 16:09:56 -08001265 if (mCurrentState.requestedFinalCrop == crop) return false;
Pablo Ceballosacbe6782016-03-04 17:54:21 +00001266 mCurrentState.sequence++;
Robert Carr8d5227b2017-03-16 15:41:03 -07001267 mCurrentState.requestedFinalCrop = crop;
Robert Carr7bf247e2017-05-18 14:02:49 -07001268 if (immediate && !mFreezeGeometryUpdates) {
Robert Carr8d5227b2017-03-16 15:41:03 -07001269 mCurrentState.finalCrop = crop;
1270 }
Robert Carr7bf247e2017-05-18 14:02:49 -07001271 mFreezeGeometryUpdates = mFreezeGeometryUpdates || !immediate;
1272
Pablo Ceballosacbe6782016-03-04 17:54:21 +00001273 mCurrentState.modified = true;
1274 setTransactionFlags(eTransactionNeeded);
1275 return true;
1276}
Mathias Agopian13127d82013-03-05 17:47:11 -08001277
Robert Carrc3574f72016-03-24 12:19:32 -07001278bool Layer::setOverrideScalingMode(int32_t scalingMode) {
David Sodman41fdfc92017-11-06 16:09:56 -08001279 if (scalingMode == mOverrideScalingMode) return false;
Robert Carrc3574f72016-03-24 12:19:32 -07001280 mOverrideScalingMode = scalingMode;
Robert Carr82364e32016-05-15 11:27:47 -07001281 setTransactionFlags(eTransactionNeeded);
Robert Carrc3574f72016-03-24 12:19:32 -07001282 return true;
1283}
1284
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -05001285void Layer::setInfo(uint32_t type, uint32_t appId) {
David Sodman41fdfc92017-11-06 16:09:56 -08001286 mCurrentState.appId = appId;
1287 mCurrentState.type = type;
1288 mCurrentState.modified = true;
1289 setTransactionFlags(eTransactionNeeded);
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -05001290}
1291
Mathias Agopian13127d82013-03-05 17:47:11 -08001292bool Layer::setLayerStack(uint32_t layerStack) {
David Sodman41fdfc92017-11-06 16:09:56 -08001293 if (mCurrentState.layerStack == layerStack) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001294 mCurrentState.sequence++;
1295 mCurrentState.layerStack = layerStack;
Dan Stoza7dde5992015-05-22 09:51:44 -07001296 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001297 setTransactionFlags(eTransactionNeeded);
1298 return true;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001299}
1300
Courtney Goeltzenleuchterbb09b432016-11-30 13:51:28 -07001301bool Layer::setDataSpace(android_dataspace dataSpace) {
David Sodman41fdfc92017-11-06 16:09:56 -08001302 if (mCurrentState.dataSpace == dataSpace) return false;
Courtney Goeltzenleuchterbb09b432016-11-30 13:51:28 -07001303 mCurrentState.sequence++;
1304 mCurrentState.dataSpace = dataSpace;
1305 mCurrentState.modified = true;
1306 setTransactionFlags(eTransactionNeeded);
1307 return true;
1308}
1309
Courtney Goeltzenleuchter532b2632017-05-05 16:34:38 -06001310android_dataspace Layer::getDataSpace() const {
1311 return mCurrentState.dataSpace;
1312}
1313
Robert Carr1f0a16a2016-10-24 16:27:39 -07001314uint32_t Layer::getLayerStack() const {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001315 auto p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001316 if (p == nullptr) {
1317 return getDrawingState().layerStack;
1318 }
1319 return p->getLayerStack();
1320}
1321
David Sodman41fdfc92017-11-06 16:09:56 -08001322void Layer::deferTransactionUntil(const sp<Layer>& barrierLayer, uint64_t frameNumber) {
Robert Carr0d480722017-01-10 16:42:54 -08001323 mCurrentState.barrierLayer = barrierLayer;
Dan Stoza7dde5992015-05-22 09:51:44 -07001324 mCurrentState.frameNumber = frameNumber;
1325 // We don't set eTransactionNeeded, because just receiving a deferral
1326 // request without any other state updates shouldn't actually induce a delay
1327 mCurrentState.modified = true;
1328 pushPendingState();
Robert Carr0d480722017-01-10 16:42:54 -08001329 mCurrentState.barrierLayer = nullptr;
Dan Stoza792e5292016-02-11 11:43:58 -08001330 mCurrentState.frameNumber = 0;
Dan Stoza7dde5992015-05-22 09:51:44 -07001331 mCurrentState.modified = false;
Robert Carr0d480722017-01-10 16:42:54 -08001332}
1333
David Sodman41fdfc92017-11-06 16:09:56 -08001334void Layer::deferTransactionUntil(const sp<IBinder>& barrierHandle, uint64_t frameNumber) {
Robert Carr0d480722017-01-10 16:42:54 -08001335 sp<Handle> handle = static_cast<Handle*>(barrierHandle.get());
1336 deferTransactionUntil(handle->owner.promote(), frameNumber);
Dan Stoza7dde5992015-05-22 09:51:44 -07001337}
1338
Dan Stozaee44edd2015-03-23 15:50:23 -07001339
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001340// ----------------------------------------------------------------------------
1341// pageflip handling...
1342// ----------------------------------------------------------------------------
1343
Robert Carr1f0a16a2016-10-24 16:27:39 -07001344bool Layer::isHiddenByPolicy() const {
1345 const Layer::State& s(mDrawingState);
Chia-I Wue41dbe62017-06-13 14:10:56 -07001346 const auto& parent = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001347 if (parent != nullptr && parent->isHiddenByPolicy()) {
1348 return true;
1349 }
1350 return s.flags & layer_state_t::eLayerHidden;
1351}
1352
David Sodman41fdfc92017-11-06 16:09:56 -08001353uint32_t Layer::getEffectiveUsage(uint32_t usage) const {
Mathias Agopiana67932f2011-04-20 14:20:59 -07001354 // TODO: should we do something special if mSecure is set?
1355 if (mProtectedByApp) {
1356 // need a hardware-protected path to external video sink
1357 usage |= GraphicBuffer::USAGE_PROTECTED;
Jamie Gennis54cc83e2010-11-02 11:51:32 -07001358 }
Riley Andrews03414a12014-07-01 14:22:59 -07001359 if (mPotentialCursor) {
1360 usage |= GraphicBuffer::USAGE_CURSOR;
1361 }
Jamie Gennis3599bf22011-08-10 11:48:07 -07001362 usage |= GraphicBuffer::USAGE_HW_COMPOSER;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001363 return usage;
Mathias Agopianb5b7f262010-05-07 15:58:44 -07001364}
1365
Mathias Agopian84300952012-11-21 16:02:13 -08001366void Layer::updateTransformHint(const sp<const DisplayDevice>& hw) const {
Mathias Agopiana4583642011-08-23 18:03:18 -07001367 uint32_t orientation = 0;
1368 if (!mFlinger->mDebugDisableTransformHint) {
Mathias Agopian84300952012-11-21 16:02:13 -08001369 // The transform hint is used to improve performance, but we can
1370 // only have a single transform hint, it cannot
Mathias Agopian4fec8732012-06-29 14:12:52 -07001371 // apply to all displays.
Mathias Agopian42977342012-08-05 00:40:46 -07001372 const Transform& planeTransform(hw->getTransform());
Mathias Agopian4fec8732012-06-29 14:12:52 -07001373 orientation = planeTransform.getOrientation();
Mathias Agopiana4583642011-08-23 18:03:18 -07001374 if (orientation & Transform::ROT_INVALID) {
1375 orientation = 0;
1376 }
1377 }
David Sodmaneb085e02017-10-05 18:49:04 -07001378 setTransformHint(orientation);
Mathias Agopiana4583642011-08-23 18:03:18 -07001379}
1380
Mathias Agopian13127d82013-03-05 17:47:11 -08001381// ----------------------------------------------------------------------------
1382// debugging
1383// ----------------------------------------------------------------------------
1384
Kalle Raitaa099a242017-01-11 11:17:29 -08001385LayerDebugInfo Layer::getLayerDebugInfo() const {
1386 LayerDebugInfo info;
1387 const Layer::State& ds = getDrawingState();
1388 info.mName = getName();
chaviw1acbec72017-07-27 15:28:26 -07001389 sp<Layer> parent = getParent();
Kalle Raitaa099a242017-01-11 11:17:29 -08001390 info.mParentName = (parent == nullptr ? std::string("none") : parent->getName().string());
1391 info.mType = String8(getTypeId());
1392 info.mTransparentRegion = ds.activeTransparentRegion;
1393 info.mVisibleRegion = visibleRegion;
1394 info.mSurfaceDamageRegion = surfaceDamageRegion;
1395 info.mLayerStack = getLayerStack();
1396 info.mX = ds.active.transform.tx();
1397 info.mY = ds.active.transform.ty();
1398 info.mZ = ds.z;
1399 info.mWidth = ds.active.w;
1400 info.mHeight = ds.active.h;
1401 info.mCrop = ds.crop;
1402 info.mFinalCrop = ds.finalCrop;
chaviw13fdc492017-06-27 12:40:18 -07001403 info.mColor = ds.color;
Kalle Raitaa099a242017-01-11 11:17:29 -08001404 info.mFlags = ds.flags;
1405 info.mPixelFormat = getPixelFormat();
1406 info.mDataSpace = getDataSpace();
1407 info.mMatrix[0][0] = ds.active.transform[0][0];
1408 info.mMatrix[0][1] = ds.active.transform[0][1];
1409 info.mMatrix[1][0] = ds.active.transform[1][0];
1410 info.mMatrix[1][1] = ds.active.transform[1][1];
1411 {
David Sodman0cc69182017-11-17 12:12:07 -08001412 sp<const GraphicBuffer> buffer = getBE().compositionInfo.mBuffer;
David Sodman5b4cffc2017-11-23 13:20:29 -08001413 if (buffer != 0) {
1414 info.mActiveBufferWidth = buffer->getWidth();
1415 info.mActiveBufferHeight = buffer->getHeight();
1416 info.mActiveBufferStride = buffer->getStride();
1417 info.mActiveBufferFormat = buffer->format;
Kalle Raitaa099a242017-01-11 11:17:29 -08001418 } else {
1419 info.mActiveBufferWidth = 0;
1420 info.mActiveBufferHeight = 0;
1421 info.mActiveBufferStride = 0;
1422 info.mActiveBufferFormat = 0;
1423 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001424 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001425 info.mNumQueuedFrames = getQueuedFrameCount();
1426 info.mRefreshPending = isBufferLatched();
1427 info.mIsOpaque = isOpaque(ds);
1428 info.mContentDirty = contentDirty;
1429 return info;
Mathias Agopian13127d82013-03-05 17:47:11 -08001430}
Chia-I Wu83ce7c12017-10-19 15:18:55 -07001431
Dan Stozae22aec72016-08-01 13:20:59 -07001432void Layer::miniDumpHeader(String8& result) {
1433 result.append("----------------------------------------");
1434 result.append("---------------------------------------\n");
1435 result.append(" Layer name\n");
1436 result.append(" Z | ");
1437 result.append(" Comp Type | ");
1438 result.append(" Disp Frame (LTRB) | ");
1439 result.append(" Source Crop (LTRB)\n");
1440 result.append("----------------------------------------");
1441 result.append("---------------------------------------\n");
1442}
1443
1444void Layer::miniDump(String8& result, int32_t hwcId) const {
David Sodman6f65f3e2017-11-03 14:28:09 -07001445 if (getBE().mHwcLayers.count(hwcId) == 0) {
Dan Stozae22aec72016-08-01 13:20:59 -07001446 return;
1447 }
1448
1449 String8 name;
1450 if (mName.length() > 77) {
1451 std::string shortened;
1452 shortened.append(mName.string(), 36);
1453 shortened.append("[...]");
1454 shortened.append(mName.string() + (mName.length() - 36), 36);
1455 name = shortened.c_str();
1456 } else {
1457 name = mName;
1458 }
1459
1460 result.appendFormat(" %s\n", name.string());
1461
1462 const Layer::State& layerState(getDrawingState());
David Sodman6f65f3e2017-11-03 14:28:09 -07001463 const LayerBE::HWCInfo& hwcInfo = getBE().mHwcLayers.at(hwcId);
John Reck8c3b6ac2017-08-24 10:25:42 -07001464 result.appendFormat(" %10d | ", layerState.z);
David Sodman41fdfc92017-11-06 16:09:56 -08001465 result.appendFormat("%10s | ", to_string(getCompositionType(hwcId)).c_str());
Dan Stozae22aec72016-08-01 13:20:59 -07001466 const Rect& frame = hwcInfo.displayFrame;
David Sodman41fdfc92017-11-06 16:09:56 -08001467 result.appendFormat("%4d %4d %4d %4d | ", frame.left, frame.top, frame.right, frame.bottom);
Dan Stoza5a423ea2017-02-16 14:10:39 -08001468 const FloatRect& crop = hwcInfo.sourceCrop;
David Sodman41fdfc92017-11-06 16:09:56 -08001469 result.appendFormat("%6.1f %6.1f %6.1f %6.1f\n", crop.left, crop.top, crop.right, crop.bottom);
Dan Stozae22aec72016-08-01 13:20:59 -07001470
1471 result.append("- - - - - - - - - - - - - - - - - - - - ");
1472 result.append("- - - - - - - - - - - - - - - - - - - -\n");
1473}
Dan Stozae22aec72016-08-01 13:20:59 -07001474
Svetoslavd85084b2014-03-20 10:28:31 -07001475void Layer::dumpFrameStats(String8& result) const {
1476 mFrameTracker.dumpStats(result);
Mathias Agopian13127d82013-03-05 17:47:11 -08001477}
1478
Svetoslavd85084b2014-03-20 10:28:31 -07001479void Layer::clearFrameStats() {
1480 mFrameTracker.clearStats();
Mathias Agopian13127d82013-03-05 17:47:11 -08001481}
1482
Jamie Gennis6547ff42013-07-16 20:12:42 -07001483void Layer::logFrameStats() {
1484 mFrameTracker.logAndResetStats(mName);
1485}
1486
Svetoslavd85084b2014-03-20 10:28:31 -07001487void Layer::getFrameStats(FrameStats* outStats) const {
1488 mFrameTracker.getStats(outStats);
1489}
1490
Brian Andersond6927fb2016-07-23 23:37:30 -07001491void Layer::dumpFrameEvents(String8& result) {
David Sodman41fdfc92017-11-06 16:09:56 -08001492 result.appendFormat("- Layer %s (%s, %p)\n", getName().string(), getTypeId(), this);
Brian Andersond6927fb2016-07-23 23:37:30 -07001493 Mutex::Autolock lock(mFrameEventHistoryMutex);
1494 mFrameEventHistory.checkFencesForCompletion();
1495 mFrameEventHistory.dump(result);
1496}
Pablo Ceballos40845df2016-01-25 17:41:15 -08001497
Brian Anderson5ea5e592016-12-01 16:54:33 -08001498void Layer::onDisconnect() {
1499 Mutex::Autolock lock(mFrameEventHistoryMutex);
1500 mFrameEventHistory.onDisconnect();
1501}
1502
Brian Anderson3890c392016-07-25 12:48:08 -07001503void Layer::addAndGetFrameTimestamps(const NewFrameEventsEntry* newTimestamps,
David Sodman41fdfc92017-11-06 16:09:56 -08001504 FrameEventHistoryDelta* outDelta) {
Brian Andersond6927fb2016-07-23 23:37:30 -07001505 Mutex::Autolock lock(mFrameEventHistoryMutex);
1506 if (newTimestamps) {
Brian Andersonfbc80ae2017-05-26 16:23:54 -07001507 // If there are any unsignaled fences in the aquire timeline at this
1508 // point, the previously queued frame hasn't been latched yet. Go ahead
1509 // and try to get the signal time here so the syscall is taken out of
1510 // the main thread's critical path.
1511 mAcquireTimeline.updateSignalTimes();
1512 // Push the new fence after updating since it's likely still pending.
Brian Anderson3d4039d2016-09-23 16:31:30 -07001513 mAcquireTimeline.push(newTimestamps->acquireFence);
Brian Andersond6927fb2016-07-23 23:37:30 -07001514 mFrameEventHistory.addQueue(*newTimestamps);
1515 }
1516
Brian Anderson3890c392016-07-25 12:48:08 -07001517 if (outDelta) {
1518 mFrameEventHistory.getAndResetDelta(outDelta);
Brian Andersond6927fb2016-07-23 23:37:30 -07001519 }
Pablo Ceballos40845df2016-01-25 17:41:15 -08001520}
Dan Stozae77c7662016-05-13 11:37:28 -07001521
Chia-I Wu98f1c102017-05-30 14:54:08 -07001522size_t Layer::getChildrenCount() const {
1523 size_t count = 0;
1524 for (const sp<Layer>& child : mCurrentChildren) {
1525 count += 1 + child->getChildrenCount();
1526 }
1527 return count;
1528}
1529
Robert Carr1f0a16a2016-10-24 16:27:39 -07001530void Layer::addChild(const sp<Layer>& layer) {
1531 mCurrentChildren.add(layer);
1532 layer->setParent(this);
1533}
1534
1535ssize_t Layer::removeChild(const sp<Layer>& layer) {
1536 layer->setParent(nullptr);
1537 return mCurrentChildren.remove(layer);
1538}
1539
Robert Carr1db73f62016-12-21 12:58:51 -08001540bool Layer::reparentChildren(const sp<IBinder>& newParentHandle) {
1541 sp<Handle> handle = nullptr;
1542 sp<Layer> newParent = nullptr;
1543 if (newParentHandle == nullptr) {
1544 return false;
1545 }
1546 handle = static_cast<Handle*>(newParentHandle.get());
1547 newParent = handle->owner.promote();
1548 if (newParent == nullptr) {
1549 ALOGE("Unable to promote Layer handle");
1550 return false;
1551 }
1552
1553 for (const sp<Layer>& child : mCurrentChildren) {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001554 newParent->addChild(child);
Robert Carr1db73f62016-12-21 12:58:51 -08001555
1556 sp<Client> client(child->mClientRef.promote());
1557 if (client != nullptr) {
1558 client->setParentLayer(newParent);
1559 }
1560 }
1561 mCurrentChildren.clear();
1562
1563 return true;
1564}
1565
chaviwf1961f72017-09-18 16:41:07 -07001566bool Layer::reparent(const sp<IBinder>& newParentHandle) {
1567 if (newParentHandle == nullptr) {
chaviw06178942017-07-27 10:25:59 -07001568 return false;
1569 }
1570
1571 auto handle = static_cast<Handle*>(newParentHandle.get());
1572 sp<Layer> newParent = handle->owner.promote();
1573 if (newParent == nullptr) {
1574 ALOGE("Unable to promote Layer handle");
1575 return false;
1576 }
1577
chaviwf1961f72017-09-18 16:41:07 -07001578 sp<Layer> parent = getParent();
1579 if (parent != nullptr) {
1580 parent->removeChild(this);
chaviw06178942017-07-27 10:25:59 -07001581 }
chaviwf1961f72017-09-18 16:41:07 -07001582 newParent->addChild(this);
chaviw06178942017-07-27 10:25:59 -07001583
chaviwf1961f72017-09-18 16:41:07 -07001584 sp<Client> client(mClientRef.promote());
chaviw06178942017-07-27 10:25:59 -07001585 sp<Client> newParentClient(newParent->mClientRef.promote());
1586
chaviwf1961f72017-09-18 16:41:07 -07001587 if (client != newParentClient) {
1588 client->setParentLayer(newParent);
chaviw06178942017-07-27 10:25:59 -07001589 }
1590
chaviw06178942017-07-27 10:25:59 -07001591 return true;
1592}
1593
Robert Carr9524cb32017-02-13 11:32:32 -08001594bool Layer::detachChildren() {
Robert Carr7f619b22017-11-06 12:56:35 -08001595 for (const sp<Layer>& child : mCurrentChildren) {
chaviw161410b02017-07-27 10:46:08 -07001596 sp<Client> parentClient = mClientRef.promote();
Robert Carr9524cb32017-02-13 11:32:32 -08001597 sp<Client> client(child->mClientRef.promote());
chaviw161410b02017-07-27 10:46:08 -07001598 if (client != nullptr && parentClient != client) {
Robert Carr7f619b22017-11-06 12:56:35 -08001599 client->detachLayer(child.get());
1600 child->detachChildren();
Robert Carr9524cb32017-02-13 11:32:32 -08001601 }
Robert Carr7f619b22017-11-06 12:56:35 -08001602 }
Robert Carr9524cb32017-02-13 11:32:32 -08001603
1604 return true;
1605}
1606
Robert Carr1f0a16a2016-10-24 16:27:39 -07001607void Layer::setParent(const sp<Layer>& layer) {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001608 mCurrentParent = layer;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001609}
1610
1611void Layer::clearSyncPoints() {
1612 for (const auto& child : mCurrentChildren) {
1613 child->clearSyncPoints();
1614 }
1615
1616 Mutex::Autolock lock(mLocalSyncPointMutex);
1617 for (auto& point : mLocalSyncPoints) {
1618 point->setFrameAvailable();
1619 }
1620 mLocalSyncPoints.clear();
1621}
1622
1623int32_t Layer::getZ() const {
1624 return mDrawingState.z;
1625}
1626
Robert Carr29abff82017-12-04 13:51:20 -08001627bool Layer::usingRelativeZ(LayerVector::StateSet stateSet) {
1628 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1629 const State& state = useDrawing ? mDrawingState : mCurrentState;
1630 return state.zOrderRelativeOf != nullptr;
1631}
1632
David Sodman41fdfc92017-11-06 16:09:56 -08001633__attribute__((no_sanitize("unsigned-integer-overflow"))) LayerVector Layer::makeTraversalList(
Robert Carr29abff82017-12-04 13:51:20 -08001634 LayerVector::StateSet stateSet, bool* outSkipRelativeZUsers) {
Dan Stoza412903f2017-04-27 13:42:17 -07001635 LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid,
1636 "makeTraversalList received invalid stateSet");
1637 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1638 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
1639 const State& state = useDrawing ? mDrawingState : mCurrentState;
1640
Robert Carr29abff82017-12-04 13:51:20 -08001641 if (state.zOrderRelatives.size() == 0) {
1642 *outSkipRelativeZUsers = true;
1643 return children;
1644 }
1645
Robert Carrdb66e622017-04-10 16:55:57 -07001646 LayerVector traverse;
Dan Stoza412903f2017-04-27 13:42:17 -07001647 for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
Robert Carrdb66e622017-04-10 16:55:57 -07001648 sp<Layer> strongRelative = weakRelative.promote();
1649 if (strongRelative != nullptr) {
1650 traverse.add(strongRelative);
Robert Carrdb66e622017-04-10 16:55:57 -07001651 }
1652 }
1653
Dan Stoza412903f2017-04-27 13:42:17 -07001654 for (const sp<Layer>& child : children) {
Robert Carr503c7042017-09-27 15:06:08 -07001655 const State& childState = useDrawing ? child->mDrawingState : child->mCurrentState;
1656 if (childState.zOrderRelativeOf != nullptr) {
1657 continue;
1658 }
Robert Carrdb66e622017-04-10 16:55:57 -07001659 traverse.add(child);
1660 }
1661
1662 return traverse;
1663}
1664
Robert Carr1f0a16a2016-10-24 16:27:39 -07001665/**
Robert Carrdb66e622017-04-10 16:55:57 -07001666 * Negatively signed relatives are before 'this' in Z-order.
Robert Carr1f0a16a2016-10-24 16:27:39 -07001667 */
Dan Stoza412903f2017-04-27 13:42:17 -07001668void Layer::traverseInZOrder(LayerVector::StateSet stateSet, const LayerVector::Visitor& visitor) {
Robert Carr29abff82017-12-04 13:51:20 -08001669 // In the case we have other layers who are using a relative Z to us, makeTraversalList will
1670 // produce a new list for traversing, including our relatives, and not including our children
1671 // who are relatives of another surface. In the case that there are no relative Z,
1672 // makeTraversalList returns our children directly to avoid significant overhead.
1673 // However in this case we need to take the responsibility for filtering children which
1674 // are relatives of another surface here.
1675 bool skipRelativeZUsers = false;
1676 const LayerVector list = makeTraversalList(stateSet, &skipRelativeZUsers);
Robert Carrdb66e622017-04-10 16:55:57 -07001677
Robert Carr1f0a16a2016-10-24 16:27:39 -07001678 size_t i = 0;
Robert Carrdb66e622017-04-10 16:55:57 -07001679 for (; i < list.size(); i++) {
1680 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001681 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1682 continue;
1683 }
1684
Robert Carrdb66e622017-04-10 16:55:57 -07001685 if (relative->getZ() >= 0) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001686 break;
Robert Carrdb66e622017-04-10 16:55:57 -07001687 }
Dan Stoza412903f2017-04-27 13:42:17 -07001688 relative->traverseInZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001689 }
Robert Carr29abff82017-12-04 13:51:20 -08001690
Dan Stoza412903f2017-04-27 13:42:17 -07001691 visitor(this);
Robert Carrdb66e622017-04-10 16:55:57 -07001692 for (; i < list.size(); i++) {
1693 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001694
1695 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1696 continue;
1697 }
Dan Stoza412903f2017-04-27 13:42:17 -07001698 relative->traverseInZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001699 }
1700}
1701
1702/**
Robert Carrdb66e622017-04-10 16:55:57 -07001703 * Positively signed relatives are before 'this' in reverse Z-order.
Robert Carr1f0a16a2016-10-24 16:27:39 -07001704 */
Dan Stoza412903f2017-04-27 13:42:17 -07001705void Layer::traverseInReverseZOrder(LayerVector::StateSet stateSet,
1706 const LayerVector::Visitor& visitor) {
Robert Carr29abff82017-12-04 13:51:20 -08001707 // See traverseInZOrder for documentation.
1708 bool skipRelativeZUsers = false;
1709 LayerVector list = makeTraversalList(stateSet, &skipRelativeZUsers);
Robert Carrdb66e622017-04-10 16:55:57 -07001710
Robert Carr1f0a16a2016-10-24 16:27:39 -07001711 int32_t i = 0;
Joel Galensonbf324992017-11-06 11:04:12 -08001712 for (i = int32_t(list.size()) - 1; i >= 0; i--) {
Robert Carrdb66e622017-04-10 16:55:57 -07001713 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001714
1715 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1716 continue;
1717 }
1718
Robert Carrdb66e622017-04-10 16:55:57 -07001719 if (relative->getZ() < 0) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001720 break;
1721 }
Dan Stoza412903f2017-04-27 13:42:17 -07001722 relative->traverseInReverseZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001723 }
Dan Stoza412903f2017-04-27 13:42:17 -07001724 visitor(this);
David Sodman41fdfc92017-11-06 16:09:56 -08001725 for (; i >= 0; i--) {
Robert Carrdb66e622017-04-10 16:55:57 -07001726 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001727
1728 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1729 continue;
1730 }
1731
Dan Stoza412903f2017-04-27 13:42:17 -07001732 relative->traverseInReverseZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001733 }
1734}
1735
chaviwa76b2712017-09-20 12:02:26 -07001736/**
1737 * Traverse only children in z order, ignoring relative layers.
1738 */
1739void Layer::traverseChildrenInZOrder(LayerVector::StateSet stateSet,
1740 const LayerVector::Visitor& visitor) {
1741 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1742 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
1743
1744 size_t i = 0;
1745 for (; i < children.size(); i++) {
1746 const auto& relative = children[i];
1747 if (relative->getZ() >= 0) {
1748 break;
1749 }
1750 relative->traverseChildrenInZOrder(stateSet, visitor);
1751 }
1752 visitor(this);
1753 for (; i < children.size(); i++) {
1754 const auto& relative = children[i];
1755 relative->traverseChildrenInZOrder(stateSet, visitor);
1756 }
1757}
1758
Robert Carr1f0a16a2016-10-24 16:27:39 -07001759Transform Layer::getTransform() const {
1760 Transform t;
Chia-I Wue41dbe62017-06-13 14:10:56 -07001761 const auto& p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001762 if (p != nullptr) {
1763 t = p->getTransform();
Robert Carr9b429f42017-04-17 14:56:57 -07001764
1765 // If the parent is not using NATIVE_WINDOW_SCALING_MODE_FREEZE (e.g.
1766 // it isFixedSize) then there may be additional scaling not accounted
1767 // for in the transform. We need to mirror this scaling in child surfaces
1768 // or we will break the contract where WM can treat child surfaces as
1769 // pixels in the parent surface.
David Sodman0cc69182017-11-17 12:12:07 -08001770 if (p->isFixedSize() && p->getBE().compositionInfo.mBuffer != nullptr) {
Robert Carr1725eee2017-04-26 18:32:15 -07001771 int bufferWidth;
1772 int bufferHeight;
1773 if ((p->mCurrentTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) == 0) {
David Sodman0cc69182017-11-17 12:12:07 -08001774 bufferWidth = p->getBE().compositionInfo.mBuffer->getWidth();
1775 bufferHeight = p->getBE().compositionInfo.mBuffer->getHeight();
Robert Carr1725eee2017-04-26 18:32:15 -07001776 } else {
David Sodman0cc69182017-11-17 12:12:07 -08001777 bufferHeight = p->getBE().compositionInfo.mBuffer->getWidth();
1778 bufferWidth = p->getBE().compositionInfo.mBuffer->getHeight();
Robert Carr1725eee2017-04-26 18:32:15 -07001779 }
David Sodman41fdfc92017-11-06 16:09:56 -08001780 float sx = p->getDrawingState().active.w / static_cast<float>(bufferWidth);
1781 float sy = p->getDrawingState().active.h / static_cast<float>(bufferHeight);
Robert Carr9b429f42017-04-17 14:56:57 -07001782 Transform extraParentScaling;
1783 extraParentScaling.set(sx, 0, 0, sy);
1784 t = t * extraParentScaling;
1785 }
Robert Carr1f0a16a2016-10-24 16:27:39 -07001786 }
1787 return t * getDrawingState().active.transform;
1788}
1789
chaviw13fdc492017-06-27 12:40:18 -07001790half Layer::getAlpha() const {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001791 const auto& p = mDrawingParent.promote();
Robert Carr6452f122017-03-21 10:41:29 -07001792
chaviw13fdc492017-06-27 12:40:18 -07001793 half parentAlpha = (p != nullptr) ? p->getAlpha() : 1.0_hf;
1794 return parentAlpha * getDrawingState().color.a;
Robert Carr6452f122017-03-21 10:41:29 -07001795}
Robert Carr6452f122017-03-21 10:41:29 -07001796
chaviw13fdc492017-06-27 12:40:18 -07001797half4 Layer::getColor() const {
1798 const half4 color(getDrawingState().color);
1799 return half4(color.r, color.g, color.b, getAlpha());
Robert Carr6452f122017-03-21 10:41:29 -07001800}
Robert Carr6452f122017-03-21 10:41:29 -07001801
Robert Carr1f0a16a2016-10-24 16:27:39 -07001802void Layer::commitChildList() {
1803 for (size_t i = 0; i < mCurrentChildren.size(); i++) {
1804 const auto& child = mCurrentChildren[i];
1805 child->commitChildList();
1806 }
1807 mDrawingChildren = mCurrentChildren;
Chia-I Wue41dbe62017-06-13 14:10:56 -07001808 mDrawingParent = mCurrentParent;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001809}
1810
chaviw1d044282017-09-27 12:19:28 -07001811void Layer::writeToProto(LayerProto* layerInfo, LayerVector::StateSet stateSet) {
1812 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1813 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
1814 const State& state = useDrawing ? mDrawingState : mCurrentState;
1815
1816 Transform requestedTransform = state.active.transform;
1817 Transform transform = getTransform();
1818
1819 layerInfo->set_id(sequence);
1820 layerInfo->set_name(getName().c_str());
1821 layerInfo->set_type(String8(getTypeId()));
1822
1823 for (const auto& child : children) {
1824 layerInfo->add_children(child->sequence);
1825 }
1826
1827 for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
1828 sp<Layer> strongRelative = weakRelative.promote();
1829 if (strongRelative != nullptr) {
1830 layerInfo->add_relatives(strongRelative->sequence);
1831 }
1832 }
1833
1834 LayerProtoHelper::writeToProto(state.activeTransparentRegion,
1835 layerInfo->mutable_transparent_region());
1836 LayerProtoHelper::writeToProto(visibleRegion, layerInfo->mutable_visible_region());
1837 LayerProtoHelper::writeToProto(surfaceDamageRegion, layerInfo->mutable_damage_region());
1838
1839 layerInfo->set_layer_stack(getLayerStack());
1840 layerInfo->set_z(state.z);
1841
1842 PositionProto* position = layerInfo->mutable_position();
1843 position->set_x(transform.tx());
1844 position->set_y(transform.ty());
1845
1846 PositionProto* requestedPosition = layerInfo->mutable_requested_position();
1847 requestedPosition->set_x(requestedTransform.tx());
1848 requestedPosition->set_y(requestedTransform.ty());
1849
1850 SizeProto* size = layerInfo->mutable_size();
1851 size->set_w(state.active.w);
1852 size->set_h(state.active.h);
1853
1854 LayerProtoHelper::writeToProto(state.crop, layerInfo->mutable_crop());
1855 LayerProtoHelper::writeToProto(state.finalCrop, layerInfo->mutable_final_crop());
1856
1857 layerInfo->set_is_opaque(isOpaque(state));
1858 layerInfo->set_invalidate(contentDirty);
1859 layerInfo->set_dataspace(dataspaceDetails(getDataSpace()));
1860 layerInfo->set_pixel_format(decodePixelFormat(getPixelFormat()));
1861 LayerProtoHelper::writeToProto(getColor(), layerInfo->mutable_color());
1862 LayerProtoHelper::writeToProto(state.color, layerInfo->mutable_requested_color());
1863 layerInfo->set_flags(state.flags);
1864
1865 LayerProtoHelper::writeToProto(transform, layerInfo->mutable_transform());
1866 LayerProtoHelper::writeToProto(requestedTransform, layerInfo->mutable_requested_transform());
1867
Jorim Jaggi8e0af362017-11-14 16:28:28 +01001868 auto parent = useDrawing ? mDrawingParent.promote() : mCurrentParent.promote();
chaviw1d044282017-09-27 12:19:28 -07001869 if (parent != nullptr) {
1870 layerInfo->set_parent(parent->sequence);
1871 }
1872
1873 auto zOrderRelativeOf = state.zOrderRelativeOf.promote();
1874 if (zOrderRelativeOf != nullptr) {
1875 layerInfo->set_z_order_relative_of(zOrderRelativeOf->sequence);
1876 }
1877
David Sodman0cc69182017-11-17 12:12:07 -08001878 auto buffer = getBE().compositionInfo.mBuffer;
David Sodman5b4cffc2017-11-23 13:20:29 -08001879 if (buffer != nullptr) {
1880 LayerProtoHelper::writeToProto(buffer, layerInfo->mutable_active_buffer());
chaviw1d044282017-09-27 12:19:28 -07001881 }
1882
1883 layerInfo->set_queued_frames(getQueuedFrameCount());
1884 layerInfo->set_refresh_pending(isBufferLatched());
1885}
1886
Mathias Agopian13127d82013-03-05 17:47:11 -08001887// ---------------------------------------------------------------------------
1888
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001889}; // namespace android
Mathias Agopian3f844832013-08-07 21:24:32 -07001890
1891#if defined(__gl_h_)
1892#error "don't include gl/gl.h in this file"
1893#endif
1894
1895#if defined(__gl2_h_)
1896#error "don't include gl2/gl2.h in this file"
1897#endif