blob: d13b6dbe19651c8d85774c6261bdbf5e74db69b8 [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
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080022#include <stdlib.h>
23#include <stdint.h>
24#include <sys/types.h>
Mathias Agopian13127d82013-03-05 17:47:11 -080025#include <math.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080026
Mathias Agopiana67932f2011-04-20 14:20:59 -070027#include <cutils/compiler.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070028#include <cutils/native_handle.h>
Mathias Agopiana67932f2011-04-20 14:20:59 -070029#include <cutils/properties.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080030
31#include <utils/Errors.h>
32#include <utils/Log.h>
Jesse Hall399184a2014-03-03 15:42:54 -080033#include <utils/NativeHandle.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080034#include <utils/StopWatch.h>
Jamie Gennis1c8e95c2012-02-23 19:27:23 -080035#include <utils/Trace.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080036
Mathias Agopian3330b202009-10-05 17:07:12 -070037#include <ui/GraphicBuffer.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080038#include <ui/PixelFormat.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080039
Dan Stoza6b9454d2014-11-07 16:00:59 -080040#include <gui/BufferItem.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080041#include <gui/Surface.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042
43#include "clz.h"
Mathias Agopian3e25fd82013-04-22 17:52:16 +020044#include "Colorizer.h"
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070045#include "DisplayDevice.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046#include "Layer.h"
Dan Stozab9b08832014-03-13 11:55:57 -070047#include "MonitoredProducer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048#include "SurfaceFlinger.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049
Mathias Agopian1b031492012-06-20 17:51:20 -070050#include "DisplayHardware/HWComposer.h"
51
Mathias Agopian875d8e12013-06-07 15:35:48 -070052#include "RenderEngine/RenderEngine.h"
53
Dan Stozac5da2712016-07-20 15:38:12 -070054#include <mutex>
55
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080056#define DEBUG_RESIZE 0
57
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080058namespace android {
59
60// ---------------------------------------------------------------------------
61
Mathias Agopian13127d82013-03-05 17:47:11 -080062int32_t Layer::sSequence = 1;
63
Mathias Agopian4d9b8222013-03-12 17:11:48 -070064Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client,
65 const String8& name, uint32_t w, uint32_t h, uint32_t flags)
Mathias Agopian13127d82013-03-05 17:47:11 -080066 : contentDirty(false),
67 sequence(uint32_t(android_atomic_inc(&sSequence))),
68 mFlinger(flinger),
Mathias Agopiana67932f2011-04-20 14:20:59 -070069 mTextureName(-1U),
Mathias Agopian13127d82013-03-05 17:47:11 -080070 mPremultipliedAlpha(true),
71 mName("unnamed"),
Mathias Agopian13127d82013-03-05 17:47:11 -080072 mFormat(PIXEL_FORMAT_NONE),
Mathias Agopian13127d82013-03-05 17:47:11 -080073 mTransactionFlags(0),
Dan Stoza7dde5992015-05-22 09:51:44 -070074 mPendingStateMutex(),
75 mPendingStates(),
Mathias Agopiana67932f2011-04-20 14:20:59 -070076 mQueuedFrames(0),
Jesse Hall399184a2014-03-03 15:42:54 -080077 mSidebandStreamChanged(false),
Mathias Agopiana67932f2011-04-20 14:20:59 -070078 mCurrentTransform(0),
Mathias Agopian933389f2011-07-18 16:15:08 -070079 mCurrentScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
Robert Carrc3574f72016-03-24 12:19:32 -070080 mOverrideScalingMode(-1),
Mathias Agopiana67932f2011-04-20 14:20:59 -070081 mCurrentOpacity(true),
Dan Stozacac35382016-01-27 12:21:06 -080082 mCurrentFrameNumber(0),
Mathias Agopian4d143ee2012-02-23 20:05:39 -080083 mRefreshPending(false),
Mathias Agopian82d7ab62012-01-19 18:34:40 -080084 mFrameLatencyNeeded(false),
Mathias Agopian13127d82013-03-05 17:47:11 -080085 mFiltering(false),
86 mNeedsFiltering(false),
Mathias Agopian5cdc8992013-08-13 20:51:23 -070087 mMesh(Mesh::TRIANGLE_FAN, 4, 2, 2),
Pablo Ceballos40845df2016-01-25 17:41:15 -080088#ifndef USE_HWC2
89 mIsGlesComposition(false),
90#endif
Mathias Agopian13127d82013-03-05 17:47:11 -080091 mProtectedByApp(false),
92 mHasSurface(false),
Riley Andrews03414a12014-07-01 14:22:59 -070093 mClientRef(client),
Dan Stozaa4650a52015-05-12 12:56:16 -070094 mPotentialCursor(false),
95 mQueueItemLock(),
96 mQueueItemCondition(),
97 mQueueItems(),
Dan Stoza65476f32015-05-14 09:27:25 -070098 mLastFrameNumberReceived(0),
Pablo Ceballos04839ab2015-11-13 13:39:23 -080099 mUpdateTexImageFailed(false),
Robert Carr82364e32016-05-15 11:27:47 -0700100 mAutoRefresh(false),
101 mFreezePositionUpdates(false)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102{
Dan Stoza9e56aa02015-11-02 13:00:03 -0800103#ifdef USE_HWC2
104 ALOGV("Creating Layer %s", name.string());
105#endif
106
Mathias Agopiana67932f2011-04-20 14:20:59 -0700107 mCurrentCrop.makeInvalid();
Mathias Agopian3f844832013-08-07 21:24:32 -0700108 mFlinger->getRenderEngine().genTextures(1, &mTextureName);
Mathias Agopian49457ac2013-08-14 18:20:17 -0700109 mTexture.init(Texture::TEXTURE_EXTERNAL, mTextureName);
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700110
111 uint32_t layerFlags = 0;
112 if (flags & ISurfaceComposerClient::eHidden)
Andy McFadden4125a4f2014-01-29 17:17:11 -0800113 layerFlags |= layer_state_t::eLayerHidden;
114 if (flags & ISurfaceComposerClient::eOpaque)
115 layerFlags |= layer_state_t::eLayerOpaque;
Dan Stoza23116082015-06-18 14:58:39 -0700116 if (flags & ISurfaceComposerClient::eSecure)
117 layerFlags |= layer_state_t::eLayerSecure;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700118
119 if (flags & ISurfaceComposerClient::eNonPremultiplied)
120 mPremultipliedAlpha = false;
121
122 mName = name;
123
124 mCurrentState.active.w = w;
125 mCurrentState.active.h = h;
Robert Carr3dcabfa2016-03-01 18:36:58 -0800126 mCurrentState.active.transform.set(0, 0);
Robert Carrb5d3d262016-03-25 15:08:13 -0700127 mCurrentState.crop.makeInvalid();
128 mCurrentState.finalCrop.makeInvalid();
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700129 mCurrentState.z = 0;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800130#ifdef USE_HWC2
131 mCurrentState.alpha = 1.0f;
132#else
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700133 mCurrentState.alpha = 0xFF;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800134#endif
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700135 mCurrentState.layerStack = 0;
136 mCurrentState.flags = layerFlags;
137 mCurrentState.sequence = 0;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700138 mCurrentState.requested = mCurrentState.active;
139
140 // drawing state & current state are identical
141 mDrawingState = mCurrentState;
Jamie Gennis6547ff42013-07-16 20:12:42 -0700142
Dan Stoza9e56aa02015-11-02 13:00:03 -0800143#ifdef USE_HWC2
144 const auto& hwc = flinger->getHwComposer();
145 const auto& activeConfig = hwc.getActiveConfig(HWC_DISPLAY_PRIMARY);
146 nsecs_t displayPeriod = activeConfig->getVsyncPeriod();
147#else
Jamie Gennis6547ff42013-07-16 20:12:42 -0700148 nsecs_t displayPeriod =
149 flinger->getHwComposer().getRefreshPeriod(HWC_DISPLAY_PRIMARY);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800150#endif
Jamie Gennis6547ff42013-07-16 20:12:42 -0700151 mFrameTracker.setDisplayRefreshPeriod(displayPeriod);
Jamie Gennise8696a42012-01-15 18:54:57 -0800152}
153
Mathias Agopian3f844832013-08-07 21:24:32 -0700154void Layer::onFirstRef() {
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800155 // Creates a custom BufferQueue for SurfaceFlingerConsumer to use
Dan Stozab3d0bdf2014-04-07 16:33:59 -0700156 sp<IGraphicBufferProducer> producer;
157 sp<IGraphicBufferConsumer> consumer;
Dan Stozab9b08832014-03-13 11:55:57 -0700158 BufferQueue::createBufferQueue(&producer, &consumer);
159 mProducer = new MonitoredProducer(producer, mFlinger);
Pablo Ceballosce796e72016-02-04 19:10:51 -0800160 mSurfaceFlingerConsumer = new SurfaceFlingerConsumer(consumer, mTextureName,
161 this);
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800162 mSurfaceFlingerConsumer->setConsumerUsageBits(getEffectiveUsage(0));
Jesse Hall399184a2014-03-03 15:42:54 -0800163 mSurfaceFlingerConsumer->setContentsChangedListener(this);
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700164 mSurfaceFlingerConsumer->setName(mName);
Daniel Lamb2675792012-02-23 14:35:13 -0800165
Dan Stozac9d97202016-03-03 08:20:27 -0800166#ifndef TARGET_DISABLE_TRIPLE_BUFFERING
Pablo Ceballos19e3e062015-08-19 16:16:06 -0700167 mProducer->setMaxDequeuedBufferCount(2);
Mathias Agopian303d5382012-02-05 01:49:16 -0800168#endif
Andy McFadden69052052012-09-14 16:10:11 -0700169
Mathias Agopian84300952012-11-21 16:02:13 -0800170 const sp<const DisplayDevice> hw(mFlinger->getDefaultDisplayDevice());
171 updateTransformHint(hw);
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700172}
173
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700174Layer::~Layer() {
Pablo Ceballos8ea4e7b2016-03-03 15:20:02 -0800175 sp<Client> c(mClientRef.promote());
176 if (c != 0) {
177 c->detachLayer(this);
178 }
179
Dan Stozacac35382016-01-27 12:21:06 -0800180 for (auto& point : mRemoteSyncPoints) {
181 point->setTransactionApplied();
182 }
Dan Stozac8145172016-04-28 16:29:06 -0700183 for (auto& point : mLocalSyncPoints) {
184 point->setFrameAvailable();
185 }
Mathias Agopian921e6ac2012-07-23 23:11:29 -0700186 mFlinger->deleteTextureAsync(mTextureName);
Jamie Gennis6547ff42013-07-16 20:12:42 -0700187 mFrameTracker.logAndResetStats(mName);
Mathias Agopian96f08192010-06-02 23:28:45 -0700188}
189
Mathias Agopian13127d82013-03-05 17:47:11 -0800190// ---------------------------------------------------------------------------
191// callbacks
192// ---------------------------------------------------------------------------
193
Dan Stoza9e56aa02015-11-02 13:00:03 -0800194#ifdef USE_HWC2
195void Layer::onLayerDisplayed(const sp<Fence>& releaseFence) {
196 if (mHwcLayers.empty()) {
197 return;
198 }
199 mSurfaceFlingerConsumer->setReleaseFence(releaseFence);
200}
201#else
Dan Stozac7014012014-02-14 15:03:43 -0800202void Layer::onLayerDisplayed(const sp<const DisplayDevice>& /* hw */,
Mathias Agopian13127d82013-03-05 17:47:11 -0800203 HWComposer::HWCLayerInterface* layer) {
204 if (layer) {
205 layer->onDisplayed();
Jesse Hall13f01cb2013-03-20 11:37:21 -0700206 mSurfaceFlingerConsumer->setReleaseFence(layer->getAndResetReleaseFence());
Mathias Agopian13127d82013-03-05 17:47:11 -0800207 }
208}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800209#endif
Mathias Agopian13127d82013-03-05 17:47:11 -0800210
Dan Stoza6b9454d2014-11-07 16:00:59 -0800211void Layer::onFrameAvailable(const BufferItem& item) {
212 // Add this buffer from our internal queue tracker
213 { // Autolock scope
214 Mutex::Autolock lock(mQueueItemLock);
Dan Stozaa4650a52015-05-12 12:56:16 -0700215
216 // Reset the frame number tracker when we receive the first buffer after
217 // a frame number reset
218 if (item.mFrameNumber == 1) {
219 mLastFrameNumberReceived = 0;
220 }
221
222 // Ensure that callbacks are handled in order
223 while (item.mFrameNumber != mLastFrameNumberReceived + 1) {
224 status_t result = mQueueItemCondition.waitRelative(mQueueItemLock,
225 ms2ns(500));
226 if (result != NO_ERROR) {
227 ALOGE("[%s] Timed out waiting on callback", mName.string());
228 }
229 }
230
Dan Stoza6b9454d2014-11-07 16:00:59 -0800231 mQueueItems.push_back(item);
Dan Stozaecc50402015-04-28 14:42:06 -0700232 android_atomic_inc(&mQueuedFrames);
Dan Stozaa4650a52015-05-12 12:56:16 -0700233
234 // Wake up any pending callbacks
235 mLastFrameNumberReceived = item.mFrameNumber;
236 mQueueItemCondition.broadcast();
Dan Stoza6b9454d2014-11-07 16:00:59 -0800237 }
238
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800239 mFlinger->signalLayerUpdate();
Mathias Agopian579b3f82010-06-08 19:54:15 -0700240}
241
Dan Stoza6b9454d2014-11-07 16:00:59 -0800242void Layer::onFrameReplaced(const BufferItem& item) {
Dan Stoza7dde5992015-05-22 09:51:44 -0700243 { // Autolock scope
244 Mutex::Autolock lock(mQueueItemLock);
Dan Stozaa4650a52015-05-12 12:56:16 -0700245
Dan Stoza7dde5992015-05-22 09:51:44 -0700246 // Ensure that callbacks are handled in order
247 while (item.mFrameNumber != mLastFrameNumberReceived + 1) {
248 status_t result = mQueueItemCondition.waitRelative(mQueueItemLock,
249 ms2ns(500));
250 if (result != NO_ERROR) {
251 ALOGE("[%s] Timed out waiting on callback", mName.string());
252 }
Dan Stozaa4650a52015-05-12 12:56:16 -0700253 }
Dan Stoza7dde5992015-05-22 09:51:44 -0700254
255 if (mQueueItems.empty()) {
256 ALOGE("Can't replace a frame on an empty queue");
257 return;
258 }
Pablo Ceballos4d85da42016-04-19 20:11:56 -0700259 mQueueItems.editItemAt(mQueueItems.size() - 1) = item;
Dan Stoza7dde5992015-05-22 09:51:44 -0700260
261 // Wake up any pending callbacks
262 mLastFrameNumberReceived = item.mFrameNumber;
263 mQueueItemCondition.broadcast();
Dan Stozaa4650a52015-05-12 12:56:16 -0700264 }
Dan Stoza6b9454d2014-11-07 16:00:59 -0800265}
266
Jesse Hall399184a2014-03-03 15:42:54 -0800267void Layer::onSidebandStreamChanged() {
268 if (android_atomic_release_cas(false, true, &mSidebandStreamChanged) == 0) {
269 // mSidebandStreamChanged was false
270 mFlinger->signalLayerUpdate();
271 }
272}
273
Mathias Agopian67106042013-03-14 19:18:13 -0700274// called with SurfaceFlinger::mStateLock from the drawing thread after
275// the layer has been remove from the current state list (and just before
276// it's removed from the drawing state list)
Mathias Agopian13127d82013-03-05 17:47:11 -0800277void Layer::onRemoved() {
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800278 mSurfaceFlingerConsumer->abandon();
Mathias Agopian48d819a2009-09-10 19:41:18 -0700279}
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700280
Mathias Agopian13127d82013-03-05 17:47:11 -0800281// ---------------------------------------------------------------------------
282// set-up
283// ---------------------------------------------------------------------------
284
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700285const String8& Layer::getName() const {
Mathias Agopian13127d82013-03-05 17:47:11 -0800286 return mName;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800287}
288
Mathias Agopianf9d93272009-06-19 17:00:27 -0700289status_t Layer::setBuffers( uint32_t w, uint32_t h,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800290 PixelFormat format, uint32_t flags)
291{
Mathias Agopianca99fb82010-04-14 16:43:44 -0700292 uint32_t const maxSurfaceDims = min(
Mathias Agopiana4912602012-07-12 14:25:33 -0700293 mFlinger->getMaxTextureSize(), mFlinger->getMaxViewportDims());
Mathias Agopianca99fb82010-04-14 16:43:44 -0700294
295 // never allow a surface larger than what our underlying GL implementation
296 // can handle.
297 if ((uint32_t(w)>maxSurfaceDims) || (uint32_t(h)>maxSurfaceDims)) {
Mathias Agopianff615cc2012-02-24 14:58:36 -0800298 ALOGE("dimensions too large %u x %u", uint32_t(w), uint32_t(h));
Mathias Agopianca99fb82010-04-14 16:43:44 -0700299 return BAD_VALUE;
300 }
301
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700302 mFormat = format;
Mathias Agopianeff062c2010-08-25 14:59:15 -0700303
Riley Andrews03414a12014-07-01 14:22:59 -0700304 mPotentialCursor = (flags & ISurfaceComposerClient::eCursorWindow) ? true : false;
Mathias Agopian3165cc22012-08-08 19:42:09 -0700305 mProtectedByApp = (flags & ISurfaceComposerClient::eProtectedByApp) ? true : false;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700306 mCurrentOpacity = getOpacityForFormat(format);
307
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800308 mSurfaceFlingerConsumer->setDefaultBufferSize(w, h);
309 mSurfaceFlingerConsumer->setDefaultBufferFormat(format);
310 mSurfaceFlingerConsumer->setConsumerUsageBits(getEffectiveUsage(0));
Mathias Agopianca99fb82010-04-14 16:43:44 -0700311
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800312 return NO_ERROR;
313}
314
Dan Stoza7dde5992015-05-22 09:51:44 -0700315/*
316 * The layer handle is just a BBinder object passed to the client
317 * (remote process) -- we don't keep any reference on our side such that
318 * the dtor is called when the remote side let go of its reference.
319 *
320 * LayerCleaner ensures that mFlinger->onLayerDestroyed() is called for
321 * this layer when the handle is destroyed.
322 */
323class Layer::Handle : public BBinder, public LayerCleaner {
324 public:
325 Handle(const sp<SurfaceFlinger>& flinger, const sp<Layer>& layer)
326 : LayerCleaner(flinger, layer), owner(layer) {}
327
328 wp<Layer> owner;
329};
330
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700331sp<IBinder> Layer::getHandle() {
Mathias Agopian13127d82013-03-05 17:47:11 -0800332 Mutex::Autolock _l(mLock);
333
334 LOG_ALWAYS_FATAL_IF(mHasSurface,
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700335 "Layer::getHandle() has already been called");
Mathias Agopian13127d82013-03-05 17:47:11 -0800336
337 mHasSurface = true;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700338
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700339 return new Handle(mFlinger, this);
Mathias Agopian13127d82013-03-05 17:47:11 -0800340}
341
Dan Stozab9b08832014-03-13 11:55:57 -0700342sp<IGraphicBufferProducer> Layer::getProducer() const {
343 return mProducer;
Mathias Agopian4d9b8222013-03-12 17:11:48 -0700344}
345
Mathias Agopian13127d82013-03-05 17:47:11 -0800346// ---------------------------------------------------------------------------
347// h/w composer set-up
348// ---------------------------------------------------------------------------
349
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800350Rect Layer::getContentCrop() const {
351 // this is the crop rectangle that applies to the buffer
352 // itself (as opposed to the window)
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700353 Rect crop;
354 if (!mCurrentCrop.isEmpty()) {
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800355 // if the buffer crop is defined, we use that
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700356 crop = mCurrentCrop;
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800357 } else if (mActiveBuffer != NULL) {
358 // otherwise we use the whole buffer
359 crop = mActiveBuffer->getBounds();
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700360 } else {
Mathias Agopiana8bca8d2013-02-27 22:03:19 -0800361 // if we don't have a buffer yet, we use an empty/invalid crop
Mathias Agopian4fec8732012-06-29 14:12:52 -0700362 crop.makeInvalid();
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700363 }
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700364 return crop;
365}
366
Mathias Agopianf3e85d42013-05-10 18:01:12 -0700367static Rect reduce(const Rect& win, const Region& exclude) {
368 if (CC_LIKELY(exclude.isEmpty())) {
369 return win;
370 }
371 if (exclude.isRect()) {
372 return win.reduce(exclude.getBounds());
373 }
374 return Region(win).subtract(exclude).getBounds();
375}
376
Mathias Agopian13127d82013-03-05 17:47:11 -0800377Rect Layer::computeBounds() const {
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700378 const Layer::State& s(getDrawingState());
Michael Lentine6c925ed2014-09-26 17:55:01 -0700379 return computeBounds(s.activeTransparentRegion);
380}
381
382Rect Layer::computeBounds(const Region& activeTransparentRegion) const {
383 const Layer::State& s(getDrawingState());
Mathias Agopian13127d82013-03-05 17:47:11 -0800384 Rect win(s.active.w, s.active.h);
Robert Carrb5d3d262016-03-25 15:08:13 -0700385
386 if (!s.crop.isEmpty()) {
387 win.intersect(s.crop, &win);
Mathias Agopian13127d82013-03-05 17:47:11 -0800388 }
Mathias Agopian6c7f25a2013-05-09 20:37:10 -0700389 // subtract the transparent region and snap to the bounds
Michael Lentine6c925ed2014-09-26 17:55:01 -0700390 return reduce(win, activeTransparentRegion);
Mathias Agopian13127d82013-03-05 17:47:11 -0800391}
392
Mathias Agopian6b442672013-07-09 21:24:52 -0700393FloatRect Layer::computeCrop(const sp<const DisplayDevice>& hw) const {
Mathias Agopian13127d82013-03-05 17:47:11 -0800394 // the content crop is the area of the content that gets scaled to the
395 // layer's size.
Mathias Agopian6b442672013-07-09 21:24:52 -0700396 FloatRect crop(getContentCrop());
Mathias Agopian13127d82013-03-05 17:47:11 -0800397
Robert Carrb5d3d262016-03-25 15:08:13 -0700398 // the crop is the area of the window that gets cropped, but not
Mathias Agopian13127d82013-03-05 17:47:11 -0800399 // scaled in any ways.
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700400 const State& s(getDrawingState());
Mathias Agopian13127d82013-03-05 17:47:11 -0800401
402 // apply the projection's clipping to the window crop in
403 // layerstack space, and convert-back to layer space.
Mathias Agopian6b442672013-07-09 21:24:52 -0700404 // if there are no window scaling involved, this operation will map to full
405 // pixels in the buffer.
406 // FIXME: the 3 lines below can produce slightly incorrect clipping when we have
407 // a viewport clipping and a window transform. we should use floating point to fix this.
Mathias Agopian0e8f1442013-08-20 21:41:07 -0700408
409 Rect activeCrop(s.active.w, s.active.h);
Robert Carrb5d3d262016-03-25 15:08:13 -0700410 if (!s.crop.isEmpty()) {
411 activeCrop = s.crop;
Mathias Agopian0e8f1442013-08-20 21:41:07 -0700412 }
413
Robert Carr3dcabfa2016-03-01 18:36:58 -0800414 activeCrop = s.active.transform.transform(activeCrop);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000415 if (!activeCrop.intersect(hw->getViewport(), &activeCrop)) {
416 activeCrop.clear();
417 }
Robert Carrb5d3d262016-03-25 15:08:13 -0700418 if (!s.finalCrop.isEmpty()) {
419 if(!activeCrop.intersect(s.finalCrop, &activeCrop)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000420 activeCrop.clear();
421 }
422 }
Robert Carr3dcabfa2016-03-01 18:36:58 -0800423 activeCrop = s.active.transform.inverse().transform(activeCrop);
Mathias Agopian13127d82013-03-05 17:47:11 -0800424
Michael Lentine28ea2172014-11-19 18:32:37 -0800425 // This needs to be here as transform.transform(Rect) computes the
426 // transformed rect and then takes the bounding box of the result before
427 // returning. This means
428 // transform.inverse().transform(transform.transform(Rect)) != Rect
429 // in which case we need to make sure the final rect is clipped to the
430 // display bounds.
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000431 if (!activeCrop.intersect(Rect(s.active.w, s.active.h), &activeCrop)) {
432 activeCrop.clear();
433 }
Mathias Agopian13127d82013-03-05 17:47:11 -0800434
Mathias Agopianf3e85d42013-05-10 18:01:12 -0700435 // subtract the transparent region and snap to the bounds
436 activeCrop = reduce(activeCrop, s.activeTransparentRegion);
437
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000438 // Transform the window crop to match the buffer coordinate system,
439 // which means using the inverse of the current transform set on the
440 // SurfaceFlingerConsumer.
441 uint32_t invTransform = mCurrentTransform;
442 if (mSurfaceFlingerConsumer->getTransformToDisplayInverse()) {
443 /*
Pablo Ceballos021623b2016-04-15 17:31:51 -0700444 * the code below applies the primary display's inverse transform to the
445 * buffer
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000446 */
Pablo Ceballos021623b2016-04-15 17:31:51 -0700447 uint32_t invTransformOrient =
448 DisplayDevice::getPrimaryDisplayOrientationTransform();
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000449 // calculate the inverse transform
450 if (invTransformOrient & NATIVE_WINDOW_TRANSFORM_ROT_90) {
451 invTransformOrient ^= NATIVE_WINDOW_TRANSFORM_FLIP_V |
452 NATIVE_WINDOW_TRANSFORM_FLIP_H;
Mathias Agopian13127d82013-03-05 17:47:11 -0800453 }
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000454 // and apply to the current transform
Pablo Ceballos0f5131f2016-05-17 13:34:45 -0700455 invTransform = (Transform(invTransformOrient) * Transform(invTransform))
456 .getOrientation();
Mathias Agopian13127d82013-03-05 17:47:11 -0800457 }
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000458
459 int winWidth = s.active.w;
460 int winHeight = s.active.h;
461 if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
462 // If the activeCrop has been rotate the ends are rotated but not
463 // the space itself so when transforming ends back we can't rely on
464 // a modification of the axes of rotation. To account for this we
465 // need to reorient the inverse rotation in terms of the current
466 // axes of rotation.
467 bool is_h_flipped = (invTransform & NATIVE_WINDOW_TRANSFORM_FLIP_H) != 0;
468 bool is_v_flipped = (invTransform & NATIVE_WINDOW_TRANSFORM_FLIP_V) != 0;
469 if (is_h_flipped == is_v_flipped) {
470 invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V |
471 NATIVE_WINDOW_TRANSFORM_FLIP_H;
472 }
473 winWidth = s.active.h;
474 winHeight = s.active.w;
475 }
476 const Rect winCrop = activeCrop.transform(
477 invTransform, s.active.w, s.active.h);
478
479 // below, crop is intersected with winCrop expressed in crop's coordinate space
480 float xScale = crop.getWidth() / float(winWidth);
481 float yScale = crop.getHeight() / float(winHeight);
482
483 float insetL = winCrop.left * xScale;
484 float insetT = winCrop.top * yScale;
485 float insetR = (winWidth - winCrop.right ) * xScale;
486 float insetB = (winHeight - winCrop.bottom) * yScale;
487
488 crop.left += insetL;
489 crop.top += insetT;
490 crop.right -= insetR;
491 crop.bottom -= insetB;
492
Mathias Agopian13127d82013-03-05 17:47:11 -0800493 return crop;
494}
495
Dan Stoza9e56aa02015-11-02 13:00:03 -0800496#ifdef USE_HWC2
497void Layer::setGeometry(const sp<const DisplayDevice>& displayDevice)
498#else
Mathias Agopian4fec8732012-06-29 14:12:52 -0700499void Layer::setGeometry(
Mathias Agopian42977342012-08-05 00:40:46 -0700500 const sp<const DisplayDevice>& hw,
Mathias Agopian4fec8732012-06-29 14:12:52 -0700501 HWComposer::HWCLayerInterface& layer)
Dan Stoza9e56aa02015-11-02 13:00:03 -0800502#endif
Mathias Agopiana350ff92010-08-10 17:14:02 -0700503{
Dan Stoza9e56aa02015-11-02 13:00:03 -0800504#ifdef USE_HWC2
505 const auto hwcId = displayDevice->getHwcDisplayId();
506 auto& hwcInfo = mHwcLayers[hwcId];
507#else
Mathias Agopian13127d82013-03-05 17:47:11 -0800508 layer.setDefaultState();
Dan Stoza9e56aa02015-11-02 13:00:03 -0800509#endif
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700510
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700511 // enable this layer
Dan Stoza9e56aa02015-11-02 13:00:03 -0800512#ifdef USE_HWC2
513 hwcInfo.forceClientComposition = false;
514
515 if (isSecure() && !displayDevice->isSecure()) {
516 hwcInfo.forceClientComposition = true;
517 }
518
519 auto& hwcLayer = hwcInfo.layer;
520#else
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700521 layer.setSkip(false);
Mathias Agopiana350ff92010-08-10 17:14:02 -0700522
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700523 if (isSecure() && !hw->isSecure()) {
524 layer.setSkip(true);
525 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800526#endif
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700527
Mathias Agopian13127d82013-03-05 17:47:11 -0800528 // this gives us only the "orientation" component of the transform
Mathias Agopian1eae0ee2013-06-05 16:59:15 -0700529 const State& s(getDrawingState());
Dan Stoza9e56aa02015-11-02 13:00:03 -0800530#ifdef USE_HWC2
531 if (!isOpaque(s) || s.alpha != 1.0f) {
532 auto blendMode = mPremultipliedAlpha ?
533 HWC2::BlendMode::Premultiplied : HWC2::BlendMode::Coverage;
534 auto error = hwcLayer->setBlendMode(blendMode);
535 ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set blend mode %s:"
536 " %s (%d)", mName.string(), to_string(blendMode).c_str(),
537 to_string(error).c_str(), static_cast<int32_t>(error));
538 }
539#else
Andy McFadden4125a4f2014-01-29 17:17:11 -0800540 if (!isOpaque(s) || s.alpha != 0xFF) {
Mathias Agopian13127d82013-03-05 17:47:11 -0800541 layer.setBlending(mPremultipliedAlpha ?
542 HWC_BLENDING_PREMULT :
543 HWC_BLENDING_COVERAGE);
544 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800545#endif
Mathias Agopian13127d82013-03-05 17:47:11 -0800546
547 // apply the layer's transform, followed by the display's global transform
548 // here we're guaranteed that the layer's transform preserves rects
Michael Lentine6c925ed2014-09-26 17:55:01 -0700549 Region activeTransparentRegion(s.activeTransparentRegion);
Robert Carrb5d3d262016-03-25 15:08:13 -0700550 if (!s.crop.isEmpty()) {
551 Rect activeCrop(s.crop);
Robert Carr3dcabfa2016-03-01 18:36:58 -0800552 activeCrop = s.active.transform.transform(activeCrop);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800553#ifdef USE_HWC2
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000554 if(!activeCrop.intersect(displayDevice->getViewport(), &activeCrop)) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800555#else
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000556 if(!activeCrop.intersect(hw->getViewport(), &activeCrop)) {
Dan Stoza9e56aa02015-11-02 13:00:03 -0800557#endif
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000558 activeCrop.clear();
559 }
Pablo Ceballos51450032016-08-03 10:20:45 -0700560 activeCrop = s.active.transform.inverse().transform(activeCrop, true);
Michael Lentine28ea2172014-11-19 18:32:37 -0800561 // This needs to be here as transform.transform(Rect) computes the
562 // transformed rect and then takes the bounding box of the result before
563 // returning. This means
564 // transform.inverse().transform(transform.transform(Rect)) != Rect
565 // in which case we need to make sure the final rect is clipped to the
566 // display bounds.
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000567 if(!activeCrop.intersect(Rect(s.active.w, s.active.h), &activeCrop)) {
568 activeCrop.clear();
569 }
Michael Lentine6c925ed2014-09-26 17:55:01 -0700570 // mark regions outside the crop as transparent
571 activeTransparentRegion.orSelf(Rect(0, 0, s.active.w, activeCrop.top));
572 activeTransparentRegion.orSelf(Rect(0, activeCrop.bottom,
573 s.active.w, s.active.h));
574 activeTransparentRegion.orSelf(Rect(0, activeCrop.top,
575 activeCrop.left, activeCrop.bottom));
576 activeTransparentRegion.orSelf(Rect(activeCrop.right, activeCrop.top,
577 s.active.w, activeCrop.bottom));
578 }
Robert Carr3dcabfa2016-03-01 18:36:58 -0800579 Rect frame(s.active.transform.transform(computeBounds(activeTransparentRegion)));
Robert Carrb5d3d262016-03-25 15:08:13 -0700580 if (!s.finalCrop.isEmpty()) {
581 if(!frame.intersect(s.finalCrop, &frame)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000582 frame.clear();
583 }
584 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800585#ifdef USE_HWC2
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000586 if (!frame.intersect(displayDevice->getViewport(), &frame)) {
587 frame.clear();
588 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800589 const Transform& tr(displayDevice->getTransform());
590 Rect transformedFrame = tr.transform(frame);
591 auto error = hwcLayer->setDisplayFrame(transformedFrame);
Dan Stozae22aec72016-08-01 13:20:59 -0700592 if (error != HWC2::Error::None) {
593 ALOGE("[%s] Failed to set display frame [%d, %d, %d, %d]: %s (%d)",
594 mName.string(), transformedFrame.left, transformedFrame.top,
595 transformedFrame.right, transformedFrame.bottom,
596 to_string(error).c_str(), static_cast<int32_t>(error));
597 } else {
598 hwcInfo.displayFrame = transformedFrame;
599 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800600
601 FloatRect sourceCrop = computeCrop(displayDevice);
602 error = hwcLayer->setSourceCrop(sourceCrop);
Dan Stozae22aec72016-08-01 13:20:59 -0700603 if (error != HWC2::Error::None) {
604 ALOGE("[%s] Failed to set source crop [%.3f, %.3f, %.3f, %.3f]: "
605 "%s (%d)", mName.string(), sourceCrop.left, sourceCrop.top,
606 sourceCrop.right, sourceCrop.bottom, to_string(error).c_str(),
607 static_cast<int32_t>(error));
608 } else {
609 hwcInfo.sourceCrop = sourceCrop;
610 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800611
612 error = hwcLayer->setPlaneAlpha(s.alpha);
613 ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set plane alpha %.3f: "
614 "%s (%d)", mName.string(), s.alpha, to_string(error).c_str(),
615 static_cast<int32_t>(error));
616
617 error = hwcLayer->setZOrder(s.z);
618 ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set Z %u: %s (%d)",
619 mName.string(), s.z, to_string(error).c_str(),
620 static_cast<int32_t>(error));
621#else
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000622 if (!frame.intersect(hw->getViewport(), &frame)) {
623 frame.clear();
624 }
Mathias Agopian13127d82013-03-05 17:47:11 -0800625 const Transform& tr(hw->getTransform());
626 layer.setFrame(tr.transform(frame));
627 layer.setCrop(computeCrop(hw));
Mathias Agopian9f8386e2013-01-29 18:56:42 -0800628 layer.setPlaneAlpha(s.alpha);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800629#endif
Mathias Agopian9f8386e2013-01-29 18:56:42 -0800630
Mathias Agopian29a367b2011-07-12 14:51:45 -0700631 /*
632 * Transformations are applied in this order:
633 * 1) buffer orientation/flip/mirror
634 * 2) state transformation (window manager)
635 * 3) layer orientation (screen orientation)
636 * (NOTE: the matrices are multiplied in reverse order)
637 */
638
639 const Transform bufferOrientation(mCurrentTransform);
Robert Carr3dcabfa2016-03-01 18:36:58 -0800640 Transform transform(tr * s.active.transform * bufferOrientation);
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700641
642 if (mSurfaceFlingerConsumer->getTransformToDisplayInverse()) {
643 /*
Pablo Ceballos021623b2016-04-15 17:31:51 -0700644 * the code below applies the primary display's inverse transform to the
645 * buffer
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700646 */
Pablo Ceballos021623b2016-04-15 17:31:51 -0700647 uint32_t invTransform =
648 DisplayDevice::getPrimaryDisplayOrientationTransform();
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700649 // calculate the inverse transform
650 if (invTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
651 invTransform ^= NATIVE_WINDOW_TRANSFORM_FLIP_V |
652 NATIVE_WINDOW_TRANSFORM_FLIP_H;
653 }
654 // and apply to the current transform
Pablo Ceballos0f5131f2016-05-17 13:34:45 -0700655 transform = Transform(invTransform) * transform;
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700656 }
Mathias Agopian29a367b2011-07-12 14:51:45 -0700657
658 // this gives us only the "orientation" component of the transform
Mathias Agopian13127d82013-03-05 17:47:11 -0800659 const uint32_t orientation = transform.getOrientation();
Dan Stoza9e56aa02015-11-02 13:00:03 -0800660#ifdef USE_HWC2
661 if (orientation & Transform::ROT_INVALID) {
662 // we can only handle simple transformation
663 hwcInfo.forceClientComposition = true;
664 } else {
665 auto transform = static_cast<HWC2::Transform>(orientation);
666 auto error = hwcLayer->setTransform(transform);
667 ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set transform %s: "
668 "%s (%d)", mName.string(), to_string(transform).c_str(),
669 to_string(error).c_str(), static_cast<int32_t>(error));
670 }
671#else
Mathias Agopian13127d82013-03-05 17:47:11 -0800672 if (orientation & Transform::ROT_INVALID) {
673 // we can only handle simple transformation
Mathias Agopian3e8b8532012-05-13 20:42:01 -0700674 layer.setSkip(true);
Mathias Agopiana537c0f2011-08-02 15:51:37 -0700675 } else {
Mathias Agopian13127d82013-03-05 17:47:11 -0800676 layer.setTransform(orientation);
Mathias Agopiana350ff92010-08-10 17:14:02 -0700677 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800678#endif
Mathias Agopiana350ff92010-08-10 17:14:02 -0700679}
680
Dan Stoza9e56aa02015-11-02 13:00:03 -0800681#ifdef USE_HWC2
682void Layer::forceClientComposition(int32_t hwcId) {
683 if (mHwcLayers.count(hwcId) == 0) {
684 ALOGE("forceClientComposition: no HWC layer found (%d)", hwcId);
685 return;
686 }
687
688 mHwcLayers[hwcId].forceClientComposition = true;
689}
690#endif
691
692#ifdef USE_HWC2
693void Layer::setPerFrameData(const sp<const DisplayDevice>& displayDevice) {
694 // Apply this display's projection's viewport to the visible region
695 // before giving it to the HWC HAL.
696 const Transform& tr = displayDevice->getTransform();
697 const auto& viewport = displayDevice->getViewport();
698 Region visible = tr.transform(visibleRegion.intersect(viewport));
699 auto hwcId = displayDevice->getHwcDisplayId();
700 auto& hwcLayer = mHwcLayers[hwcId].layer;
701 auto error = hwcLayer->setVisibleRegion(visible);
702 if (error != HWC2::Error::None) {
703 ALOGE("[%s] Failed to set visible region: %s (%d)", mName.string(),
704 to_string(error).c_str(), static_cast<int32_t>(error));
705 visible.dump(LOG_TAG);
706 }
707
708 error = hwcLayer->setSurfaceDamage(surfaceDamageRegion);
709 if (error != HWC2::Error::None) {
710 ALOGE("[%s] Failed to set surface damage: %s (%d)", mName.string(),
711 to_string(error).c_str(), static_cast<int32_t>(error));
712 surfaceDamageRegion.dump(LOG_TAG);
713 }
714
Dan Stoza0f67b3f2016-05-17 10:48:38 -0700715 // Sideband layers
Dan Stoza9e56aa02015-11-02 13:00:03 -0800716 if (mSidebandStream.get()) {
Dan Stoza0f67b3f2016-05-17 10:48:38 -0700717 setCompositionType(hwcId, HWC2::Composition::Sideband);
718 ALOGV("[%s] Requesting Sideband composition", mName.string());
719 error = hwcLayer->setSidebandStream(mSidebandStream->handle());
Dan Stoza9e56aa02015-11-02 13:00:03 -0800720 if (error != HWC2::Error::None) {
721 ALOGE("[%s] Failed to set sideband stream %p: %s (%d)",
722 mName.string(), mSidebandStream->handle(),
723 to_string(error).c_str(), static_cast<int32_t>(error));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800724 }
Dan Stoza0f67b3f2016-05-17 10:48:38 -0700725 return;
Dan Stoza9e56aa02015-11-02 13:00:03 -0800726 }
727
Dan Stoza0a21df72016-07-20 12:52:38 -0700728 // Client layers
729 if (mHwcLayers[hwcId].forceClientComposition ||
730 (mActiveBuffer != nullptr && mActiveBuffer->handle == nullptr)) {
Dan Stoza0f67b3f2016-05-17 10:48:38 -0700731 ALOGV("[%s] Requesting Client composition", mName.string());
Dan Stoza9e56aa02015-11-02 13:00:03 -0800732 setCompositionType(hwcId, HWC2::Composition::Client);
Dan Stoza0f67b3f2016-05-17 10:48:38 -0700733 return;
734 }
735
Dan Stoza0a21df72016-07-20 12:52:38 -0700736 // SolidColor layers
737 if (mActiveBuffer == nullptr) {
738 setCompositionType(hwcId, HWC2::Composition::SolidColor);
Dan Stozac6c89542016-07-27 10:16:52 -0700739
740 // For now, we only support black for DimLayer
Dan Stoza0a21df72016-07-20 12:52:38 -0700741 error = hwcLayer->setColor({0, 0, 0, 255});
742 if (error != HWC2::Error::None) {
743 ALOGE("[%s] Failed to set color: %s (%d)", mName.string(),
744 to_string(error).c_str(), static_cast<int32_t>(error));
745 }
Dan Stozac6c89542016-07-27 10:16:52 -0700746
747 // Clear out the transform, because it doesn't make sense absent a
748 // source buffer
749 error = hwcLayer->setTransform(HWC2::Transform::None);
750 if (error != HWC2::Error::None) {
751 ALOGE("[%s] Failed to clear transform: %s (%d)", mName.string(),
752 to_string(error).c_str(), static_cast<int32_t>(error));
753 }
754
Dan Stoza0a21df72016-07-20 12:52:38 -0700755 return;
756 }
757
Dan Stoza0f67b3f2016-05-17 10:48:38 -0700758 // Device or Cursor layers
759 if (mPotentialCursor) {
760 ALOGV("[%s] Requesting Cursor composition", mName.string());
761 setCompositionType(hwcId, HWC2::Composition::Cursor);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800762 } else {
763 ALOGV("[%s] Requesting Device composition", mName.string());
764 setCompositionType(hwcId, HWC2::Composition::Device);
765 }
Dan Stoza0f67b3f2016-05-17 10:48:38 -0700766
767 auto acquireFence = mSurfaceFlingerConsumer->getCurrentFence();
768 error = hwcLayer->setBuffer(mActiveBuffer->handle, acquireFence);
769 if (error != HWC2::Error::None) {
770 ALOGE("[%s] Failed to set buffer %p: %s (%d)", mName.string(),
771 mActiveBuffer->handle, to_string(error).c_str(),
772 static_cast<int32_t>(error));
773 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800774}
775#else
Mathias Agopian42977342012-08-05 00:40:46 -0700776void Layer::setPerFrameData(const sp<const DisplayDevice>& hw,
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700777 HWComposer::HWCLayerInterface& layer) {
Mathias Agopian13127d82013-03-05 17:47:11 -0800778 // we have to set the visible region on every frame because
779 // we currently free it during onLayerDisplayed(), which is called
780 // after HWComposer::commit() -- every frame.
781 // Apply this display's projection's viewport to the visible region
782 // before giving it to the HWC HAL.
783 const Transform& tr = hw->getTransform();
784 Region visible = tr.transform(visibleRegion.intersect(hw->getViewport()));
785 layer.setVisibleRegionScreen(visible);
Dan Stozadb4850c2015-06-25 16:10:18 -0700786 layer.setSurfaceDamage(surfaceDamageRegion);
Pablo Ceballos40845df2016-01-25 17:41:15 -0800787 mIsGlesComposition = (layer.getCompositionType() == HWC_FRAMEBUFFER);
Dan Stozaee44edd2015-03-23 15:50:23 -0700788
Jesse Hall399184a2014-03-03 15:42:54 -0800789 if (mSidebandStream.get()) {
790 layer.setSidebandStream(mSidebandStream);
791 } else {
792 // NOTE: buffer can be NULL if the client never drew into this
793 // layer yet, or if we ran out of memory
794 layer.setBuffer(mActiveBuffer);
795 }
Jesse Hallc5c5a142012-07-02 16:49:28 -0700796}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800797#endif
Jesse Halldc5b4852012-06-29 15:21:18 -0700798
Dan Stoza9e56aa02015-11-02 13:00:03 -0800799#ifdef USE_HWC2
800void Layer::updateCursorPosition(const sp<const DisplayDevice>& displayDevice) {
801 auto hwcId = displayDevice->getHwcDisplayId();
802 if (mHwcLayers.count(hwcId) == 0 ||
803 getCompositionType(hwcId) != HWC2::Composition::Cursor) {
804 return;
805 }
806
807 // This gives us only the "orientation" component of the transform
808 const State& s(getCurrentState());
809
810 // Apply the layer's transform, followed by the display's global transform
811 // Here we're guaranteed that the layer's transform preserves rects
812 Rect win(s.active.w, s.active.h);
Robert Carrb5d3d262016-03-25 15:08:13 -0700813 if (!s.crop.isEmpty()) {
814 win.intersect(s.crop, &win);
Dan Stoza9e56aa02015-11-02 13:00:03 -0800815 }
816 // Subtract the transparent region and snap to the bounds
817 Rect bounds = reduce(win, s.activeTransparentRegion);
Dan Stozabaf416d2016-03-10 11:57:08 -0800818 Rect frame(s.active.transform.transform(bounds));
Dan Stoza9e56aa02015-11-02 13:00:03 -0800819 frame.intersect(displayDevice->getViewport(), &frame);
Robert Carrb5d3d262016-03-25 15:08:13 -0700820 if (!s.finalCrop.isEmpty()) {
821 frame.intersect(s.finalCrop, &frame);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000822 }
Dan Stoza9e56aa02015-11-02 13:00:03 -0800823 auto& displayTransform(displayDevice->getTransform());
824 auto position = displayTransform.transform(frame);
825
826 auto error = mHwcLayers[hwcId].layer->setCursorPosition(position.left,
827 position.top);
828 ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set cursor position "
829 "to (%d, %d): %s (%d)", mName.string(), position.left,
830 position.top, to_string(error).c_str(),
831 static_cast<int32_t>(error));
832}
833#else
Dan Stozac7014012014-02-14 15:03:43 -0800834void Layer::setAcquireFence(const sp<const DisplayDevice>& /* hw */,
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700835 HWComposer::HWCLayerInterface& layer) {
Jesse Hallc5c5a142012-07-02 16:49:28 -0700836 int fenceFd = -1;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700837
838 // TODO: there is a possible optimization here: we only need to set the
839 // acquire fence the first time a new buffer is acquired on EACH display.
840
Riley Andrews03414a12014-07-01 14:22:59 -0700841 if (layer.getCompositionType() == HWC_OVERLAY || layer.getCompositionType() == HWC_CURSOR_OVERLAY) {
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800842 sp<Fence> fence = mSurfaceFlingerConsumer->getCurrentFence();
Jamie Gennis1df8c342012-12-20 14:05:45 -0800843 if (fence->isValid()) {
Jesse Hallc5c5a142012-07-02 16:49:28 -0700844 fenceFd = fence->dup();
Jesse Halldc5b4852012-06-29 15:21:18 -0700845 if (fenceFd == -1) {
846 ALOGW("failed to dup layer fence, skipping sync: %d", errno);
847 }
Jesse Halldc5b4852012-06-29 15:21:18 -0700848 }
Jesse Halldc5b4852012-06-29 15:21:18 -0700849 }
Jesse Hallc5c5a142012-07-02 16:49:28 -0700850 layer.setAcquireFenceFd(fenceFd);
Mathias Agopiana350ff92010-08-10 17:14:02 -0700851}
852
Riley Andrews03414a12014-07-01 14:22:59 -0700853Rect Layer::getPosition(
854 const sp<const DisplayDevice>& hw)
855{
856 // this gives us only the "orientation" component of the transform
857 const State& s(getCurrentState());
858
859 // apply the layer's transform, followed by the display's global transform
860 // here we're guaranteed that the layer's transform preserves rects
861 Rect win(s.active.w, s.active.h);
Robert Carrb5d3d262016-03-25 15:08:13 -0700862 if (!s.crop.isEmpty()) {
863 win.intersect(s.crop, &win);
Riley Andrews03414a12014-07-01 14:22:59 -0700864 }
865 // subtract the transparent region and snap to the bounds
866 Rect bounds = reduce(win, s.activeTransparentRegion);
Robert Carr3dcabfa2016-03-01 18:36:58 -0800867 Rect frame(s.active.transform.transform(bounds));
Riley Andrews03414a12014-07-01 14:22:59 -0700868 frame.intersect(hw->getViewport(), &frame);
Robert Carrb5d3d262016-03-25 15:08:13 -0700869 if (!s.finalCrop.isEmpty()) {
870 frame.intersect(s.finalCrop, &frame);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000871 }
Riley Andrews03414a12014-07-01 14:22:59 -0700872 const Transform& tr(hw->getTransform());
873 return Rect(tr.transform(frame));
874}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800875#endif
Riley Andrews03414a12014-07-01 14:22:59 -0700876
Mathias Agopian13127d82013-03-05 17:47:11 -0800877// ---------------------------------------------------------------------------
878// drawing...
879// ---------------------------------------------------------------------------
880
881void Layer::draw(const sp<const DisplayDevice>& hw, const Region& clip) const {
Dan Stozac7014012014-02-14 15:03:43 -0800882 onDraw(hw, clip, false);
Mathias Agopian13127d82013-03-05 17:47:11 -0800883}
884
Dan Stozac7014012014-02-14 15:03:43 -0800885void Layer::draw(const sp<const DisplayDevice>& hw,
886 bool useIdentityTransform) const {
887 onDraw(hw, Region(hw->bounds()), useIdentityTransform);
Mathias Agopian13127d82013-03-05 17:47:11 -0800888}
889
Dan Stozac7014012014-02-14 15:03:43 -0800890void Layer::draw(const sp<const DisplayDevice>& hw) const {
891 onDraw(hw, Region(hw->bounds()), false);
892}
893
894void Layer::onDraw(const sp<const DisplayDevice>& hw, const Region& clip,
895 bool useIdentityTransform) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800896{
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800897 ATRACE_CALL();
898
Mathias Agopiana67932f2011-04-20 14:20:59 -0700899 if (CC_UNLIKELY(mActiveBuffer == 0)) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800900 // the texture has not been created yet, this Layer has
Mathias Agopian179169e2010-05-06 20:21:45 -0700901 // in fact never been drawn into. This happens frequently with
902 // SurfaceView because the WindowManager can't know when the client
903 // has drawn the first time.
904
905 // If there is nothing under us, we paint the screen in black, otherwise
906 // we just skip this update.
907
908 // figure out if there is something below us
909 Region under;
Mathias Agopianf7ae69d2011-08-23 12:34:29 -0700910 const SurfaceFlinger::LayerVector& drawingLayers(
911 mFlinger->mDrawingState.layersSortedByZ);
Mathias Agopian179169e2010-05-06 20:21:45 -0700912 const size_t count = drawingLayers.size();
913 for (size_t i=0 ; i<count ; ++i) {
Mathias Agopian13127d82013-03-05 17:47:11 -0800914 const sp<Layer>& layer(drawingLayers[i]);
915 if (layer.get() == static_cast<Layer const*>(this))
Mathias Agopian179169e2010-05-06 20:21:45 -0700916 break;
Mathias Agopian42977342012-08-05 00:40:46 -0700917 under.orSelf( hw->getTransform().transform(layer->visibleRegion) );
Mathias Agopian179169e2010-05-06 20:21:45 -0700918 }
919 // if not everything below us is covered, we plug the holes!
920 Region holes(clip.subtract(under));
921 if (!holes.isEmpty()) {
Mathias Agopian1b031492012-06-20 17:51:20 -0700922 clearWithOpenGL(hw, holes, 0, 0, 0, 1);
Mathias Agopian179169e2010-05-06 20:21:45 -0700923 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800924 return;
925 }
Mathias Agopiana67932f2011-04-20 14:20:59 -0700926
Andy McFadden97eba892012-12-11 15:21:45 -0800927 // Bind the current buffer to the GL texture, and wait for it to be
928 // ready for us to draw into.
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800929 status_t err = mSurfaceFlingerConsumer->bindTextureImage();
930 if (err != NO_ERROR) {
Andy McFadden97eba892012-12-11 15:21:45 -0800931 ALOGW("onDraw: bindTextureImage failed (err=%d)", err);
Jesse Halldc5b4852012-06-29 15:21:18 -0700932 // Go ahead and draw the buffer anyway; no matter what we do the screen
933 // is probably going to have something visibly wrong.
934 }
935
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700936 bool blackOutLayer = isProtected() || (isSecure() && !hw->isSecure());
937
Mathias Agopian875d8e12013-06-07 15:35:48 -0700938 RenderEngine& engine(mFlinger->getRenderEngine());
939
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700940 if (!blackOutLayer) {
Jamie Genniscbb1a952012-05-08 17:05:52 -0700941 // TODO: we could be more subtle with isFixedSize()
Mathias Agopianeba8c682012-09-19 23:14:45 -0700942 const bool useFiltering = getFiltering() || needsFiltering(hw) || isFixedSize();
Jamie Genniscbb1a952012-05-08 17:05:52 -0700943
944 // Query the texture matrix given our current filtering mode.
945 float textureMatrix[16];
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800946 mSurfaceFlingerConsumer->setFilteringEnabled(useFiltering);
947 mSurfaceFlingerConsumer->getTransformMatrix(textureMatrix);
Jamie Genniscbb1a952012-05-08 17:05:52 -0700948
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700949 if (mSurfaceFlingerConsumer->getTransformToDisplayInverse()) {
950
951 /*
Pablo Ceballos021623b2016-04-15 17:31:51 -0700952 * the code below applies the primary display's inverse transform to
953 * the texture transform
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700954 */
955
956 // create a 4x4 transform matrix from the display transform flags
957 const mat4 flipH(-1,0,0,0, 0,1,0,0, 0,0,1,0, 1,0,0,1);
958 const mat4 flipV( 1,0,0,0, 0,-1,0,0, 0,0,1,0, 0,1,0,1);
959 const mat4 rot90( 0,1,0,0, -1,0,0,0, 0,0,1,0, 1,0,0,1);
960
961 mat4 tr;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700962 uint32_t transform =
963 DisplayDevice::getPrimaryDisplayOrientationTransform();
Mathias Agopianc1c05de2013-09-17 23:45:22 -0700964 if (transform & NATIVE_WINDOW_TRANSFORM_ROT_90)
965 tr = tr * rot90;
966 if (transform & NATIVE_WINDOW_TRANSFORM_FLIP_H)
967 tr = tr * flipH;
968 if (transform & NATIVE_WINDOW_TRANSFORM_FLIP_V)
969 tr = tr * flipV;
970
971 // calculate the inverse
972 tr = inverse(tr);
973
974 // and finally apply it to the original texture matrix
975 const mat4 texTransform(mat4(static_cast<const float*>(textureMatrix)) * tr);
976 memcpy(textureMatrix, texTransform.asArray(), sizeof(textureMatrix));
977 }
978
Jamie Genniscbb1a952012-05-08 17:05:52 -0700979 // Set things up for texturing.
Mathias Agopian49457ac2013-08-14 18:20:17 -0700980 mTexture.setDimensions(mActiveBuffer->getWidth(), mActiveBuffer->getHeight());
981 mTexture.setFiltering(useFiltering);
982 mTexture.setMatrix(textureMatrix);
983
984 engine.setupLayerTexturing(mTexture);
Mathias Agopiana67932f2011-04-20 14:20:59 -0700985 } else {
Mathias Agopian875d8e12013-06-07 15:35:48 -0700986 engine.setupLayerBlackedOut();
Mathias Agopiana67932f2011-04-20 14:20:59 -0700987 }
Dan Stozac7014012014-02-14 15:03:43 -0800988 drawWithOpenGL(hw, clip, useIdentityTransform);
Mathias Agopian875d8e12013-06-07 15:35:48 -0700989 engine.disableTexturing();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800990}
991
Mathias Agopian13127d82013-03-05 17:47:11 -0800992
Dan Stozac7014012014-02-14 15:03:43 -0800993void Layer::clearWithOpenGL(const sp<const DisplayDevice>& hw,
994 const Region& /* clip */, float red, float green, float blue,
995 float alpha) const
Mathias Agopian13127d82013-03-05 17:47:11 -0800996{
Mathias Agopian19733a32013-08-28 18:13:56 -0700997 RenderEngine& engine(mFlinger->getRenderEngine());
Dan Stozac7014012014-02-14 15:03:43 -0800998 computeGeometry(hw, mMesh, false);
Mathias Agopian19733a32013-08-28 18:13:56 -0700999 engine.setupFillWithColor(red, green, blue, alpha);
1000 engine.drawMesh(mMesh);
Mathias Agopian13127d82013-03-05 17:47:11 -08001001}
1002
1003void Layer::clearWithOpenGL(
1004 const sp<const DisplayDevice>& hw, const Region& clip) const {
1005 clearWithOpenGL(hw, clip, 0,0,0,0);
1006}
1007
Dan Stozac7014012014-02-14 15:03:43 -08001008void Layer::drawWithOpenGL(const sp<const DisplayDevice>& hw,
1009 const Region& /* clip */, bool useIdentityTransform) const {
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001010 const State& s(getDrawingState());
Mathias Agopian13127d82013-03-05 17:47:11 -08001011
Dan Stozac7014012014-02-14 15:03:43 -08001012 computeGeometry(hw, mMesh, useIdentityTransform);
Mathias Agopian13127d82013-03-05 17:47:11 -08001013
Mathias Agopian13127d82013-03-05 17:47:11 -08001014 /*
1015 * NOTE: the way we compute the texture coordinates here produces
1016 * different results than when we take the HWC path -- in the later case
1017 * the "source crop" is rounded to texel boundaries.
1018 * This can produce significantly different results when the texture
1019 * is scaled by a large amount.
1020 *
1021 * The GL code below is more logical (imho), and the difference with
1022 * HWC is due to a limitation of the HWC API to integers -- a question
Mathias Agopianc1c05de2013-09-17 23:45:22 -07001023 * is suspend is whether we should ignore this problem or revert to
Mathias Agopian13127d82013-03-05 17:47:11 -08001024 * GL composition when a buffer scaling is applied (maybe with some
1025 * minimal value)? Or, we could make GL behave like HWC -- but this feel
1026 * like more of a hack.
1027 */
Pablo Ceballosacbe6782016-03-04 17:54:21 +00001028 Rect win(computeBounds());
1029
Robert Carrb5d3d262016-03-25 15:08:13 -07001030 if (!s.finalCrop.isEmpty()) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +00001031 win = s.active.transform.transform(win);
Robert Carrb5d3d262016-03-25 15:08:13 -07001032 if (!win.intersect(s.finalCrop, &win)) {
Pablo Ceballosacbe6782016-03-04 17:54:21 +00001033 win.clear();
1034 }
1035 win = s.active.transform.inverse().transform(win);
1036 if (!win.intersect(computeBounds(), &win)) {
1037 win.clear();
1038 }
1039 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001040
Mathias Agopian3f844832013-08-07 21:24:32 -07001041 float left = float(win.left) / float(s.active.w);
1042 float top = float(win.top) / float(s.active.h);
1043 float right = float(win.right) / float(s.active.w);
1044 float bottom = float(win.bottom) / float(s.active.h);
Mathias Agopian13127d82013-03-05 17:47:11 -08001045
Mathias Agopian875d8e12013-06-07 15:35:48 -07001046 // TODO: we probably want to generate the texture coords with the mesh
1047 // here we assume that we only have 4 vertices
Mathias Agopianff2ed702013-09-01 21:36:12 -07001048 Mesh::VertexArray<vec2> texCoords(mMesh.getTexCoordArray<vec2>());
1049 texCoords[0] = vec2(left, 1.0f - top);
1050 texCoords[1] = vec2(left, 1.0f - bottom);
1051 texCoords[2] = vec2(right, 1.0f - bottom);
1052 texCoords[3] = vec2(right, 1.0f - top);
Mathias Agopian13127d82013-03-05 17:47:11 -08001053
Mathias Agopian875d8e12013-06-07 15:35:48 -07001054 RenderEngine& engine(mFlinger->getRenderEngine());
Andy McFadden4125a4f2014-01-29 17:17:11 -08001055 engine.setupLayerBlending(mPremultipliedAlpha, isOpaque(s), s.alpha);
Mathias Agopian5cdc8992013-08-13 20:51:23 -07001056 engine.drawMesh(mMesh);
Mathias Agopian875d8e12013-06-07 15:35:48 -07001057 engine.disableBlending();
Mathias Agopian13127d82013-03-05 17:47:11 -08001058}
1059
Dan Stoza9e56aa02015-11-02 13:00:03 -08001060#ifdef USE_HWC2
1061void Layer::setCompositionType(int32_t hwcId, HWC2::Composition type,
1062 bool callIntoHwc) {
1063 if (mHwcLayers.count(hwcId) == 0) {
1064 ALOGE("setCompositionType called without a valid HWC layer");
1065 return;
1066 }
1067 auto& hwcInfo = mHwcLayers[hwcId];
1068 auto& hwcLayer = hwcInfo.layer;
1069 ALOGV("setCompositionType(%" PRIx64 ", %s, %d)", hwcLayer->getId(),
1070 to_string(type).c_str(), static_cast<int>(callIntoHwc));
1071 if (hwcInfo.compositionType != type) {
1072 ALOGV(" actually setting");
1073 hwcInfo.compositionType = type;
1074 if (callIntoHwc) {
1075 auto error = hwcLayer->setCompositionType(type);
1076 ALOGE_IF(error != HWC2::Error::None, "[%s] Failed to set "
1077 "composition type %s: %s (%d)", mName.string(),
1078 to_string(type).c_str(), to_string(error).c_str(),
1079 static_cast<int32_t>(error));
1080 }
1081 }
1082}
1083
1084HWC2::Composition Layer::getCompositionType(int32_t hwcId) const {
Dan Stozaec0f7172016-07-21 11:09:40 -07001085 if (hwcId == DisplayDevice::DISPLAY_ID_INVALID) {
1086 // If we're querying the composition type for a display that does not
1087 // have a HWC counterpart, then it will always be Client
1088 return HWC2::Composition::Client;
1089 }
Dan Stoza9e56aa02015-11-02 13:00:03 -08001090 if (mHwcLayers.count(hwcId) == 0) {
Dan Stozaec0f7172016-07-21 11:09:40 -07001091 ALOGE("getCompositionType called with an invalid HWC layer");
Dan Stoza9e56aa02015-11-02 13:00:03 -08001092 return HWC2::Composition::Invalid;
1093 }
1094 return mHwcLayers.at(hwcId).compositionType;
1095}
1096
1097void Layer::setClearClientTarget(int32_t hwcId, bool clear) {
1098 if (mHwcLayers.count(hwcId) == 0) {
1099 ALOGE("setClearClientTarget called without a valid HWC layer");
1100 return;
1101 }
1102 mHwcLayers[hwcId].clearClientTarget = clear;
1103}
1104
1105bool Layer::getClearClientTarget(int32_t hwcId) const {
1106 if (mHwcLayers.count(hwcId) == 0) {
1107 ALOGE("getClearClientTarget called without a valid HWC layer");
1108 return false;
1109 }
1110 return mHwcLayers.at(hwcId).clearClientTarget;
1111}
1112#endif
1113
Ruben Brunk1681d952014-06-27 15:51:55 -07001114uint32_t Layer::getProducerStickyTransform() const {
1115 int producerStickyTransform = 0;
1116 int ret = mProducer->query(NATIVE_WINDOW_STICKY_TRANSFORM, &producerStickyTransform);
1117 if (ret != OK) {
1118 ALOGW("%s: Error %s (%d) while querying window sticky transform.", __FUNCTION__,
1119 strerror(-ret), ret);
1120 return 0;
1121 }
1122 return static_cast<uint32_t>(producerStickyTransform);
1123}
1124
Dan Stozac5da2712016-07-20 15:38:12 -07001125bool Layer::latchUnsignaledBuffers() {
1126 static bool propertyLoaded = false;
1127 static bool latch = false;
1128 static std::mutex mutex;
1129 std::lock_guard<std::mutex> lock(mutex);
1130 if (!propertyLoaded) {
1131 char value[PROPERTY_VALUE_MAX] = {};
1132 property_get("debug.sf.latch_unsignaled", value, "0");
1133 latch = atoi(value);
1134 propertyLoaded = true;
1135 }
1136 return latch;
1137}
1138
Dan Stozacac35382016-01-27 12:21:06 -08001139uint64_t Layer::getHeadFrameNumber() const {
1140 Mutex::Autolock lock(mQueueItemLock);
1141 if (!mQueueItems.empty()) {
1142 return mQueueItems[0].mFrameNumber;
1143 } else {
1144 return mCurrentFrameNumber;
1145 }
1146}
1147
Dan Stoza1ce65812016-06-15 16:26:27 -07001148bool Layer::headFenceHasSignaled() const {
1149#ifdef USE_HWC2
Dan Stozac5da2712016-07-20 15:38:12 -07001150 if (latchUnsignaledBuffers()) {
1151 return true;
1152 }
1153
Dan Stoza1ce65812016-06-15 16:26:27 -07001154 Mutex::Autolock lock(mQueueItemLock);
1155 if (mQueueItems.empty()) {
1156 return true;
1157 }
1158 if (mQueueItems[0].mIsDroppable) {
1159 // Even though this buffer's fence may not have signaled yet, it could
1160 // be replaced by another buffer before it has a chance to, which means
1161 // that it's possible to get into a situation where a buffer is never
1162 // able to be latched. To avoid this, grab this buffer anyway.
1163 return true;
1164 }
1165 return mQueueItems[0].mFence->getSignalTime() != INT64_MAX;
1166#else
1167 return true;
1168#endif
1169}
1170
Dan Stozacac35382016-01-27 12:21:06 -08001171bool Layer::addSyncPoint(const std::shared_ptr<SyncPoint>& point) {
1172 if (point->getFrameNumber() <= mCurrentFrameNumber) {
1173 // Don't bother with a SyncPoint, since we've already latched the
1174 // relevant frame
1175 return false;
Dan Stoza7dde5992015-05-22 09:51:44 -07001176 }
1177
Dan Stozacac35382016-01-27 12:21:06 -08001178 Mutex::Autolock lock(mLocalSyncPointMutex);
1179 mLocalSyncPoints.push_back(point);
1180 return true;
Dan Stoza7dde5992015-05-22 09:51:44 -07001181}
1182
Mathias Agopian13127d82013-03-05 17:47:11 -08001183void Layer::setFiltering(bool filtering) {
1184 mFiltering = filtering;
1185}
1186
1187bool Layer::getFiltering() const {
1188 return mFiltering;
1189}
1190
Eric Hassoldac45e6b2011-02-10 14:41:26 -08001191// As documented in libhardware header, formats in the range
1192// 0x100 - 0x1FF are specific to the HAL implementation, and
1193// are known to have no alpha channel
1194// TODO: move definition for device-specific range into
1195// hardware.h, instead of using hard-coded values here.
1196#define HARDWARE_IS_DEVICE_FORMAT(f) ((f) >= 0x100 && (f) <= 0x1FF)
1197
Mathias Agopian5773d3f2013-07-25 19:24:31 -07001198bool Layer::getOpacityForFormat(uint32_t format) {
Mathias Agopiana67932f2011-04-20 14:20:59 -07001199 if (HARDWARE_IS_DEVICE_FORMAT(format)) {
1200 return true;
Eric Hassoldac45e6b2011-02-10 14:41:26 -08001201 }
Mathias Agopian5773d3f2013-07-25 19:24:31 -07001202 switch (format) {
1203 case HAL_PIXEL_FORMAT_RGBA_8888:
1204 case HAL_PIXEL_FORMAT_BGRA_8888:
Mathias Agopiandd533712013-07-26 15:31:39 -07001205 return false;
Mathias Agopian5773d3f2013-07-25 19:24:31 -07001206 }
1207 // in all other case, we have no blending (also for unknown formats)
Mathias Agopiandd533712013-07-26 15:31:39 -07001208 return true;
Eric Hassoldac45e6b2011-02-10 14:41:26 -08001209}
1210
Mathias Agopian13127d82013-03-05 17:47:11 -08001211// ----------------------------------------------------------------------------
1212// local state
1213// ----------------------------------------------------------------------------
1214
Pablo Ceballosacbe6782016-03-04 17:54:21 +00001215static void boundPoint(vec2* point, const Rect& crop) {
1216 if (point->x < crop.left) {
1217 point->x = crop.left;
1218 }
1219 if (point->x > crop.right) {
1220 point->x = crop.right;
1221 }
1222 if (point->y < crop.top) {
1223 point->y = crop.top;
1224 }
1225 if (point->y > crop.bottom) {
1226 point->y = crop.bottom;
1227 }
1228}
1229
Dan Stozac7014012014-02-14 15:03:43 -08001230void Layer::computeGeometry(const sp<const DisplayDevice>& hw, Mesh& mesh,
1231 bool useIdentityTransform) const
Mathias Agopian13127d82013-03-05 17:47:11 -08001232{
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001233 const Layer::State& s(getDrawingState());
Pablo Ceballosacbe6782016-03-04 17:54:21 +00001234 const Transform tr(hw->getTransform());
Mathias Agopian13127d82013-03-05 17:47:11 -08001235 const uint32_t hw_h = hw->getHeight();
1236 Rect win(s.active.w, s.active.h);
Robert Carrb5d3d262016-03-25 15:08:13 -07001237 if (!s.crop.isEmpty()) {
1238 win.intersect(s.crop, &win);
Mathias Agopian13127d82013-03-05 17:47:11 -08001239 }
Mathias Agopian6c7f25a2013-05-09 20:37:10 -07001240 // subtract the transparent region and snap to the bounds
Mathias Agopianf3e85d42013-05-10 18:01:12 -07001241 win = reduce(win, s.activeTransparentRegion);
Mathias Agopian3f844832013-08-07 21:24:32 -07001242
Pablo Ceballosacbe6782016-03-04 17:54:21 +00001243 vec2 lt = vec2(win.left, win.top);
1244 vec2 lb = vec2(win.left, win.bottom);
1245 vec2 rb = vec2(win.right, win.bottom);
1246 vec2 rt = vec2(win.right, win.top);
1247
1248 if (!useIdentityTransform) {
1249 lt = s.active.transform.transform(lt);
1250 lb = s.active.transform.transform(lb);
1251 rb = s.active.transform.transform(rb);
1252 rt = s.active.transform.transform(rt);
1253 }
1254
Robert Carrb5d3d262016-03-25 15:08:13 -07001255 if (!s.finalCrop.isEmpty()) {
1256 boundPoint(&lt, s.finalCrop);
1257 boundPoint(&lb, s.finalCrop);
1258 boundPoint(&rb, s.finalCrop);
1259 boundPoint(&rt, s.finalCrop);
Pablo Ceballosacbe6782016-03-04 17:54:21 +00001260 }
1261
Mathias Agopianff2ed702013-09-01 21:36:12 -07001262 Mesh::VertexArray<vec2> position(mesh.getPositionArray<vec2>());
Pablo Ceballosacbe6782016-03-04 17:54:21 +00001263 position[0] = tr.transform(lt);
1264 position[1] = tr.transform(lb);
1265 position[2] = tr.transform(rb);
1266 position[3] = tr.transform(rt);
Mathias Agopian3f844832013-08-07 21:24:32 -07001267 for (size_t i=0 ; i<4 ; i++) {
Mathias Agopian5cdc8992013-08-13 20:51:23 -07001268 position[i].y = hw_h - position[i].y;
Mathias Agopian13127d82013-03-05 17:47:11 -08001269 }
1270}
Eric Hassoldac45e6b2011-02-10 14:41:26 -08001271
Andy McFadden4125a4f2014-01-29 17:17:11 -08001272bool Layer::isOpaque(const Layer::State& s) const
Mathias Agopiana7f66922010-05-26 22:08:52 -07001273{
Mathias Agopiana67932f2011-04-20 14:20:59 -07001274 // if we don't have a buffer yet, we're translucent regardless of the
1275 // layer's opaque flag.
Jamie Gennisdb5230f2011-07-28 14:54:07 -07001276 if (mActiveBuffer == 0) {
Mathias Agopiana67932f2011-04-20 14:20:59 -07001277 return false;
Jamie Gennisdb5230f2011-07-28 14:54:07 -07001278 }
Mathias Agopiana67932f2011-04-20 14:20:59 -07001279
1280 // if the layer has the opaque flag, then we're always opaque,
1281 // otherwise we use the current buffer's format.
Andy McFadden4125a4f2014-01-29 17:17:11 -08001282 return ((s.flags & layer_state_t::eLayerOpaque) != 0) || mCurrentOpacity;
Mathias Agopiana7f66922010-05-26 22:08:52 -07001283}
1284
Dan Stoza23116082015-06-18 14:58:39 -07001285bool Layer::isSecure() const
1286{
1287 const Layer::State& s(mDrawingState);
1288 return (s.flags & layer_state_t::eLayerSecure);
1289}
1290
Jamie Gennis7a4d0df2011-03-09 17:05:02 -08001291bool Layer::isProtected() const
1292{
Mathias Agopiana67932f2011-04-20 14:20:59 -07001293 const sp<GraphicBuffer>& activeBuffer(mActiveBuffer);
Jamie Gennis7a4d0df2011-03-09 17:05:02 -08001294 return (activeBuffer != 0) &&
1295 (activeBuffer->getUsage() & GRALLOC_USAGE_PROTECTED);
1296}
Mathias Agopianb5b7f262010-05-07 15:58:44 -07001297
Mathias Agopian13127d82013-03-05 17:47:11 -08001298bool Layer::isFixedSize() const {
Robert Carrc3574f72016-03-24 12:19:32 -07001299 return getEffectiveScalingMode() != NATIVE_WINDOW_SCALING_MODE_FREEZE;
Mathias Agopian13127d82013-03-05 17:47:11 -08001300}
1301
1302bool Layer::isCropped() const {
1303 return !mCurrentCrop.isEmpty();
1304}
1305
1306bool Layer::needsFiltering(const sp<const DisplayDevice>& hw) const {
1307 return mNeedsFiltering || hw->needsFiltering();
1308}
1309
1310void Layer::setVisibleRegion(const Region& visibleRegion) {
1311 // always called from main thread
1312 this->visibleRegion = visibleRegion;
1313}
1314
1315void Layer::setCoveredRegion(const Region& coveredRegion) {
1316 // always called from main thread
1317 this->coveredRegion = coveredRegion;
1318}
1319
1320void Layer::setVisibleNonTransparentRegion(const Region&
1321 setVisibleNonTransparentRegion) {
1322 // always called from main thread
1323 this->visibleNonTransparentRegion = setVisibleNonTransparentRegion;
1324}
1325
1326// ----------------------------------------------------------------------------
1327// transaction
1328// ----------------------------------------------------------------------------
1329
Dan Stoza7dde5992015-05-22 09:51:44 -07001330void Layer::pushPendingState() {
1331 if (!mCurrentState.modified) {
1332 return;
1333 }
1334
Dan Stoza7dde5992015-05-22 09:51:44 -07001335 // If this transaction is waiting on the receipt of a frame, generate a sync
1336 // point and send it to the remote layer.
1337 if (mCurrentState.handle != nullptr) {
Dan Stoza92cd24e2016-08-09 13:21:03 -07001338 sp<IBinder> strongBinder = mCurrentState.handle.promote();
1339 sp<Handle> handle = nullptr;
1340 sp<Layer> handleLayer = nullptr;
1341 if (strongBinder != nullptr) {
1342 handle = static_cast<Handle*>(strongBinder.get());
1343 handleLayer = handle->owner.promote();
1344 }
1345 if (strongBinder == nullptr || handleLayer == nullptr) {
Dan Stoza7dde5992015-05-22 09:51:44 -07001346 ALOGE("[%s] Unable to promote Layer handle", mName.string());
1347 // If we can't promote the layer we are intended to wait on,
1348 // then it is expired or otherwise invalid. Allow this transaction
1349 // to be applied as per normal (no synchronization).
1350 mCurrentState.handle = nullptr;
Pablo Ceballos3bddd5b2015-11-19 14:39:14 -08001351 } else {
1352 auto syncPoint = std::make_shared<SyncPoint>(
1353 mCurrentState.frameNumber);
Dan Stozacac35382016-01-27 12:21:06 -08001354 if (handleLayer->addSyncPoint(syncPoint)) {
1355 mRemoteSyncPoints.push_back(std::move(syncPoint));
1356 } else {
1357 // We already missed the frame we're supposed to synchronize
1358 // on, so go ahead and apply the state update
1359 mCurrentState.handle = nullptr;
1360 }
Dan Stoza7dde5992015-05-22 09:51:44 -07001361 }
1362
Dan Stoza7dde5992015-05-22 09:51:44 -07001363 // Wake us up to check if the frame has been received
1364 setTransactionFlags(eTransactionNeeded);
1365 }
1366 mPendingStates.push_back(mCurrentState);
1367}
1368
Pablo Ceballos05289c22016-04-14 15:49:55 -07001369void Layer::popPendingState(State* stateToCommit) {
1370 auto oldFlags = stateToCommit->flags;
1371 *stateToCommit = mPendingStates[0];
1372 stateToCommit->flags = (oldFlags & ~stateToCommit->mask) |
1373 (stateToCommit->flags & stateToCommit->mask);
Dan Stoza7dde5992015-05-22 09:51:44 -07001374
1375 mPendingStates.removeAt(0);
1376}
1377
Pablo Ceballos05289c22016-04-14 15:49:55 -07001378bool Layer::applyPendingStates(State* stateToCommit) {
Dan Stoza7dde5992015-05-22 09:51:44 -07001379 bool stateUpdateAvailable = false;
1380 while (!mPendingStates.empty()) {
1381 if (mPendingStates[0].handle != nullptr) {
1382 if (mRemoteSyncPoints.empty()) {
1383 // If we don't have a sync point for this, apply it anyway. It
1384 // will be visually wrong, but it should keep us from getting
1385 // into too much trouble.
1386 ALOGE("[%s] No local sync point found", mName.string());
Pablo Ceballos05289c22016-04-14 15:49:55 -07001387 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -07001388 stateUpdateAvailable = true;
1389 continue;
1390 }
1391
Dan Stozacac35382016-01-27 12:21:06 -08001392 if (mRemoteSyncPoints.front()->getFrameNumber() !=
1393 mPendingStates[0].frameNumber) {
1394 ALOGE("[%s] Unexpected sync point frame number found",
1395 mName.string());
1396
1397 // Signal our end of the sync point and then dispose of it
1398 mRemoteSyncPoints.front()->setTransactionApplied();
1399 mRemoteSyncPoints.pop_front();
1400 continue;
1401 }
1402
Dan Stoza7dde5992015-05-22 09:51:44 -07001403 if (mRemoteSyncPoints.front()->frameIsAvailable()) {
1404 // Apply the state update
Pablo Ceballos05289c22016-04-14 15:49:55 -07001405 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -07001406 stateUpdateAvailable = true;
1407
1408 // Signal our end of the sync point and then dispose of it
1409 mRemoteSyncPoints.front()->setTransactionApplied();
1410 mRemoteSyncPoints.pop_front();
Dan Stoza792e5292016-02-11 11:43:58 -08001411 } else {
1412 break;
Dan Stoza7dde5992015-05-22 09:51:44 -07001413 }
Dan Stoza7dde5992015-05-22 09:51:44 -07001414 } else {
Pablo Ceballos05289c22016-04-14 15:49:55 -07001415 popPendingState(stateToCommit);
Dan Stoza7dde5992015-05-22 09:51:44 -07001416 stateUpdateAvailable = true;
1417 }
1418 }
1419
1420 // If we still have pending updates, wake SurfaceFlinger back up and point
1421 // it at this layer so we can process them
1422 if (!mPendingStates.empty()) {
1423 setTransactionFlags(eTransactionNeeded);
1424 mFlinger->setTransactionFlags(eTraversalNeeded);
1425 }
1426
1427 mCurrentState.modified = false;
1428 return stateUpdateAvailable;
1429}
1430
1431void Layer::notifyAvailableFrames() {
Dan Stozacac35382016-01-27 12:21:06 -08001432 auto headFrameNumber = getHeadFrameNumber();
Dan Stoza1ce65812016-06-15 16:26:27 -07001433 bool headFenceSignaled = headFenceHasSignaled();
Dan Stozacac35382016-01-27 12:21:06 -08001434 Mutex::Autolock lock(mLocalSyncPointMutex);
1435 for (auto& point : mLocalSyncPoints) {
Dan Stoza1ce65812016-06-15 16:26:27 -07001436 if (headFrameNumber >= point->getFrameNumber() && headFenceSignaled) {
Dan Stozacac35382016-01-27 12:21:06 -08001437 point->setFrameAvailable();
1438 }
Dan Stoza7dde5992015-05-22 09:51:44 -07001439 }
1440}
1441
Mathias Agopian13127d82013-03-05 17:47:11 -08001442uint32_t Layer::doTransaction(uint32_t flags) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -08001443 ATRACE_CALL();
1444
Dan Stoza7dde5992015-05-22 09:51:44 -07001445 pushPendingState();
Pablo Ceballos05289c22016-04-14 15:49:55 -07001446 Layer::State c = getCurrentState();
1447 if (!applyPendingStates(&c)) {
Dan Stoza7dde5992015-05-22 09:51:44 -07001448 return 0;
1449 }
1450
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001451 const Layer::State& s(getDrawingState());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001452
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001453 const bool sizeChanged = (c.requested.w != s.requested.w) ||
1454 (c.requested.h != s.requested.h);
Mathias Agopiana138f892010-05-21 17:24:35 -07001455
1456 if (sizeChanged) {
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001457 // the size changed, we need to ask our client to request a new buffer
Steve Block9d453682011-12-20 16:23:08 +00001458 ALOGD_IF(DEBUG_RESIZE,
Andy McFadden69052052012-09-14 16:10:11 -07001459 "doTransaction: geometry (layer=%p '%s'), tr=%02x, scalingMode=%d\n"
Mathias Agopian419e1962012-05-23 14:34:07 -07001460 " current={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
Robert Carrb5d3d262016-03-25 15:08:13 -07001461 " requested={ wh={%4u,%4u} }}\n"
Mathias Agopian419e1962012-05-23 14:34:07 -07001462 " drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
Robert Carrb5d3d262016-03-25 15:08:13 -07001463 " requested={ wh={%4u,%4u} }}\n",
Robert Carrc3574f72016-03-24 12:19:32 -07001464 this, getName().string(), mCurrentTransform,
1465 getEffectiveScalingMode(),
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001466 c.active.w, c.active.h,
Robert Carrb5d3d262016-03-25 15:08:13 -07001467 c.crop.left,
1468 c.crop.top,
1469 c.crop.right,
1470 c.crop.bottom,
1471 c.crop.getWidth(),
1472 c.crop.getHeight(),
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001473 c.requested.w, c.requested.h,
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001474 s.active.w, s.active.h,
Robert Carrb5d3d262016-03-25 15:08:13 -07001475 s.crop.left,
1476 s.crop.top,
1477 s.crop.right,
1478 s.crop.bottom,
1479 s.crop.getWidth(),
1480 s.crop.getHeight(),
1481 s.requested.w, s.requested.h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001482
Jamie Gennis2a0d5b62011-09-26 16:54:44 -07001483 // record the new size, form this point on, when the client request
1484 // a buffer, it'll get the new size.
Andy McFaddenbf974ab2012-12-04 16:51:15 -08001485 mSurfaceFlingerConsumer->setDefaultBufferSize(
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001486 c.requested.w, c.requested.h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001487 }
Mathias Agopiancbb288b2009-09-07 16:32:45 -07001488
Robert Carr82364e32016-05-15 11:27:47 -07001489 const bool resizePending = (c.requested.w != c.active.w) ||
1490 (c.requested.h != c.active.h);
Mathias Agopian0cd545f2012-06-07 14:18:55 -07001491 if (!isFixedSize()) {
Dan Stoza9e9b0442015-04-22 14:59:08 -07001492 if (resizePending && mSidebandStream == NULL) {
Mathias Agopian13127d82013-03-05 17:47:11 -08001493 // don't let Layer::doTransaction update the drawing state
Mathias Agopian0cd545f2012-06-07 14:18:55 -07001494 // if we have a pending resize, unless we are in fixed-size mode.
1495 // the drawing state will be updated only once we receive a buffer
1496 // with the correct size.
1497 //
1498 // in particular, we want to make sure the clip (which is part
1499 // of the geometry state) is latched together with the size but is
1500 // latched immediately when no resizing is involved.
Dan Stoza9e9b0442015-04-22 14:59:08 -07001501 //
1502 // If a sideband stream is attached, however, we want to skip this
1503 // optimization so that transactions aren't missed when a buffer
1504 // never arrives
Mathias Agopian0cd545f2012-06-07 14:18:55 -07001505
1506 flags |= eDontUpdateGeometryState;
1507 }
1508 }
1509
Mathias Agopian13127d82013-03-05 17:47:11 -08001510 // always set active to requested, unless we're asked not to
1511 // this is used by Layer, which special cases resizes.
1512 if (flags & eDontUpdateGeometryState) {
1513 } else {
Pablo Ceballos7d052572016-06-02 17:46:05 -07001514 Layer::State& editCurrentState(getCurrentState());
Robert Carr82364e32016-05-15 11:27:47 -07001515 if (mFreezePositionUpdates) {
1516 float tx = c.active.transform.tx();
1517 float ty = c.active.transform.ty();
1518 c.active = c.requested;
1519 c.active.transform.set(tx, ty);
1520 editCurrentState.active = c.active;
1521 } else {
1522 editCurrentState.active = editCurrentState.requested;
1523 c.active = c.requested;
1524 }
Mathias Agopian13127d82013-03-05 17:47:11 -08001525 }
1526
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001527 if (s.active != c.active) {
Mathias Agopian13127d82013-03-05 17:47:11 -08001528 // invalidate and recompute the visible regions if needed
1529 flags |= Layer::eVisibleRegion;
1530 }
1531
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07001532 if (c.sequence != s.sequence) {
Mathias Agopian13127d82013-03-05 17:47:11 -08001533 // invalidate and recompute the visible regions if needed
1534 flags |= eVisibleRegion;
1535 this->contentDirty = true;
1536
1537 // we may use linear filtering, if the matrix scales us
Robert Carr3dcabfa2016-03-01 18:36:58 -08001538 const uint8_t type = c.active.transform.getType();
1539 mNeedsFiltering = (!c.active.transform.preserveRects() ||
Mathias Agopian13127d82013-03-05 17:47:11 -08001540 (type >= Transform::SCALE));
1541 }
1542
Dan Stozac8145172016-04-28 16:29:06 -07001543 // If the layer is hidden, signal and clear out all local sync points so
1544 // that transactions for layers depending on this layer's frames becoming
1545 // visible are not blocked
1546 if (c.flags & layer_state_t::eLayerHidden) {
1547 Mutex::Autolock lock(mLocalSyncPointMutex);
1548 for (auto& point : mLocalSyncPoints) {
1549 point->setFrameAvailable();
1550 }
1551 mLocalSyncPoints.clear();
1552 }
1553
Mathias Agopian13127d82013-03-05 17:47:11 -08001554 // Commit the transaction
Pablo Ceballos05289c22016-04-14 15:49:55 -07001555 commitTransaction(c);
Mathias Agopian13127d82013-03-05 17:47:11 -08001556 return flags;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001557}
1558
Pablo Ceballos05289c22016-04-14 15:49:55 -07001559void Layer::commitTransaction(const State& stateToCommit) {
1560 mDrawingState = stateToCommit;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001561}
1562
Mathias Agopian13127d82013-03-05 17:47:11 -08001563uint32_t Layer::getTransactionFlags(uint32_t flags) {
1564 return android_atomic_and(~flags, &mTransactionFlags) & flags;
1565}
1566
1567uint32_t Layer::setTransactionFlags(uint32_t flags) {
1568 return android_atomic_or(flags, &mTransactionFlags);
1569}
1570
Robert Carr82364e32016-05-15 11:27:47 -07001571bool Layer::setPosition(float x, float y, bool immediate) {
Robert Carr3dcabfa2016-03-01 18:36:58 -08001572 if (mCurrentState.requested.transform.tx() == x && mCurrentState.requested.transform.ty() == y)
Mathias Agopian13127d82013-03-05 17:47:11 -08001573 return false;
1574 mCurrentState.sequence++;
Robert Carr69663fb2016-03-27 19:59:19 -07001575
1576 // We update the requested and active position simultaneously because
1577 // we want to apply the position portion of the transform matrix immediately,
1578 // but still delay scaling when resizing a SCALING_MODE_FREEZE layer.
Robert Carr3dcabfa2016-03-01 18:36:58 -08001579 mCurrentState.requested.transform.set(x, y);
Robert Carr82364e32016-05-15 11:27:47 -07001580 if (immediate && !mFreezePositionUpdates) {
1581 mCurrentState.active.transform.set(x, y);
1582 }
1583 mFreezePositionUpdates = mFreezePositionUpdates || !immediate;
Robert Carr69663fb2016-03-27 19:59:19 -07001584
Dan Stoza7dde5992015-05-22 09:51:44 -07001585 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001586 setTransactionFlags(eTransactionNeeded);
1587 return true;
1588}
Robert Carr82364e32016-05-15 11:27:47 -07001589
Mathias Agopian13127d82013-03-05 17:47:11 -08001590bool Layer::setLayer(uint32_t z) {
1591 if (mCurrentState.z == z)
1592 return false;
1593 mCurrentState.sequence++;
1594 mCurrentState.z = z;
Dan Stoza7dde5992015-05-22 09:51:44 -07001595 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001596 setTransactionFlags(eTransactionNeeded);
1597 return true;
1598}
1599bool Layer::setSize(uint32_t w, uint32_t h) {
1600 if (mCurrentState.requested.w == w && mCurrentState.requested.h == h)
1601 return false;
1602 mCurrentState.requested.w = w;
1603 mCurrentState.requested.h = h;
Dan Stoza7dde5992015-05-22 09:51:44 -07001604 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001605 setTransactionFlags(eTransactionNeeded);
1606 return true;
1607}
Dan Stoza9e56aa02015-11-02 13:00:03 -08001608#ifdef USE_HWC2
1609bool Layer::setAlpha(float alpha) {
1610#else
Mathias Agopian13127d82013-03-05 17:47:11 -08001611bool Layer::setAlpha(uint8_t alpha) {
Dan Stoza9e56aa02015-11-02 13:00:03 -08001612#endif
Mathias Agopian13127d82013-03-05 17:47:11 -08001613 if (mCurrentState.alpha == alpha)
1614 return false;
1615 mCurrentState.sequence++;
1616 mCurrentState.alpha = alpha;
Dan Stoza7dde5992015-05-22 09:51:44 -07001617 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001618 setTransactionFlags(eTransactionNeeded);
1619 return true;
1620}
1621bool Layer::setMatrix(const layer_state_t::matrix22_t& matrix) {
1622 mCurrentState.sequence++;
Robert Carr3dcabfa2016-03-01 18:36:58 -08001623 mCurrentState.requested.transform.set(
Mathias Agopian13127d82013-03-05 17:47:11 -08001624 matrix.dsdx, matrix.dsdy, matrix.dtdx, matrix.dtdy);
Dan Stoza7dde5992015-05-22 09:51:44 -07001625 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001626 setTransactionFlags(eTransactionNeeded);
1627 return true;
1628}
1629bool Layer::setTransparentRegionHint(const Region& transparent) {
Mathias Agopian2ca79392013-04-02 18:30:32 -07001630 mCurrentState.requestedTransparentRegion = transparent;
Dan Stoza7dde5992015-05-22 09:51:44 -07001631 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001632 setTransactionFlags(eTransactionNeeded);
1633 return true;
1634}
1635bool Layer::setFlags(uint8_t flags, uint8_t mask) {
1636 const uint32_t newFlags = (mCurrentState.flags & ~mask) | (flags & mask);
1637 if (mCurrentState.flags == newFlags)
1638 return false;
1639 mCurrentState.sequence++;
1640 mCurrentState.flags = newFlags;
Dan Stoza7dde5992015-05-22 09:51:44 -07001641 mCurrentState.mask = mask;
1642 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001643 setTransactionFlags(eTransactionNeeded);
1644 return true;
1645}
Robert Carr99e27f02016-06-16 15:18:02 -07001646
1647bool Layer::setCrop(const Rect& crop, bool immediate) {
Robert Carrb5d3d262016-03-25 15:08:13 -07001648 if (mCurrentState.crop == crop)
Mathias Agopian13127d82013-03-05 17:47:11 -08001649 return false;
1650 mCurrentState.sequence++;
Robert Carr99e27f02016-06-16 15:18:02 -07001651 mCurrentState.requestedCrop = crop;
1652 if (immediate) {
1653 mCurrentState.crop = crop;
1654 }
Dan Stoza7dde5992015-05-22 09:51:44 -07001655 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001656 setTransactionFlags(eTransactionNeeded);
1657 return true;
1658}
Pablo Ceballosacbe6782016-03-04 17:54:21 +00001659bool Layer::setFinalCrop(const Rect& crop) {
Robert Carrb5d3d262016-03-25 15:08:13 -07001660 if (mCurrentState.finalCrop == crop)
Pablo Ceballosacbe6782016-03-04 17:54:21 +00001661 return false;
1662 mCurrentState.sequence++;
Robert Carrb5d3d262016-03-25 15:08:13 -07001663 mCurrentState.finalCrop = crop;
Pablo Ceballosacbe6782016-03-04 17:54:21 +00001664 mCurrentState.modified = true;
1665 setTransactionFlags(eTransactionNeeded);
1666 return true;
1667}
Mathias Agopian13127d82013-03-05 17:47:11 -08001668
Robert Carrc3574f72016-03-24 12:19:32 -07001669bool Layer::setOverrideScalingMode(int32_t scalingMode) {
1670 if (scalingMode == mOverrideScalingMode)
1671 return false;
1672 mOverrideScalingMode = scalingMode;
Robert Carr82364e32016-05-15 11:27:47 -07001673 setTransactionFlags(eTransactionNeeded);
Robert Carrc3574f72016-03-24 12:19:32 -07001674 return true;
1675}
1676
1677uint32_t Layer::getEffectiveScalingMode() const {
1678 if (mOverrideScalingMode >= 0) {
1679 return mOverrideScalingMode;
1680 }
1681 return mCurrentScalingMode;
1682}
1683
Mathias Agopian13127d82013-03-05 17:47:11 -08001684bool Layer::setLayerStack(uint32_t layerStack) {
1685 if (mCurrentState.layerStack == layerStack)
1686 return false;
1687 mCurrentState.sequence++;
1688 mCurrentState.layerStack = layerStack;
Dan Stoza7dde5992015-05-22 09:51:44 -07001689 mCurrentState.modified = true;
Mathias Agopian13127d82013-03-05 17:47:11 -08001690 setTransactionFlags(eTransactionNeeded);
1691 return true;
Mathias Agopiana67932f2011-04-20 14:20:59 -07001692}
1693
Dan Stoza7dde5992015-05-22 09:51:44 -07001694void Layer::deferTransactionUntil(const sp<IBinder>& handle,
1695 uint64_t frameNumber) {
1696 mCurrentState.handle = handle;
1697 mCurrentState.frameNumber = frameNumber;
1698 // We don't set eTransactionNeeded, because just receiving a deferral
1699 // request without any other state updates shouldn't actually induce a delay
1700 mCurrentState.modified = true;
1701 pushPendingState();
Dan Stoza792e5292016-02-11 11:43:58 -08001702 mCurrentState.handle = nullptr;
1703 mCurrentState.frameNumber = 0;
Dan Stoza7dde5992015-05-22 09:51:44 -07001704 mCurrentState.modified = false;
1705}
1706
Dan Stozaee44edd2015-03-23 15:50:23 -07001707void Layer::useSurfaceDamage() {
1708 if (mFlinger->mForceFullDamage) {
1709 surfaceDamageRegion = Region::INVALID_REGION;
1710 } else {
1711 surfaceDamageRegion = mSurfaceFlingerConsumer->getSurfaceDamage();
1712 }
1713}
1714
1715void Layer::useEmptyDamage() {
1716 surfaceDamageRegion.clear();
1717}
1718
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001719// ----------------------------------------------------------------------------
1720// pageflip handling...
1721// ----------------------------------------------------------------------------
1722
Dan Stoza6b9454d2014-11-07 16:00:59 -08001723bool Layer::shouldPresentNow(const DispSync& dispSync) const {
Pablo Ceballosff95aab2016-01-13 17:09:58 -08001724 if (mSidebandStreamChanged || mAutoRefresh) {
Dan Stozad87defa2015-07-29 16:15:50 -07001725 return true;
1726 }
1727
Dan Stoza6b9454d2014-11-07 16:00:59 -08001728 Mutex::Autolock lock(mQueueItemLock);
Dan Stoza0eb2d392015-07-06 12:56:50 -07001729 if (mQueueItems.empty()) {
1730 return false;
1731 }
1732 auto timestamp = mQueueItems[0].mTimestamp;
Dan Stoza6b9454d2014-11-07 16:00:59 -08001733 nsecs_t expectedPresent =
1734 mSurfaceFlingerConsumer->computeExpectedPresent(dispSync);
Dan Stoza0eb2d392015-07-06 12:56:50 -07001735
1736 // Ignore timestamps more than a second in the future
1737 bool isPlausible = timestamp < (expectedPresent + s2ns(1));
1738 ALOGW_IF(!isPlausible, "[%s] Timestamp %" PRId64 " seems implausible "
1739 "relative to expectedPresent %" PRId64, mName.string(), timestamp,
1740 expectedPresent);
1741
1742 bool isDue = timestamp < expectedPresent;
1743 return isDue || !isPlausible;
Dan Stoza6b9454d2014-11-07 16:00:59 -08001744}
1745
Mathias Agopian4d143ee2012-02-23 20:05:39 -08001746bool Layer::onPreComposition() {
1747 mRefreshPending = false;
Pablo Ceballosff95aab2016-01-13 17:09:58 -08001748 return mQueuedFrames > 0 || mSidebandStreamChanged || mAutoRefresh;
Mathias Agopian99ce5cd2012-01-31 18:24:27 -08001749}
1750
Dan Stozae77c7662016-05-13 11:37:28 -07001751bool Layer::onPostComposition() {
1752 bool frameLatencyNeeded = mFrameLatencyNeeded;
Mathias Agopiand3ee2312012-08-02 14:01:42 -07001753 if (mFrameLatencyNeeded) {
Andy McFaddenbf974ab2012-12-04 16:51:15 -08001754 nsecs_t desiredPresentTime = mSurfaceFlingerConsumer->getTimestamp();
Jamie Gennis82dbc742012-11-08 19:23:28 -08001755 mFrameTracker.setDesiredPresentTime(desiredPresentTime);
1756
Andy McFaddenbf974ab2012-12-04 16:51:15 -08001757 sp<Fence> frameReadyFence = mSurfaceFlingerConsumer->getCurrentFence();
Jamie Gennis789a6c32013-02-25 13:37:54 -08001758 if (frameReadyFence->isValid()) {
Jamie Gennis82dbc742012-11-08 19:23:28 -08001759 mFrameTracker.setFrameReadyFence(frameReadyFence);
1760 } else {
1761 // There was no fence for this frame, so assume that it was ready
1762 // to be presented at the desired present time.
1763 mFrameTracker.setFrameReadyTime(desiredPresentTime);
1764 }
1765
Mathias Agopiand3ee2312012-08-02 14:01:42 -07001766 const HWComposer& hwc = mFlinger->getHwComposer();
Dan Stoza9e56aa02015-11-02 13:00:03 -08001767#ifdef USE_HWC2
1768 sp<Fence> presentFence = hwc.getRetireFence(HWC_DISPLAY_PRIMARY);
1769#else
Jamie Gennis82dbc742012-11-08 19:23:28 -08001770 sp<Fence> presentFence = hwc.getDisplayFence(HWC_DISPLAY_PRIMARY);
Dan Stoza9e56aa02015-11-02 13:00:03 -08001771#endif
Jamie Gennis789a6c32013-02-25 13:37:54 -08001772 if (presentFence->isValid()) {
Jamie Gennis82dbc742012-11-08 19:23:28 -08001773 mFrameTracker.setActualPresentFence(presentFence);
1774 } else {
1775 // The HWC doesn't support present fences, so use the refresh
1776 // timestamp instead.
1777 nsecs_t presentTime = hwc.getRefreshTimestamp(HWC_DISPLAY_PRIMARY);
1778 mFrameTracker.setActualPresentTime(presentTime);
1779 }
1780
1781 mFrameTracker.advanceFrame();
Mathias Agopiand3ee2312012-08-02 14:01:42 -07001782 mFrameLatencyNeeded = false;
1783 }
Dan Stozae77c7662016-05-13 11:37:28 -07001784 return frameLatencyNeeded;
Mathias Agopiand3ee2312012-08-02 14:01:42 -07001785}
1786
Dan Stoza9e56aa02015-11-02 13:00:03 -08001787#ifdef USE_HWC2
1788void Layer::releasePendingBuffer() {
1789 mSurfaceFlingerConsumer->releasePendingBuffer();
1790}
1791#endif
1792
Mathias Agopianda27af92012-09-13 18:17:13 -07001793bool Layer::isVisible() const {
Mathias Agopian13127d82013-03-05 17:47:11 -08001794 const Layer::State& s(mDrawingState);
Dan Stoza9e56aa02015-11-02 13:00:03 -08001795#ifdef USE_HWC2
1796 return !(s.flags & layer_state_t::eLayerHidden) && s.alpha > 0.0f
1797 && (mActiveBuffer != NULL || mSidebandStream != NULL);
1798#else
Mathias Agopian13127d82013-03-05 17:47:11 -08001799 return !(s.flags & layer_state_t::eLayerHidden) && s.alpha
Wonsik Kimafe30812014-03-31 23:16:08 +09001800 && (mActiveBuffer != NULL || mSidebandStream != NULL);
Dan Stoza9e56aa02015-11-02 13:00:03 -08001801#endif
Mathias Agopianda27af92012-09-13 18:17:13 -07001802}
1803
Mathias Agopian4fec8732012-06-29 14:12:52 -07001804Region Layer::latchBuffer(bool& recomputeVisibleRegions)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001805{
Jamie Gennis1c8e95c2012-02-23 19:27:23 -08001806 ATRACE_CALL();
1807
Jesse Hall399184a2014-03-03 15:42:54 -08001808 if (android_atomic_acquire_cas(true, false, &mSidebandStreamChanged) == 0) {
1809 // mSidebandStreamChanged was true
1810 mSidebandStream = mSurfaceFlingerConsumer->getSidebandStream();
Dan Stoza12e0a272015-05-05 14:00:52 -07001811 if (mSidebandStream != NULL) {
1812 setTransactionFlags(eTransactionNeeded);
1813 mFlinger->setTransactionFlags(eTraversalNeeded);
1814 }
Jesse Hall5bf786d2014-09-30 10:35:11 -07001815 recomputeVisibleRegions = true;
1816
1817 const State& s(getDrawingState());
Robert Carr3dcabfa2016-03-01 18:36:58 -08001818 return s.active.transform.transform(Region(Rect(s.active.w, s.active.h)));
Jesse Hall399184a2014-03-03 15:42:54 -08001819 }
1820
Mathias Agopian4fec8732012-06-29 14:12:52 -07001821 Region outDirtyRegion;
Pablo Ceballosff95aab2016-01-13 17:09:58 -08001822 if (mQueuedFrames > 0 || mAutoRefresh) {
Mathias Agopian99ce5cd2012-01-31 18:24:27 -08001823
1824 // if we've already called updateTexImage() without going through
1825 // a composition step, we have to skip this layer at this point
1826 // because we cannot call updateTeximage() without a corresponding
1827 // compositionComplete() call.
1828 // we'll trigger an update in onPreComposition().
Mathias Agopian4d143ee2012-02-23 20:05:39 -08001829 if (mRefreshPending) {
Mathias Agopian4fec8732012-06-29 14:12:52 -07001830 return outDirtyRegion;
Mathias Agopian99ce5cd2012-01-31 18:24:27 -08001831 }
1832
Dan Stoza1ce65812016-06-15 16:26:27 -07001833 // If the head buffer's acquire fence hasn't signaled yet, return and
1834 // try again later
1835 if (!headFenceHasSignaled()) {
1836 mFlinger->signalLayerUpdate();
1837 return outDirtyRegion;
1838 }
1839
Jamie Gennis351a5132011-09-14 18:23:37 -07001840 // Capture the old state of the layer for comparisons later
Andy McFadden4125a4f2014-01-29 17:17:11 -08001841 const State& s(getDrawingState());
1842 const bool oldOpacity = isOpaque(s);
Jamie Gennis351a5132011-09-14 18:23:37 -07001843 sp<GraphicBuffer> oldActiveBuffer = mActiveBuffer;
Jamie Gennisdb5230f2011-07-28 14:54:07 -07001844
Andy McFaddenbf974ab2012-12-04 16:51:15 -08001845 struct Reject : public SurfaceFlingerConsumer::BufferRejecter {
Mathias Agopian2c8207e2012-05-23 17:56:42 -07001846 Layer::State& front;
1847 Layer::State& current;
1848 bool& recomputeVisibleRegions;
Ruben Brunk1681d952014-06-27 15:51:55 -07001849 bool stickyTransformSet;
Robert Carrb5d3d262016-03-25 15:08:13 -07001850 const char* name;
Robert Carrc3574f72016-03-24 12:19:32 -07001851 int32_t overrideScalingMode;
Robert Carra3920732016-06-20 21:49:49 -07001852 bool& freezePositionUpdates;
Robert Carrb5d3d262016-03-25 15:08:13 -07001853
Mathias Agopian2c8207e2012-05-23 17:56:42 -07001854 Reject(Layer::State& front, Layer::State& current,
Robert Carrb5d3d262016-03-25 15:08:13 -07001855 bool& recomputeVisibleRegions, bool stickySet,
Robert Carrc3574f72016-03-24 12:19:32 -07001856 const char* name,
Robert Carra3920732016-06-20 21:49:49 -07001857 int32_t overrideScalingMode,
1858 bool& freezePositionUpdates)
Mathias Agopian2c8207e2012-05-23 17:56:42 -07001859 : front(front), current(current),
Ruben Brunk1681d952014-06-27 15:51:55 -07001860 recomputeVisibleRegions(recomputeVisibleRegions),
Robert Carrb5d3d262016-03-25 15:08:13 -07001861 stickyTransformSet(stickySet),
Robert Carrc3574f72016-03-24 12:19:32 -07001862 name(name),
Robert Carra3920732016-06-20 21:49:49 -07001863 overrideScalingMode(overrideScalingMode),
1864 freezePositionUpdates(freezePositionUpdates) {
Mathias Agopian2c8207e2012-05-23 17:56:42 -07001865 }
1866
1867 virtual bool reject(const sp<GraphicBuffer>& buf,
Dan Stoza11611f92015-03-12 15:12:44 -07001868 const BufferItem& item) {
Mathias Agopian2c8207e2012-05-23 17:56:42 -07001869 if (buf == NULL) {
1870 return false;
1871 }
1872
1873 uint32_t bufWidth = buf->getWidth();
1874 uint32_t bufHeight = buf->getHeight();
1875
1876 // check that we received a buffer of the right size
1877 // (Take the buffer's orientation into account)
1878 if (item.mTransform & Transform::ROT_90) {
1879 swap(bufWidth, bufHeight);
1880 }
1881
Robert Carrc3574f72016-03-24 12:19:32 -07001882 int actualScalingMode = overrideScalingMode >= 0 ?
1883 overrideScalingMode : item.mScalingMode;
1884 bool isFixedSize = actualScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE;
Mathias Agopian2c8207e2012-05-23 17:56:42 -07001885 if (front.active != front.requested) {
1886
1887 if (isFixedSize ||
1888 (bufWidth == front.requested.w &&
1889 bufHeight == front.requested.h))
1890 {
1891 // Here we pretend the transaction happened by updating the
1892 // current and drawing states. Drawing state is only accessed
1893 // in this thread, no need to have it locked
1894 front.active = front.requested;
1895
1896 // We also need to update the current state so that
1897 // we don't end-up overwriting the drawing state with
1898 // this stale current state during the next transaction
1899 //
1900 // NOTE: We don't need to hold the transaction lock here
1901 // because State::active is only accessed from this thread.
1902 current.active = front.active;
Pablo Ceballos39c88e82016-05-10 17:15:24 -07001903 current.modified = true;
Mathias Agopian2c8207e2012-05-23 17:56:42 -07001904
1905 // recompute visible region
1906 recomputeVisibleRegions = true;
1907 }
1908
1909 ALOGD_IF(DEBUG_RESIZE,
Robert Carrb5d3d262016-03-25 15:08:13 -07001910 "[%s] latchBuffer/reject: buffer (%ux%u, tr=%02x), scalingMode=%d\n"
Mathias Agopian2c8207e2012-05-23 17:56:42 -07001911 " drawing={ active ={ wh={%4u,%4u} crop={%4d,%4d,%4d,%4d} (%4d,%4d) }\n"
Robert Carrb5d3d262016-03-25 15:08:13 -07001912 " requested={ wh={%4u,%4u} }}\n",
1913 name,
Andy McFadden69052052012-09-14 16:10:11 -07001914 bufWidth, bufHeight, item.mTransform, item.mScalingMode,
Mathias Agopian2c8207e2012-05-23 17:56:42 -07001915 front.active.w, front.active.h,
Robert Carrb5d3d262016-03-25 15:08:13 -07001916 front.crop.left,
1917 front.crop.top,
1918 front.crop.right,
1919 front.crop.bottom,
1920 front.crop.getWidth(),
1921 front.crop.getHeight(),
1922 front.requested.w, front.requested.h);
Mathias Agopian2c8207e2012-05-23 17:56:42 -07001923 }
1924
Ruben Brunk1681d952014-06-27 15:51:55 -07001925 if (!isFixedSize && !stickyTransformSet) {
Mathias Agopian2c8207e2012-05-23 17:56:42 -07001926 if (front.active.w != bufWidth ||
1927 front.active.h != bufHeight) {
Mathias Agopian4824d402012-06-04 18:16:30 -07001928 // reject this buffer
Robert Carrb5d3d262016-03-25 15:08:13 -07001929 ALOGE("[%s] rejecting buffer: "
1930 "bufWidth=%d, bufHeight=%d, front.active.{w=%d, h=%d}",
1931 name, bufWidth, bufHeight, front.active.w, front.active.h);
Mathias Agopian2c8207e2012-05-23 17:56:42 -07001932 return true;
1933 }
1934 }
Mathias Agopian2ca79392013-04-02 18:30:32 -07001935
1936 // if the transparent region has changed (this test is
1937 // conservative, but that's fine, worst case we're doing
1938 // a bit of extra work), we latch the new one and we
1939 // trigger a visible-region recompute.
1940 if (!front.activeTransparentRegion.isTriviallyEqual(
1941 front.requestedTransparentRegion)) {
1942 front.activeTransparentRegion = front.requestedTransparentRegion;
Mathias Agopian6c67f0f2013-04-12 16:58:11 -07001943
1944 // We also need to update the current state so that
1945 // we don't end-up overwriting the drawing state with
1946 // this stale current state during the next transaction
1947 //
1948 // NOTE: We don't need to hold the transaction lock here
1949 // because State::active is only accessed from this thread.
1950 current.activeTransparentRegion = front.activeTransparentRegion;
1951
1952 // recompute visible region
Mathias Agopian2ca79392013-04-02 18:30:32 -07001953 recomputeVisibleRegions = true;
1954 }
1955
Robert Carr99e27f02016-06-16 15:18:02 -07001956 if (front.crop != front.requestedCrop) {
1957 front.crop = front.requestedCrop;
1958 current.crop = front.requestedCrop;
1959 recomputeVisibleRegions = true;
1960 }
Robert Carra3920732016-06-20 21:49:49 -07001961 freezePositionUpdates = false;
Robert Carr99e27f02016-06-16 15:18:02 -07001962
Mathias Agopian2c8207e2012-05-23 17:56:42 -07001963 return false;
1964 }
1965 };
1966
Ruben Brunk1681d952014-06-27 15:51:55 -07001967 Reject r(mDrawingState, getCurrentState(), recomputeVisibleRegions,
Robert Carrc3574f72016-03-24 12:19:32 -07001968 getProducerStickyTransform() != 0, mName.string(),
Robert Carra3920732016-06-20 21:49:49 -07001969 mOverrideScalingMode, mFreezePositionUpdates);
Mathias Agopian2c8207e2012-05-23 17:56:42 -07001970
Dan Stozacac35382016-01-27 12:21:06 -08001971
1972 // Check all of our local sync points to ensure that all transactions
1973 // which need to have been applied prior to the frame which is about to
1974 // be latched have signaled
1975
1976 auto headFrameNumber = getHeadFrameNumber();
1977 bool matchingFramesFound = false;
1978 bool allTransactionsApplied = true;
Dan Stozaa4650a52015-05-12 12:56:16 -07001979 {
Dan Stozacac35382016-01-27 12:21:06 -08001980 Mutex::Autolock lock(mLocalSyncPointMutex);
1981 for (auto& point : mLocalSyncPoints) {
1982 if (point->getFrameNumber() > headFrameNumber) {
1983 break;
1984 }
1985
1986 matchingFramesFound = true;
1987
1988 if (!point->frameIsAvailable()) {
1989 // We haven't notified the remote layer that the frame for
1990 // this point is available yet. Notify it now, and then
1991 // abort this attempt to latch.
1992 point->setFrameAvailable();
1993 allTransactionsApplied = false;
1994 break;
1995 }
1996
1997 allTransactionsApplied &= point->transactionIsApplied();
Dan Stoza7dde5992015-05-22 09:51:44 -07001998 }
1999 }
2000
Dan Stozacac35382016-01-27 12:21:06 -08002001 if (matchingFramesFound && !allTransactionsApplied) {
2002 mFlinger->signalLayerUpdate();
2003 return outDirtyRegion;
Dan Stozaa4650a52015-05-12 12:56:16 -07002004 }
2005
Pablo Ceballos06312182015-10-07 16:32:12 -07002006 // This boolean is used to make sure that SurfaceFlinger's shadow copy
2007 // of the buffer queue isn't modified when the buffer queue is returning
Pablo Ceballos2dcb3632016-03-17 15:50:23 -07002008 // BufferItem's that weren't actually queued. This can happen in shared
Pablo Ceballos06312182015-10-07 16:32:12 -07002009 // buffer mode.
2010 bool queuedBuffer = false;
Andy McFadden41d67d72014-04-25 16:58:34 -07002011 status_t updateResult = mSurfaceFlingerConsumer->updateTexImage(&r,
Pablo Ceballosff95aab2016-01-13 17:09:58 -08002012 mFlinger->mPrimaryDispSync, &mAutoRefresh, &queuedBuffer,
Dan Stozacac35382016-01-27 12:21:06 -08002013 mLastFrameNumberReceived);
Andy McFadden1585c4d2013-06-28 13:52:40 -07002014 if (updateResult == BufferQueue::PRESENT_LATER) {
2015 // Producer doesn't want buffer to be displayed yet. Signal a
2016 // layer update so we check again at the next opportunity.
2017 mFlinger->signalLayerUpdate();
2018 return outDirtyRegion;
Dan Stozaecc50402015-04-28 14:42:06 -07002019 } else if (updateResult == SurfaceFlingerConsumer::BUFFER_REJECTED) {
2020 // If the buffer has been rejected, remove it from the shadow queue
2021 // and return early
Pablo Ceballos06312182015-10-07 16:32:12 -07002022 if (queuedBuffer) {
2023 Mutex::Autolock lock(mQueueItemLock);
2024 mQueueItems.removeAt(0);
2025 android_atomic_dec(&mQueuedFrames);
2026 }
Dan Stozaecc50402015-04-28 14:42:06 -07002027 return outDirtyRegion;
Dan Stoza65476f32015-05-14 09:27:25 -07002028 } else if (updateResult != NO_ERROR || mUpdateTexImageFailed) {
2029 // This can occur if something goes wrong when trying to create the
2030 // EGLImage for this buffer. If this happens, the buffer has already
2031 // been released, so we need to clean up the queue and bug out
2032 // early.
Pablo Ceballos06312182015-10-07 16:32:12 -07002033 if (queuedBuffer) {
Dan Stoza65476f32015-05-14 09:27:25 -07002034 Mutex::Autolock lock(mQueueItemLock);
2035 mQueueItems.clear();
2036 android_atomic_and(0, &mQueuedFrames);
2037 }
2038
2039 // Once we have hit this state, the shadow queue may no longer
2040 // correctly reflect the incoming BufferQueue's contents, so even if
2041 // updateTexImage starts working, the only safe course of action is
2042 // to continue to ignore updates.
2043 mUpdateTexImageFailed = true;
2044
2045 return outDirtyRegion;
Andy McFadden1585c4d2013-06-28 13:52:40 -07002046 }
2047
Pablo Ceballos06312182015-10-07 16:32:12 -07002048 if (queuedBuffer) {
2049 // Autolock scope
Dan Stozaecc50402015-04-28 14:42:06 -07002050 auto currentFrameNumber = mSurfaceFlingerConsumer->getFrameNumber();
2051
Dan Stoza6b9454d2014-11-07 16:00:59 -08002052 Mutex::Autolock lock(mQueueItemLock);
Dan Stozaecc50402015-04-28 14:42:06 -07002053
2054 // Remove any stale buffers that have been dropped during
2055 // updateTexImage
2056 while (mQueueItems[0].mFrameNumber != currentFrameNumber) {
2057 mQueueItems.removeAt(0);
2058 android_atomic_dec(&mQueuedFrames);
2059 }
2060
Dan Stoza6b9454d2014-11-07 16:00:59 -08002061 mQueueItems.removeAt(0);
2062 }
2063
Dan Stozaecc50402015-04-28 14:42:06 -07002064
Andy McFadden1585c4d2013-06-28 13:52:40 -07002065 // Decrement the queued-frames count. Signal another event if we
2066 // have more frames pending.
Pablo Ceballos06312182015-10-07 16:32:12 -07002067 if ((queuedBuffer && android_atomic_dec(&mQueuedFrames) > 1)
Pablo Ceballosff95aab2016-01-13 17:09:58 -08002068 || mAutoRefresh) {
Andy McFadden1585c4d2013-06-28 13:52:40 -07002069 mFlinger->signalLayerUpdate();
2070 }
2071
2072 if (updateResult != NO_ERROR) {
Mathias Agopiana67932f2011-04-20 14:20:59 -07002073 // something happened!
2074 recomputeVisibleRegions = true;
Mathias Agopian4fec8732012-06-29 14:12:52 -07002075 return outDirtyRegion;
Mathias Agopiana67932f2011-04-20 14:20:59 -07002076 }
Mathias Agopian96f08192010-06-02 23:28:45 -07002077
Jamie Gennis351a5132011-09-14 18:23:37 -07002078 // update the active buffer
Andy McFaddenbf974ab2012-12-04 16:51:15 -08002079 mActiveBuffer = mSurfaceFlingerConsumer->getCurrentBuffer();
Mathias Agopiane31564d2012-05-29 20:41:03 -07002080 if (mActiveBuffer == NULL) {
2081 // this can only happen if the very first buffer was rejected.
Mathias Agopian4fec8732012-06-29 14:12:52 -07002082 return outDirtyRegion;
Mathias Agopiane31564d2012-05-29 20:41:03 -07002083 }
Mathias Agopianda9584d2010-12-13 18:51:59 -08002084
Mathias Agopian4824d402012-06-04 18:16:30 -07002085 mRefreshPending = true;
Mathias Agopian2c8207e2012-05-23 17:56:42 -07002086 mFrameLatencyNeeded = true;
Mathias Agopiane31564d2012-05-29 20:41:03 -07002087 if (oldActiveBuffer == NULL) {
Mathias Agopian2c8207e2012-05-23 17:56:42 -07002088 // the first time we receive a buffer, we need to trigger a
2089 // geometry invalidation.
Andy McFaddenab10c582012-09-26 16:19:12 -07002090 recomputeVisibleRegions = true;
Mathias Agopian2c8207e2012-05-23 17:56:42 -07002091 }
2092
Andy McFaddenbf974ab2012-12-04 16:51:15 -08002093 Rect crop(mSurfaceFlingerConsumer->getCurrentCrop());
2094 const uint32_t transform(mSurfaceFlingerConsumer->getCurrentTransform());
2095 const uint32_t scalingMode(mSurfaceFlingerConsumer->getCurrentScalingMode());
Mathias Agopian702634a2012-05-23 17:50:31 -07002096 if ((crop != mCurrentCrop) ||
2097 (transform != mCurrentTransform) ||
2098 (scalingMode != mCurrentScalingMode))
2099 {
2100 mCurrentCrop = crop;
2101 mCurrentTransform = transform;
2102 mCurrentScalingMode = scalingMode;
Andy McFaddenab10c582012-09-26 16:19:12 -07002103 recomputeVisibleRegions = true;
Mathias Agopian702634a2012-05-23 17:50:31 -07002104 }
2105
2106 if (oldActiveBuffer != NULL) {
Mathias Agopiane31564d2012-05-29 20:41:03 -07002107 uint32_t bufWidth = mActiveBuffer->getWidth();
2108 uint32_t bufHeight = mActiveBuffer->getHeight();
Mathias Agopian702634a2012-05-23 17:50:31 -07002109 if (bufWidth != uint32_t(oldActiveBuffer->width) ||
2110 bufHeight != uint32_t(oldActiveBuffer->height)) {
Andy McFaddenab10c582012-09-26 16:19:12 -07002111 recomputeVisibleRegions = true;
Mathias Agopian702634a2012-05-23 17:50:31 -07002112 }
2113 }
2114
2115 mCurrentOpacity = getOpacityForFormat(mActiveBuffer->format);
Andy McFadden4125a4f2014-01-29 17:17:11 -08002116 if (oldOpacity != isOpaque(s)) {
Mathias Agopian702634a2012-05-23 17:50:31 -07002117 recomputeVisibleRegions = true;
2118 }
2119
Dan Stozacac35382016-01-27 12:21:06 -08002120 mCurrentFrameNumber = mSurfaceFlingerConsumer->getFrameNumber();
2121
2122 // Remove any sync points corresponding to the buffer which was just
2123 // latched
2124 {
2125 Mutex::Autolock lock(mLocalSyncPointMutex);
2126 auto point = mLocalSyncPoints.begin();
2127 while (point != mLocalSyncPoints.end()) {
2128 if (!(*point)->frameIsAvailable() ||
2129 !(*point)->transactionIsApplied()) {
2130 // This sync point must have been added since we started
2131 // latching. Don't drop it yet.
2132 ++point;
2133 continue;
2134 }
2135
2136 if ((*point)->getFrameNumber() <= mCurrentFrameNumber) {
2137 point = mLocalSyncPoints.erase(point);
2138 } else {
2139 ++point;
2140 }
2141 }
2142 }
2143
Mathias Agopian4fec8732012-06-29 14:12:52 -07002144 // FIXME: postedRegion should be dirty & bounds
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07002145 Region dirtyRegion(Rect(s.active.w, s.active.h));
Mathias Agopian4fec8732012-06-29 14:12:52 -07002146
2147 // transform the dirty region to window-manager space
Robert Carr3dcabfa2016-03-01 18:36:58 -08002148 outDirtyRegion = (s.active.transform.transform(dirtyRegion));
Mathias Agopiancaa600c2009-09-16 18:27:24 -07002149 }
Mathias Agopian4fec8732012-06-29 14:12:52 -07002150 return outDirtyRegion;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002151}
2152
Mathias Agopiana67932f2011-04-20 14:20:59 -07002153uint32_t Layer::getEffectiveUsage(uint32_t usage) const
Mathias Agopianb7e930d2010-06-01 15:12:58 -07002154{
Mathias Agopiana67932f2011-04-20 14:20:59 -07002155 // TODO: should we do something special if mSecure is set?
2156 if (mProtectedByApp) {
2157 // need a hardware-protected path to external video sink
2158 usage |= GraphicBuffer::USAGE_PROTECTED;
Jamie Gennis54cc83e2010-11-02 11:51:32 -07002159 }
Riley Andrews03414a12014-07-01 14:22:59 -07002160 if (mPotentialCursor) {
2161 usage |= GraphicBuffer::USAGE_CURSOR;
2162 }
Jamie Gennis3599bf22011-08-10 11:48:07 -07002163 usage |= GraphicBuffer::USAGE_HW_COMPOSER;
Mathias Agopiana67932f2011-04-20 14:20:59 -07002164 return usage;
Mathias Agopianb5b7f262010-05-07 15:58:44 -07002165}
2166
Mathias Agopian84300952012-11-21 16:02:13 -08002167void Layer::updateTransformHint(const sp<const DisplayDevice>& hw) const {
Mathias Agopiana4583642011-08-23 18:03:18 -07002168 uint32_t orientation = 0;
2169 if (!mFlinger->mDebugDisableTransformHint) {
Mathias Agopian84300952012-11-21 16:02:13 -08002170 // The transform hint is used to improve performance, but we can
2171 // only have a single transform hint, it cannot
Mathias Agopian4fec8732012-06-29 14:12:52 -07002172 // apply to all displays.
Mathias Agopian42977342012-08-05 00:40:46 -07002173 const Transform& planeTransform(hw->getTransform());
Mathias Agopian4fec8732012-06-29 14:12:52 -07002174 orientation = planeTransform.getOrientation();
Mathias Agopiana4583642011-08-23 18:03:18 -07002175 if (orientation & Transform::ROT_INVALID) {
2176 orientation = 0;
2177 }
2178 }
Andy McFaddenbf974ab2012-12-04 16:51:15 -08002179 mSurfaceFlingerConsumer->setTransformHint(orientation);
Mathias Agopiana4583642011-08-23 18:03:18 -07002180}
2181
Mathias Agopian13127d82013-03-05 17:47:11 -08002182// ----------------------------------------------------------------------------
2183// debugging
2184// ----------------------------------------------------------------------------
2185
Mathias Agopian3e25fd82013-04-22 17:52:16 +02002186void Layer::dump(String8& result, Colorizer& colorizer) const
Mathias Agopian13127d82013-03-05 17:47:11 -08002187{
Mathias Agopian1eae0ee2013-06-05 16:59:15 -07002188 const Layer::State& s(getDrawingState());
Mathias Agopian13127d82013-03-05 17:47:11 -08002189
Mathias Agopian3e25fd82013-04-22 17:52:16 +02002190 colorizer.colorize(result, Colorizer::GREEN);
Mathias Agopian74d211a2013-04-22 16:55:35 +02002191 result.appendFormat(
Mathias Agopian13127d82013-03-05 17:47:11 -08002192 "+ %s %p (%s)\n",
2193 getTypeId(), this, getName().string());
Mathias Agopian3e25fd82013-04-22 17:52:16 +02002194 colorizer.reset(result);
Mathias Agopian13127d82013-03-05 17:47:11 -08002195
Mathias Agopian2ca79392013-04-02 18:30:32 -07002196 s.activeTransparentRegion.dump(result, "transparentRegion");
Mathias Agopian13127d82013-03-05 17:47:11 -08002197 visibleRegion.dump(result, "visibleRegion");
Dan Stozaee44edd2015-03-23 15:50:23 -07002198 surfaceDamageRegion.dump(result, "surfaceDamageRegion");
Mathias Agopian13127d82013-03-05 17:47:11 -08002199 sp<Client> client(mClientRef.promote());
2200
Mathias Agopian74d211a2013-04-22 16:55:35 +02002201 result.appendFormat( " "
Pablo Ceballosacbe6782016-03-04 17:54:21 +00002202 "layerStack=%4d, z=%9d, pos=(%g,%g), size=(%4d,%4d), "
2203 "crop=(%4d,%4d,%4d,%4d), finalCrop=(%4d,%4d,%4d,%4d), "
Mathias Agopian13127d82013-03-05 17:47:11 -08002204 "isOpaque=%1d, invalidate=%1d, "
Dan Stoza9e56aa02015-11-02 13:00:03 -08002205#ifdef USE_HWC2
2206 "alpha=%.3f, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n"
2207#else
Mathias Agopian13127d82013-03-05 17:47:11 -08002208 "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n"
Dan Stoza9e56aa02015-11-02 13:00:03 -08002209#endif
Mathias Agopian13127d82013-03-05 17:47:11 -08002210 " client=%p\n",
Robert Carr3dcabfa2016-03-01 18:36:58 -08002211 s.layerStack, s.z, s.active.transform.tx(), s.active.transform.ty(), s.active.w, s.active.h,
Robert Carrb5d3d262016-03-25 15:08:13 -07002212 s.crop.left, s.crop.top,
2213 s.crop.right, s.crop.bottom,
2214 s.finalCrop.left, s.finalCrop.top,
2215 s.finalCrop.right, s.finalCrop.bottom,
Andy McFadden4125a4f2014-01-29 17:17:11 -08002216 isOpaque(s), contentDirty,
Mathias Agopian13127d82013-03-05 17:47:11 -08002217 s.alpha, s.flags,
Robert Carr3dcabfa2016-03-01 18:36:58 -08002218 s.active.transform[0][0], s.active.transform[0][1],
2219 s.active.transform[1][0], s.active.transform[1][1],
Mathias Agopian13127d82013-03-05 17:47:11 -08002220 client.get());
Mathias Agopian13127d82013-03-05 17:47:11 -08002221
2222 sp<const GraphicBuffer> buf0(mActiveBuffer);
2223 uint32_t w0=0, h0=0, s0=0, f0=0;
2224 if (buf0 != 0) {
2225 w0 = buf0->getWidth();
2226 h0 = buf0->getHeight();
2227 s0 = buf0->getStride();
2228 f0 = buf0->format;
2229 }
Mathias Agopian74d211a2013-04-22 16:55:35 +02002230 result.appendFormat(
Mathias Agopian13127d82013-03-05 17:47:11 -08002231 " "
2232 "format=%2d, activeBuffer=[%4ux%4u:%4u,%3X],"
2233 " queued-frames=%d, mRefreshPending=%d\n",
2234 mFormat, w0, h0, s0,f0,
2235 mQueuedFrames, mRefreshPending);
2236
Mathias Agopian13127d82013-03-05 17:47:11 -08002237 if (mSurfaceFlingerConsumer != 0) {
Colin Crossdc782512016-09-26 18:10:16 -07002238 mSurfaceFlingerConsumer->dumpState(result, " ");
Mathias Agopian13127d82013-03-05 17:47:11 -08002239 }
2240}
2241
Dan Stozae22aec72016-08-01 13:20:59 -07002242#ifdef USE_HWC2
2243void Layer::miniDumpHeader(String8& result) {
2244 result.append("----------------------------------------");
2245 result.append("---------------------------------------\n");
2246 result.append(" Layer name\n");
2247 result.append(" Z | ");
2248 result.append(" Comp Type | ");
2249 result.append(" Disp Frame (LTRB) | ");
2250 result.append(" Source Crop (LTRB)\n");
2251 result.append("----------------------------------------");
2252 result.append("---------------------------------------\n");
2253}
2254
2255void Layer::miniDump(String8& result, int32_t hwcId) const {
2256 if (mHwcLayers.count(hwcId) == 0) {
2257 return;
2258 }
2259
2260 String8 name;
2261 if (mName.length() > 77) {
2262 std::string shortened;
2263 shortened.append(mName.string(), 36);
2264 shortened.append("[...]");
2265 shortened.append(mName.string() + (mName.length() - 36), 36);
2266 name = shortened.c_str();
2267 } else {
2268 name = mName;
2269 }
2270
2271 result.appendFormat(" %s\n", name.string());
2272
2273 const Layer::State& layerState(getDrawingState());
2274 const HWCInfo& hwcInfo = mHwcLayers.at(hwcId);
2275 result.appendFormat(" %10u | ", layerState.z);
2276 result.appendFormat("%10s | ",
2277 to_string(getCompositionType(hwcId)).c_str());
2278 const Rect& frame = hwcInfo.displayFrame;
2279 result.appendFormat("%4d %4d %4d %4d | ", frame.left, frame.top,
2280 frame.right, frame.bottom);
2281 const FloatRect& crop = hwcInfo.sourceCrop;
2282 result.appendFormat("%6.1f %6.1f %6.1f %6.1f\n", crop.left, crop.top,
2283 crop.right, crop.bottom);
2284
2285 result.append("- - - - - - - - - - - - - - - - - - - - ");
2286 result.append("- - - - - - - - - - - - - - - - - - - -\n");
2287}
2288#endif
2289
Svetoslavd85084b2014-03-20 10:28:31 -07002290void Layer::dumpFrameStats(String8& result) const {
2291 mFrameTracker.dumpStats(result);
Mathias Agopian13127d82013-03-05 17:47:11 -08002292}
2293
Svetoslavd85084b2014-03-20 10:28:31 -07002294void Layer::clearFrameStats() {
2295 mFrameTracker.clearStats();
Mathias Agopian13127d82013-03-05 17:47:11 -08002296}
2297
Jamie Gennis6547ff42013-07-16 20:12:42 -07002298void Layer::logFrameStats() {
2299 mFrameTracker.logAndResetStats(mName);
2300}
2301
Svetoslavd85084b2014-03-20 10:28:31 -07002302void Layer::getFrameStats(FrameStats* outStats) const {
2303 mFrameTracker.getStats(outStats);
2304}
2305
Pablo Ceballos40845df2016-01-25 17:41:15 -08002306void Layer::getFenceData(String8* outName, uint64_t* outFrameNumber,
2307 bool* outIsGlesComposition, nsecs_t* outPostedTime,
2308 sp<Fence>* outAcquireFence, sp<Fence>* outPrevReleaseFence) const {
2309 *outName = mName;
2310 *outFrameNumber = mSurfaceFlingerConsumer->getFrameNumber();
2311
2312#ifdef USE_HWC2
2313 *outIsGlesComposition = mHwcLayers.count(HWC_DISPLAY_PRIMARY) ?
2314 mHwcLayers.at(HWC_DISPLAY_PRIMARY).compositionType ==
2315 HWC2::Composition::Client : true;
2316#else
2317 *outIsGlesComposition = mIsGlesComposition;
2318#endif
2319 *outPostedTime = mSurfaceFlingerConsumer->getTimestamp();
2320 *outAcquireFence = mSurfaceFlingerConsumer->getCurrentFence();
2321 *outPrevReleaseFence = mSurfaceFlingerConsumer->getPrevReleaseFence();
2322}
Dan Stozae77c7662016-05-13 11:37:28 -07002323
2324std::vector<OccupancyTracker::Segment> Layer::getOccupancyHistory(
2325 bool forceFlush) {
2326 std::vector<OccupancyTracker::Segment> history;
2327 status_t result = mSurfaceFlingerConsumer->getOccupancyHistory(forceFlush,
2328 &history);
2329 if (result != NO_ERROR) {
2330 ALOGW("[%s] Failed to obtain occupancy history (%d)", mName.string(),
2331 result);
2332 return {};
2333 }
2334 return history;
2335}
2336
Robert Carr367c5682016-06-20 11:55:28 -07002337bool Layer::getTransformToDisplayInverse() const {
2338 return mSurfaceFlingerConsumer->getTransformToDisplayInverse();
2339}
2340
Mathias Agopian13127d82013-03-05 17:47:11 -08002341// ---------------------------------------------------------------------------
2342
2343Layer::LayerCleaner::LayerCleaner(const sp<SurfaceFlinger>& flinger,
2344 const sp<Layer>& layer)
2345 : mFlinger(flinger), mLayer(layer) {
2346}
2347
2348Layer::LayerCleaner::~LayerCleaner() {
2349 // destroy client resources
2350 mFlinger->onLayerDestroyed(mLayer);
2351}
2352
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002353// ---------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08002354}; // namespace android
Mathias Agopian3f844832013-08-07 21:24:32 -07002355
2356#if defined(__gl_h_)
2357#error "don't include gl/gl.h in this file"
2358#endif
2359
2360#if defined(__gl2_h_)
2361#error "don't include gl2/gl2.h in this file"
2362#endif