blob: 8e7be473a6c53c867514c9048b996abc591f71cc [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>
chaviw4b129c22018-04-09 16:19:43 -070026#include <algorithm>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027
Yiwei Zhang5434a782018-12-05 18:06:32 -080028#include <android-base/stringprintf.h>
29
Mathias Agopiana67932f2011-04-20 14:20:59 -070030#include <cutils/compiler.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070031#include <cutils/native_handle.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070032#include <cutils/properties.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033
34#include <utils/Errors.h>
35#include <utils/Log.h>
Jesse Hall399184a2014-03-03 15:42:54 -080036#include <utils/NativeHandle.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037#include <utils/StopWatch.h>
Jamie Gennis1c8e95c2012-02-23 19:27:23 -080038#include <utils/Trace.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080039
Courtney Goeltzenleuchter36c44dc2017-04-14 09:33:16 -060040#include <ui/DebugUtils.h>
Mathias Agopian3330b202009-10-05 17:07:12 -070041#include <ui/GraphicBuffer.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042#include <ui/PixelFormat.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080043
Dan Stoza6b9454d2014-11-07 16:00:59 -080044#include <gui/BufferItem.h>
Kalle Raitaa099a242017-01-11 11:17:29 -080045#include <gui/LayerDebugInfo.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080046#include <gui/Surface.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080047
Yiwei Zhang60d1a192018-03-07 14:52:28 -080048#include "BufferLayer.h"
Mathias Agopian3e25fd82013-04-22 17:52:16 +020049#include "Colorizer.h"
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070050#include "DisplayDevice.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051#include "Layer.h"
Fabien Sanglard7b1563a2016-10-13 12:05:28 -070052#include "LayerRejecter.h"
Dan Stozab9b08832014-03-13 11:55:57 -070053#include "MonitoredProducer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080054#include "SurfaceFlinger.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080055
Mathias Agopian1b031492012-06-20 17:51:20 -070056#include "DisplayHardware/HWComposer.h"
Yiwei Zhang7e666a52018-11-15 13:33:42 -080057#include "TimeStats/TimeStats.h"
Mathias Agopian1b031492012-06-20 17:51:20 -070058
Peiyong Lincbc184f2018-08-22 13:24:10 -070059#include <renderengine/RenderEngine.h>
Mathias Agopian875d8e12013-06-07 15:35:48 -070060
Dan Stozac5da2712016-07-20 15:38:12 -070061#include <mutex>
chaviw1d044282017-09-27 12:19:28 -070062#include "LayerProtoHelper.h"
Dan Stozac5da2712016-07-20 15:38:12 -070063
David Sodman41fdfc92017-11-06 16:09:56 -080064#define DEBUG_RESIZE 0
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080065
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080066namespace android {
67
Yiwei Zhang5434a782018-12-05 18:06:32 -080068using base::StringAppendF;
69
Lloyd Piquef1c675b2018-09-12 20:45:39 -070070std::atomic<int32_t> Layer::sSequence{1};
Mathias Agopian13127d82013-03-05 17:47:11 -080071
Lloyd Pique42ab75e2018-09-12 20:46:03 -070072Layer::Layer(const LayerCreationArgs& args)
73 : mFlinger(args.flinger),
74 mName(args.name),
75 mClientRef(args.client),
76 mBE{this, args.name.string()} {
Mathias Agopiana67932f2011-04-20 14:20:59 -070077 mCurrentCrop.makeInvalid();
Mathias Agopian4d9b8222013-03-12 17:11:48 -070078
79 uint32_t layerFlags = 0;
Lloyd Pique42ab75e2018-09-12 20:46:03 -070080 if (args.flags & ISurfaceComposerClient::eHidden) layerFlags |= layer_state_t::eLayerHidden;
81 if (args.flags & ISurfaceComposerClient::eOpaque) layerFlags |= layer_state_t::eLayerOpaque;
82 if (args.flags & ISurfaceComposerClient::eSecure) layerFlags |= layer_state_t::eLayerSecure;
Mathias Agopian4d9b8222013-03-12 17:11:48 -070083
Dan Stozaf7ba41a2017-05-10 15:11:11 -070084 mTransactionName = String8("TX - ") + mName;
Mathias Agopian4d9b8222013-03-12 17:11:48 -070085
Lloyd Pique42ab75e2018-09-12 20:46:03 -070086 mCurrentState.active_legacy.w = args.w;
87 mCurrentState.active_legacy.h = args.h;
David Sodman0c69cad2017-08-21 12:12:51 -070088 mCurrentState.flags = layerFlags;
Marissa Wallf58c14b2018-07-24 10:50:43 -070089 mCurrentState.active_legacy.transform.set(0, 0);
90 mCurrentState.crop_legacy.makeInvalid();
Marissa Wallf58c14b2018-07-24 10:50:43 -070091 mCurrentState.requestedCrop_legacy = mCurrentState.crop_legacy;
Mathias Agopian4d9b8222013-03-12 17:11:48 -070092 mCurrentState.z = 0;
chaviw13fdc492017-06-27 12:40:18 -070093 mCurrentState.color.a = 1.0f;
Mathias Agopian4d9b8222013-03-12 17:11:48 -070094 mCurrentState.layerStack = 0;
Mathias Agopian4d9b8222013-03-12 17:11:48 -070095 mCurrentState.sequence = 0;
Marissa Wallf58c14b2018-07-24 10:50:43 -070096 mCurrentState.requested_legacy = mCurrentState.active_legacy;
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -050097 mCurrentState.appId = 0;
98 mCurrentState.type = 0;
Marissa Wall61c58622018-07-18 10:12:20 -070099 mCurrentState.active.w = 0;
100 mCurrentState.active.h = 0;
101 mCurrentState.active.transform.set(0, 0);
102 mCurrentState.transform = 0;
103 mCurrentState.transformToDisplayInverse = false;
104 mCurrentState.crop.makeInvalid();
105 mCurrentState.acquireFence = new Fence(-1);
106 mCurrentState.dataspace = ui::Dataspace::UNKNOWN;
107 mCurrentState.hdrMetadata.validTypes = 0;
108 mCurrentState.surfaceDamageRegion.clear();
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700109 mCurrentState.cornerRadius = 0.0f;
Marissa Wall61c58622018-07-18 10:12:20 -0700110 mCurrentState.api = -1;
Peiyong Lin747321c2018-10-01 10:03:11 -0700111 mCurrentState.hasColorTransform = false;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700112
113 // drawing state & current state are identical
114 mDrawingState = mCurrentState;
Jamie Gennis6547ff42013-07-16 20:12:42 -0700115
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800116 CompositorTiming compositorTiming;
Lloyd Pique42ab75e2018-09-12 20:46:03 -0700117 args.flinger->getCompositorTiming(&compositorTiming);
Brian Anderson0a61b0c2016-12-07 14:55:56 -0800118 mFrameEventHistory.initializeCompositorTiming(compositorTiming);
Jorim Jaggibd6480f2018-08-10 14:37:31 +0200119 mFrameTracker.setDisplayRefreshPeriod(compositorTiming.interval);
Robert Carr2e102c92018-10-23 12:11:15 -0700120
121 mFlinger->onLayerCreated();
Dan Stoza436ccf32018-06-21 12:10:12 -0700122}
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700123
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700124Layer::~Layer() {
David Sodman577c8962017-12-08 14:50:53 -0800125 sp<Client> c(mClientRef.promote());
126 if (c != 0) {
127 c->detachLayer(this);
128 }
129
Jorim Jaggi10c985e2018-10-23 11:17:45 +0000130 mFrameTracker.logAndResetStats(mName);
Robert Carr2e102c92018-10-23 12:11:15 -0700131
chaviw61626f22018-11-15 16:26:27 -0800132 destroyAllHwcLayersPlusChildren();
Robert Carr2e102c92018-10-23 12:11:15 -0700133
134 mFlinger->onLayerDestroyed();
Mathias Agopian96f08192010-06-02 23:28:45 -0700135}
136
Mathias Agopian13127d82013-03-05 17:47:11 -0800137// ---------------------------------------------------------------------------
138// callbacks
139// ---------------------------------------------------------------------------
140
David Sodmaneb085e02017-10-05 18:49:04 -0700141/*
142 * onLayerDisplayed is only meaningful for BufferLayer, but, is called through
143 * Layer. So, the implementation is done in BufferLayer. When called on a
144 * ColorLayer object, it's essentially a NOP.
145 */
David Sodmaneb085e02017-10-05 18:49:04 -0700146void Layer::onLayerDisplayed(const sp<Fence>& /*releaseFence*/) {}
Mathias Agopian13127d82013-03-05 17:47:11 -0800147
Chia-I Wuc6657022017-08-15 11:18:17 -0700148void Layer::onRemovedFromCurrentState() {
Robert Carr2e102c92018-10-23 12:11:15 -0700149 mRemovedFromCurrentState = true;
150
Chia-I Wuc6657022017-08-15 11:18:17 -0700151 // the layer is removed from SF mCurrentState to mLayersPendingRemoval
Robert Carr5edb1ad2017-04-25 10:54:24 -0700152 if (mCurrentState.zOrderRelativeOf != nullptr) {
153 sp<Layer> strongRelative = mCurrentState.zOrderRelativeOf.promote();
154 if (strongRelative != nullptr) {
155 strongRelative->removeZOrderRelative(this);
Chia-I Wuc6657022017-08-15 11:18:17 -0700156 mFlinger->setTransactionFlags(eTraversalNeeded);
Robert Carr5edb1ad2017-04-25 10:54:24 -0700157 }
158 mCurrentState.zOrderRelativeOf = nullptr;
159 }
Rob Carr4bba3702018-10-08 21:53:30 +0000160
Robert Carr2e102c92018-10-23 12:11:15 -0700161 // Since we are no longer reachable from CurrentState SurfaceFlinger
162 // will no longer invoke doTransaction for us, and so we will
163 // never finish applying transactions. We signal the sync point
164 // now so that another layer will not become indefinitely
165 // blocked.
166 for (auto& point: mRemoteSyncPoints) {
167 point->setTransactionApplied();
168 }
169 mRemoteSyncPoints.clear();
170
171 {
172 Mutex::Autolock syncLock(mLocalSyncPointMutex);
173 for (auto& point : mLocalSyncPoints) {
174 point->setFrameAvailable();
175 }
176 mLocalSyncPoints.clear();
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
chaviw61626f22018-11-15 16:26:27 -0800184void Layer::addToCurrentState() {
185 mRemovedFromCurrentState = false;
186
187 for (const auto& child : mCurrentChildren) {
188 child->addToCurrentState();
189 }
190}
191
Mathias Agopian13127d82013-03-05 17:47:11 -0800192// ---------------------------------------------------------------------------
193// set-up
194// ---------------------------------------------------------------------------
195
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700196const String8& Layer::getName() const {
Mathias Agopian13127d82013-03-05 17:47:11 -0800197 return mName;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800198}
199
chaviw13fdc492017-06-27 12:40:18 -0700200bool Layer::getPremultipledAlpha() const {
201 return mPremultipliedAlpha;
202}
203
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700204sp<IBinder> Layer::getHandle() {
Mathias Agopian13127d82013-03-05 17:47:11 -0800205 Mutex::Autolock _l(mLock);
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700206 return new Handle(mFlinger, this);
Mathias Agopian13127d82013-03-05 17:47:11 -0800207}
208
209// ---------------------------------------------------------------------------
210// h/w composer set-up
211// ---------------------------------------------------------------------------
212
Dominik Laskowski075d3172018-05-24 15:50:06 -0700213bool Layer::createHwcLayer(HWComposer* hwc, DisplayId displayId) {
Dominik Laskowski34157762018-10-31 13:07:19 -0700214 LOG_ALWAYS_FATAL_IF(hasHwcLayer(displayId), "Already have a layer for display %s",
215 to_string(displayId).c_str());
David Sodmanb8aaea12017-12-14 15:54:51 -0800216 auto layer = std::shared_ptr<HWC2::Layer>(
217 hwc->createLayer(displayId),
218 [hwc, displayId](HWC2::Layer* layer) {
219 hwc->destroyLayer(displayId, layer); });
Steven Thomasb02664d2017-07-26 18:48:28 -0700220 if (!layer) {
221 return false;
222 }
Dominik Laskowski7e045462018-05-30 13:02:02 -0700223 LayerBE::HWCInfo& hwcInfo = getBE().mHwcLayers[displayId];
Steven Thomasb02664d2017-07-26 18:48:28 -0700224 hwcInfo.hwc = hwc;
225 hwcInfo.layer = layer;
David Sodmanf6a38932018-05-25 15:27:50 -0700226 layer->setLayerDestroyedListener(
Dominik Laskowski7e045462018-05-30 13:02:02 -0700227 [this, displayId](HWC2::Layer* /*layer*/) { getBE().mHwcLayers.erase(displayId); });
Steven Thomasb02664d2017-07-26 18:48:28 -0700228 return true;
229}
230
Dominik Laskowski075d3172018-05-24 15:50:06 -0700231bool Layer::destroyHwcLayer(DisplayId displayId) {
Dominik Laskowski34157762018-10-31 13:07:19 -0700232 if (!hasHwcLayer(displayId)) {
Chia-I Wu83806892017-11-16 10:50:20 -0800233 return false;
Steven Thomasb02664d2017-07-26 18:48:28 -0700234 }
Dominik Laskowski7e045462018-05-30 13:02:02 -0700235 auto& hwcInfo = getBE().mHwcLayers[displayId];
David Sodman41fdfc92017-11-06 16:09:56 -0800236 LOG_ALWAYS_FATAL_IF(hwcInfo.layer == nullptr, "Attempt to destroy null layer");
Steven Thomasb02664d2017-07-26 18:48:28 -0700237 LOG_ALWAYS_FATAL_IF(hwcInfo.hwc == nullptr, "Missing HWComposer");
David Sodmanb8aaea12017-12-14 15:54:51 -0800238 hwcInfo.layer = nullptr;
239
Chia-I Wu83806892017-11-16 10:50:20 -0800240 return true;
Steven Thomasb02664d2017-07-26 18:48:28 -0700241}
242
chaviw61626f22018-11-15 16:26:27 -0800243void Layer::destroyHwcLayersForAllDisplays() {
David Sodman6f65f3e2017-11-03 14:28:09 -0700244 size_t numLayers = getBE().mHwcLayers.size();
Steven Thomasb02664d2017-07-26 18:48:28 -0700245 for (size_t i = 0; i < numLayers; ++i) {
David Sodman6f65f3e2017-11-03 14:28:09 -0700246 LOG_ALWAYS_FATAL_IF(getBE().mHwcLayers.empty(), "destroyAllHwcLayers failed");
247 destroyHwcLayer(getBE().mHwcLayers.begin()->first);
Steven Thomasb02664d2017-07-26 18:48:28 -0700248 }
chaviw61626f22018-11-15 16:26:27 -0800249}
250
251void Layer::destroyAllHwcLayersPlusChildren() {
252 destroyHwcLayersForAllDisplays();
David Sodman6f65f3e2017-11-03 14:28:09 -0700253 LOG_ALWAYS_FATAL_IF(!getBE().mHwcLayers.empty(),
David Sodman41fdfc92017-11-06 16:09:56 -0800254 "All hardware composer layers should have been destroyed");
Robert Carr2e102c92018-10-23 12:11:15 -0700255
256 for (const sp<Layer>& child : mDrawingChildren) {
chaviw61626f22018-11-15 16:26:27 -0800257 child->destroyAllHwcLayersPlusChildren();
Robert Carr2e102c92018-10-23 12:11:15 -0700258 }
Steven Thomasb02664d2017-07-26 18:48:28 -0700259}
Steven Thomasb02664d2017-07-26 18:48:28 -0700260
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800261Rect Layer::getContentCrop() const {
262 // this is the crop rectangle that applies to the buffer
263 // itself (as opposed to the window)
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700264 Rect crop;
265 if (!mCurrentCrop.isEmpty()) {
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800266 // if the buffer crop is defined, we use that
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700267 crop = mCurrentCrop;
Peiyong Lin566a3b42018-01-09 18:22:43 -0800268 } else if (getBE().compositionInfo.mBuffer != nullptr) {
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800269 // otherwise we use the whole buffer
David Sodman0cc69182017-11-17 12:12:07 -0800270 crop = getBE().compositionInfo.mBuffer->getBounds();
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700271 } else {
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800272 // if we don't have a buffer yet, we use an empty/invalid crop
Mathias Agopian4fec8732012-06-29 14:12:52 -0700273 crop.makeInvalid();
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700274 }
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700275 return crop;
276}
277
Mathias Agopianf3e85d42013-05-10 18:01:12 -0700278static Rect reduce(const Rect& win, const Region& exclude) {
279 if (CC_LIKELY(exclude.isEmpty())) {
280 return win;
281 }
282 if (exclude.isRect()) {
283 return win.reduce(exclude.getBounds());
284 }
285 return Region(win).subtract(exclude).getBounds();
286}
287
Dan Stoza80d61162017-12-20 15:57:52 -0800288static FloatRect reduce(const FloatRect& win, const Region& exclude) {
289 if (CC_LIKELY(exclude.isEmpty())) {
290 return win;
291 }
292 // Convert through Rect (by rounding) for lack of FloatRegion
293 return Region(Rect{win}).subtract(exclude).getBounds().toFloatRect();
294}
295
Vishnu Nair60356342018-11-13 13:00:45 -0800296Rect Layer::computeScreenBounds() const {
297 FloatRect bounds = computeBounds();
Peiyong Linefefaac2018-08-17 12:27:51 -0700298 ui::Transform t = getTransform();
Vishnu Nair60356342018-11-13 13:00:45 -0800299 // Transform to screen space.
300 bounds = t.transform(bounds);
301 return Rect{bounds};
Robert Carr1f0a16a2016-10-24 16:27:39 -0700302}
303
Dan Stoza80d61162017-12-20 15:57:52 -0800304FloatRect Layer::computeBounds() const {
Alec Mourib416efd2018-09-06 21:01:59 +0000305 const State& s(getDrawingState());
Marissa Wall61c58622018-07-18 10:12:20 -0700306 return computeBounds(getActiveTransparentRegion(s));
Michael Lentine6c925ed2014-09-26 17:55:01 -0700307}
308
Dan Stoza80d61162017-12-20 15:57:52 -0800309FloatRect Layer::computeBounds(const Region& activeTransparentRegion) const {
Alec Mourib416efd2018-09-06 21:01:59 +0000310 const State& s(getDrawingState());
Vishnu Nair60356342018-11-13 13:00:45 -0800311 Rect bounds = getCroppedBufferSize(s);
312 FloatRect floatBounds = bounds.toFloatRect();
313 if (bounds.isValid()) {
314 // Layer has bounds. Pass in our bounds as a special case. Then pass on to our parents so
315 // that they can clip it.
316 floatBounds = cropChildBounds(floatBounds);
317 } else {
318 // Layer does not have bounds, so we fill to our parent bounds. This is done by getting our
319 // parent bounds and inverting the transform to get the maximum bounds we can have that
320 // will fit within our parent bounds.
321 const auto& p = mDrawingParent.promote();
322 if (p != nullptr) {
323 ui::Transform t = s.active_legacy.transform;
324 // When calculating the parent bounds for purposes of clipping, we don't need to
325 // constrain the parent to its transparent region. The transparent region is an
326 // optimization based on the buffer contents of the layer, but does not affect the
327 // space allocated to it by policy, and thus children should be allowed to extend into
328 // the parent's transparent region.
329 // One of the main uses is a parent window with a child sitting behind the parent
330 // window, marked by a transparent region. When computing the parent bounds from the
331 // parent's perspective we pass in the transparent region to reduce buffer allocation
332 // size. When computing the parent bounds from the child's perspective, we pass in an
333 // empty transparent region in order to extend into the the parent bounds.
334 floatBounds = p->computeBounds(Region());
335 // Transform back to layer space.
336 floatBounds = t.inverse().transform(floatBounds);
337 }
338 }
Robert Carrb5d3d262016-03-25 15:08:13 -0700339
Vishnu Nair60356342018-11-13 13:00:45 -0800340 // Subtract the transparent region and snap to the bounds.
341 return reduce(floatBounds, activeTransparentRegion);
342}
343
344FloatRect Layer::cropChildBounds(const FloatRect& childBounds) const {
345 const State& s(getDrawingState());
346 Rect bounds = getCroppedBufferSize(s);
347 FloatRect croppedBounds = childBounds;
348
349 // If the layer has bounds, then crop the passed in child bounds and pass
350 // it to our parents so they can crop it as well. If the layer has no bounds,
351 // then pass on the child bounds.
352 if (bounds.isValid()) {
353 croppedBounds = croppedBounds.intersect(bounds.toFloatRect());
Mathias Agopian13127d82013-03-05 17:47:11 -0800354 }
Robert Carr1f0a16a2016-10-24 16:27:39 -0700355
Chia-I Wue41dbe62017-06-13 14:10:56 -0700356 const auto& p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700357 if (p != nullptr) {
Vishnu Nair60356342018-11-13 13:00:45 -0800358 // Transform to parent space and allow parent layer to crop the
359 // child bounds as well.
360 ui::Transform t = s.active_legacy.transform;
361 croppedBounds = t.transform(croppedBounds);
362 croppedBounds = p->cropChildBounds(croppedBounds);
363 croppedBounds = t.inverse().transform(croppedBounds);
Robert Carr1f0a16a2016-10-24 16:27:39 -0700364 }
Vishnu Nair60356342018-11-13 13:00:45 -0800365 return croppedBounds;
366}
Robert Carr1f0a16a2016-10-24 16:27:39 -0700367
Vishnu Nair60356342018-11-13 13:00:45 -0800368Rect Layer::getCroppedBufferSize(const State& s) const {
369 Rect size = getBufferSize(s);
370 Rect crop = getCrop(s);
371 if (!crop.isEmpty() && size.isValid()) {
372 size.intersect(crop, &size);
373 } else if (!crop.isEmpty()) {
374 size = crop;
Robert Carr1f0a16a2016-10-24 16:27:39 -0700375 }
Vishnu Nair60356342018-11-13 13:00:45 -0800376 return size;
Mathias Agopian13127d82013-03-05 17:47:11 -0800377}
378
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700379Rect Layer::computeInitialCrop(const sp<const DisplayDevice>& display) const {
Robert Carrb5d3d262016-03-25 15:08:13 -0700380 // the crop is the area of the window that gets cropped, but not
Mathias Agopian13127d82013-03-05 17:47:11 -0800381 // scaled in any ways.
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700382 const State& s(getDrawingState());
Mathias Agopian13127d82013-03-05 17:47:11 -0800383
384 // apply the projection's clipping to the window crop in
385 // layerstack space, and convert-back to layer space.
Mathias Agopian6b442672013-07-09 21:24:52 -0700386 // if there are no window scaling involved, this operation will map to full
387 // pixels in the buffer.
Mathias Agopian0e8f1442013-08-20 21:41:07 -0700388
Vishnu Nairfb5594c2018-11-28 12:38:35 -0800389 FloatRect activeCropFloat = computeBounds();
Peiyong Linefefaac2018-08-17 12:27:51 -0700390 ui::Transform t = getTransform();
Vishnu Nairfb5594c2018-11-28 12:38:35 -0800391 // Transform to screen space.
392 activeCropFloat = t.transform(activeCropFloat);
393 activeCropFloat = activeCropFloat.intersect(display->getViewport().toFloatRect());
394 // Back to layer space to work with the content crop.
395 activeCropFloat = t.inverse().transform(activeCropFloat);
396 // This needs to be here as transform.transform(Rect) computes the
397 // transformed rect and then takes the bounding box of the result before
398 // returning. This means
399 // transform.inverse().transform(transform.transform(Rect)) != Rect
400 // in which case we need to make sure the final rect is clipped to the
401 // display bounds.
402 Rect activeCrop{activeCropFloat};
403 if (!activeCrop.intersect(getBufferSize(s), &activeCrop)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000404 activeCrop.clear();
405 }
Robert Carr1f0a16a2016-10-24 16:27:39 -0700406 return activeCrop;
407}
408
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700409void Layer::setupRoundedCornersCropCoordinates(Rect win,
410 const FloatRect& roundedCornersCrop) const {
411 // Translate win by the rounded corners rect coordinates, to have all values in
412 // layer coordinate space.
413 win.left -= roundedCornersCrop.left;
414 win.right -= roundedCornersCrop.left;
415 win.top -= roundedCornersCrop.top;
416 win.bottom -= roundedCornersCrop.top;
417
418 renderengine::Mesh::VertexArray<vec2> cropCoords(getBE().mMesh.getCropCoordArray<vec2>());
419 cropCoords[0] = vec2(win.left, win.top);
420 cropCoords[1] = vec2(win.left, win.top + win.getHeight());
421 cropCoords[2] = vec2(win.right, win.top + win.getHeight());
422 cropCoords[3] = vec2(win.right, win.top);
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700423}
424
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700425FloatRect Layer::computeCrop(const sp<const DisplayDevice>& display) const {
Robert Carr1f0a16a2016-10-24 16:27:39 -0700426 // the content crop is the area of the content that gets scaled to the
427 // layer's size. This is in buffer space.
Dan Stoza5a423ea2017-02-16 14:10:39 -0800428 FloatRect crop = getContentCrop().toFloatRect();
Robert Carr1f0a16a2016-10-24 16:27:39 -0700429
430 // In addition there is a WM-specified crop we pull from our drawing state.
431 const State& s(getDrawingState());
432
Dominik Laskowskia2edf612018-06-01 13:15:16 -0700433 Rect activeCrop = computeInitialCrop(display);
Vishnu Nairfb5594c2018-11-28 12:38:35 -0800434 Rect bufferSize = getBufferSize(s);
Mathias Agopianf3e85d42013-05-10 18:01:12 -0700435
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000436 // Transform the window crop to match the buffer coordinate system,
437 // which means using the inverse of the current transform set on the
438 // SurfaceFlingerConsumer.
439 uint32_t invTransform = mCurrentTransform;
Robert Carrcae605c2017-03-29 12:10:31 -0700440 if (getTransformToDisplayInverse()) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000441 /*
Pablo Ceballos021623b2016-04-15 17:31:51 -0700442 * the code below applies the primary display's inverse transform to the
443 * buffer
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000444 */
David Sodman41fdfc92017-11-06 16:09:56 -0800445 uint32_t invTransformOrient = DisplayDevice::getPrimaryDisplayOrientationTransform();
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000446 // calculate the inverse transform
447 if (invTransformOrient & NATIVE_WINDOW_TRANSFORM_ROT_90) {
David Sodman41fdfc92017-11-06 16:09:56 -0800448 invTransformOrient ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H;
Mathias Agopian13127d82013-03-05 17:47:11 -0800449 }
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000450 // and apply to the current transform
Peiyong Linefefaac2018-08-17 12:27:51 -0700451 invTransform = (ui::Transform(invTransformOrient) *
452 ui::Transform(invTransform)).getOrientation();
Mathias Agopian13127d82013-03-05 17:47:11 -0800453 }
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000454
Vishnu Nairfb5594c2018-11-28 12:38:35 -0800455 int winWidth = bufferSize.getWidth();
456 int winHeight = bufferSize.getHeight();
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000457 if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
458 // If the activeCrop has been rotate the ends are rotated but not
459 // the space itself so when transforming ends back we can't rely on
460 // a modification of the axes of rotation. To account for this we
461 // need to reorient the inverse rotation in terms of the current
462 // axes of rotation.
463 bool is_h_flipped = (invTransform & NATIVE_WINDOW_TRANSFORM_FLIP_H) != 0;
464 bool is_v_flipped = (invTransform & NATIVE_WINDOW_TRANSFORM_FLIP_V) != 0;
465 if (is_h_flipped == is_v_flipped) {
David Sodman41fdfc92017-11-06 16:09:56 -0800466 invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H;
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000467 }
Vishnu Nairfb5594c2018-11-28 12:38:35 -0800468 std::swap(winWidth, winHeight);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000469 }
Vishnu Nairfb5594c2018-11-28 12:38:35 -0800470 const Rect winCrop =
471 activeCrop.transform(invTransform, bufferSize.getWidth(), bufferSize.getHeight());
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000472
473 // below, crop is intersected with winCrop expressed in crop's coordinate space
David Sodman41fdfc92017-11-06 16:09:56 -0800474 float xScale = crop.getWidth() / float(winWidth);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000475 float yScale = crop.getHeight() / float(winHeight);
476
David Sodman41fdfc92017-11-06 16:09:56 -0800477 float insetL = winCrop.left * xScale;
478 float insetT = winCrop.top * yScale;
479 float insetR = (winWidth - winCrop.right) * xScale;
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000480 float insetB = (winHeight - winCrop.bottom) * yScale;
481
David Sodman41fdfc92017-11-06 16:09:56 -0800482 crop.left += insetL;
483 crop.top += insetT;
484 crop.right -= insetR;
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000485 crop.bottom -= insetB;
486
Mathias Agopian13127d82013-03-05 17:47:11 -0800487 return crop;
488}
489
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700490void Layer::setGeometry(const sp<const DisplayDevice>& display, uint32_t z) {
Dominik Laskowski7e045462018-05-30 13:02:02 -0700491 const auto displayId = display->getId();
Dominik Laskowski075d3172018-05-24 15:50:06 -0700492 LOG_ALWAYS_FATAL_IF(!displayId);
Dominik Laskowski34157762018-10-31 13:07:19 -0700493 RETURN_IF_NO_HWC_LAYER(*displayId);
Dominik Laskowski075d3172018-05-24 15:50:06 -0700494 auto& hwcInfo = getBE().mHwcLayers[*displayId];
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700495
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700496 // enable this layer
Dan Stoza9e56aa02015-11-02 13:00:03 -0800497 hwcInfo.forceClientComposition = false;
498
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700499 if (isSecure() && !display->isSecure()) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800500 hwcInfo.forceClientComposition = true;
501 }
502
David Sodman15094112018-10-11 09:39:37 -0700503 auto& hwcLayer = hwcInfo.layer;
504
Mathias Agopian13127d82013-03-05 17:47:11 -0800505 // this gives us only the "orientation" component of the transform
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700506 const State& s(getDrawingState());
Vishnu Nairfb5594c2018-11-28 12:38:35 -0800507 const int bufferWidth = getBufferSize(s).getWidth();
508 const int bufferHeight = getBufferSize(s).getHeight();
David Revemanecf0fa52017-03-03 11:32:44 -0500509 auto blendMode = HWC2::BlendMode::None;
Robert Carr6452f122017-03-21 10:41:29 -0700510 if (!isOpaque(s) || getAlpha() != 1.0f) {
David Sodman41fdfc92017-11-06 16:09:56 -0800511 blendMode =
512 mPremultipliedAlpha ? HWC2::BlendMode::Premultiplied : HWC2::BlendMode::Coverage;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800513 }
David Sodman15094112018-10-11 09:39:37 -0700514 auto error = hwcLayer->setBlendMode(blendMode);
515 ALOGE_IF(error != HWC2::Error::None,
516 "[%s] Failed to set blend mode %s:"
517 " %s (%d)",
518 mName.string(), to_string(blendMode).c_str(), to_string(error).c_str(),
519 static_cast<int32_t>(error));
David Sodmanba340492018-08-05 21:51:33 -0700520 getBE().compositionInfo.hwc.blendMode = blendMode;
Mathias Agopian13127d82013-03-05 17:47:11 -0800521
522 // apply the layer's transform, followed by the display's global transform
523 // here we're guaranteed that the layer's transform preserves rects
Marissa Wall61c58622018-07-18 10:12:20 -0700524 Region activeTransparentRegion(getActiveTransparentRegion(s));
Peiyong Linefefaac2018-08-17 12:27:51 -0700525 ui::Transform t = getTransform();
Marissa Wall61c58622018-07-18 10:12:20 -0700526 Rect activeCrop = getCrop(s);
527 if (!activeCrop.isEmpty()) {
Robert Carr1f0a16a2016-10-24 16:27:39 -0700528 activeCrop = t.transform(activeCrop);
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700529 if (!activeCrop.intersect(display->getViewport(), &activeCrop)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000530 activeCrop.clear();
531 }
Robert Carr1f0a16a2016-10-24 16:27:39 -0700532 activeCrop = t.inverse().transform(activeCrop, true);
Michael Lentine28ea2172014-11-19 18:32:37 -0800533 // This needs to be here as transform.transform(Rect) computes the
534 // transformed rect and then takes the bounding box of the result before
535 // returning. This means
536 // transform.inverse().transform(transform.transform(Rect)) != Rect
537 // in which case we need to make sure the final rect is clipped to the
538 // display bounds.
Vishnu Nairfb5594c2018-11-28 12:38:35 -0800539 if (!activeCrop.intersect(Rect(bufferWidth, bufferHeight), &activeCrop)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000540 activeCrop.clear();
541 }
Michael Lentine6c925ed2014-09-26 17:55:01 -0700542 // mark regions outside the crop as transparent
Vishnu Nairfb5594c2018-11-28 12:38:35 -0800543 activeTransparentRegion.orSelf(Rect(0, 0, bufferWidth, activeCrop.top));
544 activeTransparentRegion.orSelf(Rect(0, activeCrop.bottom, bufferWidth, bufferHeight));
David Sodman41fdfc92017-11-06 16:09:56 -0800545 activeTransparentRegion.orSelf(Rect(0, activeCrop.top, activeCrop.left, activeCrop.bottom));
546 activeTransparentRegion.orSelf(
Vishnu Nairfb5594c2018-11-28 12:38:35 -0800547 Rect(activeCrop.right, activeCrop.top, bufferWidth, activeCrop.bottom));
Michael Lentine6c925ed2014-09-26 17:55:01 -0700548 }
Robert Carr1f0a16a2016-10-24 16:27:39 -0700549
Dan Stoza80d61162017-12-20 15:57:52 -0800550 // computeBounds returns a FloatRect to provide more accuracy during the
551 // transformation. We then round upon constructing 'frame'.
552 Rect frame{t.transform(computeBounds(activeTransparentRegion))};
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700553 if (!frame.intersect(display->getViewport(), &frame)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000554 frame.clear();
555 }
Peiyong Linefefaac2018-08-17 12:27:51 -0700556 const ui::Transform& tr = display->getTransform();
Dan Stoza9e56aa02015-11-02 13:00:03 -0800557 Rect transformedFrame = tr.transform(frame);
David Sodman15094112018-10-11 09:39:37 -0700558 error = hwcLayer->setDisplayFrame(transformedFrame);
559 if (error != HWC2::Error::None) {
560 ALOGE("[%s] Failed to set display frame [%d, %d, %d, %d]: %s (%d)", mName.string(),
561 transformedFrame.left, transformedFrame.top, transformedFrame.right,
562 transformedFrame.bottom, to_string(error).c_str(), static_cast<int32_t>(error));
563 } else {
564 hwcInfo.displayFrame = transformedFrame;
565 }
David Sodmanba340492018-08-05 21:51:33 -0700566 getBE().compositionInfo.hwc.displayFrame = transformedFrame;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800567
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700568 FloatRect sourceCrop = computeCrop(display);
David Sodman15094112018-10-11 09:39:37 -0700569 error = hwcLayer->setSourceCrop(sourceCrop);
570 if (error != HWC2::Error::None) {
571 ALOGE("[%s] Failed to set source crop [%.3f, %.3f, %.3f, %.3f]: "
572 "%s (%d)",
573 mName.string(), sourceCrop.left, sourceCrop.top, sourceCrop.right, sourceCrop.bottom,
574 to_string(error).c_str(), static_cast<int32_t>(error));
575 } else {
576 hwcInfo.sourceCrop = sourceCrop;
577 }
David Sodmanba340492018-08-05 21:51:33 -0700578 getBE().compositionInfo.hwc.sourceCrop = sourceCrop;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800579
chaviw13fdc492017-06-27 12:40:18 -0700580 float alpha = static_cast<float>(getAlpha());
David Sodman15094112018-10-11 09:39:37 -0700581 error = hwcLayer->setPlaneAlpha(alpha);
582 ALOGE_IF(error != HWC2::Error::None,
583 "[%s] Failed to set plane alpha %.3f: "
584 "%s (%d)",
585 mName.string(), alpha, to_string(error).c_str(), static_cast<int32_t>(error));
David Sodmanba340492018-08-05 21:51:33 -0700586 getBE().compositionInfo.hwc.alpha = alpha;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800587
David Sodman15094112018-10-11 09:39:37 -0700588 error = hwcLayer->setZOrder(z);
589 ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set Z %u: %s (%d)", mName.string(), z,
590 to_string(error).c_str(), static_cast<int32_t>(error));
David Sodmanba340492018-08-05 21:51:33 -0700591 getBE().compositionInfo.hwc.z = z;
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -0500592
Albert Chaulk2a589632017-05-04 16:59:44 -0400593 int type = s.type;
594 int appId = s.appId;
Chia-I Wue41dbe62017-06-13 14:10:56 -0700595 sp<Layer> parent = mDrawingParent.promote();
Albert Chaulk2a589632017-05-04 16:59:44 -0400596 if (parent.get()) {
597 auto& parentState = parent->getDrawingState();
rongliucfb187b2018-03-14 12:26:23 -0700598 if (parentState.type >= 0 || parentState.appId >= 0) {
599 type = parentState.type;
600 appId = parentState.appId;
601 }
Albert Chaulk2a589632017-05-04 16:59:44 -0400602 }
603
David Sodman15094112018-10-11 09:39:37 -0700604 error = hwcLayer->setInfo(type, appId);
605 ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set info (%d)", mName.string(),
606 static_cast<int32_t>(error));
607
David Sodmanba340492018-08-05 21:51:33 -0700608 getBE().compositionInfo.hwc.type = type;
609 getBE().compositionInfo.hwc.appId = appId;
610
Mathias Agopian29a367b2011-07-12 14:51:45 -0700611 /*
612 * Transformations are applied in this order:
613 * 1) buffer orientation/flip/mirror
614 * 2) state transformation (window manager)
615 * 3) layer orientation (screen orientation)
616 * (NOTE: the matrices are multiplied in reverse order)
617 */
618
Peiyong Linefefaac2018-08-17 12:27:51 -0700619 const ui::Transform bufferOrientation(mCurrentTransform);
620 ui::Transform transform(tr * t * bufferOrientation);
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700621
Robert Carrcae605c2017-03-29 12:10:31 -0700622 if (getTransformToDisplayInverse()) {
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700623 /*
Pablo Ceballos021623b2016-04-15 17:31:51 -0700624 * the code below applies the primary display's inverse transform to the
625 * buffer
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700626 */
David Sodman41fdfc92017-11-06 16:09:56 -0800627 uint32_t invTransform = DisplayDevice::getPrimaryDisplayOrientationTransform();
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700628 // calculate the inverse transform
629 if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
David Sodman41fdfc92017-11-06 16:09:56 -0800630 invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V | NATIVE_WINDOW_TRANSFORM_FLIP_H;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700631 }
Robert Carrcae605c2017-03-29 12:10:31 -0700632
633 /*
634 * Here we cancel out the orientation component of the WM transform.
635 * The scaling and translate components are already included in our bounds
636 * computation so it's enough to just omit it in the composition.
637 * See comment in onDraw with ref to b/36727915 for why.
638 */
Peiyong Linefefaac2018-08-17 12:27:51 -0700639 transform = ui::Transform(invTransform) * tr * bufferOrientation;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700640 }
Mathias Agopian29a367b2011-07-12 14:51:45 -0700641
642 // this gives us only the "orientation" component of the transform
Mathias Agopian13127d82013-03-05 17:47:11 -0800643 const uint32_t orientation = transform.getOrientation();
Peiyong Linefefaac2018-08-17 12:27:51 -0700644 if (orientation & ui::Transform::ROT_INVALID) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800645 // we can only handle simple transformation
Lloyd Pique074e8122018-07-26 12:57:23 -0700646 hwcInfo.forceClientComposition = true;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700647 getBE().mHwcLayers[*displayId].compositionType = HWC2::Composition::Client;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800648 } else {
649 auto transform = static_cast<HWC2::Transform>(orientation);
Yiwei Zhang7124ad32018-02-21 13:02:45 -0800650 hwcInfo.transform = transform;
David Sodman15094112018-10-11 09:39:37 -0700651 auto error = hwcLayer->setTransform(transform);
652 ALOGE_IF(error != HWC2::Error::None,
653 "[%s] Failed to set transform %s: "
654 "%s (%d)",
655 mName.string(), to_string(transform).c_str(), to_string(error).c_str(),
656 static_cast<int32_t>(error));
David Sodmanba340492018-08-05 21:51:33 -0700657 getBE().compositionInfo.hwc.transform = transform;
David Sodman4b7c4bc2017-11-17 12:13:59 -0800658 }
659}
660
Dominik Laskowski075d3172018-05-24 15:50:06 -0700661void Layer::forceClientComposition(DisplayId displayId) {
Dominik Laskowski34157762018-10-31 13:07:19 -0700662 RETURN_IF_NO_HWC_LAYER(displayId);
Dominik Laskowski7e045462018-05-30 13:02:02 -0700663 getBE().mHwcLayers[displayId].forceClientComposition = true;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800664}
Dan Stozaee44edd2015-03-23 15:50:23 -0700665
Dominik Laskowski075d3172018-05-24 15:50:06 -0700666bool Layer::getForceClientComposition(DisplayId displayId) {
Dominik Laskowski34157762018-10-31 13:07:19 -0700667 RETURN_IF_NO_HWC_LAYER(displayId, false);
Dominik Laskowski7e045462018-05-30 13:02:02 -0700668 return getBE().mHwcLayers[displayId].forceClientComposition;
chaviwc9232ed2017-11-14 15:31:15 -0800669}
670
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700671void Layer::updateCursorPosition(const sp<const DisplayDevice>& display) {
Dominik Laskowski7e045462018-05-30 13:02:02 -0700672 const auto displayId = display->getId();
Dominik Laskowski34157762018-10-31 13:07:19 -0700673 LOG_ALWAYS_FATAL_IF(!displayId);
674 if (!hasHwcLayer(*displayId) || getCompositionType(displayId) != HWC2::Composition::Cursor) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800675 return;
676 }
677
678 // This gives us only the "orientation" component of the transform
679 const State& s(getCurrentState());
680
681 // Apply the layer's transform, followed by the display's global transform
682 // Here we're guaranteed that the layer's transform preserves rects
Vishnu Nairfb5594c2018-11-28 12:38:35 -0800683 Rect win = getCroppedBufferSize(s);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800684 // Subtract the transparent region and snap to the bounds
Marissa Wall61c58622018-07-18 10:12:20 -0700685 Rect bounds = reduce(win, getActiveTransparentRegion(s));
Robert Carr1f0a16a2016-10-24 16:27:39 -0700686 Rect frame(getTransform().transform(bounds));
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700687 frame.intersect(display->getViewport(), &frame);
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700688 auto& displayTransform = display->getTransform();
Dan Stoza9e56aa02015-11-02 13:00:03 -0800689 auto position = displayTransform.transform(frame);
690
Dominik Laskowski7e045462018-05-30 13:02:02 -0700691 auto error =
Dominik Laskowski075d3172018-05-24 15:50:06 -0700692 getBE().mHwcLayers[*displayId].layer->setCursorPosition(position.left, position.top);
693
David Sodman41fdfc92017-11-06 16:09:56 -0800694 ALOGE_IF(error != HWC2::Error::None,
695 "[%s] Failed to set cursor position "
696 "to (%d, %d): %s (%d)",
697 mName.string(), position.left, position.top, to_string(error).c_str(),
698 static_cast<int32_t>(error));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800699}
Riley Andrews03414a12014-07-01 14:22:59 -0700700
Mathias Agopian13127d82013-03-05 17:47:11 -0800701// ---------------------------------------------------------------------------
702// drawing...
703// ---------------------------------------------------------------------------
704
Marissa Wall61c58622018-07-18 10:12:20 -0700705void Layer::draw(const RenderArea& renderArea, const Region& clip) {
chaviwa76b2712017-09-20 12:02:26 -0700706 onDraw(renderArea, clip, false);
Mathias Agopian13127d82013-03-05 17:47:11 -0800707}
708
Marissa Wall61c58622018-07-18 10:12:20 -0700709void Layer::draw(const RenderArea& renderArea, bool useIdentityTransform) {
chaviwa76b2712017-09-20 12:02:26 -0700710 onDraw(renderArea, Region(renderArea.getBounds()), useIdentityTransform);
Mathias Agopian13127d82013-03-05 17:47:11 -0800711}
712
David Sodman41fdfc92017-11-06 16:09:56 -0800713void Layer::clearWithOpenGL(const RenderArea& renderArea, float red, float green, float blue,
714 float alpha) const {
Lloyd Pique144e1162017-12-20 16:44:52 -0800715 auto& engine(mFlinger->getRenderEngine());
David Sodman9eeae692017-11-02 10:53:32 -0700716 computeGeometry(renderArea, getBE().mMesh, false);
Mathias Agopian19733a32013-08-28 18:13:56 -0700717 engine.setupFillWithColor(red, green, blue, alpha);
David Sodman9eeae692017-11-02 10:53:32 -0700718 engine.drawMesh(getBE().mMesh);
Mathias Agopian13127d82013-03-05 17:47:11 -0800719}
720
David Sodmanc1498e62018-09-12 14:36:26 -0700721void Layer::clearWithOpenGL(const RenderArea& renderArea) const {
722 clearWithOpenGL(renderArea, 0, 0, 0, 0);
723}
724
Dominik Laskowski075d3172018-05-24 15:50:06 -0700725void Layer::setCompositionType(DisplayId displayId, HWC2::Composition type, bool callIntoHwc) {
Dominik Laskowski7e045462018-05-30 13:02:02 -0700726 if (getBE().mHwcLayers.count(displayId) == 0) {
Chia-I Wu30505fb2018-03-26 16:20:31 -0700727 ALOGE("setCompositionType called without a valid HWC layer");
728 return;
David Sodman15094112018-10-11 09:39:37 -0700729 }
730 auto& hwcInfo = getBE().mHwcLayers[displayId];
731 auto& hwcLayer = hwcInfo.layer;
732 ALOGV("setCompositionType(%" PRIx64 ", %s, %d)", (hwcLayer)->getId(), to_string(type).c_str(),
733 static_cast<int>(callIntoHwc));
734 if (hwcInfo.compositionType != type) {
735 ALOGV(" actually setting");
736 hwcInfo.compositionType = type;
737 if (callIntoHwc) {
738 auto error = (hwcLayer)->setCompositionType(type);
739 ALOGE_IF(error != HWC2::Error::None,
740 "[%s] Failed to set "
741 "composition type %s: %s (%d)",
742 mName.string(), to_string(type).c_str(), to_string(error).c_str(),
743 static_cast<int32_t>(error));
Chia-I Wu30505fb2018-03-26 16:20:31 -0700744 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800745 }
746}
747
Dominik Laskowski075d3172018-05-24 15:50:06 -0700748HWC2::Composition Layer::getCompositionType(const std::optional<DisplayId>& displayId) const {
749 if (!displayId) {
Dan Stozaec0f7172016-07-21 11:09:40 -0700750 // If we're querying the composition type for a display that does not
751 // have a HWC counterpart, then it will always be Client
752 return HWC2::Composition::Client;
753 }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700754 if (getBE().mHwcLayers.count(*displayId) == 0) {
755 ALOGE("getCompositionType called with an invalid HWC layer");
756 return HWC2::Composition::Invalid;
757 }
758 return getBE().mHwcLayers.at(*displayId).compositionType;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800759}
760
Dominik Laskowski075d3172018-05-24 15:50:06 -0700761void Layer::setClearClientTarget(DisplayId displayId, bool clear) {
Dominik Laskowski7e045462018-05-30 13:02:02 -0700762 if (getBE().mHwcLayers.count(displayId) == 0) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800763 ALOGE("setClearClientTarget called without a valid HWC layer");
764 return;
765 }
Dominik Laskowski7e045462018-05-30 13:02:02 -0700766 getBE().mHwcLayers[displayId].clearClientTarget = clear;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800767}
768
Dominik Laskowski075d3172018-05-24 15:50:06 -0700769bool Layer::getClearClientTarget(DisplayId displayId) const {
Dominik Laskowski7e045462018-05-30 13:02:02 -0700770 if (getBE().mHwcLayers.count(displayId) == 0) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800771 ALOGE("getClearClientTarget called without a valid HWC layer");
772 return false;
773 }
Dominik Laskowski7e045462018-05-30 13:02:02 -0700774 return getBE().mHwcLayers.at(displayId).clearClientTarget;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800775}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800776
Dan Stozacac35382016-01-27 12:21:06 -0800777bool Layer::addSyncPoint(const std::shared_ptr<SyncPoint>& point) {
778 if (point->getFrameNumber() <= mCurrentFrameNumber) {
779 // Don't bother with a SyncPoint, since we've already latched the
780 // relevant frame
781 return false;
Dan Stoza7dde5992015-05-22 09:51:44 -0700782 }
Robert Carr2e102c92018-10-23 12:11:15 -0700783 if (isRemovedFromCurrentState()) {
784 return false;
785 }
Dan Stoza7dde5992015-05-22 09:51:44 -0700786
Dan Stozacac35382016-01-27 12:21:06 -0800787 Mutex::Autolock lock(mLocalSyncPointMutex);
788 mLocalSyncPoints.push_back(point);
789 return true;
Dan Stoza7dde5992015-05-22 09:51:44 -0700790}
791
Mathias Agopian13127d82013-03-05 17:47:11 -0800792// ----------------------------------------------------------------------------
793// local state
794// ----------------------------------------------------------------------------
795
Peiyong Lin833074a2018-08-28 11:53:54 -0700796void Layer::computeGeometry(const RenderArea& renderArea,
797 renderengine::Mesh& mesh,
chaviwa76b2712017-09-20 12:02:26 -0700798 bool useIdentityTransform) const {
Peiyong Linefefaac2018-08-17 12:27:51 -0700799 const ui::Transform renderAreaTransform(renderArea.getTransform());
Dan Stoza80d61162017-12-20 15:57:52 -0800800 FloatRect win = computeBounds();
Mathias Agopian3f844832013-08-07 21:24:32 -0700801
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000802 vec2 lt = vec2(win.left, win.top);
803 vec2 lb = vec2(win.left, win.bottom);
804 vec2 rb = vec2(win.right, win.bottom);
805 vec2 rt = vec2(win.right, win.top);
806
Peiyong Linefefaac2018-08-17 12:27:51 -0700807 ui::Transform layerTransform = getTransform();
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000808 if (!useIdentityTransform) {
Robert Carr1f0a16a2016-10-24 16:27:39 -0700809 lt = layerTransform.transform(lt);
810 lb = layerTransform.transform(lb);
811 rb = layerTransform.transform(rb);
812 rt = layerTransform.transform(rt);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000813 }
814
Peiyong Lin833074a2018-08-28 11:53:54 -0700815 renderengine::Mesh::VertexArray<vec2> position(mesh.getPositionArray<vec2>());
chaviwa76b2712017-09-20 12:02:26 -0700816 position[0] = renderAreaTransform.transform(lt);
817 position[1] = renderAreaTransform.transform(lb);
818 position[2] = renderAreaTransform.transform(rb);
819 position[3] = renderAreaTransform.transform(rt);
Mathias Agopian13127d82013-03-05 17:47:11 -0800820}
Eric Hassoldac45e6b2011-02-10 14:41:26 -0800821
David Sodman41fdfc92017-11-06 16:09:56 -0800822bool Layer::isSecure() const {
Alec Mourib416efd2018-09-06 21:01:59 +0000823 const State& s(mDrawingState);
Dan Stoza23116082015-06-18 14:58:39 -0700824 return (s.flags & layer_state_t::eLayerSecure);
825}
826
Mathias Agopian13127d82013-03-05 17:47:11 -0800827void Layer::setVisibleRegion(const Region& visibleRegion) {
828 // always called from main thread
829 this->visibleRegion = visibleRegion;
830}
831
832void Layer::setCoveredRegion(const Region& coveredRegion) {
833 // always called from main thread
834 this->coveredRegion = coveredRegion;
835}
836
David Sodman41fdfc92017-11-06 16:09:56 -0800837void Layer::setVisibleNonTransparentRegion(const Region& setVisibleNonTransparentRegion) {
Mathias Agopian13127d82013-03-05 17:47:11 -0800838 // always called from main thread
839 this->visibleNonTransparentRegion = setVisibleNonTransparentRegion;
840}
841
Robert Carre5f4f692018-01-12 13:12:28 -0800842void Layer::clearVisibilityRegions() {
843 visibleRegion.clear();
844 visibleNonTransparentRegion.clear();
845 coveredRegion.clear();
846}
847
Mathias Agopian13127d82013-03-05 17:47:11 -0800848// ----------------------------------------------------------------------------
849// transaction
850// ----------------------------------------------------------------------------
851
Dan Stoza7dde5992015-05-22 09:51:44 -0700852void Layer::pushPendingState() {
853 if (!mCurrentState.modified) {
854 return;
855 }
856
Dan Stoza7dde5992015-05-22 09:51:44 -0700857 // If this transaction is waiting on the receipt of a frame, generate a sync
858 // point and send it to the remote layer.
Robert Carr2e102c92018-10-23 12:11:15 -0700859 // We don't allow installing sync points after we are removed from the current state
860 // as we won't be able to signal our end.
861 if (mCurrentState.barrierLayer_legacy != nullptr && !isRemovedFromCurrentState()) {
Marissa Wallf58c14b2018-07-24 10:50:43 -0700862 sp<Layer> barrierLayer = mCurrentState.barrierLayer_legacy.promote();
Robert Carr0d480722017-01-10 16:42:54 -0800863 if (barrierLayer == nullptr) {
864 ALOGE("[%s] Unable to promote barrier Layer.", mName.string());
Dan Stoza7dde5992015-05-22 09:51:44 -0700865 // If we can't promote the layer we are intended to wait on,
866 // then it is expired or otherwise invalid. Allow this transaction
867 // to be applied as per normal (no synchronization).
Marissa Wallf58c14b2018-07-24 10:50:43 -0700868 mCurrentState.barrierLayer_legacy = nullptr;
Pablo Ceballos3bddd5b2015-11-19 14:39:14 -0800869 } else {
Marissa Wallf58c14b2018-07-24 10:50:43 -0700870 auto syncPoint = std::make_shared<SyncPoint>(mCurrentState.frameNumber_legacy);
Robert Carr0d480722017-01-10 16:42:54 -0800871 if (barrierLayer->addSyncPoint(syncPoint)) {
Dan Stozacac35382016-01-27 12:21:06 -0800872 mRemoteSyncPoints.push_back(std::move(syncPoint));
873 } else {
874 // We already missed the frame we're supposed to synchronize
875 // on, so go ahead and apply the state update
Marissa Wallf58c14b2018-07-24 10:50:43 -0700876 mCurrentState.barrierLayer_legacy = nullptr;
Dan Stozacac35382016-01-27 12:21:06 -0800877 }
Dan Stoza7dde5992015-05-22 09:51:44 -0700878 }
879
Dan Stoza7dde5992015-05-22 09:51:44 -0700880 // Wake us up to check if the frame has been received
881 setTransactionFlags(eTransactionNeeded);
Dan Stozaf5702ff2016-11-02 16:27:47 -0700882 mFlinger->setTransactionFlags(eTraversalNeeded);
Dan Stoza7dde5992015-05-22 09:51:44 -0700883 }
884 mPendingStates.push_back(mCurrentState);
Dan Stozaf7ba41a2017-05-10 15:11:11 -0700885 ATRACE_INT(mTransactionName.string(), mPendingStates.size());
Dan Stoza7dde5992015-05-22 09:51:44 -0700886}
887
Pablo Ceballos05289c22016-04-14 15:49:55 -0700888void Layer::popPendingState(State* stateToCommit) {
Pablo Ceballos05289c22016-04-14 15:49:55 -0700889 *stateToCommit = mPendingStates[0];
Dan Stoza7dde5992015-05-22 09:51:44 -0700890
891 mPendingStates.removeAt(0);
Dan Stozaf7ba41a2017-05-10 15:11:11 -0700892 ATRACE_INT(mTransactionName.string(), mPendingStates.size());
Dan Stoza7dde5992015-05-22 09:51:44 -0700893}
894
Pablo Ceballos05289c22016-04-14 15:49:55 -0700895bool Layer::applyPendingStates(State* stateToCommit) {
Dan Stoza7dde5992015-05-22 09:51:44 -0700896 bool stateUpdateAvailable = false;
897 while (!mPendingStates.empty()) {
Marissa Wallf58c14b2018-07-24 10:50:43 -0700898 if (mPendingStates[0].barrierLayer_legacy != nullptr) {
Dan Stoza7dde5992015-05-22 09:51:44 -0700899 if (mRemoteSyncPoints.empty()) {
900 // If we don't have a sync point for this, apply it anyway. It
901 // will be visually wrong, but it should keep us from getting
902 // into too much trouble.
903 ALOGE("[%s] No local sync point found", mName.string());
Pablo Ceballos05289c22016-04-14 15:49:55 -0700904 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -0700905 stateUpdateAvailable = true;
906 continue;
907 }
908
Marissa Wallf58c14b2018-07-24 10:50:43 -0700909 if (mRemoteSyncPoints.front()->getFrameNumber() !=
910 mPendingStates[0].frameNumber_legacy) {
David Sodman41fdfc92017-11-06 16:09:56 -0800911 ALOGE("[%s] Unexpected sync point frame number found", mName.string());
Dan Stozacac35382016-01-27 12:21:06 -0800912
913 // Signal our end of the sync point and then dispose of it
914 mRemoteSyncPoints.front()->setTransactionApplied();
915 mRemoteSyncPoints.pop_front();
916 continue;
917 }
918
Dan Stoza7dde5992015-05-22 09:51:44 -0700919 if (mRemoteSyncPoints.front()->frameIsAvailable()) {
920 // Apply the state update
Pablo Ceballos05289c22016-04-14 15:49:55 -0700921 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -0700922 stateUpdateAvailable = true;
923
924 // Signal our end of the sync point and then dispose of it
925 mRemoteSyncPoints.front()->setTransactionApplied();
926 mRemoteSyncPoints.pop_front();
Dan Stoza792e5292016-02-11 11:43:58 -0800927 } else {
928 break;
Dan Stoza7dde5992015-05-22 09:51:44 -0700929 }
Dan Stoza7dde5992015-05-22 09:51:44 -0700930 } else {
Pablo Ceballos05289c22016-04-14 15:49:55 -0700931 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -0700932 stateUpdateAvailable = true;
933 }
934 }
935
936 // If we still have pending updates, wake SurfaceFlinger back up and point
937 // it at this layer so we can process them
938 if (!mPendingStates.empty()) {
939 setTransactionFlags(eTransactionNeeded);
940 mFlinger->setTransactionFlags(eTraversalNeeded);
941 }
942
943 mCurrentState.modified = false;
944 return stateUpdateAvailable;
945}
946
Marissa Wall61c58622018-07-18 10:12:20 -0700947uint32_t Layer::doTransactionResize(uint32_t flags, State* stateToCommit) {
Alec Mourib416efd2018-09-06 21:01:59 +0000948 const State& s(getDrawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800949
Marissa Wall61c58622018-07-18 10:12:20 -0700950 const bool sizeChanged = (stateToCommit->requested_legacy.w != s.requested_legacy.w) ||
951 (stateToCommit->requested_legacy.h != s.requested_legacy.h);
Mathias Agopiana138f892010-05-21 17:24:35 -0700952
David Sodmaneb085e02017-10-05 18:49:04 -0700953 if (sizeChanged) {
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700954 // the size changed, we need to ask our client to request a new buffer
Steve Block9d453682011-12-20 16:23:08 +0000955 ALOGD_IF(DEBUG_RESIZE,
David Sodman41fdfc92017-11-06 16:09:56 -0800956 "doTransaction: geometry (layer=%p '%s'), tr=%02x, scalingMode=%d\n"
957 " current={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
958 " requested={ wh={%4u,%4u} }}\n"
959 " drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
960 " requested={ wh={%4u,%4u} }}\n",
Marissa Wallf58c14b2018-07-24 10:50:43 -0700961 this, getName().string(), mCurrentTransform, getEffectiveScalingMode(),
Marissa Wall61c58622018-07-18 10:12:20 -0700962 stateToCommit->active_legacy.w, stateToCommit->active_legacy.h,
963 stateToCommit->crop_legacy.left, stateToCommit->crop_legacy.top,
964 stateToCommit->crop_legacy.right, stateToCommit->crop_legacy.bottom,
965 stateToCommit->crop_legacy.getWidth(), stateToCommit->crop_legacy.getHeight(),
966 stateToCommit->requested_legacy.w, stateToCommit->requested_legacy.h,
Marissa Wallf58c14b2018-07-24 10:50:43 -0700967 s.active_legacy.w, s.active_legacy.h, s.crop_legacy.left, s.crop_legacy.top,
968 s.crop_legacy.right, s.crop_legacy.bottom, s.crop_legacy.getWidth(),
969 s.crop_legacy.getHeight(), s.requested_legacy.w, s.requested_legacy.h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800970 }
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700971
Robert Carre392b552017-09-19 12:16:05 -0700972 // Don't let Layer::doTransaction update the drawing state
973 // if we have a pending resize, unless we are in fixed-size mode.
974 // the drawing state will be updated only once we receive a buffer
975 // with the correct size.
976 //
977 // In particular, we want to make sure the clip (which is part
978 // of the geometry state) is latched together with the size but is
979 // latched immediately when no resizing is involved.
980 //
981 // If a sideband stream is attached, however, we want to skip this
982 // optimization so that transactions aren't missed when a buffer
983 // never arrives
984 //
985 // In the case that we don't have a buffer we ignore other factors
986 // and avoid entering the resizePending state. At a high level the
987 // resizePending state is to avoid applying the state of the new buffer
988 // to the old buffer. However in the state where we don't have an old buffer
989 // there is no such concern but we may still be being used as a parent layer.
Marissa Wall61c58622018-07-18 10:12:20 -0700990 const bool resizePending =
991 ((stateToCommit->requested_legacy.w != stateToCommit->active_legacy.w) ||
992 (stateToCommit->requested_legacy.h != stateToCommit->active_legacy.h)) &&
David Sodman0cc69182017-11-17 12:12:07 -0800993 (getBE().compositionInfo.mBuffer != nullptr);
Mathias Agopian0cd545f2012-06-07 14:18:55 -0700994 if (!isFixedSize()) {
David Sodman0cc69182017-11-17 12:12:07 -0800995 if (resizePending && getBE().compositionInfo.hwc.sidebandStream == nullptr) {
Mathias Agopian0cd545f2012-06-07 14:18:55 -0700996 flags |= eDontUpdateGeometryState;
997 }
998 }
999
Robert Carr7bf247e2017-05-18 14:02:49 -07001000 // Here we apply various requested geometry states, depending on our
1001 // latching configuration. See Layer.h for a detailed discussion of
1002 // how geometry latching is controlled.
1003 if (!(flags & eDontUpdateGeometryState)) {
Alec Mourib416efd2018-09-06 21:01:59 +00001004 State& editCurrentState(getCurrentState());
Robert Carr7bf247e2017-05-18 14:02:49 -07001005
1006 // If mFreezeGeometryUpdates is true we are in the setGeometryAppliesWithResize
1007 // mode, which causes attributes which normally latch regardless of scaling mode,
1008 // to be delayed. We copy the requested state to the active state making sure
1009 // to respect these rules (again see Layer.h for a detailed discussion).
1010 //
1011 // There is an awkward asymmetry in the handling of the crop states in the position
1012 // states, as can be seen below. Largely this arises from position and transform
1013 // being stored in the same data structure while having different latching rules.
1014 // b/38182305
1015 //
Marissa Wall61c58622018-07-18 10:12:20 -07001016 // Careful that "stateToCommit" and editCurrentState may not begin as equivalent due to
Robert Carr7bf247e2017-05-18 14:02:49 -07001017 // applyPendingStates in the presence of deferred transactions.
1018 if (mFreezeGeometryUpdates) {
Marissa Wall61c58622018-07-18 10:12:20 -07001019 float tx = stateToCommit->active_legacy.transform.tx();
1020 float ty = stateToCommit->active_legacy.transform.ty();
1021 stateToCommit->active_legacy = stateToCommit->requested_legacy;
1022 stateToCommit->active_legacy.transform.set(tx, ty);
1023 editCurrentState.active_legacy = stateToCommit->active_legacy;
Robert Carr82364e32016-05-15 11:27:47 -07001024 } else {
Marissa Wallf58c14b2018-07-24 10:50:43 -07001025 editCurrentState.active_legacy = editCurrentState.requested_legacy;
Marissa Wall61c58622018-07-18 10:12:20 -07001026 stateToCommit->active_legacy = stateToCommit->requested_legacy;
Robert Carr82364e32016-05-15 11:27:47 -07001027 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001028 }
1029
Marissa Wall61c58622018-07-18 10:12:20 -07001030 return flags;
1031}
1032
1033uint32_t Layer::doTransaction(uint32_t flags) {
1034 ATRACE_CALL();
1035
chaviw5aedec92018-10-22 10:40:38 -07001036 if (mLayerDetached) {
1037 return 0;
1038 }
1039
Marissa Wall61c58622018-07-18 10:12:20 -07001040 pushPendingState();
Alec Mourib416efd2018-09-06 21:01:59 +00001041 State c = getCurrentState();
Marissa Wall61c58622018-07-18 10:12:20 -07001042 if (!applyPendingStates(&c)) {
1043 return 0;
1044 }
1045
1046 flags = doTransactionResize(flags, &c);
1047
Alec Mourib416efd2018-09-06 21:01:59 +00001048 const State& s(getDrawingState());
Marissa Wall61c58622018-07-18 10:12:20 -07001049
1050 if (getActiveGeometry(c) != getActiveGeometry(s)) {
Mathias Agopian13127d82013-03-05 17:47:11 -08001051 // invalidate and recompute the visible regions if needed
1052 flags |= Layer::eVisibleRegion;
1053 }
1054
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001055 if (c.sequence != s.sequence) {
Mathias Agopian13127d82013-03-05 17:47:11 -08001056 // invalidate and recompute the visible regions if needed
1057 flags |= eVisibleRegion;
1058 this->contentDirty = true;
1059
1060 // we may use linear filtering, if the matrix scales us
Marissa Wall61c58622018-07-18 10:12:20 -07001061 const uint8_t type = getActiveTransform(c).getType();
Peiyong Linefefaac2018-08-17 12:27:51 -07001062 mNeedsFiltering = (!getActiveTransform(c).preserveRects() || type >= ui::Transform::SCALE);
Mathias Agopian13127d82013-03-05 17:47:11 -08001063 }
1064
Dan Stozac8145172016-04-28 16:29:06 -07001065 // If the layer is hidden, signal and clear out all local sync points so
1066 // that transactions for layers depending on this layer's frames becoming
1067 // visible are not blocked
1068 if (c.flags & layer_state_t::eLayerHidden) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001069 clearSyncPoints();
Dan Stozac8145172016-04-28 16:29:06 -07001070 }
1071
Robert Carr720e5062018-07-30 17:45:14 -07001072 if (mCurrentState.inputInfoChanged) {
1073 flags |= eInputInfoChanged;
1074 mCurrentState.inputInfoChanged = false;
1075 }
1076
Mathias Agopian13127d82013-03-05 17:47:11 -08001077 // Commit the transaction
Pablo Ceballos05289c22016-04-14 15:49:55 -07001078 commitTransaction(c);
Marissa Walle2ffb422018-10-12 11:33:52 -07001079 mCurrentState.callbackHandles = {};
Mathias Agopian13127d82013-03-05 17:47:11 -08001080 return flags;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001081}
1082
Pablo Ceballos05289c22016-04-14 15:49:55 -07001083void Layer::commitTransaction(const State& stateToCommit) {
1084 mDrawingState = stateToCommit;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001085}
1086
Mathias Agopian13127d82013-03-05 17:47:11 -08001087uint32_t Layer::getTransactionFlags(uint32_t flags) {
Lloyd Piquef1c675b2018-09-12 20:45:39 -07001088 return mTransactionFlags.fetch_and(~flags) & flags;
Mathias Agopian13127d82013-03-05 17:47:11 -08001089}
1090
1091uint32_t Layer::setTransactionFlags(uint32_t flags) {
Lloyd Piquef1c675b2018-09-12 20:45:39 -07001092 return mTransactionFlags.fetch_or(flags);
Mathias Agopian13127d82013-03-05 17:47:11 -08001093}
1094
Robert Carr82364e32016-05-15 11:27:47 -07001095bool Layer::setPosition(float x, float y, bool immediate) {
Marissa Wallf58c14b2018-07-24 10:50:43 -07001096 if (mCurrentState.requested_legacy.transform.tx() == x &&
1097 mCurrentState.requested_legacy.transform.ty() == y)
Mathias Agopian13127d82013-03-05 17:47:11 -08001098 return false;
1099 mCurrentState.sequence++;
Robert Carr69663fb2016-03-27 19:59:19 -07001100
1101 // We update the requested and active position simultaneously because
1102 // we want to apply the position portion of the transform matrix immediately,
1103 // but still delay scaling when resizing a SCALING_MODE_FREEZE layer.
Marissa Wallf58c14b2018-07-24 10:50:43 -07001104 mCurrentState.requested_legacy.transform.set(x, y);
Robert Carr7bf247e2017-05-18 14:02:49 -07001105 if (immediate && !mFreezeGeometryUpdates) {
1106 // Here we directly update the active state
1107 // unlike other setters, because we store it within
1108 // the transform, but use different latching rules.
1109 // b/38182305
Marissa Wallf58c14b2018-07-24 10:50:43 -07001110 mCurrentState.active_legacy.transform.set(x, y);
Robert Carr82364e32016-05-15 11:27:47 -07001111 }
Robert Carr7bf247e2017-05-18 14:02:49 -07001112 mFreezeGeometryUpdates = mFreezeGeometryUpdates || !immediate;
Robert Carr69663fb2016-03-27 19:59:19 -07001113
Dan Stoza7dde5992015-05-22 09:51:44 -07001114 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001115 setTransactionFlags(eTransactionNeeded);
1116 return true;
1117}
Robert Carr82364e32016-05-15 11:27:47 -07001118
Robert Carr1f0a16a2016-10-24 16:27:39 -07001119bool Layer::setChildLayer(const sp<Layer>& childLayer, int32_t z) {
1120 ssize_t idx = mCurrentChildren.indexOf(childLayer);
1121 if (idx < 0) {
1122 return false;
1123 }
1124 if (childLayer->setLayer(z)) {
1125 mCurrentChildren.removeAt(idx);
1126 mCurrentChildren.add(childLayer);
Robert Carr503d2bd2017-12-04 15:49:47 -08001127 return true;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001128 }
Robert Carr503d2bd2017-12-04 15:49:47 -08001129 return false;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001130}
1131
Robert Carr503c7042017-09-27 15:06:08 -07001132bool Layer::setChildRelativeLayer(const sp<Layer>& childLayer,
1133 const sp<IBinder>& relativeToHandle, int32_t relativeZ) {
1134 ssize_t idx = mCurrentChildren.indexOf(childLayer);
1135 if (idx < 0) {
1136 return false;
1137 }
1138 if (childLayer->setRelativeLayer(relativeToHandle, relativeZ)) {
1139 mCurrentChildren.removeAt(idx);
1140 mCurrentChildren.add(childLayer);
Robert Carr503d2bd2017-12-04 15:49:47 -08001141 return true;
Robert Carr503c7042017-09-27 15:06:08 -07001142 }
Robert Carr503d2bd2017-12-04 15:49:47 -08001143 return false;
Robert Carr503c7042017-09-27 15:06:08 -07001144}
1145
Robert Carrae060832016-11-28 10:51:00 -08001146bool Layer::setLayer(int32_t z) {
Robert Carr503d2bd2017-12-04 15:49:47 -08001147 if (mCurrentState.z == z && !usingRelativeZ(LayerVector::StateSet::Current)) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001148 mCurrentState.sequence++;
1149 mCurrentState.z = z;
Dan Stoza7dde5992015-05-22 09:51:44 -07001150 mCurrentState.modified = true;
Robert Carrdb66e622017-04-10 16:55:57 -07001151
1152 // Discard all relative layering.
1153 if (mCurrentState.zOrderRelativeOf != nullptr) {
1154 sp<Layer> strongRelative = mCurrentState.zOrderRelativeOf.promote();
1155 if (strongRelative != nullptr) {
1156 strongRelative->removeZOrderRelative(this);
1157 }
1158 mCurrentState.zOrderRelativeOf = nullptr;
1159 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001160 setTransactionFlags(eTransactionNeeded);
1161 return true;
1162}
Robert Carr1f0a16a2016-10-24 16:27:39 -07001163
Robert Carrdb66e622017-04-10 16:55:57 -07001164void Layer::removeZOrderRelative(const wp<Layer>& relative) {
1165 mCurrentState.zOrderRelatives.remove(relative);
1166 mCurrentState.sequence++;
1167 mCurrentState.modified = true;
1168 setTransactionFlags(eTransactionNeeded);
1169}
1170
1171void Layer::addZOrderRelative(const wp<Layer>& relative) {
1172 mCurrentState.zOrderRelatives.add(relative);
1173 mCurrentState.modified = true;
1174 mCurrentState.sequence++;
1175 setTransactionFlags(eTransactionNeeded);
1176}
1177
Robert Carr503d2bd2017-12-04 15:49:47 -08001178bool Layer::setRelativeLayer(const sp<IBinder>& relativeToHandle, int32_t relativeZ) {
Robert Carrdb66e622017-04-10 16:55:57 -07001179 sp<Handle> handle = static_cast<Handle*>(relativeToHandle.get());
1180 if (handle == nullptr) {
1181 return false;
1182 }
1183 sp<Layer> relative = handle->owner.promote();
1184 if (relative == nullptr) {
1185 return false;
1186 }
1187
Robert Carr503d2bd2017-12-04 15:49:47 -08001188 if (mCurrentState.z == relativeZ && usingRelativeZ(LayerVector::StateSet::Current) &&
1189 mCurrentState.zOrderRelativeOf == relative) {
1190 return false;
1191 }
1192
Robert Carrdb66e622017-04-10 16:55:57 -07001193 mCurrentState.sequence++;
1194 mCurrentState.modified = true;
Robert Carr503d2bd2017-12-04 15:49:47 -08001195 mCurrentState.z = relativeZ;
Robert Carrdb66e622017-04-10 16:55:57 -07001196
chaviw9ab4bd12017-11-03 13:11:00 -07001197 auto oldZOrderRelativeOf = mCurrentState.zOrderRelativeOf.promote();
1198 if (oldZOrderRelativeOf != nullptr) {
1199 oldZOrderRelativeOf->removeZOrderRelative(this);
1200 }
Robert Carrdb66e622017-04-10 16:55:57 -07001201 mCurrentState.zOrderRelativeOf = relative;
1202 relative->addZOrderRelative(this);
1203
1204 setTransactionFlags(eTransactionNeeded);
1205
1206 return true;
1207}
1208
Mathias Agopian13127d82013-03-05 17:47:11 -08001209bool Layer::setSize(uint32_t w, uint32_t h) {
Marissa Wallf58c14b2018-07-24 10:50:43 -07001210 if (mCurrentState.requested_legacy.w == w && mCurrentState.requested_legacy.h == h)
1211 return false;
1212 mCurrentState.requested_legacy.w = w;
1213 mCurrentState.requested_legacy.h = h;
Dan Stoza7dde5992015-05-22 09:51:44 -07001214 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001215 setTransactionFlags(eTransactionNeeded);
Vishnu Naird01c4432018-08-13 10:38:47 -07001216
1217 // record the new size, from this point on, when the client request
1218 // a buffer, it'll get the new size.
1219 setDefaultBufferSize(mCurrentState.requested_legacy.w, mCurrentState.requested_legacy.h);
Mathias Agopian13127d82013-03-05 17:47:11 -08001220 return true;
1221}
Dan Stoza9e56aa02015-11-02 13:00:03 -08001222bool Layer::setAlpha(float alpha) {
David Sodman41fdfc92017-11-06 16:09:56 -08001223 if (mCurrentState.color.a == alpha) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001224 mCurrentState.sequence++;
chaviw13fdc492017-06-27 12:40:18 -07001225 mCurrentState.color.a = alpha;
Dan Stoza7dde5992015-05-22 09:51:44 -07001226 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001227 setTransactionFlags(eTransactionNeeded);
1228 return true;
1229}
chaviw13fdc492017-06-27 12:40:18 -07001230
1231bool Layer::setColor(const half3& color) {
David Sodman41fdfc92017-11-06 16:09:56 -08001232 if (color.r == mCurrentState.color.r && color.g == mCurrentState.color.g &&
1233 color.b == mCurrentState.color.b)
chaviw13fdc492017-06-27 12:40:18 -07001234 return false;
1235
1236 mCurrentState.sequence++;
1237 mCurrentState.color.r = color.r;
1238 mCurrentState.color.g = color.g;
1239 mCurrentState.color.b = color.b;
1240 mCurrentState.modified = true;
1241 setTransactionFlags(eTransactionNeeded);
1242 return true;
1243}
1244
Lucas Dupin1b6531c2018-07-05 17:18:21 -07001245bool Layer::setCornerRadius(float cornerRadius) {
1246 if (mCurrentState.cornerRadius == cornerRadius)
1247 return false;
1248
1249 mCurrentState.sequence++;
1250 mCurrentState.cornerRadius = cornerRadius;
1251 mCurrentState.modified = true;
1252 setTransactionFlags(eTransactionNeeded);
1253 return true;
1254}
1255
Robert Carrd4ae7f32018-06-07 16:10:57 -07001256bool Layer::setMatrix(const layer_state_t::matrix22_t& matrix,
1257 bool allowNonRectPreservingTransforms) {
Peiyong Linefefaac2018-08-17 12:27:51 -07001258 ui::Transform t;
Robert Carrd4ae7f32018-06-07 16:10:57 -07001259 t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
1260
1261 if (!allowNonRectPreservingTransforms && !t.preserveRects()) {
1262 ALOGW("Attempt to set rotation matrix without permission ACCESS_SURFACE_FLINGER ignored");
1263 return false;
1264 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001265 mCurrentState.sequence++;
Marissa Wallf58c14b2018-07-24 10:50:43 -07001266 mCurrentState.requested_legacy.transform.set(matrix.dsdx, matrix.dtdy, matrix.dtdx,
1267 matrix.dsdy);
Dan Stoza7dde5992015-05-22 09:51:44 -07001268 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001269 setTransactionFlags(eTransactionNeeded);
1270 return true;
1271}
Marissa Wall61c58622018-07-18 10:12:20 -07001272
Mathias Agopian13127d82013-03-05 17:47:11 -08001273bool Layer::setTransparentRegionHint(const Region& transparent) {
Marissa Wallf58c14b2018-07-24 10:50:43 -07001274 mCurrentState.requestedTransparentRegion_legacy = transparent;
Dan Stoza7dde5992015-05-22 09:51:44 -07001275 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001276 setTransactionFlags(eTransactionNeeded);
1277 return true;
1278}
1279bool Layer::setFlags(uint8_t flags, uint8_t mask) {
1280 const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask);
David Sodman41fdfc92017-11-06 16:09:56 -08001281 if (mCurrentState.flags == newFlags) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001282 mCurrentState.sequence++;
1283 mCurrentState.flags = newFlags;
Dan Stoza7dde5992015-05-22 09:51:44 -07001284 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001285 setTransactionFlags(eTransactionNeeded);
1286 return true;
1287}
Robert Carr99e27f02016-06-16 15:18:02 -07001288
Marissa Wallf58c14b2018-07-24 10:50:43 -07001289bool Layer::setCrop_legacy(const Rect& crop, bool immediate) {
1290 if (mCurrentState.requestedCrop_legacy == crop) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001291 mCurrentState.sequence++;
Marissa Wallf58c14b2018-07-24 10:50:43 -07001292 mCurrentState.requestedCrop_legacy = crop;
Robert Carr7bf247e2017-05-18 14:02:49 -07001293 if (immediate && !mFreezeGeometryUpdates) {
Marissa Wallf58c14b2018-07-24 10:50:43 -07001294 mCurrentState.crop_legacy = crop;
Robert Carr99e27f02016-06-16 15:18:02 -07001295 }
Robert Carr7bf247e2017-05-18 14:02:49 -07001296 mFreezeGeometryUpdates = mFreezeGeometryUpdates || !immediate;
1297
Dan Stoza7dde5992015-05-22 09:51:44 -07001298 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001299 setTransactionFlags(eTransactionNeeded);
1300 return true;
1301}
Robert Carr8d5227b2017-03-16 15:41:03 -07001302
Robert Carrc3574f72016-03-24 12:19:32 -07001303bool Layer::setOverrideScalingMode(int32_t scalingMode) {
David Sodman41fdfc92017-11-06 16:09:56 -08001304 if (scalingMode == mOverrideScalingMode) return false;
Robert Carrc3574f72016-03-24 12:19:32 -07001305 mOverrideScalingMode = scalingMode;
Robert Carr82364e32016-05-15 11:27:47 -07001306 setTransactionFlags(eTransactionNeeded);
Robert Carrc3574f72016-03-24 12:19:32 -07001307 return true;
1308}
1309
rongliucfb187b2018-03-14 12:26:23 -07001310void Layer::setInfo(int32_t type, int32_t appId) {
David Sodman41fdfc92017-11-06 16:09:56 -08001311 mCurrentState.appId = appId;
1312 mCurrentState.type = type;
1313 mCurrentState.modified = true;
1314 setTransactionFlags(eTransactionNeeded);
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -05001315}
1316
Mathias Agopian13127d82013-03-05 17:47:11 -08001317bool Layer::setLayerStack(uint32_t layerStack) {
David Sodman41fdfc92017-11-06 16:09:56 -08001318 if (mCurrentState.layerStack == layerStack) return false;
Mathias Agopian13127d82013-03-05 17:47:11 -08001319 mCurrentState.sequence++;
1320 mCurrentState.layerStack = layerStack;
Dan Stoza7dde5992015-05-22 09:51:44 -07001321 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001322 setTransactionFlags(eTransactionNeeded);
1323 return true;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001324}
1325
Robert Carr1f0a16a2016-10-24 16:27:39 -07001326uint32_t Layer::getLayerStack() const {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001327 auto p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001328 if (p == nullptr) {
1329 return getDrawingState().layerStack;
1330 }
1331 return p->getLayerStack();
1332}
1333
Marissa Wallf58c14b2018-07-24 10:50:43 -07001334void Layer::deferTransactionUntil_legacy(const sp<Layer>& barrierLayer, uint64_t frameNumber) {
1335 mCurrentState.barrierLayer_legacy = barrierLayer;
1336 mCurrentState.frameNumber_legacy = frameNumber;
Dan Stoza7dde5992015-05-22 09:51:44 -07001337 // We don't set eTransactionNeeded, because just receiving a deferral
1338 // request without any other state updates shouldn't actually induce a delay
1339 mCurrentState.modified = true;
1340 pushPendingState();
Marissa Wallf58c14b2018-07-24 10:50:43 -07001341 mCurrentState.barrierLayer_legacy = nullptr;
1342 mCurrentState.frameNumber_legacy = 0;
Dan Stoza7dde5992015-05-22 09:51:44 -07001343 mCurrentState.modified = false;
Robert Carr0d480722017-01-10 16:42:54 -08001344}
1345
Marissa Wallf58c14b2018-07-24 10:50:43 -07001346void Layer::deferTransactionUntil_legacy(const sp<IBinder>& barrierHandle, uint64_t frameNumber) {
Robert Carr0d480722017-01-10 16:42:54 -08001347 sp<Handle> handle = static_cast<Handle*>(barrierHandle.get());
Marissa Wallf58c14b2018-07-24 10:50:43 -07001348 deferTransactionUntil_legacy(handle->owner.promote(), frameNumber);
Dan Stoza7dde5992015-05-22 09:51:44 -07001349}
1350
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001351// ----------------------------------------------------------------------------
1352// pageflip handling...
1353// ----------------------------------------------------------------------------
1354
Robert Carr1f0a16a2016-10-24 16:27:39 -07001355bool Layer::isHiddenByPolicy() const {
Alec Mourib416efd2018-09-06 21:01:59 +00001356 const State& s(mDrawingState);
Chia-I Wue41dbe62017-06-13 14:10:56 -07001357 const auto& parent = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001358 if (parent != nullptr && parent->isHiddenByPolicy()) {
1359 return true;
1360 }
1361 return s.flags & layer_state_t::eLayerHidden;
1362}
1363
David Sodman41fdfc92017-11-06 16:09:56 -08001364uint32_t Layer::getEffectiveUsage(uint32_t usage) const {
Mathias Agopiana67932f2011-04-20 14:20:59 -07001365 // TODO: should we do something special if mSecure is set?
1366 if (mProtectedByApp) {
1367 // need a hardware-protected path to external video sink
1368 usage |= GraphicBuffer::USAGE_PROTECTED;
Jamie Gennis54cc83e2010-11-02 11:51:32 -07001369 }
Riley Andrews03414a12014-07-01 14:22:59 -07001370 if (mPotentialCursor) {
1371 usage |= GraphicBuffer::USAGE_CURSOR;
1372 }
Jamie Gennis3599bf22011-08-10 11:48:07 -07001373 usage |= GraphicBuffer::USAGE_HW_COMPOSER;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001374 return usage;
Mathias Agopianb5b7f262010-05-07 15:58:44 -07001375}
1376
Dominik Laskowskia2edf612018-06-01 13:15:16 -07001377void Layer::updateTransformHint(const sp<const DisplayDevice>& display) const {
Mathias Agopiana4583642011-08-23 18:03:18 -07001378 uint32_t orientation = 0;
Vishnu Nairf2deb822018-11-12 17:53:48 -08001379 // Disable setting transform hint if the debug flag is set or if the
1380 // getTransformToDisplayInverse flag is set and the client wants to submit buffers
1381 // in one orientation.
1382 if (!mFlinger->mDebugDisableTransformHint && !getTransformToDisplayInverse()) {
Mathias Agopian84300952012-11-21 16:02:13 -08001383 // The transform hint is used to improve performance, but we can
1384 // only have a single transform hint, it cannot
Mathias Agopian4fec8732012-06-29 14:12:52 -07001385 // apply to all displays.
Peiyong Linefefaac2018-08-17 12:27:51 -07001386 const ui::Transform& planeTransform = display->getTransform();
Mathias Agopian4fec8732012-06-29 14:12:52 -07001387 orientation = planeTransform.getOrientation();
Peiyong Linefefaac2018-08-17 12:27:51 -07001388 if (orientation & ui::Transform::ROT_INVALID) {
Mathias Agopiana4583642011-08-23 18:03:18 -07001389 orientation = 0;
1390 }
1391 }
David Sodmaneb085e02017-10-05 18:49:04 -07001392 setTransformHint(orientation);
Mathias Agopiana4583642011-08-23 18:03:18 -07001393}
1394
Mathias Agopian13127d82013-03-05 17:47:11 -08001395// ----------------------------------------------------------------------------
1396// debugging
1397// ----------------------------------------------------------------------------
1398
Marissa Wall61c58622018-07-18 10:12:20 -07001399// TODO(marissaw): add new layer state info to layer debugging
Kalle Raitaa099a242017-01-11 11:17:29 -08001400LayerDebugInfo Layer::getLayerDebugInfo() const {
1401 LayerDebugInfo info;
Alec Mourib416efd2018-09-06 21:01:59 +00001402 const State& ds = getDrawingState();
Kalle Raitaa099a242017-01-11 11:17:29 -08001403 info.mName = getName();
chaviw1acbec72017-07-27 15:28:26 -07001404 sp<Layer> parent = getParent();
Kalle Raitaa099a242017-01-11 11:17:29 -08001405 info.mParentName = (parent == nullptr ? std::string("none") : parent->getName().string());
Yiwei Zhang5434a782018-12-05 18:06:32 -08001406 info.mType = std::string(getTypeId());
Marissa Wallf58c14b2018-07-24 10:50:43 -07001407 info.mTransparentRegion = ds.activeTransparentRegion_legacy;
Kalle Raitaa099a242017-01-11 11:17:29 -08001408 info.mVisibleRegion = visibleRegion;
1409 info.mSurfaceDamageRegion = surfaceDamageRegion;
1410 info.mLayerStack = getLayerStack();
Marissa Wallf58c14b2018-07-24 10:50:43 -07001411 info.mX = ds.active_legacy.transform.tx();
1412 info.mY = ds.active_legacy.transform.ty();
Kalle Raitaa099a242017-01-11 11:17:29 -08001413 info.mZ = ds.z;
Marissa Wallf58c14b2018-07-24 10:50:43 -07001414 info.mWidth = ds.active_legacy.w;
1415 info.mHeight = ds.active_legacy.h;
1416 info.mCrop = ds.crop_legacy;
chaviw13fdc492017-06-27 12:40:18 -07001417 info.mColor = ds.color;
Kalle Raitaa099a242017-01-11 11:17:29 -08001418 info.mFlags = ds.flags;
1419 info.mPixelFormat = getPixelFormat();
Chia-I Wu01591c92018-05-22 12:03:00 -07001420 info.mDataSpace = static_cast<android_dataspace>(mCurrentDataSpace);
Marissa Wallf58c14b2018-07-24 10:50:43 -07001421 info.mMatrix[0][0] = ds.active_legacy.transform[0][0];
1422 info.mMatrix[0][1] = ds.active_legacy.transform[0][1];
1423 info.mMatrix[1][0] = ds.active_legacy.transform[1][0];
1424 info.mMatrix[1][1] = ds.active_legacy.transform[1][1];
Kalle Raitaa099a242017-01-11 11:17:29 -08001425 {
David Sodman0cf8f8d2017-12-20 18:19:45 -08001426 sp<const GraphicBuffer> buffer = mActiveBuffer;
David Sodman5b4cffc2017-11-23 13:20:29 -08001427 if (buffer != 0) {
1428 info.mActiveBufferWidth = buffer->getWidth();
1429 info.mActiveBufferHeight = buffer->getHeight();
1430 info.mActiveBufferStride = buffer->getStride();
1431 info.mActiveBufferFormat = buffer->format;
Kalle Raitaa099a242017-01-11 11:17:29 -08001432 } else {
1433 info.mActiveBufferWidth = 0;
1434 info.mActiveBufferHeight = 0;
1435 info.mActiveBufferStride = 0;
1436 info.mActiveBufferFormat = 0;
1437 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001438 }
Kalle Raitaa099a242017-01-11 11:17:29 -08001439 info.mNumQueuedFrames = getQueuedFrameCount();
1440 info.mRefreshPending = isBufferLatched();
1441 info.mIsOpaque = isOpaque(ds);
1442 info.mContentDirty = contentDirty;
1443 return info;
Mathias Agopian13127d82013-03-05 17:47:11 -08001444}
Chia-I Wu83ce7c12017-10-19 15:18:55 -07001445
Yiwei Zhang5434a782018-12-05 18:06:32 -08001446void Layer::miniDumpHeader(std::string& result) {
Yichi Chen6ca35192018-05-29 12:20:43 +08001447 result.append("-------------------------------");
1448 result.append("-------------------------------");
1449 result.append("-----------------------------\n");
Dan Stozae22aec72016-08-01 13:20:59 -07001450 result.append(" Layer name\n");
1451 result.append(" Z | ");
1452 result.append(" Comp Type | ");
Yichi Chen6ca35192018-05-29 12:20:43 +08001453 result.append(" Transform | ");
Dan Stozae22aec72016-08-01 13:20:59 -07001454 result.append(" Disp Frame (LTRB) | ");
1455 result.append(" Source Crop (LTRB)\n");
Yichi Chen6ca35192018-05-29 12:20:43 +08001456 result.append("-------------------------------");
1457 result.append("-------------------------------");
1458 result.append("-----------------------------\n");
Dan Stozae22aec72016-08-01 13:20:59 -07001459}
1460
Yiwei Zhang5434a782018-12-05 18:06:32 -08001461void Layer::miniDump(std::string& result, DisplayId displayId) const {
Dominik Laskowski34157762018-10-31 13:07:19 -07001462 if (!hasHwcLayer(displayId)) {
Dan Stozae22aec72016-08-01 13:20:59 -07001463 return;
1464 }
1465
Yiwei Zhang5434a782018-12-05 18:06:32 -08001466 std::string name;
Dan Stozae22aec72016-08-01 13:20:59 -07001467 if (mName.length() > 77) {
1468 std::string shortened;
1469 shortened.append(mName.string(), 36);
1470 shortened.append("[...]");
1471 shortened.append(mName.string() + (mName.length() - 36), 36);
Yiwei Zhang5434a782018-12-05 18:06:32 -08001472 name = shortened;
Dan Stozae22aec72016-08-01 13:20:59 -07001473 } else {
Yiwei Zhang5434a782018-12-05 18:06:32 -08001474 name = std::string(mName.string(), mName.size());
Dan Stozae22aec72016-08-01 13:20:59 -07001475 }
1476
Yiwei Zhang5434a782018-12-05 18:06:32 -08001477 StringAppendF(&result, " %s\n", name.c_str());
Dan Stozae22aec72016-08-01 13:20:59 -07001478
Alec Mourib416efd2018-09-06 21:01:59 +00001479 const State& layerState(getDrawingState());
Lloyd Pique074e8122018-07-26 12:57:23 -07001480 const LayerBE::HWCInfo& hwcInfo = getBE().mHwcLayers.at(displayId);
Chia-I Wu1e043612018-03-01 09:45:09 -08001481 if (layerState.zOrderRelativeOf != nullptr || mDrawingParent != nullptr) {
Yiwei Zhang5434a782018-12-05 18:06:32 -08001482 StringAppendF(&result, " rel %6d | ", layerState.z);
Chia-I Wu1e043612018-03-01 09:45:09 -08001483 } else {
Yiwei Zhang5434a782018-12-05 18:06:32 -08001484 StringAppendF(&result, " %10d | ", layerState.z);
Chia-I Wu1e043612018-03-01 09:45:09 -08001485 }
Yiwei Zhang5434a782018-12-05 18:06:32 -08001486 StringAppendF(&result, "%10s | ", to_string(getCompositionType(displayId)).c_str());
1487 StringAppendF(&result, "%10s | ", to_string(hwcInfo.transform).c_str());
Lloyd Pique074e8122018-07-26 12:57:23 -07001488 const Rect& frame = hwcInfo.displayFrame;
Yiwei Zhang5434a782018-12-05 18:06:32 -08001489 StringAppendF(&result, "%4d %4d %4d %4d | ", frame.left, frame.top, frame.right, frame.bottom);
Lloyd Pique074e8122018-07-26 12:57:23 -07001490 const FloatRect& crop = hwcInfo.sourceCrop;
Yiwei Zhang5434a782018-12-05 18:06:32 -08001491 StringAppendF(&result, "%6.1f %6.1f %6.1f %6.1f\n", crop.left, crop.top, crop.right,
1492 crop.bottom);
Dan Stozae22aec72016-08-01 13:20:59 -07001493
David Sodman7e4ae112018-02-09 15:02:28 -08001494 result.append("- - - - - - - - - - - - - - - -\n");
1495
1496 std::string compositionInfoStr;
1497 getBE().compositionInfo.dump(compositionInfoStr, "compositionInfo");
Yiwei Zhang5434a782018-12-05 18:06:32 -08001498 result.append(compositionInfoStr);
David Sodman7e4ae112018-02-09 15:02:28 -08001499
Yichi Chen6ca35192018-05-29 12:20:43 +08001500 result.append("- - - - - - - - - - - - - - - -");
1501 result.append("- - - - - - - - - - - - - - - -");
1502 result.append("- - - - - - - - - - - - - - -\n");
Dan Stozae22aec72016-08-01 13:20:59 -07001503}
Dan Stozae22aec72016-08-01 13:20:59 -07001504
Yiwei Zhang5434a782018-12-05 18:06:32 -08001505void Layer::dumpFrameStats(std::string& result) const {
Svetoslavd85084b2014-03-20 10:28:31 -07001506 mFrameTracker.dumpStats(result);
Mathias Agopian13127d82013-03-05 17:47:11 -08001507}
1508
Svetoslavd85084b2014-03-20 10:28:31 -07001509void Layer::clearFrameStats() {
1510 mFrameTracker.clearStats();
Mathias Agopian13127d82013-03-05 17:47:11 -08001511}
1512
Jamie Gennis6547ff42013-07-16 20:12:42 -07001513void Layer::logFrameStats() {
1514 mFrameTracker.logAndResetStats(mName);
1515}
1516
Svetoslavd85084b2014-03-20 10:28:31 -07001517void Layer::getFrameStats(FrameStats* outStats) const {
1518 mFrameTracker.getStats(outStats);
1519}
1520
Yiwei Zhang5434a782018-12-05 18:06:32 -08001521void Layer::dumpFrameEvents(std::string& result) {
1522 StringAppendF(&result, "- Layer %s (%s, %p)\n", getName().string(), getTypeId(), this);
Brian Andersond6927fb2016-07-23 23:37:30 -07001523 Mutex::Autolock lock(mFrameEventHistoryMutex);
1524 mFrameEventHistory.checkFencesForCompletion();
1525 mFrameEventHistory.dump(result);
1526}
Pablo Ceballos40845df2016-01-25 17:41:15 -08001527
Brian Anderson5ea5e592016-12-01 16:54:33 -08001528void Layer::onDisconnect() {
1529 Mutex::Autolock lock(mFrameEventHistoryMutex);
1530 mFrameEventHistory.onDisconnect();
Yiwei Zhangaf8ee942018-11-22 00:15:23 -08001531 mFlinger->mTimeStats->onDestroy(getSequence());
Brian Anderson5ea5e592016-12-01 16:54:33 -08001532}
1533
Brian Anderson3890c392016-07-25 12:48:08 -07001534void Layer::addAndGetFrameTimestamps(const NewFrameEventsEntry* newTimestamps,
David Sodman41fdfc92017-11-06 16:09:56 -08001535 FrameEventHistoryDelta* outDelta) {
Yiwei Zhangfaf3ded2018-05-02 17:37:17 -07001536 if (newTimestamps) {
Yiwei Zhang7e666a52018-11-15 13:33:42 -08001537 mFlinger->mTimeStats->setPostTime(getSequence(), newTimestamps->frameNumber,
1538 getName().c_str(), newTimestamps->postedTime);
Yiwei Zhangfaf3ded2018-05-02 17:37:17 -07001539 }
1540
Brian Andersond6927fb2016-07-23 23:37:30 -07001541 Mutex::Autolock lock(mFrameEventHistoryMutex);
1542 if (newTimestamps) {
Brian Andersonfbc80ae2017-05-26 16:23:54 -07001543 // If there are any unsignaled fences in the aquire timeline at this
1544 // point, the previously queued frame hasn't been latched yet. Go ahead
1545 // and try to get the signal time here so the syscall is taken out of
1546 // the main thread's critical path.
1547 mAcquireTimeline.updateSignalTimes();
1548 // Push the new fence after updating since it's likely still pending.
Brian Anderson3d4039d2016-09-23 16:31:30 -07001549 mAcquireTimeline.push(newTimestamps->acquireFence);
Brian Andersond6927fb2016-07-23 23:37:30 -07001550 mFrameEventHistory.addQueue(*newTimestamps);
1551 }
1552
Brian Anderson3890c392016-07-25 12:48:08 -07001553 if (outDelta) {
1554 mFrameEventHistory.getAndResetDelta(outDelta);
Brian Andersond6927fb2016-07-23 23:37:30 -07001555 }
Pablo Ceballos40845df2016-01-25 17:41:15 -08001556}
Dan Stozae77c7662016-05-13 11:37:28 -07001557
Chia-I Wu98f1c102017-05-30 14:54:08 -07001558size_t Layer::getChildrenCount() const {
1559 size_t count = 0;
1560 for (const sp<Layer>& child : mCurrentChildren) {
1561 count += 1 + child->getChildrenCount();
1562 }
1563 return count;
1564}
1565
Robert Carr1f0a16a2016-10-24 16:27:39 -07001566void Layer::addChild(const sp<Layer>& layer) {
1567 mCurrentChildren.add(layer);
1568 layer->setParent(this);
1569}
1570
1571ssize_t Layer::removeChild(const sp<Layer>& layer) {
1572 layer->setParent(nullptr);
1573 return mCurrentChildren.remove(layer);
1574}
1575
Robert Carr1db73f62016-12-21 12:58:51 -08001576bool Layer::reparentChildren(const sp<IBinder>& newParentHandle) {
1577 sp<Handle> handle = nullptr;
1578 sp<Layer> newParent = nullptr;
1579 if (newParentHandle == nullptr) {
1580 return false;
1581 }
1582 handle = static_cast<Handle*>(newParentHandle.get());
1583 newParent = handle->owner.promote();
1584 if (newParent == nullptr) {
1585 ALOGE("Unable to promote Layer handle");
1586 return false;
1587 }
1588
chaviw5aedec92018-10-22 10:40:38 -07001589 if (attachChildren()) {
1590 setTransactionFlags(eTransactionNeeded);
1591 }
Robert Carr1db73f62016-12-21 12:58:51 -08001592 for (const sp<Layer>& child : mCurrentChildren) {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001593 newParent->addChild(child);
Robert Carr1db73f62016-12-21 12:58:51 -08001594
1595 sp<Client> client(child->mClientRef.promote());
1596 if (client != nullptr) {
Robert Carr94c7d3d2018-04-24 12:30:47 -07001597 client->updateParent(newParent);
Robert Carr1db73f62016-12-21 12:58:51 -08001598 }
1599 }
1600 mCurrentChildren.clear();
1601
1602 return true;
1603}
1604
Robert Carr15eae092018-03-23 13:43:53 -07001605void Layer::setChildrenDrawingParent(const sp<Layer>& newParent) {
Robert Carr578038f2018-03-09 12:25:24 -08001606 for (const sp<Layer>& child : mDrawingChildren) {
1607 child->mDrawingParent = newParent;
1608 }
1609}
1610
chaviwf1961f72017-09-18 16:41:07 -07001611bool Layer::reparent(const sp<IBinder>& newParentHandle) {
1612 if (newParentHandle == nullptr) {
chaviw06178942017-07-27 10:25:59 -07001613 return false;
1614 }
1615
1616 auto handle = static_cast<Handle*>(newParentHandle.get());
1617 sp<Layer> newParent = handle->owner.promote();
1618 if (newParent == nullptr) {
1619 ALOGE("Unable to promote Layer handle");
1620 return false;
1621 }
1622
chaviwf1961f72017-09-18 16:41:07 -07001623 sp<Layer> parent = getParent();
1624 if (parent != nullptr) {
1625 parent->removeChild(this);
chaviw06178942017-07-27 10:25:59 -07001626 }
chaviwf1961f72017-09-18 16:41:07 -07001627 newParent->addChild(this);
chaviw06178942017-07-27 10:25:59 -07001628
chaviw61626f22018-11-15 16:26:27 -08001629 if (!newParent->isRemovedFromCurrentState()) {
1630 addToCurrentState();
1631 }
1632
chaviwf1961f72017-09-18 16:41:07 -07001633 sp<Client> client(mClientRef.promote());
chaviw06178942017-07-27 10:25:59 -07001634 sp<Client> newParentClient(newParent->mClientRef.promote());
1635
chaviwf1961f72017-09-18 16:41:07 -07001636 if (client != newParentClient) {
Robert Carr94c7d3d2018-04-24 12:30:47 -07001637 client->updateParent(newParent);
chaviw06178942017-07-27 10:25:59 -07001638 }
1639
chaviw5aedec92018-10-22 10:40:38 -07001640 if (mLayerDetached) {
1641 mLayerDetached = false;
1642 setTransactionFlags(eTransactionNeeded);
1643 }
1644 if (attachChildren()) {
1645 setTransactionFlags(eTransactionNeeded);
1646 }
chaviw06178942017-07-27 10:25:59 -07001647 return true;
1648}
1649
Robert Carr9524cb32017-02-13 11:32:32 -08001650bool Layer::detachChildren() {
Robert Carr7f619b22017-11-06 12:56:35 -08001651 for (const sp<Layer>& child : mCurrentChildren) {
chaviw161410b02017-07-27 10:46:08 -07001652 sp<Client> parentClient = mClientRef.promote();
Robert Carr9524cb32017-02-13 11:32:32 -08001653 sp<Client> client(child->mClientRef.promote());
chaviw161410b02017-07-27 10:46:08 -07001654 if (client != nullptr && parentClient != client) {
chaviw5aedec92018-10-22 10:40:38 -07001655 child->mLayerDetached = true;
Robert Carr7f619b22017-11-06 12:56:35 -08001656 child->detachChildren();
Robert Carr9524cb32017-02-13 11:32:32 -08001657 }
Robert Carr7f619b22017-11-06 12:56:35 -08001658 }
Robert Carr9524cb32017-02-13 11:32:32 -08001659
1660 return true;
1661}
1662
chaviw5aedec92018-10-22 10:40:38 -07001663bool Layer::attachChildren() {
1664 bool changed = false;
1665 for (const sp<Layer>& child : mCurrentChildren) {
1666 sp<Client> parentClient = mClientRef.promote();
1667 sp<Client> client(child->mClientRef.promote());
1668 if (client != nullptr && parentClient != client) {
1669 if (child->mLayerDetached) {
1670 child->mLayerDetached = false;
1671 changed = true;
1672 }
1673 changed |= child->attachChildren();
1674 }
1675 }
1676
1677 return changed;
1678}
1679
Peiyong Lind3788632018-09-18 16:01:31 -07001680bool Layer::setColorTransform(const mat4& matrix) {
Peiyong Lin747321c2018-10-01 10:03:11 -07001681 static const mat4 identityMatrix = mat4();
1682
Peiyong Lind3788632018-09-18 16:01:31 -07001683 if (mCurrentState.colorTransform == matrix) {
1684 return false;
1685 }
1686 ++mCurrentState.sequence;
1687 mCurrentState.colorTransform = matrix;
Peiyong Lin747321c2018-10-01 10:03:11 -07001688 mCurrentState.hasColorTransform = matrix != identityMatrix;
1689 mCurrentState.modified = true;
Peiyong Lind3788632018-09-18 16:01:31 -07001690 setTransactionFlags(eTransactionNeeded);
1691 return true;
1692}
1693
chaviwf66724d2018-11-28 16:35:21 -08001694mat4 Layer::getColorTransform() const {
1695 mat4 colorTransform = mat4(getDrawingState().colorTransform);
1696 if (sp<Layer> parent = mDrawingParent.promote(); parent != nullptr) {
1697 colorTransform = parent->getColorTransform() * colorTransform;
1698 }
1699 return colorTransform;
Peiyong Lind3788632018-09-18 16:01:31 -07001700}
1701
1702bool Layer::hasColorTransform() const {
chaviwf66724d2018-11-28 16:35:21 -08001703 bool hasColorTransform = getDrawingState().hasColorTransform;
1704 if (sp<Layer> parent = mDrawingParent.promote(); parent != nullptr) {
1705 hasColorTransform = hasColorTransform || parent->hasColorTransform();
1706 }
1707 return hasColorTransform;
Peiyong Lind3788632018-09-18 16:01:31 -07001708}
1709
Chia-I Wu11481472018-05-04 10:43:19 -07001710bool Layer::isLegacyDataSpace() const {
1711 // return true when no higher bits are set
Chia-I Wu01591c92018-05-22 12:03:00 -07001712 return !(mCurrentDataSpace & (ui::Dataspace::STANDARD_MASK |
Chia-I Wu11481472018-05-04 10:43:19 -07001713 ui::Dataspace::TRANSFER_MASK | ui::Dataspace::RANGE_MASK));
Peiyong Lindd9b2ae2018-03-01 16:22:45 -08001714}
1715
Robert Carr1f0a16a2016-10-24 16:27:39 -07001716void Layer::setParent(const sp<Layer>& layer) {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001717 mCurrentParent = layer;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001718}
1719
1720void Layer::clearSyncPoints() {
1721 for (const auto& child : mCurrentChildren) {
1722 child->clearSyncPoints();
1723 }
1724
1725 Mutex::Autolock lock(mLocalSyncPointMutex);
1726 for (auto& point : mLocalSyncPoints) {
1727 point->setFrameAvailable();
1728 }
1729 mLocalSyncPoints.clear();
1730}
1731
1732int32_t Layer::getZ() const {
1733 return mDrawingState.z;
1734}
1735
Robert Carr29abff82017-12-04 13:51:20 -08001736bool Layer::usingRelativeZ(LayerVector::StateSet stateSet) {
1737 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1738 const State& state = useDrawing ? mDrawingState : mCurrentState;
1739 return state.zOrderRelativeOf != nullptr;
1740}
1741
David Sodman41fdfc92017-11-06 16:09:56 -08001742__attribute__((no_sanitize("unsigned-integer-overflow"))) LayerVector Layer::makeTraversalList(
Robert Carr29abff82017-12-04 13:51:20 -08001743 LayerVector::StateSet stateSet, bool* outSkipRelativeZUsers) {
Dan Stoza412903f2017-04-27 13:42:17 -07001744 LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid,
1745 "makeTraversalList received invalid stateSet");
1746 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1747 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
1748 const State& state = useDrawing ? mDrawingState : mCurrentState;
1749
Robert Carr29abff82017-12-04 13:51:20 -08001750 if (state.zOrderRelatives.size() == 0) {
1751 *outSkipRelativeZUsers = true;
1752 return children;
1753 }
1754
chaviwfd462612018-05-31 16:11:27 -07001755 LayerVector traverse(stateSet);
Dan Stoza412903f2017-04-27 13:42:17 -07001756 for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
Robert Carrdb66e622017-04-10 16:55:57 -07001757 sp<Layer> strongRelative = weakRelative.promote();
1758 if (strongRelative != nullptr) {
1759 traverse.add(strongRelative);
Robert Carrdb66e622017-04-10 16:55:57 -07001760 }
1761 }
1762
Dan Stoza412903f2017-04-27 13:42:17 -07001763 for (const sp<Layer>& child : children) {
Robert Carr503c7042017-09-27 15:06:08 -07001764 const State& childState = useDrawing ? child->mDrawingState : child->mCurrentState;
1765 if (childState.zOrderRelativeOf != nullptr) {
1766 continue;
1767 }
Robert Carrdb66e622017-04-10 16:55:57 -07001768 traverse.add(child);
1769 }
1770
1771 return traverse;
1772}
1773
Robert Carr1f0a16a2016-10-24 16:27:39 -07001774/**
Robert Carrdb66e622017-04-10 16:55:57 -07001775 * Negatively signed relatives are before 'this' in Z-order.
Robert Carr1f0a16a2016-10-24 16:27:39 -07001776 */
Dan Stoza412903f2017-04-27 13:42:17 -07001777void Layer::traverseInZOrder(LayerVector::StateSet stateSet, const LayerVector::Visitor& visitor) {
Robert Carr29abff82017-12-04 13:51:20 -08001778 // In the case we have other layers who are using a relative Z to us, makeTraversalList will
1779 // produce a new list for traversing, including our relatives, and not including our children
1780 // who are relatives of another surface. In the case that there are no relative Z,
1781 // makeTraversalList returns our children directly to avoid significant overhead.
1782 // However in this case we need to take the responsibility for filtering children which
1783 // are relatives of another surface here.
1784 bool skipRelativeZUsers = false;
1785 const LayerVector list = makeTraversalList(stateSet, &skipRelativeZUsers);
Robert Carrdb66e622017-04-10 16:55:57 -07001786
Robert Carr1f0a16a2016-10-24 16:27:39 -07001787 size_t i = 0;
Robert Carrdb66e622017-04-10 16:55:57 -07001788 for (; i < list.size(); i++) {
1789 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001790 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1791 continue;
1792 }
1793
Robert Carrdb66e622017-04-10 16:55:57 -07001794 if (relative->getZ() >= 0) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001795 break;
Robert Carrdb66e622017-04-10 16:55:57 -07001796 }
Dan Stoza412903f2017-04-27 13:42:17 -07001797 relative->traverseInZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001798 }
Robert Carr29abff82017-12-04 13:51:20 -08001799
Dan Stoza412903f2017-04-27 13:42:17 -07001800 visitor(this);
Robert Carrdb66e622017-04-10 16:55:57 -07001801 for (; i < list.size(); i++) {
1802 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001803
1804 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1805 continue;
1806 }
Dan Stoza412903f2017-04-27 13:42:17 -07001807 relative->traverseInZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001808 }
1809}
1810
1811/**
Robert Carrdb66e622017-04-10 16:55:57 -07001812 * Positively signed relatives are before 'this' in reverse Z-order.
Robert Carr1f0a16a2016-10-24 16:27:39 -07001813 */
Dan Stoza412903f2017-04-27 13:42:17 -07001814void Layer::traverseInReverseZOrder(LayerVector::StateSet stateSet,
1815 const LayerVector::Visitor& visitor) {
Robert Carr29abff82017-12-04 13:51:20 -08001816 // See traverseInZOrder for documentation.
1817 bool skipRelativeZUsers = false;
1818 LayerVector list = makeTraversalList(stateSet, &skipRelativeZUsers);
Robert Carrdb66e622017-04-10 16:55:57 -07001819
Robert Carr1f0a16a2016-10-24 16:27:39 -07001820 int32_t i = 0;
Joel Galensonbf324992017-11-06 11:04:12 -08001821 for (i = int32_t(list.size()) - 1; i >= 0; i--) {
Robert Carrdb66e622017-04-10 16:55:57 -07001822 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001823
1824 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1825 continue;
1826 }
1827
Robert Carrdb66e622017-04-10 16:55:57 -07001828 if (relative->getZ() < 0) {
Robert Carr1f0a16a2016-10-24 16:27:39 -07001829 break;
1830 }
Dan Stoza412903f2017-04-27 13:42:17 -07001831 relative->traverseInReverseZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001832 }
Dan Stoza412903f2017-04-27 13:42:17 -07001833 visitor(this);
David Sodman41fdfc92017-11-06 16:09:56 -08001834 for (; i >= 0; i--) {
Robert Carrdb66e622017-04-10 16:55:57 -07001835 const auto& relative = list[i];
Robert Carr29abff82017-12-04 13:51:20 -08001836
1837 if (skipRelativeZUsers && relative->usingRelativeZ(stateSet)) {
1838 continue;
1839 }
1840
Dan Stoza412903f2017-04-27 13:42:17 -07001841 relative->traverseInReverseZOrder(stateSet, visitor);
Robert Carr1f0a16a2016-10-24 16:27:39 -07001842 }
1843}
1844
chaviw4b129c22018-04-09 16:19:43 -07001845LayerVector Layer::makeChildrenTraversalList(LayerVector::StateSet stateSet,
1846 const std::vector<Layer*>& layersInTree) {
1847 LOG_ALWAYS_FATAL_IF(stateSet == LayerVector::StateSet::Invalid,
1848 "makeTraversalList received invalid stateSet");
chaviwa76b2712017-09-20 12:02:26 -07001849 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1850 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
chaviw4b129c22018-04-09 16:19:43 -07001851 const State& state = useDrawing ? mDrawingState : mCurrentState;
1852
chaviwfd462612018-05-31 16:11:27 -07001853 LayerVector traverse(stateSet);
chaviw4b129c22018-04-09 16:19:43 -07001854 for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
1855 sp<Layer> strongRelative = weakRelative.promote();
1856 // Only add relative layers that are also descendents of the top most parent of the tree.
1857 // If a relative layer is not a descendent, then it should be ignored.
1858 if (std::binary_search(layersInTree.begin(), layersInTree.end(), strongRelative.get())) {
1859 traverse.add(strongRelative);
1860 }
1861 }
1862
1863 for (const sp<Layer>& child : children) {
1864 const State& childState = useDrawing ? child->mDrawingState : child->mCurrentState;
1865 // If a layer has a relativeOf layer, only ignore if the layer it's relative to is a
1866 // descendent of the top most parent of the tree. If it's not a descendent, then just add
1867 // the child here since it won't be added later as a relative.
1868 if (std::binary_search(layersInTree.begin(), layersInTree.end(),
1869 childState.zOrderRelativeOf.promote().get())) {
1870 continue;
1871 }
1872 traverse.add(child);
1873 }
1874
1875 return traverse;
1876}
1877
1878void Layer::traverseChildrenInZOrderInner(const std::vector<Layer*>& layersInTree,
1879 LayerVector::StateSet stateSet,
1880 const LayerVector::Visitor& visitor) {
1881 const LayerVector list = makeChildrenTraversalList(stateSet, layersInTree);
chaviwa76b2712017-09-20 12:02:26 -07001882
1883 size_t i = 0;
chaviw4b129c22018-04-09 16:19:43 -07001884 for (; i < list.size(); i++) {
1885 const auto& relative = list[i];
chaviwa76b2712017-09-20 12:02:26 -07001886 if (relative->getZ() >= 0) {
1887 break;
1888 }
chaviw4b129c22018-04-09 16:19:43 -07001889 relative->traverseChildrenInZOrderInner(layersInTree, stateSet, visitor);
chaviwa76b2712017-09-20 12:02:26 -07001890 }
chaviw4b129c22018-04-09 16:19:43 -07001891
chaviwa76b2712017-09-20 12:02:26 -07001892 visitor(this);
chaviw4b129c22018-04-09 16:19:43 -07001893 for (; i < list.size(); i++) {
1894 const auto& relative = list[i];
1895 relative->traverseChildrenInZOrderInner(layersInTree, stateSet, visitor);
chaviwa76b2712017-09-20 12:02:26 -07001896 }
1897}
1898
chaviw4b129c22018-04-09 16:19:43 -07001899std::vector<Layer*> Layer::getLayersInTree(LayerVector::StateSet stateSet) {
1900 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
1901 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
1902
1903 std::vector<Layer*> layersInTree = {this};
1904 for (size_t i = 0; i < children.size(); i++) {
1905 const auto& child = children[i];
1906 std::vector<Layer*> childLayers = child->getLayersInTree(stateSet);
1907 layersInTree.insert(layersInTree.end(), childLayers.cbegin(), childLayers.cend());
1908 }
1909
1910 return layersInTree;
1911}
1912
1913void Layer::traverseChildrenInZOrder(LayerVector::StateSet stateSet,
1914 const LayerVector::Visitor& visitor) {
1915 std::vector<Layer*> layersInTree = getLayersInTree(stateSet);
1916 std::sort(layersInTree.begin(), layersInTree.end());
1917 traverseChildrenInZOrderInner(layersInTree, stateSet, visitor);
1918}
1919
Peiyong Linefefaac2018-08-17 12:27:51 -07001920ui::Transform Layer::getTransform() const {
1921 ui::Transform t;
Chia-I Wue41dbe62017-06-13 14:10:56 -07001922 const auto& p = mDrawingParent.promote();
Robert Carr1f0a16a2016-10-24 16:27:39 -07001923 if (p != nullptr) {
1924 t = p->getTransform();
Robert Carr9b429f42017-04-17 14:56:57 -07001925
1926 // If the parent is not using NATIVE_WINDOW_SCALING_MODE_FREEZE (e.g.
1927 // it isFixedSize) then there may be additional scaling not accounted
1928 // for in the transform. We need to mirror this scaling in child surfaces
1929 // or we will break the contract where WM can treat child surfaces as
1930 // pixels in the parent surface.
David Sodman0cc69182017-11-17 12:12:07 -08001931 if (p->isFixedSize() && p->getBE().compositionInfo.mBuffer != nullptr) {
Robert Carr1725eee2017-04-26 18:32:15 -07001932 int bufferWidth;
1933 int bufferHeight;
1934 if ((p->mCurrentTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) == 0) {
David Sodman0cc69182017-11-17 12:12:07 -08001935 bufferWidth = p->getBE().compositionInfo.mBuffer->getWidth();
1936 bufferHeight = p->getBE().compositionInfo.mBuffer->getHeight();
Robert Carr1725eee2017-04-26 18:32:15 -07001937 } else {
David Sodman0cc69182017-11-17 12:12:07 -08001938 bufferHeight = p->getBE().compositionInfo.mBuffer->getWidth();
1939 bufferWidth = p->getBE().compositionInfo.mBuffer->getHeight();
Robert Carr1725eee2017-04-26 18:32:15 -07001940 }
Marissa Wall61c58622018-07-18 10:12:20 -07001941 float sx = p->getActiveWidth(p->getDrawingState()) / static_cast<float>(bufferWidth);
1942 float sy = p->getActiveHeight(p->getDrawingState()) / static_cast<float>(bufferHeight);
Peiyong Linefefaac2018-08-17 12:27:51 -07001943 ui::Transform extraParentScaling;
Robert Carr9b429f42017-04-17 14:56:57 -07001944 extraParentScaling.set(sx, 0, 0, sy);
1945 t = t * extraParentScaling;
1946 }
Robert Carr1f0a16a2016-10-24 16:27:39 -07001947 }
Marissa Wall61c58622018-07-18 10:12:20 -07001948 return t * getActiveTransform(getDrawingState());
Robert Carr1f0a16a2016-10-24 16:27:39 -07001949}
1950
chaviw13fdc492017-06-27 12:40:18 -07001951half Layer::getAlpha() const {
Chia-I Wue41dbe62017-06-13 14:10:56 -07001952 const auto& p = mDrawingParent.promote();
Robert Carr6452f122017-03-21 10:41:29 -07001953
chaviw13fdc492017-06-27 12:40:18 -07001954 half parentAlpha = (p != nullptr) ? p->getAlpha() : 1.0_hf;
1955 return parentAlpha * getDrawingState().color.a;
Robert Carr6452f122017-03-21 10:41:29 -07001956}
Robert Carr6452f122017-03-21 10:41:29 -07001957
chaviw13fdc492017-06-27 12:40:18 -07001958half4 Layer::getColor() const {
1959 const half4 color(getDrawingState().color);
1960 return half4(color.r, color.g, color.b, getAlpha());
Robert Carr6452f122017-03-21 10:41:29 -07001961}
Robert Carr6452f122017-03-21 10:41:29 -07001962
Lucas Dupin1b6531c2018-07-05 17:18:21 -07001963Layer::RoundedCornerState Layer::getRoundedCornerState() const {
1964 const auto& p = mDrawingParent.promote();
1965 if (p != nullptr) {
1966 RoundedCornerState parentState = p->getRoundedCornerState();
1967 if (parentState.radius > 0) {
1968 ui::Transform t = getActiveTransform(getDrawingState());
1969 t = t.inverse();
1970 parentState.cropRect = t.transform(parentState.cropRect);
1971 // The rounded corners shader only accepts 1 corner radius for performance reasons,
1972 // but a transform matrix can define horizontal and vertical scales.
1973 // Let's take the average between both of them and pass into the shader, practically we
1974 // never do this type of transformation on windows anyway.
1975 parentState.radius *= (t[0][0] + t[1][1]) / 2.0f;
1976 return parentState;
1977 }
1978 }
1979 const float radius = getDrawingState().cornerRadius;
1980 return radius > 0 ? RoundedCornerState(computeBounds(), radius) : RoundedCornerState();
1981}
1982
Robert Carr1f0a16a2016-10-24 16:27:39 -07001983void Layer::commitChildList() {
1984 for (size_t i = 0; i < mCurrentChildren.size(); i++) {
1985 const auto& child = mCurrentChildren[i];
1986 child->commitChildList();
1987 }
1988 mDrawingChildren = mCurrentChildren;
Chia-I Wue41dbe62017-06-13 14:10:56 -07001989 mDrawingParent = mCurrentParent;
Robert Carr1f0a16a2016-10-24 16:27:39 -07001990}
1991
Robert Carr720e5062018-07-30 17:45:14 -07001992void Layer::setInputInfo(const InputWindowInfo& info) {
1993 mCurrentState.inputInfo = info;
1994 mCurrentState.modified = true;
1995 mCurrentState.inputInfoChanged = true;
1996 setTransactionFlags(eTransactionNeeded);
1997}
1998
chaviw1d044282017-09-27 12:19:28 -07001999void Layer::writeToProto(LayerProto* layerInfo, LayerVector::StateSet stateSet) {
2000 const bool useDrawing = stateSet == LayerVector::StateSet::Drawing;
2001 const LayerVector& children = useDrawing ? mDrawingChildren : mCurrentChildren;
2002 const State& state = useDrawing ? mDrawingState : mCurrentState;
2003
Peiyong Linefefaac2018-08-17 12:27:51 -07002004 ui::Transform requestedTransform = state.active_legacy.transform;
2005 ui::Transform transform = getTransform();
chaviw1d044282017-09-27 12:19:28 -07002006
2007 layerInfo->set_id(sequence);
2008 layerInfo->set_name(getName().c_str());
2009 layerInfo->set_type(String8(getTypeId()));
2010
2011 for (const auto& child : children) {
2012 layerInfo->add_children(child->sequence);
2013 }
2014
2015 for (const wp<Layer>& weakRelative : state.zOrderRelatives) {
2016 sp<Layer> strongRelative = weakRelative.promote();
2017 if (strongRelative != nullptr) {
2018 layerInfo->add_relatives(strongRelative->sequence);
2019 }
2020 }
2021
Marissa Wallf58c14b2018-07-24 10:50:43 -07002022 LayerProtoHelper::writeToProto(state.activeTransparentRegion_legacy,
chaviw1d044282017-09-27 12:19:28 -07002023 layerInfo->mutable_transparent_region());
2024 LayerProtoHelper::writeToProto(visibleRegion, layerInfo->mutable_visible_region());
2025 LayerProtoHelper::writeToProto(surfaceDamageRegion, layerInfo->mutable_damage_region());
2026
2027 layerInfo->set_layer_stack(getLayerStack());
2028 layerInfo->set_z(state.z);
2029
2030 PositionProto* position = layerInfo->mutable_position();
2031 position->set_x(transform.tx());
2032 position->set_y(transform.ty());
2033
2034 PositionProto* requestedPosition = layerInfo->mutable_requested_position();
2035 requestedPosition->set_x(requestedTransform.tx());
2036 requestedPosition->set_y(requestedTransform.ty());
2037
2038 SizeProto* size = layerInfo->mutable_size();
Marissa Wallf58c14b2018-07-24 10:50:43 -07002039 size->set_w(state.active_legacy.w);
2040 size->set_h(state.active_legacy.h);
chaviw1d044282017-09-27 12:19:28 -07002041
Marissa Wallf58c14b2018-07-24 10:50:43 -07002042 LayerProtoHelper::writeToProto(state.crop_legacy, layerInfo->mutable_crop());
Lucas Dupin1b6531c2018-07-05 17:18:21 -07002043 layerInfo->set_corner_radius(getRoundedCornerState().radius);
chaviw1d044282017-09-27 12:19:28 -07002044
2045 layerInfo->set_is_opaque(isOpaque(state));
2046 layerInfo->set_invalidate(contentDirty);
Chia-I Wu01591c92018-05-22 12:03:00 -07002047
2048 // XXX (b/79210409) mCurrentDataSpace is not protected
2049 layerInfo->set_dataspace(dataspaceDetails(static_cast<android_dataspace>(mCurrentDataSpace)));
2050
chaviw1d044282017-09-27 12:19:28 -07002051 layerInfo->set_pixel_format(decodePixelFormat(getPixelFormat()));
2052 LayerProtoHelper::writeToProto(getColor(), layerInfo->mutable_color());
2053 LayerProtoHelper::writeToProto(state.color, layerInfo->mutable_requested_color());
2054 layerInfo->set_flags(state.flags);
2055
2056 LayerProtoHelper::writeToProto(transform, layerInfo->mutable_transform());
2057 LayerProtoHelper::writeToProto(requestedTransform, layerInfo->mutable_requested_transform());
2058
Jorim Jaggi8e0af362017-11-14 16:28:28 +01002059 auto parent = useDrawing ? mDrawingParent.promote() : mCurrentParent.promote();
chaviw1d044282017-09-27 12:19:28 -07002060 if (parent != nullptr) {
2061 layerInfo->set_parent(parent->sequence);
2062 }
2063
2064 auto zOrderRelativeOf = state.zOrderRelativeOf.promote();
2065 if (zOrderRelativeOf != nullptr) {
2066 layerInfo->set_z_order_relative_of(zOrderRelativeOf->sequence);
2067 }
2068
Chia-I Wu01591c92018-05-22 12:03:00 -07002069 // XXX getBE().compositionInfo.mBuffer is not protected
David Sodman0cc69182017-11-17 12:12:07 -08002070 auto buffer = getBE().compositionInfo.mBuffer;
David Sodman5b4cffc2017-11-23 13:20:29 -08002071 if (buffer != nullptr) {
2072 LayerProtoHelper::writeToProto(buffer, layerInfo->mutable_active_buffer());
Peiyong Linefefaac2018-08-17 12:27:51 -07002073 LayerProtoHelper::writeToProto(ui::Transform(mCurrentTransform),
Yichi Chen6ca35192018-05-29 12:20:43 +08002074 layerInfo->mutable_buffer_transform());
chaviw1d044282017-09-27 12:19:28 -07002075 }
2076
2077 layerInfo->set_queued_frames(getQueuedFrameCount());
2078 layerInfo->set_refresh_pending(isBufferLatched());
rongliucfb187b2018-03-14 12:26:23 -07002079 layerInfo->set_window_type(state.type);
2080 layerInfo->set_app_id(state.appId);
chaviwadc40c22018-07-10 16:57:27 -07002081 layerInfo->set_curr_frame(mCurrentFrameNumber);
Vishnu Nairf2deb822018-11-12 17:53:48 -08002082 layerInfo->set_effective_scaling_mode(getEffectiveScalingMode());
chaviwadc40c22018-07-10 16:57:27 -07002083
2084 for (const auto& pendingState : mPendingStates) {
Marissa Wallf58c14b2018-07-24 10:50:43 -07002085 auto barrierLayer = pendingState.barrierLayer_legacy.promote();
chaviwadc40c22018-07-10 16:57:27 -07002086 if (barrierLayer != nullptr) {
2087 BarrierLayerProto* barrierLayerProto = layerInfo->add_barrier_layer();
2088 barrierLayerProto->set_id(barrierLayer->sequence);
Marissa Wallf58c14b2018-07-24 10:50:43 -07002089 barrierLayerProto->set_frame_number(pendingState.frameNumber_legacy);
chaviwadc40c22018-07-10 16:57:27 -07002090 }
2091 }
chaviw1d044282017-09-27 12:19:28 -07002092}
2093
Dominik Laskowski075d3172018-05-24 15:50:06 -07002094void Layer::writeToProto(LayerProto* layerInfo, DisplayId displayId) {
Peiyong Lin91b1df22018-06-18 18:00:16 -07002095 if (!hasHwcLayer(displayId)) {
2096 return;
2097 }
2098
Yiwei Zhang7124ad32018-02-21 13:02:45 -08002099 writeToProto(layerInfo, LayerVector::StateSet::Drawing);
2100
Dominik Laskowski7e045462018-05-30 13:02:02 -07002101 const auto& hwcInfo = getBE().mHwcLayers.at(displayId);
Yiwei Zhang7124ad32018-02-21 13:02:45 -08002102
2103 const Rect& frame = hwcInfo.displayFrame;
2104 LayerProtoHelper::writeToProto(frame, layerInfo->mutable_hwc_frame());
2105
2106 const FloatRect& crop = hwcInfo.sourceCrop;
2107 LayerProtoHelper::writeToProto(crop, layerInfo->mutable_hwc_crop());
2108
2109 const int32_t transform = static_cast<int32_t>(hwcInfo.transform);
2110 layerInfo->set_hwc_transform(transform);
Yiwei Zhang60d1a192018-03-07 14:52:28 -08002111
2112 const int32_t compositionType = static_cast<int32_t>(hwcInfo.compositionType);
2113 layerInfo->set_hwc_composition_type(compositionType);
2114
2115 if (std::strcmp(getTypeId(), "BufferLayer") == 0 &&
2116 static_cast<BufferLayer*>(this)->isProtected()) {
2117 layerInfo->set_is_protected(true);
2118 } else {
2119 layerInfo->set_is_protected(false);
2120 }
Yiwei Zhang7124ad32018-02-21 13:02:45 -08002121}
2122
Robert Carr2e102c92018-10-23 12:11:15 -07002123bool Layer::isRemovedFromCurrentState() const {
2124 return mRemovedFromCurrentState;
2125}
2126
Robert Carr720e5062018-07-30 17:45:14 -07002127InputWindowInfo Layer::fillInputInfo(const Rect& screenBounds) {
2128 InputWindowInfo info = mDrawingState.inputInfo;
Robert Carr720e5062018-07-30 17:45:14 -07002129
Robert Carre07e1032018-11-26 12:55:53 -08002130 ui::Transform t = getTransform();
Riddle Hsu39d4aa52018-11-30 20:46:53 +08002131 const float xScale = t.sx();
2132 const float yScale = t.sy();
2133 if (xScale != 1.0f || yScale != 1.0f) {
2134 info.windowXScale *= 1.0f / xScale;
2135 info.windowYScale *= 1.0f / yScale;
2136 info.touchableRegion.scaleSelf(xScale, yScale);
2137 }
Robert Carre07e1032018-11-26 12:55:53 -08002138
Vishnu Nair8033a492018-12-05 07:27:23 -08002139 // Transform layer size to screen space and inset it by surface insets.
2140 Rect layerBounds = getCroppedBufferSize(getDrawingState());
2141 layerBounds = t.transform(layerBounds);
2142 layerBounds.inset(info.surfaceInset, info.surfaceInset, info.surfaceInset, info.surfaceInset);
2143
2144 // Intersect with screen bounds to shrink the frame by the surface insets. The surface insets
2145 // are not set on the screen bounds directly since the surface inset region may already be
2146 // cropped by a parent layer.
2147 Rect frame;
2148 screenBounds.intersect(layerBounds, &frame);
2149
2150 info.frameLeft = frame.left;
2151 info.frameTop = frame.top;
2152 info.frameRight = frame.right;
2153 info.frameBottom = frame.bottom;
2154
2155 // Position the touchable region relative to frame screen location and restrict it to frame
2156 // bounds.
2157 info.touchableRegion = info.touchableRegion.translate(info.frameLeft, info.frameTop);
2158 info.touchableRegion = info.touchableRegion.intersect(frame);
Robert Carr720e5062018-07-30 17:45:14 -07002159 info.visible = isVisible();
2160 return info;
2161}
2162
2163bool Layer::hasInput() const {
Robert Carr5c8a0262018-10-03 16:30:44 -07002164 return mDrawingState.inputInfo.token != nullptr;
Robert Carr720e5062018-07-30 17:45:14 -07002165}
2166
Mathias Agopian13127d82013-03-05 17:47:11 -08002167// ---------------------------------------------------------------------------
2168
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002169}; // namespace android
Mathias Agopian3f844832013-08-07 21:24:32 -07002170
2171#if defined(__gl_h_)
2172#error "don't include gl/gl.h in this file"
2173#endif
2174
2175#if defined(__gl2_h_)
2176#error "don't include gl2/gl2.h in this file"
2177#endif