blob: fa4d2892498fa8108e637f49e490f8e7174a6853 [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() {
Jamie Gennis6547ff42013-07-16 20:12:42 -0700145 mFrameTracker.logAndResetStats(mName);
Mathias Agopian96f08192010-06-02 23:28:45 -0700146}
147
Mathias Agopian13127d82013-03-05 17:47:11 -0800148// ---------------------------------------------------------------------------
149// callbacks
150// ---------------------------------------------------------------------------
151
David Sodmaneb085e02017-10-05 18:49:04 -0700152/*
153 * onLayerDisplayed is only meaningful for BufferLayer, but, is called through
154 * Layer. So, the implementation is done in BufferLayer. When called on a
155 * ColorLayer object, it's essentially a NOP.
156 */
David Sodmaneb085e02017-10-05 18:49:04 -0700157void Layer::onLayerDisplayed(const sp<Fence>& /*releaseFence*/) {}
Mathias Agopian13127d82013-03-05 17:47:11 -0800158
Chia-I Wuc6657022017-08-15 11:18:17 -0700159void Layer::onRemovedFromCurrentState() {
160 // the layer is removed from SF mCurrentState to mLayersPendingRemoval
161
chaviw8b3871a2017-11-01 17:41:01 -0700162 mPendingRemoval = true;
163
Robert Carr5edb1ad2017-04-25 10:54:24 -0700164 if (mCurrentState.zOrderRelativeOf != nullptr) {
165 sp<Layer> strongRelative = mCurrentState.zOrderRelativeOf.promote();
166 if (strongRelative != nullptr) {
167 strongRelative->removeZOrderRelative(this);
Chia-I Wuc6657022017-08-15 11:18:17 -0700168 mFlinger->setTransactionFlags(eTraversalNeeded);
Robert Carr5edb1ad2017-04-25 10:54:24 -0700169 }
170 mCurrentState.zOrderRelativeOf = nullptr;
171 }
172
Chia-I Wuc6657022017-08-15 11:18:17 -0700173 for (const auto& child : mCurrentChildren) {
174 child->onRemovedFromCurrentState();
175 }
176}
Chia-I Wu38512252017-05-17 14:36:16 -0700177
Chia-I Wuc6657022017-08-15 11:18:17 -0700178void Layer::onRemoved() {
179 // the layer is removed from SF mLayersPendingRemoval
David Sodmaneb085e02017-10-05 18:49:04 -0700180 abandon();
Chia-I Wuc6657022017-08-15 11:18:17 -0700181
Steven Thomasb02664d2017-07-26 18:48:28 -0700182 destroyAllHwcLayers();
Chia-I Wu38512252017-05-17 14:36:16 -0700183
Robert Carr1f0a16a2016-10-24 16:27:39 -0700184 for (const auto& child : mCurrentChildren) {
185 child->onRemoved();
186 }
Mathias Agopian48d819a2009-09-10 19:41:18 -0700187}
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700188
Mathias Agopian13127d82013-03-05 17:47:11 -0800189// ---------------------------------------------------------------------------
190// set-up
191// ---------------------------------------------------------------------------
192
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700193const String8& Layer::getName() const {
Mathias Agopian13127d82013-03-05 17:47:11 -0800194 return mName;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800195}
196
chaviw13fdc492017-06-27 12:40:18 -0700197bool Layer::getPremultipledAlpha() const {
198 return mPremultipliedAlpha;
199}
200
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700201sp<IBinder> Layer::getHandle() {
Mathias Agopian13127d82013-03-05 17:47:11 -0800202 Mutex::Autolock _l(mLock);
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700203 return new Handle(mFlinger, this);
Mathias Agopian13127d82013-03-05 17:47:11 -0800204}
205
206// ---------------------------------------------------------------------------
207// h/w composer set-up
208// ---------------------------------------------------------------------------
209
Steven Thomasb02664d2017-07-26 18:48:28 -0700210bool Layer::createHwcLayer(HWComposer* hwc, int32_t hwcId) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700211 LOG_ALWAYS_FATAL_IF(getBE().mHwcLayers.count(hwcId) != 0,
David Sodman9eeae692017-11-02 10:53:32 -0700212 "Already have a layer for hwcId %d", hwcId);
Steven Thomasb02664d2017-07-26 18:48:28 -0700213 HWC2::Layer* layer = hwc->createLayer(hwcId);
214 if (!layer) {
215 return false;
216 }
David Sodman6f65f3e2017-11-03 14:28:09 -0700217 LayerBE::HWCInfo& hwcInfo = getBE().mHwcLayers[hwcId];
Steven Thomasb02664d2017-07-26 18:48:28 -0700218 hwcInfo.hwc = hwc;
219 hwcInfo.layer = layer;
220 layer->setLayerDestroyedListener(
David Sodman6f65f3e2017-11-03 14:28:09 -0700221 [this, hwcId](HWC2::Layer* /*layer*/) { getBE().mHwcLayers.erase(hwcId); });
Steven Thomasb02664d2017-07-26 18:48:28 -0700222 return true;
223}
224
Chia-I Wu83806892017-11-16 10:50:20 -0800225bool Layer::destroyHwcLayer(int32_t hwcId) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700226 if (getBE().mHwcLayers.count(hwcId) == 0) {
Chia-I Wu83806892017-11-16 10:50:20 -0800227 return false;
Steven Thomasb02664d2017-07-26 18:48:28 -0700228 }
David Sodman6f65f3e2017-11-03 14:28:09 -0700229 auto& hwcInfo = getBE().mHwcLayers[hwcId];
David Sodman41fdfc92017-11-06 16:09:56 -0800230 LOG_ALWAYS_FATAL_IF(hwcInfo.layer == nullptr, "Attempt to destroy null layer");
Steven Thomasb02664d2017-07-26 18:48:28 -0700231 LOG_ALWAYS_FATAL_IF(hwcInfo.hwc == nullptr, "Missing HWComposer");
232 hwcInfo.hwc->destroyLayer(hwcId, hwcInfo.layer);
233 // The layer destroyed listener should have cleared the entry from
234 // mHwcLayers. Verify that.
David Sodman6f65f3e2017-11-03 14:28:09 -0700235 LOG_ALWAYS_FATAL_IF(getBE().mHwcLayers.count(hwcId) != 0,
236 "Stale layer entry in getBE().mHwcLayers");
Chia-I Wu83806892017-11-16 10:50:20 -0800237 return true;
Steven Thomasb02664d2017-07-26 18:48:28 -0700238}
239
240void Layer::destroyAllHwcLayers() {
David Sodman6f65f3e2017-11-03 14:28:09 -0700241 size_t numLayers = getBE().mHwcLayers.size();
Steven Thomasb02664d2017-07-26 18:48:28 -0700242 for (size_t i = 0; i < numLayers; ++i) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700243 LOG_ALWAYS_FATAL_IF(getBE().mHwcLayers.empty(), "destroyAllHwcLayers failed");
244 destroyHwcLayer(getBE().mHwcLayers.begin()->first);
Steven Thomasb02664d2017-07-26 18:48:28 -0700245 }
David Sodman6f65f3e2017-11-03 14:28:09 -0700246 LOG_ALWAYS_FATAL_IF(!getBE().mHwcLayers.empty(),
David Sodman41fdfc92017-11-06 16:09:56 -0800247 "All hardware composer layers should have been destroyed");
Steven Thomasb02664d2017-07-26 18:48:28 -0700248}
Steven Thomasb02664d2017-07-26 18:48:28 -0700249
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800250Rect Layer::getContentCrop() const {
251 // this is the crop rectangle that applies to the buffer
252 // itself (as opposed to the window)
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700253 Rect crop;
254 if (!mCurrentCrop.isEmpty()) {
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800255 // if the buffer crop is defined, we use that
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700256 crop = mCurrentCrop;
David Sodman0cc69182017-11-17 12:12:07 -0800257 } else if (getBE().compositionInfo.mBuffer != NULL) {
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800258 // otherwise we use the whole buffer
David Sodman0cc69182017-11-17 12:12:07 -0800259 crop = getBE().compositionInfo.mBuffer->getBounds();
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700260 } else {
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800261 // if we don't have a buffer yet, we use an empty/invalid crop
Mathias Agopian4fec8732012-06-29 14:12:52 -0700262 crop.makeInvalid();
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700263 }
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700264 return crop;
265}
266
Mathias Agopianf3e85d42013-05-10 18:01:12 -0700267static Rect reduce(const Rect& win, const Region& exclude) {
268 if (CC_LIKELY(exclude.isEmpty())) {
269 return win;
270 }
271 if (exclude.isRect()) {
272 return win.reduce(exclude.getBounds());
273 }
274 return Region(win).subtract(exclude).getBounds();
275}
276
Robert Carr1f0a16a2016-10-24 16:27:39 -0700277Rect Layer::computeScreenBounds(bool reduceTransparentRegion) const {
278 const Layer::State& s(getDrawingState());
279 Rect win(s.active.w, s.active.h);
280
281 if (!s.crop.isEmpty()) {
282 win.intersect(s.crop, &win);
283 }
284
285 Transform t = getTransform();
286 win = t.transform(win);
287
Robert Carr41b08b52017-06-01 16:11:34 -0700288 if (!s.finalCrop.isEmpty()) {
289 win.intersect(s.finalCrop, &win);
290 }
291
Chia-I Wue41dbe62017-06-13 14:10:56 -0700292 const sp<Layer>& p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700293 // Now we need to calculate the parent bounds, so we can clip ourselves to those.
294 // When calculating the parent bounds for purposes of clipping,
295 // we don't need to constrain the parent to its transparent region.
296 // The transparent region is an optimization based on the
297 // buffer contents of the layer, but does not affect the space allocated to
298 // it by policy, and thus children should be allowed to extend into the
299 // parent's transparent region. In fact one of the main uses, is to reduce
300 // buffer allocation size in cases where a child window sits behind a main window
301 // (by marking the hole in the parent window as a transparent region)
302 if (p != nullptr) {
303 Rect bounds = p->computeScreenBounds(false);
304 bounds.intersect(win, &win);
305 }
306
307 if (reduceTransparentRegion) {
308 auto const screenTransparentRegion = t.transform(s.activeTransparentRegion);
309 win = reduce(win, screenTransparentRegion);
310 }
311
312 return win;
313}
314
Mathias Agopian13127d82013-03-05 17:47:11 -0800315Rect Layer::computeBounds() const {
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700316 const Layer::State& s(getDrawingState());
Michael Lentine6c925ed2014-09-26 17:55:01 -0700317 return computeBounds(s.activeTransparentRegion);
318}
319
320Rect Layer::computeBounds(const Region& activeTransparentRegion) const {
321 const Layer::State& s(getDrawingState());
Mathias Agopian13127d82013-03-05 17:47:11 -0800322 Rect win(s.active.w, s.active.h);
Robert Carrb5d3d262016-03-25 15:08:13 -0700323
324 if (!s.crop.isEmpty()) {
325 win.intersect(s.crop, &win);
Mathias Agopian13127d82013-03-05 17:47:11 -0800326 }
Robert Carr1f0a16a2016-10-24 16:27:39 -0700327
328 Rect bounds = win;
Chia-I Wue41dbe62017-06-13 14:10:56 -0700329 const auto& p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700330 if (p != nullptr) {
Robert Carrde9ec442017-02-08 17:43:36 -0800331 // Look in computeScreenBounds recursive call for explanation of
332 // why we pass false here.
333 bounds = p->computeScreenBounds(false /* reduceTransparentRegion */);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700334 }
335
336 Transform t = getTransform();
337 if (p != nullptr) {
338 win = t.transform(win);
339 win.intersect(bounds, &win);
340 win = t.inverse().transform(win);
341 }
342
Mathias Agopian6c7f25a2013-05-09 20:37:10 -0700343 // subtract the transparent region and snap to the bounds
Michael Lentine6c925ed2014-09-26 17:55:01 -0700344 return reduce(win, activeTransparentRegion);
Mathias Agopian13127d82013-03-05 17:47:11 -0800345}
346
Robert Carr1f0a16a2016-10-24 16:27:39 -0700347Rect Layer::computeInitialCrop(const sp<const DisplayDevice>& hw) const {
Robert Carrb5d3d262016-03-25 15:08:13 -0700348 // the crop is the area of the window that gets cropped, but not
Mathias Agopian13127d82013-03-05 17:47:11 -0800349 // scaled in any ways.
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700350 const State& s(getDrawingState());
Mathias Agopian13127d82013-03-05 17:47:11 -0800351
352 // apply the projection's clipping to the window crop in
353 // layerstack space, and convert-back to layer space.
Mathias Agopian6b442672013-07-09 21:24:52 -0700354 // if there are no window scaling involved, this operation will map to full
355 // pixels in the buffer.
356 // FIXME: the 3 lines below can produce slightly incorrect clipping when we have
357 // a viewport clipping and a window transform. we should use floating point to fix this.
Mathias Agopian0e8f1442013-08-20 21:41:07 -0700358
359 Rect activeCrop(s.active.w, s.active.h);
Robert Carrb5d3d262016-03-25 15:08:13 -0700360 if (!s.crop.isEmpty()) {
Chia-I Wudf7867f2017-07-20 14:24:37 -0700361 activeCrop.intersect(s.crop, &activeCrop);
Mathias Agopian0e8f1442013-08-20 21:41:07 -0700362 }
363
Robert Carr1f0a16a2016-10-24 16:27:39 -0700364 Transform t = getTransform();
365 activeCrop = t.transform(activeCrop);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000366 if (!activeCrop.intersect(hw->getViewport(), &activeCrop)) {
367 activeCrop.clear();
368 }
Robert Carrb5d3d262016-03-25 15:08:13 -0700369 if (!s.finalCrop.isEmpty()) {
David Sodman41fdfc92017-11-06 16:09:56 -0800370 if (!activeCrop.intersect(s.finalCrop, &activeCrop)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000371 activeCrop.clear();
372 }
373 }
chaviwb1154d12017-10-31 14:15:36 -0700374
375 const auto& p = mDrawingParent.promote();
376 if (p != nullptr) {
377 auto parentCrop = p->computeInitialCrop(hw);
378 activeCrop.intersect(parentCrop, &activeCrop);
379 }
380
Robert Carr1f0a16a2016-10-24 16:27:39 -0700381 return activeCrop;
382}
383
Dan Stoza5a423ea2017-02-16 14:10:39 -0800384FloatRect Layer::computeCrop(const sp<const DisplayDevice>& hw) const {
Robert Carr1f0a16a2016-10-24 16:27:39 -0700385 // the content crop is the area of the content that gets scaled to the
386 // layer's size. This is in buffer space.
Dan Stoza5a423ea2017-02-16 14:10:39 -0800387 FloatRect crop = getContentCrop().toFloatRect();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700388
389 // In addition there is a WM-specified crop we pull from our drawing state.
390 const State& s(getDrawingState());
391
392 // Screen space to make reduction to parent crop clearer.
393 Rect activeCrop = computeInitialCrop(hw);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700394 Transform t = getTransform();
395 // Back to layer space to work with the content crop.
396 activeCrop = t.inverse().transform(activeCrop);
Mathias Agopian13127d82013-03-05 17:47:11 -0800397
Michael Lentine28ea2172014-11-19 18:32:37 -0800398 // This needs to be here as transform.transform(Rect) computes the
399 // transformed rect and then takes the bounding box of the result before
400 // returning. This means
401 // transform.inverse().transform(transform.transform(Rect)) != Rect
402 // in which case we need to make sure the final rect is clipped to the
403 // display bounds.
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000404 if (!activeCrop.intersect(Rect(s.active.w, s.active.h), &activeCrop)) {
405 activeCrop.clear();
406 }
Mathias Agopian13127d82013-03-05 17:47:11 -0800407
Mathias Agopianf3e85d42013-05-10 18:01:12 -0700408 // subtract the transparent region and snap to the bounds
409 activeCrop = reduce(activeCrop, s.activeTransparentRegion);
410
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000411 // Transform the window crop to match the buffer coordinate system,
412 // which means using the inverse of the current transform set on the
413 // SurfaceFlingerConsumer.
414 uint32_t invTransform = mCurrentTransform;
Robert Carrcae605c2017-03-29 12:10:31 -0700415 if (getTransformToDisplayInverse()) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000416 /*
Pablo Ceballos021623b2016-04-15 17:31:51 -0700417 * the code below applies the primary display's inverse transform to the
418 * buffer
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000419 */
David Sodman41fdfc92017-11-06 16:09:56 -0800420 uint32_t invTransformOrient = DisplayDevice::getPrimaryDisplayOrientationTransform();
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000421 // calculate the inverse transform
422 if (invTransformOrient & NATIVE_WINDOW_TRANSFORM_ROT_90) {
David Sodman41fdfc92017-11-06 16:09:56 -0800423 invTransformOrient ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H;
Mathias Agopian13127d82013-03-05 17:47:11 -0800424 }
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000425 // and apply to the current transform
David Sodman41fdfc92017-11-06 16:09:56 -0800426 invTransform = (Transform(invTransformOrient) * Transform(invTransform)).getOrientation();
Mathias Agopian13127d82013-03-05 17:47:11 -0800427 }
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000428
429 int winWidth = s.active.w;
430 int winHeight = s.active.h;
431 if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
432 // If the activeCrop has been rotate the ends are rotated but not
433 // the space itself so when transforming ends back we can't rely on
434 // a modification of the axes of rotation. To account for this we
435 // need to reorient the inverse rotation in terms of the current
436 // axes of rotation.
437 bool is_h_flipped = (invTransform & NATIVE_WINDOW_TRANSFORM_FLIP_H) != 0;
438 bool is_v_flipped = (invTransform & NATIVE_WINDOW_TRANSFORM_FLIP_V) != 0;
439 if (is_h_flipped == is_v_flipped) {
David Sodman41fdfc92017-11-06 16:09:56 -0800440 invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H;
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000441 }
442 winWidth = s.active.h;
443 winHeight = s.active.w;
444 }
David Sodman41fdfc92017-11-06 16:09:56 -0800445 const Rect winCrop = activeCrop.transform(invTransform, s.active.w, s.active.h);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000446
447 // below, crop is intersected with winCrop expressed in crop's coordinate space
David Sodman41fdfc92017-11-06 16:09:56 -0800448 float xScale = crop.getWidth() / float(winWidth);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000449 float yScale = crop.getHeight() / float(winHeight);
450
David Sodman41fdfc92017-11-06 16:09:56 -0800451 float insetL = winCrop.left * xScale;
452 float insetT = winCrop.top * yScale;
453 float insetR = (winWidth - winCrop.right) * xScale;
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000454 float insetB = (winHeight - winCrop.bottom) * yScale;
455
David Sodman41fdfc92017-11-06 16:09:56 -0800456 crop.left += insetL;
457 crop.top += insetT;
458 crop.right -= insetR;
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000459 crop.bottom -= insetB;
460
Mathias Agopian13127d82013-03-05 17:47:11 -0800461 return crop;
462}
463
Robert Carrae060832016-11-28 10:51:00 -0800464void Layer::setGeometry(const sp<const DisplayDevice>& displayDevice, uint32_t z)
Mathias Agopiana350ff92010-08-10 17:14:02 -0700465{
Dan Stoza9e56aa02015-11-02 13:00:03 -0800466 const auto hwcId = displayDevice->getHwcDisplayId();
David Sodman6f65f3e2017-11-03 14:28:09 -0700467 auto& hwcInfo = getBE().mHwcLayers[hwcId];
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700468
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700469 // enable this layer
Dan Stoza9e56aa02015-11-02 13:00:03 -0800470 hwcInfo.forceClientComposition = false;
471
472 if (isSecure() && !displayDevice->isSecure()) {
473 hwcInfo.forceClientComposition = true;
474 }
475
476 auto& hwcLayer = hwcInfo.layer;
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700477
Mathias Agopian13127d82013-03-05 17:47:11 -0800478 // this gives us only the "orientation" component of the transform
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700479 const State& s(getDrawingState());
David Revemanecf0fa52017-03-03 11:32:44 -0500480 auto blendMode = HWC2::BlendMode::None;
Robert Carr6452f122017-03-21 10:41:29 -0700481 if (!isOpaque(s) || getAlpha() != 1.0f) {
David Sodman41fdfc92017-11-06 16:09:56 -0800482 blendMode =
483 mPremultipliedAlpha ? HWC2::BlendMode::Premultiplied : HWC2::BlendMode::Coverage;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800484 }
David Revemanecf0fa52017-03-03 11:32:44 -0500485 auto error = hwcLayer->setBlendMode(blendMode);
David Sodman41fdfc92017-11-06 16:09:56 -0800486 ALOGE_IF(error != HWC2::Error::None,
487 "[%s] Failed to set blend mode %s:"
488 " %s (%d)",
489 mName.string(), to_string(blendMode).c_str(), to_string(error).c_str(),
490 static_cast<int32_t>(error));
Mathias Agopian13127d82013-03-05 17:47:11 -0800491
492 // apply the layer's transform, followed by the display's global transform
493 // here we're guaranteed that the layer's transform preserves rects
Michael Lentine6c925ed2014-09-26 17:55:01 -0700494 Region activeTransparentRegion(s.activeTransparentRegion);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700495 Transform t = getTransform();
Robert Carrb5d3d262016-03-25 15:08:13 -0700496 if (!s.crop.isEmpty()) {
497 Rect activeCrop(s.crop);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700498 activeCrop = t.transform(activeCrop);
David Sodman41fdfc92017-11-06 16:09:56 -0800499 if (!activeCrop.intersect(displayDevice->getViewport(), &activeCrop)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000500 activeCrop.clear();
501 }
Robert Carr1f0a16a2016-10-24 16:27:39 -0700502 activeCrop = t.inverse().transform(activeCrop, true);
Michael Lentine28ea2172014-11-19 18:32:37 -0800503 // This needs to be here as transform.transform(Rect) computes the
504 // transformed rect and then takes the bounding box of the result before
505 // returning. This means
506 // transform.inverse().transform(transform.transform(Rect)) != Rect
507 // in which case we need to make sure the final rect is clipped to the
508 // display bounds.
David Sodman41fdfc92017-11-06 16:09:56 -0800509 if (!activeCrop.intersect(Rect(s.active.w, s.active.h), &activeCrop)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000510 activeCrop.clear();
511 }
Michael Lentine6c925ed2014-09-26 17:55:01 -0700512 // mark regions outside the crop as transparent
513 activeTransparentRegion.orSelf(Rect(0, 0, s.active.w, activeCrop.top));
David Sodman41fdfc92017-11-06 16:09:56 -0800514 activeTransparentRegion.orSelf(Rect(0, activeCrop.bottom, s.active.w, s.active.h));
515 activeTransparentRegion.orSelf(Rect(0, activeCrop.top, activeCrop.left, activeCrop.bottom));
516 activeTransparentRegion.orSelf(
517 Rect(activeCrop.right, activeCrop.top, s.active.w, activeCrop.bottom));
Michael Lentine6c925ed2014-09-26 17:55:01 -0700518 }
Robert Carr1f0a16a2016-10-24 16:27:39 -0700519
520 Rect frame(t.transform(computeBounds(activeTransparentRegion)));
Robert Carrb5d3d262016-03-25 15:08:13 -0700521 if (!s.finalCrop.isEmpty()) {
David Sodman41fdfc92017-11-06 16:09:56 -0800522 if (!frame.intersect(s.finalCrop, &frame)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000523 frame.clear();
524 }
525 }
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000526 if (!frame.intersect(displayDevice->getViewport(), &frame)) {
527 frame.clear();
528 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800529 const Transform& tr(displayDevice->getTransform());
530 Rect transformedFrame = tr.transform(frame);
David Revemanecf0fa52017-03-03 11:32:44 -0500531 error = hwcLayer->setDisplayFrame(transformedFrame);
Dan Stozae22aec72016-08-01 13:20:59 -0700532 if (error != HWC2::Error::None) {
David Sodman41fdfc92017-11-06 16:09:56 -0800533 ALOGE("[%s] Failed to set display frame [%d, %d, %d, %d]: %s (%d)", mName.string(),
534 transformedFrame.left, transformedFrame.top, transformedFrame.right,
535 transformedFrame.bottom, to_string(error).c_str(), static_cast<int32_t>(error));
Dan Stozae22aec72016-08-01 13:20:59 -0700536 } else {
537 hwcInfo.displayFrame = transformedFrame;
538 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800539
Dan Stoza5a423ea2017-02-16 14:10:39 -0800540 FloatRect sourceCrop = computeCrop(displayDevice);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800541 error = hwcLayer->setSourceCrop(sourceCrop);
Dan Stozae22aec72016-08-01 13:20:59 -0700542 if (error != HWC2::Error::None) {
543 ALOGE("[%s] Failed to set source crop [%.3f, %.3f, %.3f, %.3f]: "
David Sodman41fdfc92017-11-06 16:09:56 -0800544 "%s (%d)",
545 mName.string(), sourceCrop.left, sourceCrop.top, sourceCrop.right, sourceCrop.bottom,
546 to_string(error).c_str(), static_cast<int32_t>(error));
Dan Stozae22aec72016-08-01 13:20:59 -0700547 } else {
548 hwcInfo.sourceCrop = sourceCrop;
549 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800550
chaviw13fdc492017-06-27 12:40:18 -0700551 float alpha = static_cast<float>(getAlpha());
Robert Carr6452f122017-03-21 10:41:29 -0700552 error = hwcLayer->setPlaneAlpha(alpha);
David Sodman41fdfc92017-11-06 16:09:56 -0800553 ALOGE_IF(error != HWC2::Error::None,
554 "[%s] Failed to set plane alpha %.3f: "
555 "%s (%d)",
556 mName.string(), alpha, to_string(error).c_str(), static_cast<int32_t>(error));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800557
Robert Carrae060832016-11-28 10:51:00 -0800558 error = hwcLayer->setZOrder(z);
David Sodman41fdfc92017-11-06 16:09:56 -0800559 ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set Z %u: %s (%d)", mName.string(), z,
560 to_string(error).c_str(), static_cast<int32_t>(error));
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -0500561
Albert Chaulk2a589632017-05-04 16:59:44 -0400562 int type = s.type;
563 int appId = s.appId;
Chia-I Wue41dbe62017-06-13 14:10:56 -0700564 sp<Layer> parent = mDrawingParent.promote();
Albert Chaulk2a589632017-05-04 16:59:44 -0400565 if (parent.get()) {
566 auto& parentState = parent->getDrawingState();
567 type = parentState.type;
568 appId = parentState.appId;
569 }
570
571 error = hwcLayer->setInfo(type, appId);
David Sodman41fdfc92017-11-06 16:09:56 -0800572 ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set info (%d)", mName.string(),
573 static_cast<int32_t>(error));
Mathias Agopian9f8386e2013-01-29 18:56:42 -0800574
Mathias Agopian29a367b2011-07-12 14:51:45 -0700575 /*
576 * Transformations are applied in this order:
577 * 1) buffer orientation/flip/mirror
578 * 2) state transformation (window manager)
579 * 3) layer orientation (screen orientation)
580 * (NOTE: the matrices are multiplied in reverse order)
581 */
582
583 const Transform bufferOrientation(mCurrentTransform);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700584 Transform transform(tr * t * bufferOrientation);
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700585
Robert Carrcae605c2017-03-29 12:10:31 -0700586 if (getTransformToDisplayInverse()) {
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700587 /*
Pablo Ceballos021623b2016-04-15 17:31:51 -0700588 * the code below applies the primary display's inverse transform to the
589 * buffer
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700590 */
David Sodman41fdfc92017-11-06 16:09:56 -0800591 uint32_t invTransform = DisplayDevice::getPrimaryDisplayOrientationTransform();
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700592 // calculate the inverse transform
593 if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
David Sodman41fdfc92017-11-06 16:09:56 -0800594 invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700595 }
Robert Carrcae605c2017-03-29 12:10:31 -0700596
597 /*
598 * Here we cancel out the orientation component of the WM transform.
599 * The scaling and translate components are already included in our bounds
600 * computation so it's enough to just omit it in the composition.
601 * See comment in onDraw with ref to b/36727915 for why.
602 */
603 transform = Transform(invTransform) * tr * bufferOrientation;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700604 }
Mathias Agopian29a367b2011-07-12 14:51:45 -0700605
606 // this gives us only the "orientation" component of the transform
Mathias Agopian13127d82013-03-05 17:47:11 -0800607 const uint32_t orientation = transform.getOrientation();
Dan Stoza9e56aa02015-11-02 13:00:03 -0800608 if (orientation & Transform::ROT_INVALID) {
609 // we can only handle simple transformation
610 hwcInfo.forceClientComposition = true;
611 } else {
612 auto transform = static_cast<HWC2::Transform>(orientation);
613 auto error = hwcLayer->setTransform(transform);
David Sodman41fdfc92017-11-06 16:09:56 -0800614 ALOGE_IF(error != HWC2::Error::None,
615 "[%s] Failed to set transform %s: "
616 "%s (%d)",
617 mName.string(), to_string(transform).c_str(), to_string(error).c_str(),
618 static_cast<int32_t>(error));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800619 }
Mathias Agopiana350ff92010-08-10 17:14:02 -0700620}
621
Dan Stoza9e56aa02015-11-02 13:00:03 -0800622void Layer::forceClientComposition(int32_t hwcId) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700623 if (getBE().mHwcLayers.count(hwcId) == 0) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800624 ALOGE("forceClientComposition: no HWC layer found (%d)", hwcId);
625 return;
626 }
627
David Sodman6f65f3e2017-11-03 14:28:09 -0700628 getBE().mHwcLayers[hwcId].forceClientComposition = true;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800629}
Dan Stozaee44edd2015-03-23 15:50:23 -0700630
chaviwc9232ed2017-11-14 15:31:15 -0800631bool Layer::getForceClientComposition(int32_t hwcId) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700632 if (getBE().mHwcLayers.count(hwcId) == 0) {
chaviwc9232ed2017-11-14 15:31:15 -0800633 ALOGE("getForceClientComposition: no HWC layer found (%d)", hwcId);
634 return false;
635 }
636
David Sodman6f65f3e2017-11-03 14:28:09 -0700637 return getBE().mHwcLayers[hwcId].forceClientComposition;
chaviwc9232ed2017-11-14 15:31:15 -0800638}
639
Dan Stoza9e56aa02015-11-02 13:00:03 -0800640void Layer::updateCursorPosition(const sp<const DisplayDevice>& displayDevice) {
641 auto hwcId = displayDevice->getHwcDisplayId();
David Sodman6f65f3e2017-11-03 14:28:09 -0700642 if (getBE().mHwcLayers.count(hwcId) == 0 ||
David Sodman9eeae692017-11-02 10:53:32 -0700643 getCompositionType(hwcId) != HWC2::Composition::Cursor) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800644 return;
645 }
646
647 // This gives us only the "orientation" component of the transform
648 const State& s(getCurrentState());
649
650 // Apply the layer's transform, followed by the display's global transform
651 // Here we're guaranteed that the layer's transform preserves rects
652 Rect win(s.active.w, s.active.h);
Robert Carrb5d3d262016-03-25 15:08:13 -0700653 if (!s.crop.isEmpty()) {
654 win.intersect(s.crop, &win);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800655 }
656 // Subtract the transparent region and snap to the bounds
657 Rect bounds = reduce(win, s.activeTransparentRegion);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700658 Rect frame(getTransform().transform(bounds));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800659 frame.intersect(displayDevice->getViewport(), &frame);
Robert Carrb5d3d262016-03-25 15:08:13 -0700660 if (!s.finalCrop.isEmpty()) {
661 frame.intersect(s.finalCrop, &frame);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000662 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800663 auto& displayTransform(displayDevice->getTransform());
664 auto position = displayTransform.transform(frame);
665
David Sodman6f65f3e2017-11-03 14:28:09 -0700666 auto error = getBE().mHwcLayers[hwcId].layer->setCursorPosition(position.left,
David Sodman9eeae692017-11-02 10:53:32 -0700667 position.top);
David Sodman41fdfc92017-11-06 16:09:56 -0800668 ALOGE_IF(error != HWC2::Error::None,
669 "[%s] Failed to set cursor position "
670 "to (%d, %d): %s (%d)",
671 mName.string(), position.left, position.top, to_string(error).c_str(),
672 static_cast<int32_t>(error));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800673}
Riley Andrews03414a12014-07-01 14:22:59 -0700674
Mathias Agopian13127d82013-03-05 17:47:11 -0800675// ---------------------------------------------------------------------------
676// drawing...
677// ---------------------------------------------------------------------------
678
chaviwa76b2712017-09-20 12:02:26 -0700679void Layer::draw(const RenderArea& renderArea, const Region& clip) const {
680 onDraw(renderArea, clip, false);
Mathias Agopian13127d82013-03-05 17:47:11 -0800681}
682
chaviwa76b2712017-09-20 12:02:26 -0700683void Layer::draw(const RenderArea& renderArea, bool useIdentityTransform) const {
684 onDraw(renderArea, Region(renderArea.getBounds()), useIdentityTransform);
Mathias Agopian13127d82013-03-05 17:47:11 -0800685}
686
chaviwa76b2712017-09-20 12:02:26 -0700687void Layer::draw(const RenderArea& renderArea) const {
688 onDraw(renderArea, Region(renderArea.getBounds()), false);
Dan Stozac7014012014-02-14 15:03:43 -0800689}
690
David Sodman41fdfc92017-11-06 16:09:56 -0800691void Layer::clearWithOpenGL(const RenderArea& renderArea, float red, float green, float blue,
692 float alpha) const {
Mathias Agopian19733a32013-08-28 18:13:56 -0700693 RenderEngine& engine(mFlinger->getRenderEngine());
David Sodman9eeae692017-11-02 10:53:32 -0700694 computeGeometry(renderArea, getBE().mMesh, false);
Mathias Agopian19733a32013-08-28 18:13:56 -0700695 engine.setupFillWithColor(red, green, blue, alpha);
David Sodman9eeae692017-11-02 10:53:32 -0700696 engine.drawMesh(getBE().mMesh);
Mathias Agopian13127d82013-03-05 17:47:11 -0800697}
698
chaviwa76b2712017-09-20 12:02:26 -0700699void Layer::clearWithOpenGL(const RenderArea& renderArea) const {
David Sodman41fdfc92017-11-06 16:09:56 -0800700 clearWithOpenGL(renderArea, 0, 0, 0, 0);
Mathias Agopian13127d82013-03-05 17:47:11 -0800701}
702
David Sodman41fdfc92017-11-06 16:09:56 -0800703void Layer::setCompositionType(int32_t hwcId, HWC2::Composition type, bool callIntoHwc) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700704 if (getBE().mHwcLayers.count(hwcId) == 0) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800705 ALOGE("setCompositionType called without a valid HWC layer");
706 return;
707 }
David Sodman6f65f3e2017-11-03 14:28:09 -0700708 auto& hwcInfo = getBE().mHwcLayers[hwcId];
Dan Stoza9e56aa02015-11-02 13:00:03 -0800709 auto& hwcLayer = hwcInfo.layer;
David Sodman41fdfc92017-11-06 16:09:56 -0800710 ALOGV("setCompositionType(%" PRIx64 ", %s, %d)", hwcLayer->getId(), to_string(type).c_str(),
711 static_cast<int>(callIntoHwc));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800712 if (hwcInfo.compositionType != type) {
713 ALOGV(" actually setting");
714 hwcInfo.compositionType = type;
715 if (callIntoHwc) {
716 auto error = hwcLayer->setCompositionType(type);
David Sodman41fdfc92017-11-06 16:09:56 -0800717 ALOGE_IF(error != HWC2::Error::None,
718 "[%s] Failed to set "
719 "composition type %s: %s (%d)",
720 mName.string(), to_string(type).c_str(), to_string(error).c_str(),
721 static_cast<int32_t>(error));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800722 }
723 }
724}
725
726HWC2::Composition Layer::getCompositionType(int32_t hwcId) const {
Dan Stozaec0f7172016-07-21 11:09:40 -0700727 if (hwcId == DisplayDevice::DISPLAY_ID_INVALID) {
728 // If we're querying the composition type for a display that does not
729 // have a HWC counterpart, then it will always be Client
730 return HWC2::Composition::Client;
731 }
David Sodman6f65f3e2017-11-03 14:28:09 -0700732 if (getBE().mHwcLayers.count(hwcId) == 0) {
Dan Stozaec0f7172016-07-21 11:09:40 -0700733 ALOGE("getCompositionType called with an invalid HWC layer");
Dan Stoza9e56aa02015-11-02 13:00:03 -0800734 return HWC2::Composition::Invalid;
735 }
David Sodman6f65f3e2017-11-03 14:28:09 -0700736 return getBE().mHwcLayers.at(hwcId).compositionType;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800737}
738
739void Layer::setClearClientTarget(int32_t hwcId, bool clear) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700740 if (getBE().mHwcLayers.count(hwcId) == 0) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800741 ALOGE("setClearClientTarget called without a valid HWC layer");
742 return;
743 }
David Sodman6f65f3e2017-11-03 14:28:09 -0700744 getBE().mHwcLayers[hwcId].clearClientTarget = clear;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800745}
746
747bool Layer::getClearClientTarget(int32_t hwcId) const {
David Sodman6f65f3e2017-11-03 14:28:09 -0700748 if (getBE().mHwcLayers.count(hwcId) == 0) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800749 ALOGE("getClearClientTarget called without a valid HWC layer");
750 return false;
751 }
David Sodman6f65f3e2017-11-03 14:28:09 -0700752 return getBE().mHwcLayers.at(hwcId).clearClientTarget;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800753}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800754
Dan Stozacac35382016-01-27 12:21:06 -0800755bool Layer::addSyncPoint(const std::shared_ptr<SyncPoint>& point) {
756 if (point->getFrameNumber() <= mCurrentFrameNumber) {
757 // Don't bother with a SyncPoint, since we've already latched the
758 // relevant frame
759 return false;
Dan Stoza7dde5992015-05-22 09:51:44 -0700760 }
761
Dan Stozacac35382016-01-27 12:21:06 -0800762 Mutex::Autolock lock(mLocalSyncPointMutex);
763 mLocalSyncPoints.push_back(point);
764 return true;
Dan Stoza7dde5992015-05-22 09:51:44 -0700765}
766
Mathias Agopian13127d82013-03-05 17:47:11 -0800767void Layer::setFiltering(bool filtering) {
768 mFiltering = filtering;
769}
770
771bool Layer::getFiltering() const {
772 return mFiltering;
773}
774
Mathias Agopian13127d82013-03-05 17:47:11 -0800775// ----------------------------------------------------------------------------
776// local state
777// ----------------------------------------------------------------------------
778
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000779static void boundPoint(vec2* point, const Rect& crop) {
780 if (point->x < crop.left) {
781 point->x = crop.left;
782 }
783 if (point->x > crop.right) {
784 point->x = crop.right;
785 }
786 if (point->y < crop.top) {
787 point->y = crop.top;
788 }
789 if (point->y > crop.bottom) {
790 point->y = crop.bottom;
791 }
792}
793
chaviwa76b2712017-09-20 12:02:26 -0700794void Layer::computeGeometry(const RenderArea& renderArea, Mesh& mesh,
795 bool useIdentityTransform) const {
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700796 const Layer::State& s(getDrawingState());
chaviwa76b2712017-09-20 12:02:26 -0700797 const Transform renderAreaTransform(renderArea.getTransform());
798 const uint32_t height = renderArea.getHeight();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700799 Rect win = computeBounds();
Mathias Agopian3f844832013-08-07 21:24:32 -0700800
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000801 vec2 lt = vec2(win.left, win.top);
802 vec2 lb = vec2(win.left, win.bottom);
803 vec2 rb = vec2(win.right, win.bottom);
804 vec2 rt = vec2(win.right, win.top);
805
Robert Carr1f0a16a2016-10-24 16:27:39 -0700806 Transform layerTransform = getTransform();
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000807 if (!useIdentityTransform) {
Robert Carr1f0a16a2016-10-24 16:27:39 -0700808 lt = layerTransform.transform(lt);
809 lb = layerTransform.transform(lb);
810 rb = layerTransform.transform(rb);
811 rt = layerTransform.transform(rt);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000812 }
813
Robert Carrb5d3d262016-03-25 15:08:13 -0700814 if (!s.finalCrop.isEmpty()) {
815 boundPoint(&lt, s.finalCrop);
816 boundPoint(&lb, s.finalCrop);
817 boundPoint(&rb, s.finalCrop);
818 boundPoint(&rt, s.finalCrop);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000819 }
820
Mathias Agopianff2ed702013-09-01 21:36:12 -0700821 Mesh::VertexArray<vec2> position(mesh.getPositionArray<vec2>());
chaviwa76b2712017-09-20 12:02:26 -0700822 position[0] = renderAreaTransform.transform(lt);
823 position[1] = renderAreaTransform.transform(lb);
824 position[2] = renderAreaTransform.transform(rb);
825 position[3] = renderAreaTransform.transform(rt);
David Sodman41fdfc92017-11-06 16:09:56 -0800826 for (size_t i = 0; i < 4; i++) {
chaviwa76b2712017-09-20 12:02:26 -0700827 position[i].y = height - position[i].y;
Mathias Agopian13127d82013-03-05 17:47:11 -0800828 }
829}
Eric Hassoldac45e6b2011-02-10 14:41:26 -0800830
David Sodman41fdfc92017-11-06 16:09:56 -0800831bool Layer::isSecure() const {
Dan Stoza23116082015-06-18 14:58:39 -0700832 const Layer::State& s(mDrawingState);
833 return (s.flags & layer_state_t::eLayerSecure);
834}
835
Mathias Agopian13127d82013-03-05 17:47:11 -0800836void Layer::setVisibleRegion(const Region& visibleRegion) {
837 // always called from main thread
838 this->visibleRegion = visibleRegion;
839}
840
841void Layer::setCoveredRegion(const Region& coveredRegion) {
842 // always called from main thread
843 this->coveredRegion = coveredRegion;
844}
845
David Sodman41fdfc92017-11-06 16:09:56 -0800846void Layer::setVisibleNonTransparentRegion(const Region& setVisibleNonTransparentRegion) {
Mathias Agopian13127d82013-03-05 17:47:11 -0800847 // always called from main thread
848 this->visibleNonTransparentRegion = setVisibleNonTransparentRegion;
849}
850
851// ----------------------------------------------------------------------------
852// transaction
853// ----------------------------------------------------------------------------
854
Dan Stoza7dde5992015-05-22 09:51:44 -0700855void Layer::pushPendingState() {
856 if (!mCurrentState.modified) {
857 return;
858 }
859
Dan Stoza7dde5992015-05-22 09:51:44 -0700860 // If this transaction is waiting on the receipt of a frame, generate a sync
861 // point and send it to the remote layer.
Robert Carr0d480722017-01-10 16:42:54 -0800862 if (mCurrentState.barrierLayer != nullptr) {
863 sp<Layer> barrierLayer = mCurrentState.barrierLayer.promote();
864 if (barrierLayer == nullptr) {
865 ALOGE("[%s] Unable to promote barrier Layer.", mName.string());
Dan Stoza7dde5992015-05-22 09:51:44 -0700866 // If we can't promote the layer we are intended to wait on,
867 // then it is expired or otherwise invalid. Allow this transaction
868 // to be applied as per normal (no synchronization).
Robert Carr0d480722017-01-10 16:42:54 -0800869 mCurrentState.barrierLayer = nullptr;
Pablo Ceballos3bddd5b2015-11-19 14:39:14 -0800870 } else {
David Sodman41fdfc92017-11-06 16:09:56 -0800871 auto syncPoint = std::make_shared<SyncPoint>(mCurrentState.frameNumber);
Robert Carr0d480722017-01-10 16:42:54 -0800872 if (barrierLayer->addSyncPoint(syncPoint)) {
Dan Stozacac35382016-01-27 12:21:06 -0800873 mRemoteSyncPoints.push_back(std::move(syncPoint));
874 } else {
875 // We already missed the frame we're supposed to synchronize
876 // on, so go ahead and apply the state update
Robert Carr0d480722017-01-10 16:42:54 -0800877 mCurrentState.barrierLayer = nullptr;
Dan Stozacac35382016-01-27 12:21:06 -0800878 }
Dan Stoza7dde5992015-05-22 09:51:44 -0700879 }
880
Dan Stoza7dde5992015-05-22 09:51:44 -0700881 // Wake us up to check if the frame has been received
882 setTransactionFlags(eTransactionNeeded);
Dan Stozaf5702ff2016-11-02 16:27:47 -0700883 mFlinger->setTransactionFlags(eTraversalNeeded);
Dan Stoza7dde5992015-05-22 09:51:44 -0700884 }
885 mPendingStates.push_back(mCurrentState);
Dan Stozaf7ba41a2017-05-10 15:11:11 -0700886 ATRACE_INT(mTransactionName.string(), mPendingStates.size());
Dan Stoza7dde5992015-05-22 09:51:44 -0700887}
888
Pablo Ceballos05289c22016-04-14 15:49:55 -0700889void Layer::popPendingState(State* stateToCommit) {
890 auto oldFlags = stateToCommit->flags;
891 *stateToCommit = mPendingStates[0];
David Sodman41fdfc92017-11-06 16:09:56 -0800892 stateToCommit->flags =
893 (oldFlags & ~stateToCommit->mask) | (stateToCommit->flags & stateToCommit->mask);
Dan Stoza7dde5992015-05-22 09:51:44 -0700894
895 mPendingStates.removeAt(0);
Dan Stozaf7ba41a2017-05-10 15:11:11 -0700896 ATRACE_INT(mTransactionName.string(), mPendingStates.size());
Dan Stoza7dde5992015-05-22 09:51:44 -0700897}
898
Pablo Ceballos05289c22016-04-14 15:49:55 -0700899bool Layer::applyPendingStates(State* stateToCommit) {
Dan Stoza7dde5992015-05-22 09:51:44 -0700900 bool stateUpdateAvailable = false;
901 while (!mPendingStates.empty()) {
Robert Carr0d480722017-01-10 16:42:54 -0800902 if (mPendingStates[0].barrierLayer != nullptr) {
Dan Stoza7dde5992015-05-22 09:51:44 -0700903 if (mRemoteSyncPoints.empty()) {
904 // If we don't have a sync point for this, apply it anyway. It
905 // will be visually wrong, but it should keep us from getting
906 // into too much trouble.
907 ALOGE("[%s] No local sync point found", mName.string());
Pablo Ceballos05289c22016-04-14 15:49:55 -0700908 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -0700909 stateUpdateAvailable = true;
910 continue;
911 }
912
David Sodman41fdfc92017-11-06 16:09:56 -0800913 if (mRemoteSyncPoints.front()->getFrameNumber() != mPendingStates[0].frameNumber) {
914 ALOGE("[%s] Unexpected sync point frame number found", mName.string());
Dan Stozacac35382016-01-27 12:21:06 -0800915
916 // Signal our end of the sync point and then dispose of it
917 mRemoteSyncPoints.front()->setTransactionApplied();
918 mRemoteSyncPoints.pop_front();
919 continue;
920 }
921
Dan Stoza7dde5992015-05-22 09:51:44 -0700922 if (mRemoteSyncPoints.front()->frameIsAvailable()) {
923 // Apply the state update
Pablo Ceballos05289c22016-04-14 15:49:55 -0700924 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -0700925 stateUpdateAvailable = true;
926
927 // Signal our end of the sync point and then dispose of it
928 mRemoteSyncPoints.front()->setTransactionApplied();
929 mRemoteSyncPoints.pop_front();
Dan Stoza792e5292016-02-11 11:43:58 -0800930 } else {
931 break;
Dan Stoza7dde5992015-05-22 09:51:44 -0700932 }
Dan Stoza7dde5992015-05-22 09:51:44 -0700933 } else {
Pablo Ceballos05289c22016-04-14 15:49:55 -0700934 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -0700935 stateUpdateAvailable = true;
936 }
937 }
938
939 // If we still have pending updates, wake SurfaceFlinger back up and point
940 // it at this layer so we can process them
941 if (!mPendingStates.empty()) {
942 setTransactionFlags(eTransactionNeeded);
943 mFlinger->setTransactionFlags(eTraversalNeeded);
944 }
945
946 mCurrentState.modified = false;
947 return stateUpdateAvailable;
948}
949
Mathias Agopian13127d82013-03-05 17:47:11 -0800950uint32_t Layer::doTransaction(uint32_t flags) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800951 ATRACE_CALL();
952
Dan Stoza7dde5992015-05-22 09:51:44 -0700953 pushPendingState();
Pablo Ceballos05289c22016-04-14 15:49:55 -0700954 Layer::State c = getCurrentState();
955 if (!applyPendingStates(&c)) {
Dan Stoza7dde5992015-05-22 09:51:44 -0700956 return 0;
957 }
958
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700959 const Layer::State& s(getDrawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800960
David Sodman41fdfc92017-11-06 16:09:56 -0800961 const bool sizeChanged = (c.requested.w != s.requested.w) || (c.requested.h != s.requested.h);
Mathias Agopiana138f892010-05-21 17:24:35 -0700962
David Sodmaneb085e02017-10-05 18:49:04 -0700963 if (sizeChanged) {
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700964 // the size changed, we need to ask our client to request a new buffer
Steve Block9d453682011-12-20 16:23:08 +0000965 ALOGD_IF(DEBUG_RESIZE,
David Sodman41fdfc92017-11-06 16:09:56 -0800966 "doTransaction: geometry (layer=%p '%s'), tr=%02x, scalingMode=%d\n"
967 " current={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
968 " requested={ wh={%4u,%4u} }}\n"
969 " drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
970 " requested={ wh={%4u,%4u} }}\n",
David Sodman9eeae692017-11-02 10:53:32 -0700971 this, getName().string(), mCurrentTransform,
972 getEffectiveScalingMode(), c.active.w, c.active.h, c.crop.left, c.crop.top,
973 c.crop.right, c.crop.bottom, c.crop.getWidth(), c.crop.getHeight(), c.requested.w,
974 c.requested.h, s.active.w, s.active.h, s.crop.left, s.crop.top, s.crop.right,
975 s.crop.bottom, s.crop.getWidth(), s.crop.getHeight(), s.requested.w,
976 s.requested.h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800977
Jamie Gennis2a0d5b62011-09-26 16:54:44 -0700978 // record the new size, form this point on, when the client request
979 // a buffer, it'll get the new size.
David Sodmaneb085e02017-10-05 18:49:04 -0700980 setDefaultBufferSize(c.requested.w, c.requested.h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800981 }
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700982
Robert Carre392b552017-09-19 12:16:05 -0700983 // Don't let Layer::doTransaction update the drawing state
984 // if we have a pending resize, unless we are in fixed-size mode.
985 // the drawing state will be updated only once we receive a buffer
986 // with the correct size.
987 //
988 // In particular, we want to make sure the clip (which is part
989 // of the geometry state) is latched together with the size but is
990 // latched immediately when no resizing is involved.
991 //
992 // If a sideband stream is attached, however, we want to skip this
993 // optimization so that transactions aren't missed when a buffer
994 // never arrives
995 //
996 // In the case that we don't have a buffer we ignore other factors
997 // and avoid entering the resizePending state. At a high level the
998 // resizePending state is to avoid applying the state of the new buffer
999 // to the old buffer. However in the state where we don't have an old buffer
1000 // there is no such concern but we may still be being used as a parent layer.
David Sodman41fdfc92017-11-06 16:09:56 -08001001 const bool resizePending = ((c.requested.w != c.active.w) || (c.requested.h != c.active.h)) &&
David Sodman0cc69182017-11-17 12:12:07 -08001002 (getBE().compositionInfo.mBuffer != nullptr);
Mathias Agopian0cd545f2012-06-07 14:18:55 -07001003 if (!isFixedSize()) {
David Sodman0cc69182017-11-17 12:12:07 -08001004 if (resizePending && getBE().compositionInfo.hwc.sidebandStream == nullptr) {
Mathias Agopian0cd545f2012-06-07 14:18:55 -07001005 flags |= eDontUpdateGeometryState;
1006 }
1007 }
1008
Robert Carr7bf247e2017-05-18 14:02:49 -07001009 // Here we apply various requested geometry states, depending on our
1010 // latching configuration. See Layer.h for a detailed discussion of
1011 // how geometry latching is controlled.
1012 if (!(flags & eDontUpdateGeometryState)) {
Pablo Ceballos7d052572016-06-02 17:46:05 -07001013 Layer::State& editCurrentState(getCurrentState());
Robert Carr7bf247e2017-05-18 14:02:49 -07001014
1015 // If mFreezeGeometryUpdates is true we are in the setGeometryAppliesWithResize
1016 // mode, which causes attributes which normally latch regardless of scaling mode,
1017 // to be delayed. We copy the requested state to the active state making sure
1018 // to respect these rules (again see Layer.h for a detailed discussion).
1019 //
1020 // There is an awkward asymmetry in the handling of the crop states in the position
1021 // states, as can be seen below. Largely this arises from position and transform
1022 // being stored in the same data structure while having different latching rules.
1023 // b/38182305
1024 //
1025 // Careful that "c" and editCurrentState may not begin as equivalent due to
1026 // applyPendingStates in the presence of deferred transactions.
1027 if (mFreezeGeometryUpdates) {
Robert Carr82364e32016-05-15 11:27:47 -07001028 float tx = c.active.transform.tx();
1029 float ty = c.active.transform.ty();
1030 c.active = c.requested;
1031 c.active.transform.set(tx, ty);
1032 editCurrentState.active = c.active;
1033 } else {
1034 editCurrentState.active = editCurrentState.requested;
1035 c.active = c.requested;
1036 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001037 }
1038
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001039 if (s.active != c.active) {
Mathias Agopian13127d82013-03-05 17:47:11 -08001040 // invalidate and recompute the visible regions if needed
1041 flags |= Layer::eVisibleRegion;
1042 }
1043
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001044 if (c.sequence != s.sequence) {
Mathias Agopian13127d82013-03-05 17:47:11 -08001045 // invalidate and recompute the visible regions if needed
1046 flags |= eVisibleRegion;
1047 this->contentDirty = true;
1048
1049 // we may use linear filtering, if the matrix scales us
Robert Carr3dcabfa2016-03-01 18:36:58 -08001050 const uint8_t type = c.active.transform.getType();
David Sodman41fdfc92017-11-06 16:09:56 -08001051 mNeedsFiltering = (!c.active.transform.preserveRects() || (type >= Transform::SCALE));
Mathias Agopian13127d82013-03-05 17:47:11 -08001052 }
1053
Dan Stozac8145172016-04-28 16:29:06 -07001054 // If the layer is hidden, signal and clear out all local sync points so
1055 // that transactions for layers depending on this layer's frames becoming
1056 // visible are not blocked
1057 if (c.flags & layer_state_t::eLayerHidden) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001058 clearSyncPoints();
Dan Stozac8145172016-04-28 16:29:06 -07001059 }
1060
Mathias Agopian13127d82013-03-05 17:47:11 -08001061 // Commit the transaction
Pablo Ceballos05289c22016-04-14 15:49:55 -07001062 commitTransaction(c);
Mathias Agopian13127d82013-03-05 17:47:11 -08001063 return flags;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001064}
1065
Pablo Ceballos05289c22016-04-14 15:49:55 -07001066void Layer::commitTransaction(const State& stateToCommit) {
1067 mDrawingState = stateToCommit;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001068}
1069
Mathias Agopian13127d82013-03-05 17:47:11 -08001070uint32_t Layer::getTransactionFlags(uint32_t flags) {
1071 return android_atomic_and(~flags, &mTransactionFlags) & flags;
1072}
1073
1074uint32_t Layer::setTransactionFlags(uint32_t flags) {
1075 return android_atomic_or(flags, &mTransactionFlags);
1076}
1077
Robert Carr82364e32016-05-15 11:27:47 -07001078bool Layer::setPosition(float x, float y, bool immediate) {
Robert Carr3dcabfa2016-03-01 18:36:58 -08001079 if (mCurrentState.requested.transform.tx() == x && mCurrentState.requested.transform.ty() == y)
Mathias Agopian13127d82013-03-05 17:47:11 -08001080 return false;
1081 mCurrentState.sequence++;
Robert Carr69663fb2016-03-27 19:59:19 -07001082
1083 // We update the requested and active position simultaneously because
1084 // we want to apply the position portion of the transform matrix immediately,
1085 // but still delay scaling when resizing a SCALING_MODE_FREEZE layer.
Robert Carr3dcabfa2016-03-01 18:36:58 -08001086 mCurrentState.requested.transform.set(x, y);
Robert Carr7bf247e2017-05-18 14:02:49 -07001087 if (immediate && !mFreezeGeometryUpdates) {
1088 // Here we directly update the active state
1089 // unlike other setters, because we store it within
1090 // the transform, but use different latching rules.
1091 // b/38182305
Robert Carr82364e32016-05-15 11:27:47 -07001092 mCurrentState.active.transform.set(x, y);
1093 }
Robert Carr7bf247e2017-05-18 14:02:49 -07001094 mFreezeGeometryUpdates = mFreezeGeometryUpdates || !immediate;
Robert Carr69663fb2016-03-27 19:59:19 -07001095
Dan Stoza7dde5992015-05-22 09:51:44 -07001096 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001097 setTransactionFlags(eTransactionNeeded);
1098 return true;
1099}
Robert Carr82364e32016-05-15 11:27:47 -07001100
Robert Carr1f0a16a2016-10-24 16:27:39 -07001101bool Layer::setChildLayer(const sp<Layer>& childLayer, int32_t z) {
1102 ssize_t idx = mCurrentChildren.indexOf(childLayer);
1103 if (idx < 0) {
1104 return false;
1105 }
1106 if (childLayer->setLayer(z)) {
1107 mCurrentChildren.removeAt(idx);
1108 mCurrentChildren.add(childLayer);
1109 }
1110 return true;
1111}
1112
Robert Carr503c7042017-09-27 15:06:08 -07001113bool Layer::setChildRelativeLayer(const sp<Layer>& childLayer,
1114 const sp<IBinder>& relativeToHandle, int32_t relativeZ) {
1115 ssize_t idx = mCurrentChildren.indexOf(childLayer);
1116 if (idx < 0) {
1117 return false;
1118 }
1119 if (childLayer->setRelativeLayer(relativeToHandle, relativeZ)) {
1120 mCurrentChildren.removeAt(idx);
1121 mCurrentChildren.add(childLayer);
1122 }
1123 return true;
1124}
1125
Robert Carrae060832016-11-28 10:51:00 -08001126bool Layer::setLayer(int32_t z) {
David Sodman41fdfc92017-11-06 16:09:56 -08001127 if (mCurrentState.z == z) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001128 mCurrentState.sequence++;
1129 mCurrentState.z = z;
Dan Stoza7dde5992015-05-22 09:51:44 -07001130 mCurrentState.modified = true;
Robert Carrdb66e622017-04-10 16:55:57 -07001131
1132 // Discard all relative layering.
1133 if (mCurrentState.zOrderRelativeOf != nullptr) {
1134 sp<Layer> strongRelative = mCurrentState.zOrderRelativeOf.promote();
1135 if (strongRelative != nullptr) {
1136 strongRelative->removeZOrderRelative(this);
1137 }
1138 mCurrentState.zOrderRelativeOf = nullptr;
1139 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001140 setTransactionFlags(eTransactionNeeded);
1141 return true;
1142}
Robert Carr1f0a16a2016-10-24 16:27:39 -07001143
Robert Carrdb66e622017-04-10 16:55:57 -07001144void Layer::removeZOrderRelative(const wp<Layer>& relative) {
1145 mCurrentState.zOrderRelatives.remove(relative);
1146 mCurrentState.sequence++;
1147 mCurrentState.modified = true;
1148 setTransactionFlags(eTransactionNeeded);
1149}
1150
1151void Layer::addZOrderRelative(const wp<Layer>& relative) {
1152 mCurrentState.zOrderRelatives.add(relative);
1153 mCurrentState.modified = true;
1154 mCurrentState.sequence++;
1155 setTransactionFlags(eTransactionNeeded);
1156}
1157
1158bool Layer::setRelativeLayer(const sp<IBinder>& relativeToHandle, int32_t z) {
1159 sp<Handle> handle = static_cast<Handle*>(relativeToHandle.get());
1160 if (handle == nullptr) {
1161 return false;
1162 }
1163 sp<Layer> relative = handle->owner.promote();
1164 if (relative == nullptr) {
1165 return false;
1166 }
1167
1168 mCurrentState.sequence++;
1169 mCurrentState.modified = true;
1170 mCurrentState.z = z;
1171
chaviw9ab4bd12017-11-03 13:11:00 -07001172 auto oldZOrderRelativeOf = mCurrentState.zOrderRelativeOf.promote();
1173 if (oldZOrderRelativeOf != nullptr) {
1174 oldZOrderRelativeOf->removeZOrderRelative(this);
1175 }
Robert Carrdb66e622017-04-10 16:55:57 -07001176 mCurrentState.zOrderRelativeOf = relative;
1177 relative->addZOrderRelative(this);
1178
1179 setTransactionFlags(eTransactionNeeded);
1180
1181 return true;
1182}
1183
Mathias Agopian13127d82013-03-05 17:47:11 -08001184bool Layer::setSize(uint32_t w, uint32_t h) {
David Sodman41fdfc92017-11-06 16:09:56 -08001185 if (mCurrentState.requested.w == w && mCurrentState.requested.h == h) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001186 mCurrentState.requested.w = w;
1187 mCurrentState.requested.h = h;
Dan Stoza7dde5992015-05-22 09:51:44 -07001188 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001189 setTransactionFlags(eTransactionNeeded);
1190 return true;
1191}
Dan Stoza9e56aa02015-11-02 13:00:03 -08001192bool Layer::setAlpha(float alpha) {
David Sodman41fdfc92017-11-06 16:09:56 -08001193 if (mCurrentState.color.a == alpha) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001194 mCurrentState.sequence++;
chaviw13fdc492017-06-27 12:40:18 -07001195 mCurrentState.color.a = alpha;
Dan Stoza7dde5992015-05-22 09:51:44 -07001196 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001197 setTransactionFlags(eTransactionNeeded);
1198 return true;
1199}
chaviw13fdc492017-06-27 12:40:18 -07001200
1201bool Layer::setColor(const half3& color) {
David Sodman41fdfc92017-11-06 16:09:56 -08001202 if (color.r == mCurrentState.color.r && color.g == mCurrentState.color.g &&
1203 color.b == mCurrentState.color.b)
chaviw13fdc492017-06-27 12:40:18 -07001204 return false;
1205
1206 mCurrentState.sequence++;
1207 mCurrentState.color.r = color.r;
1208 mCurrentState.color.g = color.g;
1209 mCurrentState.color.b = color.b;
1210 mCurrentState.modified = true;
1211 setTransactionFlags(eTransactionNeeded);
1212 return true;
1213}
1214
Mathias Agopian13127d82013-03-05 17:47:11 -08001215bool Layer::setMatrix(const layer_state_t::matrix22_t& matrix) {
1216 mCurrentState.sequence++;
David Sodman41fdfc92017-11-06 16:09:56 -08001217 mCurrentState.requested.transform.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
Dan Stoza7dde5992015-05-22 09:51:44 -07001218 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001219 setTransactionFlags(eTransactionNeeded);
1220 return true;
1221}
1222bool Layer::setTransparentRegionHint(const Region& transparent) {
Mathias Agopian2ca79392013-04-02 18:30:32 -07001223 mCurrentState.requestedTransparentRegion = transparent;
Dan Stoza7dde5992015-05-22 09:51:44 -07001224 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001225 setTransactionFlags(eTransactionNeeded);
1226 return true;
1227}
1228bool Layer::setFlags(uint8_t flags, uint8_t mask) {
1229 const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask);
David Sodman41fdfc92017-11-06 16:09:56 -08001230 if (mCurrentState.flags == newFlags) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001231 mCurrentState.sequence++;
1232 mCurrentState.flags = newFlags;
Dan Stoza7dde5992015-05-22 09:51:44 -07001233 mCurrentState.mask = mask;
1234 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001235 setTransactionFlags(eTransactionNeeded);
1236 return true;
1237}
Robert Carr99e27f02016-06-16 15:18:02 -07001238
1239bool Layer::setCrop(const Rect& crop, bool immediate) {
David Sodman41fdfc92017-11-06 16:09:56 -08001240 if (mCurrentState.requestedCrop == crop) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001241 mCurrentState.sequence++;
Robert Carr99e27f02016-06-16 15:18:02 -07001242 mCurrentState.requestedCrop = crop;
Robert Carr7bf247e2017-05-18 14:02:49 -07001243 if (immediate && !mFreezeGeometryUpdates) {
Robert Carr99e27f02016-06-16 15:18:02 -07001244 mCurrentState.crop = crop;
1245 }
Robert Carr7bf247e2017-05-18 14:02:49 -07001246 mFreezeGeometryUpdates = mFreezeGeometryUpdates || !immediate;
1247
Dan Stoza7dde5992015-05-22 09:51:44 -07001248 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001249 setTransactionFlags(eTransactionNeeded);
1250 return true;
1251}
Robert Carr8d5227b2017-03-16 15:41:03 -07001252
1253bool Layer::setFinalCrop(const Rect& crop, bool immediate) {
David Sodman41fdfc92017-11-06 16:09:56 -08001254 if (mCurrentState.requestedFinalCrop == crop) return false;
Pablo Ceballosacbe6782016-03-04 17:54:21 +00001255 mCurrentState.sequence++;
Robert Carr8d5227b2017-03-16 15:41:03 -07001256 mCurrentState.requestedFinalCrop = crop;
Robert Carr7bf247e2017-05-18 14:02:49 -07001257 if (immediate && !mFreezeGeometryUpdates) {
Robert Carr8d5227b2017-03-16 15:41:03 -07001258 mCurrentState.finalCrop = crop;
1259 }
Robert Carr7bf247e2017-05-18 14:02:49 -07001260 mFreezeGeometryUpdates = mFreezeGeometryUpdates || !immediate;
1261
Pablo Ceballosacbe6782016-03-04 17:54:21 +00001262 mCurrentState.modified = true;
1263 setTransactionFlags(eTransactionNeeded);
1264 return true;
1265}
Mathias Agopian13127d82013-03-05 17:47:11 -08001266
Robert Carrc3574f72016-03-24 12:19:32 -07001267bool Layer::setOverrideScalingMode(int32_t scalingMode) {
David Sodman41fdfc92017-11-06 16:09:56 -08001268 if (scalingMode == mOverrideScalingMode) return false;
Robert Carrc3574f72016-03-24 12:19:32 -07001269 mOverrideScalingMode = scalingMode;
Robert Carr82364e32016-05-15 11:27:47 -07001270 setTransactionFlags(eTransactionNeeded);
Robert Carrc3574f72016-03-24 12:19:32 -07001271 return true;
1272}
1273
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -05001274void Layer::setInfo(uint32_t type, uint32_t appId) {
David Sodman41fdfc92017-11-06 16:09:56 -08001275 mCurrentState.appId = appId;
1276 mCurrentState.type = type;
1277 mCurrentState.modified = true;
1278 setTransactionFlags(eTransactionNeeded);
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -05001279}
1280
Mathias Agopian13127d82013-03-05 17:47:11 -08001281bool Layer::setLayerStack(uint32_t layerStack) {
David Sodman41fdfc92017-11-06 16:09:56 -08001282 if (mCurrentState.layerStack == layerStack) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001283 mCurrentState.sequence++;
1284 mCurrentState.layerStack = layerStack;
Dan Stoza7dde5992015-05-22 09:51:44 -07001285 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001286 setTransactionFlags(eTransactionNeeded);
1287 return true;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001288}
1289
Courtney Goeltzenleuchterbb09b432016-11-30 13:51:28 -07001290bool Layer::setDataSpace(android_dataspace dataSpace) {
David Sodman41fdfc92017-11-06 16:09:56 -08001291 if (mCurrentState.dataSpace == dataSpace) return false;
Courtney Goeltzenleuchterbb09b432016-11-30 13:51:28 -07001292 mCurrentState.sequence++;
1293 mCurrentState.dataSpace = dataSpace;
1294 mCurrentState.modified = true;
1295 setTransactionFlags(eTransactionNeeded);
1296 return true;
1297}
1298
Courtney Goeltzenleuchter532b2632017-05-05 16:34:38 -06001299android_dataspace Layer::getDataSpace() const {
1300 return mCurrentState.dataSpace;
1301}
1302
Robert Carr1f0a16a2016-10-24 16:27:39 -07001303uint32_t Layer::getLayerStack() const {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001304 auto p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001305 if (p == nullptr) {
1306 return getDrawingState().layerStack;
1307 }
1308 return p->getLayerStack();
1309}
1310
David Sodman41fdfc92017-11-06 16:09:56 -08001311void Layer::deferTransactionUntil(const sp<Layer>& barrierLayer, uint64_t frameNumber) {
Robert Carr0d480722017-01-10 16:42:54 -08001312 mCurrentState.barrierLayer = barrierLayer;
Dan Stoza7dde5992015-05-22 09:51:44 -07001313 mCurrentState.frameNumber = frameNumber;
1314 // We don't set eTransactionNeeded, because just receiving a deferral
1315 // request without any other state updates shouldn't actually induce a delay
1316 mCurrentState.modified = true;
1317 pushPendingState();
Robert Carr0d480722017-01-10 16:42:54 -08001318 mCurrentState.barrierLayer = nullptr;
Dan Stoza792e5292016-02-11 11:43:58 -08001319 mCurrentState.frameNumber = 0;
Dan Stoza7dde5992015-05-22 09:51:44 -07001320 mCurrentState.modified = false;
Robert Carr0d480722017-01-10 16:42:54 -08001321}
1322
David Sodman41fdfc92017-11-06 16:09:56 -08001323void Layer::deferTransactionUntil(const sp<IBinder>& barrierHandle, uint64_t frameNumber) {
Robert Carr0d480722017-01-10 16:42:54 -08001324 sp<Handle> handle = static_cast<Handle*>(barrierHandle.get());
1325 deferTransactionUntil(handle->owner.promote(), frameNumber);
Dan Stoza7dde5992015-05-22 09:51:44 -07001326}
1327
Dan Stozaee44edd2015-03-23 15:50:23 -07001328
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001329// ----------------------------------------------------------------------------
1330// pageflip handling...
1331// ----------------------------------------------------------------------------
1332
Robert Carr1f0a16a2016-10-24 16:27:39 -07001333bool Layer::isHiddenByPolicy() const {
1334 const Layer::State& s(mDrawingState);
Chia-I Wue41dbe62017-06-13 14:10:56 -07001335 const auto& parent = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001336 if (parent != nullptr && parent->isHiddenByPolicy()) {
1337 return true;
1338 }
1339 return s.flags & layer_state_t::eLayerHidden;
1340}
1341
David Sodman41fdfc92017-11-06 16:09:56 -08001342uint32_t Layer::getEffectiveUsage(uint32_t usage) const {
Mathias Agopiana67932f2011-04-20 14:20:59 -07001343 // TODO: should we do something special if mSecure is set?
1344 if (mProtectedByApp) {
1345 // need a hardware-protected path to external video sink
1346 usage |= GraphicBuffer::USAGE_PROTECTED;
Jamie Gennis54cc83e2010-11-02 11:51:32 -07001347 }
Riley Andrews03414a12014-07-01 14:22:59 -07001348 if (mPotentialCursor) {
1349 usage |= GraphicBuffer::USAGE_CURSOR;
1350 }
Jamie Gennis3599bf22011-08-10 11:48:07 -07001351 usage |= GraphicBuffer::USAGE_HW_COMPOSER;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001352 return usage;
Mathias Agopianb5b7f262010-05-07 15:58:44 -07001353}
1354
Mathias Agopian84300952012-11-21 16:02:13 -08001355void Layer::updateTransformHint(const sp<const DisplayDevice>& hw) const {
Mathias Agopiana4583642011-08-23 18:03:18 -07001356 uint32_t orientation = 0;
1357 if (!mFlinger->mDebugDisableTransformHint) {
Mathias Agopian84300952012-11-21 16:02:13 -08001358 // The transform hint is used to improve performance, but we can
1359 // only have a single transform hint, it cannot
Mathias Agopian4fec8732012-06-29 14:12:52 -07001360 // apply to all displays.
Mathias Agopian42977342012-08-05 00:40:46 -07001361 const Transform& planeTransform(hw->getTransform());
Mathias Agopian4fec8732012-06-29 14:12:52 -07001362 orientation = planeTransform.getOrientation();
Mathias Agopiana4583642011-08-23 18:03:18 -07001363 if (orientation & Transform::ROT_INVALID) {
1364 orientation = 0;
1365 }
1366 }
David Sodmaneb085e02017-10-05 18:49:04 -07001367 setTransformHint(orientation);
Mathias Agopiana4583642011-08-23 18:03:18 -07001368}
1369
Mathias Agopian13127d82013-03-05 17:47:11 -08001370// ----------------------------------------------------------------------------
1371// debugging
1372// ----------------------------------------------------------------------------
1373
Kalle Raitaa099a242017-01-11 11:17:29 -08001374LayerDebugInfo Layer::getLayerDebugInfo() const {
1375 LayerDebugInfo info;
1376 const Layer::State& ds = getDrawingState();
1377 info.mName = getName();
chaviw1acbec72017-07-27 15:28:26 -07001378 sp<Layer> parent = getParent();
Kalle Raitaa099a242017-01-11 11:17:29 -08001379 info.mParentName = (parent == nullptr ? std::string("none") : parent->getName().string());
1380 info.mType = String8(getTypeId());
1381 info.mTransparentRegion = ds.activeTransparentRegion;
1382 info.mVisibleRegion = visibleRegion;
1383 info.mSurfaceDamageRegion = surfaceDamageRegion;
1384 info.mLayerStack = getLayerStack();
1385 info.mX = ds.active.transform.tx();
1386 info.mY = ds.active.transform.ty();
1387 info.mZ = ds.z;
1388 info.mWidth = ds.active.w;
1389 info.mHeight = ds.active.h;
1390 info.mCrop = ds.crop;
1391 info.mFinalCrop = ds.finalCrop;
chaviw13fdc492017-06-27 12:40:18 -07001392 info.mColor = ds.color;
Kalle Raitaa099a242017-01-11 11:17:29 -08001393 info.mFlags = ds.flags;
1394 info.mPixelFormat = getPixelFormat();
1395 info.mDataSpace = getDataSpace();
1396 info.mMatrix[0][0] = ds.active.transform[0][0];
1397 info.mMatrix[0][1] = ds.active.transform[0][1];
1398 info.mMatrix[1][0] = ds.active.transform[1][0];
1399 info.mMatrix[1][1] = ds.active.transform[1][1];
1400 {
David Sodman0cc69182017-11-17 12:12:07 -08001401 sp<const GraphicBuffer> buffer = getBE().compositionInfo.mBuffer;
David Sodman5b4cffc2017-11-23 13:20:29 -08001402 if (buffer != 0) {
1403 info.mActiveBufferWidth = buffer->getWidth();
1404 info.mActiveBufferHeight = buffer->getHeight();
1405 info.mActiveBufferStride = buffer->getStride();
1406 info.mActiveBufferFormat = buffer->format;
Kalle Raitaa099a242017-01-11 11:17:29 -08001407 } else {
1408 info.mActiveBufferWidth = 0;
1409 info.mActiveBufferHeight = 0;
1410 info.mActiveBufferStride = 0;
1411 info.mActiveBufferFormat = 0;
1412 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001413 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001414 info.mNumQueuedFrames = getQueuedFrameCount();
1415 info.mRefreshPending = isBufferLatched();
1416 info.mIsOpaque = isOpaque(ds);
1417 info.mContentDirty = contentDirty;
1418 return info;
Mathias Agopian13127d82013-03-05 17:47:11 -08001419}
Chia-I Wu83ce7c12017-10-19 15:18:55 -07001420
Dan Stozae22aec72016-08-01 13:20:59 -07001421void Layer::miniDumpHeader(String8& result) {
1422 result.append("----------------------------------------");
1423 result.append("---------------------------------------\n");
1424 result.append(" Layer name\n");
1425 result.append(" Z | ");
1426 result.append(" Comp Type | ");
1427 result.append(" Disp Frame (LTRB) | ");
1428 result.append(" Source Crop (LTRB)\n");
1429 result.append("----------------------------------------");
1430 result.append("---------------------------------------\n");
1431}
1432
1433void Layer::miniDump(String8& result, int32_t hwcId) const {
David Sodman6f65f3e2017-11-03 14:28:09 -07001434 if (getBE().mHwcLayers.count(hwcId) == 0) {
Dan Stozae22aec72016-08-01 13:20:59 -07001435 return;
1436 }
1437
1438 String8 name;
1439 if (mName.length() > 77) {
1440 std::string shortened;
1441 shortened.append(mName.string(), 36);
1442 shortened.append("[...]");
1443 shortened.append(mName.string() + (mName.length() - 36), 36);
1444 name = shortened.c_str();
1445 } else {
1446 name = mName;
1447 }
1448
1449 result.appendFormat(" %s\n", name.string());
1450
1451 const Layer::State& layerState(getDrawingState());
David Sodman6f65f3e2017-11-03 14:28:09 -07001452 const LayerBE::HWCInfo& hwcInfo = getBE().mHwcLayers.at(hwcId);
John Reck8c3b6ac2017-08-24 10:25:42 -07001453 result.appendFormat(" %10d | ", layerState.z);
David Sodman41fdfc92017-11-06 16:09:56 -08001454 result.appendFormat("%10s | ", to_string(getCompositionType(hwcId)).c_str());
Dan Stozae22aec72016-08-01 13:20:59 -07001455 const Rect& frame = hwcInfo.displayFrame;
David Sodman41fdfc92017-11-06 16:09:56 -08001456 result.appendFormat("%4d %4d %4d %4d | ", frame.left, frame.top, frame.right, frame.bottom);
Dan Stoza5a423ea2017-02-16 14:10:39 -08001457 const FloatRect& crop = hwcInfo.sourceCrop;
David Sodman41fdfc92017-11-06 16:09:56 -08001458 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 -07001459
1460 result.append("- - - - - - - - - - - - - - - - - - - - ");
1461 result.append("- - - - - - - - - - - - - - - - - - - -\n");
1462}
Dan Stozae22aec72016-08-01 13:20:59 -07001463
Svetoslavd85084b2014-03-20 10:28:31 -07001464void Layer::dumpFrameStats(String8& result) const {
1465 mFrameTracker.dumpStats(result);
Mathias Agopian13127d82013-03-05 17:47:11 -08001466}
1467
Svetoslavd85084b2014-03-20 10:28:31 -07001468void Layer::clearFrameStats() {
1469 mFrameTracker.clearStats();
Mathias Agopian13127d82013-03-05 17:47:11 -08001470}
1471
Jamie Gennis6547ff42013-07-16 20:12:42 -07001472void Layer::logFrameStats() {
1473 mFrameTracker.logAndResetStats(mName);
1474}
1475
Svetoslavd85084b2014-03-20 10:28:31 -07001476void Layer::getFrameStats(FrameStats* outStats) const {
1477 mFrameTracker.getStats(outStats);
1478}
1479
Brian Andersond6927fb2016-07-23 23:37:30 -07001480void Layer::dumpFrameEvents(String8& result) {
David Sodman41fdfc92017-11-06 16:09:56 -08001481 result.appendFormat("- Layer %s (%s, %p)\n", getName().string(), getTypeId(), this);
Brian Andersond6927fb2016-07-23 23:37:30 -07001482 Mutex::Autolock lock(mFrameEventHistoryMutex);
1483 mFrameEventHistory.checkFencesForCompletion();
1484 mFrameEventHistory.dump(result);
1485}
Pablo Ceballos40845df2016-01-25 17:41:15 -08001486
Brian Anderson5ea5e592016-12-01 16:54:33 -08001487void Layer::onDisconnect() {
1488 Mutex::Autolock lock(mFrameEventHistoryMutex);
1489 mFrameEventHistory.onDisconnect();
1490}
1491
Brian Anderson3890c392016-07-25 12:48:08 -07001492void Layer::addAndGetFrameTimestamps(const NewFrameEventsEntry* newTimestamps,
David Sodman41fdfc92017-11-06 16:09:56 -08001493 FrameEventHistoryDelta* outDelta) {
Brian Andersond6927fb2016-07-23 23:37:30 -07001494 Mutex::Autolock lock(mFrameEventHistoryMutex);
1495 if (newTimestamps) {
Brian Andersonfbc80ae2017-05-26 16:23:54 -07001496 // If there are any unsignaled fences in the aquire timeline at this
1497 // point, the previously queued frame hasn't been latched yet. Go ahead
1498 // and try to get the signal time here so the syscall is taken out of
1499 // the main thread's critical path.
1500 mAcquireTimeline.updateSignalTimes();
1501 // Push the new fence after updating since it's likely still pending.
Brian Anderson3d4039d2016-09-23 16:31:30 -07001502 mAcquireTimeline.push(newTimestamps->acquireFence);
Brian Andersond6927fb2016-07-23 23:37:30 -07001503 mFrameEventHistory.addQueue(*newTimestamps);
1504 }
1505
Brian Anderson3890c392016-07-25 12:48:08 -07001506 if (outDelta) {
1507 mFrameEventHistory.getAndResetDelta(outDelta);
Brian Andersond6927fb2016-07-23 23:37:30 -07001508 }
Pablo Ceballos40845df2016-01-25 17:41:15 -08001509}
Dan Stozae77c7662016-05-13 11:37:28 -07001510
Chia-I Wu98f1c102017-05-30 14:54:08 -07001511size_t Layer::getChildrenCount() const {
1512 size_t count = 0;
1513 for (const sp<Layer>& child : mCurrentChildren) {
1514 count += 1 + child->getChildrenCount();
1515 }
1516 return count;
1517}
1518
Robert Carr1f0a16a2016-10-24 16:27:39 -07001519void Layer::addChild(const sp<Layer>& layer) {
1520 mCurrentChildren.add(layer);
1521 layer->setParent(this);
1522}
1523
1524ssize_t Layer::removeChild(const sp<Layer>& layer) {
1525 layer->setParent(nullptr);
1526 return mCurrentChildren.remove(layer);
1527}
1528
Robert Carr1db73f62016-12-21 12:58:51 -08001529bool Layer::reparentChildren(const sp<IBinder>& newParentHandle) {
1530 sp<Handle> handle = nullptr;
1531 sp<Layer> newParent = nullptr;
1532 if (newParentHandle == nullptr) {
1533 return false;
1534 }
1535 handle = static_cast<Handle*>(newParentHandle.get());
1536 newParent = handle->owner.promote();
1537 if (newParent == nullptr) {
1538 ALOGE("Unable to promote Layer handle");
1539 return false;
1540 }
1541
1542 for (const sp<Layer>& child : mCurrentChildren) {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001543 newParent->addChild(child);
Robert Carr1db73f62016-12-21 12:58:51 -08001544
1545 sp<Client> client(child->mClientRef.promote());
1546 if (client != nullptr) {
1547 client->setParentLayer(newParent);
1548 }
1549 }
1550 mCurrentChildren.clear();
1551
1552 return true;
1553}
1554
chaviwf1961f72017-09-18 16:41:07 -07001555bool Layer::reparent(const sp<IBinder>& newParentHandle) {
1556 if (newParentHandle == nullptr) {
chaviw06178942017-07-27 10:25:59 -07001557 return false;
1558 }
1559
1560 auto handle = static_cast<Handle*>(newParentHandle.get());
1561 sp<Layer> newParent = handle->owner.promote();
1562 if (newParent == nullptr) {
1563 ALOGE("Unable to promote Layer handle");
1564 return false;
1565 }
1566
chaviwf1961f72017-09-18 16:41:07 -07001567 sp<Layer> parent = getParent();
1568 if (parent != nullptr) {
1569 parent->removeChild(this);
chaviw06178942017-07-27 10:25:59 -07001570 }
chaviwf1961f72017-09-18 16:41:07 -07001571 newParent->addChild(this);
chaviw06178942017-07-27 10:25:59 -07001572
chaviwf1961f72017-09-18 16:41:07 -07001573 sp<Client> client(mClientRef.promote());
chaviw06178942017-07-27 10:25:59 -07001574 sp<Client> newParentClient(newParent->mClientRef.promote());
1575
chaviwf1961f72017-09-18 16:41:07 -07001576 if (client != newParentClient) {
1577 client->setParentLayer(newParent);
chaviw06178942017-07-27 10:25:59 -07001578 }
1579
chaviw06178942017-07-27 10:25:59 -07001580 return true;
1581}
1582
Robert Carr9524cb32017-02-13 11:32:32 -08001583bool Layer::detachChildren() {
Robert Carr7f619b22017-11-06 12:56:35 -08001584 for (const sp<Layer>& child : mCurrentChildren) {
chaviw161410b02017-07-27 10:46:08 -07001585 sp<Client> parentClient = mClientRef.promote();
Robert Carr9524cb32017-02-13 11:32:32 -08001586 sp<Client> client(child->mClientRef.promote());
chaviw161410b02017-07-27 10:46:08 -07001587 if (client != nullptr && parentClient != client) {
Robert Carr7f619b22017-11-06 12:56:35 -08001588 client->detachLayer(child.get());
1589 child->detachChildren();
Robert Carr9524cb32017-02-13 11:32:32 -08001590 }
Robert Carr7f619b22017-11-06 12:56:35 -08001591 }
Robert Carr9524cb32017-02-13 11:32:32 -08001592
1593 return true;
1594}
1595
Robert Carr1f0a16a2016-10-24 16:27:39 -07001596void Layer::setParent(const sp<Layer>& layer) {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001597 mCurrentParent = layer;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001598}
1599
1600void Layer::clearSyncPoints() {
1601 for (const auto& child : mCurrentChildren) {
1602 child->clearSyncPoints();
1603 }
1604
1605 Mutex::Autolock lock(mLocalSyncPointMutex);
1606 for (auto& point : mLocalSyncPoints) {
1607 point->setFrameAvailable();
1608 }
1609 mLocalSyncPoints.clear();
1610}
1611
1612int32_t Layer::getZ() const {
1613 return mDrawingState.z;
1614}
1615
Robert Carr29abff82017-12-04 13:51:20 -08001616bool Layer::usingRelativeZ(LayerVector::StateSet stateSet) {
1617 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1618 const State& state = useDrawing ? mDrawingState : mCurrentState;
1619 return state.zOrderRelativeOf != nullptr;
1620}
1621
David Sodman41fdfc92017-11-06 16:09:56 -08001622__attribute__((no_sanitize("unsigned-integer-overflow"))) LayerVector Layer::makeTraversalList(
Robert Carr29abff82017-12-04 13:51:20 -08001623 LayerVector::StateSet stateSet, bool* outSkipRelativeZUsers) {
Dan Stoza412903f2017-04-27 13:42:17 -07001624 LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid,
1625 "makeTraversalList received invalid stateSet");
1626 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1627 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
1628 const State& state = useDrawing ? mDrawingState : mCurrentState;
1629
Robert Carr29abff82017-12-04 13:51:20 -08001630 if (state.zOrderRelatives.size() == 0) {
1631 *outSkipRelativeZUsers = true;
1632 return children;
1633 }
1634
Robert Carrdb66e622017-04-10 16:55:57 -07001635 LayerVector traverse;
Dan Stoza412903f2017-04-27 13:42:17 -07001636 for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
Robert Carrdb66e622017-04-10 16:55:57 -07001637 sp<Layer> strongRelative = weakRelative.promote();
1638 if (strongRelative != nullptr) {
1639 traverse.add(strongRelative);
Robert Carrdb66e622017-04-10 16:55:57 -07001640 }
1641 }
1642
Dan Stoza412903f2017-04-27 13:42:17 -07001643 for (const sp<Layer>& child : children) {
Robert Carr503c7042017-09-27 15:06:08 -07001644 const State& childState = useDrawing ? child->mDrawingState : child->mCurrentState;
1645 if (childState.zOrderRelativeOf != nullptr) {
1646 continue;
1647 }
Robert Carrdb66e622017-04-10 16:55:57 -07001648 traverse.add(child);
1649 }
1650
1651 return traverse;
1652}
1653
Robert Carr1f0a16a2016-10-24 16:27:39 -07001654/**
Robert Carrdb66e622017-04-10 16:55:57 -07001655 * Negatively signed relatives are before 'this' in Z-order.
Robert Carr1f0a16a2016-10-24 16:27:39 -07001656 */
Dan Stoza412903f2017-04-27 13:42:17 -07001657void Layer::traverseInZOrder(LayerVector::StateSet stateSet, const LayerVector::Visitor& visitor) {
Robert Carr29abff82017-12-04 13:51:20 -08001658 // In the case we have other layers who are using a relative Z to us, makeTraversalList will
1659 // produce a new list for traversing, including our relatives, and not including our children
1660 // who are relatives of another surface. In the case that there are no relative Z,
1661 // makeTraversalList returns our children directly to avoid significant overhead.
1662 // However in this case we need to take the responsibility for filtering children which
1663 // are relatives of another surface here.
1664 bool skipRelativeZUsers = false;
1665 const LayerVector list = makeTraversalList(stateSet, &skipRelativeZUsers);
Robert Carrdb66e622017-04-10 16:55:57 -07001666
Robert Carr1f0a16a2016-10-24 16:27:39 -07001667 size_t i = 0;
Robert Carrdb66e622017-04-10 16:55:57 -07001668 for (; i < list.size(); i++) {
1669 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001670 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1671 continue;
1672 }
1673
Robert Carrdb66e622017-04-10 16:55:57 -07001674 if (relative->getZ() >= 0) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001675 break;
Robert Carrdb66e622017-04-10 16:55:57 -07001676 }
Dan Stoza412903f2017-04-27 13:42:17 -07001677 relative->traverseInZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001678 }
Robert Carr29abff82017-12-04 13:51:20 -08001679
Dan Stoza412903f2017-04-27 13:42:17 -07001680 visitor(this);
Robert Carrdb66e622017-04-10 16:55:57 -07001681 for (; i < list.size(); i++) {
1682 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001683
1684 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1685 continue;
1686 }
Dan Stoza412903f2017-04-27 13:42:17 -07001687 relative->traverseInZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001688 }
1689}
1690
1691/**
Robert Carrdb66e622017-04-10 16:55:57 -07001692 * Positively signed relatives are before 'this' in reverse Z-order.
Robert Carr1f0a16a2016-10-24 16:27:39 -07001693 */
Dan Stoza412903f2017-04-27 13:42:17 -07001694void Layer::traverseInReverseZOrder(LayerVector::StateSet stateSet,
1695 const LayerVector::Visitor& visitor) {
Robert Carr29abff82017-12-04 13:51:20 -08001696 // See traverseInZOrder for documentation.
1697 bool skipRelativeZUsers = false;
1698 LayerVector list = makeTraversalList(stateSet, &skipRelativeZUsers);
Robert Carrdb66e622017-04-10 16:55:57 -07001699
Robert Carr1f0a16a2016-10-24 16:27:39 -07001700 int32_t i = 0;
Joel Galensonbf324992017-11-06 11:04:12 -08001701 for (i = int32_t(list.size()) - 1; i >= 0; i--) {
Robert Carrdb66e622017-04-10 16:55:57 -07001702 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001703
1704 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1705 continue;
1706 }
1707
Robert Carrdb66e622017-04-10 16:55:57 -07001708 if (relative->getZ() < 0) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001709 break;
1710 }
Dan Stoza412903f2017-04-27 13:42:17 -07001711 relative->traverseInReverseZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001712 }
Dan Stoza412903f2017-04-27 13:42:17 -07001713 visitor(this);
David Sodman41fdfc92017-11-06 16:09:56 -08001714 for (; i >= 0; i--) {
Robert Carrdb66e622017-04-10 16:55:57 -07001715 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001716
1717 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1718 continue;
1719 }
1720
Dan Stoza412903f2017-04-27 13:42:17 -07001721 relative->traverseInReverseZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001722 }
1723}
1724
chaviwa76b2712017-09-20 12:02:26 -07001725/**
1726 * Traverse only children in z order, ignoring relative layers.
1727 */
1728void Layer::traverseChildrenInZOrder(LayerVector::StateSet stateSet,
1729 const LayerVector::Visitor& visitor) {
1730 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1731 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
1732
1733 size_t i = 0;
1734 for (; i < children.size(); i++) {
1735 const auto& relative = children[i];
1736 if (relative->getZ() >= 0) {
1737 break;
1738 }
1739 relative->traverseChildrenInZOrder(stateSet, visitor);
1740 }
1741 visitor(this);
1742 for (; i < children.size(); i++) {
1743 const auto& relative = children[i];
1744 relative->traverseChildrenInZOrder(stateSet, visitor);
1745 }
1746}
1747
Robert Carr1f0a16a2016-10-24 16:27:39 -07001748Transform Layer::getTransform() const {
1749 Transform t;
Chia-I Wue41dbe62017-06-13 14:10:56 -07001750 const auto& p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001751 if (p != nullptr) {
1752 t = p->getTransform();
Robert Carr9b429f42017-04-17 14:56:57 -07001753
1754 // If the parent is not using NATIVE_WINDOW_SCALING_MODE_FREEZE (e.g.
1755 // it isFixedSize) then there may be additional scaling not accounted
1756 // for in the transform. We need to mirror this scaling in child surfaces
1757 // or we will break the contract where WM can treat child surfaces as
1758 // pixels in the parent surface.
David Sodman0cc69182017-11-17 12:12:07 -08001759 if (p->isFixedSize() && p->getBE().compositionInfo.mBuffer != nullptr) {
Robert Carr1725eee2017-04-26 18:32:15 -07001760 int bufferWidth;
1761 int bufferHeight;
1762 if ((p->mCurrentTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) == 0) {
David Sodman0cc69182017-11-17 12:12:07 -08001763 bufferWidth = p->getBE().compositionInfo.mBuffer->getWidth();
1764 bufferHeight = p->getBE().compositionInfo.mBuffer->getHeight();
Robert Carr1725eee2017-04-26 18:32:15 -07001765 } else {
David Sodman0cc69182017-11-17 12:12:07 -08001766 bufferHeight = p->getBE().compositionInfo.mBuffer->getWidth();
1767 bufferWidth = p->getBE().compositionInfo.mBuffer->getHeight();
Robert Carr1725eee2017-04-26 18:32:15 -07001768 }
David Sodman41fdfc92017-11-06 16:09:56 -08001769 float sx = p->getDrawingState().active.w / static_cast<float>(bufferWidth);
1770 float sy = p->getDrawingState().active.h / static_cast<float>(bufferHeight);
Robert Carr9b429f42017-04-17 14:56:57 -07001771 Transform extraParentScaling;
1772 extraParentScaling.set(sx, 0, 0, sy);
1773 t = t * extraParentScaling;
1774 }
Robert Carr1f0a16a2016-10-24 16:27:39 -07001775 }
1776 return t * getDrawingState().active.transform;
1777}
1778
chaviw13fdc492017-06-27 12:40:18 -07001779half Layer::getAlpha() const {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001780 const auto& p = mDrawingParent.promote();
Robert Carr6452f122017-03-21 10:41:29 -07001781
chaviw13fdc492017-06-27 12:40:18 -07001782 half parentAlpha = (p != nullptr) ? p->getAlpha() : 1.0_hf;
1783 return parentAlpha * getDrawingState().color.a;
Robert Carr6452f122017-03-21 10:41:29 -07001784}
Robert Carr6452f122017-03-21 10:41:29 -07001785
chaviw13fdc492017-06-27 12:40:18 -07001786half4 Layer::getColor() const {
1787 const half4 color(getDrawingState().color);
1788 return half4(color.r, color.g, color.b, getAlpha());
Robert Carr6452f122017-03-21 10:41:29 -07001789}
Robert Carr6452f122017-03-21 10:41:29 -07001790
Robert Carr1f0a16a2016-10-24 16:27:39 -07001791void Layer::commitChildList() {
1792 for (size_t i = 0; i < mCurrentChildren.size(); i++) {
1793 const auto& child = mCurrentChildren[i];
1794 child->commitChildList();
1795 }
1796 mDrawingChildren = mCurrentChildren;
Chia-I Wue41dbe62017-06-13 14:10:56 -07001797 mDrawingParent = mCurrentParent;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001798}
1799
chaviw1d044282017-09-27 12:19:28 -07001800void Layer::writeToProto(LayerProto* layerInfo, LayerVector::StateSet stateSet) {
1801 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1802 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
1803 const State& state = useDrawing ? mDrawingState : mCurrentState;
1804
1805 Transform requestedTransform = state.active.transform;
1806 Transform transform = getTransform();
1807
1808 layerInfo->set_id(sequence);
1809 layerInfo->set_name(getName().c_str());
1810 layerInfo->set_type(String8(getTypeId()));
1811
1812 for (const auto& child : children) {
1813 layerInfo->add_children(child->sequence);
1814 }
1815
1816 for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
1817 sp<Layer> strongRelative = weakRelative.promote();
1818 if (strongRelative != nullptr) {
1819 layerInfo->add_relatives(strongRelative->sequence);
1820 }
1821 }
1822
1823 LayerProtoHelper::writeToProto(state.activeTransparentRegion,
1824 layerInfo->mutable_transparent_region());
1825 LayerProtoHelper::writeToProto(visibleRegion, layerInfo->mutable_visible_region());
1826 LayerProtoHelper::writeToProto(surfaceDamageRegion, layerInfo->mutable_damage_region());
1827
1828 layerInfo->set_layer_stack(getLayerStack());
1829 layerInfo->set_z(state.z);
1830
1831 PositionProto* position = layerInfo->mutable_position();
1832 position->set_x(transform.tx());
1833 position->set_y(transform.ty());
1834
1835 PositionProto* requestedPosition = layerInfo->mutable_requested_position();
1836 requestedPosition->set_x(requestedTransform.tx());
1837 requestedPosition->set_y(requestedTransform.ty());
1838
1839 SizeProto* size = layerInfo->mutable_size();
1840 size->set_w(state.active.w);
1841 size->set_h(state.active.h);
1842
1843 LayerProtoHelper::writeToProto(state.crop, layerInfo->mutable_crop());
1844 LayerProtoHelper::writeToProto(state.finalCrop, layerInfo->mutable_final_crop());
1845
1846 layerInfo->set_is_opaque(isOpaque(state));
1847 layerInfo->set_invalidate(contentDirty);
1848 layerInfo->set_dataspace(dataspaceDetails(getDataSpace()));
1849 layerInfo->set_pixel_format(decodePixelFormat(getPixelFormat()));
1850 LayerProtoHelper::writeToProto(getColor(), layerInfo->mutable_color());
1851 LayerProtoHelper::writeToProto(state.color, layerInfo->mutable_requested_color());
1852 layerInfo->set_flags(state.flags);
1853
1854 LayerProtoHelper::writeToProto(transform, layerInfo->mutable_transform());
1855 LayerProtoHelper::writeToProto(requestedTransform, layerInfo->mutable_requested_transform());
1856
Jorim Jaggi8e0af362017-11-14 16:28:28 +01001857 auto parent = useDrawing ? mDrawingParent.promote() : mCurrentParent.promote();
chaviw1d044282017-09-27 12:19:28 -07001858 if (parent != nullptr) {
1859 layerInfo->set_parent(parent->sequence);
1860 }
1861
1862 auto zOrderRelativeOf = state.zOrderRelativeOf.promote();
1863 if (zOrderRelativeOf != nullptr) {
1864 layerInfo->set_z_order_relative_of(zOrderRelativeOf->sequence);
1865 }
1866
David Sodman0cc69182017-11-17 12:12:07 -08001867 auto buffer = getBE().compositionInfo.mBuffer;
David Sodman5b4cffc2017-11-23 13:20:29 -08001868 if (buffer != nullptr) {
1869 LayerProtoHelper::writeToProto(buffer, layerInfo->mutable_active_buffer());
chaviw1d044282017-09-27 12:19:28 -07001870 }
1871
1872 layerInfo->set_queued_frames(getQueuedFrameCount());
1873 layerInfo->set_refresh_pending(isBufferLatched());
1874}
1875
Mathias Agopian13127d82013-03-05 17:47:11 -08001876// ---------------------------------------------------------------------------
1877
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001878}; // namespace android
Mathias Agopian3f844832013-08-07 21:24:32 -07001879
1880#if defined(__gl_h_)
1881#error "don't include gl/gl.h in this file"
1882#endif
1883
1884#if defined(__gl2_h_)
1885#error "don't include gl2/gl2.h in this file"
1886#endif