blob: 80987a4f91fdc84386dd17c2dc6e93dabf5aafdb [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>
Mathias Agopiana9347642017-02-13 16:42:28 -080042#include <gui/BufferQueue.h>
Kalle Raitaa099a242017-01-11 11:17:29 -080043#include <gui/LayerDebugInfo.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080044#include <gui/Surface.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045
Mathias Agopian3e25fd82013-04-22 17:52:16 +020046#include "Colorizer.h"
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070047#include "DisplayDevice.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048#include "Layer.h"
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070049#include "LayerRejecter.h"
Dan Stozab9b08832014-03-13 11:55:57 -070050#include "MonitoredProducer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051#include "SurfaceFlinger.h"
David Sodman41fdfc92017-11-06 16:09:56 -080052#include "clz.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053
Mathias Agopian1b031492012-06-20 17:51:20 -070054#include "DisplayHardware/HWComposer.h"
55
Mathias Agopian875d8e12013-06-07 15:35:48 -070056#include "RenderEngine/RenderEngine.h"
57
Dan Stozac5da2712016-07-20 15:38:12 -070058#include <mutex>
chaviw1d044282017-09-27 12:19:28 -070059#include "LayerProtoHelper.h"
Dan Stozac5da2712016-07-20 15:38:12 -070060
David Sodman41fdfc92017-11-06 16:09:56 -080061#define DEBUG_RESIZE 0
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080062
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080063namespace android {
64
Mathias Agopian13127d82013-03-05 17:47:11 -080065int32_t Layer::sSequence = 1;
66
David Sodman41fdfc92017-11-06 16:09:56 -080067Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client, const String8& name, uint32_t w,
68 uint32_t h, uint32_t flags)
David Sodman0c69cad2017-08-21 12:12:51 -070069 : contentDirty(false),
Mathias Agopian13127d82013-03-05 17:47:11 -080070 sequence(uint32_t(android_atomic_inc(&sSequence))),
71 mFlinger(flinger),
Mathias Agopian13127d82013-03-05 17:47:11 -080072 mPremultipliedAlpha(true),
David Sodman0c69cad2017-08-21 12:12:51 -070073 mName(name),
Mathias Agopian13127d82013-03-05 17:47:11 -080074 mTransactionFlags(0),
Dan Stoza7dde5992015-05-22 09:51:44 -070075 mPendingStateMutex(),
76 mPendingStates(),
Mathias Agopiana67932f2011-04-20 14:20:59 -070077 mQueuedFrames(0),
Jesse Hall399184a2014-03-03 15:42:54 -080078 mSidebandStreamChanged(false),
Mathias Agopiana9347642017-02-13 16:42:28 -080079 mActiveBufferSlot(BufferQueue::INVALID_BUFFER_SLOT),
Mathias Agopiana67932f2011-04-20 14:20:59 -070080 mCurrentTransform(0),
Robert Carrc3574f72016-03-24 12:19:32 -070081 mOverrideScalingMode(-1),
Mathias Agopiana67932f2011-04-20 14:20:59 -070082 mCurrentOpacity(true),
Dan Stozacac35382016-01-27 12:21:06 -080083 mCurrentFrameNumber(0),
Mathias Agopian82d7ab62012-01-19 18:34:40 -080084 mFrameLatencyNeeded(false),
Mathias Agopian13127d82013-03-05 17:47:11 -080085 mFiltering(false),
86 mNeedsFiltering(false),
Mathias Agopian5cdc8992013-08-13 20:51:23 -070087 mMesh(Mesh::TRIANGLE_FAN, 4, 2, 2),
Fabien Sanglard9d96de42016-10-11 00:15:18 +000088#ifndef USE_HWC2
89 mIsGlesComposition(false),
90#endif
Mathias Agopian13127d82013-03-05 17:47:11 -080091 mProtectedByApp(false),
Riley Andrews03414a12014-07-01 14:22:59 -070092 mClientRef(client),
Dan Stozaa4650a52015-05-12 12:56:16 -070093 mPotentialCursor(false),
94 mQueueItemLock(),
95 mQueueItemCondition(),
96 mQueueItems(),
Dan Stoza65476f32015-05-14 09:27:25 -070097 mLastFrameNumberReceived(0),
Robert Carr82364e32016-05-15 11:27:47 -070098 mAutoRefresh(false),
David Sodman41fdfc92017-11-06 16:09:56 -080099 mFreezeGeometryUpdates(false) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800100
Mathias Agopiana67932f2011-04-20 14:20:59 -0700101 mCurrentCrop.makeInvalid();
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700102
103 uint32_t layerFlags = 0;
David Sodman41fdfc92017-11-06 16:09:56 -0800104 if (flags & ISurfaceComposerClient::eHidden) layerFlags |= layer_state_t::eLayerHidden;
105 if (flags & ISurfaceComposerClient::eOpaque) layerFlags |= layer_state_t::eLayerOpaque;
106 if (flags & ISurfaceComposerClient::eSecure) layerFlags |= layer_state_t::eLayerSecure;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700107
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700108 mName = name;
Dan Stozaf7ba41a2017-05-10 15:11:11 -0700109 mTransactionName = String8("TX - ") + mName;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700110
111 mCurrentState.active.w = w;
112 mCurrentState.active.h = h;
David Sodman0c69cad2017-08-21 12:12:51 -0700113 mCurrentState.flags = layerFlags;
Robert Carr3dcabfa2016-03-01 18:36:58 -0800114 mCurrentState.active.transform.set(0, 0);
Robert Carrb5d3d262016-03-25 15:08:13 -0700115 mCurrentState.crop.makeInvalid();
116 mCurrentState.finalCrop.makeInvalid();
Robert Carr7bf247e2017-05-18 14:02:49 -0700117 mCurrentState.requestedFinalCrop = mCurrentState.finalCrop;
118 mCurrentState.requestedCrop = mCurrentState.crop;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700119 mCurrentState.z = 0;
chaviw13fdc492017-06-27 12:40:18 -0700120 mCurrentState.color.a = 1.0f;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700121 mCurrentState.layerStack = 0;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700122 mCurrentState.sequence = 0;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700123 mCurrentState.requested = mCurrentState.active;
Courtney Goeltzenleuchterbb09b432016-11-30 13:51:28 -0700124 mCurrentState.dataSpace = HAL_DATASPACE_UNKNOWN;
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -0500125 mCurrentState.appId = 0;
126 mCurrentState.type = 0;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700127
128 // drawing state & current state are identical
129 mDrawingState = mCurrentState;
Jamie Gennis6547ff42013-07-16 20:12:42 -0700130
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000131#ifdef USE_HWC2
Dan Stoza9e56aa02015-11-02 13:00:03 -0800132 const auto& hwc = flinger->getHwComposer();
133 const auto& activeConfig = hwc.getActiveConfig(HWC_DISPLAY_PRIMARY);
134 nsecs_t displayPeriod = activeConfig->getVsyncPeriod();
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000135#else
David Sodman41fdfc92017-11-06 16:09:56 -0800136 nsecs_t displayPeriod = flinger->getHwComposer().getRefreshPeriod(HWC_DISPLAY_PRIMARY);
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000137#endif
Jamie Gennis6547ff42013-07-16 20:12:42 -0700138 mFrameTracker.setDisplayRefreshPeriod(displayPeriod);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800139
140 CompositorTiming compositorTiming;
141 flinger->getCompositorTiming(&compositorTiming);
142 mFrameEventHistory.initializeCompositorTiming(compositorTiming);
Jamie Gennise8696a42012-01-15 18:54:57 -0800143}
144
David Sodman41fdfc92017-11-06 16:09:56 -0800145void Layer::onFirstRef() {}
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700146
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700147Layer::~Layer() {
Jamie Gennis6547ff42013-07-16 20:12:42 -0700148 mFrameTracker.logAndResetStats(mName);
Mathias Agopian96f08192010-06-02 23:28:45 -0700149}
150
Mathias Agopian13127d82013-03-05 17:47:11 -0800151// ---------------------------------------------------------------------------
152// callbacks
153// ---------------------------------------------------------------------------
154
David Sodmaneb085e02017-10-05 18:49:04 -0700155/*
156 * onLayerDisplayed is only meaningful for BufferLayer, but, is called through
157 * Layer. So, the implementation is done in BufferLayer. When called on a
158 * ColorLayer object, it's essentially a NOP.
159 */
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000160#ifdef USE_HWC2
David Sodmaneb085e02017-10-05 18:49:04 -0700161void Layer::onLayerDisplayed(const sp<Fence>& /*releaseFence*/) {}
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000162#else
163void Layer::onLayerDisplayed(const sp<const DisplayDevice>& /* hw */,
David Sodmaneb085e02017-10-05 18:49:04 -0700164 HWComposer::HWCLayerInterface* /*layer*/) {}
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000165#endif
Mathias Agopian13127d82013-03-05 17:47:11 -0800166
Chia-I Wuc6657022017-08-15 11:18:17 -0700167void Layer::onRemovedFromCurrentState() {
168 // the layer is removed from SF mCurrentState to mLayersPendingRemoval
169
chaviw8b3871a2017-11-01 17:41:01 -0700170 mPendingRemoval = true;
171
Robert Carr5edb1ad2017-04-25 10:54:24 -0700172 if (mCurrentState.zOrderRelativeOf != nullptr) {
173 sp<Layer> strongRelative = mCurrentState.zOrderRelativeOf.promote();
174 if (strongRelative != nullptr) {
175 strongRelative->removeZOrderRelative(this);
Chia-I Wuc6657022017-08-15 11:18:17 -0700176 mFlinger->setTransactionFlags(eTraversalNeeded);
Robert Carr5edb1ad2017-04-25 10:54:24 -0700177 }
178 mCurrentState.zOrderRelativeOf = nullptr;
179 }
180
Chia-I Wuc6657022017-08-15 11:18:17 -0700181 for (const auto& child : mCurrentChildren) {
182 child->onRemovedFromCurrentState();
183 }
184}
Chia-I Wu38512252017-05-17 14:36:16 -0700185
Chia-I Wuc6657022017-08-15 11:18:17 -0700186void Layer::onRemoved() {
187 // the layer is removed from SF mLayersPendingRemoval
David Sodmaneb085e02017-10-05 18:49:04 -0700188 abandon();
Chia-I Wuc6657022017-08-15 11:18:17 -0700189
Chia-I Wu38512252017-05-17 14:36:16 -0700190#ifdef USE_HWC2
Steven Thomasb02664d2017-07-26 18:48:28 -0700191 destroyAllHwcLayers();
Chia-I Wu38512252017-05-17 14:36:16 -0700192#endif
193
Robert Carr1f0a16a2016-10-24 16:27:39 -0700194 for (const auto& child : mCurrentChildren) {
195 child->onRemoved();
196 }
Mathias Agopian48d819a2009-09-10 19:41:18 -0700197}
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700198
Mathias Agopian13127d82013-03-05 17:47:11 -0800199// ---------------------------------------------------------------------------
200// set-up
201// ---------------------------------------------------------------------------
202
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700203const String8& Layer::getName() const {
Mathias Agopian13127d82013-03-05 17:47:11 -0800204 return mName;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800205}
206
chaviw13fdc492017-06-27 12:40:18 -0700207bool Layer::getPremultipledAlpha() const {
208 return mPremultipliedAlpha;
209}
210
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700211sp<IBinder> Layer::getHandle() {
Mathias Agopian13127d82013-03-05 17:47:11 -0800212 Mutex::Autolock _l(mLock);
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700213 return new Handle(mFlinger, this);
Mathias Agopian13127d82013-03-05 17:47:11 -0800214}
215
216// ---------------------------------------------------------------------------
217// h/w composer set-up
218// ---------------------------------------------------------------------------
219
Steven Thomasb02664d2017-07-26 18:48:28 -0700220#ifdef USE_HWC2
221bool Layer::createHwcLayer(HWComposer* hwc, int32_t hwcId) {
David Sodman41fdfc92017-11-06 16:09:56 -0800222 LOG_ALWAYS_FATAL_IF(mHwcLayers.count(hwcId) != 0, "Already have a layer for hwcId %d", hwcId);
Steven Thomasb02664d2017-07-26 18:48:28 -0700223 HWC2::Layer* layer = hwc->createLayer(hwcId);
224 if (!layer) {
225 return false;
226 }
227 HWCInfo& hwcInfo = mHwcLayers[hwcId];
228 hwcInfo.hwc = hwc;
229 hwcInfo.layer = layer;
230 layer->setLayerDestroyedListener(
David Sodman41fdfc92017-11-06 16:09:56 -0800231 [this, hwcId](HWC2::Layer* /*layer*/) { mHwcLayers.erase(hwcId); });
Steven Thomasb02664d2017-07-26 18:48:28 -0700232 return true;
233}
234
235void Layer::destroyHwcLayer(int32_t hwcId) {
236 if (mHwcLayers.count(hwcId) == 0) {
237 return;
238 }
239 auto& hwcInfo = mHwcLayers[hwcId];
David Sodman41fdfc92017-11-06 16:09:56 -0800240 LOG_ALWAYS_FATAL_IF(hwcInfo.layer == nullptr, "Attempt to destroy null layer");
Steven Thomasb02664d2017-07-26 18:48:28 -0700241 LOG_ALWAYS_FATAL_IF(hwcInfo.hwc == nullptr, "Missing HWComposer");
242 hwcInfo.hwc->destroyLayer(hwcId, hwcInfo.layer);
243 // The layer destroyed listener should have cleared the entry from
244 // mHwcLayers. Verify that.
David Sodman41fdfc92017-11-06 16:09:56 -0800245 LOG_ALWAYS_FATAL_IF(mHwcLayers.count(hwcId) != 0, "Stale layer entry in mHwcLayers");
Steven Thomasb02664d2017-07-26 18:48:28 -0700246}
247
248void Layer::destroyAllHwcLayers() {
249 size_t numLayers = mHwcLayers.size();
250 for (size_t i = 0; i < numLayers; ++i) {
251 LOG_ALWAYS_FATAL_IF(mHwcLayers.empty(), "destroyAllHwcLayers failed");
252 destroyHwcLayer(mHwcLayers.begin()->first);
253 }
254 LOG_ALWAYS_FATAL_IF(!mHwcLayers.empty(),
David Sodman41fdfc92017-11-06 16:09:56 -0800255 "All hardware composer layers should have been destroyed");
Steven Thomasb02664d2017-07-26 18:48:28 -0700256}
257#endif
258
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800259Rect Layer::getContentCrop() const {
260 // this is the crop rectangle that applies to the buffer
261 // itself (as opposed to the window)
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700262 Rect crop;
263 if (!mCurrentCrop.isEmpty()) {
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800264 // if the buffer crop is defined, we use that
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700265 crop = mCurrentCrop;
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800266 } else if (mActiveBuffer != NULL) {
267 // otherwise we use the whole buffer
268 crop = mActiveBuffer->getBounds();
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700269 } else {
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800270 // if we don't have a buffer yet, we use an empty/invalid crop
Mathias Agopian4fec8732012-06-29 14:12:52 -0700271 crop.makeInvalid();
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700272 }
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700273 return crop;
274}
275
Mathias Agopianf3e85d42013-05-10 18:01:12 -0700276static Rect reduce(const Rect& win, const Region& exclude) {
277 if (CC_LIKELY(exclude.isEmpty())) {
278 return win;
279 }
280 if (exclude.isRect()) {
281 return win.reduce(exclude.getBounds());
282 }
283 return Region(win).subtract(exclude).getBounds();
284}
285
Robert Carr1f0a16a2016-10-24 16:27:39 -0700286Rect Layer::computeScreenBounds(bool reduceTransparentRegion) const {
287 const Layer::State& s(getDrawingState());
288 Rect win(s.active.w, s.active.h);
289
290 if (!s.crop.isEmpty()) {
291 win.intersect(s.crop, &win);
292 }
293
294 Transform t = getTransform();
295 win = t.transform(win);
296
Robert Carr41b08b52017-06-01 16:11:34 -0700297 if (!s.finalCrop.isEmpty()) {
298 win.intersect(s.finalCrop, &win);
299 }
300
Chia-I Wue41dbe62017-06-13 14:10:56 -0700301 const sp<Layer>& p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700302 // Now we need to calculate the parent bounds, so we can clip ourselves to those.
303 // When calculating the parent bounds for purposes of clipping,
304 // we don't need to constrain the parent to its transparent region.
305 // The transparent region is an optimization based on the
306 // buffer contents of the layer, but does not affect the space allocated to
307 // it by policy, and thus children should be allowed to extend into the
308 // parent's transparent region. In fact one of the main uses, is to reduce
309 // buffer allocation size in cases where a child window sits behind a main window
310 // (by marking the hole in the parent window as a transparent region)
311 if (p != nullptr) {
312 Rect bounds = p->computeScreenBounds(false);
313 bounds.intersect(win, &win);
314 }
315
316 if (reduceTransparentRegion) {
317 auto const screenTransparentRegion = t.transform(s.activeTransparentRegion);
318 win = reduce(win, screenTransparentRegion);
319 }
320
321 return win;
322}
323
Mathias Agopian13127d82013-03-05 17:47:11 -0800324Rect Layer::computeBounds() const {
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700325 const Layer::State& s(getDrawingState());
Michael Lentine6c925ed2014-09-26 17:55:01 -0700326 return computeBounds(s.activeTransparentRegion);
327}
328
329Rect Layer::computeBounds(const Region& activeTransparentRegion) const {
330 const Layer::State& s(getDrawingState());
Mathias Agopian13127d82013-03-05 17:47:11 -0800331 Rect win(s.active.w, s.active.h);
Robert Carrb5d3d262016-03-25 15:08:13 -0700332
333 if (!s.crop.isEmpty()) {
334 win.intersect(s.crop, &win);
Mathias Agopian13127d82013-03-05 17:47:11 -0800335 }
Robert Carr1f0a16a2016-10-24 16:27:39 -0700336
337 Rect bounds = win;
Chia-I Wue41dbe62017-06-13 14:10:56 -0700338 const auto& p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700339 if (p != nullptr) {
Robert Carrde9ec442017-02-08 17:43:36 -0800340 // Look in computeScreenBounds recursive call for explanation of
341 // why we pass false here.
342 bounds = p->computeScreenBounds(false /* reduceTransparentRegion */);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700343 }
344
345 Transform t = getTransform();
346 if (p != nullptr) {
347 win = t.transform(win);
348 win.intersect(bounds, &win);
349 win = t.inverse().transform(win);
350 }
351
Mathias Agopian6c7f25a2013-05-09 20:37:10 -0700352 // subtract the transparent region and snap to the bounds
Michael Lentine6c925ed2014-09-26 17:55:01 -0700353 return reduce(win, activeTransparentRegion);
Mathias Agopian13127d82013-03-05 17:47:11 -0800354}
355
Robert Carr1f0a16a2016-10-24 16:27:39 -0700356Rect Layer::computeInitialCrop(const sp<const DisplayDevice>& hw) const {
Robert Carrb5d3d262016-03-25 15:08:13 -0700357 // the crop is the area of the window that gets cropped, but not
Mathias Agopian13127d82013-03-05 17:47:11 -0800358 // scaled in any ways.
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700359 const State& s(getDrawingState());
Mathias Agopian13127d82013-03-05 17:47:11 -0800360
361 // apply the projection's clipping to the window crop in
362 // layerstack space, and convert-back to layer space.
Mathias Agopian6b442672013-07-09 21:24:52 -0700363 // if there are no window scaling involved, this operation will map to full
364 // pixels in the buffer.
365 // FIXME: the 3 lines below can produce slightly incorrect clipping when we have
366 // a viewport clipping and a window transform. we should use floating point to fix this.
Mathias Agopian0e8f1442013-08-20 21:41:07 -0700367
368 Rect activeCrop(s.active.w, s.active.h);
Robert Carrb5d3d262016-03-25 15:08:13 -0700369 if (!s.crop.isEmpty()) {
Chia-I Wudf7867f2017-07-20 14:24:37 -0700370 activeCrop.intersect(s.crop, &activeCrop);
Mathias Agopian0e8f1442013-08-20 21:41:07 -0700371 }
372
Robert Carr1f0a16a2016-10-24 16:27:39 -0700373 Transform t = getTransform();
374 activeCrop = t.transform(activeCrop);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000375 if (!activeCrop.intersect(hw->getViewport(), &activeCrop)) {
376 activeCrop.clear();
377 }
Robert Carrb5d3d262016-03-25 15:08:13 -0700378 if (!s.finalCrop.isEmpty()) {
David Sodman41fdfc92017-11-06 16:09:56 -0800379 if (!activeCrop.intersect(s.finalCrop, &activeCrop)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000380 activeCrop.clear();
381 }
382 }
chaviwb1154d12017-10-31 14:15:36 -0700383
384 const auto& p = mDrawingParent.promote();
385 if (p != nullptr) {
386 auto parentCrop = p->computeInitialCrop(hw);
387 activeCrop.intersect(parentCrop, &activeCrop);
388 }
389
Robert Carr1f0a16a2016-10-24 16:27:39 -0700390 return activeCrop;
391}
392
Dan Stoza5a423ea2017-02-16 14:10:39 -0800393FloatRect Layer::computeCrop(const sp<const DisplayDevice>& hw) const {
Robert Carr1f0a16a2016-10-24 16:27:39 -0700394 // the content crop is the area of the content that gets scaled to the
395 // layer's size. This is in buffer space.
Dan Stoza5a423ea2017-02-16 14:10:39 -0800396 FloatRect crop = getContentCrop().toFloatRect();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700397
398 // In addition there is a WM-specified crop we pull from our drawing state.
399 const State& s(getDrawingState());
400
401 // Screen space to make reduction to parent crop clearer.
402 Rect activeCrop = computeInitialCrop(hw);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700403 Transform t = getTransform();
404 // Back to layer space to work with the content crop.
405 activeCrop = t.inverse().transform(activeCrop);
Mathias Agopian13127d82013-03-05 17:47:11 -0800406
Michael Lentine28ea2172014-11-19 18:32:37 -0800407 // This needs to be here as transform.transform(Rect) computes the
408 // transformed rect and then takes the bounding box of the result before
409 // returning. This means
410 // transform.inverse().transform(transform.transform(Rect)) != Rect
411 // in which case we need to make sure the final rect is clipped to the
412 // display bounds.
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000413 if (!activeCrop.intersect(Rect(s.active.w, s.active.h), &activeCrop)) {
414 activeCrop.clear();
415 }
Mathias Agopian13127d82013-03-05 17:47:11 -0800416
Mathias Agopianf3e85d42013-05-10 18:01:12 -0700417 // subtract the transparent region and snap to the bounds
418 activeCrop = reduce(activeCrop, s.activeTransparentRegion);
419
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000420 // Transform the window crop to match the buffer coordinate system,
421 // which means using the inverse of the current transform set on the
422 // SurfaceFlingerConsumer.
423 uint32_t invTransform = mCurrentTransform;
Robert Carrcae605c2017-03-29 12:10:31 -0700424 if (getTransformToDisplayInverse()) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000425 /*
Pablo Ceballos021623b2016-04-15 17:31:51 -0700426 * the code below applies the primary display's inverse transform to the
427 * buffer
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000428 */
David Sodman41fdfc92017-11-06 16:09:56 -0800429 uint32_t invTransformOrient = DisplayDevice::getPrimaryDisplayOrientationTransform();
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000430 // calculate the inverse transform
431 if (invTransformOrient & NATIVE_WINDOW_TRANSFORM_ROT_90) {
David Sodman41fdfc92017-11-06 16:09:56 -0800432 invTransformOrient ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H;
Mathias Agopian13127d82013-03-05 17:47:11 -0800433 }
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000434 // and apply to the current transform
David Sodman41fdfc92017-11-06 16:09:56 -0800435 invTransform = (Transform(invTransformOrient) * Transform(invTransform)).getOrientation();
Mathias Agopian13127d82013-03-05 17:47:11 -0800436 }
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000437
438 int winWidth = s.active.w;
439 int winHeight = s.active.h;
440 if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
441 // If the activeCrop has been rotate the ends are rotated but not
442 // the space itself so when transforming ends back we can't rely on
443 // a modification of the axes of rotation. To account for this we
444 // need to reorient the inverse rotation in terms of the current
445 // axes of rotation.
446 bool is_h_flipped = (invTransform & NATIVE_WINDOW_TRANSFORM_FLIP_H) != 0;
447 bool is_v_flipped = (invTransform & NATIVE_WINDOW_TRANSFORM_FLIP_V) != 0;
448 if (is_h_flipped == is_v_flipped) {
David Sodman41fdfc92017-11-06 16:09:56 -0800449 invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H;
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000450 }
451 winWidth = s.active.h;
452 winHeight = s.active.w;
453 }
David Sodman41fdfc92017-11-06 16:09:56 -0800454 const Rect winCrop = activeCrop.transform(invTransform, s.active.w, s.active.h);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000455
456 // below, crop is intersected with winCrop expressed in crop's coordinate space
David Sodman41fdfc92017-11-06 16:09:56 -0800457 float xScale = crop.getWidth() / float(winWidth);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000458 float yScale = crop.getHeight() / float(winHeight);
459
David Sodman41fdfc92017-11-06 16:09:56 -0800460 float insetL = winCrop.left * xScale;
461 float insetT = winCrop.top * yScale;
462 float insetR = (winWidth - winCrop.right) * xScale;
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000463 float insetB = (winHeight - winCrop.bottom) * yScale;
464
David Sodman41fdfc92017-11-06 16:09:56 -0800465 crop.left += insetL;
466 crop.top += insetT;
467 crop.right -= insetR;
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000468 crop.bottom -= insetB;
469
Mathias Agopian13127d82013-03-05 17:47:11 -0800470 return crop;
471}
472
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000473#ifdef USE_HWC2
Robert Carrae060832016-11-28 10:51:00 -0800474void Layer::setGeometry(const sp<const DisplayDevice>& displayDevice, uint32_t z)
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000475#else
David Sodman41fdfc92017-11-06 16:09:56 -0800476void Layer::setGeometry(const sp<const DisplayDevice>& hw, HWComposer::HWCLayerInterface& layer)
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000477#endif
Mathias Agopiana350ff92010-08-10 17:14:02 -0700478{
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000479#ifdef USE_HWC2
Dan Stoza9e56aa02015-11-02 13:00:03 -0800480 const auto hwcId = displayDevice->getHwcDisplayId();
481 auto& hwcInfo = mHwcLayers[hwcId];
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000482#else
483 layer.setDefaultState();
484#endif
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700485
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700486 // enable this layer
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000487#ifdef USE_HWC2
Dan Stoza9e56aa02015-11-02 13:00:03 -0800488 hwcInfo.forceClientComposition = false;
489
490 if (isSecure() && !displayDevice->isSecure()) {
491 hwcInfo.forceClientComposition = true;
492 }
493
494 auto& hwcLayer = hwcInfo.layer;
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000495#else
496 layer.setSkip(false);
497
498 if (isSecure() && !hw->isSecure()) {
499 layer.setSkip(true);
500 }
501#endif
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700502
Mathias Agopian13127d82013-03-05 17:47:11 -0800503 // this gives us only the "orientation" component of the transform
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700504 const State& s(getDrawingState());
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000505#ifdef USE_HWC2
David Revemanecf0fa52017-03-03 11:32:44 -0500506 auto blendMode = HWC2::BlendMode::None;
Robert Carr6452f122017-03-21 10:41:29 -0700507 if (!isOpaque(s) || getAlpha() != 1.0f) {
David Sodman41fdfc92017-11-06 16:09:56 -0800508 blendMode =
509 mPremultipliedAlpha ? HWC2::BlendMode::Premultiplied : HWC2::BlendMode::Coverage;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800510 }
David Revemanecf0fa52017-03-03 11:32:44 -0500511 auto error = hwcLayer->setBlendMode(blendMode);
David Sodman41fdfc92017-11-06 16:09:56 -0800512 ALOGE_IF(error != HWC2::Error::None,
513 "[%s] Failed to set blend mode %s:"
514 " %s (%d)",
515 mName.string(), to_string(blendMode).c_str(), to_string(error).c_str(),
516 static_cast<int32_t>(error));
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000517#else
chaviw13fdc492017-06-27 12:40:18 -0700518 if (!isOpaque(s) || getAlpha() != 1.0f) {
David Sodman41fdfc92017-11-06 16:09:56 -0800519 layer.setBlending(mPremultipliedAlpha ? HWC_BLENDING_PREMULT : HWC_BLENDING_COVERAGE);
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000520 }
521#endif
Mathias Agopian13127d82013-03-05 17:47:11 -0800522
523 // apply the layer's transform, followed by the display's global transform
524 // here we're guaranteed that the layer's transform preserves rects
Michael Lentine6c925ed2014-09-26 17:55:01 -0700525 Region activeTransparentRegion(s.activeTransparentRegion);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700526 Transform t = getTransform();
Robert Carrb5d3d262016-03-25 15:08:13 -0700527 if (!s.crop.isEmpty()) {
528 Rect activeCrop(s.crop);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700529 activeCrop = t.transform(activeCrop);
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000530#ifdef USE_HWC2
David Sodman41fdfc92017-11-06 16:09:56 -0800531 if (!activeCrop.intersect(displayDevice->getViewport(), &activeCrop)) {
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000532#else
David Sodman41fdfc92017-11-06 16:09:56 -0800533 if (!activeCrop.intersect(hw->getViewport(), &activeCrop)) {
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000534#endif
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000535 activeCrop.clear();
536 }
Robert Carr1f0a16a2016-10-24 16:27:39 -0700537 activeCrop = t.inverse().transform(activeCrop, true);
Michael Lentine28ea2172014-11-19 18:32:37 -0800538 // This needs to be here as transform.transform(Rect) computes the
539 // transformed rect and then takes the bounding box of the result before
540 // returning. This means
541 // transform.inverse().transform(transform.transform(Rect)) != Rect
542 // in which case we need to make sure the final rect is clipped to the
543 // display bounds.
David Sodman41fdfc92017-11-06 16:09:56 -0800544 if (!activeCrop.intersect(Rect(s.active.w, s.active.h), &activeCrop)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000545 activeCrop.clear();
546 }
Michael Lentine6c925ed2014-09-26 17:55:01 -0700547 // mark regions outside the crop as transparent
548 activeTransparentRegion.orSelf(Rect(0, 0, s.active.w, activeCrop.top));
David Sodman41fdfc92017-11-06 16:09:56 -0800549 activeTransparentRegion.orSelf(Rect(0, activeCrop.bottom, s.active.w, s.active.h));
550 activeTransparentRegion.orSelf(Rect(0, activeCrop.top, activeCrop.left, activeCrop.bottom));
551 activeTransparentRegion.orSelf(
552 Rect(activeCrop.right, activeCrop.top, s.active.w, activeCrop.bottom));
Michael Lentine6c925ed2014-09-26 17:55:01 -0700553 }
Robert Carr1f0a16a2016-10-24 16:27:39 -0700554
555 Rect frame(t.transform(computeBounds(activeTransparentRegion)));
Robert Carrb5d3d262016-03-25 15:08:13 -0700556 if (!s.finalCrop.isEmpty()) {
David Sodman41fdfc92017-11-06 16:09:56 -0800557 if (!frame.intersect(s.finalCrop, &frame)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000558 frame.clear();
559 }
560 }
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000561#ifdef USE_HWC2
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000562 if (!frame.intersect(displayDevice->getViewport(), &frame)) {
563 frame.clear();
564 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800565 const Transform& tr(displayDevice->getTransform());
566 Rect transformedFrame = tr.transform(frame);
David Revemanecf0fa52017-03-03 11:32:44 -0500567 error = hwcLayer->setDisplayFrame(transformedFrame);
Dan Stozae22aec72016-08-01 13:20:59 -0700568 if (error != HWC2::Error::None) {
David Sodman41fdfc92017-11-06 16:09:56 -0800569 ALOGE("[%s] Failed to set display frame [%d, %d, %d, %d]: %s (%d)", mName.string(),
570 transformedFrame.left, transformedFrame.top, transformedFrame.right,
571 transformedFrame.bottom, to_string(error).c_str(), static_cast<int32_t>(error));
Dan Stozae22aec72016-08-01 13:20:59 -0700572 } else {
573 hwcInfo.displayFrame = transformedFrame;
574 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800575
Dan Stoza5a423ea2017-02-16 14:10:39 -0800576 FloatRect sourceCrop = computeCrop(displayDevice);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800577 error = hwcLayer->setSourceCrop(sourceCrop);
Dan Stozae22aec72016-08-01 13:20:59 -0700578 if (error != HWC2::Error::None) {
579 ALOGE("[%s] Failed to set source crop [%.3f, %.3f, %.3f, %.3f]: "
David Sodman41fdfc92017-11-06 16:09:56 -0800580 "%s (%d)",
581 mName.string(), sourceCrop.left, sourceCrop.top, sourceCrop.right, sourceCrop.bottom,
582 to_string(error).c_str(), static_cast<int32_t>(error));
Dan Stozae22aec72016-08-01 13:20:59 -0700583 } else {
584 hwcInfo.sourceCrop = sourceCrop;
585 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800586
chaviw13fdc492017-06-27 12:40:18 -0700587 float alpha = static_cast<float>(getAlpha());
Robert Carr6452f122017-03-21 10:41:29 -0700588 error = hwcLayer->setPlaneAlpha(alpha);
David Sodman41fdfc92017-11-06 16:09:56 -0800589 ALOGE_IF(error != HWC2::Error::None,
590 "[%s] Failed to set plane alpha %.3f: "
591 "%s (%d)",
592 mName.string(), alpha, to_string(error).c_str(), static_cast<int32_t>(error));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800593
Robert Carrae060832016-11-28 10:51:00 -0800594 error = hwcLayer->setZOrder(z);
David Sodman41fdfc92017-11-06 16:09:56 -0800595 ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set Z %u: %s (%d)", mName.string(), z,
596 to_string(error).c_str(), static_cast<int32_t>(error));
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -0500597
Albert Chaulk2a589632017-05-04 16:59:44 -0400598 int type = s.type;
599 int appId = s.appId;
Chia-I Wue41dbe62017-06-13 14:10:56 -0700600 sp<Layer> parent = mDrawingParent.promote();
Albert Chaulk2a589632017-05-04 16:59:44 -0400601 if (parent.get()) {
602 auto& parentState = parent->getDrawingState();
603 type = parentState.type;
604 appId = parentState.appId;
605 }
606
607 error = hwcLayer->setInfo(type, appId);
David Sodman41fdfc92017-11-06 16:09:56 -0800608 ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set info (%d)", mName.string(),
609 static_cast<int32_t>(error));
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000610#else
611 if (!frame.intersect(hw->getViewport(), &frame)) {
612 frame.clear();
613 }
614 const Transform& tr(hw->getTransform());
615 layer.setFrame(tr.transform(frame));
616 layer.setCrop(computeCrop(hw));
David Sodman41fdfc92017-11-06 16:09:56 -0800617 layer.setPlaneAlpha(static_cast<uint8_t>(std::round(255.0f * getAlpha())));
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000618#endif
Mathias Agopian9f8386e2013-01-29 18:56:42 -0800619
Mathias Agopian29a367b2011-07-12 14:51:45 -0700620 /*
621 * Transformations are applied in this order:
622 * 1) buffer orientation/flip/mirror
623 * 2) state transformation (window manager)
624 * 3) layer orientation (screen orientation)
625 * (NOTE: the matrices are multiplied in reverse order)
626 */
627
628 const Transform bufferOrientation(mCurrentTransform);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700629 Transform transform(tr * t * bufferOrientation);
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700630
Robert Carrcae605c2017-03-29 12:10:31 -0700631 if (getTransformToDisplayInverse()) {
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700632 /*
Pablo Ceballos021623b2016-04-15 17:31:51 -0700633 * the code below applies the primary display's inverse transform to the
634 * buffer
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700635 */
David Sodman41fdfc92017-11-06 16:09:56 -0800636 uint32_t invTransform = DisplayDevice::getPrimaryDisplayOrientationTransform();
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700637 // calculate the inverse transform
638 if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
David Sodman41fdfc92017-11-06 16:09:56 -0800639 invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700640 }
Robert Carrcae605c2017-03-29 12:10:31 -0700641
642 /*
643 * Here we cancel out the orientation component of the WM transform.
644 * The scaling and translate components are already included in our bounds
645 * computation so it's enough to just omit it in the composition.
646 * See comment in onDraw with ref to b/36727915 for why.
647 */
648 transform = Transform(invTransform) * tr * bufferOrientation;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700649 }
Mathias Agopian29a367b2011-07-12 14:51:45 -0700650
651 // this gives us only the "orientation" component of the transform
Mathias Agopian13127d82013-03-05 17:47:11 -0800652 const uint32_t orientation = transform.getOrientation();
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000653#ifdef USE_HWC2
Dan Stoza9e56aa02015-11-02 13:00:03 -0800654 if (orientation & Transform::ROT_INVALID) {
655 // we can only handle simple transformation
656 hwcInfo.forceClientComposition = true;
657 } else {
658 auto transform = static_cast<HWC2::Transform>(orientation);
659 auto error = hwcLayer->setTransform(transform);
David Sodman41fdfc92017-11-06 16:09:56 -0800660 ALOGE_IF(error != HWC2::Error::None,
661 "[%s] Failed to set transform %s: "
662 "%s (%d)",
663 mName.string(), to_string(transform).c_str(), to_string(error).c_str(),
664 static_cast<int32_t>(error));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800665 }
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000666#else
667 if (orientation & Transform::ROT_INVALID) {
668 // we can only handle simple transformation
669 layer.setSkip(true);
670 } else {
671 layer.setTransform(orientation);
672 }
673#endif
Mathias Agopiana350ff92010-08-10 17:14:02 -0700674}
675
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000676#ifdef USE_HWC2
Dan Stoza9e56aa02015-11-02 13:00:03 -0800677void Layer::forceClientComposition(int32_t hwcId) {
678 if (mHwcLayers.count(hwcId) == 0) {
679 ALOGE("forceClientComposition: no HWC layer found (%d)", hwcId);
680 return;
681 }
682
683 mHwcLayers[hwcId].forceClientComposition = true;
684}
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000685#else
686void Layer::setPerFrameData(const sp<const DisplayDevice>& hw,
David Sodmaneb085e02017-10-05 18:49:04 -0700687 HWComposer::HWCLayerInterface& layer) {
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000688 // we have to set the visible region on every frame because
689 // we currently free it during onLayerDisplayed(), which is called
690 // after HWComposer::commit() -- every frame.
691 // Apply this display's projection's viewport to the visible region
692 // before giving it to the HWC HAL.
693 const Transform& tr = hw->getTransform();
694 Region visible = tr.transform(visibleRegion.intersect(hw->getViewport()));
695 layer.setVisibleRegionScreen(visible);
696 layer.setSurfaceDamage(surfaceDamageRegion);
697 mIsGlesComposition = (layer.getCompositionType() == HWC_FRAMEBUFFER);
Dan Stozaee44edd2015-03-23 15:50:23 -0700698
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000699 if (mSidebandStream.get()) {
700 layer.setSidebandStream(mSidebandStream);
701 } else {
702 // NOTE: buffer can be NULL if the client never drew into this
703 // layer yet, or if we ran out of memory
704 layer.setBuffer(mActiveBuffer);
705 }
706}
707#endif
708
David Sodmaneb085e02017-10-05 18:49:04 -0700709
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000710#ifdef USE_HWC2
Dan Stoza9e56aa02015-11-02 13:00:03 -0800711void Layer::updateCursorPosition(const sp<const DisplayDevice>& displayDevice) {
712 auto hwcId = displayDevice->getHwcDisplayId();
David Sodman41fdfc92017-11-06 16:09:56 -0800713 if (mHwcLayers.count(hwcId) == 0 || getCompositionType(hwcId) != HWC2::Composition::Cursor) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800714 return;
715 }
716
717 // This gives us only the "orientation" component of the transform
718 const State& s(getCurrentState());
719
720 // Apply the layer's transform, followed by the display's global transform
721 // Here we're guaranteed that the layer's transform preserves rects
722 Rect win(s.active.w, s.active.h);
Robert Carrb5d3d262016-03-25 15:08:13 -0700723 if (!s.crop.isEmpty()) {
724 win.intersect(s.crop, &win);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800725 }
726 // Subtract the transparent region and snap to the bounds
727 Rect bounds = reduce(win, s.activeTransparentRegion);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700728 Rect frame(getTransform().transform(bounds));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800729 frame.intersect(displayDevice->getViewport(), &frame);
Robert Carrb5d3d262016-03-25 15:08:13 -0700730 if (!s.finalCrop.isEmpty()) {
731 frame.intersect(s.finalCrop, &frame);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000732 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800733 auto& displayTransform(displayDevice->getTransform());
734 auto position = displayTransform.transform(frame);
735
David Sodman41fdfc92017-11-06 16:09:56 -0800736 auto error = mHwcLayers[hwcId].layer->setCursorPosition(position.left, position.top);
737 ALOGE_IF(error != HWC2::Error::None,
738 "[%s] Failed to set cursor position "
739 "to (%d, %d): %s (%d)",
740 mName.string(), position.left, position.top, to_string(error).c_str(),
741 static_cast<int32_t>(error));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800742}
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000743#else
David Sodman41fdfc92017-11-06 16:09:56 -0800744Rect Layer::getPosition(const sp<const DisplayDevice>& hw) {
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000745 // this gives us only the "orientation" component of the transform
746 const State& s(getCurrentState());
747
748 // apply the layer's transform, followed by the display's global transform
749 // here we're guaranteed that the layer's transform preserves rects
750 Rect win(s.active.w, s.active.h);
751 if (!s.crop.isEmpty()) {
752 win.intersect(s.crop, &win);
753 }
754 // subtract the transparent region and snap to the bounds
755 Rect bounds = reduce(win, s.activeTransparentRegion);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700756 Rect frame(getTransform().transform(bounds));
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000757 frame.intersect(hw->getViewport(), &frame);
758 if (!s.finalCrop.isEmpty()) {
759 frame.intersect(s.finalCrop, &frame);
760 }
761 const Transform& tr(hw->getTransform());
762 return Rect(tr.transform(frame));
763}
764#endif
Riley Andrews03414a12014-07-01 14:22:59 -0700765
Mathias Agopian13127d82013-03-05 17:47:11 -0800766// ---------------------------------------------------------------------------
767// drawing...
768// ---------------------------------------------------------------------------
769
chaviwa76b2712017-09-20 12:02:26 -0700770void Layer::draw(const RenderArea& renderArea, const Region& clip) const {
771 onDraw(renderArea, clip, false);
Mathias Agopian13127d82013-03-05 17:47:11 -0800772}
773
chaviwa76b2712017-09-20 12:02:26 -0700774void Layer::draw(const RenderArea& renderArea, bool useIdentityTransform) const {
775 onDraw(renderArea, Region(renderArea.getBounds()), useIdentityTransform);
Mathias Agopian13127d82013-03-05 17:47:11 -0800776}
777
chaviwa76b2712017-09-20 12:02:26 -0700778void Layer::draw(const RenderArea& renderArea) const {
779 onDraw(renderArea, Region(renderArea.getBounds()), false);
Dan Stozac7014012014-02-14 15:03:43 -0800780}
781
David Sodman41fdfc92017-11-06 16:09:56 -0800782void Layer::clearWithOpenGL(const RenderArea& renderArea, float red, float green, float blue,
783 float alpha) const {
Mathias Agopian19733a32013-08-28 18:13:56 -0700784 RenderEngine& engine(mFlinger->getRenderEngine());
chaviwa76b2712017-09-20 12:02:26 -0700785 computeGeometry(renderArea, mMesh, false);
Mathias Agopian19733a32013-08-28 18:13:56 -0700786 engine.setupFillWithColor(red, green, blue, alpha);
787 engine.drawMesh(mMesh);
Mathias Agopian13127d82013-03-05 17:47:11 -0800788}
789
chaviwa76b2712017-09-20 12:02:26 -0700790void Layer::clearWithOpenGL(const RenderArea& renderArea) const {
David Sodman41fdfc92017-11-06 16:09:56 -0800791 clearWithOpenGL(renderArea, 0, 0, 0, 0);
Mathias Agopian13127d82013-03-05 17:47:11 -0800792}
793
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000794#ifdef USE_HWC2
David Sodman41fdfc92017-11-06 16:09:56 -0800795void Layer::setCompositionType(int32_t hwcId, HWC2::Composition type, bool callIntoHwc) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800796 if (mHwcLayers.count(hwcId) == 0) {
797 ALOGE("setCompositionType called without a valid HWC layer");
798 return;
799 }
800 auto& hwcInfo = mHwcLayers[hwcId];
801 auto& hwcLayer = hwcInfo.layer;
David Sodman41fdfc92017-11-06 16:09:56 -0800802 ALOGV("setCompositionType(%" PRIx64 ", %s, %d)", hwcLayer->getId(), to_string(type).c_str(),
803 static_cast<int>(callIntoHwc));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800804 if (hwcInfo.compositionType != type) {
805 ALOGV(" actually setting");
806 hwcInfo.compositionType = type;
807 if (callIntoHwc) {
808 auto error = hwcLayer->setCompositionType(type);
David Sodman41fdfc92017-11-06 16:09:56 -0800809 ALOGE_IF(error != HWC2::Error::None,
810 "[%s] Failed to set "
811 "composition type %s: %s (%d)",
812 mName.string(), to_string(type).c_str(), to_string(error).c_str(),
813 static_cast<int32_t>(error));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800814 }
815 }
816}
817
818HWC2::Composition Layer::getCompositionType(int32_t hwcId) const {
Dan Stozaec0f7172016-07-21 11:09:40 -0700819 if (hwcId == DisplayDevice::DISPLAY_ID_INVALID) {
820 // If we're querying the composition type for a display that does not
821 // have a HWC counterpart, then it will always be Client
822 return HWC2::Composition::Client;
823 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800824 if (mHwcLayers.count(hwcId) == 0) {
Dan Stozaec0f7172016-07-21 11:09:40 -0700825 ALOGE("getCompositionType called with an invalid HWC layer");
Dan Stoza9e56aa02015-11-02 13:00:03 -0800826 return HWC2::Composition::Invalid;
827 }
828 return mHwcLayers.at(hwcId).compositionType;
829}
830
831void Layer::setClearClientTarget(int32_t hwcId, bool clear) {
832 if (mHwcLayers.count(hwcId) == 0) {
833 ALOGE("setClearClientTarget called without a valid HWC layer");
834 return;
835 }
836 mHwcLayers[hwcId].clearClientTarget = clear;
837}
838
839bool Layer::getClearClientTarget(int32_t hwcId) const {
840 if (mHwcLayers.count(hwcId) == 0) {
841 ALOGE("getClearClientTarget called without a valid HWC layer");
842 return false;
843 }
844 return mHwcLayers.at(hwcId).clearClientTarget;
845}
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000846#endif
Dan Stoza9e56aa02015-11-02 13:00:03 -0800847
Dan Stozacac35382016-01-27 12:21:06 -0800848bool Layer::addSyncPoint(const std::shared_ptr<SyncPoint>& point) {
849 if (point->getFrameNumber() <= mCurrentFrameNumber) {
850 // Don't bother with a SyncPoint, since we've already latched the
851 // relevant frame
852 return false;
Dan Stoza7dde5992015-05-22 09:51:44 -0700853 }
854
Dan Stozacac35382016-01-27 12:21:06 -0800855 Mutex::Autolock lock(mLocalSyncPointMutex);
856 mLocalSyncPoints.push_back(point);
857 return true;
Dan Stoza7dde5992015-05-22 09:51:44 -0700858}
859
Mathias Agopian13127d82013-03-05 17:47:11 -0800860void Layer::setFiltering(bool filtering) {
861 mFiltering = filtering;
862}
863
864bool Layer::getFiltering() const {
865 return mFiltering;
866}
867
Mathias Agopian13127d82013-03-05 17:47:11 -0800868// ----------------------------------------------------------------------------
869// local state
870// ----------------------------------------------------------------------------
871
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000872static void boundPoint(vec2* point, const Rect& crop) {
873 if (point->x < crop.left) {
874 point->x = crop.left;
875 }
876 if (point->x > crop.right) {
877 point->x = crop.right;
878 }
879 if (point->y < crop.top) {
880 point->y = crop.top;
881 }
882 if (point->y > crop.bottom) {
883 point->y = crop.bottom;
884 }
885}
886
chaviwa76b2712017-09-20 12:02:26 -0700887void Layer::computeGeometry(const RenderArea& renderArea, Mesh& mesh,
888 bool useIdentityTransform) const {
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700889 const Layer::State& s(getDrawingState());
chaviwa76b2712017-09-20 12:02:26 -0700890 const Transform renderAreaTransform(renderArea.getTransform());
891 const uint32_t height = renderArea.getHeight();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700892 Rect win = computeBounds();
Mathias Agopian3f844832013-08-07 21:24:32 -0700893
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000894 vec2 lt = vec2(win.left, win.top);
895 vec2 lb = vec2(win.left, win.bottom);
896 vec2 rb = vec2(win.right, win.bottom);
897 vec2 rt = vec2(win.right, win.top);
898
Robert Carr1f0a16a2016-10-24 16:27:39 -0700899 Transform layerTransform = getTransform();
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000900 if (!useIdentityTransform) {
Robert Carr1f0a16a2016-10-24 16:27:39 -0700901 lt = layerTransform.transform(lt);
902 lb = layerTransform.transform(lb);
903 rb = layerTransform.transform(rb);
904 rt = layerTransform.transform(rt);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000905 }
906
Robert Carrb5d3d262016-03-25 15:08:13 -0700907 if (!s.finalCrop.isEmpty()) {
908 boundPoint(&lt, s.finalCrop);
909 boundPoint(&lb, s.finalCrop);
910 boundPoint(&rb, s.finalCrop);
911 boundPoint(&rt, s.finalCrop);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000912 }
913
Mathias Agopianff2ed702013-09-01 21:36:12 -0700914 Mesh::VertexArray<vec2> position(mesh.getPositionArray<vec2>());
chaviwa76b2712017-09-20 12:02:26 -0700915 position[0] = renderAreaTransform.transform(lt);
916 position[1] = renderAreaTransform.transform(lb);
917 position[2] = renderAreaTransform.transform(rb);
918 position[3] = renderAreaTransform.transform(rt);
David Sodman41fdfc92017-11-06 16:09:56 -0800919 for (size_t i = 0; i < 4; i++) {
chaviwa76b2712017-09-20 12:02:26 -0700920 position[i].y = height - position[i].y;
Mathias Agopian13127d82013-03-05 17:47:11 -0800921 }
922}
Eric Hassoldac45e6b2011-02-10 14:41:26 -0800923
David Sodman41fdfc92017-11-06 16:09:56 -0800924bool Layer::isSecure() const {
Dan Stoza23116082015-06-18 14:58:39 -0700925 const Layer::State& s(mDrawingState);
926 return (s.flags & layer_state_t::eLayerSecure);
927}
928
Mathias Agopian13127d82013-03-05 17:47:11 -0800929void Layer::setVisibleRegion(const Region& visibleRegion) {
930 // always called from main thread
931 this->visibleRegion = visibleRegion;
932}
933
934void Layer::setCoveredRegion(const Region& coveredRegion) {
935 // always called from main thread
936 this->coveredRegion = coveredRegion;
937}
938
David Sodman41fdfc92017-11-06 16:09:56 -0800939void Layer::setVisibleNonTransparentRegion(const Region& setVisibleNonTransparentRegion) {
Mathias Agopian13127d82013-03-05 17:47:11 -0800940 // always called from main thread
941 this->visibleNonTransparentRegion = setVisibleNonTransparentRegion;
942}
943
944// ----------------------------------------------------------------------------
945// transaction
946// ----------------------------------------------------------------------------
947
Dan Stoza7dde5992015-05-22 09:51:44 -0700948void Layer::pushPendingState() {
949 if (!mCurrentState.modified) {
950 return;
951 }
952
Dan Stoza7dde5992015-05-22 09:51:44 -0700953 // If this transaction is waiting on the receipt of a frame, generate a sync
954 // point and send it to the remote layer.
Robert Carr0d480722017-01-10 16:42:54 -0800955 if (mCurrentState.barrierLayer != nullptr) {
956 sp<Layer> barrierLayer = mCurrentState.barrierLayer.promote();
957 if (barrierLayer == nullptr) {
958 ALOGE("[%s] Unable to promote barrier Layer.", mName.string());
Dan Stoza7dde5992015-05-22 09:51:44 -0700959 // If we can't promote the layer we are intended to wait on,
960 // then it is expired or otherwise invalid. Allow this transaction
961 // to be applied as per normal (no synchronization).
Robert Carr0d480722017-01-10 16:42:54 -0800962 mCurrentState.barrierLayer = nullptr;
Pablo Ceballos3bddd5b2015-11-19 14:39:14 -0800963 } else {
David Sodman41fdfc92017-11-06 16:09:56 -0800964 auto syncPoint = std::make_shared<SyncPoint>(mCurrentState.frameNumber);
Robert Carr0d480722017-01-10 16:42:54 -0800965 if (barrierLayer->addSyncPoint(syncPoint)) {
Dan Stozacac35382016-01-27 12:21:06 -0800966 mRemoteSyncPoints.push_back(std::move(syncPoint));
967 } else {
968 // We already missed the frame we're supposed to synchronize
969 // on, so go ahead and apply the state update
Robert Carr0d480722017-01-10 16:42:54 -0800970 mCurrentState.barrierLayer = nullptr;
Dan Stozacac35382016-01-27 12:21:06 -0800971 }
Dan Stoza7dde5992015-05-22 09:51:44 -0700972 }
973
Dan Stoza7dde5992015-05-22 09:51:44 -0700974 // Wake us up to check if the frame has been received
975 setTransactionFlags(eTransactionNeeded);
Dan Stozaf5702ff2016-11-02 16:27:47 -0700976 mFlinger->setTransactionFlags(eTraversalNeeded);
Dan Stoza7dde5992015-05-22 09:51:44 -0700977 }
978 mPendingStates.push_back(mCurrentState);
Dan Stozaf7ba41a2017-05-10 15:11:11 -0700979 ATRACE_INT(mTransactionName.string(), mPendingStates.size());
Dan Stoza7dde5992015-05-22 09:51:44 -0700980}
981
Pablo Ceballos05289c22016-04-14 15:49:55 -0700982void Layer::popPendingState(State* stateToCommit) {
983 auto oldFlags = stateToCommit->flags;
984 *stateToCommit = mPendingStates[0];
David Sodman41fdfc92017-11-06 16:09:56 -0800985 stateToCommit->flags =
986 (oldFlags & ~stateToCommit->mask) | (stateToCommit->flags & stateToCommit->mask);
Dan Stoza7dde5992015-05-22 09:51:44 -0700987
988 mPendingStates.removeAt(0);
Dan Stozaf7ba41a2017-05-10 15:11:11 -0700989 ATRACE_INT(mTransactionName.string(), mPendingStates.size());
Dan Stoza7dde5992015-05-22 09:51:44 -0700990}
991
Pablo Ceballos05289c22016-04-14 15:49:55 -0700992bool Layer::applyPendingStates(State* stateToCommit) {
Dan Stoza7dde5992015-05-22 09:51:44 -0700993 bool stateUpdateAvailable = false;
994 while (!mPendingStates.empty()) {
Robert Carr0d480722017-01-10 16:42:54 -0800995 if (mPendingStates[0].barrierLayer != nullptr) {
Dan Stoza7dde5992015-05-22 09:51:44 -0700996 if (mRemoteSyncPoints.empty()) {
997 // If we don't have a sync point for this, apply it anyway. It
998 // will be visually wrong, but it should keep us from getting
999 // into too much trouble.
1000 ALOGE("[%s] No local sync point found", mName.string());
Pablo Ceballos05289c22016-04-14 15:49:55 -07001001 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -07001002 stateUpdateAvailable = true;
1003 continue;
1004 }
1005
David Sodman41fdfc92017-11-06 16:09:56 -08001006 if (mRemoteSyncPoints.front()->getFrameNumber() != mPendingStates[0].frameNumber) {
1007 ALOGE("[%s] Unexpected sync point frame number found", mName.string());
Dan Stozacac35382016-01-27 12:21:06 -08001008
1009 // Signal our end of the sync point and then dispose of it
1010 mRemoteSyncPoints.front()->setTransactionApplied();
1011 mRemoteSyncPoints.pop_front();
1012 continue;
1013 }
1014
Dan Stoza7dde5992015-05-22 09:51:44 -07001015 if (mRemoteSyncPoints.front()->frameIsAvailable()) {
1016 // Apply the state update
Pablo Ceballos05289c22016-04-14 15:49:55 -07001017 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -07001018 stateUpdateAvailable = true;
1019
1020 // Signal our end of the sync point and then dispose of it
1021 mRemoteSyncPoints.front()->setTransactionApplied();
1022 mRemoteSyncPoints.pop_front();
Dan Stoza792e5292016-02-11 11:43:58 -08001023 } else {
1024 break;
Dan Stoza7dde5992015-05-22 09:51:44 -07001025 }
Dan Stoza7dde5992015-05-22 09:51:44 -07001026 } else {
Pablo Ceballos05289c22016-04-14 15:49:55 -07001027 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -07001028 stateUpdateAvailable = true;
1029 }
1030 }
1031
1032 // If we still have pending updates, wake SurfaceFlinger back up and point
1033 // it at this layer so we can process them
1034 if (!mPendingStates.empty()) {
1035 setTransactionFlags(eTransactionNeeded);
1036 mFlinger->setTransactionFlags(eTraversalNeeded);
1037 }
1038
1039 mCurrentState.modified = false;
1040 return stateUpdateAvailable;
1041}
1042
Mathias Agopian13127d82013-03-05 17:47:11 -08001043uint32_t Layer::doTransaction(uint32_t flags) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -08001044 ATRACE_CALL();
1045
Dan Stoza7dde5992015-05-22 09:51:44 -07001046 pushPendingState();
Pablo Ceballos05289c22016-04-14 15:49:55 -07001047 Layer::State c = getCurrentState();
1048 if (!applyPendingStates(&c)) {
Dan Stoza7dde5992015-05-22 09:51:44 -07001049 return 0;
1050 }
1051
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001052 const Layer::State& s(getDrawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001053
David Sodman41fdfc92017-11-06 16:09:56 -08001054 const bool sizeChanged = (c.requested.w != s.requested.w) || (c.requested.h != s.requested.h);
Mathias Agopiana138f892010-05-21 17:24:35 -07001055
David Sodmaneb085e02017-10-05 18:49:04 -07001056 if (sizeChanged) {
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001057 // the size changed, we need to ask our client to request a new buffer
Steve Block9d453682011-12-20 16:23:08 +00001058 ALOGD_IF(DEBUG_RESIZE,
David Sodman41fdfc92017-11-06 16:09:56 -08001059 "doTransaction: geometry (layer=%p '%s'), tr=%02x, scalingMode=%d\n"
1060 " current={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
1061 " requested={ wh={%4u,%4u} }}\n"
1062 " drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
1063 " requested={ wh={%4u,%4u} }}\n",
1064 this, getName().string(), mCurrentTransform, getEffectiveScalingMode(), c.active.w,
1065 c.active.h, c.crop.left, c.crop.top, c.crop.right, c.crop.bottom,
1066 c.crop.getWidth(), c.crop.getHeight(), c.requested.w, c.requested.h, s.active.w,
1067 s.active.h, s.crop.left, s.crop.top, s.crop.right, s.crop.bottom,
1068 s.crop.getWidth(), s.crop.getHeight(), s.requested.w, s.requested.h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001069
Jamie Gennis2a0d5b62011-09-26 16:54:44 -07001070 // record the new size, form this point on, when the client request
1071 // a buffer, it'll get the new size.
David Sodmaneb085e02017-10-05 18:49:04 -07001072 setDefaultBufferSize(c.requested.w, c.requested.h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001073 }
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001074
Robert Carre392b552017-09-19 12:16:05 -07001075 // Don't let Layer::doTransaction update the drawing state
1076 // if we have a pending resize, unless we are in fixed-size mode.
1077 // the drawing state will be updated only once we receive a buffer
1078 // with the correct size.
1079 //
1080 // In particular, we want to make sure the clip (which is part
1081 // of the geometry state) is latched together with the size but is
1082 // latched immediately when no resizing is involved.
1083 //
1084 // If a sideband stream is attached, however, we want to skip this
1085 // optimization so that transactions aren't missed when a buffer
1086 // never arrives
1087 //
1088 // In the case that we don't have a buffer we ignore other factors
1089 // and avoid entering the resizePending state. At a high level the
1090 // resizePending state is to avoid applying the state of the new buffer
1091 // to the old buffer. However in the state where we don't have an old buffer
1092 // there is no such concern but we may still be being used as a parent layer.
David Sodman41fdfc92017-11-06 16:09:56 -08001093 const bool resizePending = ((c.requested.w != c.active.w) || (c.requested.h != c.active.h)) &&
1094 (mActiveBuffer != nullptr);
Mathias Agopian0cd545f2012-06-07 14:18:55 -07001095 if (!isFixedSize()) {
Dan Stoza9e9b0442015-04-22 14:59:08 -07001096 if (resizePending && mSidebandStream == NULL) {
Mathias Agopian0cd545f2012-06-07 14:18:55 -07001097 flags |= eDontUpdateGeometryState;
1098 }
1099 }
1100
Robert Carr7bf247e2017-05-18 14:02:49 -07001101 // Here we apply various requested geometry states, depending on our
1102 // latching configuration. See Layer.h for a detailed discussion of
1103 // how geometry latching is controlled.
1104 if (!(flags & eDontUpdateGeometryState)) {
Pablo Ceballos7d052572016-06-02 17:46:05 -07001105 Layer::State& editCurrentState(getCurrentState());
Robert Carr7bf247e2017-05-18 14:02:49 -07001106
1107 // If mFreezeGeometryUpdates is true we are in the setGeometryAppliesWithResize
1108 // mode, which causes attributes which normally latch regardless of scaling mode,
1109 // to be delayed. We copy the requested state to the active state making sure
1110 // to respect these rules (again see Layer.h for a detailed discussion).
1111 //
1112 // There is an awkward asymmetry in the handling of the crop states in the position
1113 // states, as can be seen below. Largely this arises from position and transform
1114 // being stored in the same data structure while having different latching rules.
1115 // b/38182305
1116 //
1117 // Careful that "c" and editCurrentState may not begin as equivalent due to
1118 // applyPendingStates in the presence of deferred transactions.
1119 if (mFreezeGeometryUpdates) {
Robert Carr82364e32016-05-15 11:27:47 -07001120 float tx = c.active.transform.tx();
1121 float ty = c.active.transform.ty();
1122 c.active = c.requested;
1123 c.active.transform.set(tx, ty);
1124 editCurrentState.active = c.active;
1125 } else {
1126 editCurrentState.active = editCurrentState.requested;
1127 c.active = c.requested;
1128 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001129 }
1130
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001131 if (s.active != c.active) {
Mathias Agopian13127d82013-03-05 17:47:11 -08001132 // invalidate and recompute the visible regions if needed
1133 flags |= Layer::eVisibleRegion;
1134 }
1135
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001136 if (c.sequence != s.sequence) {
Mathias Agopian13127d82013-03-05 17:47:11 -08001137 // invalidate and recompute the visible regions if needed
1138 flags |= eVisibleRegion;
1139 this->contentDirty = true;
1140
1141 // we may use linear filtering, if the matrix scales us
Robert Carr3dcabfa2016-03-01 18:36:58 -08001142 const uint8_t type = c.active.transform.getType();
David Sodman41fdfc92017-11-06 16:09:56 -08001143 mNeedsFiltering = (!c.active.transform.preserveRects() || (type >= Transform::SCALE));
Mathias Agopian13127d82013-03-05 17:47:11 -08001144 }
1145
Dan Stozac8145172016-04-28 16:29:06 -07001146 // If the layer is hidden, signal and clear out all local sync points so
1147 // that transactions for layers depending on this layer's frames becoming
1148 // visible are not blocked
1149 if (c.flags & layer_state_t::eLayerHidden) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001150 clearSyncPoints();
Dan Stozac8145172016-04-28 16:29:06 -07001151 }
1152
Mathias Agopian13127d82013-03-05 17:47:11 -08001153 // Commit the transaction
Pablo Ceballos05289c22016-04-14 15:49:55 -07001154 commitTransaction(c);
Mathias Agopian13127d82013-03-05 17:47:11 -08001155 return flags;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001156}
1157
Pablo Ceballos05289c22016-04-14 15:49:55 -07001158void Layer::commitTransaction(const State& stateToCommit) {
1159 mDrawingState = stateToCommit;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001160}
1161
Mathias Agopian13127d82013-03-05 17:47:11 -08001162uint32_t Layer::getTransactionFlags(uint32_t flags) {
1163 return android_atomic_and(~flags, &mTransactionFlags) & flags;
1164}
1165
1166uint32_t Layer::setTransactionFlags(uint32_t flags) {
1167 return android_atomic_or(flags, &mTransactionFlags);
1168}
1169
Robert Carr82364e32016-05-15 11:27:47 -07001170bool Layer::setPosition(float x, float y, bool immediate) {
Robert Carr3dcabfa2016-03-01 18:36:58 -08001171 if (mCurrentState.requested.transform.tx() == x && mCurrentState.requested.transform.ty() == y)
Mathias Agopian13127d82013-03-05 17:47:11 -08001172 return false;
1173 mCurrentState.sequence++;
Robert Carr69663fb2016-03-27 19:59:19 -07001174
1175 // We update the requested and active position simultaneously because
1176 // we want to apply the position portion of the transform matrix immediately,
1177 // but still delay scaling when resizing a SCALING_MODE_FREEZE layer.
Robert Carr3dcabfa2016-03-01 18:36:58 -08001178 mCurrentState.requested.transform.set(x, y);
Robert Carr7bf247e2017-05-18 14:02:49 -07001179 if (immediate && !mFreezeGeometryUpdates) {
1180 // Here we directly update the active state
1181 // unlike other setters, because we store it within
1182 // the transform, but use different latching rules.
1183 // b/38182305
Robert Carr82364e32016-05-15 11:27:47 -07001184 mCurrentState.active.transform.set(x, y);
1185 }
Robert Carr7bf247e2017-05-18 14:02:49 -07001186 mFreezeGeometryUpdates = mFreezeGeometryUpdates || !immediate;
Robert Carr69663fb2016-03-27 19:59:19 -07001187
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}
Robert Carr82364e32016-05-15 11:27:47 -07001192
Robert Carr1f0a16a2016-10-24 16:27:39 -07001193bool Layer::setChildLayer(const sp<Layer>& childLayer, int32_t z) {
1194 ssize_t idx = mCurrentChildren.indexOf(childLayer);
1195 if (idx < 0) {
1196 return false;
1197 }
1198 if (childLayer->setLayer(z)) {
1199 mCurrentChildren.removeAt(idx);
1200 mCurrentChildren.add(childLayer);
1201 }
1202 return true;
1203}
1204
Robert Carrae060832016-11-28 10:51:00 -08001205bool Layer::setLayer(int32_t z) {
David Sodman41fdfc92017-11-06 16:09:56 -08001206 if (mCurrentState.z == z) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001207 mCurrentState.sequence++;
1208 mCurrentState.z = z;
Dan Stoza7dde5992015-05-22 09:51:44 -07001209 mCurrentState.modified = true;
Robert Carrdb66e622017-04-10 16:55:57 -07001210
1211 // Discard all relative layering.
1212 if (mCurrentState.zOrderRelativeOf != nullptr) {
1213 sp<Layer> strongRelative = mCurrentState.zOrderRelativeOf.promote();
1214 if (strongRelative != nullptr) {
1215 strongRelative->removeZOrderRelative(this);
1216 }
1217 mCurrentState.zOrderRelativeOf = nullptr;
1218 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001219 setTransactionFlags(eTransactionNeeded);
1220 return true;
1221}
Robert Carr1f0a16a2016-10-24 16:27:39 -07001222
Robert Carrdb66e622017-04-10 16:55:57 -07001223void Layer::removeZOrderRelative(const wp<Layer>& relative) {
1224 mCurrentState.zOrderRelatives.remove(relative);
1225 mCurrentState.sequence++;
1226 mCurrentState.modified = true;
1227 setTransactionFlags(eTransactionNeeded);
1228}
1229
1230void Layer::addZOrderRelative(const wp<Layer>& relative) {
1231 mCurrentState.zOrderRelatives.add(relative);
1232 mCurrentState.modified = true;
1233 mCurrentState.sequence++;
1234 setTransactionFlags(eTransactionNeeded);
1235}
1236
1237bool Layer::setRelativeLayer(const sp<IBinder>& relativeToHandle, int32_t z) {
1238 sp<Handle> handle = static_cast<Handle*>(relativeToHandle.get());
1239 if (handle == nullptr) {
1240 return false;
1241 }
1242 sp<Layer> relative = handle->owner.promote();
1243 if (relative == nullptr) {
1244 return false;
1245 }
1246
1247 mCurrentState.sequence++;
1248 mCurrentState.modified = true;
1249 mCurrentState.z = z;
1250
chaviw9ab4bd12017-11-03 13:11:00 -07001251 auto oldZOrderRelativeOf = mCurrentState.zOrderRelativeOf.promote();
1252 if (oldZOrderRelativeOf != nullptr) {
1253 oldZOrderRelativeOf->removeZOrderRelative(this);
1254 }
Robert Carrdb66e622017-04-10 16:55:57 -07001255 mCurrentState.zOrderRelativeOf = relative;
1256 relative->addZOrderRelative(this);
1257
1258 setTransactionFlags(eTransactionNeeded);
1259
1260 return true;
1261}
1262
Mathias Agopian13127d82013-03-05 17:47:11 -08001263bool Layer::setSize(uint32_t w, uint32_t h) {
David Sodman41fdfc92017-11-06 16:09:56 -08001264 if (mCurrentState.requested.w == w && mCurrentState.requested.h == h) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001265 mCurrentState.requested.w = w;
1266 mCurrentState.requested.h = h;
Dan Stoza7dde5992015-05-22 09:51:44 -07001267 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001268 setTransactionFlags(eTransactionNeeded);
1269 return true;
1270}
Dan Stoza9e56aa02015-11-02 13:00:03 -08001271bool Layer::setAlpha(float alpha) {
David Sodman41fdfc92017-11-06 16:09:56 -08001272 if (mCurrentState.color.a == alpha) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001273 mCurrentState.sequence++;
chaviw13fdc492017-06-27 12:40:18 -07001274 mCurrentState.color.a = alpha;
Dan Stoza7dde5992015-05-22 09:51:44 -07001275 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001276 setTransactionFlags(eTransactionNeeded);
1277 return true;
1278}
chaviw13fdc492017-06-27 12:40:18 -07001279
1280bool Layer::setColor(const half3& color) {
David Sodman41fdfc92017-11-06 16:09:56 -08001281 if (color.r == mCurrentState.color.r && color.g == mCurrentState.color.g &&
1282 color.b == mCurrentState.color.b)
chaviw13fdc492017-06-27 12:40:18 -07001283 return false;
1284
1285 mCurrentState.sequence++;
1286 mCurrentState.color.r = color.r;
1287 mCurrentState.color.g = color.g;
1288 mCurrentState.color.b = color.b;
1289 mCurrentState.modified = true;
1290 setTransactionFlags(eTransactionNeeded);
1291 return true;
1292}
1293
Mathias Agopian13127d82013-03-05 17:47:11 -08001294bool Layer::setMatrix(const layer_state_t::matrix22_t& matrix) {
1295 mCurrentState.sequence++;
David Sodman41fdfc92017-11-06 16:09:56 -08001296 mCurrentState.requested.transform.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
Dan Stoza7dde5992015-05-22 09:51:44 -07001297 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001298 setTransactionFlags(eTransactionNeeded);
1299 return true;
1300}
1301bool Layer::setTransparentRegionHint(const Region& transparent) {
Mathias Agopian2ca79392013-04-02 18:30:32 -07001302 mCurrentState.requestedTransparentRegion = transparent;
Dan Stoza7dde5992015-05-22 09:51:44 -07001303 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001304 setTransactionFlags(eTransactionNeeded);
1305 return true;
1306}
1307bool Layer::setFlags(uint8_t flags, uint8_t mask) {
1308 const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask);
David Sodman41fdfc92017-11-06 16:09:56 -08001309 if (mCurrentState.flags == newFlags) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001310 mCurrentState.sequence++;
1311 mCurrentState.flags = newFlags;
Dan Stoza7dde5992015-05-22 09:51:44 -07001312 mCurrentState.mask = mask;
1313 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001314 setTransactionFlags(eTransactionNeeded);
1315 return true;
1316}
Robert Carr99e27f02016-06-16 15:18:02 -07001317
1318bool Layer::setCrop(const Rect& crop, bool immediate) {
David Sodman41fdfc92017-11-06 16:09:56 -08001319 if (mCurrentState.requestedCrop == crop) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001320 mCurrentState.sequence++;
Robert Carr99e27f02016-06-16 15:18:02 -07001321 mCurrentState.requestedCrop = crop;
Robert Carr7bf247e2017-05-18 14:02:49 -07001322 if (immediate && !mFreezeGeometryUpdates) {
Robert Carr99e27f02016-06-16 15:18:02 -07001323 mCurrentState.crop = crop;
1324 }
Robert Carr7bf247e2017-05-18 14:02:49 -07001325 mFreezeGeometryUpdates = mFreezeGeometryUpdates || !immediate;
1326
Dan Stoza7dde5992015-05-22 09:51:44 -07001327 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001328 setTransactionFlags(eTransactionNeeded);
1329 return true;
1330}
Robert Carr8d5227b2017-03-16 15:41:03 -07001331
1332bool Layer::setFinalCrop(const Rect& crop, bool immediate) {
David Sodman41fdfc92017-11-06 16:09:56 -08001333 if (mCurrentState.requestedFinalCrop == crop) return false;
Pablo Ceballosacbe6782016-03-04 17:54:21 +00001334 mCurrentState.sequence++;
Robert Carr8d5227b2017-03-16 15:41:03 -07001335 mCurrentState.requestedFinalCrop = crop;
Robert Carr7bf247e2017-05-18 14:02:49 -07001336 if (immediate && !mFreezeGeometryUpdates) {
Robert Carr8d5227b2017-03-16 15:41:03 -07001337 mCurrentState.finalCrop = crop;
1338 }
Robert Carr7bf247e2017-05-18 14:02:49 -07001339 mFreezeGeometryUpdates = mFreezeGeometryUpdates || !immediate;
1340
Pablo Ceballosacbe6782016-03-04 17:54:21 +00001341 mCurrentState.modified = true;
1342 setTransactionFlags(eTransactionNeeded);
1343 return true;
1344}
Mathias Agopian13127d82013-03-05 17:47:11 -08001345
Robert Carrc3574f72016-03-24 12:19:32 -07001346bool Layer::setOverrideScalingMode(int32_t scalingMode) {
David Sodman41fdfc92017-11-06 16:09:56 -08001347 if (scalingMode == mOverrideScalingMode) return false;
Robert Carrc3574f72016-03-24 12:19:32 -07001348 mOverrideScalingMode = scalingMode;
Robert Carr82364e32016-05-15 11:27:47 -07001349 setTransactionFlags(eTransactionNeeded);
Robert Carrc3574f72016-03-24 12:19:32 -07001350 return true;
1351}
1352
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -05001353void Layer::setInfo(uint32_t type, uint32_t appId) {
David Sodman41fdfc92017-11-06 16:09:56 -08001354 mCurrentState.appId = appId;
1355 mCurrentState.type = type;
1356 mCurrentState.modified = true;
1357 setTransactionFlags(eTransactionNeeded);
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -05001358}
1359
Mathias Agopian13127d82013-03-05 17:47:11 -08001360bool Layer::setLayerStack(uint32_t layerStack) {
David Sodman41fdfc92017-11-06 16:09:56 -08001361 if (mCurrentState.layerStack == layerStack) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001362 mCurrentState.sequence++;
1363 mCurrentState.layerStack = layerStack;
Dan Stoza7dde5992015-05-22 09:51:44 -07001364 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001365 setTransactionFlags(eTransactionNeeded);
1366 return true;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001367}
1368
Courtney Goeltzenleuchterbb09b432016-11-30 13:51:28 -07001369bool Layer::setDataSpace(android_dataspace dataSpace) {
David Sodman41fdfc92017-11-06 16:09:56 -08001370 if (mCurrentState.dataSpace == dataSpace) return false;
Courtney Goeltzenleuchterbb09b432016-11-30 13:51:28 -07001371 mCurrentState.sequence++;
1372 mCurrentState.dataSpace = dataSpace;
1373 mCurrentState.modified = true;
1374 setTransactionFlags(eTransactionNeeded);
1375 return true;
1376}
1377
Courtney Goeltzenleuchter532b2632017-05-05 16:34:38 -06001378android_dataspace Layer::getDataSpace() const {
1379 return mCurrentState.dataSpace;
1380}
1381
Robert Carr1f0a16a2016-10-24 16:27:39 -07001382uint32_t Layer::getLayerStack() const {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001383 auto p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001384 if (p == nullptr) {
1385 return getDrawingState().layerStack;
1386 }
1387 return p->getLayerStack();
1388}
1389
David Sodman41fdfc92017-11-06 16:09:56 -08001390void Layer::deferTransactionUntil(const sp<Layer>& barrierLayer, uint64_t frameNumber) {
Robert Carr0d480722017-01-10 16:42:54 -08001391 mCurrentState.barrierLayer = barrierLayer;
Dan Stoza7dde5992015-05-22 09:51:44 -07001392 mCurrentState.frameNumber = frameNumber;
1393 // We don't set eTransactionNeeded, because just receiving a deferral
1394 // request without any other state updates shouldn't actually induce a delay
1395 mCurrentState.modified = true;
1396 pushPendingState();
Robert Carr0d480722017-01-10 16:42:54 -08001397 mCurrentState.barrierLayer = nullptr;
Dan Stoza792e5292016-02-11 11:43:58 -08001398 mCurrentState.frameNumber = 0;
Dan Stoza7dde5992015-05-22 09:51:44 -07001399 mCurrentState.modified = false;
Robert Carr0d480722017-01-10 16:42:54 -08001400}
1401
David Sodman41fdfc92017-11-06 16:09:56 -08001402void Layer::deferTransactionUntil(const sp<IBinder>& barrierHandle, uint64_t frameNumber) {
Robert Carr0d480722017-01-10 16:42:54 -08001403 sp<Handle> handle = static_cast<Handle*>(barrierHandle.get());
1404 deferTransactionUntil(handle->owner.promote(), frameNumber);
Dan Stoza7dde5992015-05-22 09:51:44 -07001405}
1406
Dan Stozaee44edd2015-03-23 15:50:23 -07001407
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001408// ----------------------------------------------------------------------------
1409// pageflip handling...
1410// ----------------------------------------------------------------------------
1411
Robert Carr1f0a16a2016-10-24 16:27:39 -07001412bool Layer::isHiddenByPolicy() const {
1413 const Layer::State& s(mDrawingState);
Chia-I Wue41dbe62017-06-13 14:10:56 -07001414 const auto& parent = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001415 if (parent != nullptr && parent->isHiddenByPolicy()) {
1416 return true;
1417 }
1418 return s.flags & layer_state_t::eLayerHidden;
1419}
1420
David Sodman41fdfc92017-11-06 16:09:56 -08001421uint32_t Layer::getEffectiveUsage(uint32_t usage) const {
Mathias Agopiana67932f2011-04-20 14:20:59 -07001422 // TODO: should we do something special if mSecure is set?
1423 if (mProtectedByApp) {
1424 // need a hardware-protected path to external video sink
1425 usage |= GraphicBuffer::USAGE_PROTECTED;
Jamie Gennis54cc83e2010-11-02 11:51:32 -07001426 }
Riley Andrews03414a12014-07-01 14:22:59 -07001427 if (mPotentialCursor) {
1428 usage |= GraphicBuffer::USAGE_CURSOR;
1429 }
Jamie Gennis3599bf22011-08-10 11:48:07 -07001430 usage |= GraphicBuffer::USAGE_HW_COMPOSER;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001431 return usage;
Mathias Agopianb5b7f262010-05-07 15:58:44 -07001432}
1433
Mathias Agopian84300952012-11-21 16:02:13 -08001434void Layer::updateTransformHint(const sp<const DisplayDevice>& hw) const {
Mathias Agopiana4583642011-08-23 18:03:18 -07001435 uint32_t orientation = 0;
1436 if (!mFlinger->mDebugDisableTransformHint) {
Mathias Agopian84300952012-11-21 16:02:13 -08001437 // The transform hint is used to improve performance, but we can
1438 // only have a single transform hint, it cannot
Mathias Agopian4fec8732012-06-29 14:12:52 -07001439 // apply to all displays.
Mathias Agopian42977342012-08-05 00:40:46 -07001440 const Transform& planeTransform(hw->getTransform());
Mathias Agopian4fec8732012-06-29 14:12:52 -07001441 orientation = planeTransform.getOrientation();
Mathias Agopiana4583642011-08-23 18:03:18 -07001442 if (orientation & Transform::ROT_INVALID) {
1443 orientation = 0;
1444 }
1445 }
David Sodmaneb085e02017-10-05 18:49:04 -07001446 setTransformHint(orientation);
Mathias Agopiana4583642011-08-23 18:03:18 -07001447}
1448
Mathias Agopian13127d82013-03-05 17:47:11 -08001449// ----------------------------------------------------------------------------
1450// debugging
1451// ----------------------------------------------------------------------------
1452
Kalle Raitaa099a242017-01-11 11:17:29 -08001453LayerDebugInfo Layer::getLayerDebugInfo() const {
1454 LayerDebugInfo info;
1455 const Layer::State& ds = getDrawingState();
1456 info.mName = getName();
chaviw1acbec72017-07-27 15:28:26 -07001457 sp<Layer> parent = getParent();
Kalle Raitaa099a242017-01-11 11:17:29 -08001458 info.mParentName = (parent == nullptr ? std::string("none") : parent->getName().string());
1459 info.mType = String8(getTypeId());
1460 info.mTransparentRegion = ds.activeTransparentRegion;
1461 info.mVisibleRegion = visibleRegion;
1462 info.mSurfaceDamageRegion = surfaceDamageRegion;
1463 info.mLayerStack = getLayerStack();
1464 info.mX = ds.active.transform.tx();
1465 info.mY = ds.active.transform.ty();
1466 info.mZ = ds.z;
1467 info.mWidth = ds.active.w;
1468 info.mHeight = ds.active.h;
1469 info.mCrop = ds.crop;
1470 info.mFinalCrop = ds.finalCrop;
chaviw13fdc492017-06-27 12:40:18 -07001471 info.mColor = ds.color;
Kalle Raitaa099a242017-01-11 11:17:29 -08001472 info.mFlags = ds.flags;
1473 info.mPixelFormat = getPixelFormat();
1474 info.mDataSpace = getDataSpace();
1475 info.mMatrix[0][0] = ds.active.transform[0][0];
1476 info.mMatrix[0][1] = ds.active.transform[0][1];
1477 info.mMatrix[1][0] = ds.active.transform[1][0];
1478 info.mMatrix[1][1] = ds.active.transform[1][1];
1479 {
1480 sp<const GraphicBuffer> activeBuffer = getActiveBuffer();
1481 if (activeBuffer != 0) {
1482 info.mActiveBufferWidth = activeBuffer->getWidth();
1483 info.mActiveBufferHeight = activeBuffer->getHeight();
1484 info.mActiveBufferStride = activeBuffer->getStride();
1485 info.mActiveBufferFormat = activeBuffer->format;
1486 } else {
1487 info.mActiveBufferWidth = 0;
1488 info.mActiveBufferHeight = 0;
1489 info.mActiveBufferStride = 0;
1490 info.mActiveBufferFormat = 0;
1491 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001492 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001493 info.mNumQueuedFrames = getQueuedFrameCount();
1494 info.mRefreshPending = isBufferLatched();
1495 info.mIsOpaque = isOpaque(ds);
1496 info.mContentDirty = contentDirty;
1497 return info;
Mathias Agopian13127d82013-03-05 17:47:11 -08001498}
Fabien Sanglard9d96de42016-10-11 00:15:18 +00001499#ifdef USE_HWC2
Dan Stozae22aec72016-08-01 13:20:59 -07001500void Layer::miniDumpHeader(String8& result) {
1501 result.append("----------------------------------------");
1502 result.append("---------------------------------------\n");
1503 result.append(" Layer name\n");
1504 result.append(" Z | ");
1505 result.append(" Comp Type | ");
1506 result.append(" Disp Frame (LTRB) | ");
1507 result.append(" Source Crop (LTRB)\n");
1508 result.append("----------------------------------------");
1509 result.append("---------------------------------------\n");
1510}
1511
1512void Layer::miniDump(String8& result, int32_t hwcId) const {
1513 if (mHwcLayers.count(hwcId) == 0) {
1514 return;
1515 }
1516
1517 String8 name;
1518 if (mName.length() > 77) {
1519 std::string shortened;
1520 shortened.append(mName.string(), 36);
1521 shortened.append("[...]");
1522 shortened.append(mName.string() + (mName.length() - 36), 36);
1523 name = shortened.c_str();
1524 } else {
1525 name = mName;
1526 }
1527
1528 result.appendFormat(" %s\n", name.string());
1529
1530 const Layer::State& layerState(getDrawingState());
1531 const HWCInfo& hwcInfo = mHwcLayers.at(hwcId);
John Reck8c3b6ac2017-08-24 10:25:42 -07001532 result.appendFormat(" %10d | ", layerState.z);
David Sodman41fdfc92017-11-06 16:09:56 -08001533 result.appendFormat("%10s | ", to_string(getCompositionType(hwcId)).c_str());
Dan Stozae22aec72016-08-01 13:20:59 -07001534 const Rect& frame = hwcInfo.displayFrame;
David Sodman41fdfc92017-11-06 16:09:56 -08001535 result.appendFormat("%4d %4d %4d %4d | ", frame.left, frame.top, frame.right, frame.bottom);
Dan Stoza5a423ea2017-02-16 14:10:39 -08001536 const FloatRect& crop = hwcInfo.sourceCrop;
David Sodman41fdfc92017-11-06 16:09:56 -08001537 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 -07001538
1539 result.append("- - - - - - - - - - - - - - - - - - - - ");
1540 result.append("- - - - - - - - - - - - - - - - - - - -\n");
1541}
Fabien Sanglard9d96de42016-10-11 00:15:18 +00001542#endif
Dan Stozae22aec72016-08-01 13:20:59 -07001543
Svetoslavd85084b2014-03-20 10:28:31 -07001544void Layer::dumpFrameStats(String8& result) const {
1545 mFrameTracker.dumpStats(result);
Mathias Agopian13127d82013-03-05 17:47:11 -08001546}
1547
Svetoslavd85084b2014-03-20 10:28:31 -07001548void Layer::clearFrameStats() {
1549 mFrameTracker.clearStats();
Mathias Agopian13127d82013-03-05 17:47:11 -08001550}
1551
Jamie Gennis6547ff42013-07-16 20:12:42 -07001552void Layer::logFrameStats() {
1553 mFrameTracker.logAndResetStats(mName);
1554}
1555
Svetoslavd85084b2014-03-20 10:28:31 -07001556void Layer::getFrameStats(FrameStats* outStats) const {
1557 mFrameTracker.getStats(outStats);
1558}
1559
Brian Andersond6927fb2016-07-23 23:37:30 -07001560void Layer::dumpFrameEvents(String8& result) {
David Sodman41fdfc92017-11-06 16:09:56 -08001561 result.appendFormat("- Layer %s (%s, %p)\n", getName().string(), getTypeId(), this);
Brian Andersond6927fb2016-07-23 23:37:30 -07001562 Mutex::Autolock lock(mFrameEventHistoryMutex);
1563 mFrameEventHistory.checkFencesForCompletion();
1564 mFrameEventHistory.dump(result);
1565}
Pablo Ceballos40845df2016-01-25 17:41:15 -08001566
Brian Anderson5ea5e592016-12-01 16:54:33 -08001567void Layer::onDisconnect() {
1568 Mutex::Autolock lock(mFrameEventHistoryMutex);
1569 mFrameEventHistory.onDisconnect();
1570}
1571
Brian Anderson3890c392016-07-25 12:48:08 -07001572void Layer::addAndGetFrameTimestamps(const NewFrameEventsEntry* newTimestamps,
David Sodman41fdfc92017-11-06 16:09:56 -08001573 FrameEventHistoryDelta* outDelta) {
Brian Andersond6927fb2016-07-23 23:37:30 -07001574 Mutex::Autolock lock(mFrameEventHistoryMutex);
1575 if (newTimestamps) {
Brian Andersonfbc80ae2017-05-26 16:23:54 -07001576 // If there are any unsignaled fences in the aquire timeline at this
1577 // point, the previously queued frame hasn't been latched yet. Go ahead
1578 // and try to get the signal time here so the syscall is taken out of
1579 // the main thread's critical path.
1580 mAcquireTimeline.updateSignalTimes();
1581 // Push the new fence after updating since it's likely still pending.
Brian Anderson3d4039d2016-09-23 16:31:30 -07001582 mAcquireTimeline.push(newTimestamps->acquireFence);
Brian Andersond6927fb2016-07-23 23:37:30 -07001583 mFrameEventHistory.addQueue(*newTimestamps);
1584 }
1585
Brian Anderson3890c392016-07-25 12:48:08 -07001586 if (outDelta) {
1587 mFrameEventHistory.getAndResetDelta(outDelta);
Brian Andersond6927fb2016-07-23 23:37:30 -07001588 }
Pablo Ceballos40845df2016-01-25 17:41:15 -08001589}
Dan Stozae77c7662016-05-13 11:37:28 -07001590
Chia-I Wu98f1c102017-05-30 14:54:08 -07001591size_t Layer::getChildrenCount() const {
1592 size_t count = 0;
1593 for (const sp<Layer>& child : mCurrentChildren) {
1594 count += 1 + child->getChildrenCount();
1595 }
1596 return count;
1597}
1598
Robert Carr1f0a16a2016-10-24 16:27:39 -07001599void Layer::addChild(const sp<Layer>& layer) {
1600 mCurrentChildren.add(layer);
1601 layer->setParent(this);
1602}
1603
1604ssize_t Layer::removeChild(const sp<Layer>& layer) {
1605 layer->setParent(nullptr);
1606 return mCurrentChildren.remove(layer);
1607}
1608
Robert Carr1db73f62016-12-21 12:58:51 -08001609bool Layer::reparentChildren(const sp<IBinder>& newParentHandle) {
1610 sp<Handle> handle = nullptr;
1611 sp<Layer> newParent = nullptr;
1612 if (newParentHandle == nullptr) {
1613 return false;
1614 }
1615 handle = static_cast<Handle*>(newParentHandle.get());
1616 newParent = handle->owner.promote();
1617 if (newParent == nullptr) {
1618 ALOGE("Unable to promote Layer handle");
1619 return false;
1620 }
1621
1622 for (const sp<Layer>& child : mCurrentChildren) {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001623 newParent->addChild(child);
Robert Carr1db73f62016-12-21 12:58:51 -08001624
1625 sp<Client> client(child->mClientRef.promote());
1626 if (client != nullptr) {
1627 client->setParentLayer(newParent);
1628 }
1629 }
1630 mCurrentChildren.clear();
1631
1632 return true;
1633}
1634
chaviwf1961f72017-09-18 16:41:07 -07001635bool Layer::reparent(const sp<IBinder>& newParentHandle) {
1636 if (newParentHandle == nullptr) {
chaviw06178942017-07-27 10:25:59 -07001637 return false;
1638 }
1639
1640 auto handle = static_cast<Handle*>(newParentHandle.get());
1641 sp<Layer> newParent = handle->owner.promote();
1642 if (newParent == nullptr) {
1643 ALOGE("Unable to promote Layer handle");
1644 return false;
1645 }
1646
chaviwf1961f72017-09-18 16:41:07 -07001647 sp<Layer> parent = getParent();
1648 if (parent != nullptr) {
1649 parent->removeChild(this);
chaviw06178942017-07-27 10:25:59 -07001650 }
chaviwf1961f72017-09-18 16:41:07 -07001651 newParent->addChild(this);
chaviw06178942017-07-27 10:25:59 -07001652
chaviwf1961f72017-09-18 16:41:07 -07001653 sp<Client> client(mClientRef.promote());
chaviw06178942017-07-27 10:25:59 -07001654 sp<Client> newParentClient(newParent->mClientRef.promote());
1655
chaviwf1961f72017-09-18 16:41:07 -07001656 if (client != newParentClient) {
1657 client->setParentLayer(newParent);
chaviw06178942017-07-27 10:25:59 -07001658 }
1659
chaviw06178942017-07-27 10:25:59 -07001660 return true;
1661}
1662
Robert Carr9524cb32017-02-13 11:32:32 -08001663bool Layer::detachChildren() {
Dan Stoza412903f2017-04-27 13:42:17 -07001664 traverseInZOrder(LayerVector::StateSet::Drawing, [this](Layer* child) {
Robert Carr9524cb32017-02-13 11:32:32 -08001665 if (child == this) {
1666 return;
1667 }
1668
chaviw161410b02017-07-27 10:46:08 -07001669 sp<Client> parentClient = mClientRef.promote();
Robert Carr9524cb32017-02-13 11:32:32 -08001670 sp<Client> client(child->mClientRef.promote());
chaviw161410b02017-07-27 10:46:08 -07001671 if (client != nullptr && parentClient != client) {
Robert Carr9524cb32017-02-13 11:32:32 -08001672 client->detachLayer(child);
1673 }
1674 });
1675
1676 return true;
1677}
1678
Robert Carr1f0a16a2016-10-24 16:27:39 -07001679void Layer::setParent(const sp<Layer>& layer) {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001680 mCurrentParent = layer;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001681}
1682
1683void Layer::clearSyncPoints() {
1684 for (const auto& child : mCurrentChildren) {
1685 child->clearSyncPoints();
1686 }
1687
1688 Mutex::Autolock lock(mLocalSyncPointMutex);
1689 for (auto& point : mLocalSyncPoints) {
1690 point->setFrameAvailable();
1691 }
1692 mLocalSyncPoints.clear();
1693}
1694
1695int32_t Layer::getZ() const {
1696 return mDrawingState.z;
1697}
1698
David Sodman41fdfc92017-11-06 16:09:56 -08001699__attribute__((no_sanitize("unsigned-integer-overflow"))) LayerVector Layer::makeTraversalList(
1700 LayerVector::StateSet stateSet) {
Dan Stoza412903f2017-04-27 13:42:17 -07001701 LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid,
1702 "makeTraversalList received invalid stateSet");
1703 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1704 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
1705 const State& state = useDrawing ? mDrawingState : mCurrentState;
1706
1707 if (state.zOrderRelatives.size() == 0) {
1708 return children;
Robert Carrdb66e622017-04-10 16:55:57 -07001709 }
1710 LayerVector traverse;
1711
Dan Stoza412903f2017-04-27 13:42:17 -07001712 for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
Robert Carrdb66e622017-04-10 16:55:57 -07001713 sp<Layer> strongRelative = weakRelative.promote();
1714 if (strongRelative != nullptr) {
1715 traverse.add(strongRelative);
Robert Carrdb66e622017-04-10 16:55:57 -07001716 }
1717 }
1718
Dan Stoza412903f2017-04-27 13:42:17 -07001719 for (const sp<Layer>& child : children) {
Robert Carrdb66e622017-04-10 16:55:57 -07001720 traverse.add(child);
1721 }
1722
1723 return traverse;
1724}
1725
Robert Carr1f0a16a2016-10-24 16:27:39 -07001726/**
Robert Carrdb66e622017-04-10 16:55:57 -07001727 * Negatively signed relatives are before 'this' in Z-order.
Robert Carr1f0a16a2016-10-24 16:27:39 -07001728 */
Dan Stoza412903f2017-04-27 13:42:17 -07001729void Layer::traverseInZOrder(LayerVector::StateSet stateSet, const LayerVector::Visitor& visitor) {
1730 LayerVector list = makeTraversalList(stateSet);
Robert Carrdb66e622017-04-10 16:55:57 -07001731
Robert Carr1f0a16a2016-10-24 16:27:39 -07001732 size_t i = 0;
Robert Carrdb66e622017-04-10 16:55:57 -07001733 for (; i < list.size(); i++) {
1734 const auto& relative = list[i];
1735 if (relative->getZ() >= 0) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001736 break;
Robert Carrdb66e622017-04-10 16:55:57 -07001737 }
Dan Stoza412903f2017-04-27 13:42:17 -07001738 relative->traverseInZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001739 }
Dan Stoza412903f2017-04-27 13:42:17 -07001740 visitor(this);
Robert Carrdb66e622017-04-10 16:55:57 -07001741 for (; i < list.size(); i++) {
1742 const auto& relative = list[i];
Dan Stoza412903f2017-04-27 13:42:17 -07001743 relative->traverseInZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001744 }
1745}
1746
1747/**
Robert Carrdb66e622017-04-10 16:55:57 -07001748 * Positively signed relatives are before 'this' in reverse Z-order.
Robert Carr1f0a16a2016-10-24 16:27:39 -07001749 */
Dan Stoza412903f2017-04-27 13:42:17 -07001750void Layer::traverseInReverseZOrder(LayerVector::StateSet stateSet,
1751 const LayerVector::Visitor& visitor) {
1752 LayerVector list = makeTraversalList(stateSet);
Robert Carrdb66e622017-04-10 16:55:57 -07001753
Robert Carr1f0a16a2016-10-24 16:27:39 -07001754 int32_t i = 0;
Joel Galensonbf324992017-11-06 11:04:12 -08001755 for (i = int32_t(list.size()) - 1; i >= 0; i--) {
Robert Carrdb66e622017-04-10 16:55:57 -07001756 const auto& relative = list[i];
1757 if (relative->getZ() < 0) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001758 break;
1759 }
Dan Stoza412903f2017-04-27 13:42:17 -07001760 relative->traverseInReverseZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001761 }
Dan Stoza412903f2017-04-27 13:42:17 -07001762 visitor(this);
David Sodman41fdfc92017-11-06 16:09:56 -08001763 for (; i >= 0; i--) {
Robert Carrdb66e622017-04-10 16:55:57 -07001764 const auto& relative = list[i];
Dan Stoza412903f2017-04-27 13:42:17 -07001765 relative->traverseInReverseZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001766 }
1767}
1768
chaviwa76b2712017-09-20 12:02:26 -07001769/**
1770 * Traverse only children in z order, ignoring relative layers.
1771 */
1772void Layer::traverseChildrenInZOrder(LayerVector::StateSet stateSet,
1773 const LayerVector::Visitor& visitor) {
1774 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1775 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
1776
1777 size_t i = 0;
1778 for (; i < children.size(); i++) {
1779 const auto& relative = children[i];
1780 if (relative->getZ() >= 0) {
1781 break;
1782 }
1783 relative->traverseChildrenInZOrder(stateSet, visitor);
1784 }
1785 visitor(this);
1786 for (; i < children.size(); i++) {
1787 const auto& relative = children[i];
1788 relative->traverseChildrenInZOrder(stateSet, visitor);
1789 }
1790}
1791
Robert Carr1f0a16a2016-10-24 16:27:39 -07001792Transform Layer::getTransform() const {
1793 Transform t;
Chia-I Wue41dbe62017-06-13 14:10:56 -07001794 const auto& p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001795 if (p != nullptr) {
1796 t = p->getTransform();
Robert Carr9b429f42017-04-17 14:56:57 -07001797
1798 // If the parent is not using NATIVE_WINDOW_SCALING_MODE_FREEZE (e.g.
1799 // it isFixedSize) then there may be additional scaling not accounted
1800 // for in the transform. We need to mirror this scaling in child surfaces
1801 // or we will break the contract where WM can treat child surfaces as
1802 // pixels in the parent surface.
Chia-I Wu0a68b462017-07-18 11:30:05 -07001803 if (p->isFixedSize() && p->mActiveBuffer != nullptr) {
Robert Carr1725eee2017-04-26 18:32:15 -07001804 int bufferWidth;
1805 int bufferHeight;
1806 if ((p->mCurrentTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) == 0) {
1807 bufferWidth = p->mActiveBuffer->getWidth();
1808 bufferHeight = p->mActiveBuffer->getHeight();
1809 } else {
1810 bufferHeight = p->mActiveBuffer->getWidth();
1811 bufferWidth = p->mActiveBuffer->getHeight();
1812 }
David Sodman41fdfc92017-11-06 16:09:56 -08001813 float sx = p->getDrawingState().active.w / static_cast<float>(bufferWidth);
1814 float sy = p->getDrawingState().active.h / static_cast<float>(bufferHeight);
Robert Carr9b429f42017-04-17 14:56:57 -07001815 Transform extraParentScaling;
1816 extraParentScaling.set(sx, 0, 0, sy);
1817 t = t * extraParentScaling;
1818 }
Robert Carr1f0a16a2016-10-24 16:27:39 -07001819 }
1820 return t * getDrawingState().active.transform;
1821}
1822
chaviw13fdc492017-06-27 12:40:18 -07001823half Layer::getAlpha() const {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001824 const auto& p = mDrawingParent.promote();
Robert Carr6452f122017-03-21 10:41:29 -07001825
chaviw13fdc492017-06-27 12:40:18 -07001826 half parentAlpha = (p != nullptr) ? p->getAlpha() : 1.0_hf;
1827 return parentAlpha * getDrawingState().color.a;
Robert Carr6452f122017-03-21 10:41:29 -07001828}
Robert Carr6452f122017-03-21 10:41:29 -07001829
chaviw13fdc492017-06-27 12:40:18 -07001830half4 Layer::getColor() const {
1831 const half4 color(getDrawingState().color);
1832 return half4(color.r, color.g, color.b, getAlpha());
Robert Carr6452f122017-03-21 10:41:29 -07001833}
Robert Carr6452f122017-03-21 10:41:29 -07001834
Robert Carr1f0a16a2016-10-24 16:27:39 -07001835void Layer::commitChildList() {
1836 for (size_t i = 0; i < mCurrentChildren.size(); i++) {
1837 const auto& child = mCurrentChildren[i];
1838 child->commitChildList();
1839 }
1840 mDrawingChildren = mCurrentChildren;
Chia-I Wue41dbe62017-06-13 14:10:56 -07001841 mDrawingParent = mCurrentParent;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001842}
1843
chaviw1d044282017-09-27 12:19:28 -07001844void Layer::writeToProto(LayerProto* layerInfo, LayerVector::StateSet stateSet) {
1845 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1846 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
1847 const State& state = useDrawing ? mDrawingState : mCurrentState;
1848
1849 Transform requestedTransform = state.active.transform;
1850 Transform transform = getTransform();
1851
1852 layerInfo->set_id(sequence);
1853 layerInfo->set_name(getName().c_str());
1854 layerInfo->set_type(String8(getTypeId()));
1855
1856 for (const auto& child : children) {
1857 layerInfo->add_children(child->sequence);
1858 }
1859
1860 for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
1861 sp<Layer> strongRelative = weakRelative.promote();
1862 if (strongRelative != nullptr) {
1863 layerInfo->add_relatives(strongRelative->sequence);
1864 }
1865 }
1866
1867 LayerProtoHelper::writeToProto(state.activeTransparentRegion,
1868 layerInfo->mutable_transparent_region());
1869 LayerProtoHelper::writeToProto(visibleRegion, layerInfo->mutable_visible_region());
1870 LayerProtoHelper::writeToProto(surfaceDamageRegion, layerInfo->mutable_damage_region());
1871
1872 layerInfo->set_layer_stack(getLayerStack());
1873 layerInfo->set_z(state.z);
1874
1875 PositionProto* position = layerInfo->mutable_position();
1876 position->set_x(transform.tx());
1877 position->set_y(transform.ty());
1878
1879 PositionProto* requestedPosition = layerInfo->mutable_requested_position();
1880 requestedPosition->set_x(requestedTransform.tx());
1881 requestedPosition->set_y(requestedTransform.ty());
1882
1883 SizeProto* size = layerInfo->mutable_size();
1884 size->set_w(state.active.w);
1885 size->set_h(state.active.h);
1886
1887 LayerProtoHelper::writeToProto(state.crop, layerInfo->mutable_crop());
1888 LayerProtoHelper::writeToProto(state.finalCrop, layerInfo->mutable_final_crop());
1889
1890 layerInfo->set_is_opaque(isOpaque(state));
1891 layerInfo->set_invalidate(contentDirty);
1892 layerInfo->set_dataspace(dataspaceDetails(getDataSpace()));
1893 layerInfo->set_pixel_format(decodePixelFormat(getPixelFormat()));
1894 LayerProtoHelper::writeToProto(getColor(), layerInfo->mutable_color());
1895 LayerProtoHelper::writeToProto(state.color, layerInfo->mutable_requested_color());
1896 layerInfo->set_flags(state.flags);
1897
1898 LayerProtoHelper::writeToProto(transform, layerInfo->mutable_transform());
1899 LayerProtoHelper::writeToProto(requestedTransform, layerInfo->mutable_requested_transform());
1900
1901 auto parent = getParent();
1902 if (parent != nullptr) {
1903 layerInfo->set_parent(parent->sequence);
1904 }
1905
1906 auto zOrderRelativeOf = state.zOrderRelativeOf.promote();
1907 if (zOrderRelativeOf != nullptr) {
1908 layerInfo->set_z_order_relative_of(zOrderRelativeOf->sequence);
1909 }
1910
1911 auto activeBuffer = getActiveBuffer();
1912 if (activeBuffer != nullptr) {
1913 LayerProtoHelper::writeToProto(activeBuffer, layerInfo->mutable_active_buffer());
1914 }
1915
1916 layerInfo->set_queued_frames(getQueuedFrameCount());
1917 layerInfo->set_refresh_pending(isBufferLatched());
1918}
1919
Mathias Agopian13127d82013-03-05 17:47:11 -08001920// ---------------------------------------------------------------------------
1921
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001922}; // namespace android
Mathias Agopian3f844832013-08-07 21:24:32 -07001923
1924#if defined(__gl_h_)
1925#error "don't include gl/gl.h in this file"
1926#endif
1927
1928#if defined(__gl2_h_)
1929#error "don't include gl2/gl2.h in this file"
1930#endif