blob: 50830998417f4bdcba1ba0472f3bd74df5b290a9 [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
Mathias Agopian13127d82013-03-05 17:47:11 -080064int32_t Layer::sSequence = 1;
65
David Sodman41fdfc92017-11-06 16:09:56 -080066Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client, const String8& name, uint32_t w,
67 uint32_t h, uint32_t flags)
David Sodman0c69cad2017-08-21 12:12:51 -070068 : contentDirty(false),
Mathias Agopian13127d82013-03-05 17:47:11 -080069 sequence(uint32_t(android_atomic_inc(&sSequence))),
70 mFlinger(flinger),
Mathias Agopian13127d82013-03-05 17:47:11 -080071 mPremultipliedAlpha(true),
David Sodman0c69cad2017-08-21 12:12:51 -070072 mName(name),
Mathias Agopian13127d82013-03-05 17:47:11 -080073 mTransactionFlags(0),
Dan Stoza7dde5992015-05-22 09:51:44 -070074 mPendingStateMutex(),
75 mPendingStates(),
Mathias Agopiana67932f2011-04-20 14:20:59 -070076 mQueuedFrames(0),
Jesse Hall399184a2014-03-03 15:42:54 -080077 mSidebandStreamChanged(false),
Mathias Agopiana9347642017-02-13 16:42:28 -080078 mActiveBufferSlot(BufferQueue::INVALID_BUFFER_SLOT),
Mathias Agopiana67932f2011-04-20 14:20:59 -070079 mCurrentTransform(0),
Robert Carrc3574f72016-03-24 12:19:32 -070080 mOverrideScalingMode(-1),
Mathias Agopiana67932f2011-04-20 14:20:59 -070081 mCurrentOpacity(true),
Dan Stozacac35382016-01-27 12:21:06 -080082 mCurrentFrameNumber(0),
Mathias Agopian82d7ab62012-01-19 18:34:40 -080083 mFrameLatencyNeeded(false),
Mathias Agopian13127d82013-03-05 17:47:11 -080084 mFiltering(false),
85 mNeedsFiltering(false),
Mathias Agopian13127d82013-03-05 17:47:11 -080086 mProtectedByApp(false),
Riley Andrews03414a12014-07-01 14:22:59 -070087 mClientRef(client),
Dan Stozaa4650a52015-05-12 12:56:16 -070088 mPotentialCursor(false),
89 mQueueItemLock(),
90 mQueueItemCondition(),
91 mQueueItems(),
Dan Stoza65476f32015-05-14 09:27:25 -070092 mLastFrameNumberReceived(0),
Robert Carr82364e32016-05-15 11:27:47 -070093 mAutoRefresh(false),
David Sodmanb8af7922017-12-21 15:17:55 -080094 mFreezeGeometryUpdates(false),
David Sodman2b727ac2017-12-21 14:28:08 -080095 mBE{this, name.string()} {
Dan Stoza9e56aa02015-11-02 13:00:03 -080096
Mathias Agopiana67932f2011-04-20 14:20:59 -070097 mCurrentCrop.makeInvalid();
Mathias Agopian4d9b8222013-03-12 17:11:48 -070098
99 uint32_t layerFlags = 0;
David Sodman41fdfc92017-11-06 16:09:56 -0800100 if (flags & ISurfaceComposerClient::eHidden) layerFlags |= layer_state_t::eLayerHidden;
101 if (flags & ISurfaceComposerClient::eOpaque) layerFlags |= layer_state_t::eLayerOpaque;
102 if (flags & ISurfaceComposerClient::eSecure) layerFlags |= layer_state_t::eLayerSecure;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700103
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700104 mName = name;
Dan Stozaf7ba41a2017-05-10 15:11:11 -0700105 mTransactionName = String8("TX - ") + mName;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700106
107 mCurrentState.active.w = w;
108 mCurrentState.active.h = h;
David Sodman0c69cad2017-08-21 12:12:51 -0700109 mCurrentState.flags = layerFlags;
Robert Carr3dcabfa2016-03-01 18:36:58 -0800110 mCurrentState.active.transform.set(0, 0);
Robert Carrb5d3d262016-03-25 15:08:13 -0700111 mCurrentState.crop.makeInvalid();
112 mCurrentState.finalCrop.makeInvalid();
Robert Carr7bf247e2017-05-18 14:02:49 -0700113 mCurrentState.requestedFinalCrop = mCurrentState.finalCrop;
114 mCurrentState.requestedCrop = mCurrentState.crop;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700115 mCurrentState.z = 0;
chaviw13fdc492017-06-27 12:40:18 -0700116 mCurrentState.color.a = 1.0f;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700117 mCurrentState.layerStack = 0;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700118 mCurrentState.sequence = 0;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700119 mCurrentState.requested = mCurrentState.active;
Courtney Goeltzenleuchterbb09b432016-11-30 13:51:28 -0700120 mCurrentState.dataSpace = HAL_DATASPACE_UNKNOWN;
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -0500121 mCurrentState.appId = 0;
122 mCurrentState.type = 0;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700123
124 // drawing state & current state are identical
125 mDrawingState = mCurrentState;
Jamie Gennis6547ff42013-07-16 20:12:42 -0700126
Dan Stoza9e56aa02015-11-02 13:00:03 -0800127 const auto& hwc = flinger->getHwComposer();
128 const auto& activeConfig = hwc.getActiveConfig(HWC_DISPLAY_PRIMARY);
129 nsecs_t displayPeriod = activeConfig->getVsyncPeriod();
Jamie Gennis6547ff42013-07-16 20:12:42 -0700130 mFrameTracker.setDisplayRefreshPeriod(displayPeriod);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800131
132 CompositorTiming compositorTiming;
133 flinger->getCompositorTiming(&compositorTiming);
134 mFrameEventHistory.initializeCompositorTiming(compositorTiming);
David Sodman9eeae692017-11-02 10:53:32 -0700135
Jamie Gennise8696a42012-01-15 18:54:57 -0800136}
137
David Sodman41fdfc92017-11-06 16:09:56 -0800138void Layer::onFirstRef() {}
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700139
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700140Layer::~Layer() {
David Sodman577c8962017-12-08 14:50:53 -0800141 sp<Client> c(mClientRef.promote());
142 if (c != 0) {
143 c->detachLayer(this);
144 }
145
146 for (auto& point : mRemoteSyncPoints) {
147 point->setTransactionApplied();
148 }
149 for (auto& point : mLocalSyncPoints) {
150 point->setFrameAvailable();
151 }
Jamie Gennis6547ff42013-07-16 20:12:42 -0700152 mFrameTracker.logAndResetStats(mName);
Mathias Agopian96f08192010-06-02 23:28:45 -0700153}
154
Mathias Agopian13127d82013-03-05 17:47:11 -0800155// ---------------------------------------------------------------------------
156// callbacks
157// ---------------------------------------------------------------------------
158
David Sodmaneb085e02017-10-05 18:49:04 -0700159/*
160 * onLayerDisplayed is only meaningful for BufferLayer, but, is called through
161 * Layer. So, the implementation is done in BufferLayer. When called on a
162 * ColorLayer object, it's essentially a NOP.
163 */
David Sodmaneb085e02017-10-05 18:49:04 -0700164void Layer::onLayerDisplayed(const sp<Fence>& /*releaseFence*/) {}
Mathias Agopian13127d82013-03-05 17:47:11 -0800165
Chia-I Wuc6657022017-08-15 11:18:17 -0700166void Layer::onRemovedFromCurrentState() {
167 // the layer is removed from SF mCurrentState to mLayersPendingRemoval
168
chaviw8b3871a2017-11-01 17:41:01 -0700169 mPendingRemoval = true;
170
Robert Carr5edb1ad2017-04-25 10:54:24 -0700171 if (mCurrentState.zOrderRelativeOf != nullptr) {
172 sp<Layer> strongRelative = mCurrentState.zOrderRelativeOf.promote();
173 if (strongRelative != nullptr) {
174 strongRelative->removeZOrderRelative(this);
Chia-I Wuc6657022017-08-15 11:18:17 -0700175 mFlinger->setTransactionFlags(eTraversalNeeded);
Robert Carr5edb1ad2017-04-25 10:54:24 -0700176 }
177 mCurrentState.zOrderRelativeOf = nullptr;
178 }
179
Chia-I Wuc6657022017-08-15 11:18:17 -0700180 for (const auto& child : mCurrentChildren) {
181 child->onRemovedFromCurrentState();
182 }
183}
Chia-I Wu38512252017-05-17 14:36:16 -0700184
Chia-I Wuc6657022017-08-15 11:18:17 -0700185void Layer::onRemoved() {
186 // the layer is removed from SF mLayersPendingRemoval
David Sodmaneb085e02017-10-05 18:49:04 -0700187 abandon();
Chia-I Wuc6657022017-08-15 11:18:17 -0700188
Steven Thomasb02664d2017-07-26 18:48:28 -0700189 destroyAllHwcLayers();
Chia-I Wu38512252017-05-17 14:36:16 -0700190
Robert Carr1f0a16a2016-10-24 16:27:39 -0700191 for (const auto& child : mCurrentChildren) {
192 child->onRemoved();
193 }
Mathias Agopian48d819a2009-09-10 19:41:18 -0700194}
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700195
Mathias Agopian13127d82013-03-05 17:47:11 -0800196// ---------------------------------------------------------------------------
197// set-up
198// ---------------------------------------------------------------------------
199
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700200const String8& Layer::getName() const {
Mathias Agopian13127d82013-03-05 17:47:11 -0800201 return mName;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800202}
203
chaviw13fdc492017-06-27 12:40:18 -0700204bool Layer::getPremultipledAlpha() const {
205 return mPremultipliedAlpha;
206}
207
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700208sp<IBinder> Layer::getHandle() {
Mathias Agopian13127d82013-03-05 17:47:11 -0800209 Mutex::Autolock _l(mLock);
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700210 return new Handle(mFlinger, this);
Mathias Agopian13127d82013-03-05 17:47:11 -0800211}
212
213// ---------------------------------------------------------------------------
214// h/w composer set-up
215// ---------------------------------------------------------------------------
216
Steven Thomasb02664d2017-07-26 18:48:28 -0700217bool Layer::createHwcLayer(HWComposer* hwc, int32_t hwcId) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700218 LOG_ALWAYS_FATAL_IF(getBE().mHwcLayers.count(hwcId) != 0,
David Sodman9eeae692017-11-02 10:53:32 -0700219 "Already have a layer for hwcId %d", hwcId);
David Sodman5d89c1d2017-12-14 15:54:51 -0800220
221 std::shared_ptr<LayerContainer> layer(new LayerContainer(hwc, hwcId));
Steven Thomasb02664d2017-07-26 18:48:28 -0700222 if (!layer) {
223 return false;
224 }
David Sodman6f65f3e2017-11-03 14:28:09 -0700225 LayerBE::HWCInfo& hwcInfo = getBE().mHwcLayers[hwcId];
Steven Thomasb02664d2017-07-26 18:48:28 -0700226 hwcInfo.hwc = hwc;
227 hwcInfo.layer = layer;
Steven Thomasb02664d2017-07-26 18:48:28 -0700228 return true;
229}
230
Chia-I Wu83806892017-11-16 10:50:20 -0800231bool Layer::destroyHwcLayer(int32_t hwcId) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700232 if (getBE().mHwcLayers.count(hwcId) == 0) {
Chia-I Wu83806892017-11-16 10:50:20 -0800233 return false;
Steven Thomasb02664d2017-07-26 18:48:28 -0700234 }
David Sodman6f65f3e2017-11-03 14:28:09 -0700235 auto& hwcInfo = getBE().mHwcLayers[hwcId];
David Sodman41fdfc92017-11-06 16:09:56 -0800236 LOG_ALWAYS_FATAL_IF(hwcInfo.layer == nullptr, "Attempt to destroy null layer");
Steven Thomasb02664d2017-07-26 18:48:28 -0700237 LOG_ALWAYS_FATAL_IF(hwcInfo.hwc == nullptr, "Missing HWComposer");
David Sodman5d89c1d2017-12-14 15:54:51 -0800238 hwcInfo.layer = nullptr;
239
240 if (getBE().mHwcLayers.count(hwcId) == 1) {
241 getBE().mHwcLayers.erase(hwcId);
242 }
243
Chia-I Wu83806892017-11-16 10:50:20 -0800244 return true;
Steven Thomasb02664d2017-07-26 18:48:28 -0700245}
246
247void Layer::destroyAllHwcLayers() {
David Sodman6f65f3e2017-11-03 14:28:09 -0700248 size_t numLayers = getBE().mHwcLayers.size();
Steven Thomasb02664d2017-07-26 18:48:28 -0700249 for (size_t i = 0; i < numLayers; ++i) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700250 LOG_ALWAYS_FATAL_IF(getBE().mHwcLayers.empty(), "destroyAllHwcLayers failed");
251 destroyHwcLayer(getBE().mHwcLayers.begin()->first);
Steven Thomasb02664d2017-07-26 18:48:28 -0700252 }
David Sodman6f65f3e2017-11-03 14:28:09 -0700253 LOG_ALWAYS_FATAL_IF(!getBE().mHwcLayers.empty(),
David Sodman41fdfc92017-11-06 16:09:56 -0800254 "All hardware composer layers should have been destroyed");
Steven Thomasb02664d2017-07-26 18:48:28 -0700255}
Steven Thomasb02664d2017-07-26 18:48:28 -0700256
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800257Rect Layer::getContentCrop() const {
258 // this is the crop rectangle that applies to the buffer
259 // itself (as opposed to the window)
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700260 Rect crop;
261 if (!mCurrentCrop.isEmpty()) {
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800262 // if the buffer crop is defined, we use that
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700263 crop = mCurrentCrop;
Peiyong Lin566a3b42018-01-09 18:22:43 -0800264 } else if (getBE().compositionInfo.mBuffer != nullptr) {
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800265 // otherwise we use the whole buffer
David Sodman0cc69182017-11-17 12:12:07 -0800266 crop = getBE().compositionInfo.mBuffer->getBounds();
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700267 } else {
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800268 // if we don't have a buffer yet, we use an empty/invalid crop
Mathias Agopian4fec8732012-06-29 14:12:52 -0700269 crop.makeInvalid();
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700270 }
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700271 return crop;
272}
273
Mathias Agopianf3e85d42013-05-10 18:01:12 -0700274static Rect reduce(const Rect& win, const Region& exclude) {
275 if (CC_LIKELY(exclude.isEmpty())) {
276 return win;
277 }
278 if (exclude.isRect()) {
279 return win.reduce(exclude.getBounds());
280 }
281 return Region(win).subtract(exclude).getBounds();
282}
283
Dan Stoza80d61162017-12-20 15:57:52 -0800284static FloatRect reduce(const FloatRect& win, const Region& exclude) {
285 if (CC_LIKELY(exclude.isEmpty())) {
286 return win;
287 }
288 // Convert through Rect (by rounding) for lack of FloatRegion
289 return Region(Rect{win}).subtract(exclude).getBounds().toFloatRect();
290}
291
Robert Carr1f0a16a2016-10-24 16:27:39 -0700292Rect Layer::computeScreenBounds(bool reduceTransparentRegion) const {
293 const Layer::State& s(getDrawingState());
294 Rect win(s.active.w, s.active.h);
295
296 if (!s.crop.isEmpty()) {
297 win.intersect(s.crop, &win);
298 }
299
300 Transform t = getTransform();
301 win = t.transform(win);
302
Robert Carr41b08b52017-06-01 16:11:34 -0700303 if (!s.finalCrop.isEmpty()) {
304 win.intersect(s.finalCrop, &win);
305 }
306
Chia-I Wue41dbe62017-06-13 14:10:56 -0700307 const sp<Layer>& p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700308 // Now we need to calculate the parent bounds, so we can clip ourselves to those.
309 // When calculating the parent bounds for purposes of clipping,
310 // we don't need to constrain the parent to its transparent region.
311 // The transparent region is an optimization based on the
312 // buffer contents of the layer, but does not affect the space allocated to
313 // it by policy, and thus children should be allowed to extend into the
314 // parent's transparent region. In fact one of the main uses, is to reduce
315 // buffer allocation size in cases where a child window sits behind a main window
316 // (by marking the hole in the parent window as a transparent region)
317 if (p != nullptr) {
318 Rect bounds = p->computeScreenBounds(false);
319 bounds.intersect(win, &win);
320 }
321
322 if (reduceTransparentRegion) {
323 auto const screenTransparentRegion = t.transform(s.activeTransparentRegion);
324 win = reduce(win, screenTransparentRegion);
325 }
326
327 return win;
328}
329
Dan Stoza80d61162017-12-20 15:57:52 -0800330FloatRect Layer::computeBounds() const {
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700331 const Layer::State& s(getDrawingState());
Michael Lentine6c925ed2014-09-26 17:55:01 -0700332 return computeBounds(s.activeTransparentRegion);
333}
334
Dan Stoza80d61162017-12-20 15:57:52 -0800335FloatRect Layer::computeBounds(const Region& activeTransparentRegion) const {
Michael Lentine6c925ed2014-09-26 17:55:01 -0700336 const Layer::State& s(getDrawingState());
Mathias Agopian13127d82013-03-05 17:47:11 -0800337 Rect win(s.active.w, s.active.h);
Robert Carrb5d3d262016-03-25 15:08:13 -0700338
339 if (!s.crop.isEmpty()) {
340 win.intersect(s.crop, &win);
Mathias Agopian13127d82013-03-05 17:47:11 -0800341 }
Robert Carr1f0a16a2016-10-24 16:27:39 -0700342
343 Rect bounds = win;
Chia-I Wue41dbe62017-06-13 14:10:56 -0700344 const auto& p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700345 if (p != nullptr) {
Robert Carrde9ec442017-02-08 17:43:36 -0800346 // Look in computeScreenBounds recursive call for explanation of
347 // why we pass false here.
348 bounds = p->computeScreenBounds(false /* reduceTransparentRegion */);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700349 }
350
351 Transform t = getTransform();
Dan Stoza80d61162017-12-20 15:57:52 -0800352
353 FloatRect floatWin = win.toFloatRect();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700354 if (p != nullptr) {
Dan Stoza80d61162017-12-20 15:57:52 -0800355 floatWin = t.transform(floatWin);
356 floatWin = floatWin.intersect(bounds.toFloatRect());
357 floatWin = t.inverse().transform(floatWin);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700358 }
359
Mathias Agopian6c7f25a2013-05-09 20:37:10 -0700360 // subtract the transparent region and snap to the bounds
Dan Stoza80d61162017-12-20 15:57:52 -0800361 return reduce(floatWin, activeTransparentRegion);
Mathias Agopian13127d82013-03-05 17:47:11 -0800362}
363
Robert Carr1f0a16a2016-10-24 16:27:39 -0700364Rect Layer::computeInitialCrop(const sp<const DisplayDevice>& hw) const {
Robert Carrb5d3d262016-03-25 15:08:13 -0700365 // the crop is the area of the window that gets cropped, but not
Mathias Agopian13127d82013-03-05 17:47:11 -0800366 // scaled in any ways.
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700367 const State& s(getDrawingState());
Mathias Agopian13127d82013-03-05 17:47:11 -0800368
369 // apply the projection's clipping to the window crop in
370 // layerstack space, and convert-back to layer space.
Mathias Agopian6b442672013-07-09 21:24:52 -0700371 // if there are no window scaling involved, this operation will map to full
372 // pixels in the buffer.
373 // FIXME: the 3 lines below can produce slightly incorrect clipping when we have
374 // a viewport clipping and a window transform. we should use floating point to fix this.
Mathias Agopian0e8f1442013-08-20 21:41:07 -0700375
376 Rect activeCrop(s.active.w, s.active.h);
Robert Carrb5d3d262016-03-25 15:08:13 -0700377 if (!s.crop.isEmpty()) {
Chia-I Wudf7867f2017-07-20 14:24:37 -0700378 activeCrop.intersect(s.crop, &activeCrop);
Mathias Agopian0e8f1442013-08-20 21:41:07 -0700379 }
380
Robert Carr1f0a16a2016-10-24 16:27:39 -0700381 Transform t = getTransform();
382 activeCrop = t.transform(activeCrop);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000383 if (!activeCrop.intersect(hw->getViewport(), &activeCrop)) {
384 activeCrop.clear();
385 }
Robert Carrb5d3d262016-03-25 15:08:13 -0700386 if (!s.finalCrop.isEmpty()) {
David Sodman41fdfc92017-11-06 16:09:56 -0800387 if (!activeCrop.intersect(s.finalCrop, &activeCrop)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000388 activeCrop.clear();
389 }
390 }
chaviwb1154d12017-10-31 14:15:36 -0700391
392 const auto& p = mDrawingParent.promote();
393 if (p != nullptr) {
394 auto parentCrop = p->computeInitialCrop(hw);
395 activeCrop.intersect(parentCrop, &activeCrop);
396 }
397
Robert Carr1f0a16a2016-10-24 16:27:39 -0700398 return activeCrop;
399}
400
Dan Stoza5a423ea2017-02-16 14:10:39 -0800401FloatRect Layer::computeCrop(const sp<const DisplayDevice>& hw) const {
Robert Carr1f0a16a2016-10-24 16:27:39 -0700402 // the content crop is the area of the content that gets scaled to the
403 // layer's size. This is in buffer space.
Dan Stoza5a423ea2017-02-16 14:10:39 -0800404 FloatRect crop = getContentCrop().toFloatRect();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700405
406 // In addition there is a WM-specified crop we pull from our drawing state.
407 const State& s(getDrawingState());
408
409 // Screen space to make reduction to parent crop clearer.
410 Rect activeCrop = computeInitialCrop(hw);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700411 Transform t = getTransform();
412 // Back to layer space to work with the content crop.
413 activeCrop = t.inverse().transform(activeCrop);
Mathias Agopian13127d82013-03-05 17:47:11 -0800414
Michael Lentine28ea2172014-11-19 18:32:37 -0800415 // This needs to be here as transform.transform(Rect) computes the
416 // transformed rect and then takes the bounding box of the result before
417 // returning. This means
418 // transform.inverse().transform(transform.transform(Rect)) != Rect
419 // in which case we need to make sure the final rect is clipped to the
420 // display bounds.
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000421 if (!activeCrop.intersect(Rect(s.active.w, s.active.h), &activeCrop)) {
422 activeCrop.clear();
423 }
Mathias Agopian13127d82013-03-05 17:47:11 -0800424
Mathias Agopianf3e85d42013-05-10 18:01:12 -0700425 // subtract the transparent region and snap to the bounds
426 activeCrop = reduce(activeCrop, s.activeTransparentRegion);
427
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000428 // Transform the window crop to match the buffer coordinate system,
429 // which means using the inverse of the current transform set on the
430 // SurfaceFlingerConsumer.
431 uint32_t invTransform = mCurrentTransform;
Robert Carrcae605c2017-03-29 12:10:31 -0700432 if (getTransformToDisplayInverse()) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000433 /*
Pablo Ceballos021623b2016-04-15 17:31:51 -0700434 * the code below applies the primary display's inverse transform to the
435 * buffer
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000436 */
David Sodman41fdfc92017-11-06 16:09:56 -0800437 uint32_t invTransformOrient = DisplayDevice::getPrimaryDisplayOrientationTransform();
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000438 // calculate the inverse transform
439 if (invTransformOrient & NATIVE_WINDOW_TRANSFORM_ROT_90) {
David Sodman41fdfc92017-11-06 16:09:56 -0800440 invTransformOrient ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H;
Mathias Agopian13127d82013-03-05 17:47:11 -0800441 }
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000442 // and apply to the current transform
David Sodman41fdfc92017-11-06 16:09:56 -0800443 invTransform = (Transform(invTransformOrient) * Transform(invTransform)).getOrientation();
Mathias Agopian13127d82013-03-05 17:47:11 -0800444 }
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000445
446 int winWidth = s.active.w;
447 int winHeight = s.active.h;
448 if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
449 // If the activeCrop has been rotate the ends are rotated but not
450 // the space itself so when transforming ends back we can't rely on
451 // a modification of the axes of rotation. To account for this we
452 // need to reorient the inverse rotation in terms of the current
453 // axes of rotation.
454 bool is_h_flipped = (invTransform & NATIVE_WINDOW_TRANSFORM_FLIP_H) != 0;
455 bool is_v_flipped = (invTransform & NATIVE_WINDOW_TRANSFORM_FLIP_V) != 0;
456 if (is_h_flipped == is_v_flipped) {
David Sodman41fdfc92017-11-06 16:09:56 -0800457 invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H;
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000458 }
459 winWidth = s.active.h;
460 winHeight = s.active.w;
461 }
David Sodman41fdfc92017-11-06 16:09:56 -0800462 const Rect winCrop = activeCrop.transform(invTransform, s.active.w, s.active.h);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000463
464 // below, crop is intersected with winCrop expressed in crop's coordinate space
David Sodman41fdfc92017-11-06 16:09:56 -0800465 float xScale = crop.getWidth() / float(winWidth);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000466 float yScale = crop.getHeight() / float(winHeight);
467
David Sodman41fdfc92017-11-06 16:09:56 -0800468 float insetL = winCrop.left * xScale;
469 float insetT = winCrop.top * yScale;
470 float insetR = (winWidth - winCrop.right) * xScale;
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000471 float insetB = (winHeight - winCrop.bottom) * yScale;
472
David Sodman41fdfc92017-11-06 16:09:56 -0800473 crop.left += insetL;
474 crop.top += insetT;
475 crop.right -= insetR;
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000476 crop.bottom -= insetB;
477
Mathias Agopian13127d82013-03-05 17:47:11 -0800478 return crop;
479}
480
Robert Carrae060832016-11-28 10:51:00 -0800481void Layer::setGeometry(const sp<const DisplayDevice>& displayDevice, uint32_t z)
Mathias Agopiana350ff92010-08-10 17:14:02 -0700482{
Dan Stoza9e56aa02015-11-02 13:00:03 -0800483 const auto hwcId = displayDevice->getHwcDisplayId();
David Sodman6f65f3e2017-11-03 14:28:09 -0700484 auto& hwcInfo = getBE().mHwcLayers[hwcId];
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700485
David Sodman56912832017-11-28 10:27:38 -0800486 // Need to program geometry parts
487 getBE().compositionInfo.hwc.skipGeometry = false;
488
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700489 // enable this layer
Dan Stoza9e56aa02015-11-02 13:00:03 -0800490 hwcInfo.forceClientComposition = false;
491
492 if (isSecure() && !displayDevice->isSecure()) {
493 hwcInfo.forceClientComposition = true;
494 }
495
Mathias Agopian13127d82013-03-05 17:47:11 -0800496 // this gives us only the "orientation" component of the transform
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700497 const State& s(getDrawingState());
David Revemanecf0fa52017-03-03 11:32:44 -0500498 auto blendMode = HWC2::BlendMode::None;
Robert Carr6452f122017-03-21 10:41:29 -0700499 if (!isOpaque(s) || getAlpha() != 1.0f) {
David Sodman41fdfc92017-11-06 16:09:56 -0800500 blendMode =
501 mPremultipliedAlpha ? HWC2::BlendMode::Premultiplied : HWC2::BlendMode::Coverage;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800502 }
David Sodman4b7c4bc2017-11-17 12:13:59 -0800503 getBE().compositionInfo.hwc.blendMode = blendMode;
Mathias Agopian13127d82013-03-05 17:47:11 -0800504
505 // apply the layer's transform, followed by the display's global transform
506 // here we're guaranteed that the layer's transform preserves rects
Michael Lentine6c925ed2014-09-26 17:55:01 -0700507 Region activeTransparentRegion(s.activeTransparentRegion);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700508 Transform t = getTransform();
Robert Carrb5d3d262016-03-25 15:08:13 -0700509 if (!s.crop.isEmpty()) {
510 Rect activeCrop(s.crop);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700511 activeCrop = t.transform(activeCrop);
David Sodman41fdfc92017-11-06 16:09:56 -0800512 if (!activeCrop.intersect(displayDevice->getViewport(), &activeCrop)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000513 activeCrop.clear();
514 }
Robert Carr1f0a16a2016-10-24 16:27:39 -0700515 activeCrop = t.inverse().transform(activeCrop, true);
Michael Lentine28ea2172014-11-19 18:32:37 -0800516 // This needs to be here as transform.transform(Rect) computes the
517 // transformed rect and then takes the bounding box of the result before
518 // returning. This means
519 // transform.inverse().transform(transform.transform(Rect)) != Rect
520 // in which case we need to make sure the final rect is clipped to the
521 // display bounds.
David Sodman41fdfc92017-11-06 16:09:56 -0800522 if (!activeCrop.intersect(Rect(s.active.w, s.active.h), &activeCrop)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000523 activeCrop.clear();
524 }
Michael Lentine6c925ed2014-09-26 17:55:01 -0700525 // mark regions outside the crop as transparent
526 activeTransparentRegion.orSelf(Rect(0, 0, s.active.w, activeCrop.top));
David Sodman41fdfc92017-11-06 16:09:56 -0800527 activeTransparentRegion.orSelf(Rect(0, activeCrop.bottom, s.active.w, s.active.h));
528 activeTransparentRegion.orSelf(Rect(0, activeCrop.top, activeCrop.left, activeCrop.bottom));
529 activeTransparentRegion.orSelf(
530 Rect(activeCrop.right, activeCrop.top, s.active.w, activeCrop.bottom));
Michael Lentine6c925ed2014-09-26 17:55:01 -0700531 }
Robert Carr1f0a16a2016-10-24 16:27:39 -0700532
Dan Stoza80d61162017-12-20 15:57:52 -0800533 // computeBounds returns a FloatRect to provide more accuracy during the
534 // transformation. We then round upon constructing 'frame'.
535 Rect frame{t.transform(computeBounds(activeTransparentRegion))};
Robert Carrb5d3d262016-03-25 15:08:13 -0700536 if (!s.finalCrop.isEmpty()) {
David Sodman41fdfc92017-11-06 16:09:56 -0800537 if (!frame.intersect(s.finalCrop, &frame)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000538 frame.clear();
539 }
540 }
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000541 if (!frame.intersect(displayDevice->getViewport(), &frame)) {
542 frame.clear();
543 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800544 const Transform& tr(displayDevice->getTransform());
545 Rect transformedFrame = tr.transform(frame);
David Sodman4b7c4bc2017-11-17 12:13:59 -0800546 getBE().compositionInfo.hwc.displayFrame = transformedFrame;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800547
Dan Stoza5a423ea2017-02-16 14:10:39 -0800548 FloatRect sourceCrop = computeCrop(displayDevice);
David Sodman4b7c4bc2017-11-17 12:13:59 -0800549 getBE().compositionInfo.hwc.sourceCrop = sourceCrop;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800550
chaviw13fdc492017-06-27 12:40:18 -0700551 float alpha = static_cast<float>(getAlpha());
David Sodman4b7c4bc2017-11-17 12:13:59 -0800552 getBE().compositionInfo.hwc.alpha = alpha;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800553
David Sodman4b7c4bc2017-11-17 12:13:59 -0800554 getBE().compositionInfo.hwc.z = z;
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -0500555
Albert Chaulk2a589632017-05-04 16:59:44 -0400556 int type = s.type;
557 int appId = s.appId;
Chia-I Wue41dbe62017-06-13 14:10:56 -0700558 sp<Layer> parent = mDrawingParent.promote();
Albert Chaulk2a589632017-05-04 16:59:44 -0400559 if (parent.get()) {
560 auto& parentState = parent->getDrawingState();
561 type = parentState.type;
562 appId = parentState.appId;
563 }
564
David Sodman4b7c4bc2017-11-17 12:13:59 -0800565 getBE().compositionInfo.hwc.type = type;
566 getBE().compositionInfo.hwc.appId = appId;
Mathias Agopian9f8386e2013-01-29 18:56:42 -0800567
Mathias Agopian29a367b2011-07-12 14:51:45 -0700568 /*
569 * Transformations are applied in this order:
570 * 1) buffer orientation/flip/mirror
571 * 2) state transformation (window manager)
572 * 3) layer orientation (screen orientation)
573 * (NOTE: the matrices are multiplied in reverse order)
574 */
575
576 const Transform bufferOrientation(mCurrentTransform);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700577 Transform transform(tr * t * bufferOrientation);
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700578
Robert Carrcae605c2017-03-29 12:10:31 -0700579 if (getTransformToDisplayInverse()) {
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700580 /*
Pablo Ceballos021623b2016-04-15 17:31:51 -0700581 * the code below applies the primary display's inverse transform to the
582 * buffer
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700583 */
David Sodman41fdfc92017-11-06 16:09:56 -0800584 uint32_t invTransform = DisplayDevice::getPrimaryDisplayOrientationTransform();
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700585 // calculate the inverse transform
586 if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
David Sodman41fdfc92017-11-06 16:09:56 -0800587 invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700588 }
Robert Carrcae605c2017-03-29 12:10:31 -0700589
590 /*
591 * Here we cancel out the orientation component of the WM transform.
592 * The scaling and translate components are already included in our bounds
593 * computation so it's enough to just omit it in the composition.
594 * See comment in onDraw with ref to b/36727915 for why.
595 */
596 transform = Transform(invTransform) * tr * bufferOrientation;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700597 }
Mathias Agopian29a367b2011-07-12 14:51:45 -0700598
Jorim Jaggi5a963262018-01-17 15:57:44 +0100599 // STOPSHIP (b/72106793): If we have less than 25% scaling, HWC usually needs to use the rotator
600 // to handle it. However, there is one guaranteed frame of jank when we switch to using the
601 // rotator. In the meantime, we force GL composition instead until we have a better fix for the
602 // HWC issue.
603 bool extremeScaling = abs(t[0][0]) <= 0.25 || abs(t[1][1]) <= 0.25;
604
Mathias Agopian29a367b2011-07-12 14:51:45 -0700605 // this gives us only the "orientation" component of the transform
Mathias Agopian13127d82013-03-05 17:47:11 -0800606 const uint32_t orientation = transform.getOrientation();
Jorim Jaggi5a963262018-01-17 15:57:44 +0100607 if (orientation & Transform::ROT_INVALID || extremeScaling) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800608 // we can only handle simple transformation
David Sodman56912832017-11-28 10:27:38 -0800609 getBE().mHwcLayers[hwcId].compositionType = HWC2::Composition::Client;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800610 } else {
611 auto transform = static_cast<HWC2::Transform>(orientation);
Yiwei Zhang7124ad32018-02-21 13:02:45 -0800612 hwcInfo.transform = transform;
David Sodman4b7c4bc2017-11-17 12:13:59 -0800613 getBE().compositionInfo.hwc.transform = transform;
614 }
615}
616
Dan Stoza9e56aa02015-11-02 13:00:03 -0800617void Layer::forceClientComposition(int32_t hwcId) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700618 if (getBE().mHwcLayers.count(hwcId) == 0) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800619 ALOGE("forceClientComposition: no HWC layer found (%d)", hwcId);
620 return;
621 }
622
David Sodman6f65f3e2017-11-03 14:28:09 -0700623 getBE().mHwcLayers[hwcId].forceClientComposition = true;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800624}
Dan Stozaee44edd2015-03-23 15:50:23 -0700625
chaviwc9232ed2017-11-14 15:31:15 -0800626bool Layer::getForceClientComposition(int32_t hwcId) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700627 if (getBE().mHwcLayers.count(hwcId) == 0) {
chaviwc9232ed2017-11-14 15:31:15 -0800628 ALOGE("getForceClientComposition: no HWC layer found (%d)", hwcId);
629 return false;
630 }
631
David Sodman6f65f3e2017-11-03 14:28:09 -0700632 return getBE().mHwcLayers[hwcId].forceClientComposition;
chaviwc9232ed2017-11-14 15:31:15 -0800633}
634
Dan Stoza9e56aa02015-11-02 13:00:03 -0800635void Layer::updateCursorPosition(const sp<const DisplayDevice>& displayDevice) {
636 auto hwcId = displayDevice->getHwcDisplayId();
David Sodman6f65f3e2017-11-03 14:28:09 -0700637 if (getBE().mHwcLayers.count(hwcId) == 0 ||
David Sodman9eeae692017-11-02 10:53:32 -0700638 getCompositionType(hwcId) != HWC2::Composition::Cursor) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800639 return;
640 }
641
642 // This gives us only the "orientation" component of the transform
643 const State& s(getCurrentState());
644
645 // Apply the layer's transform, followed by the display's global transform
646 // Here we're guaranteed that the layer's transform preserves rects
647 Rect win(s.active.w, s.active.h);
Robert Carrb5d3d262016-03-25 15:08:13 -0700648 if (!s.crop.isEmpty()) {
649 win.intersect(s.crop, &win);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800650 }
651 // Subtract the transparent region and snap to the bounds
652 Rect bounds = reduce(win, s.activeTransparentRegion);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700653 Rect frame(getTransform().transform(bounds));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800654 frame.intersect(displayDevice->getViewport(), &frame);
Robert Carrb5d3d262016-03-25 15:08:13 -0700655 if (!s.finalCrop.isEmpty()) {
656 frame.intersect(s.finalCrop, &frame);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000657 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800658 auto& displayTransform(displayDevice->getTransform());
659 auto position = displayTransform.transform(frame);
660
David Sodman5d89c1d2017-12-14 15:54:51 -0800661 auto error = (*getBE().mHwcLayers[hwcId].layer)->setCursorPosition(position.left,
David Sodman9eeae692017-11-02 10:53:32 -0700662 position.top);
David Sodman41fdfc92017-11-06 16:09:56 -0800663 ALOGE_IF(error != HWC2::Error::None,
664 "[%s] Failed to set cursor position "
665 "to (%d, %d): %s (%d)",
666 mName.string(), position.left, position.top, to_string(error).c_str(),
667 static_cast<int32_t>(error));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800668}
Riley Andrews03414a12014-07-01 14:22:59 -0700669
Mathias Agopian13127d82013-03-05 17:47:11 -0800670// ---------------------------------------------------------------------------
671// drawing...
672// ---------------------------------------------------------------------------
673
chaviwa76b2712017-09-20 12:02:26 -0700674void Layer::draw(const RenderArea& renderArea, const Region& clip) const {
675 onDraw(renderArea, clip, false);
Mathias Agopian13127d82013-03-05 17:47:11 -0800676}
677
chaviwa76b2712017-09-20 12:02:26 -0700678void Layer::draw(const RenderArea& renderArea, bool useIdentityTransform) const {
679 onDraw(renderArea, Region(renderArea.getBounds()), useIdentityTransform);
Mathias Agopian13127d82013-03-05 17:47:11 -0800680}
681
chaviwa76b2712017-09-20 12:02:26 -0700682void Layer::draw(const RenderArea& renderArea) const {
683 onDraw(renderArea, Region(renderArea.getBounds()), false);
Dan Stozac7014012014-02-14 15:03:43 -0800684}
685
David Sodman41fdfc92017-11-06 16:09:56 -0800686void Layer::clearWithOpenGL(const RenderArea& renderArea, float red, float green, float blue,
687 float alpha) const {
Lloyd Pique144e1162017-12-20 16:44:52 -0800688 auto& engine(mFlinger->getRenderEngine());
David Sodman9eeae692017-11-02 10:53:32 -0700689 computeGeometry(renderArea, getBE().mMesh, false);
Mathias Agopian19733a32013-08-28 18:13:56 -0700690 engine.setupFillWithColor(red, green, blue, alpha);
David Sodman9eeae692017-11-02 10:53:32 -0700691 engine.drawMesh(getBE().mMesh);
Mathias Agopian13127d82013-03-05 17:47:11 -0800692}
693
chaviwa76b2712017-09-20 12:02:26 -0700694void Layer::clearWithOpenGL(const RenderArea& renderArea) const {
David Sodman41fdfc92017-11-06 16:09:56 -0800695 clearWithOpenGL(renderArea, 0, 0, 0, 0);
Mathias Agopian13127d82013-03-05 17:47:11 -0800696}
697
David Sodman56912832017-11-28 10:27:38 -0800698void Layer::setCompositionType(int32_t /*hwcId*/, HWC2::Composition type, bool /*callIntoHwc*/) {
699 if (getBE().compositionInfo.compositionType != type) {
700 ALOGV("setCompositionType: Changing compositionType from %s to %s",
701 to_string(getBE().compositionInfo.compositionType).c_str(),
702 to_string(type).c_str());
703 getBE().compositionInfo.compositionType = type;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800704 }
705}
706
707HWC2::Composition Layer::getCompositionType(int32_t hwcId) const {
Dan Stozaec0f7172016-07-21 11:09:40 -0700708 if (hwcId == DisplayDevice::DISPLAY_ID_INVALID) {
709 // If we're querying the composition type for a display that does not
710 // have a HWC counterpart, then it will always be Client
711 return HWC2::Composition::Client;
712 }
David Sodman56912832017-11-28 10:27:38 -0800713 return getBE().compositionInfo.compositionType;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800714}
715
716void Layer::setClearClientTarget(int32_t hwcId, bool clear) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700717 if (getBE().mHwcLayers.count(hwcId) == 0) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800718 ALOGE("setClearClientTarget called without a valid HWC layer");
719 return;
720 }
David Sodman6f65f3e2017-11-03 14:28:09 -0700721 getBE().mHwcLayers[hwcId].clearClientTarget = clear;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800722}
723
724bool Layer::getClearClientTarget(int32_t hwcId) const {
David Sodman6f65f3e2017-11-03 14:28:09 -0700725 if (getBE().mHwcLayers.count(hwcId) == 0) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800726 ALOGE("getClearClientTarget called without a valid HWC layer");
727 return false;
728 }
David Sodman6f65f3e2017-11-03 14:28:09 -0700729 return getBE().mHwcLayers.at(hwcId).clearClientTarget;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800730}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800731
Dan Stozacac35382016-01-27 12:21:06 -0800732bool Layer::addSyncPoint(const std::shared_ptr<SyncPoint>& point) {
733 if (point->getFrameNumber() <= mCurrentFrameNumber) {
734 // Don't bother with a SyncPoint, since we've already latched the
735 // relevant frame
736 return false;
Dan Stoza7dde5992015-05-22 09:51:44 -0700737 }
738
Dan Stozacac35382016-01-27 12:21:06 -0800739 Mutex::Autolock lock(mLocalSyncPointMutex);
740 mLocalSyncPoints.push_back(point);
741 return true;
Dan Stoza7dde5992015-05-22 09:51:44 -0700742}
743
Mathias Agopian13127d82013-03-05 17:47:11 -0800744void Layer::setFiltering(bool filtering) {
745 mFiltering = filtering;
746}
747
748bool Layer::getFiltering() const {
749 return mFiltering;
750}
751
Mathias Agopian13127d82013-03-05 17:47:11 -0800752// ----------------------------------------------------------------------------
753// local state
754// ----------------------------------------------------------------------------
755
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000756static void boundPoint(vec2* point, const Rect& crop) {
757 if (point->x < crop.left) {
758 point->x = crop.left;
759 }
760 if (point->x > crop.right) {
761 point->x = crop.right;
762 }
763 if (point->y < crop.top) {
764 point->y = crop.top;
765 }
766 if (point->y > crop.bottom) {
767 point->y = crop.bottom;
768 }
769}
770
chaviwa76b2712017-09-20 12:02:26 -0700771void Layer::computeGeometry(const RenderArea& renderArea, Mesh& mesh,
772 bool useIdentityTransform) const {
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700773 const Layer::State& s(getDrawingState());
chaviwa76b2712017-09-20 12:02:26 -0700774 const Transform renderAreaTransform(renderArea.getTransform());
775 const uint32_t height = renderArea.getHeight();
Dan Stoza80d61162017-12-20 15:57:52 -0800776 FloatRect win = computeBounds();
Mathias Agopian3f844832013-08-07 21:24:32 -0700777
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000778 vec2 lt = vec2(win.left, win.top);
779 vec2 lb = vec2(win.left, win.bottom);
780 vec2 rb = vec2(win.right, win.bottom);
781 vec2 rt = vec2(win.right, win.top);
782
Robert Carr1f0a16a2016-10-24 16:27:39 -0700783 Transform layerTransform = getTransform();
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000784 if (!useIdentityTransform) {
Robert Carr1f0a16a2016-10-24 16:27:39 -0700785 lt = layerTransform.transform(lt);
786 lb = layerTransform.transform(lb);
787 rb = layerTransform.transform(rb);
788 rt = layerTransform.transform(rt);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000789 }
790
Robert Carrb5d3d262016-03-25 15:08:13 -0700791 if (!s.finalCrop.isEmpty()) {
792 boundPoint(&lt, s.finalCrop);
793 boundPoint(&lb, s.finalCrop);
794 boundPoint(&rb, s.finalCrop);
795 boundPoint(&rt, s.finalCrop);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000796 }
797
Mathias Agopianff2ed702013-09-01 21:36:12 -0700798 Mesh::VertexArray<vec2> position(mesh.getPositionArray<vec2>());
chaviwa76b2712017-09-20 12:02:26 -0700799 position[0] = renderAreaTransform.transform(lt);
800 position[1] = renderAreaTransform.transform(lb);
801 position[2] = renderAreaTransform.transform(rb);
802 position[3] = renderAreaTransform.transform(rt);
David Sodman41fdfc92017-11-06 16:09:56 -0800803 for (size_t i = 0; i < 4; i++) {
chaviwa76b2712017-09-20 12:02:26 -0700804 position[i].y = height - position[i].y;
Mathias Agopian13127d82013-03-05 17:47:11 -0800805 }
806}
Eric Hassoldac45e6b2011-02-10 14:41:26 -0800807
David Sodman41fdfc92017-11-06 16:09:56 -0800808bool Layer::isSecure() const {
Dan Stoza23116082015-06-18 14:58:39 -0700809 const Layer::State& s(mDrawingState);
810 return (s.flags & layer_state_t::eLayerSecure);
811}
812
Mathias Agopian13127d82013-03-05 17:47:11 -0800813void Layer::setVisibleRegion(const Region& visibleRegion) {
814 // always called from main thread
815 this->visibleRegion = visibleRegion;
816}
817
818void Layer::setCoveredRegion(const Region& coveredRegion) {
819 // always called from main thread
820 this->coveredRegion = coveredRegion;
821}
822
David Sodman41fdfc92017-11-06 16:09:56 -0800823void Layer::setVisibleNonTransparentRegion(const Region& setVisibleNonTransparentRegion) {
Mathias Agopian13127d82013-03-05 17:47:11 -0800824 // always called from main thread
825 this->visibleNonTransparentRegion = setVisibleNonTransparentRegion;
826}
827
Robert Carre5f4f692018-01-12 13:12:28 -0800828void Layer::clearVisibilityRegions() {
829 visibleRegion.clear();
830 visibleNonTransparentRegion.clear();
831 coveredRegion.clear();
832}
833
Mathias Agopian13127d82013-03-05 17:47:11 -0800834// ----------------------------------------------------------------------------
835// transaction
836// ----------------------------------------------------------------------------
837
Dan Stoza7dde5992015-05-22 09:51:44 -0700838void Layer::pushPendingState() {
839 if (!mCurrentState.modified) {
840 return;
841 }
842
Dan Stoza7dde5992015-05-22 09:51:44 -0700843 // If this transaction is waiting on the receipt of a frame, generate a sync
844 // point and send it to the remote layer.
Robert Carr0d480722017-01-10 16:42:54 -0800845 if (mCurrentState.barrierLayer != nullptr) {
846 sp<Layer> barrierLayer = mCurrentState.barrierLayer.promote();
847 if (barrierLayer == nullptr) {
848 ALOGE("[%s] Unable to promote barrier Layer.", mName.string());
Dan Stoza7dde5992015-05-22 09:51:44 -0700849 // If we can't promote the layer we are intended to wait on,
850 // then it is expired or otherwise invalid. Allow this transaction
851 // to be applied as per normal (no synchronization).
Robert Carr0d480722017-01-10 16:42:54 -0800852 mCurrentState.barrierLayer = nullptr;
Pablo Ceballos3bddd5b2015-11-19 14:39:14 -0800853 } else {
David Sodman41fdfc92017-11-06 16:09:56 -0800854 auto syncPoint = std::make_shared<SyncPoint>(mCurrentState.frameNumber);
Robert Carr0d480722017-01-10 16:42:54 -0800855 if (barrierLayer->addSyncPoint(syncPoint)) {
Dan Stozacac35382016-01-27 12:21:06 -0800856 mRemoteSyncPoints.push_back(std::move(syncPoint));
857 } else {
858 // We already missed the frame we're supposed to synchronize
859 // on, so go ahead and apply the state update
Robert Carr0d480722017-01-10 16:42:54 -0800860 mCurrentState.barrierLayer = nullptr;
Dan Stozacac35382016-01-27 12:21:06 -0800861 }
Dan Stoza7dde5992015-05-22 09:51:44 -0700862 }
863
Dan Stoza7dde5992015-05-22 09:51:44 -0700864 // Wake us up to check if the frame has been received
865 setTransactionFlags(eTransactionNeeded);
Dan Stozaf5702ff2016-11-02 16:27:47 -0700866 mFlinger->setTransactionFlags(eTraversalNeeded);
Dan Stoza7dde5992015-05-22 09:51:44 -0700867 }
868 mPendingStates.push_back(mCurrentState);
Dan Stozaf7ba41a2017-05-10 15:11:11 -0700869 ATRACE_INT(mTransactionName.string(), mPendingStates.size());
Dan Stoza7dde5992015-05-22 09:51:44 -0700870}
871
Pablo Ceballos05289c22016-04-14 15:49:55 -0700872void Layer::popPendingState(State* stateToCommit) {
873 auto oldFlags = stateToCommit->flags;
874 *stateToCommit = mPendingStates[0];
David Sodman41fdfc92017-11-06 16:09:56 -0800875 stateToCommit->flags =
876 (oldFlags & ~stateToCommit->mask) | (stateToCommit->flags & stateToCommit->mask);
Dan Stoza7dde5992015-05-22 09:51:44 -0700877
878 mPendingStates.removeAt(0);
Dan Stozaf7ba41a2017-05-10 15:11:11 -0700879 ATRACE_INT(mTransactionName.string(), mPendingStates.size());
Dan Stoza7dde5992015-05-22 09:51:44 -0700880}
881
Pablo Ceballos05289c22016-04-14 15:49:55 -0700882bool Layer::applyPendingStates(State* stateToCommit) {
Dan Stoza7dde5992015-05-22 09:51:44 -0700883 bool stateUpdateAvailable = false;
884 while (!mPendingStates.empty()) {
Robert Carr0d480722017-01-10 16:42:54 -0800885 if (mPendingStates[0].barrierLayer != nullptr) {
Dan Stoza7dde5992015-05-22 09:51:44 -0700886 if (mRemoteSyncPoints.empty()) {
887 // If we don't have a sync point for this, apply it anyway. It
888 // will be visually wrong, but it should keep us from getting
889 // into too much trouble.
890 ALOGE("[%s] No local sync point found", mName.string());
Pablo Ceballos05289c22016-04-14 15:49:55 -0700891 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -0700892 stateUpdateAvailable = true;
893 continue;
894 }
895
David Sodman41fdfc92017-11-06 16:09:56 -0800896 if (mRemoteSyncPoints.front()->getFrameNumber() != mPendingStates[0].frameNumber) {
897 ALOGE("[%s] Unexpected sync point frame number found", mName.string());
Dan Stozacac35382016-01-27 12:21:06 -0800898
899 // Signal our end of the sync point and then dispose of it
900 mRemoteSyncPoints.front()->setTransactionApplied();
901 mRemoteSyncPoints.pop_front();
902 continue;
903 }
904
Dan Stoza7dde5992015-05-22 09:51:44 -0700905 if (mRemoteSyncPoints.front()->frameIsAvailable()) {
906 // Apply the state update
Pablo Ceballos05289c22016-04-14 15:49:55 -0700907 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -0700908 stateUpdateAvailable = true;
909
910 // Signal our end of the sync point and then dispose of it
911 mRemoteSyncPoints.front()->setTransactionApplied();
912 mRemoteSyncPoints.pop_front();
Dan Stoza792e5292016-02-11 11:43:58 -0800913 } else {
914 break;
Dan Stoza7dde5992015-05-22 09:51:44 -0700915 }
Dan Stoza7dde5992015-05-22 09:51:44 -0700916 } else {
Pablo Ceballos05289c22016-04-14 15:49:55 -0700917 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -0700918 stateUpdateAvailable = true;
919 }
920 }
921
922 // If we still have pending updates, wake SurfaceFlinger back up and point
923 // it at this layer so we can process them
924 if (!mPendingStates.empty()) {
925 setTransactionFlags(eTransactionNeeded);
926 mFlinger->setTransactionFlags(eTraversalNeeded);
927 }
928
929 mCurrentState.modified = false;
930 return stateUpdateAvailable;
931}
932
Mathias Agopian13127d82013-03-05 17:47:11 -0800933uint32_t Layer::doTransaction(uint32_t flags) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800934 ATRACE_CALL();
935
Dan Stoza7dde5992015-05-22 09:51:44 -0700936 pushPendingState();
Pablo Ceballos05289c22016-04-14 15:49:55 -0700937 Layer::State c = getCurrentState();
938 if (!applyPendingStates(&c)) {
Dan Stoza7dde5992015-05-22 09:51:44 -0700939 return 0;
940 }
941
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700942 const Layer::State& s(getDrawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800943
David Sodman41fdfc92017-11-06 16:09:56 -0800944 const bool sizeChanged = (c.requested.w != s.requested.w) || (c.requested.h != s.requested.h);
Mathias Agopiana138f892010-05-21 17:24:35 -0700945
David Sodmaneb085e02017-10-05 18:49:04 -0700946 if (sizeChanged) {
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700947 // the size changed, we need to ask our client to request a new buffer
Steve Block9d453682011-12-20 16:23:08 +0000948 ALOGD_IF(DEBUG_RESIZE,
David Sodman41fdfc92017-11-06 16:09:56 -0800949 "doTransaction: geometry (layer=%p '%s'), tr=%02x, scalingMode=%d\n"
950 " current={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
951 " requested={ wh={%4u,%4u} }}\n"
952 " drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
953 " requested={ wh={%4u,%4u} }}\n",
David Sodman9eeae692017-11-02 10:53:32 -0700954 this, getName().string(), mCurrentTransform,
955 getEffectiveScalingMode(), c.active.w, c.active.h, c.crop.left, c.crop.top,
956 c.crop.right, c.crop.bottom, c.crop.getWidth(), c.crop.getHeight(), c.requested.w,
957 c.requested.h, s.active.w, s.active.h, s.crop.left, s.crop.top, s.crop.right,
958 s.crop.bottom, s.crop.getWidth(), s.crop.getHeight(), s.requested.w,
959 s.requested.h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800960
Jamie Gennis2a0d5b62011-09-26 16:54:44 -0700961 // record the new size, form this point on, when the client request
962 // a buffer, it'll get the new size.
David Sodmaneb085e02017-10-05 18:49:04 -0700963 setDefaultBufferSize(c.requested.w, c.requested.h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800964 }
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700965
Robert Carre392b552017-09-19 12:16:05 -0700966 // Don't let Layer::doTransaction update the drawing state
967 // if we have a pending resize, unless we are in fixed-size mode.
968 // the drawing state will be updated only once we receive a buffer
969 // with the correct size.
970 //
971 // In particular, we want to make sure the clip (which is part
972 // of the geometry state) is latched together with the size but is
973 // latched immediately when no resizing is involved.
974 //
975 // If a sideband stream is attached, however, we want to skip this
976 // optimization so that transactions aren't missed when a buffer
977 // never arrives
978 //
979 // In the case that we don't have a buffer we ignore other factors
980 // and avoid entering the resizePending state. At a high level the
981 // resizePending state is to avoid applying the state of the new buffer
982 // to the old buffer. However in the state where we don't have an old buffer
983 // there is no such concern but we may still be being used as a parent layer.
David Sodman41fdfc92017-11-06 16:09:56 -0800984 const bool resizePending = ((c.requested.w != c.active.w) || (c.requested.h != c.active.h)) &&
David Sodman0cc69182017-11-17 12:12:07 -0800985 (getBE().compositionInfo.mBuffer != nullptr);
Mathias Agopian0cd545f2012-06-07 14:18:55 -0700986 if (!isFixedSize()) {
David Sodman0cc69182017-11-17 12:12:07 -0800987 if (resizePending && getBE().compositionInfo.hwc.sidebandStream == nullptr) {
Mathias Agopian0cd545f2012-06-07 14:18:55 -0700988 flags |= eDontUpdateGeometryState;
989 }
990 }
991
Robert Carr7bf247e2017-05-18 14:02:49 -0700992 // Here we apply various requested geometry states, depending on our
993 // latching configuration. See Layer.h for a detailed discussion of
994 // how geometry latching is controlled.
995 if (!(flags & eDontUpdateGeometryState)) {
Pablo Ceballos7d052572016-06-02 17:46:05 -0700996 Layer::State& editCurrentState(getCurrentState());
Robert Carr7bf247e2017-05-18 14:02:49 -0700997
998 // If mFreezeGeometryUpdates is true we are in the setGeometryAppliesWithResize
999 // mode, which causes attributes which normally latch regardless of scaling mode,
1000 // to be delayed. We copy the requested state to the active state making sure
1001 // to respect these rules (again see Layer.h for a detailed discussion).
1002 //
1003 // There is an awkward asymmetry in the handling of the crop states in the position
1004 // states, as can be seen below. Largely this arises from position and transform
1005 // being stored in the same data structure while having different latching rules.
1006 // b/38182305
1007 //
1008 // Careful that "c" and editCurrentState may not begin as equivalent due to
1009 // applyPendingStates in the presence of deferred transactions.
1010 if (mFreezeGeometryUpdates) {
Robert Carr82364e32016-05-15 11:27:47 -07001011 float tx = c.active.transform.tx();
1012 float ty = c.active.transform.ty();
1013 c.active = c.requested;
1014 c.active.transform.set(tx, ty);
1015 editCurrentState.active = c.active;
1016 } else {
1017 editCurrentState.active = editCurrentState.requested;
1018 c.active = c.requested;
1019 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001020 }
1021
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001022 if (s.active != c.active) {
Mathias Agopian13127d82013-03-05 17:47:11 -08001023 // invalidate and recompute the visible regions if needed
1024 flags |= Layer::eVisibleRegion;
1025 }
1026
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001027 if (c.sequence != s.sequence) {
Mathias Agopian13127d82013-03-05 17:47:11 -08001028 // invalidate and recompute the visible regions if needed
1029 flags |= eVisibleRegion;
1030 this->contentDirty = true;
1031
1032 // we may use linear filtering, if the matrix scales us
Robert Carr3dcabfa2016-03-01 18:36:58 -08001033 const uint8_t type = c.active.transform.getType();
David Sodman41fdfc92017-11-06 16:09:56 -08001034 mNeedsFiltering = (!c.active.transform.preserveRects() || (type >= Transform::SCALE));
Mathias Agopian13127d82013-03-05 17:47:11 -08001035 }
1036
Dan Stozac8145172016-04-28 16:29:06 -07001037 // If the layer is hidden, signal and clear out all local sync points so
1038 // that transactions for layers depending on this layer's frames becoming
1039 // visible are not blocked
1040 if (c.flags & layer_state_t::eLayerHidden) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001041 clearSyncPoints();
Dan Stozac8145172016-04-28 16:29:06 -07001042 }
1043
Mathias Agopian13127d82013-03-05 17:47:11 -08001044 // Commit the transaction
Pablo Ceballos05289c22016-04-14 15:49:55 -07001045 commitTransaction(c);
Mathias Agopian13127d82013-03-05 17:47:11 -08001046 return flags;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001047}
1048
Pablo Ceballos05289c22016-04-14 15:49:55 -07001049void Layer::commitTransaction(const State& stateToCommit) {
1050 mDrawingState = stateToCommit;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001051}
1052
Mathias Agopian13127d82013-03-05 17:47:11 -08001053uint32_t Layer::getTransactionFlags(uint32_t flags) {
1054 return android_atomic_and(~flags, &mTransactionFlags) & flags;
1055}
1056
1057uint32_t Layer::setTransactionFlags(uint32_t flags) {
1058 return android_atomic_or(flags, &mTransactionFlags);
1059}
1060
Robert Carr82364e32016-05-15 11:27:47 -07001061bool Layer::setPosition(float x, float y, bool immediate) {
Robert Carr3dcabfa2016-03-01 18:36:58 -08001062 if (mCurrentState.requested.transform.tx() == x && mCurrentState.requested.transform.ty() == y)
Mathias Agopian13127d82013-03-05 17:47:11 -08001063 return false;
1064 mCurrentState.sequence++;
Robert Carr69663fb2016-03-27 19:59:19 -07001065
1066 // We update the requested and active position simultaneously because
1067 // we want to apply the position portion of the transform matrix immediately,
1068 // but still delay scaling when resizing a SCALING_MODE_FREEZE layer.
Robert Carr3dcabfa2016-03-01 18:36:58 -08001069 mCurrentState.requested.transform.set(x, y);
Robert Carr7bf247e2017-05-18 14:02:49 -07001070 if (immediate && !mFreezeGeometryUpdates) {
1071 // Here we directly update the active state
1072 // unlike other setters, because we store it within
1073 // the transform, but use different latching rules.
1074 // b/38182305
Robert Carr82364e32016-05-15 11:27:47 -07001075 mCurrentState.active.transform.set(x, y);
1076 }
Robert Carr7bf247e2017-05-18 14:02:49 -07001077 mFreezeGeometryUpdates = mFreezeGeometryUpdates || !immediate;
Robert Carr69663fb2016-03-27 19:59:19 -07001078
Dan Stoza7dde5992015-05-22 09:51:44 -07001079 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001080 setTransactionFlags(eTransactionNeeded);
1081 return true;
1082}
Robert Carr82364e32016-05-15 11:27:47 -07001083
Robert Carr1f0a16a2016-10-24 16:27:39 -07001084bool Layer::setChildLayer(const sp<Layer>& childLayer, int32_t z) {
1085 ssize_t idx = mCurrentChildren.indexOf(childLayer);
1086 if (idx < 0) {
1087 return false;
1088 }
1089 if (childLayer->setLayer(z)) {
1090 mCurrentChildren.removeAt(idx);
1091 mCurrentChildren.add(childLayer);
Robert Carr503d2bd2017-12-04 15:49:47 -08001092 return true;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001093 }
Robert Carr503d2bd2017-12-04 15:49:47 -08001094 return false;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001095}
1096
Robert Carr503c7042017-09-27 15:06:08 -07001097bool Layer::setChildRelativeLayer(const sp<Layer>& childLayer,
1098 const sp<IBinder>& relativeToHandle, int32_t relativeZ) {
1099 ssize_t idx = mCurrentChildren.indexOf(childLayer);
1100 if (idx < 0) {
1101 return false;
1102 }
1103 if (childLayer->setRelativeLayer(relativeToHandle, relativeZ)) {
1104 mCurrentChildren.removeAt(idx);
1105 mCurrentChildren.add(childLayer);
Robert Carr503d2bd2017-12-04 15:49:47 -08001106 return true;
Robert Carr503c7042017-09-27 15:06:08 -07001107 }
Robert Carr503d2bd2017-12-04 15:49:47 -08001108 return false;
Robert Carr503c7042017-09-27 15:06:08 -07001109}
1110
Robert Carrae060832016-11-28 10:51:00 -08001111bool Layer::setLayer(int32_t z) {
Robert Carr503d2bd2017-12-04 15:49:47 -08001112 if (mCurrentState.z == z && !usingRelativeZ(LayerVector::StateSet::Current)) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001113 mCurrentState.sequence++;
1114 mCurrentState.z = z;
Dan Stoza7dde5992015-05-22 09:51:44 -07001115 mCurrentState.modified = true;
Robert Carrdb66e622017-04-10 16:55:57 -07001116
1117 // Discard all relative layering.
1118 if (mCurrentState.zOrderRelativeOf != nullptr) {
1119 sp<Layer> strongRelative = mCurrentState.zOrderRelativeOf.promote();
1120 if (strongRelative != nullptr) {
1121 strongRelative->removeZOrderRelative(this);
1122 }
1123 mCurrentState.zOrderRelativeOf = nullptr;
1124 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001125 setTransactionFlags(eTransactionNeeded);
1126 return true;
1127}
Robert Carr1f0a16a2016-10-24 16:27:39 -07001128
Robert Carrdb66e622017-04-10 16:55:57 -07001129void Layer::removeZOrderRelative(const wp<Layer>& relative) {
1130 mCurrentState.zOrderRelatives.remove(relative);
1131 mCurrentState.sequence++;
1132 mCurrentState.modified = true;
1133 setTransactionFlags(eTransactionNeeded);
1134}
1135
1136void Layer::addZOrderRelative(const wp<Layer>& relative) {
1137 mCurrentState.zOrderRelatives.add(relative);
1138 mCurrentState.modified = true;
1139 mCurrentState.sequence++;
1140 setTransactionFlags(eTransactionNeeded);
1141}
1142
Robert Carr503d2bd2017-12-04 15:49:47 -08001143bool Layer::setRelativeLayer(const sp<IBinder>& relativeToHandle, int32_t relativeZ) {
Robert Carrdb66e622017-04-10 16:55:57 -07001144 sp<Handle> handle = static_cast<Handle*>(relativeToHandle.get());
1145 if (handle == nullptr) {
1146 return false;
1147 }
1148 sp<Layer> relative = handle->owner.promote();
1149 if (relative == nullptr) {
1150 return false;
1151 }
1152
Robert Carr503d2bd2017-12-04 15:49:47 -08001153 if (mCurrentState.z == relativeZ && usingRelativeZ(LayerVector::StateSet::Current) &&
1154 mCurrentState.zOrderRelativeOf == relative) {
1155 return false;
1156 }
1157
Robert Carrdb66e622017-04-10 16:55:57 -07001158 mCurrentState.sequence++;
1159 mCurrentState.modified = true;
Robert Carr503d2bd2017-12-04 15:49:47 -08001160 mCurrentState.z = relativeZ;
Robert Carrdb66e622017-04-10 16:55:57 -07001161
chaviw9ab4bd12017-11-03 13:11:00 -07001162 auto oldZOrderRelativeOf = mCurrentState.zOrderRelativeOf.promote();
1163 if (oldZOrderRelativeOf != nullptr) {
1164 oldZOrderRelativeOf->removeZOrderRelative(this);
1165 }
Robert Carrdb66e622017-04-10 16:55:57 -07001166 mCurrentState.zOrderRelativeOf = relative;
1167 relative->addZOrderRelative(this);
1168
1169 setTransactionFlags(eTransactionNeeded);
1170
1171 return true;
1172}
1173
Mathias Agopian13127d82013-03-05 17:47:11 -08001174bool Layer::setSize(uint32_t w, uint32_t h) {
David Sodman41fdfc92017-11-06 16:09:56 -08001175 if (mCurrentState.requested.w == w && mCurrentState.requested.h == h) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001176 mCurrentState.requested.w = w;
1177 mCurrentState.requested.h = h;
Dan Stoza7dde5992015-05-22 09:51:44 -07001178 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001179 setTransactionFlags(eTransactionNeeded);
1180 return true;
1181}
Dan Stoza9e56aa02015-11-02 13:00:03 -08001182bool Layer::setAlpha(float alpha) {
David Sodman41fdfc92017-11-06 16:09:56 -08001183 if (mCurrentState.color.a == alpha) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001184 mCurrentState.sequence++;
chaviw13fdc492017-06-27 12:40:18 -07001185 mCurrentState.color.a = alpha;
Dan Stoza7dde5992015-05-22 09:51:44 -07001186 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001187 setTransactionFlags(eTransactionNeeded);
1188 return true;
1189}
chaviw13fdc492017-06-27 12:40:18 -07001190
1191bool Layer::setColor(const half3& color) {
David Sodman41fdfc92017-11-06 16:09:56 -08001192 if (color.r == mCurrentState.color.r && color.g == mCurrentState.color.g &&
1193 color.b == mCurrentState.color.b)
chaviw13fdc492017-06-27 12:40:18 -07001194 return false;
1195
1196 mCurrentState.sequence++;
1197 mCurrentState.color.r = color.r;
1198 mCurrentState.color.g = color.g;
1199 mCurrentState.color.b = color.b;
1200 mCurrentState.modified = true;
1201 setTransactionFlags(eTransactionNeeded);
1202 return true;
1203}
1204
Mathias Agopian13127d82013-03-05 17:47:11 -08001205bool Layer::setMatrix(const layer_state_t::matrix22_t& matrix) {
1206 mCurrentState.sequence++;
David Sodman41fdfc92017-11-06 16:09:56 -08001207 mCurrentState.requested.transform.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
Dan Stoza7dde5992015-05-22 09:51:44 -07001208 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001209 setTransactionFlags(eTransactionNeeded);
1210 return true;
1211}
1212bool Layer::setTransparentRegionHint(const Region& transparent) {
Mathias Agopian2ca79392013-04-02 18:30:32 -07001213 mCurrentState.requestedTransparentRegion = transparent;
Dan Stoza7dde5992015-05-22 09:51:44 -07001214 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001215 setTransactionFlags(eTransactionNeeded);
1216 return true;
1217}
1218bool Layer::setFlags(uint8_t flags, uint8_t mask) {
1219 const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask);
David Sodman41fdfc92017-11-06 16:09:56 -08001220 if (mCurrentState.flags == newFlags) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001221 mCurrentState.sequence++;
1222 mCurrentState.flags = newFlags;
Dan Stoza7dde5992015-05-22 09:51:44 -07001223 mCurrentState.mask = mask;
1224 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001225 setTransactionFlags(eTransactionNeeded);
1226 return true;
1227}
Robert Carr99e27f02016-06-16 15:18:02 -07001228
1229bool Layer::setCrop(const Rect& crop, bool immediate) {
David Sodman41fdfc92017-11-06 16:09:56 -08001230 if (mCurrentState.requestedCrop == crop) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001231 mCurrentState.sequence++;
Robert Carr99e27f02016-06-16 15:18:02 -07001232 mCurrentState.requestedCrop = crop;
Robert Carr7bf247e2017-05-18 14:02:49 -07001233 if (immediate && !mFreezeGeometryUpdates) {
Robert Carr99e27f02016-06-16 15:18:02 -07001234 mCurrentState.crop = crop;
1235 }
Robert Carr7bf247e2017-05-18 14:02:49 -07001236 mFreezeGeometryUpdates = mFreezeGeometryUpdates || !immediate;
1237
Dan Stoza7dde5992015-05-22 09:51:44 -07001238 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001239 setTransactionFlags(eTransactionNeeded);
1240 return true;
1241}
Robert Carr8d5227b2017-03-16 15:41:03 -07001242
1243bool Layer::setFinalCrop(const Rect& crop, bool immediate) {
David Sodman41fdfc92017-11-06 16:09:56 -08001244 if (mCurrentState.requestedFinalCrop == crop) return false;
Pablo Ceballosacbe6782016-03-04 17:54:21 +00001245 mCurrentState.sequence++;
Robert Carr8d5227b2017-03-16 15:41:03 -07001246 mCurrentState.requestedFinalCrop = crop;
Robert Carr7bf247e2017-05-18 14:02:49 -07001247 if (immediate && !mFreezeGeometryUpdates) {
Robert Carr8d5227b2017-03-16 15:41:03 -07001248 mCurrentState.finalCrop = crop;
1249 }
Robert Carr7bf247e2017-05-18 14:02:49 -07001250 mFreezeGeometryUpdates = mFreezeGeometryUpdates || !immediate;
1251
Pablo Ceballosacbe6782016-03-04 17:54:21 +00001252 mCurrentState.modified = true;
1253 setTransactionFlags(eTransactionNeeded);
1254 return true;
1255}
Mathias Agopian13127d82013-03-05 17:47:11 -08001256
Robert Carrc3574f72016-03-24 12:19:32 -07001257bool Layer::setOverrideScalingMode(int32_t scalingMode) {
David Sodman41fdfc92017-11-06 16:09:56 -08001258 if (scalingMode == mOverrideScalingMode) return false;
Robert Carrc3574f72016-03-24 12:19:32 -07001259 mOverrideScalingMode = scalingMode;
Robert Carr82364e32016-05-15 11:27:47 -07001260 setTransactionFlags(eTransactionNeeded);
Robert Carrc3574f72016-03-24 12:19:32 -07001261 return true;
1262}
1263
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -05001264void Layer::setInfo(uint32_t type, uint32_t appId) {
David Sodman41fdfc92017-11-06 16:09:56 -08001265 mCurrentState.appId = appId;
1266 mCurrentState.type = type;
1267 mCurrentState.modified = true;
1268 setTransactionFlags(eTransactionNeeded);
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -05001269}
1270
Mathias Agopian13127d82013-03-05 17:47:11 -08001271bool Layer::setLayerStack(uint32_t layerStack) {
David Sodman41fdfc92017-11-06 16:09:56 -08001272 if (mCurrentState.layerStack == layerStack) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001273 mCurrentState.sequence++;
1274 mCurrentState.layerStack = layerStack;
Dan Stoza7dde5992015-05-22 09:51:44 -07001275 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001276 setTransactionFlags(eTransactionNeeded);
1277 return true;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001278}
1279
Courtney Goeltzenleuchterbb09b432016-11-30 13:51:28 -07001280bool Layer::setDataSpace(android_dataspace dataSpace) {
David Sodman41fdfc92017-11-06 16:09:56 -08001281 if (mCurrentState.dataSpace == dataSpace) return false;
Courtney Goeltzenleuchterbb09b432016-11-30 13:51:28 -07001282 mCurrentState.sequence++;
1283 mCurrentState.dataSpace = dataSpace;
1284 mCurrentState.modified = true;
1285 setTransactionFlags(eTransactionNeeded);
1286 return true;
1287}
1288
Courtney Goeltzenleuchter532b2632017-05-05 16:34:38 -06001289android_dataspace Layer::getDataSpace() const {
1290 return mCurrentState.dataSpace;
1291}
1292
Robert Carr1f0a16a2016-10-24 16:27:39 -07001293uint32_t Layer::getLayerStack() const {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001294 auto p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001295 if (p == nullptr) {
1296 return getDrawingState().layerStack;
1297 }
1298 return p->getLayerStack();
1299}
1300
David Sodman41fdfc92017-11-06 16:09:56 -08001301void Layer::deferTransactionUntil(const sp<Layer>& barrierLayer, uint64_t frameNumber) {
Robert Carr0d480722017-01-10 16:42:54 -08001302 mCurrentState.barrierLayer = barrierLayer;
Dan Stoza7dde5992015-05-22 09:51:44 -07001303 mCurrentState.frameNumber = frameNumber;
1304 // We don't set eTransactionNeeded, because just receiving a deferral
1305 // request without any other state updates shouldn't actually induce a delay
1306 mCurrentState.modified = true;
1307 pushPendingState();
Robert Carr0d480722017-01-10 16:42:54 -08001308 mCurrentState.barrierLayer = nullptr;
Dan Stoza792e5292016-02-11 11:43:58 -08001309 mCurrentState.frameNumber = 0;
Dan Stoza7dde5992015-05-22 09:51:44 -07001310 mCurrentState.modified = false;
Robert Carr0d480722017-01-10 16:42:54 -08001311}
1312
David Sodman41fdfc92017-11-06 16:09:56 -08001313void Layer::deferTransactionUntil(const sp<IBinder>& barrierHandle, uint64_t frameNumber) {
Robert Carr0d480722017-01-10 16:42:54 -08001314 sp<Handle> handle = static_cast<Handle*>(barrierHandle.get());
1315 deferTransactionUntil(handle->owner.promote(), frameNumber);
Dan Stoza7dde5992015-05-22 09:51:44 -07001316}
1317
Dan Stozaee44edd2015-03-23 15:50:23 -07001318
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001319// ----------------------------------------------------------------------------
1320// pageflip handling...
1321// ----------------------------------------------------------------------------
1322
Robert Carr1f0a16a2016-10-24 16:27:39 -07001323bool Layer::isHiddenByPolicy() const {
1324 const Layer::State& s(mDrawingState);
Chia-I Wue41dbe62017-06-13 14:10:56 -07001325 const auto& parent = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001326 if (parent != nullptr && parent->isHiddenByPolicy()) {
1327 return true;
1328 }
1329 return s.flags & layer_state_t::eLayerHidden;
1330}
1331
David Sodman41fdfc92017-11-06 16:09:56 -08001332uint32_t Layer::getEffectiveUsage(uint32_t usage) const {
Mathias Agopiana67932f2011-04-20 14:20:59 -07001333 // TODO: should we do something special if mSecure is set?
1334 if (mProtectedByApp) {
1335 // need a hardware-protected path to external video sink
1336 usage |= GraphicBuffer::USAGE_PROTECTED;
Jamie Gennis54cc83e2010-11-02 11:51:32 -07001337 }
Riley Andrews03414a12014-07-01 14:22:59 -07001338 if (mPotentialCursor) {
1339 usage |= GraphicBuffer::USAGE_CURSOR;
1340 }
Jamie Gennis3599bf22011-08-10 11:48:07 -07001341 usage |= GraphicBuffer::USAGE_HW_COMPOSER;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001342 return usage;
Mathias Agopianb5b7f262010-05-07 15:58:44 -07001343}
1344
Mathias Agopian84300952012-11-21 16:02:13 -08001345void Layer::updateTransformHint(const sp<const DisplayDevice>& hw) const {
Mathias Agopiana4583642011-08-23 18:03:18 -07001346 uint32_t orientation = 0;
1347 if (!mFlinger->mDebugDisableTransformHint) {
Mathias Agopian84300952012-11-21 16:02:13 -08001348 // The transform hint is used to improve performance, but we can
1349 // only have a single transform hint, it cannot
Mathias Agopian4fec8732012-06-29 14:12:52 -07001350 // apply to all displays.
Mathias Agopian42977342012-08-05 00:40:46 -07001351 const Transform& planeTransform(hw->getTransform());
Mathias Agopian4fec8732012-06-29 14:12:52 -07001352 orientation = planeTransform.getOrientation();
Mathias Agopiana4583642011-08-23 18:03:18 -07001353 if (orientation & Transform::ROT_INVALID) {
1354 orientation = 0;
1355 }
1356 }
David Sodmaneb085e02017-10-05 18:49:04 -07001357 setTransformHint(orientation);
Mathias Agopiana4583642011-08-23 18:03:18 -07001358}
1359
Mathias Agopian13127d82013-03-05 17:47:11 -08001360// ----------------------------------------------------------------------------
1361// debugging
1362// ----------------------------------------------------------------------------
1363
Kalle Raitaa099a242017-01-11 11:17:29 -08001364LayerDebugInfo Layer::getLayerDebugInfo() const {
1365 LayerDebugInfo info;
1366 const Layer::State& ds = getDrawingState();
1367 info.mName = getName();
chaviw1acbec72017-07-27 15:28:26 -07001368 sp<Layer> parent = getParent();
Kalle Raitaa099a242017-01-11 11:17:29 -08001369 info.mParentName = (parent == nullptr ? std::string("none") : parent->getName().string());
1370 info.mType = String8(getTypeId());
1371 info.mTransparentRegion = ds.activeTransparentRegion;
1372 info.mVisibleRegion = visibleRegion;
1373 info.mSurfaceDamageRegion = surfaceDamageRegion;
1374 info.mLayerStack = getLayerStack();
1375 info.mX = ds.active.transform.tx();
1376 info.mY = ds.active.transform.ty();
1377 info.mZ = ds.z;
1378 info.mWidth = ds.active.w;
1379 info.mHeight = ds.active.h;
1380 info.mCrop = ds.crop;
1381 info.mFinalCrop = ds.finalCrop;
chaviw13fdc492017-06-27 12:40:18 -07001382 info.mColor = ds.color;
Kalle Raitaa099a242017-01-11 11:17:29 -08001383 info.mFlags = ds.flags;
1384 info.mPixelFormat = getPixelFormat();
1385 info.mDataSpace = getDataSpace();
1386 info.mMatrix[0][0] = ds.active.transform[0][0];
1387 info.mMatrix[0][1] = ds.active.transform[0][1];
1388 info.mMatrix[1][0] = ds.active.transform[1][0];
1389 info.mMatrix[1][1] = ds.active.transform[1][1];
1390 {
David Sodman0cf8f8d2017-12-20 18:19:45 -08001391 sp<const GraphicBuffer> buffer = mActiveBuffer;
David Sodman5b4cffc2017-11-23 13:20:29 -08001392 if (buffer != 0) {
1393 info.mActiveBufferWidth = buffer->getWidth();
1394 info.mActiveBufferHeight = buffer->getHeight();
1395 info.mActiveBufferStride = buffer->getStride();
1396 info.mActiveBufferFormat = buffer->format;
Kalle Raitaa099a242017-01-11 11:17:29 -08001397 } else {
1398 info.mActiveBufferWidth = 0;
1399 info.mActiveBufferHeight = 0;
1400 info.mActiveBufferStride = 0;
1401 info.mActiveBufferFormat = 0;
1402 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001403 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001404 info.mNumQueuedFrames = getQueuedFrameCount();
1405 info.mRefreshPending = isBufferLatched();
1406 info.mIsOpaque = isOpaque(ds);
1407 info.mContentDirty = contentDirty;
1408 return info;
Mathias Agopian13127d82013-03-05 17:47:11 -08001409}
Chia-I Wu83ce7c12017-10-19 15:18:55 -07001410
Dan Stozae22aec72016-08-01 13:20:59 -07001411void Layer::miniDumpHeader(String8& result) {
1412 result.append("----------------------------------------");
1413 result.append("---------------------------------------\n");
1414 result.append(" Layer name\n");
1415 result.append(" Z | ");
1416 result.append(" Comp Type | ");
1417 result.append(" Disp Frame (LTRB) | ");
1418 result.append(" Source Crop (LTRB)\n");
1419 result.append("----------------------------------------");
1420 result.append("---------------------------------------\n");
1421}
1422
1423void Layer::miniDump(String8& result, int32_t hwcId) const {
David Sodman6f65f3e2017-11-03 14:28:09 -07001424 if (getBE().mHwcLayers.count(hwcId) == 0) {
Dan Stozae22aec72016-08-01 13:20:59 -07001425 return;
1426 }
1427
1428 String8 name;
1429 if (mName.length() > 77) {
1430 std::string shortened;
1431 shortened.append(mName.string(), 36);
1432 shortened.append("[...]");
1433 shortened.append(mName.string() + (mName.length() - 36), 36);
1434 name = shortened.c_str();
1435 } else {
1436 name = mName;
1437 }
1438
1439 result.appendFormat(" %s\n", name.string());
1440
1441 const Layer::State& layerState(getDrawingState());
John Reck8c3b6ac2017-08-24 10:25:42 -07001442 result.appendFormat(" %10d | ", layerState.z);
David Sodman41fdfc92017-11-06 16:09:56 -08001443 result.appendFormat("%10s | ", to_string(getCompositionType(hwcId)).c_str());
David Sodman4b7c4bc2017-11-17 12:13:59 -08001444 const Rect& frame = getBE().compositionInfo.hwc.displayFrame;
David Sodman41fdfc92017-11-06 16:09:56 -08001445 result.appendFormat("%4d %4d %4d %4d | ", frame.left, frame.top, frame.right, frame.bottom);
David Sodman4b7c4bc2017-11-17 12:13:59 -08001446 const FloatRect& crop = getBE().compositionInfo.hwc.sourceCrop;
David Sodman41fdfc92017-11-06 16:09:56 -08001447 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 -07001448
1449 result.append("- - - - - - - - - - - - - - - - - - - - ");
1450 result.append("- - - - - - - - - - - - - - - - - - - -\n");
1451}
Dan Stozae22aec72016-08-01 13:20:59 -07001452
Svetoslavd85084b2014-03-20 10:28:31 -07001453void Layer::dumpFrameStats(String8& result) const {
1454 mFrameTracker.dumpStats(result);
Mathias Agopian13127d82013-03-05 17:47:11 -08001455}
1456
Svetoslavd85084b2014-03-20 10:28:31 -07001457void Layer::clearFrameStats() {
1458 mFrameTracker.clearStats();
Mathias Agopian13127d82013-03-05 17:47:11 -08001459}
1460
Jamie Gennis6547ff42013-07-16 20:12:42 -07001461void Layer::logFrameStats() {
1462 mFrameTracker.logAndResetStats(mName);
1463}
1464
Svetoslavd85084b2014-03-20 10:28:31 -07001465void Layer::getFrameStats(FrameStats* outStats) const {
1466 mFrameTracker.getStats(outStats);
1467}
1468
Brian Andersond6927fb2016-07-23 23:37:30 -07001469void Layer::dumpFrameEvents(String8& result) {
David Sodman41fdfc92017-11-06 16:09:56 -08001470 result.appendFormat("- Layer %s (%s, %p)\n", getName().string(), getTypeId(), this);
Brian Andersond6927fb2016-07-23 23:37:30 -07001471 Mutex::Autolock lock(mFrameEventHistoryMutex);
1472 mFrameEventHistory.checkFencesForCompletion();
1473 mFrameEventHistory.dump(result);
1474}
Pablo Ceballos40845df2016-01-25 17:41:15 -08001475
Brian Anderson5ea5e592016-12-01 16:54:33 -08001476void Layer::onDisconnect() {
1477 Mutex::Autolock lock(mFrameEventHistoryMutex);
1478 mFrameEventHistory.onDisconnect();
1479}
1480
Brian Anderson3890c392016-07-25 12:48:08 -07001481void Layer::addAndGetFrameTimestamps(const NewFrameEventsEntry* newTimestamps,
David Sodman41fdfc92017-11-06 16:09:56 -08001482 FrameEventHistoryDelta* outDelta) {
Brian Andersond6927fb2016-07-23 23:37:30 -07001483 Mutex::Autolock lock(mFrameEventHistoryMutex);
1484 if (newTimestamps) {
Brian Andersonfbc80ae2017-05-26 16:23:54 -07001485 // If there are any unsignaled fences in the aquire timeline at this
1486 // point, the previously queued frame hasn't been latched yet. Go ahead
1487 // and try to get the signal time here so the syscall is taken out of
1488 // the main thread's critical path.
1489 mAcquireTimeline.updateSignalTimes();
1490 // Push the new fence after updating since it's likely still pending.
Brian Anderson3d4039d2016-09-23 16:31:30 -07001491 mAcquireTimeline.push(newTimestamps->acquireFence);
Brian Andersond6927fb2016-07-23 23:37:30 -07001492 mFrameEventHistory.addQueue(*newTimestamps);
1493 }
1494
Brian Anderson3890c392016-07-25 12:48:08 -07001495 if (outDelta) {
1496 mFrameEventHistory.getAndResetDelta(outDelta);
Brian Andersond6927fb2016-07-23 23:37:30 -07001497 }
Pablo Ceballos40845df2016-01-25 17:41:15 -08001498}
Dan Stozae77c7662016-05-13 11:37:28 -07001499
Chia-I Wu98f1c102017-05-30 14:54:08 -07001500size_t Layer::getChildrenCount() const {
1501 size_t count = 0;
1502 for (const sp<Layer>& child : mCurrentChildren) {
1503 count += 1 + child->getChildrenCount();
1504 }
1505 return count;
1506}
1507
Robert Carr1f0a16a2016-10-24 16:27:39 -07001508void Layer::addChild(const sp<Layer>& layer) {
1509 mCurrentChildren.add(layer);
1510 layer->setParent(this);
1511}
1512
1513ssize_t Layer::removeChild(const sp<Layer>& layer) {
1514 layer->setParent(nullptr);
1515 return mCurrentChildren.remove(layer);
1516}
1517
Robert Carr1db73f62016-12-21 12:58:51 -08001518bool Layer::reparentChildren(const sp<IBinder>& newParentHandle) {
1519 sp<Handle> handle = nullptr;
1520 sp<Layer> newParent = nullptr;
1521 if (newParentHandle == nullptr) {
1522 return false;
1523 }
1524 handle = static_cast<Handle*>(newParentHandle.get());
1525 newParent = handle->owner.promote();
1526 if (newParent == nullptr) {
1527 ALOGE("Unable to promote Layer handle");
1528 return false;
1529 }
1530
1531 for (const sp<Layer>& child : mCurrentChildren) {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001532 newParent->addChild(child);
Robert Carr1db73f62016-12-21 12:58:51 -08001533
1534 sp<Client> client(child->mClientRef.promote());
1535 if (client != nullptr) {
1536 client->setParentLayer(newParent);
1537 }
1538 }
1539 mCurrentChildren.clear();
1540
1541 return true;
1542}
1543
Robert Carr578038f2018-03-09 12:25:24 -08001544void Layer::reparentChildrenForDrawing(const sp<Layer>& newParent) {
1545 for (const sp<Layer>& child : mDrawingChildren) {
1546 child->mDrawingParent = newParent;
1547 }
1548}
1549
chaviwf1961f72017-09-18 16:41:07 -07001550bool Layer::reparent(const sp<IBinder>& newParentHandle) {
1551 if (newParentHandle == nullptr) {
chaviw06178942017-07-27 10:25:59 -07001552 return false;
1553 }
1554
1555 auto handle = static_cast<Handle*>(newParentHandle.get());
1556 sp<Layer> newParent = handle->owner.promote();
1557 if (newParent == nullptr) {
1558 ALOGE("Unable to promote Layer handle");
1559 return false;
1560 }
1561
chaviwf1961f72017-09-18 16:41:07 -07001562 sp<Layer> parent = getParent();
1563 if (parent != nullptr) {
1564 parent->removeChild(this);
chaviw06178942017-07-27 10:25:59 -07001565 }
chaviwf1961f72017-09-18 16:41:07 -07001566 newParent->addChild(this);
chaviw06178942017-07-27 10:25:59 -07001567
chaviwf1961f72017-09-18 16:41:07 -07001568 sp<Client> client(mClientRef.promote());
chaviw06178942017-07-27 10:25:59 -07001569 sp<Client> newParentClient(newParent->mClientRef.promote());
1570
chaviwf1961f72017-09-18 16:41:07 -07001571 if (client != newParentClient) {
1572 client->setParentLayer(newParent);
chaviw06178942017-07-27 10:25:59 -07001573 }
1574
chaviw06178942017-07-27 10:25:59 -07001575 return true;
1576}
1577
Robert Carr9524cb32017-02-13 11:32:32 -08001578bool Layer::detachChildren() {
Robert Carr7f619b22017-11-06 12:56:35 -08001579 for (const sp<Layer>& child : mCurrentChildren) {
chaviw161410b02017-07-27 10:46:08 -07001580 sp<Client> parentClient = mClientRef.promote();
Robert Carr9524cb32017-02-13 11:32:32 -08001581 sp<Client> client(child->mClientRef.promote());
chaviw161410b02017-07-27 10:46:08 -07001582 if (client != nullptr && parentClient != client) {
Robert Carr7f619b22017-11-06 12:56:35 -08001583 client->detachLayer(child.get());
1584 child->detachChildren();
Robert Carr9524cb32017-02-13 11:32:32 -08001585 }
Robert Carr7f619b22017-11-06 12:56:35 -08001586 }
Robert Carr9524cb32017-02-13 11:32:32 -08001587
1588 return true;
1589}
1590
Robert Carr1f0a16a2016-10-24 16:27:39 -07001591void Layer::setParent(const sp<Layer>& layer) {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001592 mCurrentParent = layer;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001593}
1594
1595void Layer::clearSyncPoints() {
1596 for (const auto& child : mCurrentChildren) {
1597 child->clearSyncPoints();
1598 }
1599
1600 Mutex::Autolock lock(mLocalSyncPointMutex);
1601 for (auto& point : mLocalSyncPoints) {
1602 point->setFrameAvailable();
1603 }
1604 mLocalSyncPoints.clear();
1605}
1606
1607int32_t Layer::getZ() const {
1608 return mDrawingState.z;
1609}
1610
Robert Carr29abff82017-12-04 13:51:20 -08001611bool Layer::usingRelativeZ(LayerVector::StateSet stateSet) {
1612 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1613 const State& state = useDrawing ? mDrawingState : mCurrentState;
1614 return state.zOrderRelativeOf != nullptr;
1615}
1616
David Sodman41fdfc92017-11-06 16:09:56 -08001617__attribute__((no_sanitize("unsigned-integer-overflow"))) LayerVector Layer::makeTraversalList(
Robert Carr29abff82017-12-04 13:51:20 -08001618 LayerVector::StateSet stateSet, bool* outSkipRelativeZUsers) {
Dan Stoza412903f2017-04-27 13:42:17 -07001619 LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid,
1620 "makeTraversalList received invalid stateSet");
1621 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1622 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
1623 const State& state = useDrawing ? mDrawingState : mCurrentState;
1624
Robert Carr29abff82017-12-04 13:51:20 -08001625 if (state.zOrderRelatives.size() == 0) {
1626 *outSkipRelativeZUsers = true;
1627 return children;
1628 }
1629
Robert Carrdb66e622017-04-10 16:55:57 -07001630 LayerVector traverse;
Dan Stoza412903f2017-04-27 13:42:17 -07001631 for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
Robert Carrdb66e622017-04-10 16:55:57 -07001632 sp<Layer> strongRelative = weakRelative.promote();
1633 if (strongRelative != nullptr) {
1634 traverse.add(strongRelative);
Robert Carrdb66e622017-04-10 16:55:57 -07001635 }
1636 }
1637
Dan Stoza412903f2017-04-27 13:42:17 -07001638 for (const sp<Layer>& child : children) {
Robert Carr503c7042017-09-27 15:06:08 -07001639 const State& childState = useDrawing ? child->mDrawingState : child->mCurrentState;
1640 if (childState.zOrderRelativeOf != nullptr) {
1641 continue;
1642 }
Robert Carrdb66e622017-04-10 16:55:57 -07001643 traverse.add(child);
1644 }
1645
1646 return traverse;
1647}
1648
Robert Carr1f0a16a2016-10-24 16:27:39 -07001649/**
Robert Carrdb66e622017-04-10 16:55:57 -07001650 * Negatively signed relatives are before 'this' in Z-order.
Robert Carr1f0a16a2016-10-24 16:27:39 -07001651 */
Dan Stoza412903f2017-04-27 13:42:17 -07001652void Layer::traverseInZOrder(LayerVector::StateSet stateSet, const LayerVector::Visitor& visitor) {
Robert Carr29abff82017-12-04 13:51:20 -08001653 // In the case we have other layers who are using a relative Z to us, makeTraversalList will
1654 // produce a new list for traversing, including our relatives, and not including our children
1655 // who are relatives of another surface. In the case that there are no relative Z,
1656 // makeTraversalList returns our children directly to avoid significant overhead.
1657 // However in this case we need to take the responsibility for filtering children which
1658 // are relatives of another surface here.
1659 bool skipRelativeZUsers = false;
1660 const LayerVector list = makeTraversalList(stateSet, &skipRelativeZUsers);
Robert Carrdb66e622017-04-10 16:55:57 -07001661
Robert Carr1f0a16a2016-10-24 16:27:39 -07001662 size_t i = 0;
Robert Carrdb66e622017-04-10 16:55:57 -07001663 for (; i < list.size(); i++) {
1664 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001665 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1666 continue;
1667 }
1668
Robert Carrdb66e622017-04-10 16:55:57 -07001669 if (relative->getZ() >= 0) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001670 break;
Robert Carrdb66e622017-04-10 16:55:57 -07001671 }
Dan Stoza412903f2017-04-27 13:42:17 -07001672 relative->traverseInZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001673 }
Robert Carr29abff82017-12-04 13:51:20 -08001674
Dan Stoza412903f2017-04-27 13:42:17 -07001675 visitor(this);
Robert Carrdb66e622017-04-10 16:55:57 -07001676 for (; i < list.size(); i++) {
1677 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001678
1679 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1680 continue;
1681 }
Dan Stoza412903f2017-04-27 13:42:17 -07001682 relative->traverseInZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001683 }
1684}
1685
1686/**
Robert Carrdb66e622017-04-10 16:55:57 -07001687 * Positively signed relatives are before 'this' in reverse Z-order.
Robert Carr1f0a16a2016-10-24 16:27:39 -07001688 */
Dan Stoza412903f2017-04-27 13:42:17 -07001689void Layer::traverseInReverseZOrder(LayerVector::StateSet stateSet,
1690 const LayerVector::Visitor& visitor) {
Robert Carr29abff82017-12-04 13:51:20 -08001691 // See traverseInZOrder for documentation.
1692 bool skipRelativeZUsers = false;
1693 LayerVector list = makeTraversalList(stateSet, &skipRelativeZUsers);
Robert Carrdb66e622017-04-10 16:55:57 -07001694
Robert Carr1f0a16a2016-10-24 16:27:39 -07001695 int32_t i = 0;
Joel Galensonbf324992017-11-06 11:04:12 -08001696 for (i = int32_t(list.size()) - 1; i >= 0; i--) {
Robert Carrdb66e622017-04-10 16:55:57 -07001697 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001698
1699 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1700 continue;
1701 }
1702
Robert Carrdb66e622017-04-10 16:55:57 -07001703 if (relative->getZ() < 0) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001704 break;
1705 }
Dan Stoza412903f2017-04-27 13:42:17 -07001706 relative->traverseInReverseZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001707 }
Dan Stoza412903f2017-04-27 13:42:17 -07001708 visitor(this);
David Sodman41fdfc92017-11-06 16:09:56 -08001709 for (; i >= 0; i--) {
Robert Carrdb66e622017-04-10 16:55:57 -07001710 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001711
1712 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1713 continue;
1714 }
1715
Dan Stoza412903f2017-04-27 13:42:17 -07001716 relative->traverseInReverseZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001717 }
1718}
1719
chaviwa76b2712017-09-20 12:02:26 -07001720/**
1721 * Traverse only children in z order, ignoring relative layers.
1722 */
1723void Layer::traverseChildrenInZOrder(LayerVector::StateSet stateSet,
1724 const LayerVector::Visitor& visitor) {
1725 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1726 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
1727
1728 size_t i = 0;
1729 for (; i < children.size(); i++) {
1730 const auto& relative = children[i];
1731 if (relative->getZ() >= 0) {
1732 break;
1733 }
1734 relative->traverseChildrenInZOrder(stateSet, visitor);
1735 }
1736 visitor(this);
1737 for (; i < children.size(); i++) {
1738 const auto& relative = children[i];
1739 relative->traverseChildrenInZOrder(stateSet, visitor);
1740 }
1741}
1742
Robert Carr1f0a16a2016-10-24 16:27:39 -07001743Transform Layer::getTransform() const {
1744 Transform t;
Chia-I Wue41dbe62017-06-13 14:10:56 -07001745 const auto& p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001746 if (p != nullptr) {
1747 t = p->getTransform();
Robert Carr9b429f42017-04-17 14:56:57 -07001748
1749 // If the parent is not using NATIVE_WINDOW_SCALING_MODE_FREEZE (e.g.
1750 // it isFixedSize) then there may be additional scaling not accounted
1751 // for in the transform. We need to mirror this scaling in child surfaces
1752 // or we will break the contract where WM can treat child surfaces as
1753 // pixels in the parent surface.
David Sodman0cc69182017-11-17 12:12:07 -08001754 if (p->isFixedSize() && p->getBE().compositionInfo.mBuffer != nullptr) {
Robert Carr1725eee2017-04-26 18:32:15 -07001755 int bufferWidth;
1756 int bufferHeight;
1757 if ((p->mCurrentTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) == 0) {
David Sodman0cc69182017-11-17 12:12:07 -08001758 bufferWidth = p->getBE().compositionInfo.mBuffer->getWidth();
1759 bufferHeight = p->getBE().compositionInfo.mBuffer->getHeight();
Robert Carr1725eee2017-04-26 18:32:15 -07001760 } else {
David Sodman0cc69182017-11-17 12:12:07 -08001761 bufferHeight = p->getBE().compositionInfo.mBuffer->getWidth();
1762 bufferWidth = p->getBE().compositionInfo.mBuffer->getHeight();
Robert Carr1725eee2017-04-26 18:32:15 -07001763 }
David Sodman41fdfc92017-11-06 16:09:56 -08001764 float sx = p->getDrawingState().active.w / static_cast<float>(bufferWidth);
1765 float sy = p->getDrawingState().active.h / static_cast<float>(bufferHeight);
Robert Carr9b429f42017-04-17 14:56:57 -07001766 Transform extraParentScaling;
1767 extraParentScaling.set(sx, 0, 0, sy);
1768 t = t * extraParentScaling;
1769 }
Robert Carr1f0a16a2016-10-24 16:27:39 -07001770 }
1771 return t * getDrawingState().active.transform;
1772}
1773
chaviw13fdc492017-06-27 12:40:18 -07001774half Layer::getAlpha() const {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001775 const auto& p = mDrawingParent.promote();
Robert Carr6452f122017-03-21 10:41:29 -07001776
chaviw13fdc492017-06-27 12:40:18 -07001777 half parentAlpha = (p != nullptr) ? p->getAlpha() : 1.0_hf;
1778 return parentAlpha * getDrawingState().color.a;
Robert Carr6452f122017-03-21 10:41:29 -07001779}
Robert Carr6452f122017-03-21 10:41:29 -07001780
chaviw13fdc492017-06-27 12:40:18 -07001781half4 Layer::getColor() const {
1782 const half4 color(getDrawingState().color);
1783 return half4(color.r, color.g, color.b, getAlpha());
Robert Carr6452f122017-03-21 10:41:29 -07001784}
Robert Carr6452f122017-03-21 10:41:29 -07001785
Robert Carr1f0a16a2016-10-24 16:27:39 -07001786void Layer::commitChildList() {
1787 for (size_t i = 0; i < mCurrentChildren.size(); i++) {
1788 const auto& child = mCurrentChildren[i];
1789 child->commitChildList();
1790 }
1791 mDrawingChildren = mCurrentChildren;
Chia-I Wue41dbe62017-06-13 14:10:56 -07001792 mDrawingParent = mCurrentParent;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001793}
1794
chaviw1d044282017-09-27 12:19:28 -07001795void Layer::writeToProto(LayerProto* layerInfo, LayerVector::StateSet stateSet) {
1796 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1797 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
1798 const State& state = useDrawing ? mDrawingState : mCurrentState;
1799
1800 Transform requestedTransform = state.active.transform;
1801 Transform transform = getTransform();
1802
1803 layerInfo->set_id(sequence);
1804 layerInfo->set_name(getName().c_str());
1805 layerInfo->set_type(String8(getTypeId()));
1806
1807 for (const auto& child : children) {
1808 layerInfo->add_children(child->sequence);
1809 }
1810
1811 for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
1812 sp<Layer> strongRelative = weakRelative.promote();
1813 if (strongRelative != nullptr) {
1814 layerInfo->add_relatives(strongRelative->sequence);
1815 }
1816 }
1817
1818 LayerProtoHelper::writeToProto(state.activeTransparentRegion,
1819 layerInfo->mutable_transparent_region());
1820 LayerProtoHelper::writeToProto(visibleRegion, layerInfo->mutable_visible_region());
1821 LayerProtoHelper::writeToProto(surfaceDamageRegion, layerInfo->mutable_damage_region());
1822
1823 layerInfo->set_layer_stack(getLayerStack());
1824 layerInfo->set_z(state.z);
1825
1826 PositionProto* position = layerInfo->mutable_position();
1827 position->set_x(transform.tx());
1828 position->set_y(transform.ty());
1829
1830 PositionProto* requestedPosition = layerInfo->mutable_requested_position();
1831 requestedPosition->set_x(requestedTransform.tx());
1832 requestedPosition->set_y(requestedTransform.ty());
1833
1834 SizeProto* size = layerInfo->mutable_size();
1835 size->set_w(state.active.w);
1836 size->set_h(state.active.h);
1837
1838 LayerProtoHelper::writeToProto(state.crop, layerInfo->mutable_crop());
1839 LayerProtoHelper::writeToProto(state.finalCrop, layerInfo->mutable_final_crop());
1840
1841 layerInfo->set_is_opaque(isOpaque(state));
1842 layerInfo->set_invalidate(contentDirty);
1843 layerInfo->set_dataspace(dataspaceDetails(getDataSpace()));
1844 layerInfo->set_pixel_format(decodePixelFormat(getPixelFormat()));
1845 LayerProtoHelper::writeToProto(getColor(), layerInfo->mutable_color());
1846 LayerProtoHelper::writeToProto(state.color, layerInfo->mutable_requested_color());
1847 layerInfo->set_flags(state.flags);
1848
1849 LayerProtoHelper::writeToProto(transform, layerInfo->mutable_transform());
1850 LayerProtoHelper::writeToProto(requestedTransform, layerInfo->mutable_requested_transform());
1851
Jorim Jaggi8e0af362017-11-14 16:28:28 +01001852 auto parent = useDrawing ? mDrawingParent.promote() : mCurrentParent.promote();
chaviw1d044282017-09-27 12:19:28 -07001853 if (parent != nullptr) {
1854 layerInfo->set_parent(parent->sequence);
1855 }
1856
1857 auto zOrderRelativeOf = state.zOrderRelativeOf.promote();
1858 if (zOrderRelativeOf != nullptr) {
1859 layerInfo->set_z_order_relative_of(zOrderRelativeOf->sequence);
1860 }
1861
David Sodman0cc69182017-11-17 12:12:07 -08001862 auto buffer = getBE().compositionInfo.mBuffer;
David Sodman5b4cffc2017-11-23 13:20:29 -08001863 if (buffer != nullptr) {
1864 LayerProtoHelper::writeToProto(buffer, layerInfo->mutable_active_buffer());
chaviw1d044282017-09-27 12:19:28 -07001865 }
1866
1867 layerInfo->set_queued_frames(getQueuedFrameCount());
1868 layerInfo->set_refresh_pending(isBufferLatched());
1869}
1870
Yiwei Zhang7124ad32018-02-21 13:02:45 -08001871void Layer::writeToProto(LayerProto* layerInfo, int32_t hwcId) {
1872 writeToProto(layerInfo, LayerVector::StateSet::Drawing);
1873
1874 const auto& hwcInfo = getBE().mHwcLayers.at(hwcId);
1875
1876 const Rect& frame = hwcInfo.displayFrame;
1877 LayerProtoHelper::writeToProto(frame, layerInfo->mutable_hwc_frame());
1878
1879 const FloatRect& crop = hwcInfo.sourceCrop;
1880 LayerProtoHelper::writeToProto(crop, layerInfo->mutable_hwc_crop());
1881
1882 const int32_t transform = static_cast<int32_t>(hwcInfo.transform);
1883 layerInfo->set_hwc_transform(transform);
1884}
1885
Mathias Agopian13127d82013-03-05 17:47:11 -08001886// ---------------------------------------------------------------------------
1887
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001888}; // namespace android
Mathias Agopian3f844832013-08-07 21:24:32 -07001889
1890#if defined(__gl_h_)
1891#error "don't include gl/gl.h in this file"
1892#endif
1893
1894#if defined(__gl2_h_)
1895#error "don't include gl2/gl2.h in this file"
1896#endif