blob: c1f1ef7644ccedaaafbd9d9990fac1cd25ea7667 [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
Robert Carr5edb1ad2017-04-25 10:54:24 -0700170 if (mCurrentState.zOrderRelativeOf != nullptr) {
171 sp<Layer> strongRelative = mCurrentState.zOrderRelativeOf.promote();
172 if (strongRelative != nullptr) {
173 strongRelative->removeZOrderRelative(this);
Chia-I Wuc6657022017-08-15 11:18:17 -0700174 mFlinger->setTransactionFlags(eTraversalNeeded);
Robert Carr5edb1ad2017-04-25 10:54:24 -0700175 }
176 mCurrentState.zOrderRelativeOf = nullptr;
177 }
178
Chia-I Wuc6657022017-08-15 11:18:17 -0700179 for (const auto& child : mCurrentChildren) {
180 child->onRemovedFromCurrentState();
181 }
182}
Chia-I Wu38512252017-05-17 14:36:16 -0700183
Chia-I Wuc6657022017-08-15 11:18:17 -0700184void Layer::onRemoved() {
185 // the layer is removed from SF mLayersPendingRemoval
David Sodmaneb085e02017-10-05 18:49:04 -0700186 abandon();
Chia-I Wuc6657022017-08-15 11:18:17 -0700187
Chia-I Wu38512252017-05-17 14:36:16 -0700188#ifdef USE_HWC2
Steven Thomasb02664d2017-07-26 18:48:28 -0700189 destroyAllHwcLayers();
Chia-I Wu38512252017-05-17 14:36:16 -0700190#endif
191
Robert Carr1f0a16a2016-10-24 16:27:39 -0700192 for (const auto& child : mCurrentChildren) {
193 child->onRemoved();
194 }
Mathias Agopian48d819a2009-09-10 19:41:18 -0700195}
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700196
Mathias Agopian13127d82013-03-05 17:47:11 -0800197// ---------------------------------------------------------------------------
198// set-up
199// ---------------------------------------------------------------------------
200
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700201const String8& Layer::getName() const {
Mathias Agopian13127d82013-03-05 17:47:11 -0800202 return mName;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800203}
204
chaviw13fdc492017-06-27 12:40:18 -0700205bool Layer::getPremultipledAlpha() const {
206 return mPremultipliedAlpha;
207}
208
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700209sp<IBinder> Layer::getHandle() {
Mathias Agopian13127d82013-03-05 17:47:11 -0800210 Mutex::Autolock _l(mLock);
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700211 return new Handle(mFlinger, this);
Mathias Agopian13127d82013-03-05 17:47:11 -0800212}
213
214// ---------------------------------------------------------------------------
215// h/w composer set-up
216// ---------------------------------------------------------------------------
217
Steven Thomasb02664d2017-07-26 18:48:28 -0700218#ifdef USE_HWC2
219bool Layer::createHwcLayer(HWComposer* hwc, int32_t hwcId) {
David Sodman41fdfc92017-11-06 16:09:56 -0800220 LOG_ALWAYS_FATAL_IF(mHwcLayers.count(hwcId) != 0, "Already have a layer for hwcId %d", hwcId);
Steven Thomasb02664d2017-07-26 18:48:28 -0700221 HWC2::Layer* layer = hwc->createLayer(hwcId);
222 if (!layer) {
223 return false;
224 }
225 HWCInfo& hwcInfo = mHwcLayers[hwcId];
226 hwcInfo.hwc = hwc;
227 hwcInfo.layer = layer;
228 layer->setLayerDestroyedListener(
David Sodman41fdfc92017-11-06 16:09:56 -0800229 [this, hwcId](HWC2::Layer* /*layer*/) { mHwcLayers.erase(hwcId); });
Steven Thomasb02664d2017-07-26 18:48:28 -0700230 return true;
231}
232
233void Layer::destroyHwcLayer(int32_t hwcId) {
234 if (mHwcLayers.count(hwcId) == 0) {
235 return;
236 }
237 auto& hwcInfo = mHwcLayers[hwcId];
David Sodman41fdfc92017-11-06 16:09:56 -0800238 LOG_ALWAYS_FATAL_IF(hwcInfo.layer == nullptr, "Attempt to destroy null layer");
Steven Thomasb02664d2017-07-26 18:48:28 -0700239 LOG_ALWAYS_FATAL_IF(hwcInfo.hwc == nullptr, "Missing HWComposer");
240 hwcInfo.hwc->destroyLayer(hwcId, hwcInfo.layer);
241 // The layer destroyed listener should have cleared the entry from
242 // mHwcLayers. Verify that.
David Sodman41fdfc92017-11-06 16:09:56 -0800243 LOG_ALWAYS_FATAL_IF(mHwcLayers.count(hwcId) != 0, "Stale layer entry in mHwcLayers");
Steven Thomasb02664d2017-07-26 18:48:28 -0700244}
245
246void Layer::destroyAllHwcLayers() {
247 size_t numLayers = mHwcLayers.size();
248 for (size_t i = 0; i < numLayers; ++i) {
249 LOG_ALWAYS_FATAL_IF(mHwcLayers.empty(), "destroyAllHwcLayers failed");
250 destroyHwcLayer(mHwcLayers.begin()->first);
251 }
252 LOG_ALWAYS_FATAL_IF(!mHwcLayers.empty(),
David Sodman41fdfc92017-11-06 16:09:56 -0800253 "All hardware composer layers should have been destroyed");
Steven Thomasb02664d2017-07-26 18:48:28 -0700254}
255#endif
256
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800257Rect Layer::getContentCrop() const {
258 // this is the crop rectangle that applies to the buffer
259 // itself (as opposed to the window)
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700260 Rect crop;
261 if (!mCurrentCrop.isEmpty()) {
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800262 // if the buffer crop is defined, we use that
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700263 crop = mCurrentCrop;
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800264 } else if (mActiveBuffer != NULL) {
265 // otherwise we use the whole buffer
266 crop = mActiveBuffer->getBounds();
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700267 } else {
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800268 // if we don't have a buffer yet, we use an empty/invalid crop
Mathias Agopian4fec8732012-06-29 14:12:52 -0700269 crop.makeInvalid();
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700270 }
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700271 return crop;
272}
273
Mathias Agopianf3e85d42013-05-10 18:01:12 -0700274static Rect reduce(const Rect& win, const Region& exclude) {
275 if (CC_LIKELY(exclude.isEmpty())) {
276 return win;
277 }
278 if (exclude.isRect()) {
279 return win.reduce(exclude.getBounds());
280 }
281 return Region(win).subtract(exclude).getBounds();
282}
283
Robert Carr1f0a16a2016-10-24 16:27:39 -0700284Rect Layer::computeScreenBounds(bool reduceTransparentRegion) const {
285 const Layer::State& s(getDrawingState());
286 Rect win(s.active.w, s.active.h);
287
288 if (!s.crop.isEmpty()) {
289 win.intersect(s.crop, &win);
290 }
291
292 Transform t = getTransform();
293 win = t.transform(win);
294
Robert Carr41b08b52017-06-01 16:11:34 -0700295 if (!s.finalCrop.isEmpty()) {
296 win.intersect(s.finalCrop, &win);
297 }
298
Chia-I Wue41dbe62017-06-13 14:10:56 -0700299 const sp<Layer>& p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700300 // Now we need to calculate the parent bounds, so we can clip ourselves to those.
301 // When calculating the parent bounds for purposes of clipping,
302 // we don't need to constrain the parent to its transparent region.
303 // The transparent region is an optimization based on the
304 // buffer contents of the layer, but does not affect the space allocated to
305 // it by policy, and thus children should be allowed to extend into the
306 // parent's transparent region. In fact one of the main uses, is to reduce
307 // buffer allocation size in cases where a child window sits behind a main window
308 // (by marking the hole in the parent window as a transparent region)
309 if (p != nullptr) {
310 Rect bounds = p->computeScreenBounds(false);
311 bounds.intersect(win, &win);
312 }
313
314 if (reduceTransparentRegion) {
315 auto const screenTransparentRegion = t.transform(s.activeTransparentRegion);
316 win = reduce(win, screenTransparentRegion);
317 }
318
319 return win;
320}
321
Mathias Agopian13127d82013-03-05 17:47:11 -0800322Rect Layer::computeBounds() const {
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700323 const Layer::State& s(getDrawingState());
Michael Lentine6c925ed2014-09-26 17:55:01 -0700324 return computeBounds(s.activeTransparentRegion);
325}
326
327Rect Layer::computeBounds(const Region& activeTransparentRegion) const {
328 const Layer::State& s(getDrawingState());
Mathias Agopian13127d82013-03-05 17:47:11 -0800329 Rect win(s.active.w, s.active.h);
Robert Carrb5d3d262016-03-25 15:08:13 -0700330
331 if (!s.crop.isEmpty()) {
332 win.intersect(s.crop, &win);
Mathias Agopian13127d82013-03-05 17:47:11 -0800333 }
Robert Carr1f0a16a2016-10-24 16:27:39 -0700334
335 Rect bounds = win;
Chia-I Wue41dbe62017-06-13 14:10:56 -0700336 const auto& p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700337 if (p != nullptr) {
Robert Carrde9ec442017-02-08 17:43:36 -0800338 // Look in computeScreenBounds recursive call for explanation of
339 // why we pass false here.
340 bounds = p->computeScreenBounds(false /* reduceTransparentRegion */);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700341 }
342
343 Transform t = getTransform();
344 if (p != nullptr) {
345 win = t.transform(win);
346 win.intersect(bounds, &win);
347 win = t.inverse().transform(win);
348 }
349
Mathias Agopian6c7f25a2013-05-09 20:37:10 -0700350 // subtract the transparent region and snap to the bounds
Michael Lentine6c925ed2014-09-26 17:55:01 -0700351 return reduce(win, activeTransparentRegion);
Mathias Agopian13127d82013-03-05 17:47:11 -0800352}
353
Robert Carr1f0a16a2016-10-24 16:27:39 -0700354Rect Layer::computeInitialCrop(const sp<const DisplayDevice>& hw) const {
Robert Carrb5d3d262016-03-25 15:08:13 -0700355 // the crop is the area of the window that gets cropped, but not
Mathias Agopian13127d82013-03-05 17:47:11 -0800356 // scaled in any ways.
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700357 const State& s(getDrawingState());
Mathias Agopian13127d82013-03-05 17:47:11 -0800358
359 // apply the projection's clipping to the window crop in
360 // layerstack space, and convert-back to layer space.
Mathias Agopian6b442672013-07-09 21:24:52 -0700361 // if there are no window scaling involved, this operation will map to full
362 // pixels in the buffer.
363 // FIXME: the 3 lines below can produce slightly incorrect clipping when we have
364 // a viewport clipping and a window transform. we should use floating point to fix this.
Mathias Agopian0e8f1442013-08-20 21:41:07 -0700365
366 Rect activeCrop(s.active.w, s.active.h);
Robert Carrb5d3d262016-03-25 15:08:13 -0700367 if (!s.crop.isEmpty()) {
Chia-I Wudf7867f2017-07-20 14:24:37 -0700368 activeCrop.intersect(s.crop, &activeCrop);
Mathias Agopian0e8f1442013-08-20 21:41:07 -0700369 }
370
Robert Carr1f0a16a2016-10-24 16:27:39 -0700371 Transform t = getTransform();
372 activeCrop = t.transform(activeCrop);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000373 if (!activeCrop.intersect(hw->getViewport(), &activeCrop)) {
374 activeCrop.clear();
375 }
Robert Carrb5d3d262016-03-25 15:08:13 -0700376 if (!s.finalCrop.isEmpty()) {
David Sodman41fdfc92017-11-06 16:09:56 -0800377 if (!activeCrop.intersect(s.finalCrop, &activeCrop)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000378 activeCrop.clear();
379 }
380 }
chaviwb1154d12017-10-31 14:15:36 -0700381
382 const auto& p = mDrawingParent.promote();
383 if (p != nullptr) {
384 auto parentCrop = p->computeInitialCrop(hw);
385 activeCrop.intersect(parentCrop, &activeCrop);
386 }
387
Robert Carr1f0a16a2016-10-24 16:27:39 -0700388 return activeCrop;
389}
390
Dan Stoza5a423ea2017-02-16 14:10:39 -0800391FloatRect Layer::computeCrop(const sp<const DisplayDevice>& hw) const {
Robert Carr1f0a16a2016-10-24 16:27:39 -0700392 // the content crop is the area of the content that gets scaled to the
393 // layer's size. This is in buffer space.
Dan Stoza5a423ea2017-02-16 14:10:39 -0800394 FloatRect crop = getContentCrop().toFloatRect();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700395
396 // In addition there is a WM-specified crop we pull from our drawing state.
397 const State& s(getDrawingState());
398
399 // Screen space to make reduction to parent crop clearer.
400 Rect activeCrop = computeInitialCrop(hw);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700401 Transform t = getTransform();
402 // Back to layer space to work with the content crop.
403 activeCrop = t.inverse().transform(activeCrop);
Mathias Agopian13127d82013-03-05 17:47:11 -0800404
Michael Lentine28ea2172014-11-19 18:32:37 -0800405 // This needs to be here as transform.transform(Rect) computes the
406 // transformed rect and then takes the bounding box of the result before
407 // returning. This means
408 // transform.inverse().transform(transform.transform(Rect)) != Rect
409 // in which case we need to make sure the final rect is clipped to the
410 // display bounds.
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000411 if (!activeCrop.intersect(Rect(s.active.w, s.active.h), &activeCrop)) {
412 activeCrop.clear();
413 }
Mathias Agopian13127d82013-03-05 17:47:11 -0800414
Mathias Agopianf3e85d42013-05-10 18:01:12 -0700415 // subtract the transparent region and snap to the bounds
416 activeCrop = reduce(activeCrop, s.activeTransparentRegion);
417
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000418 // Transform the window crop to match the buffer coordinate system,
419 // which means using the inverse of the current transform set on the
420 // SurfaceFlingerConsumer.
421 uint32_t invTransform = mCurrentTransform;
Robert Carrcae605c2017-03-29 12:10:31 -0700422 if (getTransformToDisplayInverse()) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000423 /*
Pablo Ceballos021623b2016-04-15 17:31:51 -0700424 * the code below applies the primary display's inverse transform to the
425 * buffer
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000426 */
David Sodman41fdfc92017-11-06 16:09:56 -0800427 uint32_t invTransformOrient = DisplayDevice::getPrimaryDisplayOrientationTransform();
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000428 // calculate the inverse transform
429 if (invTransformOrient & NATIVE_WINDOW_TRANSFORM_ROT_90) {
David Sodman41fdfc92017-11-06 16:09:56 -0800430 invTransformOrient ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H;
Mathias Agopian13127d82013-03-05 17:47:11 -0800431 }
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000432 // and apply to the current transform
David Sodman41fdfc92017-11-06 16:09:56 -0800433 invTransform = (Transform(invTransformOrient) * Transform(invTransform)).getOrientation();
Mathias Agopian13127d82013-03-05 17:47:11 -0800434 }
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000435
436 int winWidth = s.active.w;
437 int winHeight = s.active.h;
438 if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
439 // If the activeCrop has been rotate the ends are rotated but not
440 // the space itself so when transforming ends back we can't rely on
441 // a modification of the axes of rotation. To account for this we
442 // need to reorient the inverse rotation in terms of the current
443 // axes of rotation.
444 bool is_h_flipped = (invTransform & NATIVE_WINDOW_TRANSFORM_FLIP_H) != 0;
445 bool is_v_flipped = (invTransform & NATIVE_WINDOW_TRANSFORM_FLIP_V) != 0;
446 if (is_h_flipped == is_v_flipped) {
David Sodman41fdfc92017-11-06 16:09:56 -0800447 invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H;
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000448 }
449 winWidth = s.active.h;
450 winHeight = s.active.w;
451 }
David Sodman41fdfc92017-11-06 16:09:56 -0800452 const Rect winCrop = activeCrop.transform(invTransform, s.active.w, s.active.h);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000453
454 // below, crop is intersected with winCrop expressed in crop's coordinate space
David Sodman41fdfc92017-11-06 16:09:56 -0800455 float xScale = crop.getWidth() / float(winWidth);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000456 float yScale = crop.getHeight() / float(winHeight);
457
David Sodman41fdfc92017-11-06 16:09:56 -0800458 float insetL = winCrop.left * xScale;
459 float insetT = winCrop.top * yScale;
460 float insetR = (winWidth - winCrop.right) * xScale;
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000461 float insetB = (winHeight - winCrop.bottom) * yScale;
462
David Sodman41fdfc92017-11-06 16:09:56 -0800463 crop.left += insetL;
464 crop.top += insetT;
465 crop.right -= insetR;
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000466 crop.bottom -= insetB;
467
Mathias Agopian13127d82013-03-05 17:47:11 -0800468 return crop;
469}
470
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000471#ifdef USE_HWC2
Robert Carrae060832016-11-28 10:51:00 -0800472void Layer::setGeometry(const sp<const DisplayDevice>& displayDevice, uint32_t z)
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000473#else
David Sodman41fdfc92017-11-06 16:09:56 -0800474void Layer::setGeometry(const sp<const DisplayDevice>& hw, HWComposer::HWCLayerInterface& layer)
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000475#endif
Mathias Agopiana350ff92010-08-10 17:14:02 -0700476{
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000477#ifdef USE_HWC2
Dan Stoza9e56aa02015-11-02 13:00:03 -0800478 const auto hwcId = displayDevice->getHwcDisplayId();
479 auto& hwcInfo = mHwcLayers[hwcId];
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000480#else
481 layer.setDefaultState();
482#endif
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700483
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700484 // enable this layer
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000485#ifdef USE_HWC2
Dan Stoza9e56aa02015-11-02 13:00:03 -0800486 hwcInfo.forceClientComposition = false;
487
488 if (isSecure() && !displayDevice->isSecure()) {
489 hwcInfo.forceClientComposition = true;
490 }
491
492 auto& hwcLayer = hwcInfo.layer;
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000493#else
494 layer.setSkip(false);
495
496 if (isSecure() && !hw->isSecure()) {
497 layer.setSkip(true);
498 }
499#endif
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700500
Mathias Agopian13127d82013-03-05 17:47:11 -0800501 // this gives us only the "orientation" component of the transform
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700502 const State& s(getDrawingState());
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000503#ifdef USE_HWC2
David Revemanecf0fa52017-03-03 11:32:44 -0500504 auto blendMode = HWC2::BlendMode::None;
Robert Carr6452f122017-03-21 10:41:29 -0700505 if (!isOpaque(s) || getAlpha() != 1.0f) {
David Sodman41fdfc92017-11-06 16:09:56 -0800506 blendMode =
507 mPremultipliedAlpha ? HWC2::BlendMode::Premultiplied : HWC2::BlendMode::Coverage;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800508 }
David Revemanecf0fa52017-03-03 11:32:44 -0500509 auto error = hwcLayer->setBlendMode(blendMode);
David Sodman41fdfc92017-11-06 16:09:56 -0800510 ALOGE_IF(error != HWC2::Error::None,
511 "[%s] Failed to set blend mode %s:"
512 " %s (%d)",
513 mName.string(), to_string(blendMode).c_str(), to_string(error).c_str(),
514 static_cast<int32_t>(error));
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000515#else
chaviw13fdc492017-06-27 12:40:18 -0700516 if (!isOpaque(s) || getAlpha() != 1.0f) {
David Sodman41fdfc92017-11-06 16:09:56 -0800517 layer.setBlending(mPremultipliedAlpha ? HWC_BLENDING_PREMULT : HWC_BLENDING_COVERAGE);
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000518 }
519#endif
Mathias Agopian13127d82013-03-05 17:47:11 -0800520
521 // apply the layer's transform, followed by the display's global transform
522 // here we're guaranteed that the layer's transform preserves rects
Michael Lentine6c925ed2014-09-26 17:55:01 -0700523 Region activeTransparentRegion(s.activeTransparentRegion);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700524 Transform t = getTransform();
Robert Carrb5d3d262016-03-25 15:08:13 -0700525 if (!s.crop.isEmpty()) {
526 Rect activeCrop(s.crop);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700527 activeCrop = t.transform(activeCrop);
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000528#ifdef USE_HWC2
David Sodman41fdfc92017-11-06 16:09:56 -0800529 if (!activeCrop.intersect(displayDevice->getViewport(), &activeCrop)) {
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000530#else
David Sodman41fdfc92017-11-06 16:09:56 -0800531 if (!activeCrop.intersect(hw->getViewport(), &activeCrop)) {
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000532#endif
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000533 activeCrop.clear();
534 }
Robert Carr1f0a16a2016-10-24 16:27:39 -0700535 activeCrop = t.inverse().transform(activeCrop, true);
Michael Lentine28ea2172014-11-19 18:32:37 -0800536 // This needs to be here as transform.transform(Rect) computes the
537 // transformed rect and then takes the bounding box of the result before
538 // returning. This means
539 // transform.inverse().transform(transform.transform(Rect)) != Rect
540 // in which case we need to make sure the final rect is clipped to the
541 // display bounds.
David Sodman41fdfc92017-11-06 16:09:56 -0800542 if (!activeCrop.intersect(Rect(s.active.w, s.active.h), &activeCrop)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000543 activeCrop.clear();
544 }
Michael Lentine6c925ed2014-09-26 17:55:01 -0700545 // mark regions outside the crop as transparent
546 activeTransparentRegion.orSelf(Rect(0, 0, s.active.w, activeCrop.top));
David Sodman41fdfc92017-11-06 16:09:56 -0800547 activeTransparentRegion.orSelf(Rect(0, activeCrop.bottom, s.active.w, s.active.h));
548 activeTransparentRegion.orSelf(Rect(0, activeCrop.top, activeCrop.left, activeCrop.bottom));
549 activeTransparentRegion.orSelf(
550 Rect(activeCrop.right, activeCrop.top, s.active.w, activeCrop.bottom));
Michael Lentine6c925ed2014-09-26 17:55:01 -0700551 }
Robert Carr1f0a16a2016-10-24 16:27:39 -0700552
553 Rect frame(t.transform(computeBounds(activeTransparentRegion)));
Robert Carrb5d3d262016-03-25 15:08:13 -0700554 if (!s.finalCrop.isEmpty()) {
David Sodman41fdfc92017-11-06 16:09:56 -0800555 if (!frame.intersect(s.finalCrop, &frame)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000556 frame.clear();
557 }
558 }
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000559#ifdef USE_HWC2
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000560 if (!frame.intersect(displayDevice->getViewport(), &frame)) {
561 frame.clear();
562 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800563 const Transform& tr(displayDevice->getTransform());
564 Rect transformedFrame = tr.transform(frame);
David Revemanecf0fa52017-03-03 11:32:44 -0500565 error = hwcLayer->setDisplayFrame(transformedFrame);
Dan Stozae22aec72016-08-01 13:20:59 -0700566 if (error != HWC2::Error::None) {
David Sodman41fdfc92017-11-06 16:09:56 -0800567 ALOGE("[%s] Failed to set display frame [%d, %d, %d, %d]: %s (%d)", mName.string(),
568 transformedFrame.left, transformedFrame.top, transformedFrame.right,
569 transformedFrame.bottom, to_string(error).c_str(), static_cast<int32_t>(error));
Dan Stozae22aec72016-08-01 13:20:59 -0700570 } else {
571 hwcInfo.displayFrame = transformedFrame;
572 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800573
Dan Stoza5a423ea2017-02-16 14:10:39 -0800574 FloatRect sourceCrop = computeCrop(displayDevice);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800575 error = hwcLayer->setSourceCrop(sourceCrop);
Dan Stozae22aec72016-08-01 13:20:59 -0700576 if (error != HWC2::Error::None) {
577 ALOGE("[%s] Failed to set source crop [%.3f, %.3f, %.3f, %.3f]: "
David Sodman41fdfc92017-11-06 16:09:56 -0800578 "%s (%d)",
579 mName.string(), sourceCrop.left, sourceCrop.top, sourceCrop.right, sourceCrop.bottom,
580 to_string(error).c_str(), static_cast<int32_t>(error));
Dan Stozae22aec72016-08-01 13:20:59 -0700581 } else {
582 hwcInfo.sourceCrop = sourceCrop;
583 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800584
chaviw13fdc492017-06-27 12:40:18 -0700585 float alpha = static_cast<float>(getAlpha());
Robert Carr6452f122017-03-21 10:41:29 -0700586 error = hwcLayer->setPlaneAlpha(alpha);
David Sodman41fdfc92017-11-06 16:09:56 -0800587 ALOGE_IF(error != HWC2::Error::None,
588 "[%s] Failed to set plane alpha %.3f: "
589 "%s (%d)",
590 mName.string(), alpha, to_string(error).c_str(), static_cast<int32_t>(error));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800591
Robert Carrae060832016-11-28 10:51:00 -0800592 error = hwcLayer->setZOrder(z);
David Sodman41fdfc92017-11-06 16:09:56 -0800593 ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set Z %u: %s (%d)", mName.string(), z,
594 to_string(error).c_str(), static_cast<int32_t>(error));
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -0500595
Albert Chaulk2a589632017-05-04 16:59:44 -0400596 int type = s.type;
597 int appId = s.appId;
Chia-I Wue41dbe62017-06-13 14:10:56 -0700598 sp<Layer> parent = mDrawingParent.promote();
Albert Chaulk2a589632017-05-04 16:59:44 -0400599 if (parent.get()) {
600 auto& parentState = parent->getDrawingState();
601 type = parentState.type;
602 appId = parentState.appId;
603 }
604
605 error = hwcLayer->setInfo(type, appId);
David Sodman41fdfc92017-11-06 16:09:56 -0800606 ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set info (%d)", mName.string(),
607 static_cast<int32_t>(error));
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000608#else
609 if (!frame.intersect(hw->getViewport(), &frame)) {
610 frame.clear();
611 }
612 const Transform& tr(hw->getTransform());
613 layer.setFrame(tr.transform(frame));
614 layer.setCrop(computeCrop(hw));
David Sodman41fdfc92017-11-06 16:09:56 -0800615 layer.setPlaneAlpha(static_cast<uint8_t>(std::round(255.0f * getAlpha())));
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000616#endif
Mathias Agopian9f8386e2013-01-29 18:56:42 -0800617
Mathias Agopian29a367b2011-07-12 14:51:45 -0700618 /*
619 * Transformations are applied in this order:
620 * 1) buffer orientation/flip/mirror
621 * 2) state transformation (window manager)
622 * 3) layer orientation (screen orientation)
623 * (NOTE: the matrices are multiplied in reverse order)
624 */
625
626 const Transform bufferOrientation(mCurrentTransform);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700627 Transform transform(tr * t * bufferOrientation);
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700628
Robert Carrcae605c2017-03-29 12:10:31 -0700629 if (getTransformToDisplayInverse()) {
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700630 /*
Pablo Ceballos021623b2016-04-15 17:31:51 -0700631 * the code below applies the primary display's inverse transform to the
632 * buffer
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700633 */
David Sodman41fdfc92017-11-06 16:09:56 -0800634 uint32_t invTransform = DisplayDevice::getPrimaryDisplayOrientationTransform();
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700635 // calculate the inverse transform
636 if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
David Sodman41fdfc92017-11-06 16:09:56 -0800637 invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700638 }
Robert Carrcae605c2017-03-29 12:10:31 -0700639
640 /*
641 * Here we cancel out the orientation component of the WM transform.
642 * The scaling and translate components are already included in our bounds
643 * computation so it's enough to just omit it in the composition.
644 * See comment in onDraw with ref to b/36727915 for why.
645 */
646 transform = Transform(invTransform) * tr * bufferOrientation;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700647 }
Mathias Agopian29a367b2011-07-12 14:51:45 -0700648
649 // this gives us only the "orientation" component of the transform
Mathias Agopian13127d82013-03-05 17:47:11 -0800650 const uint32_t orientation = transform.getOrientation();
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000651#ifdef USE_HWC2
Dan Stoza9e56aa02015-11-02 13:00:03 -0800652 if (orientation & Transform::ROT_INVALID) {
653 // we can only handle simple transformation
654 hwcInfo.forceClientComposition = true;
655 } else {
656 auto transform = static_cast<HWC2::Transform>(orientation);
657 auto error = hwcLayer->setTransform(transform);
David Sodman41fdfc92017-11-06 16:09:56 -0800658 ALOGE_IF(error != HWC2::Error::None,
659 "[%s] Failed to set transform %s: "
660 "%s (%d)",
661 mName.string(), to_string(transform).c_str(), to_string(error).c_str(),
662 static_cast<int32_t>(error));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800663 }
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000664#else
665 if (orientation & Transform::ROT_INVALID) {
666 // we can only handle simple transformation
667 layer.setSkip(true);
668 } else {
669 layer.setTransform(orientation);
670 }
671#endif
Mathias Agopiana350ff92010-08-10 17:14:02 -0700672}
673
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000674#ifdef USE_HWC2
Dan Stoza9e56aa02015-11-02 13:00:03 -0800675void Layer::forceClientComposition(int32_t hwcId) {
676 if (mHwcLayers.count(hwcId) == 0) {
677 ALOGE("forceClientComposition: no HWC layer found (%d)", hwcId);
678 return;
679 }
680
681 mHwcLayers[hwcId].forceClientComposition = true;
682}
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000683#else
684void Layer::setPerFrameData(const sp<const DisplayDevice>& hw,
David Sodmaneb085e02017-10-05 18:49:04 -0700685 HWComposer::HWCLayerInterface& layer) {
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000686 // we have to set the visible region on every frame because
687 // we currently free it during onLayerDisplayed(), which is called
688 // after HWComposer::commit() -- every frame.
689 // Apply this display's projection's viewport to the visible region
690 // before giving it to the HWC HAL.
691 const Transform& tr = hw->getTransform();
692 Region visible = tr.transform(visibleRegion.intersect(hw->getViewport()));
693 layer.setVisibleRegionScreen(visible);
694 layer.setSurfaceDamage(surfaceDamageRegion);
695 mIsGlesComposition = (layer.getCompositionType() == HWC_FRAMEBUFFER);
Dan Stozaee44edd2015-03-23 15:50:23 -0700696
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000697 if (mSidebandStream.get()) {
698 layer.setSidebandStream(mSidebandStream);
699 } else {
700 // NOTE: buffer can be NULL if the client never drew into this
701 // layer yet, or if we ran out of memory
702 layer.setBuffer(mActiveBuffer);
703 }
704}
705#endif
706
David Sodmaneb085e02017-10-05 18:49:04 -0700707
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000708#ifdef USE_HWC2
Dan Stoza9e56aa02015-11-02 13:00:03 -0800709void Layer::updateCursorPosition(const sp<const DisplayDevice>& displayDevice) {
710 auto hwcId = displayDevice->getHwcDisplayId();
David Sodman41fdfc92017-11-06 16:09:56 -0800711 if (mHwcLayers.count(hwcId) == 0 || getCompositionType(hwcId) != HWC2::Composition::Cursor) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800712 return;
713 }
714
715 // This gives us only the "orientation" component of the transform
716 const State& s(getCurrentState());
717
718 // Apply the layer's transform, followed by the display's global transform
719 // Here we're guaranteed that the layer's transform preserves rects
720 Rect win(s.active.w, s.active.h);
Robert Carrb5d3d262016-03-25 15:08:13 -0700721 if (!s.crop.isEmpty()) {
722 win.intersect(s.crop, &win);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800723 }
724 // Subtract the transparent region and snap to the bounds
725 Rect bounds = reduce(win, s.activeTransparentRegion);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700726 Rect frame(getTransform().transform(bounds));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800727 frame.intersect(displayDevice->getViewport(), &frame);
Robert Carrb5d3d262016-03-25 15:08:13 -0700728 if (!s.finalCrop.isEmpty()) {
729 frame.intersect(s.finalCrop, &frame);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000730 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800731 auto& displayTransform(displayDevice->getTransform());
732 auto position = displayTransform.transform(frame);
733
David Sodman41fdfc92017-11-06 16:09:56 -0800734 auto error = mHwcLayers[hwcId].layer->setCursorPosition(position.left, position.top);
735 ALOGE_IF(error != HWC2::Error::None,
736 "[%s] Failed to set cursor position "
737 "to (%d, %d): %s (%d)",
738 mName.string(), position.left, position.top, to_string(error).c_str(),
739 static_cast<int32_t>(error));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800740}
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000741#else
David Sodman41fdfc92017-11-06 16:09:56 -0800742Rect Layer::getPosition(const sp<const DisplayDevice>& hw) {
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000743 // this gives us only the "orientation" component of the transform
744 const State& s(getCurrentState());
745
746 // apply the layer's transform, followed by the display's global transform
747 // here we're guaranteed that the layer's transform preserves rects
748 Rect win(s.active.w, s.active.h);
749 if (!s.crop.isEmpty()) {
750 win.intersect(s.crop, &win);
751 }
752 // subtract the transparent region and snap to the bounds
753 Rect bounds = reduce(win, s.activeTransparentRegion);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700754 Rect frame(getTransform().transform(bounds));
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000755 frame.intersect(hw->getViewport(), &frame);
756 if (!s.finalCrop.isEmpty()) {
757 frame.intersect(s.finalCrop, &frame);
758 }
759 const Transform& tr(hw->getTransform());
760 return Rect(tr.transform(frame));
761}
762#endif
Riley Andrews03414a12014-07-01 14:22:59 -0700763
Mathias Agopian13127d82013-03-05 17:47:11 -0800764// ---------------------------------------------------------------------------
765// drawing...
766// ---------------------------------------------------------------------------
767
chaviwa76b2712017-09-20 12:02:26 -0700768void Layer::draw(const RenderArea& renderArea, const Region& clip) const {
769 onDraw(renderArea, clip, false);
Mathias Agopian13127d82013-03-05 17:47:11 -0800770}
771
chaviwa76b2712017-09-20 12:02:26 -0700772void Layer::draw(const RenderArea& renderArea, bool useIdentityTransform) const {
773 onDraw(renderArea, Region(renderArea.getBounds()), useIdentityTransform);
Mathias Agopian13127d82013-03-05 17:47:11 -0800774}
775
chaviwa76b2712017-09-20 12:02:26 -0700776void Layer::draw(const RenderArea& renderArea) const {
777 onDraw(renderArea, Region(renderArea.getBounds()), false);
Dan Stozac7014012014-02-14 15:03:43 -0800778}
779
David Sodman41fdfc92017-11-06 16:09:56 -0800780void Layer::clearWithOpenGL(const RenderArea& renderArea, float red, float green, float blue,
781 float alpha) const {
Mathias Agopian19733a32013-08-28 18:13:56 -0700782 RenderEngine& engine(mFlinger->getRenderEngine());
chaviwa76b2712017-09-20 12:02:26 -0700783 computeGeometry(renderArea, mMesh, false);
Mathias Agopian19733a32013-08-28 18:13:56 -0700784 engine.setupFillWithColor(red, green, blue, alpha);
785 engine.drawMesh(mMesh);
Mathias Agopian13127d82013-03-05 17:47:11 -0800786}
787
chaviwa76b2712017-09-20 12:02:26 -0700788void Layer::clearWithOpenGL(const RenderArea& renderArea) const {
David Sodman41fdfc92017-11-06 16:09:56 -0800789 clearWithOpenGL(renderArea, 0, 0, 0, 0);
Mathias Agopian13127d82013-03-05 17:47:11 -0800790}
791
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000792#ifdef USE_HWC2
David Sodman41fdfc92017-11-06 16:09:56 -0800793void Layer::setCompositionType(int32_t hwcId, HWC2::Composition type, bool callIntoHwc) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800794 if (mHwcLayers.count(hwcId) == 0) {
795 ALOGE("setCompositionType called without a valid HWC layer");
796 return;
797 }
798 auto& hwcInfo = mHwcLayers[hwcId];
799 auto& hwcLayer = hwcInfo.layer;
David Sodman41fdfc92017-11-06 16:09:56 -0800800 ALOGV("setCompositionType(%" PRIx64 ", %s, %d)", hwcLayer->getId(), to_string(type).c_str(),
801 static_cast<int>(callIntoHwc));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800802 if (hwcInfo.compositionType != type) {
803 ALOGV(" actually setting");
804 hwcInfo.compositionType = type;
805 if (callIntoHwc) {
806 auto error = hwcLayer->setCompositionType(type);
David Sodman41fdfc92017-11-06 16:09:56 -0800807 ALOGE_IF(error != HWC2::Error::None,
808 "[%s] Failed to set "
809 "composition type %s: %s (%d)",
810 mName.string(), to_string(type).c_str(), to_string(error).c_str(),
811 static_cast<int32_t>(error));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800812 }
813 }
814}
815
816HWC2::Composition Layer::getCompositionType(int32_t hwcId) const {
Dan Stozaec0f7172016-07-21 11:09:40 -0700817 if (hwcId == DisplayDevice::DISPLAY_ID_INVALID) {
818 // If we're querying the composition type for a display that does not
819 // have a HWC counterpart, then it will always be Client
820 return HWC2::Composition::Client;
821 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800822 if (mHwcLayers.count(hwcId) == 0) {
Dan Stozaec0f7172016-07-21 11:09:40 -0700823 ALOGE("getCompositionType called with an invalid HWC layer");
Dan Stoza9e56aa02015-11-02 13:00:03 -0800824 return HWC2::Composition::Invalid;
825 }
826 return mHwcLayers.at(hwcId).compositionType;
827}
828
829void Layer::setClearClientTarget(int32_t hwcId, bool clear) {
830 if (mHwcLayers.count(hwcId) == 0) {
831 ALOGE("setClearClientTarget called without a valid HWC layer");
832 return;
833 }
834 mHwcLayers[hwcId].clearClientTarget = clear;
835}
836
837bool Layer::getClearClientTarget(int32_t hwcId) const {
838 if (mHwcLayers.count(hwcId) == 0) {
839 ALOGE("getClearClientTarget called without a valid HWC layer");
840 return false;
841 }
842 return mHwcLayers.at(hwcId).clearClientTarget;
843}
Fabien Sanglard9d96de42016-10-11 00:15:18 +0000844#endif
Dan Stoza9e56aa02015-11-02 13:00:03 -0800845
Dan Stozacac35382016-01-27 12:21:06 -0800846bool Layer::addSyncPoint(const std::shared_ptr<SyncPoint>& point) {
847 if (point->getFrameNumber() <= mCurrentFrameNumber) {
848 // Don't bother with a SyncPoint, since we've already latched the
849 // relevant frame
850 return false;
Dan Stoza7dde5992015-05-22 09:51:44 -0700851 }
852
Dan Stozacac35382016-01-27 12:21:06 -0800853 Mutex::Autolock lock(mLocalSyncPointMutex);
854 mLocalSyncPoints.push_back(point);
855 return true;
Dan Stoza7dde5992015-05-22 09:51:44 -0700856}
857
Mathias Agopian13127d82013-03-05 17:47:11 -0800858void Layer::setFiltering(bool filtering) {
859 mFiltering = filtering;
860}
861
862bool Layer::getFiltering() const {
863 return mFiltering;
864}
865
Mathias Agopian13127d82013-03-05 17:47:11 -0800866// ----------------------------------------------------------------------------
867// local state
868// ----------------------------------------------------------------------------
869
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000870static void boundPoint(vec2* point, const Rect& crop) {
871 if (point->x < crop.left) {
872 point->x = crop.left;
873 }
874 if (point->x > crop.right) {
875 point->x = crop.right;
876 }
877 if (point->y < crop.top) {
878 point->y = crop.top;
879 }
880 if (point->y > crop.bottom) {
881 point->y = crop.bottom;
882 }
883}
884
chaviwa76b2712017-09-20 12:02:26 -0700885void Layer::computeGeometry(const RenderArea& renderArea, Mesh& mesh,
886 bool useIdentityTransform) const {
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700887 const Layer::State& s(getDrawingState());
chaviwa76b2712017-09-20 12:02:26 -0700888 const Transform renderAreaTransform(renderArea.getTransform());
889 const uint32_t height = renderArea.getHeight();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700890 Rect win = computeBounds();
Mathias Agopian3f844832013-08-07 21:24:32 -0700891
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000892 vec2 lt = vec2(win.left, win.top);
893 vec2 lb = vec2(win.left, win.bottom);
894 vec2 rb = vec2(win.right, win.bottom);
895 vec2 rt = vec2(win.right, win.top);
896
Robert Carr1f0a16a2016-10-24 16:27:39 -0700897 Transform layerTransform = getTransform();
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000898 if (!useIdentityTransform) {
Robert Carr1f0a16a2016-10-24 16:27:39 -0700899 lt = layerTransform.transform(lt);
900 lb = layerTransform.transform(lb);
901 rb = layerTransform.transform(rb);
902 rt = layerTransform.transform(rt);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000903 }
904
Robert Carrb5d3d262016-03-25 15:08:13 -0700905 if (!s.finalCrop.isEmpty()) {
906 boundPoint(&lt, s.finalCrop);
907 boundPoint(&lb, s.finalCrop);
908 boundPoint(&rb, s.finalCrop);
909 boundPoint(&rt, s.finalCrop);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000910 }
911
Mathias Agopianff2ed702013-09-01 21:36:12 -0700912 Mesh::VertexArray<vec2> position(mesh.getPositionArray<vec2>());
chaviwa76b2712017-09-20 12:02:26 -0700913 position[0] = renderAreaTransform.transform(lt);
914 position[1] = renderAreaTransform.transform(lb);
915 position[2] = renderAreaTransform.transform(rb);
916 position[3] = renderAreaTransform.transform(rt);
David Sodman41fdfc92017-11-06 16:09:56 -0800917 for (size_t i = 0; i < 4; i++) {
chaviwa76b2712017-09-20 12:02:26 -0700918 position[i].y = height - position[i].y;
Mathias Agopian13127d82013-03-05 17:47:11 -0800919 }
920}
Eric Hassoldac45e6b2011-02-10 14:41:26 -0800921
David Sodman41fdfc92017-11-06 16:09:56 -0800922bool Layer::isSecure() const {
Dan Stoza23116082015-06-18 14:58:39 -0700923 const Layer::State& s(mDrawingState);
924 return (s.flags & layer_state_t::eLayerSecure);
925}
926
Mathias Agopian13127d82013-03-05 17:47:11 -0800927void Layer::setVisibleRegion(const Region& visibleRegion) {
928 // always called from main thread
929 this->visibleRegion = visibleRegion;
930}
931
932void Layer::setCoveredRegion(const Region& coveredRegion) {
933 // always called from main thread
934 this->coveredRegion = coveredRegion;
935}
936
David Sodman41fdfc92017-11-06 16:09:56 -0800937void Layer::setVisibleNonTransparentRegion(const Region& setVisibleNonTransparentRegion) {
Mathias Agopian13127d82013-03-05 17:47:11 -0800938 // always called from main thread
939 this->visibleNonTransparentRegion = setVisibleNonTransparentRegion;
940}
941
942// ----------------------------------------------------------------------------
943// transaction
944// ----------------------------------------------------------------------------
945
Dan Stoza7dde5992015-05-22 09:51:44 -0700946void Layer::pushPendingState() {
947 if (!mCurrentState.modified) {
948 return;
949 }
950
Dan Stoza7dde5992015-05-22 09:51:44 -0700951 // If this transaction is waiting on the receipt of a frame, generate a sync
952 // point and send it to the remote layer.
Robert Carr0d480722017-01-10 16:42:54 -0800953 if (mCurrentState.barrierLayer != nullptr) {
954 sp<Layer> barrierLayer = mCurrentState.barrierLayer.promote();
955 if (barrierLayer == nullptr) {
956 ALOGE("[%s] Unable to promote barrier Layer.", mName.string());
Dan Stoza7dde5992015-05-22 09:51:44 -0700957 // If we can't promote the layer we are intended to wait on,
958 // then it is expired or otherwise invalid. Allow this transaction
959 // to be applied as per normal (no synchronization).
Robert Carr0d480722017-01-10 16:42:54 -0800960 mCurrentState.barrierLayer = nullptr;
Pablo Ceballos3bddd5b2015-11-19 14:39:14 -0800961 } else {
David Sodman41fdfc92017-11-06 16:09:56 -0800962 auto syncPoint = std::make_shared<SyncPoint>(mCurrentState.frameNumber);
Robert Carr0d480722017-01-10 16:42:54 -0800963 if (barrierLayer->addSyncPoint(syncPoint)) {
Dan Stozacac35382016-01-27 12:21:06 -0800964 mRemoteSyncPoints.push_back(std::move(syncPoint));
965 } else {
966 // We already missed the frame we're supposed to synchronize
967 // on, so go ahead and apply the state update
Robert Carr0d480722017-01-10 16:42:54 -0800968 mCurrentState.barrierLayer = nullptr;
Dan Stozacac35382016-01-27 12:21:06 -0800969 }
Dan Stoza7dde5992015-05-22 09:51:44 -0700970 }
971
Dan Stoza7dde5992015-05-22 09:51:44 -0700972 // Wake us up to check if the frame has been received
973 setTransactionFlags(eTransactionNeeded);
Dan Stozaf5702ff2016-11-02 16:27:47 -0700974 mFlinger->setTransactionFlags(eTraversalNeeded);
Dan Stoza7dde5992015-05-22 09:51:44 -0700975 }
976 mPendingStates.push_back(mCurrentState);
Dan Stozaf7ba41a2017-05-10 15:11:11 -0700977 ATRACE_INT(mTransactionName.string(), mPendingStates.size());
Dan Stoza7dde5992015-05-22 09:51:44 -0700978}
979
Pablo Ceballos05289c22016-04-14 15:49:55 -0700980void Layer::popPendingState(State* stateToCommit) {
981 auto oldFlags = stateToCommit->flags;
982 *stateToCommit = mPendingStates[0];
David Sodman41fdfc92017-11-06 16:09:56 -0800983 stateToCommit->flags =
984 (oldFlags & ~stateToCommit->mask) | (stateToCommit->flags & stateToCommit->mask);
Dan Stoza7dde5992015-05-22 09:51:44 -0700985
986 mPendingStates.removeAt(0);
Dan Stozaf7ba41a2017-05-10 15:11:11 -0700987 ATRACE_INT(mTransactionName.string(), mPendingStates.size());
Dan Stoza7dde5992015-05-22 09:51:44 -0700988}
989
Pablo Ceballos05289c22016-04-14 15:49:55 -0700990bool Layer::applyPendingStates(State* stateToCommit) {
Dan Stoza7dde5992015-05-22 09:51:44 -0700991 bool stateUpdateAvailable = false;
992 while (!mPendingStates.empty()) {
Robert Carr0d480722017-01-10 16:42:54 -0800993 if (mPendingStates[0].barrierLayer != nullptr) {
Dan Stoza7dde5992015-05-22 09:51:44 -0700994 if (mRemoteSyncPoints.empty()) {
995 // If we don't have a sync point for this, apply it anyway. It
996 // will be visually wrong, but it should keep us from getting
997 // into too much trouble.
998 ALOGE("[%s] No local sync point found", mName.string());
Pablo Ceballos05289c22016-04-14 15:49:55 -0700999 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -07001000 stateUpdateAvailable = true;
1001 continue;
1002 }
1003
David Sodman41fdfc92017-11-06 16:09:56 -08001004 if (mRemoteSyncPoints.front()->getFrameNumber() != mPendingStates[0].frameNumber) {
1005 ALOGE("[%s] Unexpected sync point frame number found", mName.string());
Dan Stozacac35382016-01-27 12:21:06 -08001006
1007 // Signal our end of the sync point and then dispose of it
1008 mRemoteSyncPoints.front()->setTransactionApplied();
1009 mRemoteSyncPoints.pop_front();
1010 continue;
1011 }
1012
Dan Stoza7dde5992015-05-22 09:51:44 -07001013 if (mRemoteSyncPoints.front()->frameIsAvailable()) {
1014 // Apply the state update
Pablo Ceballos05289c22016-04-14 15:49:55 -07001015 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -07001016 stateUpdateAvailable = true;
1017
1018 // Signal our end of the sync point and then dispose of it
1019 mRemoteSyncPoints.front()->setTransactionApplied();
1020 mRemoteSyncPoints.pop_front();
Dan Stoza792e5292016-02-11 11:43:58 -08001021 } else {
1022 break;
Dan Stoza7dde5992015-05-22 09:51:44 -07001023 }
Dan Stoza7dde5992015-05-22 09:51:44 -07001024 } else {
Pablo Ceballos05289c22016-04-14 15:49:55 -07001025 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -07001026 stateUpdateAvailable = true;
1027 }
1028 }
1029
1030 // If we still have pending updates, wake SurfaceFlinger back up and point
1031 // it at this layer so we can process them
1032 if (!mPendingStates.empty()) {
1033 setTransactionFlags(eTransactionNeeded);
1034 mFlinger->setTransactionFlags(eTraversalNeeded);
1035 }
1036
1037 mCurrentState.modified = false;
1038 return stateUpdateAvailable;
1039}
1040
Mathias Agopian13127d82013-03-05 17:47:11 -08001041uint32_t Layer::doTransaction(uint32_t flags) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -08001042 ATRACE_CALL();
1043
Dan Stoza7dde5992015-05-22 09:51:44 -07001044 pushPendingState();
Pablo Ceballos05289c22016-04-14 15:49:55 -07001045 Layer::State c = getCurrentState();
1046 if (!applyPendingStates(&c)) {
Dan Stoza7dde5992015-05-22 09:51:44 -07001047 return 0;
1048 }
1049
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001050 const Layer::State& s(getDrawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001051
David Sodman41fdfc92017-11-06 16:09:56 -08001052 const bool sizeChanged = (c.requested.w != s.requested.w) || (c.requested.h != s.requested.h);
Mathias Agopiana138f892010-05-21 17:24:35 -07001053
David Sodmaneb085e02017-10-05 18:49:04 -07001054 if (sizeChanged) {
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001055 // the size changed, we need to ask our client to request a new buffer
Steve Block9d453682011-12-20 16:23:08 +00001056 ALOGD_IF(DEBUG_RESIZE,
David Sodman41fdfc92017-11-06 16:09:56 -08001057 "doTransaction: geometry (layer=%p '%s'), tr=%02x, scalingMode=%d\n"
1058 " current={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
1059 " requested={ wh={%4u,%4u} }}\n"
1060 " drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
1061 " requested={ wh={%4u,%4u} }}\n",
1062 this, getName().string(), mCurrentTransform, getEffectiveScalingMode(), c.active.w,
1063 c.active.h, c.crop.left, c.crop.top, c.crop.right, c.crop.bottom,
1064 c.crop.getWidth(), c.crop.getHeight(), c.requested.w, c.requested.h, s.active.w,
1065 s.active.h, s.crop.left, s.crop.top, s.crop.right, s.crop.bottom,
1066 s.crop.getWidth(), s.crop.getHeight(), s.requested.w, s.requested.h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001067
Jamie Gennis2a0d5b62011-09-26 16:54:44 -07001068 // record the new size, form this point on, when the client request
1069 // a buffer, it'll get the new size.
David Sodmaneb085e02017-10-05 18:49:04 -07001070 setDefaultBufferSize(c.requested.w, c.requested.h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001071 }
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001072
Robert Carre392b552017-09-19 12:16:05 -07001073 // Don't let Layer::doTransaction update the drawing state
1074 // if we have a pending resize, unless we are in fixed-size mode.
1075 // the drawing state will be updated only once we receive a buffer
1076 // with the correct size.
1077 //
1078 // In particular, we want to make sure the clip (which is part
1079 // of the geometry state) is latched together with the size but is
1080 // latched immediately when no resizing is involved.
1081 //
1082 // If a sideband stream is attached, however, we want to skip this
1083 // optimization so that transactions aren't missed when a buffer
1084 // never arrives
1085 //
1086 // In the case that we don't have a buffer we ignore other factors
1087 // and avoid entering the resizePending state. At a high level the
1088 // resizePending state is to avoid applying the state of the new buffer
1089 // to the old buffer. However in the state where we don't have an old buffer
1090 // there is no such concern but we may still be being used as a parent layer.
David Sodman41fdfc92017-11-06 16:09:56 -08001091 const bool resizePending = ((c.requested.w != c.active.w) || (c.requested.h != c.active.h)) &&
1092 (mActiveBuffer != nullptr);
Mathias Agopian0cd545f2012-06-07 14:18:55 -07001093 if (!isFixedSize()) {
Dan Stoza9e9b0442015-04-22 14:59:08 -07001094 if (resizePending && mSidebandStream == NULL) {
Mathias Agopian0cd545f2012-06-07 14:18:55 -07001095 flags |= eDontUpdateGeometryState;
1096 }
1097 }
1098
Robert Carr7bf247e2017-05-18 14:02:49 -07001099 // Here we apply various requested geometry states, depending on our
1100 // latching configuration. See Layer.h for a detailed discussion of
1101 // how geometry latching is controlled.
1102 if (!(flags & eDontUpdateGeometryState)) {
Pablo Ceballos7d052572016-06-02 17:46:05 -07001103 Layer::State& editCurrentState(getCurrentState());
Robert Carr7bf247e2017-05-18 14:02:49 -07001104
1105 // If mFreezeGeometryUpdates is true we are in the setGeometryAppliesWithResize
1106 // mode, which causes attributes which normally latch regardless of scaling mode,
1107 // to be delayed. We copy the requested state to the active state making sure
1108 // to respect these rules (again see Layer.h for a detailed discussion).
1109 //
1110 // There is an awkward asymmetry in the handling of the crop states in the position
1111 // states, as can be seen below. Largely this arises from position and transform
1112 // being stored in the same data structure while having different latching rules.
1113 // b/38182305
1114 //
1115 // Careful that "c" and editCurrentState may not begin as equivalent due to
1116 // applyPendingStates in the presence of deferred transactions.
1117 if (mFreezeGeometryUpdates) {
Robert Carr82364e32016-05-15 11:27:47 -07001118 float tx = c.active.transform.tx();
1119 float ty = c.active.transform.ty();
1120 c.active = c.requested;
1121 c.active.transform.set(tx, ty);
1122 editCurrentState.active = c.active;
1123 } else {
1124 editCurrentState.active = editCurrentState.requested;
1125 c.active = c.requested;
1126 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001127 }
1128
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001129 if (s.active != c.active) {
Mathias Agopian13127d82013-03-05 17:47:11 -08001130 // invalidate and recompute the visible regions if needed
1131 flags |= Layer::eVisibleRegion;
1132 }
1133
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001134 if (c.sequence != s.sequence) {
Mathias Agopian13127d82013-03-05 17:47:11 -08001135 // invalidate and recompute the visible regions if needed
1136 flags |= eVisibleRegion;
1137 this->contentDirty = true;
1138
1139 // we may use linear filtering, if the matrix scales us
Robert Carr3dcabfa2016-03-01 18:36:58 -08001140 const uint8_t type = c.active.transform.getType();
David Sodman41fdfc92017-11-06 16:09:56 -08001141 mNeedsFiltering = (!c.active.transform.preserveRects() || (type >= Transform::SCALE));
Mathias Agopian13127d82013-03-05 17:47:11 -08001142 }
1143
Dan Stozac8145172016-04-28 16:29:06 -07001144 // If the layer is hidden, signal and clear out all local sync points so
1145 // that transactions for layers depending on this layer's frames becoming
1146 // visible are not blocked
1147 if (c.flags & layer_state_t::eLayerHidden) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001148 clearSyncPoints();
Dan Stozac8145172016-04-28 16:29:06 -07001149 }
1150
Mathias Agopian13127d82013-03-05 17:47:11 -08001151 // Commit the transaction
Pablo Ceballos05289c22016-04-14 15:49:55 -07001152 commitTransaction(c);
Mathias Agopian13127d82013-03-05 17:47:11 -08001153 return flags;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001154}
1155
Pablo Ceballos05289c22016-04-14 15:49:55 -07001156void Layer::commitTransaction(const State& stateToCommit) {
1157 mDrawingState = stateToCommit;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001158}
1159
Mathias Agopian13127d82013-03-05 17:47:11 -08001160uint32_t Layer::getTransactionFlags(uint32_t flags) {
1161 return android_atomic_and(~flags, &mTransactionFlags) & flags;
1162}
1163
1164uint32_t Layer::setTransactionFlags(uint32_t flags) {
1165 return android_atomic_or(flags, &mTransactionFlags);
1166}
1167
Robert Carr82364e32016-05-15 11:27:47 -07001168bool Layer::setPosition(float x, float y, bool immediate) {
Robert Carr3dcabfa2016-03-01 18:36:58 -08001169 if (mCurrentState.requested.transform.tx() == x && mCurrentState.requested.transform.ty() == y)
Mathias Agopian13127d82013-03-05 17:47:11 -08001170 return false;
1171 mCurrentState.sequence++;
Robert Carr69663fb2016-03-27 19:59:19 -07001172
1173 // We update the requested and active position simultaneously because
1174 // we want to apply the position portion of the transform matrix immediately,
1175 // but still delay scaling when resizing a SCALING_MODE_FREEZE layer.
Robert Carr3dcabfa2016-03-01 18:36:58 -08001176 mCurrentState.requested.transform.set(x, y);
Robert Carr7bf247e2017-05-18 14:02:49 -07001177 if (immediate && !mFreezeGeometryUpdates) {
1178 // Here we directly update the active state
1179 // unlike other setters, because we store it within
1180 // the transform, but use different latching rules.
1181 // b/38182305
Robert Carr82364e32016-05-15 11:27:47 -07001182 mCurrentState.active.transform.set(x, y);
1183 }
Robert Carr7bf247e2017-05-18 14:02:49 -07001184 mFreezeGeometryUpdates = mFreezeGeometryUpdates || !immediate;
Robert Carr69663fb2016-03-27 19:59:19 -07001185
Dan Stoza7dde5992015-05-22 09:51:44 -07001186 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001187 setTransactionFlags(eTransactionNeeded);
1188 return true;
1189}
Robert Carr82364e32016-05-15 11:27:47 -07001190
Robert Carr1f0a16a2016-10-24 16:27:39 -07001191bool Layer::setChildLayer(const sp<Layer>& childLayer, int32_t z) {
1192 ssize_t idx = mCurrentChildren.indexOf(childLayer);
1193 if (idx < 0) {
1194 return false;
1195 }
1196 if (childLayer->setLayer(z)) {
1197 mCurrentChildren.removeAt(idx);
1198 mCurrentChildren.add(childLayer);
1199 }
1200 return true;
1201}
1202
Robert Carrae060832016-11-28 10:51:00 -08001203bool Layer::setLayer(int32_t z) {
David Sodman41fdfc92017-11-06 16:09:56 -08001204 if (mCurrentState.z == z) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001205 mCurrentState.sequence++;
1206 mCurrentState.z = z;
Dan Stoza7dde5992015-05-22 09:51:44 -07001207 mCurrentState.modified = true;
Robert Carrdb66e622017-04-10 16:55:57 -07001208
1209 // Discard all relative layering.
1210 if (mCurrentState.zOrderRelativeOf != nullptr) {
1211 sp<Layer> strongRelative = mCurrentState.zOrderRelativeOf.promote();
1212 if (strongRelative != nullptr) {
1213 strongRelative->removeZOrderRelative(this);
1214 }
1215 mCurrentState.zOrderRelativeOf = nullptr;
1216 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001217 setTransactionFlags(eTransactionNeeded);
1218 return true;
1219}
Robert Carr1f0a16a2016-10-24 16:27:39 -07001220
Robert Carrdb66e622017-04-10 16:55:57 -07001221void Layer::removeZOrderRelative(const wp<Layer>& relative) {
1222 mCurrentState.zOrderRelatives.remove(relative);
1223 mCurrentState.sequence++;
1224 mCurrentState.modified = true;
1225 setTransactionFlags(eTransactionNeeded);
1226}
1227
1228void Layer::addZOrderRelative(const wp<Layer>& relative) {
1229 mCurrentState.zOrderRelatives.add(relative);
1230 mCurrentState.modified = true;
1231 mCurrentState.sequence++;
1232 setTransactionFlags(eTransactionNeeded);
1233}
1234
1235bool Layer::setRelativeLayer(const sp<IBinder>& relativeToHandle, int32_t z) {
1236 sp<Handle> handle = static_cast<Handle*>(relativeToHandle.get());
1237 if (handle == nullptr) {
1238 return false;
1239 }
1240 sp<Layer> relative = handle->owner.promote();
1241 if (relative == nullptr) {
1242 return false;
1243 }
1244
1245 mCurrentState.sequence++;
1246 mCurrentState.modified = true;
1247 mCurrentState.z = z;
1248
chaviw9ab4bd12017-11-03 13:11:00 -07001249 auto oldZOrderRelativeOf = mCurrentState.zOrderRelativeOf.promote();
1250 if (oldZOrderRelativeOf != nullptr) {
1251 oldZOrderRelativeOf->removeZOrderRelative(this);
1252 }
Robert Carrdb66e622017-04-10 16:55:57 -07001253 mCurrentState.zOrderRelativeOf = relative;
1254 relative->addZOrderRelative(this);
1255
1256 setTransactionFlags(eTransactionNeeded);
1257
1258 return true;
1259}
1260
Mathias Agopian13127d82013-03-05 17:47:11 -08001261bool Layer::setSize(uint32_t w, uint32_t h) {
David Sodman41fdfc92017-11-06 16:09:56 -08001262 if (mCurrentState.requested.w == w && mCurrentState.requested.h == h) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001263 mCurrentState.requested.w = w;
1264 mCurrentState.requested.h = h;
Dan Stoza7dde5992015-05-22 09:51:44 -07001265 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001266 setTransactionFlags(eTransactionNeeded);
1267 return true;
1268}
Dan Stoza9e56aa02015-11-02 13:00:03 -08001269bool Layer::setAlpha(float alpha) {
David Sodman41fdfc92017-11-06 16:09:56 -08001270 if (mCurrentState.color.a == alpha) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001271 mCurrentState.sequence++;
chaviw13fdc492017-06-27 12:40:18 -07001272 mCurrentState.color.a = alpha;
Dan Stoza7dde5992015-05-22 09:51:44 -07001273 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001274 setTransactionFlags(eTransactionNeeded);
1275 return true;
1276}
chaviw13fdc492017-06-27 12:40:18 -07001277
1278bool Layer::setColor(const half3& color) {
David Sodman41fdfc92017-11-06 16:09:56 -08001279 if (color.r == mCurrentState.color.r && color.g == mCurrentState.color.g &&
1280 color.b == mCurrentState.color.b)
chaviw13fdc492017-06-27 12:40:18 -07001281 return false;
1282
1283 mCurrentState.sequence++;
1284 mCurrentState.color.r = color.r;
1285 mCurrentState.color.g = color.g;
1286 mCurrentState.color.b = color.b;
1287 mCurrentState.modified = true;
1288 setTransactionFlags(eTransactionNeeded);
1289 return true;
1290}
1291
Mathias Agopian13127d82013-03-05 17:47:11 -08001292bool Layer::setMatrix(const layer_state_t::matrix22_t& matrix) {
1293 mCurrentState.sequence++;
David Sodman41fdfc92017-11-06 16:09:56 -08001294 mCurrentState.requested.transform.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
Dan Stoza7dde5992015-05-22 09:51:44 -07001295 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001296 setTransactionFlags(eTransactionNeeded);
1297 return true;
1298}
1299bool Layer::setTransparentRegionHint(const Region& transparent) {
Mathias Agopian2ca79392013-04-02 18:30:32 -07001300 mCurrentState.requestedTransparentRegion = transparent;
Dan Stoza7dde5992015-05-22 09:51:44 -07001301 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001302 setTransactionFlags(eTransactionNeeded);
1303 return true;
1304}
1305bool Layer::setFlags(uint8_t flags, uint8_t mask) {
1306 const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask);
David Sodman41fdfc92017-11-06 16:09:56 -08001307 if (mCurrentState.flags == newFlags) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001308 mCurrentState.sequence++;
1309 mCurrentState.flags = newFlags;
Dan Stoza7dde5992015-05-22 09:51:44 -07001310 mCurrentState.mask = mask;
1311 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001312 setTransactionFlags(eTransactionNeeded);
1313 return true;
1314}
Robert Carr99e27f02016-06-16 15:18:02 -07001315
1316bool Layer::setCrop(const Rect& crop, bool immediate) {
David Sodman41fdfc92017-11-06 16:09:56 -08001317 if (mCurrentState.requestedCrop == crop) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001318 mCurrentState.sequence++;
Robert Carr99e27f02016-06-16 15:18:02 -07001319 mCurrentState.requestedCrop = crop;
Robert Carr7bf247e2017-05-18 14:02:49 -07001320 if (immediate && !mFreezeGeometryUpdates) {
Robert Carr99e27f02016-06-16 15:18:02 -07001321 mCurrentState.crop = crop;
1322 }
Robert Carr7bf247e2017-05-18 14:02:49 -07001323 mFreezeGeometryUpdates = mFreezeGeometryUpdates || !immediate;
1324
Dan Stoza7dde5992015-05-22 09:51:44 -07001325 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001326 setTransactionFlags(eTransactionNeeded);
1327 return true;
1328}
Robert Carr8d5227b2017-03-16 15:41:03 -07001329
1330bool Layer::setFinalCrop(const Rect& crop, bool immediate) {
David Sodman41fdfc92017-11-06 16:09:56 -08001331 if (mCurrentState.requestedFinalCrop == crop) return false;
Pablo Ceballosacbe6782016-03-04 17:54:21 +00001332 mCurrentState.sequence++;
Robert Carr8d5227b2017-03-16 15:41:03 -07001333 mCurrentState.requestedFinalCrop = crop;
Robert Carr7bf247e2017-05-18 14:02:49 -07001334 if (immediate && !mFreezeGeometryUpdates) {
Robert Carr8d5227b2017-03-16 15:41:03 -07001335 mCurrentState.finalCrop = crop;
1336 }
Robert Carr7bf247e2017-05-18 14:02:49 -07001337 mFreezeGeometryUpdates = mFreezeGeometryUpdates || !immediate;
1338
Pablo Ceballosacbe6782016-03-04 17:54:21 +00001339 mCurrentState.modified = true;
1340 setTransactionFlags(eTransactionNeeded);
1341 return true;
1342}
Mathias Agopian13127d82013-03-05 17:47:11 -08001343
Robert Carrc3574f72016-03-24 12:19:32 -07001344bool Layer::setOverrideScalingMode(int32_t scalingMode) {
David Sodman41fdfc92017-11-06 16:09:56 -08001345 if (scalingMode == mOverrideScalingMode) return false;
Robert Carrc3574f72016-03-24 12:19:32 -07001346 mOverrideScalingMode = scalingMode;
Robert Carr82364e32016-05-15 11:27:47 -07001347 setTransactionFlags(eTransactionNeeded);
Robert Carrc3574f72016-03-24 12:19:32 -07001348 return true;
1349}
1350
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -05001351void Layer::setInfo(uint32_t type, uint32_t appId) {
David Sodman41fdfc92017-11-06 16:09:56 -08001352 mCurrentState.appId = appId;
1353 mCurrentState.type = type;
1354 mCurrentState.modified = true;
1355 setTransactionFlags(eTransactionNeeded);
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -05001356}
1357
Mathias Agopian13127d82013-03-05 17:47:11 -08001358bool Layer::setLayerStack(uint32_t layerStack) {
David Sodman41fdfc92017-11-06 16:09:56 -08001359 if (mCurrentState.layerStack == layerStack) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001360 mCurrentState.sequence++;
1361 mCurrentState.layerStack = layerStack;
Dan Stoza7dde5992015-05-22 09:51:44 -07001362 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001363 setTransactionFlags(eTransactionNeeded);
1364 return true;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001365}
1366
Courtney Goeltzenleuchterbb09b432016-11-30 13:51:28 -07001367bool Layer::setDataSpace(android_dataspace dataSpace) {
David Sodman41fdfc92017-11-06 16:09:56 -08001368 if (mCurrentState.dataSpace == dataSpace) return false;
Courtney Goeltzenleuchterbb09b432016-11-30 13:51:28 -07001369 mCurrentState.sequence++;
1370 mCurrentState.dataSpace = dataSpace;
1371 mCurrentState.modified = true;
1372 setTransactionFlags(eTransactionNeeded);
1373 return true;
1374}
1375
Courtney Goeltzenleuchter532b2632017-05-05 16:34:38 -06001376android_dataspace Layer::getDataSpace() const {
1377 return mCurrentState.dataSpace;
1378}
1379
Robert Carr1f0a16a2016-10-24 16:27:39 -07001380uint32_t Layer::getLayerStack() const {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001381 auto p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001382 if (p == nullptr) {
1383 return getDrawingState().layerStack;
1384 }
1385 return p->getLayerStack();
1386}
1387
David Sodman41fdfc92017-11-06 16:09:56 -08001388void Layer::deferTransactionUntil(const sp<Layer>& barrierLayer, uint64_t frameNumber) {
Robert Carr0d480722017-01-10 16:42:54 -08001389 mCurrentState.barrierLayer = barrierLayer;
Dan Stoza7dde5992015-05-22 09:51:44 -07001390 mCurrentState.frameNumber = frameNumber;
1391 // We don't set eTransactionNeeded, because just receiving a deferral
1392 // request without any other state updates shouldn't actually induce a delay
1393 mCurrentState.modified = true;
1394 pushPendingState();
Robert Carr0d480722017-01-10 16:42:54 -08001395 mCurrentState.barrierLayer = nullptr;
Dan Stoza792e5292016-02-11 11:43:58 -08001396 mCurrentState.frameNumber = 0;
Dan Stoza7dde5992015-05-22 09:51:44 -07001397 mCurrentState.modified = false;
Robert Carr0d480722017-01-10 16:42:54 -08001398}
1399
David Sodman41fdfc92017-11-06 16:09:56 -08001400void Layer::deferTransactionUntil(const sp<IBinder>& barrierHandle, uint64_t frameNumber) {
Robert Carr0d480722017-01-10 16:42:54 -08001401 sp<Handle> handle = static_cast<Handle*>(barrierHandle.get());
1402 deferTransactionUntil(handle->owner.promote(), frameNumber);
Dan Stoza7dde5992015-05-22 09:51:44 -07001403}
1404
Dan Stozaee44edd2015-03-23 15:50:23 -07001405
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001406// ----------------------------------------------------------------------------
1407// pageflip handling...
1408// ----------------------------------------------------------------------------
1409
Robert Carr1f0a16a2016-10-24 16:27:39 -07001410bool Layer::isHiddenByPolicy() const {
1411 const Layer::State& s(mDrawingState);
Chia-I Wue41dbe62017-06-13 14:10:56 -07001412 const auto& parent = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001413 if (parent != nullptr && parent->isHiddenByPolicy()) {
1414 return true;
1415 }
1416 return s.flags & layer_state_t::eLayerHidden;
1417}
1418
David Sodman41fdfc92017-11-06 16:09:56 -08001419uint32_t Layer::getEffectiveUsage(uint32_t usage) const {
Mathias Agopiana67932f2011-04-20 14:20:59 -07001420 // TODO: should we do something special if mSecure is set?
1421 if (mProtectedByApp) {
1422 // need a hardware-protected path to external video sink
1423 usage |= GraphicBuffer::USAGE_PROTECTED;
Jamie Gennis54cc83e2010-11-02 11:51:32 -07001424 }
Riley Andrews03414a12014-07-01 14:22:59 -07001425 if (mPotentialCursor) {
1426 usage |= GraphicBuffer::USAGE_CURSOR;
1427 }
Jamie Gennis3599bf22011-08-10 11:48:07 -07001428 usage |= GraphicBuffer::USAGE_HW_COMPOSER;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001429 return usage;
Mathias Agopianb5b7f262010-05-07 15:58:44 -07001430}
1431
Mathias Agopian84300952012-11-21 16:02:13 -08001432void Layer::updateTransformHint(const sp<const DisplayDevice>& hw) const {
Mathias Agopiana4583642011-08-23 18:03:18 -07001433 uint32_t orientation = 0;
1434 if (!mFlinger->mDebugDisableTransformHint) {
Mathias Agopian84300952012-11-21 16:02:13 -08001435 // The transform hint is used to improve performance, but we can
1436 // only have a single transform hint, it cannot
Mathias Agopian4fec8732012-06-29 14:12:52 -07001437 // apply to all displays.
Mathias Agopian42977342012-08-05 00:40:46 -07001438 const Transform& planeTransform(hw->getTransform());
Mathias Agopian4fec8732012-06-29 14:12:52 -07001439 orientation = planeTransform.getOrientation();
Mathias Agopiana4583642011-08-23 18:03:18 -07001440 if (orientation & Transform::ROT_INVALID) {
1441 orientation = 0;
1442 }
1443 }
David Sodmaneb085e02017-10-05 18:49:04 -07001444 setTransformHint(orientation);
Mathias Agopiana4583642011-08-23 18:03:18 -07001445}
1446
Mathias Agopian13127d82013-03-05 17:47:11 -08001447// ----------------------------------------------------------------------------
1448// debugging
1449// ----------------------------------------------------------------------------
1450
Kalle Raitaa099a242017-01-11 11:17:29 -08001451LayerDebugInfo Layer::getLayerDebugInfo() const {
1452 LayerDebugInfo info;
1453 const Layer::State& ds = getDrawingState();
1454 info.mName = getName();
chaviw1acbec72017-07-27 15:28:26 -07001455 sp<Layer> parent = getParent();
Kalle Raitaa099a242017-01-11 11:17:29 -08001456 info.mParentName = (parent == nullptr ? std::string("none") : parent->getName().string());
1457 info.mType = String8(getTypeId());
1458 info.mTransparentRegion = ds.activeTransparentRegion;
1459 info.mVisibleRegion = visibleRegion;
1460 info.mSurfaceDamageRegion = surfaceDamageRegion;
1461 info.mLayerStack = getLayerStack();
1462 info.mX = ds.active.transform.tx();
1463 info.mY = ds.active.transform.ty();
1464 info.mZ = ds.z;
1465 info.mWidth = ds.active.w;
1466 info.mHeight = ds.active.h;
1467 info.mCrop = ds.crop;
1468 info.mFinalCrop = ds.finalCrop;
chaviw13fdc492017-06-27 12:40:18 -07001469 info.mColor = ds.color;
Kalle Raitaa099a242017-01-11 11:17:29 -08001470 info.mFlags = ds.flags;
1471 info.mPixelFormat = getPixelFormat();
1472 info.mDataSpace = getDataSpace();
1473 info.mMatrix[0][0] = ds.active.transform[0][0];
1474 info.mMatrix[0][1] = ds.active.transform[0][1];
1475 info.mMatrix[1][0] = ds.active.transform[1][0];
1476 info.mMatrix[1][1] = ds.active.transform[1][1];
1477 {
1478 sp<const GraphicBuffer> activeBuffer = getActiveBuffer();
1479 if (activeBuffer != 0) {
1480 info.mActiveBufferWidth = activeBuffer->getWidth();
1481 info.mActiveBufferHeight = activeBuffer->getHeight();
1482 info.mActiveBufferStride = activeBuffer->getStride();
1483 info.mActiveBufferFormat = activeBuffer->format;
1484 } else {
1485 info.mActiveBufferWidth = 0;
1486 info.mActiveBufferHeight = 0;
1487 info.mActiveBufferStride = 0;
1488 info.mActiveBufferFormat = 0;
1489 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001490 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001491 info.mNumQueuedFrames = getQueuedFrameCount();
1492 info.mRefreshPending = isBufferLatched();
1493 info.mIsOpaque = isOpaque(ds);
1494 info.mContentDirty = contentDirty;
1495 return info;
Mathias Agopian13127d82013-03-05 17:47:11 -08001496}
Fabien Sanglard9d96de42016-10-11 00:15:18 +00001497#ifdef USE_HWC2
Dan Stozae22aec72016-08-01 13:20:59 -07001498void Layer::miniDumpHeader(String8& result) {
1499 result.append("----------------------------------------");
1500 result.append("---------------------------------------\n");
1501 result.append(" Layer name\n");
1502 result.append(" Z | ");
1503 result.append(" Comp Type | ");
1504 result.append(" Disp Frame (LTRB) | ");
1505 result.append(" Source Crop (LTRB)\n");
1506 result.append("----------------------------------------");
1507 result.append("---------------------------------------\n");
1508}
1509
1510void Layer::miniDump(String8& result, int32_t hwcId) const {
1511 if (mHwcLayers.count(hwcId) == 0) {
1512 return;
1513 }
1514
1515 String8 name;
1516 if (mName.length() > 77) {
1517 std::string shortened;
1518 shortened.append(mName.string(), 36);
1519 shortened.append("[...]");
1520 shortened.append(mName.string() + (mName.length() - 36), 36);
1521 name = shortened.c_str();
1522 } else {
1523 name = mName;
1524 }
1525
1526 result.appendFormat(" %s\n", name.string());
1527
1528 const Layer::State& layerState(getDrawingState());
1529 const HWCInfo& hwcInfo = mHwcLayers.at(hwcId);
John Reck8c3b6ac2017-08-24 10:25:42 -07001530 result.appendFormat(" %10d | ", layerState.z);
David Sodman41fdfc92017-11-06 16:09:56 -08001531 result.appendFormat("%10s | ", to_string(getCompositionType(hwcId)).c_str());
Dan Stozae22aec72016-08-01 13:20:59 -07001532 const Rect& frame = hwcInfo.displayFrame;
David Sodman41fdfc92017-11-06 16:09:56 -08001533 result.appendFormat("%4d %4d %4d %4d | ", frame.left, frame.top, frame.right, frame.bottom);
Dan Stoza5a423ea2017-02-16 14:10:39 -08001534 const FloatRect& crop = hwcInfo.sourceCrop;
David Sodman41fdfc92017-11-06 16:09:56 -08001535 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 -07001536
1537 result.append("- - - - - - - - - - - - - - - - - - - - ");
1538 result.append("- - - - - - - - - - - - - - - - - - - -\n");
1539}
Fabien Sanglard9d96de42016-10-11 00:15:18 +00001540#endif
Dan Stozae22aec72016-08-01 13:20:59 -07001541
Svetoslavd85084b2014-03-20 10:28:31 -07001542void Layer::dumpFrameStats(String8& result) const {
1543 mFrameTracker.dumpStats(result);
Mathias Agopian13127d82013-03-05 17:47:11 -08001544}
1545
Svetoslavd85084b2014-03-20 10:28:31 -07001546void Layer::clearFrameStats() {
1547 mFrameTracker.clearStats();
Mathias Agopian13127d82013-03-05 17:47:11 -08001548}
1549
Jamie Gennis6547ff42013-07-16 20:12:42 -07001550void Layer::logFrameStats() {
1551 mFrameTracker.logAndResetStats(mName);
1552}
1553
Svetoslavd85084b2014-03-20 10:28:31 -07001554void Layer::getFrameStats(FrameStats* outStats) const {
1555 mFrameTracker.getStats(outStats);
1556}
1557
Brian Andersond6927fb2016-07-23 23:37:30 -07001558void Layer::dumpFrameEvents(String8& result) {
David Sodman41fdfc92017-11-06 16:09:56 -08001559 result.appendFormat("- Layer %s (%s, %p)\n", getName().string(), getTypeId(), this);
Brian Andersond6927fb2016-07-23 23:37:30 -07001560 Mutex::Autolock lock(mFrameEventHistoryMutex);
1561 mFrameEventHistory.checkFencesForCompletion();
1562 mFrameEventHistory.dump(result);
1563}
Pablo Ceballos40845df2016-01-25 17:41:15 -08001564
Brian Anderson5ea5e592016-12-01 16:54:33 -08001565void Layer::onDisconnect() {
1566 Mutex::Autolock lock(mFrameEventHistoryMutex);
1567 mFrameEventHistory.onDisconnect();
1568}
1569
Brian Anderson3890c392016-07-25 12:48:08 -07001570void Layer::addAndGetFrameTimestamps(const NewFrameEventsEntry* newTimestamps,
David Sodman41fdfc92017-11-06 16:09:56 -08001571 FrameEventHistoryDelta* outDelta) {
Brian Andersond6927fb2016-07-23 23:37:30 -07001572 Mutex::Autolock lock(mFrameEventHistoryMutex);
1573 if (newTimestamps) {
Brian Andersonfbc80ae2017-05-26 16:23:54 -07001574 // If there are any unsignaled fences in the aquire timeline at this
1575 // point, the previously queued frame hasn't been latched yet. Go ahead
1576 // and try to get the signal time here so the syscall is taken out of
1577 // the main thread's critical path.
1578 mAcquireTimeline.updateSignalTimes();
1579 // Push the new fence after updating since it's likely still pending.
Brian Anderson3d4039d2016-09-23 16:31:30 -07001580 mAcquireTimeline.push(newTimestamps->acquireFence);
Brian Andersond6927fb2016-07-23 23:37:30 -07001581 mFrameEventHistory.addQueue(*newTimestamps);
1582 }
1583
Brian Anderson3890c392016-07-25 12:48:08 -07001584 if (outDelta) {
1585 mFrameEventHistory.getAndResetDelta(outDelta);
Brian Andersond6927fb2016-07-23 23:37:30 -07001586 }
Pablo Ceballos40845df2016-01-25 17:41:15 -08001587}
Dan Stozae77c7662016-05-13 11:37:28 -07001588
Chia-I Wu98f1c102017-05-30 14:54:08 -07001589size_t Layer::getChildrenCount() const {
1590 size_t count = 0;
1591 for (const sp<Layer>& child : mCurrentChildren) {
1592 count += 1 + child->getChildrenCount();
1593 }
1594 return count;
1595}
1596
Robert Carr1f0a16a2016-10-24 16:27:39 -07001597void Layer::addChild(const sp<Layer>& layer) {
1598 mCurrentChildren.add(layer);
1599 layer->setParent(this);
1600}
1601
1602ssize_t Layer::removeChild(const sp<Layer>& layer) {
1603 layer->setParent(nullptr);
1604 return mCurrentChildren.remove(layer);
1605}
1606
Robert Carr1db73f62016-12-21 12:58:51 -08001607bool Layer::reparentChildren(const sp<IBinder>& newParentHandle) {
1608 sp<Handle> handle = nullptr;
1609 sp<Layer> newParent = nullptr;
1610 if (newParentHandle == nullptr) {
1611 return false;
1612 }
1613 handle = static_cast<Handle*>(newParentHandle.get());
1614 newParent = handle->owner.promote();
1615 if (newParent == nullptr) {
1616 ALOGE("Unable to promote Layer handle");
1617 return false;
1618 }
1619
1620 for (const sp<Layer>& child : mCurrentChildren) {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001621 newParent->addChild(child);
Robert Carr1db73f62016-12-21 12:58:51 -08001622
1623 sp<Client> client(child->mClientRef.promote());
1624 if (client != nullptr) {
1625 client->setParentLayer(newParent);
1626 }
1627 }
1628 mCurrentChildren.clear();
1629
1630 return true;
1631}
1632
chaviwf1961f72017-09-18 16:41:07 -07001633bool Layer::reparent(const sp<IBinder>& newParentHandle) {
1634 if (newParentHandle == nullptr) {
chaviw06178942017-07-27 10:25:59 -07001635 return false;
1636 }
1637
1638 auto handle = static_cast<Handle*>(newParentHandle.get());
1639 sp<Layer> newParent = handle->owner.promote();
1640 if (newParent == nullptr) {
1641 ALOGE("Unable to promote Layer handle");
1642 return false;
1643 }
1644
chaviwf1961f72017-09-18 16:41:07 -07001645 sp<Layer> parent = getParent();
1646 if (parent != nullptr) {
1647 parent->removeChild(this);
chaviw06178942017-07-27 10:25:59 -07001648 }
chaviwf1961f72017-09-18 16:41:07 -07001649 newParent->addChild(this);
chaviw06178942017-07-27 10:25:59 -07001650
chaviwf1961f72017-09-18 16:41:07 -07001651 sp<Client> client(mClientRef.promote());
chaviw06178942017-07-27 10:25:59 -07001652 sp<Client> newParentClient(newParent->mClientRef.promote());
1653
chaviwf1961f72017-09-18 16:41:07 -07001654 if (client != newParentClient) {
1655 client->setParentLayer(newParent);
chaviw06178942017-07-27 10:25:59 -07001656 }
1657
chaviw06178942017-07-27 10:25:59 -07001658 return true;
1659}
1660
Robert Carr9524cb32017-02-13 11:32:32 -08001661bool Layer::detachChildren() {
Dan Stoza412903f2017-04-27 13:42:17 -07001662 traverseInZOrder(LayerVector::StateSet::Drawing, [this](Layer* child) {
Robert Carr9524cb32017-02-13 11:32:32 -08001663 if (child == this) {
1664 return;
1665 }
1666
chaviw161410b02017-07-27 10:46:08 -07001667 sp<Client> parentClient = mClientRef.promote();
Robert Carr9524cb32017-02-13 11:32:32 -08001668 sp<Client> client(child->mClientRef.promote());
chaviw161410b02017-07-27 10:46:08 -07001669 if (client != nullptr && parentClient != client) {
Robert Carr9524cb32017-02-13 11:32:32 -08001670 client->detachLayer(child);
1671 }
1672 });
1673
1674 return true;
1675}
1676
Robert Carr1f0a16a2016-10-24 16:27:39 -07001677void Layer::setParent(const sp<Layer>& layer) {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001678 mCurrentParent = layer;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001679}
1680
1681void Layer::clearSyncPoints() {
1682 for (const auto& child : mCurrentChildren) {
1683 child->clearSyncPoints();
1684 }
1685
1686 Mutex::Autolock lock(mLocalSyncPointMutex);
1687 for (auto& point : mLocalSyncPoints) {
1688 point->setFrameAvailable();
1689 }
1690 mLocalSyncPoints.clear();
1691}
1692
1693int32_t Layer::getZ() const {
1694 return mDrawingState.z;
1695}
1696
David Sodman41fdfc92017-11-06 16:09:56 -08001697__attribute__((no_sanitize("unsigned-integer-overflow"))) LayerVector Layer::makeTraversalList(
1698 LayerVector::StateSet stateSet) {
Dan Stoza412903f2017-04-27 13:42:17 -07001699 LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid,
1700 "makeTraversalList received invalid stateSet");
1701 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1702 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
1703 const State& state = useDrawing ? mDrawingState : mCurrentState;
1704
1705 if (state.zOrderRelatives.size() == 0) {
1706 return children;
Robert Carrdb66e622017-04-10 16:55:57 -07001707 }
1708 LayerVector traverse;
1709
Dan Stoza412903f2017-04-27 13:42:17 -07001710 for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
Robert Carrdb66e622017-04-10 16:55:57 -07001711 sp<Layer> strongRelative = weakRelative.promote();
1712 if (strongRelative != nullptr) {
1713 traverse.add(strongRelative);
Robert Carrdb66e622017-04-10 16:55:57 -07001714 }
1715 }
1716
Dan Stoza412903f2017-04-27 13:42:17 -07001717 for (const sp<Layer>& child : children) {
Robert Carrdb66e622017-04-10 16:55:57 -07001718 traverse.add(child);
1719 }
1720
1721 return traverse;
1722}
1723
Robert Carr1f0a16a2016-10-24 16:27:39 -07001724/**
Robert Carrdb66e622017-04-10 16:55:57 -07001725 * Negatively signed relatives are before 'this' in Z-order.
Robert Carr1f0a16a2016-10-24 16:27:39 -07001726 */
Dan Stoza412903f2017-04-27 13:42:17 -07001727void Layer::traverseInZOrder(LayerVector::StateSet stateSet, const LayerVector::Visitor& visitor) {
1728 LayerVector list = makeTraversalList(stateSet);
Robert Carrdb66e622017-04-10 16:55:57 -07001729
Robert Carr1f0a16a2016-10-24 16:27:39 -07001730 size_t i = 0;
Robert Carrdb66e622017-04-10 16:55:57 -07001731 for (; i < list.size(); i++) {
1732 const auto& relative = list[i];
1733 if (relative->getZ() >= 0) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001734 break;
Robert Carrdb66e622017-04-10 16:55:57 -07001735 }
Dan Stoza412903f2017-04-27 13:42:17 -07001736 relative->traverseInZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001737 }
Dan Stoza412903f2017-04-27 13:42:17 -07001738 visitor(this);
Robert Carrdb66e622017-04-10 16:55:57 -07001739 for (; i < list.size(); i++) {
1740 const auto& relative = list[i];
Dan Stoza412903f2017-04-27 13:42:17 -07001741 relative->traverseInZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001742 }
1743}
1744
1745/**
Robert Carrdb66e622017-04-10 16:55:57 -07001746 * Positively signed relatives are before 'this' in reverse Z-order.
Robert Carr1f0a16a2016-10-24 16:27:39 -07001747 */
Dan Stoza412903f2017-04-27 13:42:17 -07001748void Layer::traverseInReverseZOrder(LayerVector::StateSet stateSet,
1749 const LayerVector::Visitor& visitor) {
1750 LayerVector list = makeTraversalList(stateSet);
Robert Carrdb66e622017-04-10 16:55:57 -07001751
Robert Carr1f0a16a2016-10-24 16:27:39 -07001752 int32_t i = 0;
Joel Galensonbf324992017-11-06 11:04:12 -08001753 for (i = int32_t(list.size()) - 1; i >= 0; i--) {
Robert Carrdb66e622017-04-10 16:55:57 -07001754 const auto& relative = list[i];
1755 if (relative->getZ() < 0) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001756 break;
1757 }
Dan Stoza412903f2017-04-27 13:42:17 -07001758 relative->traverseInReverseZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001759 }
Dan Stoza412903f2017-04-27 13:42:17 -07001760 visitor(this);
David Sodman41fdfc92017-11-06 16:09:56 -08001761 for (; i >= 0; i--) {
Robert Carrdb66e622017-04-10 16:55:57 -07001762 const auto& relative = list[i];
Dan Stoza412903f2017-04-27 13:42:17 -07001763 relative->traverseInReverseZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001764 }
1765}
1766
chaviwa76b2712017-09-20 12:02:26 -07001767/**
1768 * Traverse only children in z order, ignoring relative layers.
1769 */
1770void Layer::traverseChildrenInZOrder(LayerVector::StateSet stateSet,
1771 const LayerVector::Visitor& visitor) {
1772 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1773 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
1774
1775 size_t i = 0;
1776 for (; i < children.size(); i++) {
1777 const auto& relative = children[i];
1778 if (relative->getZ() >= 0) {
1779 break;
1780 }
1781 relative->traverseChildrenInZOrder(stateSet, visitor);
1782 }
1783 visitor(this);
1784 for (; i < children.size(); i++) {
1785 const auto& relative = children[i];
1786 relative->traverseChildrenInZOrder(stateSet, visitor);
1787 }
1788}
1789
Robert Carr1f0a16a2016-10-24 16:27:39 -07001790Transform Layer::getTransform() const {
1791 Transform t;
Chia-I Wue41dbe62017-06-13 14:10:56 -07001792 const auto& p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001793 if (p != nullptr) {
1794 t = p->getTransform();
Robert Carr9b429f42017-04-17 14:56:57 -07001795
1796 // If the parent is not using NATIVE_WINDOW_SCALING_MODE_FREEZE (e.g.
1797 // it isFixedSize) then there may be additional scaling not accounted
1798 // for in the transform. We need to mirror this scaling in child surfaces
1799 // or we will break the contract where WM can treat child surfaces as
1800 // pixels in the parent surface.
Chia-I Wu0a68b462017-07-18 11:30:05 -07001801 if (p->isFixedSize() && p->mActiveBuffer != nullptr) {
Robert Carr1725eee2017-04-26 18:32:15 -07001802 int bufferWidth;
1803 int bufferHeight;
1804 if ((p->mCurrentTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) == 0) {
1805 bufferWidth = p->mActiveBuffer->getWidth();
1806 bufferHeight = p->mActiveBuffer->getHeight();
1807 } else {
1808 bufferHeight = p->mActiveBuffer->getWidth();
1809 bufferWidth = p->mActiveBuffer->getHeight();
1810 }
David Sodman41fdfc92017-11-06 16:09:56 -08001811 float sx = p->getDrawingState().active.w / static_cast<float>(bufferWidth);
1812 float sy = p->getDrawingState().active.h / static_cast<float>(bufferHeight);
Robert Carr9b429f42017-04-17 14:56:57 -07001813 Transform extraParentScaling;
1814 extraParentScaling.set(sx, 0, 0, sy);
1815 t = t * extraParentScaling;
1816 }
Robert Carr1f0a16a2016-10-24 16:27:39 -07001817 }
1818 return t * getDrawingState().active.transform;
1819}
1820
chaviw13fdc492017-06-27 12:40:18 -07001821half Layer::getAlpha() const {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001822 const auto& p = mDrawingParent.promote();
Robert Carr6452f122017-03-21 10:41:29 -07001823
chaviw13fdc492017-06-27 12:40:18 -07001824 half parentAlpha = (p != nullptr) ? p->getAlpha() : 1.0_hf;
1825 return parentAlpha * getDrawingState().color.a;
Robert Carr6452f122017-03-21 10:41:29 -07001826}
Robert Carr6452f122017-03-21 10:41:29 -07001827
chaviw13fdc492017-06-27 12:40:18 -07001828half4 Layer::getColor() const {
1829 const half4 color(getDrawingState().color);
1830 return half4(color.r, color.g, color.b, getAlpha());
Robert Carr6452f122017-03-21 10:41:29 -07001831}
Robert Carr6452f122017-03-21 10:41:29 -07001832
Robert Carr1f0a16a2016-10-24 16:27:39 -07001833void Layer::commitChildList() {
1834 for (size_t i = 0; i < mCurrentChildren.size(); i++) {
1835 const auto& child = mCurrentChildren[i];
1836 child->commitChildList();
1837 }
1838 mDrawingChildren = mCurrentChildren;
Chia-I Wue41dbe62017-06-13 14:10:56 -07001839 mDrawingParent = mCurrentParent;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001840}
1841
chaviw1d044282017-09-27 12:19:28 -07001842void Layer::writeToProto(LayerProto* layerInfo, LayerVector::StateSet stateSet) {
1843 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1844 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
1845 const State& state = useDrawing ? mDrawingState : mCurrentState;
1846
1847 Transform requestedTransform = state.active.transform;
1848 Transform transform = getTransform();
1849
1850 layerInfo->set_id(sequence);
1851 layerInfo->set_name(getName().c_str());
1852 layerInfo->set_type(String8(getTypeId()));
1853
1854 for (const auto& child : children) {
1855 layerInfo->add_children(child->sequence);
1856 }
1857
1858 for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
1859 sp<Layer> strongRelative = weakRelative.promote();
1860 if (strongRelative != nullptr) {
1861 layerInfo->add_relatives(strongRelative->sequence);
1862 }
1863 }
1864
1865 LayerProtoHelper::writeToProto(state.activeTransparentRegion,
1866 layerInfo->mutable_transparent_region());
1867 LayerProtoHelper::writeToProto(visibleRegion, layerInfo->mutable_visible_region());
1868 LayerProtoHelper::writeToProto(surfaceDamageRegion, layerInfo->mutable_damage_region());
1869
1870 layerInfo->set_layer_stack(getLayerStack());
1871 layerInfo->set_z(state.z);
1872
1873 PositionProto* position = layerInfo->mutable_position();
1874 position->set_x(transform.tx());
1875 position->set_y(transform.ty());
1876
1877 PositionProto* requestedPosition = layerInfo->mutable_requested_position();
1878 requestedPosition->set_x(requestedTransform.tx());
1879 requestedPosition->set_y(requestedTransform.ty());
1880
1881 SizeProto* size = layerInfo->mutable_size();
1882 size->set_w(state.active.w);
1883 size->set_h(state.active.h);
1884
1885 LayerProtoHelper::writeToProto(state.crop, layerInfo->mutable_crop());
1886 LayerProtoHelper::writeToProto(state.finalCrop, layerInfo->mutable_final_crop());
1887
1888 layerInfo->set_is_opaque(isOpaque(state));
1889 layerInfo->set_invalidate(contentDirty);
1890 layerInfo->set_dataspace(dataspaceDetails(getDataSpace()));
1891 layerInfo->set_pixel_format(decodePixelFormat(getPixelFormat()));
1892 LayerProtoHelper::writeToProto(getColor(), layerInfo->mutable_color());
1893 LayerProtoHelper::writeToProto(state.color, layerInfo->mutable_requested_color());
1894 layerInfo->set_flags(state.flags);
1895
1896 LayerProtoHelper::writeToProto(transform, layerInfo->mutable_transform());
1897 LayerProtoHelper::writeToProto(requestedTransform, layerInfo->mutable_requested_transform());
1898
1899 auto parent = getParent();
1900 if (parent != nullptr) {
1901 layerInfo->set_parent(parent->sequence);
1902 }
1903
1904 auto zOrderRelativeOf = state.zOrderRelativeOf.promote();
1905 if (zOrderRelativeOf != nullptr) {
1906 layerInfo->set_z_order_relative_of(zOrderRelativeOf->sequence);
1907 }
1908
1909 auto activeBuffer = getActiveBuffer();
1910 if (activeBuffer != nullptr) {
1911 LayerProtoHelper::writeToProto(activeBuffer, layerInfo->mutable_active_buffer());
1912 }
1913
1914 layerInfo->set_queued_frames(getQueuedFrameCount());
1915 layerInfo->set_refresh_pending(isBufferLatched());
1916}
1917
Mathias Agopian13127d82013-03-05 17:47:11 -08001918// ---------------------------------------------------------------------------
1919
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001920}; // namespace android
Mathias Agopian3f844832013-08-07 21:24:32 -07001921
1922#if defined(__gl_h_)
1923#error "don't include gl/gl.h in this file"
1924#endif
1925
1926#if defined(__gl2_h_)
1927#error "don't include gl2/gl2.h in this file"
1928#endif