blob: b86408e57297286691a3cad759d1c0a752253f10 [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();
rongliucfb187b2018-03-14 12:26:23 -0700561 if (parentState.type >= 0 || parentState.appId >= 0) {
562 type = parentState.type;
563 appId = parentState.appId;
564 }
Albert Chaulk2a589632017-05-04 16:59:44 -0400565 }
566
David Sodman4b7c4bc2017-11-17 12:13:59 -0800567 getBE().compositionInfo.hwc.type = type;
568 getBE().compositionInfo.hwc.appId = appId;
Mathias Agopian9f8386e2013-01-29 18:56:42 -0800569
Mathias Agopian29a367b2011-07-12 14:51:45 -0700570 /*
571 * Transformations are applied in this order:
572 * 1) buffer orientation/flip/mirror
573 * 2) state transformation (window manager)
574 * 3) layer orientation (screen orientation)
575 * (NOTE: the matrices are multiplied in reverse order)
576 */
577
578 const Transform bufferOrientation(mCurrentTransform);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700579 Transform transform(tr * t * bufferOrientation);
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700580
Robert Carrcae605c2017-03-29 12:10:31 -0700581 if (getTransformToDisplayInverse()) {
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700582 /*
Pablo Ceballos021623b2016-04-15 17:31:51 -0700583 * the code below applies the primary display's inverse transform to the
584 * buffer
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700585 */
David Sodman41fdfc92017-11-06 16:09:56 -0800586 uint32_t invTransform = DisplayDevice::getPrimaryDisplayOrientationTransform();
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700587 // calculate the inverse transform
588 if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
David Sodman41fdfc92017-11-06 16:09:56 -0800589 invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700590 }
Robert Carrcae605c2017-03-29 12:10:31 -0700591
592 /*
593 * Here we cancel out the orientation component of the WM transform.
594 * The scaling and translate components are already included in our bounds
595 * computation so it's enough to just omit it in the composition.
596 * See comment in onDraw with ref to b/36727915 for why.
597 */
598 transform = Transform(invTransform) * tr * bufferOrientation;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700599 }
Mathias Agopian29a367b2011-07-12 14:51:45 -0700600
Jorim Jaggi5a963262018-01-17 15:57:44 +0100601 // STOPSHIP (b/72106793): If we have less than 25% scaling, HWC usually needs to use the rotator
602 // to handle it. However, there is one guaranteed frame of jank when we switch to using the
603 // rotator. In the meantime, we force GL composition instead until we have a better fix for the
604 // HWC issue.
605 bool extremeScaling = abs(t[0][0]) <= 0.25 || abs(t[1][1]) <= 0.25;
606
Mathias Agopian29a367b2011-07-12 14:51:45 -0700607 // this gives us only the "orientation" component of the transform
Mathias Agopian13127d82013-03-05 17:47:11 -0800608 const uint32_t orientation = transform.getOrientation();
Jorim Jaggi5a963262018-01-17 15:57:44 +0100609 if (orientation & Transform::ROT_INVALID || extremeScaling) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800610 // we can only handle simple transformation
David Sodman56912832017-11-28 10:27:38 -0800611 getBE().mHwcLayers[hwcId].compositionType = HWC2::Composition::Client;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800612 } else {
613 auto transform = static_cast<HWC2::Transform>(orientation);
Yiwei Zhang7124ad32018-02-21 13:02:45 -0800614 hwcInfo.transform = transform;
David Sodman4b7c4bc2017-11-17 12:13:59 -0800615 getBE().compositionInfo.hwc.transform = transform;
616 }
617}
618
Dan Stoza9e56aa02015-11-02 13:00:03 -0800619void Layer::forceClientComposition(int32_t hwcId) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700620 if (getBE().mHwcLayers.count(hwcId) == 0) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800621 ALOGE("forceClientComposition: no HWC layer found (%d)", hwcId);
622 return;
623 }
624
David Sodman6f65f3e2017-11-03 14:28:09 -0700625 getBE().mHwcLayers[hwcId].forceClientComposition = true;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800626}
Dan Stozaee44edd2015-03-23 15:50:23 -0700627
chaviwc9232ed2017-11-14 15:31:15 -0800628bool Layer::getForceClientComposition(int32_t hwcId) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700629 if (getBE().mHwcLayers.count(hwcId) == 0) {
chaviwc9232ed2017-11-14 15:31:15 -0800630 ALOGE("getForceClientComposition: no HWC layer found (%d)", hwcId);
631 return false;
632 }
633
David Sodman6f65f3e2017-11-03 14:28:09 -0700634 return getBE().mHwcLayers[hwcId].forceClientComposition;
chaviwc9232ed2017-11-14 15:31:15 -0800635}
636
Dan Stoza9e56aa02015-11-02 13:00:03 -0800637void Layer::updateCursorPosition(const sp<const DisplayDevice>& displayDevice) {
638 auto hwcId = displayDevice->getHwcDisplayId();
David Sodman6f65f3e2017-11-03 14:28:09 -0700639 if (getBE().mHwcLayers.count(hwcId) == 0 ||
David Sodman9eeae692017-11-02 10:53:32 -0700640 getCompositionType(hwcId) != HWC2::Composition::Cursor) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800641 return;
642 }
643
644 // This gives us only the "orientation" component of the transform
645 const State& s(getCurrentState());
646
647 // Apply the layer's transform, followed by the display's global transform
648 // Here we're guaranteed that the layer's transform preserves rects
649 Rect win(s.active.w, s.active.h);
Robert Carrb5d3d262016-03-25 15:08:13 -0700650 if (!s.crop.isEmpty()) {
651 win.intersect(s.crop, &win);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800652 }
653 // Subtract the transparent region and snap to the bounds
654 Rect bounds = reduce(win, s.activeTransparentRegion);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700655 Rect frame(getTransform().transform(bounds));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800656 frame.intersect(displayDevice->getViewport(), &frame);
Robert Carrb5d3d262016-03-25 15:08:13 -0700657 if (!s.finalCrop.isEmpty()) {
658 frame.intersect(s.finalCrop, &frame);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000659 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800660 auto& displayTransform(displayDevice->getTransform());
661 auto position = displayTransform.transform(frame);
662
David Sodman5d89c1d2017-12-14 15:54:51 -0800663 auto error = (*getBE().mHwcLayers[hwcId].layer)->setCursorPosition(position.left,
David Sodman9eeae692017-11-02 10:53:32 -0700664 position.top);
David Sodman41fdfc92017-11-06 16:09:56 -0800665 ALOGE_IF(error != HWC2::Error::None,
666 "[%s] Failed to set cursor position "
667 "to (%d, %d): %s (%d)",
668 mName.string(), position.left, position.top, to_string(error).c_str(),
669 static_cast<int32_t>(error));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800670}
Riley Andrews03414a12014-07-01 14:22:59 -0700671
Mathias Agopian13127d82013-03-05 17:47:11 -0800672// ---------------------------------------------------------------------------
673// drawing...
674// ---------------------------------------------------------------------------
675
chaviwa76b2712017-09-20 12:02:26 -0700676void Layer::draw(const RenderArea& renderArea, const Region& clip) const {
677 onDraw(renderArea, clip, false);
Mathias Agopian13127d82013-03-05 17:47:11 -0800678}
679
chaviwa76b2712017-09-20 12:02:26 -0700680void Layer::draw(const RenderArea& renderArea, bool useIdentityTransform) const {
681 onDraw(renderArea, Region(renderArea.getBounds()), useIdentityTransform);
Mathias Agopian13127d82013-03-05 17:47:11 -0800682}
683
chaviwa76b2712017-09-20 12:02:26 -0700684void Layer::draw(const RenderArea& renderArea) const {
685 onDraw(renderArea, Region(renderArea.getBounds()), false);
Dan Stozac7014012014-02-14 15:03:43 -0800686}
687
David Sodman41fdfc92017-11-06 16:09:56 -0800688void Layer::clearWithOpenGL(const RenderArea& renderArea, float red, float green, float blue,
689 float alpha) const {
Lloyd Pique144e1162017-12-20 16:44:52 -0800690 auto& engine(mFlinger->getRenderEngine());
David Sodman9eeae692017-11-02 10:53:32 -0700691 computeGeometry(renderArea, getBE().mMesh, false);
Mathias Agopian19733a32013-08-28 18:13:56 -0700692 engine.setupFillWithColor(red, green, blue, alpha);
David Sodman9eeae692017-11-02 10:53:32 -0700693 engine.drawMesh(getBE().mMesh);
Mathias Agopian13127d82013-03-05 17:47:11 -0800694}
695
chaviwa76b2712017-09-20 12:02:26 -0700696void Layer::clearWithOpenGL(const RenderArea& renderArea) const {
David Sodman41fdfc92017-11-06 16:09:56 -0800697 clearWithOpenGL(renderArea, 0, 0, 0, 0);
Mathias Agopian13127d82013-03-05 17:47:11 -0800698}
699
David Sodman56912832017-11-28 10:27:38 -0800700void Layer::setCompositionType(int32_t /*hwcId*/, HWC2::Composition type, bool /*callIntoHwc*/) {
701 if (getBE().compositionInfo.compositionType != type) {
702 ALOGV("setCompositionType: Changing compositionType from %s to %s",
703 to_string(getBE().compositionInfo.compositionType).c_str(),
704 to_string(type).c_str());
705 getBE().compositionInfo.compositionType = type;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800706 }
707}
708
709HWC2::Composition Layer::getCompositionType(int32_t hwcId) const {
Dan Stozaec0f7172016-07-21 11:09:40 -0700710 if (hwcId == DisplayDevice::DISPLAY_ID_INVALID) {
711 // If we're querying the composition type for a display that does not
712 // have a HWC counterpart, then it will always be Client
713 return HWC2::Composition::Client;
714 }
David Sodman56912832017-11-28 10:27:38 -0800715 return getBE().compositionInfo.compositionType;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800716}
717
718void Layer::setClearClientTarget(int32_t hwcId, bool clear) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700719 if (getBE().mHwcLayers.count(hwcId) == 0) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800720 ALOGE("setClearClientTarget called without a valid HWC layer");
721 return;
722 }
David Sodman6f65f3e2017-11-03 14:28:09 -0700723 getBE().mHwcLayers[hwcId].clearClientTarget = clear;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800724}
725
726bool Layer::getClearClientTarget(int32_t hwcId) const {
David Sodman6f65f3e2017-11-03 14:28:09 -0700727 if (getBE().mHwcLayers.count(hwcId) == 0) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800728 ALOGE("getClearClientTarget called without a valid HWC layer");
729 return false;
730 }
David Sodman6f65f3e2017-11-03 14:28:09 -0700731 return getBE().mHwcLayers.at(hwcId).clearClientTarget;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800732}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800733
Dan Stozacac35382016-01-27 12:21:06 -0800734bool Layer::addSyncPoint(const std::shared_ptr<SyncPoint>& point) {
735 if (point->getFrameNumber() <= mCurrentFrameNumber) {
736 // Don't bother with a SyncPoint, since we've already latched the
737 // relevant frame
738 return false;
Dan Stoza7dde5992015-05-22 09:51:44 -0700739 }
740
Dan Stozacac35382016-01-27 12:21:06 -0800741 Mutex::Autolock lock(mLocalSyncPointMutex);
742 mLocalSyncPoints.push_back(point);
743 return true;
Dan Stoza7dde5992015-05-22 09:51:44 -0700744}
745
Mathias Agopian13127d82013-03-05 17:47:11 -0800746void Layer::setFiltering(bool filtering) {
747 mFiltering = filtering;
748}
749
750bool Layer::getFiltering() const {
751 return mFiltering;
752}
753
Mathias Agopian13127d82013-03-05 17:47:11 -0800754// ----------------------------------------------------------------------------
755// local state
756// ----------------------------------------------------------------------------
757
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000758static void boundPoint(vec2* point, const Rect& crop) {
759 if (point->x < crop.left) {
760 point->x = crop.left;
761 }
762 if (point->x > crop.right) {
763 point->x = crop.right;
764 }
765 if (point->y < crop.top) {
766 point->y = crop.top;
767 }
768 if (point->y > crop.bottom) {
769 point->y = crop.bottom;
770 }
771}
772
chaviwa76b2712017-09-20 12:02:26 -0700773void Layer::computeGeometry(const RenderArea& renderArea, Mesh& mesh,
774 bool useIdentityTransform) const {
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700775 const Layer::State& s(getDrawingState());
chaviwa76b2712017-09-20 12:02:26 -0700776 const Transform renderAreaTransform(renderArea.getTransform());
777 const uint32_t height = renderArea.getHeight();
Dan Stoza80d61162017-12-20 15:57:52 -0800778 FloatRect win = computeBounds();
Mathias Agopian3f844832013-08-07 21:24:32 -0700779
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000780 vec2 lt = vec2(win.left, win.top);
781 vec2 lb = vec2(win.left, win.bottom);
782 vec2 rb = vec2(win.right, win.bottom);
783 vec2 rt = vec2(win.right, win.top);
784
Robert Carr1f0a16a2016-10-24 16:27:39 -0700785 Transform layerTransform = getTransform();
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000786 if (!useIdentityTransform) {
Robert Carr1f0a16a2016-10-24 16:27:39 -0700787 lt = layerTransform.transform(lt);
788 lb = layerTransform.transform(lb);
789 rb = layerTransform.transform(rb);
790 rt = layerTransform.transform(rt);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000791 }
792
Robert Carrb5d3d262016-03-25 15:08:13 -0700793 if (!s.finalCrop.isEmpty()) {
794 boundPoint(&lt, s.finalCrop);
795 boundPoint(&lb, s.finalCrop);
796 boundPoint(&rb, s.finalCrop);
797 boundPoint(&rt, s.finalCrop);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000798 }
799
Mathias Agopianff2ed702013-09-01 21:36:12 -0700800 Mesh::VertexArray<vec2> position(mesh.getPositionArray<vec2>());
chaviwa76b2712017-09-20 12:02:26 -0700801 position[0] = renderAreaTransform.transform(lt);
802 position[1] = renderAreaTransform.transform(lb);
803 position[2] = renderAreaTransform.transform(rb);
804 position[3] = renderAreaTransform.transform(rt);
David Sodman41fdfc92017-11-06 16:09:56 -0800805 for (size_t i = 0; i < 4; i++) {
chaviwa76b2712017-09-20 12:02:26 -0700806 position[i].y = height - position[i].y;
Mathias Agopian13127d82013-03-05 17:47:11 -0800807 }
808}
Eric Hassoldac45e6b2011-02-10 14:41:26 -0800809
David Sodman41fdfc92017-11-06 16:09:56 -0800810bool Layer::isSecure() const {
Dan Stoza23116082015-06-18 14:58:39 -0700811 const Layer::State& s(mDrawingState);
812 return (s.flags & layer_state_t::eLayerSecure);
813}
814
Mathias Agopian13127d82013-03-05 17:47:11 -0800815void Layer::setVisibleRegion(const Region& visibleRegion) {
816 // always called from main thread
817 this->visibleRegion = visibleRegion;
818}
819
820void Layer::setCoveredRegion(const Region& coveredRegion) {
821 // always called from main thread
822 this->coveredRegion = coveredRegion;
823}
824
David Sodman41fdfc92017-11-06 16:09:56 -0800825void Layer::setVisibleNonTransparentRegion(const Region& setVisibleNonTransparentRegion) {
Mathias Agopian13127d82013-03-05 17:47:11 -0800826 // always called from main thread
827 this->visibleNonTransparentRegion = setVisibleNonTransparentRegion;
828}
829
Robert Carre5f4f692018-01-12 13:12:28 -0800830void Layer::clearVisibilityRegions() {
831 visibleRegion.clear();
832 visibleNonTransparentRegion.clear();
833 coveredRegion.clear();
834}
835
Mathias Agopian13127d82013-03-05 17:47:11 -0800836// ----------------------------------------------------------------------------
837// transaction
838// ----------------------------------------------------------------------------
839
Dan Stoza7dde5992015-05-22 09:51:44 -0700840void Layer::pushPendingState() {
841 if (!mCurrentState.modified) {
842 return;
843 }
844
Dan Stoza7dde5992015-05-22 09:51:44 -0700845 // If this transaction is waiting on the receipt of a frame, generate a sync
846 // point and send it to the remote layer.
Robert Carr0d480722017-01-10 16:42:54 -0800847 if (mCurrentState.barrierLayer != nullptr) {
848 sp<Layer> barrierLayer = mCurrentState.barrierLayer.promote();
849 if (barrierLayer == nullptr) {
850 ALOGE("[%s] Unable to promote barrier Layer.", mName.string());
Dan Stoza7dde5992015-05-22 09:51:44 -0700851 // If we can't promote the layer we are intended to wait on,
852 // then it is expired or otherwise invalid. Allow this transaction
853 // to be applied as per normal (no synchronization).
Robert Carr0d480722017-01-10 16:42:54 -0800854 mCurrentState.barrierLayer = nullptr;
Pablo Ceballos3bddd5b2015-11-19 14:39:14 -0800855 } else {
David Sodman41fdfc92017-11-06 16:09:56 -0800856 auto syncPoint = std::make_shared<SyncPoint>(mCurrentState.frameNumber);
Robert Carr0d480722017-01-10 16:42:54 -0800857 if (barrierLayer->addSyncPoint(syncPoint)) {
Dan Stozacac35382016-01-27 12:21:06 -0800858 mRemoteSyncPoints.push_back(std::move(syncPoint));
859 } else {
860 // We already missed the frame we're supposed to synchronize
861 // on, so go ahead and apply the state update
Robert Carr0d480722017-01-10 16:42:54 -0800862 mCurrentState.barrierLayer = nullptr;
Dan Stozacac35382016-01-27 12:21:06 -0800863 }
Dan Stoza7dde5992015-05-22 09:51:44 -0700864 }
865
Dan Stoza7dde5992015-05-22 09:51:44 -0700866 // Wake us up to check if the frame has been received
867 setTransactionFlags(eTransactionNeeded);
Dan Stozaf5702ff2016-11-02 16:27:47 -0700868 mFlinger->setTransactionFlags(eTraversalNeeded);
Dan Stoza7dde5992015-05-22 09:51:44 -0700869 }
870 mPendingStates.push_back(mCurrentState);
Dan Stozaf7ba41a2017-05-10 15:11:11 -0700871 ATRACE_INT(mTransactionName.string(), mPendingStates.size());
Dan Stoza7dde5992015-05-22 09:51:44 -0700872}
873
Pablo Ceballos05289c22016-04-14 15:49:55 -0700874void Layer::popPendingState(State* stateToCommit) {
875 auto oldFlags = stateToCommit->flags;
876 *stateToCommit = mPendingStates[0];
David Sodman41fdfc92017-11-06 16:09:56 -0800877 stateToCommit->flags =
878 (oldFlags & ~stateToCommit->mask) | (stateToCommit->flags & stateToCommit->mask);
Dan Stoza7dde5992015-05-22 09:51:44 -0700879
880 mPendingStates.removeAt(0);
Dan Stozaf7ba41a2017-05-10 15:11:11 -0700881 ATRACE_INT(mTransactionName.string(), mPendingStates.size());
Dan Stoza7dde5992015-05-22 09:51:44 -0700882}
883
Pablo Ceballos05289c22016-04-14 15:49:55 -0700884bool Layer::applyPendingStates(State* stateToCommit) {
Dan Stoza7dde5992015-05-22 09:51:44 -0700885 bool stateUpdateAvailable = false;
886 while (!mPendingStates.empty()) {
Robert Carr0d480722017-01-10 16:42:54 -0800887 if (mPendingStates[0].barrierLayer != nullptr) {
Dan Stoza7dde5992015-05-22 09:51:44 -0700888 if (mRemoteSyncPoints.empty()) {
889 // If we don't have a sync point for this, apply it anyway. It
890 // will be visually wrong, but it should keep us from getting
891 // into too much trouble.
892 ALOGE("[%s] No local sync point found", mName.string());
Pablo Ceballos05289c22016-04-14 15:49:55 -0700893 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -0700894 stateUpdateAvailable = true;
895 continue;
896 }
897
David Sodman41fdfc92017-11-06 16:09:56 -0800898 if (mRemoteSyncPoints.front()->getFrameNumber() != mPendingStates[0].frameNumber) {
899 ALOGE("[%s] Unexpected sync point frame number found", mName.string());
Dan Stozacac35382016-01-27 12:21:06 -0800900
901 // Signal our end of the sync point and then dispose of it
902 mRemoteSyncPoints.front()->setTransactionApplied();
903 mRemoteSyncPoints.pop_front();
904 continue;
905 }
906
Dan Stoza7dde5992015-05-22 09:51:44 -0700907 if (mRemoteSyncPoints.front()->frameIsAvailable()) {
908 // Apply the state update
Pablo Ceballos05289c22016-04-14 15:49:55 -0700909 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -0700910 stateUpdateAvailable = true;
911
912 // Signal our end of the sync point and then dispose of it
913 mRemoteSyncPoints.front()->setTransactionApplied();
914 mRemoteSyncPoints.pop_front();
Dan Stoza792e5292016-02-11 11:43:58 -0800915 } else {
916 break;
Dan Stoza7dde5992015-05-22 09:51:44 -0700917 }
Dan Stoza7dde5992015-05-22 09:51:44 -0700918 } else {
Pablo Ceballos05289c22016-04-14 15:49:55 -0700919 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -0700920 stateUpdateAvailable = true;
921 }
922 }
923
924 // If we still have pending updates, wake SurfaceFlinger back up and point
925 // it at this layer so we can process them
926 if (!mPendingStates.empty()) {
927 setTransactionFlags(eTransactionNeeded);
928 mFlinger->setTransactionFlags(eTraversalNeeded);
929 }
930
931 mCurrentState.modified = false;
932 return stateUpdateAvailable;
933}
934
Mathias Agopian13127d82013-03-05 17:47:11 -0800935uint32_t Layer::doTransaction(uint32_t flags) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800936 ATRACE_CALL();
937
Dan Stoza7dde5992015-05-22 09:51:44 -0700938 pushPendingState();
Pablo Ceballos05289c22016-04-14 15:49:55 -0700939 Layer::State c = getCurrentState();
940 if (!applyPendingStates(&c)) {
Dan Stoza7dde5992015-05-22 09:51:44 -0700941 return 0;
942 }
943
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700944 const Layer::State& s(getDrawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800945
David Sodman41fdfc92017-11-06 16:09:56 -0800946 const bool sizeChanged = (c.requested.w != s.requested.w) || (c.requested.h != s.requested.h);
Mathias Agopiana138f892010-05-21 17:24:35 -0700947
David Sodmaneb085e02017-10-05 18:49:04 -0700948 if (sizeChanged) {
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700949 // the size changed, we need to ask our client to request a new buffer
Steve Block9d453682011-12-20 16:23:08 +0000950 ALOGD_IF(DEBUG_RESIZE,
David Sodman41fdfc92017-11-06 16:09:56 -0800951 "doTransaction: geometry (layer=%p '%s'), tr=%02x, scalingMode=%d\n"
952 " current={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
953 " requested={ wh={%4u,%4u} }}\n"
954 " drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
955 " requested={ wh={%4u,%4u} }}\n",
David Sodman9eeae692017-11-02 10:53:32 -0700956 this, getName().string(), mCurrentTransform,
957 getEffectiveScalingMode(), c.active.w, c.active.h, c.crop.left, c.crop.top,
958 c.crop.right, c.crop.bottom, c.crop.getWidth(), c.crop.getHeight(), c.requested.w,
959 c.requested.h, s.active.w, s.active.h, s.crop.left, s.crop.top, s.crop.right,
960 s.crop.bottom, s.crop.getWidth(), s.crop.getHeight(), s.requested.w,
961 s.requested.h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800962
Jamie Gennis2a0d5b62011-09-26 16:54:44 -0700963 // record the new size, form this point on, when the client request
964 // a buffer, it'll get the new size.
David Sodmaneb085e02017-10-05 18:49:04 -0700965 setDefaultBufferSize(c.requested.w, c.requested.h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800966 }
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700967
Robert Carre392b552017-09-19 12:16:05 -0700968 // Don't let Layer::doTransaction update the drawing state
969 // if we have a pending resize, unless we are in fixed-size mode.
970 // the drawing state will be updated only once we receive a buffer
971 // with the correct size.
972 //
973 // In particular, we want to make sure the clip (which is part
974 // of the geometry state) is latched together with the size but is
975 // latched immediately when no resizing is involved.
976 //
977 // If a sideband stream is attached, however, we want to skip this
978 // optimization so that transactions aren't missed when a buffer
979 // never arrives
980 //
981 // In the case that we don't have a buffer we ignore other factors
982 // and avoid entering the resizePending state. At a high level the
983 // resizePending state is to avoid applying the state of the new buffer
984 // to the old buffer. However in the state where we don't have an old buffer
985 // there is no such concern but we may still be being used as a parent layer.
David Sodman41fdfc92017-11-06 16:09:56 -0800986 const bool resizePending = ((c.requested.w != c.active.w) || (c.requested.h != c.active.h)) &&
David Sodman0cc69182017-11-17 12:12:07 -0800987 (getBE().compositionInfo.mBuffer != nullptr);
Mathias Agopian0cd545f2012-06-07 14:18:55 -0700988 if (!isFixedSize()) {
David Sodman0cc69182017-11-17 12:12:07 -0800989 if (resizePending && getBE().compositionInfo.hwc.sidebandStream == nullptr) {
Mathias Agopian0cd545f2012-06-07 14:18:55 -0700990 flags |= eDontUpdateGeometryState;
991 }
992 }
993
Robert Carr7bf247e2017-05-18 14:02:49 -0700994 // Here we apply various requested geometry states, depending on our
995 // latching configuration. See Layer.h for a detailed discussion of
996 // how geometry latching is controlled.
997 if (!(flags & eDontUpdateGeometryState)) {
Pablo Ceballos7d052572016-06-02 17:46:05 -0700998 Layer::State& editCurrentState(getCurrentState());
Robert Carr7bf247e2017-05-18 14:02:49 -0700999
1000 // If mFreezeGeometryUpdates is true we are in the setGeometryAppliesWithResize
1001 // mode, which causes attributes which normally latch regardless of scaling mode,
1002 // to be delayed. We copy the requested state to the active state making sure
1003 // to respect these rules (again see Layer.h for a detailed discussion).
1004 //
1005 // There is an awkward asymmetry in the handling of the crop states in the position
1006 // states, as can be seen below. Largely this arises from position and transform
1007 // being stored in the same data structure while having different latching rules.
1008 // b/38182305
1009 //
1010 // Careful that "c" and editCurrentState may not begin as equivalent due to
1011 // applyPendingStates in the presence of deferred transactions.
1012 if (mFreezeGeometryUpdates) {
Robert Carr82364e32016-05-15 11:27:47 -07001013 float tx = c.active.transform.tx();
1014 float ty = c.active.transform.ty();
1015 c.active = c.requested;
1016 c.active.transform.set(tx, ty);
1017 editCurrentState.active = c.active;
1018 } else {
1019 editCurrentState.active = editCurrentState.requested;
1020 c.active = c.requested;
1021 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001022 }
1023
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001024 if (s.active != c.active) {
Mathias Agopian13127d82013-03-05 17:47:11 -08001025 // invalidate and recompute the visible regions if needed
1026 flags |= Layer::eVisibleRegion;
1027 }
1028
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001029 if (c.sequence != s.sequence) {
Mathias Agopian13127d82013-03-05 17:47:11 -08001030 // invalidate and recompute the visible regions if needed
1031 flags |= eVisibleRegion;
1032 this->contentDirty = true;
1033
1034 // we may use linear filtering, if the matrix scales us
Robert Carr3dcabfa2016-03-01 18:36:58 -08001035 const uint8_t type = c.active.transform.getType();
David Sodman41fdfc92017-11-06 16:09:56 -08001036 mNeedsFiltering = (!c.active.transform.preserveRects() || (type >= Transform::SCALE));
Mathias Agopian13127d82013-03-05 17:47:11 -08001037 }
1038
Dan Stozac8145172016-04-28 16:29:06 -07001039 // If the layer is hidden, signal and clear out all local sync points so
1040 // that transactions for layers depending on this layer's frames becoming
1041 // visible are not blocked
1042 if (c.flags & layer_state_t::eLayerHidden) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001043 clearSyncPoints();
Dan Stozac8145172016-04-28 16:29:06 -07001044 }
1045
Mathias Agopian13127d82013-03-05 17:47:11 -08001046 // Commit the transaction
Pablo Ceballos05289c22016-04-14 15:49:55 -07001047 commitTransaction(c);
Mathias Agopian13127d82013-03-05 17:47:11 -08001048 return flags;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001049}
1050
Pablo Ceballos05289c22016-04-14 15:49:55 -07001051void Layer::commitTransaction(const State& stateToCommit) {
1052 mDrawingState = stateToCommit;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001053}
1054
Mathias Agopian13127d82013-03-05 17:47:11 -08001055uint32_t Layer::getTransactionFlags(uint32_t flags) {
1056 return android_atomic_and(~flags, &mTransactionFlags) & flags;
1057}
1058
1059uint32_t Layer::setTransactionFlags(uint32_t flags) {
1060 return android_atomic_or(flags, &mTransactionFlags);
1061}
1062
Robert Carr82364e32016-05-15 11:27:47 -07001063bool Layer::setPosition(float x, float y, bool immediate) {
Robert Carr3dcabfa2016-03-01 18:36:58 -08001064 if (mCurrentState.requested.transform.tx() == x && mCurrentState.requested.transform.ty() == y)
Mathias Agopian13127d82013-03-05 17:47:11 -08001065 return false;
1066 mCurrentState.sequence++;
Robert Carr69663fb2016-03-27 19:59:19 -07001067
1068 // We update the requested and active position simultaneously because
1069 // we want to apply the position portion of the transform matrix immediately,
1070 // but still delay scaling when resizing a SCALING_MODE_FREEZE layer.
Robert Carr3dcabfa2016-03-01 18:36:58 -08001071 mCurrentState.requested.transform.set(x, y);
Robert Carr7bf247e2017-05-18 14:02:49 -07001072 if (immediate && !mFreezeGeometryUpdates) {
1073 // Here we directly update the active state
1074 // unlike other setters, because we store it within
1075 // the transform, but use different latching rules.
1076 // b/38182305
Robert Carr82364e32016-05-15 11:27:47 -07001077 mCurrentState.active.transform.set(x, y);
1078 }
Robert Carr7bf247e2017-05-18 14:02:49 -07001079 mFreezeGeometryUpdates = mFreezeGeometryUpdates || !immediate;
Robert Carr69663fb2016-03-27 19:59:19 -07001080
Dan Stoza7dde5992015-05-22 09:51:44 -07001081 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001082 setTransactionFlags(eTransactionNeeded);
1083 return true;
1084}
Robert Carr82364e32016-05-15 11:27:47 -07001085
Robert Carr1f0a16a2016-10-24 16:27:39 -07001086bool Layer::setChildLayer(const sp<Layer>& childLayer, int32_t z) {
1087 ssize_t idx = mCurrentChildren.indexOf(childLayer);
1088 if (idx < 0) {
1089 return false;
1090 }
1091 if (childLayer->setLayer(z)) {
1092 mCurrentChildren.removeAt(idx);
1093 mCurrentChildren.add(childLayer);
Robert Carr503d2bd2017-12-04 15:49:47 -08001094 return true;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001095 }
Robert Carr503d2bd2017-12-04 15:49:47 -08001096 return false;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001097}
1098
Robert Carr503c7042017-09-27 15:06:08 -07001099bool Layer::setChildRelativeLayer(const sp<Layer>& childLayer,
1100 const sp<IBinder>& relativeToHandle, int32_t relativeZ) {
1101 ssize_t idx = mCurrentChildren.indexOf(childLayer);
1102 if (idx < 0) {
1103 return false;
1104 }
1105 if (childLayer->setRelativeLayer(relativeToHandle, relativeZ)) {
1106 mCurrentChildren.removeAt(idx);
1107 mCurrentChildren.add(childLayer);
Robert Carr503d2bd2017-12-04 15:49:47 -08001108 return true;
Robert Carr503c7042017-09-27 15:06:08 -07001109 }
Robert Carr503d2bd2017-12-04 15:49:47 -08001110 return false;
Robert Carr503c7042017-09-27 15:06:08 -07001111}
1112
Robert Carrae060832016-11-28 10:51:00 -08001113bool Layer::setLayer(int32_t z) {
Robert Carr503d2bd2017-12-04 15:49:47 -08001114 if (mCurrentState.z == z && !usingRelativeZ(LayerVector::StateSet::Current)) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001115 mCurrentState.sequence++;
1116 mCurrentState.z = z;
Dan Stoza7dde5992015-05-22 09:51:44 -07001117 mCurrentState.modified = true;
Robert Carrdb66e622017-04-10 16:55:57 -07001118
1119 // Discard all relative layering.
1120 if (mCurrentState.zOrderRelativeOf != nullptr) {
1121 sp<Layer> strongRelative = mCurrentState.zOrderRelativeOf.promote();
1122 if (strongRelative != nullptr) {
1123 strongRelative->removeZOrderRelative(this);
1124 }
1125 mCurrentState.zOrderRelativeOf = nullptr;
1126 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001127 setTransactionFlags(eTransactionNeeded);
1128 return true;
1129}
Robert Carr1f0a16a2016-10-24 16:27:39 -07001130
Robert Carrdb66e622017-04-10 16:55:57 -07001131void Layer::removeZOrderRelative(const wp<Layer>& relative) {
1132 mCurrentState.zOrderRelatives.remove(relative);
1133 mCurrentState.sequence++;
1134 mCurrentState.modified = true;
1135 setTransactionFlags(eTransactionNeeded);
1136}
1137
1138void Layer::addZOrderRelative(const wp<Layer>& relative) {
1139 mCurrentState.zOrderRelatives.add(relative);
1140 mCurrentState.modified = true;
1141 mCurrentState.sequence++;
1142 setTransactionFlags(eTransactionNeeded);
1143}
1144
Robert Carr503d2bd2017-12-04 15:49:47 -08001145bool Layer::setRelativeLayer(const sp<IBinder>& relativeToHandle, int32_t relativeZ) {
Robert Carrdb66e622017-04-10 16:55:57 -07001146 sp<Handle> handle = static_cast<Handle*>(relativeToHandle.get());
1147 if (handle == nullptr) {
1148 return false;
1149 }
1150 sp<Layer> relative = handle->owner.promote();
1151 if (relative == nullptr) {
1152 return false;
1153 }
1154
Robert Carr503d2bd2017-12-04 15:49:47 -08001155 if (mCurrentState.z == relativeZ && usingRelativeZ(LayerVector::StateSet::Current) &&
1156 mCurrentState.zOrderRelativeOf == relative) {
1157 return false;
1158 }
1159
Robert Carrdb66e622017-04-10 16:55:57 -07001160 mCurrentState.sequence++;
1161 mCurrentState.modified = true;
Robert Carr503d2bd2017-12-04 15:49:47 -08001162 mCurrentState.z = relativeZ;
Robert Carrdb66e622017-04-10 16:55:57 -07001163
chaviw9ab4bd12017-11-03 13:11:00 -07001164 auto oldZOrderRelativeOf = mCurrentState.zOrderRelativeOf.promote();
1165 if (oldZOrderRelativeOf != nullptr) {
1166 oldZOrderRelativeOf->removeZOrderRelative(this);
1167 }
Robert Carrdb66e622017-04-10 16:55:57 -07001168 mCurrentState.zOrderRelativeOf = relative;
1169 relative->addZOrderRelative(this);
1170
1171 setTransactionFlags(eTransactionNeeded);
1172
1173 return true;
1174}
1175
Mathias Agopian13127d82013-03-05 17:47:11 -08001176bool Layer::setSize(uint32_t w, uint32_t h) {
David Sodman41fdfc92017-11-06 16:09:56 -08001177 if (mCurrentState.requested.w == w && mCurrentState.requested.h == h) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001178 mCurrentState.requested.w = w;
1179 mCurrentState.requested.h = h;
Dan Stoza7dde5992015-05-22 09:51:44 -07001180 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001181 setTransactionFlags(eTransactionNeeded);
1182 return true;
1183}
Dan Stoza9e56aa02015-11-02 13:00:03 -08001184bool Layer::setAlpha(float alpha) {
David Sodman41fdfc92017-11-06 16:09:56 -08001185 if (mCurrentState.color.a == alpha) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001186 mCurrentState.sequence++;
chaviw13fdc492017-06-27 12:40:18 -07001187 mCurrentState.color.a = alpha;
Dan Stoza7dde5992015-05-22 09:51:44 -07001188 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001189 setTransactionFlags(eTransactionNeeded);
1190 return true;
1191}
chaviw13fdc492017-06-27 12:40:18 -07001192
1193bool Layer::setColor(const half3& color) {
David Sodman41fdfc92017-11-06 16:09:56 -08001194 if (color.r == mCurrentState.color.r && color.g == mCurrentState.color.g &&
1195 color.b == mCurrentState.color.b)
chaviw13fdc492017-06-27 12:40:18 -07001196 return false;
1197
1198 mCurrentState.sequence++;
1199 mCurrentState.color.r = color.r;
1200 mCurrentState.color.g = color.g;
1201 mCurrentState.color.b = color.b;
1202 mCurrentState.modified = true;
1203 setTransactionFlags(eTransactionNeeded);
1204 return true;
1205}
1206
Mathias Agopian13127d82013-03-05 17:47:11 -08001207bool Layer::setMatrix(const layer_state_t::matrix22_t& matrix) {
1208 mCurrentState.sequence++;
David Sodman41fdfc92017-11-06 16:09:56 -08001209 mCurrentState.requested.transform.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
Dan Stoza7dde5992015-05-22 09:51:44 -07001210 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001211 setTransactionFlags(eTransactionNeeded);
1212 return true;
1213}
1214bool Layer::setTransparentRegionHint(const Region& transparent) {
Mathias Agopian2ca79392013-04-02 18:30:32 -07001215 mCurrentState.requestedTransparentRegion = transparent;
Dan Stoza7dde5992015-05-22 09:51:44 -07001216 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001217 setTransactionFlags(eTransactionNeeded);
1218 return true;
1219}
1220bool Layer::setFlags(uint8_t flags, uint8_t mask) {
1221 const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask);
David Sodman41fdfc92017-11-06 16:09:56 -08001222 if (mCurrentState.flags == newFlags) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001223 mCurrentState.sequence++;
1224 mCurrentState.flags = newFlags;
Dan Stoza7dde5992015-05-22 09:51:44 -07001225 mCurrentState.mask = mask;
1226 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001227 setTransactionFlags(eTransactionNeeded);
1228 return true;
1229}
Robert Carr99e27f02016-06-16 15:18:02 -07001230
1231bool Layer::setCrop(const Rect& crop, bool immediate) {
David Sodman41fdfc92017-11-06 16:09:56 -08001232 if (mCurrentState.requestedCrop == crop) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001233 mCurrentState.sequence++;
Robert Carr99e27f02016-06-16 15:18:02 -07001234 mCurrentState.requestedCrop = crop;
Robert Carr7bf247e2017-05-18 14:02:49 -07001235 if (immediate && !mFreezeGeometryUpdates) {
Robert Carr99e27f02016-06-16 15:18:02 -07001236 mCurrentState.crop = crop;
1237 }
Robert Carr7bf247e2017-05-18 14:02:49 -07001238 mFreezeGeometryUpdates = mFreezeGeometryUpdates || !immediate;
1239
Dan Stoza7dde5992015-05-22 09:51:44 -07001240 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001241 setTransactionFlags(eTransactionNeeded);
1242 return true;
1243}
Robert Carr8d5227b2017-03-16 15:41:03 -07001244
1245bool Layer::setFinalCrop(const Rect& crop, bool immediate) {
David Sodman41fdfc92017-11-06 16:09:56 -08001246 if (mCurrentState.requestedFinalCrop == crop) return false;
Pablo Ceballosacbe6782016-03-04 17:54:21 +00001247 mCurrentState.sequence++;
Robert Carr8d5227b2017-03-16 15:41:03 -07001248 mCurrentState.requestedFinalCrop = crop;
Robert Carr7bf247e2017-05-18 14:02:49 -07001249 if (immediate && !mFreezeGeometryUpdates) {
Robert Carr8d5227b2017-03-16 15:41:03 -07001250 mCurrentState.finalCrop = crop;
1251 }
Robert Carr7bf247e2017-05-18 14:02:49 -07001252 mFreezeGeometryUpdates = mFreezeGeometryUpdates || !immediate;
1253
Pablo Ceballosacbe6782016-03-04 17:54:21 +00001254 mCurrentState.modified = true;
1255 setTransactionFlags(eTransactionNeeded);
1256 return true;
1257}
Mathias Agopian13127d82013-03-05 17:47:11 -08001258
Robert Carrc3574f72016-03-24 12:19:32 -07001259bool Layer::setOverrideScalingMode(int32_t scalingMode) {
David Sodman41fdfc92017-11-06 16:09:56 -08001260 if (scalingMode == mOverrideScalingMode) return false;
Robert Carrc3574f72016-03-24 12:19:32 -07001261 mOverrideScalingMode = scalingMode;
Robert Carr82364e32016-05-15 11:27:47 -07001262 setTransactionFlags(eTransactionNeeded);
Robert Carrc3574f72016-03-24 12:19:32 -07001263 return true;
1264}
1265
rongliucfb187b2018-03-14 12:26:23 -07001266void Layer::setInfo(int32_t type, int32_t appId) {
David Sodman41fdfc92017-11-06 16:09:56 -08001267 mCurrentState.appId = appId;
1268 mCurrentState.type = type;
1269 mCurrentState.modified = true;
1270 setTransactionFlags(eTransactionNeeded);
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -05001271}
1272
Mathias Agopian13127d82013-03-05 17:47:11 -08001273bool Layer::setLayerStack(uint32_t layerStack) {
David Sodman41fdfc92017-11-06 16:09:56 -08001274 if (mCurrentState.layerStack == layerStack) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001275 mCurrentState.sequence++;
1276 mCurrentState.layerStack = layerStack;
Dan Stoza7dde5992015-05-22 09:51:44 -07001277 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001278 setTransactionFlags(eTransactionNeeded);
1279 return true;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001280}
1281
Courtney Goeltzenleuchterbb09b432016-11-30 13:51:28 -07001282bool Layer::setDataSpace(android_dataspace dataSpace) {
David Sodman41fdfc92017-11-06 16:09:56 -08001283 if (mCurrentState.dataSpace == dataSpace) return false;
Courtney Goeltzenleuchterbb09b432016-11-30 13:51:28 -07001284 mCurrentState.sequence++;
1285 mCurrentState.dataSpace = dataSpace;
1286 mCurrentState.modified = true;
1287 setTransactionFlags(eTransactionNeeded);
1288 return true;
1289}
1290
Courtney Goeltzenleuchter532b2632017-05-05 16:34:38 -06001291android_dataspace Layer::getDataSpace() const {
1292 return mCurrentState.dataSpace;
1293}
1294
Robert Carr1f0a16a2016-10-24 16:27:39 -07001295uint32_t Layer::getLayerStack() const {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001296 auto p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001297 if (p == nullptr) {
1298 return getDrawingState().layerStack;
1299 }
1300 return p->getLayerStack();
1301}
1302
David Sodman41fdfc92017-11-06 16:09:56 -08001303void Layer::deferTransactionUntil(const sp<Layer>& barrierLayer, uint64_t frameNumber) {
Robert Carr0d480722017-01-10 16:42:54 -08001304 mCurrentState.barrierLayer = barrierLayer;
Dan Stoza7dde5992015-05-22 09:51:44 -07001305 mCurrentState.frameNumber = frameNumber;
1306 // We don't set eTransactionNeeded, because just receiving a deferral
1307 // request without any other state updates shouldn't actually induce a delay
1308 mCurrentState.modified = true;
1309 pushPendingState();
Robert Carr0d480722017-01-10 16:42:54 -08001310 mCurrentState.barrierLayer = nullptr;
Dan Stoza792e5292016-02-11 11:43:58 -08001311 mCurrentState.frameNumber = 0;
Dan Stoza7dde5992015-05-22 09:51:44 -07001312 mCurrentState.modified = false;
Robert Carr0d480722017-01-10 16:42:54 -08001313}
1314
David Sodman41fdfc92017-11-06 16:09:56 -08001315void Layer::deferTransactionUntil(const sp<IBinder>& barrierHandle, uint64_t frameNumber) {
Robert Carr0d480722017-01-10 16:42:54 -08001316 sp<Handle> handle = static_cast<Handle*>(barrierHandle.get());
1317 deferTransactionUntil(handle->owner.promote(), frameNumber);
Dan Stoza7dde5992015-05-22 09:51:44 -07001318}
1319
Dan Stozaee44edd2015-03-23 15:50:23 -07001320
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001321// ----------------------------------------------------------------------------
1322// pageflip handling...
1323// ----------------------------------------------------------------------------
1324
Robert Carr1f0a16a2016-10-24 16:27:39 -07001325bool Layer::isHiddenByPolicy() const {
1326 const Layer::State& s(mDrawingState);
Chia-I Wue41dbe62017-06-13 14:10:56 -07001327 const auto& parent = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001328 if (parent != nullptr && parent->isHiddenByPolicy()) {
1329 return true;
1330 }
1331 return s.flags & layer_state_t::eLayerHidden;
1332}
1333
David Sodman41fdfc92017-11-06 16:09:56 -08001334uint32_t Layer::getEffectiveUsage(uint32_t usage) const {
Mathias Agopiana67932f2011-04-20 14:20:59 -07001335 // TODO: should we do something special if mSecure is set?
1336 if (mProtectedByApp) {
1337 // need a hardware-protected path to external video sink
1338 usage |= GraphicBuffer::USAGE_PROTECTED;
Jamie Gennis54cc83e2010-11-02 11:51:32 -07001339 }
Riley Andrews03414a12014-07-01 14:22:59 -07001340 if (mPotentialCursor) {
1341 usage |= GraphicBuffer::USAGE_CURSOR;
1342 }
Jamie Gennis3599bf22011-08-10 11:48:07 -07001343 usage |= GraphicBuffer::USAGE_HW_COMPOSER;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001344 return usage;
Mathias Agopianb5b7f262010-05-07 15:58:44 -07001345}
1346
Mathias Agopian84300952012-11-21 16:02:13 -08001347void Layer::updateTransformHint(const sp<const DisplayDevice>& hw) const {
Mathias Agopiana4583642011-08-23 18:03:18 -07001348 uint32_t orientation = 0;
1349 if (!mFlinger->mDebugDisableTransformHint) {
Mathias Agopian84300952012-11-21 16:02:13 -08001350 // The transform hint is used to improve performance, but we can
1351 // only have a single transform hint, it cannot
Mathias Agopian4fec8732012-06-29 14:12:52 -07001352 // apply to all displays.
Mathias Agopian42977342012-08-05 00:40:46 -07001353 const Transform& planeTransform(hw->getTransform());
Mathias Agopian4fec8732012-06-29 14:12:52 -07001354 orientation = planeTransform.getOrientation();
Mathias Agopiana4583642011-08-23 18:03:18 -07001355 if (orientation & Transform::ROT_INVALID) {
1356 orientation = 0;
1357 }
1358 }
David Sodmaneb085e02017-10-05 18:49:04 -07001359 setTransformHint(orientation);
Mathias Agopiana4583642011-08-23 18:03:18 -07001360}
1361
Mathias Agopian13127d82013-03-05 17:47:11 -08001362// ----------------------------------------------------------------------------
1363// debugging
1364// ----------------------------------------------------------------------------
1365
Kalle Raitaa099a242017-01-11 11:17:29 -08001366LayerDebugInfo Layer::getLayerDebugInfo() const {
1367 LayerDebugInfo info;
1368 const Layer::State& ds = getDrawingState();
1369 info.mName = getName();
chaviw1acbec72017-07-27 15:28:26 -07001370 sp<Layer> parent = getParent();
Kalle Raitaa099a242017-01-11 11:17:29 -08001371 info.mParentName = (parent == nullptr ? std::string("none") : parent->getName().string());
1372 info.mType = String8(getTypeId());
1373 info.mTransparentRegion = ds.activeTransparentRegion;
1374 info.mVisibleRegion = visibleRegion;
1375 info.mSurfaceDamageRegion = surfaceDamageRegion;
1376 info.mLayerStack = getLayerStack();
1377 info.mX = ds.active.transform.tx();
1378 info.mY = ds.active.transform.ty();
1379 info.mZ = ds.z;
1380 info.mWidth = ds.active.w;
1381 info.mHeight = ds.active.h;
1382 info.mCrop = ds.crop;
1383 info.mFinalCrop = ds.finalCrop;
chaviw13fdc492017-06-27 12:40:18 -07001384 info.mColor = ds.color;
Kalle Raitaa099a242017-01-11 11:17:29 -08001385 info.mFlags = ds.flags;
1386 info.mPixelFormat = getPixelFormat();
1387 info.mDataSpace = getDataSpace();
1388 info.mMatrix[0][0] = ds.active.transform[0][0];
1389 info.mMatrix[0][1] = ds.active.transform[0][1];
1390 info.mMatrix[1][0] = ds.active.transform[1][0];
1391 info.mMatrix[1][1] = ds.active.transform[1][1];
1392 {
David Sodman0cf8f8d2017-12-20 18:19:45 -08001393 sp<const GraphicBuffer> buffer = mActiveBuffer;
David Sodman5b4cffc2017-11-23 13:20:29 -08001394 if (buffer != 0) {
1395 info.mActiveBufferWidth = buffer->getWidth();
1396 info.mActiveBufferHeight = buffer->getHeight();
1397 info.mActiveBufferStride = buffer->getStride();
1398 info.mActiveBufferFormat = buffer->format;
Kalle Raitaa099a242017-01-11 11:17:29 -08001399 } else {
1400 info.mActiveBufferWidth = 0;
1401 info.mActiveBufferHeight = 0;
1402 info.mActiveBufferStride = 0;
1403 info.mActiveBufferFormat = 0;
1404 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001405 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001406 info.mNumQueuedFrames = getQueuedFrameCount();
1407 info.mRefreshPending = isBufferLatched();
1408 info.mIsOpaque = isOpaque(ds);
1409 info.mContentDirty = contentDirty;
1410 return info;
Mathias Agopian13127d82013-03-05 17:47:11 -08001411}
Chia-I Wu83ce7c12017-10-19 15:18:55 -07001412
Dan Stozae22aec72016-08-01 13:20:59 -07001413void Layer::miniDumpHeader(String8& result) {
1414 result.append("----------------------------------------");
1415 result.append("---------------------------------------\n");
1416 result.append(" Layer name\n");
1417 result.append(" Z | ");
1418 result.append(" Comp Type | ");
1419 result.append(" Disp Frame (LTRB) | ");
1420 result.append(" Source Crop (LTRB)\n");
1421 result.append("----------------------------------------");
1422 result.append("---------------------------------------\n");
1423}
1424
1425void Layer::miniDump(String8& result, int32_t hwcId) const {
David Sodman6f65f3e2017-11-03 14:28:09 -07001426 if (getBE().mHwcLayers.count(hwcId) == 0) {
Dan Stozae22aec72016-08-01 13:20:59 -07001427 return;
1428 }
1429
1430 String8 name;
1431 if (mName.length() > 77) {
1432 std::string shortened;
1433 shortened.append(mName.string(), 36);
1434 shortened.append("[...]");
1435 shortened.append(mName.string() + (mName.length() - 36), 36);
1436 name = shortened.c_str();
1437 } else {
1438 name = mName;
1439 }
1440
1441 result.appendFormat(" %s\n", name.string());
1442
1443 const Layer::State& layerState(getDrawingState());
John Reck8c3b6ac2017-08-24 10:25:42 -07001444 result.appendFormat(" %10d | ", layerState.z);
David Sodman41fdfc92017-11-06 16:09:56 -08001445 result.appendFormat("%10s | ", to_string(getCompositionType(hwcId)).c_str());
David Sodman4b7c4bc2017-11-17 12:13:59 -08001446 const Rect& frame = getBE().compositionInfo.hwc.displayFrame;
David Sodman41fdfc92017-11-06 16:09:56 -08001447 result.appendFormat("%4d %4d %4d %4d | ", frame.left, frame.top, frame.right, frame.bottom);
David Sodman4b7c4bc2017-11-17 12:13:59 -08001448 const FloatRect& crop = getBE().compositionInfo.hwc.sourceCrop;
David Sodman41fdfc92017-11-06 16:09:56 -08001449 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 -07001450
1451 result.append("- - - - - - - - - - - - - - - - - - - - ");
1452 result.append("- - - - - - - - - - - - - - - - - - - -\n");
1453}
Dan Stozae22aec72016-08-01 13:20:59 -07001454
Svetoslavd85084b2014-03-20 10:28:31 -07001455void Layer::dumpFrameStats(String8& result) const {
1456 mFrameTracker.dumpStats(result);
Mathias Agopian13127d82013-03-05 17:47:11 -08001457}
1458
Svetoslavd85084b2014-03-20 10:28:31 -07001459void Layer::clearFrameStats() {
1460 mFrameTracker.clearStats();
Mathias Agopian13127d82013-03-05 17:47:11 -08001461}
1462
Jamie Gennis6547ff42013-07-16 20:12:42 -07001463void Layer::logFrameStats() {
1464 mFrameTracker.logAndResetStats(mName);
1465}
1466
Svetoslavd85084b2014-03-20 10:28:31 -07001467void Layer::getFrameStats(FrameStats* outStats) const {
1468 mFrameTracker.getStats(outStats);
1469}
1470
Brian Andersond6927fb2016-07-23 23:37:30 -07001471void Layer::dumpFrameEvents(String8& result) {
David Sodman41fdfc92017-11-06 16:09:56 -08001472 result.appendFormat("- Layer %s (%s, %p)\n", getName().string(), getTypeId(), this);
Brian Andersond6927fb2016-07-23 23:37:30 -07001473 Mutex::Autolock lock(mFrameEventHistoryMutex);
1474 mFrameEventHistory.checkFencesForCompletion();
1475 mFrameEventHistory.dump(result);
1476}
Pablo Ceballos40845df2016-01-25 17:41:15 -08001477
Brian Anderson5ea5e592016-12-01 16:54:33 -08001478void Layer::onDisconnect() {
1479 Mutex::Autolock lock(mFrameEventHistoryMutex);
1480 mFrameEventHistory.onDisconnect();
1481}
1482
Brian Anderson3890c392016-07-25 12:48:08 -07001483void Layer::addAndGetFrameTimestamps(const NewFrameEventsEntry* newTimestamps,
David Sodman41fdfc92017-11-06 16:09:56 -08001484 FrameEventHistoryDelta* outDelta) {
Brian Andersond6927fb2016-07-23 23:37:30 -07001485 Mutex::Autolock lock(mFrameEventHistoryMutex);
1486 if (newTimestamps) {
Brian Andersonfbc80ae2017-05-26 16:23:54 -07001487 // If there are any unsignaled fences in the aquire timeline at this
1488 // point, the previously queued frame hasn't been latched yet. Go ahead
1489 // and try to get the signal time here so the syscall is taken out of
1490 // the main thread's critical path.
1491 mAcquireTimeline.updateSignalTimes();
1492 // Push the new fence after updating since it's likely still pending.
Brian Anderson3d4039d2016-09-23 16:31:30 -07001493 mAcquireTimeline.push(newTimestamps->acquireFence);
Brian Andersond6927fb2016-07-23 23:37:30 -07001494 mFrameEventHistory.addQueue(*newTimestamps);
1495 }
1496
Brian Anderson3890c392016-07-25 12:48:08 -07001497 if (outDelta) {
1498 mFrameEventHistory.getAndResetDelta(outDelta);
Brian Andersond6927fb2016-07-23 23:37:30 -07001499 }
Pablo Ceballos40845df2016-01-25 17:41:15 -08001500}
Dan Stozae77c7662016-05-13 11:37:28 -07001501
Chia-I Wu98f1c102017-05-30 14:54:08 -07001502size_t Layer::getChildrenCount() const {
1503 size_t count = 0;
1504 for (const sp<Layer>& child : mCurrentChildren) {
1505 count += 1 + child->getChildrenCount();
1506 }
1507 return count;
1508}
1509
Robert Carr1f0a16a2016-10-24 16:27:39 -07001510void Layer::addChild(const sp<Layer>& layer) {
1511 mCurrentChildren.add(layer);
1512 layer->setParent(this);
1513}
1514
1515ssize_t Layer::removeChild(const sp<Layer>& layer) {
1516 layer->setParent(nullptr);
1517 return mCurrentChildren.remove(layer);
1518}
1519
Robert Carr1db73f62016-12-21 12:58:51 -08001520bool Layer::reparentChildren(const sp<IBinder>& newParentHandle) {
1521 sp<Handle> handle = nullptr;
1522 sp<Layer> newParent = nullptr;
1523 if (newParentHandle == nullptr) {
1524 return false;
1525 }
1526 handle = static_cast<Handle*>(newParentHandle.get());
1527 newParent = handle->owner.promote();
1528 if (newParent == nullptr) {
1529 ALOGE("Unable to promote Layer handle");
1530 return false;
1531 }
1532
1533 for (const sp<Layer>& child : mCurrentChildren) {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001534 newParent->addChild(child);
Robert Carr1db73f62016-12-21 12:58:51 -08001535
1536 sp<Client> client(child->mClientRef.promote());
1537 if (client != nullptr) {
1538 client->setParentLayer(newParent);
1539 }
1540 }
1541 mCurrentChildren.clear();
1542
1543 return true;
1544}
1545
Robert Carr578038f2018-03-09 12:25:24 -08001546void Layer::reparentChildrenForDrawing(const sp<Layer>& newParent) {
1547 for (const sp<Layer>& child : mDrawingChildren) {
1548 child->mDrawingParent = newParent;
1549 }
1550}
1551
chaviwf1961f72017-09-18 16:41:07 -07001552bool Layer::reparent(const sp<IBinder>& newParentHandle) {
1553 if (newParentHandle == nullptr) {
chaviw06178942017-07-27 10:25:59 -07001554 return false;
1555 }
1556
1557 auto handle = static_cast<Handle*>(newParentHandle.get());
1558 sp<Layer> newParent = handle->owner.promote();
1559 if (newParent == nullptr) {
1560 ALOGE("Unable to promote Layer handle");
1561 return false;
1562 }
1563
chaviwf1961f72017-09-18 16:41:07 -07001564 sp<Layer> parent = getParent();
1565 if (parent != nullptr) {
1566 parent->removeChild(this);
chaviw06178942017-07-27 10:25:59 -07001567 }
chaviwf1961f72017-09-18 16:41:07 -07001568 newParent->addChild(this);
chaviw06178942017-07-27 10:25:59 -07001569
chaviwf1961f72017-09-18 16:41:07 -07001570 sp<Client> client(mClientRef.promote());
chaviw06178942017-07-27 10:25:59 -07001571 sp<Client> newParentClient(newParent->mClientRef.promote());
1572
chaviwf1961f72017-09-18 16:41:07 -07001573 if (client != newParentClient) {
1574 client->setParentLayer(newParent);
chaviw06178942017-07-27 10:25:59 -07001575 }
1576
chaviw06178942017-07-27 10:25:59 -07001577 return true;
1578}
1579
Robert Carr9524cb32017-02-13 11:32:32 -08001580bool Layer::detachChildren() {
Robert Carr7f619b22017-11-06 12:56:35 -08001581 for (const sp<Layer>& child : mCurrentChildren) {
chaviw161410b02017-07-27 10:46:08 -07001582 sp<Client> parentClient = mClientRef.promote();
Robert Carr9524cb32017-02-13 11:32:32 -08001583 sp<Client> client(child->mClientRef.promote());
chaviw161410b02017-07-27 10:46:08 -07001584 if (client != nullptr && parentClient != client) {
Robert Carr7f619b22017-11-06 12:56:35 -08001585 client->detachLayer(child.get());
1586 child->detachChildren();
Robert Carr9524cb32017-02-13 11:32:32 -08001587 }
Robert Carr7f619b22017-11-06 12:56:35 -08001588 }
Robert Carr9524cb32017-02-13 11:32:32 -08001589
1590 return true;
1591}
1592
Robert Carr1f0a16a2016-10-24 16:27:39 -07001593void Layer::setParent(const sp<Layer>& layer) {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001594 mCurrentParent = layer;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001595}
1596
1597void Layer::clearSyncPoints() {
1598 for (const auto& child : mCurrentChildren) {
1599 child->clearSyncPoints();
1600 }
1601
1602 Mutex::Autolock lock(mLocalSyncPointMutex);
1603 for (auto& point : mLocalSyncPoints) {
1604 point->setFrameAvailable();
1605 }
1606 mLocalSyncPoints.clear();
1607}
1608
1609int32_t Layer::getZ() const {
1610 return mDrawingState.z;
1611}
1612
Robert Carr29abff82017-12-04 13:51:20 -08001613bool Layer::usingRelativeZ(LayerVector::StateSet stateSet) {
1614 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1615 const State& state = useDrawing ? mDrawingState : mCurrentState;
1616 return state.zOrderRelativeOf != nullptr;
1617}
1618
David Sodman41fdfc92017-11-06 16:09:56 -08001619__attribute__((no_sanitize("unsigned-integer-overflow"))) LayerVector Layer::makeTraversalList(
Robert Carr29abff82017-12-04 13:51:20 -08001620 LayerVector::StateSet stateSet, bool* outSkipRelativeZUsers) {
Dan Stoza412903f2017-04-27 13:42:17 -07001621 LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid,
1622 "makeTraversalList received invalid stateSet");
1623 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1624 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
1625 const State& state = useDrawing ? mDrawingState : mCurrentState;
1626
Robert Carr29abff82017-12-04 13:51:20 -08001627 if (state.zOrderRelatives.size() == 0) {
1628 *outSkipRelativeZUsers = true;
1629 return children;
1630 }
1631
Robert Carrdb66e622017-04-10 16:55:57 -07001632 LayerVector traverse;
Dan Stoza412903f2017-04-27 13:42:17 -07001633 for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
Robert Carrdb66e622017-04-10 16:55:57 -07001634 sp<Layer> strongRelative = weakRelative.promote();
1635 if (strongRelative != nullptr) {
1636 traverse.add(strongRelative);
Robert Carrdb66e622017-04-10 16:55:57 -07001637 }
1638 }
1639
Dan Stoza412903f2017-04-27 13:42:17 -07001640 for (const sp<Layer>& child : children) {
Robert Carr503c7042017-09-27 15:06:08 -07001641 const State& childState = useDrawing ? child->mDrawingState : child->mCurrentState;
1642 if (childState.zOrderRelativeOf != nullptr) {
1643 continue;
1644 }
Robert Carrdb66e622017-04-10 16:55:57 -07001645 traverse.add(child);
1646 }
1647
1648 return traverse;
1649}
1650
Robert Carr1f0a16a2016-10-24 16:27:39 -07001651/**
Robert Carrdb66e622017-04-10 16:55:57 -07001652 * Negatively signed relatives are before 'this' in Z-order.
Robert Carr1f0a16a2016-10-24 16:27:39 -07001653 */
Dan Stoza412903f2017-04-27 13:42:17 -07001654void Layer::traverseInZOrder(LayerVector::StateSet stateSet, const LayerVector::Visitor& visitor) {
Robert Carr29abff82017-12-04 13:51:20 -08001655 // In the case we have other layers who are using a relative Z to us, makeTraversalList will
1656 // produce a new list for traversing, including our relatives, and not including our children
1657 // who are relatives of another surface. In the case that there are no relative Z,
1658 // makeTraversalList returns our children directly to avoid significant overhead.
1659 // However in this case we need to take the responsibility for filtering children which
1660 // are relatives of another surface here.
1661 bool skipRelativeZUsers = false;
1662 const LayerVector list = makeTraversalList(stateSet, &skipRelativeZUsers);
Robert Carrdb66e622017-04-10 16:55:57 -07001663
Robert Carr1f0a16a2016-10-24 16:27:39 -07001664 size_t i = 0;
Robert Carrdb66e622017-04-10 16:55:57 -07001665 for (; i < list.size(); i++) {
1666 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001667 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1668 continue;
1669 }
1670
Robert Carrdb66e622017-04-10 16:55:57 -07001671 if (relative->getZ() >= 0) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001672 break;
Robert Carrdb66e622017-04-10 16:55:57 -07001673 }
Dan Stoza412903f2017-04-27 13:42:17 -07001674 relative->traverseInZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001675 }
Robert Carr29abff82017-12-04 13:51:20 -08001676
Dan Stoza412903f2017-04-27 13:42:17 -07001677 visitor(this);
Robert Carrdb66e622017-04-10 16:55:57 -07001678 for (; i < list.size(); i++) {
1679 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001680
1681 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1682 continue;
1683 }
Dan Stoza412903f2017-04-27 13:42:17 -07001684 relative->traverseInZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001685 }
1686}
1687
1688/**
Robert Carrdb66e622017-04-10 16:55:57 -07001689 * Positively signed relatives are before 'this' in reverse Z-order.
Robert Carr1f0a16a2016-10-24 16:27:39 -07001690 */
Dan Stoza412903f2017-04-27 13:42:17 -07001691void Layer::traverseInReverseZOrder(LayerVector::StateSet stateSet,
1692 const LayerVector::Visitor& visitor) {
Robert Carr29abff82017-12-04 13:51:20 -08001693 // See traverseInZOrder for documentation.
1694 bool skipRelativeZUsers = false;
1695 LayerVector list = makeTraversalList(stateSet, &skipRelativeZUsers);
Robert Carrdb66e622017-04-10 16:55:57 -07001696
Robert Carr1f0a16a2016-10-24 16:27:39 -07001697 int32_t i = 0;
Joel Galensonbf324992017-11-06 11:04:12 -08001698 for (i = int32_t(list.size()) - 1; i >= 0; i--) {
Robert Carrdb66e622017-04-10 16:55:57 -07001699 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001700
1701 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1702 continue;
1703 }
1704
Robert Carrdb66e622017-04-10 16:55:57 -07001705 if (relative->getZ() < 0) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001706 break;
1707 }
Dan Stoza412903f2017-04-27 13:42:17 -07001708 relative->traverseInReverseZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001709 }
Dan Stoza412903f2017-04-27 13:42:17 -07001710 visitor(this);
David Sodman41fdfc92017-11-06 16:09:56 -08001711 for (; i >= 0; i--) {
Robert Carrdb66e622017-04-10 16:55:57 -07001712 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001713
1714 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1715 continue;
1716 }
1717
Dan Stoza412903f2017-04-27 13:42:17 -07001718 relative->traverseInReverseZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001719 }
1720}
1721
chaviwa76b2712017-09-20 12:02:26 -07001722/**
1723 * Traverse only children in z order, ignoring relative layers.
1724 */
1725void Layer::traverseChildrenInZOrder(LayerVector::StateSet stateSet,
1726 const LayerVector::Visitor& visitor) {
1727 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1728 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
1729
1730 size_t i = 0;
1731 for (; i < children.size(); i++) {
1732 const auto& relative = children[i];
1733 if (relative->getZ() >= 0) {
1734 break;
1735 }
1736 relative->traverseChildrenInZOrder(stateSet, visitor);
1737 }
1738 visitor(this);
1739 for (; i < children.size(); i++) {
1740 const auto& relative = children[i];
1741 relative->traverseChildrenInZOrder(stateSet, visitor);
1742 }
1743}
1744
Robert Carr1f0a16a2016-10-24 16:27:39 -07001745Transform Layer::getTransform() const {
1746 Transform t;
Chia-I Wue41dbe62017-06-13 14:10:56 -07001747 const auto& p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001748 if (p != nullptr) {
1749 t = p->getTransform();
Robert Carr9b429f42017-04-17 14:56:57 -07001750
1751 // If the parent is not using NATIVE_WINDOW_SCALING_MODE_FREEZE (e.g.
1752 // it isFixedSize) then there may be additional scaling not accounted
1753 // for in the transform. We need to mirror this scaling in child surfaces
1754 // or we will break the contract where WM can treat child surfaces as
1755 // pixels in the parent surface.
David Sodman0cc69182017-11-17 12:12:07 -08001756 if (p->isFixedSize() && p->getBE().compositionInfo.mBuffer != nullptr) {
Robert Carr1725eee2017-04-26 18:32:15 -07001757 int bufferWidth;
1758 int bufferHeight;
1759 if ((p->mCurrentTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) == 0) {
David Sodman0cc69182017-11-17 12:12:07 -08001760 bufferWidth = p->getBE().compositionInfo.mBuffer->getWidth();
1761 bufferHeight = p->getBE().compositionInfo.mBuffer->getHeight();
Robert Carr1725eee2017-04-26 18:32:15 -07001762 } else {
David Sodman0cc69182017-11-17 12:12:07 -08001763 bufferHeight = p->getBE().compositionInfo.mBuffer->getWidth();
1764 bufferWidth = p->getBE().compositionInfo.mBuffer->getHeight();
Robert Carr1725eee2017-04-26 18:32:15 -07001765 }
David Sodman41fdfc92017-11-06 16:09:56 -08001766 float sx = p->getDrawingState().active.w / static_cast<float>(bufferWidth);
1767 float sy = p->getDrawingState().active.h / static_cast<float>(bufferHeight);
Robert Carr9b429f42017-04-17 14:56:57 -07001768 Transform extraParentScaling;
1769 extraParentScaling.set(sx, 0, 0, sy);
1770 t = t * extraParentScaling;
1771 }
Robert Carr1f0a16a2016-10-24 16:27:39 -07001772 }
1773 return t * getDrawingState().active.transform;
1774}
1775
chaviw13fdc492017-06-27 12:40:18 -07001776half Layer::getAlpha() const {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001777 const auto& p = mDrawingParent.promote();
Robert Carr6452f122017-03-21 10:41:29 -07001778
chaviw13fdc492017-06-27 12:40:18 -07001779 half parentAlpha = (p != nullptr) ? p->getAlpha() : 1.0_hf;
1780 return parentAlpha * getDrawingState().color.a;
Robert Carr6452f122017-03-21 10:41:29 -07001781}
Robert Carr6452f122017-03-21 10:41:29 -07001782
chaviw13fdc492017-06-27 12:40:18 -07001783half4 Layer::getColor() const {
1784 const half4 color(getDrawingState().color);
1785 return half4(color.r, color.g, color.b, getAlpha());
Robert Carr6452f122017-03-21 10:41:29 -07001786}
Robert Carr6452f122017-03-21 10:41:29 -07001787
Robert Carr1f0a16a2016-10-24 16:27:39 -07001788void Layer::commitChildList() {
1789 for (size_t i = 0; i < mCurrentChildren.size(); i++) {
1790 const auto& child = mCurrentChildren[i];
1791 child->commitChildList();
1792 }
1793 mDrawingChildren = mCurrentChildren;
Chia-I Wue41dbe62017-06-13 14:10:56 -07001794 mDrawingParent = mCurrentParent;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001795}
1796
chaviw1d044282017-09-27 12:19:28 -07001797void Layer::writeToProto(LayerProto* layerInfo, LayerVector::StateSet stateSet) {
1798 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1799 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
1800 const State& state = useDrawing ? mDrawingState : mCurrentState;
1801
1802 Transform requestedTransform = state.active.transform;
1803 Transform transform = getTransform();
1804
1805 layerInfo->set_id(sequence);
1806 layerInfo->set_name(getName().c_str());
1807 layerInfo->set_type(String8(getTypeId()));
1808
1809 for (const auto& child : children) {
1810 layerInfo->add_children(child->sequence);
1811 }
1812
1813 for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
1814 sp<Layer> strongRelative = weakRelative.promote();
1815 if (strongRelative != nullptr) {
1816 layerInfo->add_relatives(strongRelative->sequence);
1817 }
1818 }
1819
1820 LayerProtoHelper::writeToProto(state.activeTransparentRegion,
1821 layerInfo->mutable_transparent_region());
1822 LayerProtoHelper::writeToProto(visibleRegion, layerInfo->mutable_visible_region());
1823 LayerProtoHelper::writeToProto(surfaceDamageRegion, layerInfo->mutable_damage_region());
1824
1825 layerInfo->set_layer_stack(getLayerStack());
1826 layerInfo->set_z(state.z);
1827
1828 PositionProto* position = layerInfo->mutable_position();
1829 position->set_x(transform.tx());
1830 position->set_y(transform.ty());
1831
1832 PositionProto* requestedPosition = layerInfo->mutable_requested_position();
1833 requestedPosition->set_x(requestedTransform.tx());
1834 requestedPosition->set_y(requestedTransform.ty());
1835
1836 SizeProto* size = layerInfo->mutable_size();
1837 size->set_w(state.active.w);
1838 size->set_h(state.active.h);
1839
1840 LayerProtoHelper::writeToProto(state.crop, layerInfo->mutable_crop());
1841 LayerProtoHelper::writeToProto(state.finalCrop, layerInfo->mutable_final_crop());
1842
1843 layerInfo->set_is_opaque(isOpaque(state));
1844 layerInfo->set_invalidate(contentDirty);
1845 layerInfo->set_dataspace(dataspaceDetails(getDataSpace()));
1846 layerInfo->set_pixel_format(decodePixelFormat(getPixelFormat()));
1847 LayerProtoHelper::writeToProto(getColor(), layerInfo->mutable_color());
1848 LayerProtoHelper::writeToProto(state.color, layerInfo->mutable_requested_color());
1849 layerInfo->set_flags(state.flags);
1850
1851 LayerProtoHelper::writeToProto(transform, layerInfo->mutable_transform());
1852 LayerProtoHelper::writeToProto(requestedTransform, layerInfo->mutable_requested_transform());
1853
Jorim Jaggi8e0af362017-11-14 16:28:28 +01001854 auto parent = useDrawing ? mDrawingParent.promote() : mCurrentParent.promote();
chaviw1d044282017-09-27 12:19:28 -07001855 if (parent != nullptr) {
1856 layerInfo->set_parent(parent->sequence);
1857 }
1858
1859 auto zOrderRelativeOf = state.zOrderRelativeOf.promote();
1860 if (zOrderRelativeOf != nullptr) {
1861 layerInfo->set_z_order_relative_of(zOrderRelativeOf->sequence);
1862 }
1863
David Sodman0cc69182017-11-17 12:12:07 -08001864 auto buffer = getBE().compositionInfo.mBuffer;
David Sodman5b4cffc2017-11-23 13:20:29 -08001865 if (buffer != nullptr) {
1866 LayerProtoHelper::writeToProto(buffer, layerInfo->mutable_active_buffer());
chaviw1d044282017-09-27 12:19:28 -07001867 }
1868
1869 layerInfo->set_queued_frames(getQueuedFrameCount());
1870 layerInfo->set_refresh_pending(isBufferLatched());
rongliucfb187b2018-03-14 12:26:23 -07001871 layerInfo->set_window_type(state.type);
1872 layerInfo->set_app_id(state.appId);
chaviw1d044282017-09-27 12:19:28 -07001873}
1874
Yiwei Zhang7124ad32018-02-21 13:02:45 -08001875void Layer::writeToProto(LayerProto* layerInfo, int32_t hwcId) {
1876 writeToProto(layerInfo, LayerVector::StateSet::Drawing);
1877
1878 const auto& hwcInfo = getBE().mHwcLayers.at(hwcId);
1879
1880 const Rect& frame = hwcInfo.displayFrame;
1881 LayerProtoHelper::writeToProto(frame, layerInfo->mutable_hwc_frame());
1882
1883 const FloatRect& crop = hwcInfo.sourceCrop;
1884 LayerProtoHelper::writeToProto(crop, layerInfo->mutable_hwc_crop());
1885
1886 const int32_t transform = static_cast<int32_t>(hwcInfo.transform);
1887 layerInfo->set_hwc_transform(transform);
1888}
1889
Mathias Agopian13127d82013-03-05 17:47:11 -08001890// ---------------------------------------------------------------------------
1891
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001892}; // namespace android
Mathias Agopian3f844832013-08-07 21:24:32 -07001893
1894#if defined(__gl_h_)
1895#error "don't include gl/gl.h in this file"
1896#endif
1897
1898#if defined(__gl2_h_)
1899#error "don't include gl2/gl2.h in this file"
1900#endif