blob: 7fd9d01a5139a9192342956ca8862c95e533034e [file] [log] [blame]
David Sodman0c69cad2017-08-21 12:12:51 -07001/*
2 * Copyright (C) 2017 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
17//#define LOG_NDEBUG 0
18#undef LOG_TAG
19#define LOG_TAG "BufferLayer"
20#define ATRACE_TAG ATRACE_TAG_GRAPHICS
21
22#include "BufferLayer.h"
23#include "Colorizer.h"
24#include "DisplayDevice.h"
25#include "LayerRejecter.h"
26#include "clz.h"
27
28#include "RenderEngine/RenderEngine.h"
29
30#include <gui/BufferItem.h>
31#include <gui/BufferQueue.h>
32#include <gui/LayerDebugInfo.h>
33#include <gui/Surface.h>
34
35#include <ui/DebugUtils.h>
36
37#include <utils/Errors.h>
38#include <utils/Log.h>
39#include <utils/NativeHandle.h>
40#include <utils/StopWatch.h>
41#include <utils/Trace.h>
42
43#include <cutils/compiler.h>
44#include <cutils/native_handle.h>
45#include <cutils/properties.h>
46
47#include <math.h>
48#include <stdlib.h>
49#include <mutex>
50
51namespace android {
52
53BufferLayer::BufferLayer(SurfaceFlinger* flinger, const sp<Client>& client, const String8& name,
54 uint32_t w, uint32_t h, uint32_t flags)
55 : Layer(flinger, client, name, w, h, flags),
Chia-I Wub28c6742017-12-27 10:59:54 -080056 mConsumer(nullptr),
Ivan Lozanoeb13f9e2017-11-09 12:39:31 -080057 mTextureName(UINT32_MAX),
David Sodman0c69cad2017-08-21 12:12:51 -070058 mFormat(PIXEL_FORMAT_NONE),
59 mCurrentScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
60 mBufferLatched(false),
61 mPreviousFrameNumber(0),
62 mUpdateTexImageFailed(false),
63 mRefreshPending(false) {
David Sodman0c69cad2017-08-21 12:12:51 -070064 ALOGV("Creating Layer %s", name.string());
David Sodman0c69cad2017-08-21 12:12:51 -070065
66 mFlinger->getRenderEngine().genTextures(1, &mTextureName);
67 mTexture.init(Texture::TEXTURE_EXTERNAL, mTextureName);
68
69 if (flags & ISurfaceComposerClient::eNonPremultiplied) mPremultipliedAlpha = false;
70
71 mCurrentState.requested = mCurrentState.active;
72
73 // drawing state & current state are identical
74 mDrawingState = mCurrentState;
75}
76
77BufferLayer::~BufferLayer() {
David Sodman0c69cad2017-08-21 12:12:51 -070078 mFlinger->deleteTextureAsync(mTextureName);
79
David Sodman6f65f3e2017-11-03 14:28:09 -070080 if (!getBE().mHwcLayers.empty()) {
David Sodman0c69cad2017-08-21 12:12:51 -070081 ALOGE("Found stale hardware composer layers when destroying "
82 "surface flinger layer %s",
83 mName.string());
84 destroyAllHwcLayers();
85 }
David Sodman0c69cad2017-08-21 12:12:51 -070086}
87
David Sodmaneb085e02017-10-05 18:49:04 -070088void BufferLayer::useSurfaceDamage() {
89 if (mFlinger->mForceFullDamage) {
90 surfaceDamageRegion = Region::INVALID_REGION;
91 } else {
Chia-I Wub28c6742017-12-27 10:59:54 -080092 surfaceDamageRegion = mConsumer->getSurfaceDamage();
David Sodmaneb085e02017-10-05 18:49:04 -070093 }
94}
95
96void BufferLayer::useEmptyDamage() {
97 surfaceDamageRegion.clear();
98}
99
David Sodman41fdfc92017-11-06 16:09:56 -0800100bool BufferLayer::isProtected() const {
David Sodman0cc69182017-11-17 12:12:07 -0800101 const sp<GraphicBuffer>& buffer(getBE().compositionInfo.mBuffer);
David Sodman5b4cffc2017-11-23 13:20:29 -0800102 return (buffer != 0) &&
103 (buffer->getUsage() & GRALLOC_USAGE_PROTECTED);
David Sodman0c69cad2017-08-21 12:12:51 -0700104}
105
106bool BufferLayer::isVisible() const {
107 return !(isHiddenByPolicy()) && getAlpha() > 0.0f &&
Peiyong Lin566a3b42018-01-09 18:22:43 -0800108 (getBE().compositionInfo.mBuffer != nullptr ||
109 getBE().compositionInfo.hwc.sidebandStream != nullptr);
David Sodman0c69cad2017-08-21 12:12:51 -0700110}
111
112bool BufferLayer::isFixedSize() const {
113 return getEffectiveScalingMode() != NATIVE_WINDOW_SCALING_MODE_FREEZE;
114}
115
116status_t BufferLayer::setBuffers(uint32_t w, uint32_t h, PixelFormat format, uint32_t flags) {
117 uint32_t const maxSurfaceDims =
118 min(mFlinger->getMaxTextureSize(), mFlinger->getMaxViewportDims());
119
120 // never allow a surface larger than what our underlying GL implementation
121 // can handle.
122 if ((uint32_t(w) > maxSurfaceDims) || (uint32_t(h) > maxSurfaceDims)) {
123 ALOGE("dimensions too large %u x %u", uint32_t(w), uint32_t(h));
124 return BAD_VALUE;
125 }
126
127 mFormat = format;
128
129 mPotentialCursor = (flags & ISurfaceComposerClient::eCursorWindow) ? true : false;
130 mProtectedByApp = (flags & ISurfaceComposerClient::eProtectedByApp) ? true : false;
131 mCurrentOpacity = getOpacityForFormat(format);
132
Chia-I Wub28c6742017-12-27 10:59:54 -0800133 mConsumer->setDefaultBufferSize(w, h);
134 mConsumer->setDefaultBufferFormat(format);
135 mConsumer->setConsumerUsageBits(getEffectiveUsage(0));
David Sodman0c69cad2017-08-21 12:12:51 -0700136
137 return NO_ERROR;
138}
139
140static constexpr mat4 inverseOrientation(uint32_t transform) {
David Sodman41fdfc92017-11-06 16:09:56 -0800141 const mat4 flipH(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1);
142 const mat4 flipV(1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1);
143 const mat4 rot90(0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1);
David Sodman0c69cad2017-08-21 12:12:51 -0700144 mat4 tr;
145
146 if (transform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
147 tr = tr * rot90;
148 }
149 if (transform & NATIVE_WINDOW_TRANSFORM_FLIP_H) {
150 tr = tr * flipH;
151 }
152 if (transform & NATIVE_WINDOW_TRANSFORM_FLIP_V) {
153 tr = tr * flipV;
154 }
155 return inverse(tr);
156}
157
158/*
159 * onDraw will draw the current layer onto the presentable buffer
160 */
161void BufferLayer::onDraw(const RenderArea& renderArea, const Region& clip,
162 bool useIdentityTransform) const {
163 ATRACE_CALL();
164
David Sodman0cc69182017-11-17 12:12:07 -0800165 if (CC_UNLIKELY(getBE().compositionInfo.mBuffer == 0)) {
David Sodman0c69cad2017-08-21 12:12:51 -0700166 // the texture has not been created yet, this Layer has
167 // in fact never been drawn into. This happens frequently with
168 // SurfaceView because the WindowManager can't know when the client
169 // has drawn the first time.
170
171 // If there is nothing under us, we paint the screen in black, otherwise
172 // we just skip this update.
173
174 // figure out if there is something below us
175 Region under;
176 bool finished = false;
177 mFlinger->mDrawingState.traverseInZOrder([&](Layer* layer) {
178 if (finished || layer == static_cast<BufferLayer const*>(this)) {
179 finished = true;
180 return;
181 }
182 under.orSelf(renderArea.getTransform().transform(layer->visibleRegion));
183 });
184 // if not everything below us is covered, we plug the holes!
185 Region holes(clip.subtract(under));
186 if (!holes.isEmpty()) {
187 clearWithOpenGL(renderArea, 0, 0, 0, 1);
188 }
189 return;
190 }
191
192 // Bind the current buffer to the GL texture, and wait for it to be
193 // ready for us to draw into.
Chia-I Wub28c6742017-12-27 10:59:54 -0800194 status_t err = mConsumer->bindTextureImage();
David Sodman0c69cad2017-08-21 12:12:51 -0700195 if (err != NO_ERROR) {
196 ALOGW("onDraw: bindTextureImage failed (err=%d)", err);
197 // Go ahead and draw the buffer anyway; no matter what we do the screen
198 // is probably going to have something visibly wrong.
199 }
200
201 bool blackOutLayer = isProtected() || (isSecure() && !renderArea.isSecure());
202
Lloyd Pique144e1162017-12-20 16:44:52 -0800203 auto& engine(mFlinger->getRenderEngine());
David Sodman0c69cad2017-08-21 12:12:51 -0700204
205 if (!blackOutLayer) {
206 // TODO: we could be more subtle with isFixedSize()
207 const bool useFiltering = getFiltering() || needsFiltering(renderArea) || isFixedSize();
208
209 // Query the texture matrix given our current filtering mode.
210 float textureMatrix[16];
Chia-I Wub28c6742017-12-27 10:59:54 -0800211 mConsumer->setFilteringEnabled(useFiltering);
212 mConsumer->getTransformMatrix(textureMatrix);
David Sodman0c69cad2017-08-21 12:12:51 -0700213
214 if (getTransformToDisplayInverse()) {
215 /*
216 * the code below applies the primary display's inverse transform to
217 * the texture transform
218 */
219 uint32_t transform = DisplayDevice::getPrimaryDisplayOrientationTransform();
220 mat4 tr = inverseOrientation(transform);
221
222 /**
223 * TODO(b/36727915): This is basically a hack.
224 *
225 * Ensure that regardless of the parent transformation,
226 * this buffer is always transformed from native display
227 * orientation to display orientation. For example, in the case
228 * of a camera where the buffer remains in native orientation,
229 * we want the pixels to always be upright.
230 */
231 sp<Layer> p = mDrawingParent.promote();
232 if (p != nullptr) {
233 const auto parentTransform = p->getTransform();
234 tr = tr * inverseOrientation(parentTransform.getOrientation());
235 }
236
237 // and finally apply it to the original texture matrix
238 const mat4 texTransform(mat4(static_cast<const float*>(textureMatrix)) * tr);
239 memcpy(textureMatrix, texTransform.asArray(), sizeof(textureMatrix));
240 }
241
242 // Set things up for texturing.
David Sodman0cc69182017-11-17 12:12:07 -0800243 mTexture.setDimensions(getBE().compositionInfo.mBuffer->getWidth(),
244 getBE().compositionInfo.mBuffer->getHeight());
David Sodman0c69cad2017-08-21 12:12:51 -0700245 mTexture.setFiltering(useFiltering);
246 mTexture.setMatrix(textureMatrix);
247
248 engine.setupLayerTexturing(mTexture);
249 } else {
250 engine.setupLayerBlackedOut();
251 }
252 drawWithOpenGL(renderArea, useIdentityTransform);
253 engine.disableTexturing();
254}
255
David Sodmaneb085e02017-10-05 18:49:04 -0700256void BufferLayer::onLayerDisplayed(const sp<Fence>& releaseFence) {
Chia-I Wub28c6742017-12-27 10:59:54 -0800257 mConsumer->setReleaseFence(releaseFence);
David Sodmaneb085e02017-10-05 18:49:04 -0700258}
David Sodmaneb085e02017-10-05 18:49:04 -0700259
260void BufferLayer::abandon() {
Chia-I Wub28c6742017-12-27 10:59:54 -0800261 mConsumer->abandon();
David Sodmaneb085e02017-10-05 18:49:04 -0700262}
263
264bool BufferLayer::shouldPresentNow(const DispSync& dispSync) const {
265 if (mSidebandStreamChanged || mAutoRefresh) {
266 return true;
267 }
268
269 Mutex::Autolock lock(mQueueItemLock);
270 if (mQueueItems.empty()) {
271 return false;
272 }
273 auto timestamp = mQueueItems[0].mTimestamp;
Chia-I Wub28c6742017-12-27 10:59:54 -0800274 nsecs_t expectedPresent = mConsumer->computeExpectedPresent(dispSync);
David Sodmaneb085e02017-10-05 18:49:04 -0700275
276 // Ignore timestamps more than a second in the future
277 bool isPlausible = timestamp < (expectedPresent + s2ns(1));
278 ALOGW_IF(!isPlausible,
279 "[%s] Timestamp %" PRId64 " seems implausible "
280 "relative to expectedPresent %" PRId64,
281 mName.string(), timestamp, expectedPresent);
282
283 bool isDue = timestamp < expectedPresent;
284 return isDue || !isPlausible;
285}
286
287void BufferLayer::setTransformHint(uint32_t orientation) const {
Chia-I Wub28c6742017-12-27 10:59:54 -0800288 mConsumer->setTransformHint(orientation);
David Sodmaneb085e02017-10-05 18:49:04 -0700289}
290
David Sodman0c69cad2017-08-21 12:12:51 -0700291bool BufferLayer::onPreComposition(nsecs_t refreshStartTime) {
292 if (mBufferLatched) {
293 Mutex::Autolock lock(mFrameEventHistoryMutex);
David Sodman9eeae692017-11-02 10:53:32 -0700294 mFrameEventHistory.addPreComposition(mCurrentFrameNumber,
295 refreshStartTime);
David Sodman0c69cad2017-08-21 12:12:51 -0700296 }
297 mRefreshPending = false;
David Sodman9eeae692017-11-02 10:53:32 -0700298 return mQueuedFrames > 0 || mSidebandStreamChanged ||
299 mAutoRefresh;
David Sodman0c69cad2017-08-21 12:12:51 -0700300}
David Sodmaneb085e02017-10-05 18:49:04 -0700301bool BufferLayer::onPostComposition(const std::shared_ptr<FenceTime>& glDoneFence,
302 const std::shared_ptr<FenceTime>& presentFence,
303 const CompositorTiming& compositorTiming) {
304 // mFrameLatencyNeeded is true when a new frame was latched for the
305 // composition.
306 if (!mFrameLatencyNeeded) return false;
307
308 // Update mFrameEventHistory.
309 {
310 Mutex::Autolock lock(mFrameEventHistoryMutex);
David Sodman9eeae692017-11-02 10:53:32 -0700311 mFrameEventHistory.addPostComposition(mCurrentFrameNumber, glDoneFence,
312 presentFence, compositorTiming);
David Sodmaneb085e02017-10-05 18:49:04 -0700313 }
314
315 // Update mFrameTracker.
Chia-I Wub28c6742017-12-27 10:59:54 -0800316 nsecs_t desiredPresentTime = mConsumer->getTimestamp();
David Sodmaneb085e02017-10-05 18:49:04 -0700317 mFrameTracker.setDesiredPresentTime(desiredPresentTime);
318
Chia-I Wub28c6742017-12-27 10:59:54 -0800319 std::shared_ptr<FenceTime> frameReadyFence = mConsumer->getCurrentFenceTime();
David Sodmaneb085e02017-10-05 18:49:04 -0700320 if (frameReadyFence->isValid()) {
321 mFrameTracker.setFrameReadyFence(std::move(frameReadyFence));
322 } else {
323 // There was no fence for this frame, so assume that it was ready
324 // to be presented at the desired present time.
325 mFrameTracker.setFrameReadyTime(desiredPresentTime);
326 }
327
328 if (presentFence->isValid()) {
329 mFrameTracker.setActualPresentFence(std::shared_ptr<FenceTime>(presentFence));
330 } else {
331 // The HWC doesn't support present fences, so use the refresh
332 // timestamp instead.
333 mFrameTracker.setActualPresentTime(
334 mFlinger->getHwComposer().getRefreshTimestamp(HWC_DISPLAY_PRIMARY));
335 }
336
337 mFrameTracker.advanceFrame();
338 mFrameLatencyNeeded = false;
339 return true;
340}
341
342std::vector<OccupancyTracker::Segment> BufferLayer::getOccupancyHistory(bool forceFlush) {
343 std::vector<OccupancyTracker::Segment> history;
Chia-I Wub28c6742017-12-27 10:59:54 -0800344 status_t result = mConsumer->getOccupancyHistory(forceFlush, &history);
David Sodmaneb085e02017-10-05 18:49:04 -0700345 if (result != NO_ERROR) {
346 ALOGW("[%s] Failed to obtain occupancy history (%d)", mName.string(), result);
347 return {};
348 }
349 return history;
350}
351
352bool BufferLayer::getTransformToDisplayInverse() const {
Chia-I Wub28c6742017-12-27 10:59:54 -0800353 return mConsumer->getTransformToDisplayInverse();
David Sodmaneb085e02017-10-05 18:49:04 -0700354}
David Sodman0c69cad2017-08-21 12:12:51 -0700355
David Sodman0c69cad2017-08-21 12:12:51 -0700356void BufferLayer::releasePendingBuffer(nsecs_t dequeueReadyTime) {
Chia-I Wub28c6742017-12-27 10:59:54 -0800357 if (!mConsumer->releasePendingBuffer()) {
David Sodman0c69cad2017-08-21 12:12:51 -0700358 return;
359 }
360
361 auto releaseFenceTime =
Chia-I Wub28c6742017-12-27 10:59:54 -0800362 std::make_shared<FenceTime>(mConsumer->getPrevFinalReleaseFence());
David Sodman0c69cad2017-08-21 12:12:51 -0700363 mReleaseTimeline.updateSignalTimes();
364 mReleaseTimeline.push(releaseFenceTime);
365
366 Mutex::Autolock lock(mFrameEventHistoryMutex);
367 if (mPreviousFrameNumber != 0) {
368 mFrameEventHistory.addRelease(mPreviousFrameNumber, dequeueReadyTime,
369 std::move(releaseFenceTime));
370 }
371}
David Sodman0c69cad2017-08-21 12:12:51 -0700372
373Region BufferLayer::latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime) {
374 ATRACE_CALL();
375
376 if (android_atomic_acquire_cas(true, false, &mSidebandStreamChanged) == 0) {
377 // mSidebandStreamChanged was true
Chia-I Wub28c6742017-12-27 10:59:54 -0800378 mSidebandStream = mConsumer->getSidebandStream();
David Sodman386c22e2017-11-09 16:34:46 -0800379 // replicated in LayerBE until FE/BE is ready to be synchronized
David Sodman0cc69182017-11-17 12:12:07 -0800380 getBE().compositionInfo.hwc.sidebandStream = mSidebandStream;
Peiyong Lin566a3b42018-01-09 18:22:43 -0800381 if (getBE().compositionInfo.hwc.sidebandStream != nullptr) {
David Sodman0c69cad2017-08-21 12:12:51 -0700382 setTransactionFlags(eTransactionNeeded);
383 mFlinger->setTransactionFlags(eTraversalNeeded);
384 }
385 recomputeVisibleRegions = true;
386
387 const State& s(getDrawingState());
388 return getTransform().transform(Region(Rect(s.active.w, s.active.h)));
389 }
390
391 Region outDirtyRegion;
392 if (mQueuedFrames <= 0 && !mAutoRefresh) {
393 return outDirtyRegion;
394 }
395
396 // if we've already called updateTexImage() without going through
397 // a composition step, we have to skip this layer at this point
398 // because we cannot call updateTeximage() without a corresponding
399 // compositionComplete() call.
400 // we'll trigger an update in onPreComposition().
401 if (mRefreshPending) {
402 return outDirtyRegion;
403 }
404
405 // If the head buffer's acquire fence hasn't signaled yet, return and
406 // try again later
407 if (!headFenceHasSignaled()) {
408 mFlinger->signalLayerUpdate();
409 return outDirtyRegion;
410 }
411
412 // Capture the old state of the layer for comparisons later
413 const State& s(getDrawingState());
414 const bool oldOpacity = isOpaque(s);
David Sodman0cc69182017-11-17 12:12:07 -0800415 sp<GraphicBuffer> oldBuffer = getBE().compositionInfo.mBuffer;
David Sodman0c69cad2017-08-21 12:12:51 -0700416
417 if (!allTransactionsSignaled()) {
418 mFlinger->signalLayerUpdate();
419 return outDirtyRegion;
420 }
421
422 // This boolean is used to make sure that SurfaceFlinger's shadow copy
423 // of the buffer queue isn't modified when the buffer queue is returning
424 // BufferItem's that weren't actually queued. This can happen in shared
425 // buffer mode.
426 bool queuedBuffer = false;
427 LayerRejecter r(mDrawingState, getCurrentState(), recomputeVisibleRegions,
David Sodman9eeae692017-11-02 10:53:32 -0700428 getProducerStickyTransform() != 0, mName.string(),
429 mOverrideScalingMode, mFreezeGeometryUpdates);
David Sodman0c69cad2017-08-21 12:12:51 -0700430 status_t updateResult =
Chia-I Wub28c6742017-12-27 10:59:54 -0800431 mConsumer->updateTexImage(&r, mFlinger->mPrimaryDispSync,
David Sodman9eeae692017-11-02 10:53:32 -0700432 &mAutoRefresh, &queuedBuffer,
433 mLastFrameNumberReceived);
David Sodman0c69cad2017-08-21 12:12:51 -0700434 if (updateResult == BufferQueue::PRESENT_LATER) {
435 // Producer doesn't want buffer to be displayed yet. Signal a
436 // layer update so we check again at the next opportunity.
437 mFlinger->signalLayerUpdate();
438 return outDirtyRegion;
Chia-I Wu0cb75ac2017-11-27 15:56:04 -0800439 } else if (updateResult == BufferLayerConsumer::BUFFER_REJECTED) {
David Sodman0c69cad2017-08-21 12:12:51 -0700440 // If the buffer has been rejected, remove it from the shadow queue
441 // and return early
442 if (queuedBuffer) {
443 Mutex::Autolock lock(mQueueItemLock);
444 mQueueItems.removeAt(0);
445 android_atomic_dec(&mQueuedFrames);
446 }
447 return outDirtyRegion;
448 } else if (updateResult != NO_ERROR || mUpdateTexImageFailed) {
449 // This can occur if something goes wrong when trying to create the
450 // EGLImage for this buffer. If this happens, the buffer has already
451 // been released, so we need to clean up the queue and bug out
452 // early.
453 if (queuedBuffer) {
454 Mutex::Autolock lock(mQueueItemLock);
455 mQueueItems.clear();
456 android_atomic_and(0, &mQueuedFrames);
457 }
458
459 // Once we have hit this state, the shadow queue may no longer
460 // correctly reflect the incoming BufferQueue's contents, so even if
461 // updateTexImage starts working, the only safe course of action is
462 // to continue to ignore updates.
463 mUpdateTexImageFailed = true;
464
465 return outDirtyRegion;
466 }
467
468 if (queuedBuffer) {
469 // Autolock scope
Chia-I Wub28c6742017-12-27 10:59:54 -0800470 auto currentFrameNumber = mConsumer->getFrameNumber();
David Sodman0c69cad2017-08-21 12:12:51 -0700471
472 Mutex::Autolock lock(mQueueItemLock);
473
474 // Remove any stale buffers that have been dropped during
475 // updateTexImage
476 while (mQueueItems[0].mFrameNumber != currentFrameNumber) {
477 mQueueItems.removeAt(0);
478 android_atomic_dec(&mQueuedFrames);
479 }
480
481 mQueueItems.removeAt(0);
482 }
483
484 // Decrement the queued-frames count. Signal another event if we
485 // have more frames pending.
David Sodman9eeae692017-11-02 10:53:32 -0700486 if ((queuedBuffer && android_atomic_dec(&mQueuedFrames) > 1) ||
487 mAutoRefresh) {
David Sodman0c69cad2017-08-21 12:12:51 -0700488 mFlinger->signalLayerUpdate();
489 }
490
491 // update the active buffer
David Sodman0cc69182017-11-17 12:12:07 -0800492 getBE().compositionInfo.mBuffer =
Chia-I Wub28c6742017-12-27 10:59:54 -0800493 mConsumer->getCurrentBuffer(&getBE().compositionInfo.mBufferSlot);
David Sodman5b4cffc2017-11-23 13:20:29 -0800494 // replicated in LayerBE until FE/BE is ready to be synchronized
David Sodman0cc69182017-11-17 12:12:07 -0800495 mActiveBuffer = getBE().compositionInfo.mBuffer;
Peiyong Lin566a3b42018-01-09 18:22:43 -0800496 if (getBE().compositionInfo.mBuffer == nullptr) {
David Sodman0c69cad2017-08-21 12:12:51 -0700497 // this can only happen if the very first buffer was rejected.
498 return outDirtyRegion;
499 }
500
501 mBufferLatched = true;
502 mPreviousFrameNumber = mCurrentFrameNumber;
Chia-I Wub28c6742017-12-27 10:59:54 -0800503 mCurrentFrameNumber = mConsumer->getFrameNumber();
David Sodman0c69cad2017-08-21 12:12:51 -0700504
505 {
506 Mutex::Autolock lock(mFrameEventHistoryMutex);
507 mFrameEventHistory.addLatch(mCurrentFrameNumber, latchTime);
David Sodman0c69cad2017-08-21 12:12:51 -0700508 }
509
510 mRefreshPending = true;
511 mFrameLatencyNeeded = true;
Peiyong Lin566a3b42018-01-09 18:22:43 -0800512 if (oldBuffer == nullptr) {
David Sodman0c69cad2017-08-21 12:12:51 -0700513 // the first time we receive a buffer, we need to trigger a
514 // geometry invalidation.
515 recomputeVisibleRegions = true;
516 }
517
Peiyong Lin923e7c52018-04-16 14:16:37 -0700518 // Dataspace::V0_SRGB and Dataspace::V0_SRGB_LINEAR are not legacy
519 // data space, however since framework doesn't distinguish them out of
520 // legacy SRGB, we have to treat them as the same for now.
521 // UNKNOWN is treated as legacy SRGB when the connected api is EGL.
522 ui::Dataspace dataSpace = mConsumer->getCurrentDataSpace();
523 switch (dataSpace) {
524 case ui::Dataspace::V0_SRGB:
525 dataSpace = ui::Dataspace::SRGB;
526 break;
527 case ui::Dataspace::V0_SRGB_LINEAR:
528 dataSpace = ui::Dataspace::SRGB_LINEAR;
529 break;
530 case ui::Dataspace::UNKNOWN:
531 if (mConsumer->getCurrentApi() == NATIVE_WINDOW_API_EGL) {
532 dataSpace = ui::Dataspace::SRGB;
533 }
534 break;
535 default:
536 break;
537 }
538 setDataSpace(dataSpace);
David Sodman0c69cad2017-08-21 12:12:51 -0700539
Chia-I Wub28c6742017-12-27 10:59:54 -0800540 Rect crop(mConsumer->getCurrentCrop());
541 const uint32_t transform(mConsumer->getCurrentTransform());
542 const uint32_t scalingMode(mConsumer->getCurrentScalingMode());
David Sodman9eeae692017-11-02 10:53:32 -0700543 if ((crop != mCurrentCrop) ||
544 (transform != mCurrentTransform) ||
David Sodman0c69cad2017-08-21 12:12:51 -0700545 (scalingMode != mCurrentScalingMode)) {
546 mCurrentCrop = crop;
547 mCurrentTransform = transform;
548 mCurrentScalingMode = scalingMode;
549 recomputeVisibleRegions = true;
550 }
551
Peiyong Lin566a3b42018-01-09 18:22:43 -0800552 if (oldBuffer != nullptr) {
David Sodman0cc69182017-11-17 12:12:07 -0800553 uint32_t bufWidth = getBE().compositionInfo.mBuffer->getWidth();
554 uint32_t bufHeight = getBE().compositionInfo.mBuffer->getHeight();
David Sodman5b4cffc2017-11-23 13:20:29 -0800555 if (bufWidth != uint32_t(oldBuffer->width) ||
556 bufHeight != uint32_t(oldBuffer->height)) {
David Sodman0c69cad2017-08-21 12:12:51 -0700557 recomputeVisibleRegions = true;
558 }
559 }
560
David Sodman0cc69182017-11-17 12:12:07 -0800561 mCurrentOpacity = getOpacityForFormat(getBE().compositionInfo.mBuffer->format);
David Sodman0c69cad2017-08-21 12:12:51 -0700562 if (oldOpacity != isOpaque(s)) {
563 recomputeVisibleRegions = true;
564 }
565
566 // Remove any sync points corresponding to the buffer which was just
567 // latched
568 {
569 Mutex::Autolock lock(mLocalSyncPointMutex);
570 auto point = mLocalSyncPoints.begin();
571 while (point != mLocalSyncPoints.end()) {
572 if (!(*point)->frameIsAvailable() || !(*point)->transactionIsApplied()) {
573 // This sync point must have been added since we started
574 // latching. Don't drop it yet.
575 ++point;
576 continue;
577 }
578
579 if ((*point)->getFrameNumber() <= mCurrentFrameNumber) {
580 point = mLocalSyncPoints.erase(point);
581 } else {
582 ++point;
583 }
584 }
585 }
586
587 // FIXME: postedRegion should be dirty & bounds
588 Region dirtyRegion(Rect(s.active.w, s.active.h));
589
590 // transform the dirty region to window-manager space
591 outDirtyRegion = (getTransform().transform(dirtyRegion));
592
593 return outDirtyRegion;
594}
595
David Sodmaneb085e02017-10-05 18:49:04 -0700596void BufferLayer::setDefaultBufferSize(uint32_t w, uint32_t h) {
Chia-I Wub28c6742017-12-27 10:59:54 -0800597 mConsumer->setDefaultBufferSize(w, h);
David Sodmaneb085e02017-10-05 18:49:04 -0700598}
599
David Sodman0c69cad2017-08-21 12:12:51 -0700600void BufferLayer::setPerFrameData(const sp<const DisplayDevice>& displayDevice) {
601 // Apply this display's projection's viewport to the visible region
602 // before giving it to the HWC HAL.
603 const Transform& tr = displayDevice->getTransform();
604 const auto& viewport = displayDevice->getViewport();
605 Region visible = tr.transform(visibleRegion.intersect(viewport));
606 auto hwcId = displayDevice->getHwcDisplayId();
David Sodman6f65f3e2017-11-03 14:28:09 -0700607 auto& hwcInfo = getBE().mHwcLayers[hwcId];
David Sodman0c69cad2017-08-21 12:12:51 -0700608 auto& hwcLayer = hwcInfo.layer;
609 auto error = hwcLayer->setVisibleRegion(visible);
610 if (error != HWC2::Error::None) {
611 ALOGE("[%s] Failed to set visible region: %s (%d)", mName.string(),
612 to_string(error).c_str(), static_cast<int32_t>(error));
613 visible.dump(LOG_TAG);
614 }
615
616 error = hwcLayer->setSurfaceDamage(surfaceDamageRegion);
617 if (error != HWC2::Error::None) {
618 ALOGE("[%s] Failed to set surface damage: %s (%d)", mName.string(),
619 to_string(error).c_str(), static_cast<int32_t>(error));
620 surfaceDamageRegion.dump(LOG_TAG);
621 }
622
623 // Sideband layers
David Sodman0cc69182017-11-17 12:12:07 -0800624 if (getBE().compositionInfo.hwc.sidebandStream.get()) {
David Sodman0c69cad2017-08-21 12:12:51 -0700625 setCompositionType(hwcId, HWC2::Composition::Sideband);
626 ALOGV("[%s] Requesting Sideband composition", mName.string());
David Sodman0cc69182017-11-17 12:12:07 -0800627 error = hwcLayer->setSidebandStream(getBE().compositionInfo.hwc.sidebandStream->handle());
David Sodman0c69cad2017-08-21 12:12:51 -0700628 if (error != HWC2::Error::None) {
629 ALOGE("[%s] Failed to set sideband stream %p: %s (%d)", mName.string(),
David Sodman0cc69182017-11-17 12:12:07 -0800630 getBE().compositionInfo.hwc.sidebandStream->handle(), to_string(error).c_str(),
David Sodman9eeae692017-11-02 10:53:32 -0700631 static_cast<int32_t>(error));
David Sodman0c69cad2017-08-21 12:12:51 -0700632 }
633 return;
634 }
635
David Sodman0c69cad2017-08-21 12:12:51 -0700636 // Device or Cursor layers
637 if (mPotentialCursor) {
638 ALOGV("[%s] Requesting Cursor composition", mName.string());
639 setCompositionType(hwcId, HWC2::Composition::Cursor);
640 } else {
641 ALOGV("[%s] Requesting Device composition", mName.string());
642 setCompositionType(hwcId, HWC2::Composition::Device);
643 }
644
Peiyong Lin13170c82018-01-22 18:55:51 -0800645 ALOGV("setPerFrameData: dataspace = %d", mDrawingState.dataSpace);
646 error = hwcLayer->setDataspace(mDrawingState.dataSpace);
David Sodman0c69cad2017-08-21 12:12:51 -0700647 if (error != HWC2::Error::None) {
Peiyong Lin13170c82018-01-22 18:55:51 -0800648 ALOGE("[%s] Failed to set dataspace %d: %s (%d)", mName.string(), mDrawingState.dataSpace,
David Sodman0c69cad2017-08-21 12:12:51 -0700649 to_string(error).c_str(), static_cast<int32_t>(error));
650 }
651
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700652 const HdrMetadata& metadata = mConsumer->getCurrentHdrMetadata();
Peiyong Lin2c327ac2018-04-19 22:06:34 -0700653 error = hwcLayer->setPerFrameMetadata(displayDevice->getSupportedPerFrameMetadata(), metadata);
Courtney Goeltzenleuchter301bb302018-03-12 11:12:42 -0600654 if (error != HWC2::Error::None && error != HWC2::Error::Unsupported) {
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700655 ALOGE("[%s] Failed to set hdrMetadata: %s (%d)", mName.string(),
656 to_string(error).c_str(), static_cast<int32_t>(error));
657 }
658
David Sodman0c69cad2017-08-21 12:12:51 -0700659 uint32_t hwcSlot = 0;
660 sp<GraphicBuffer> hwcBuffer;
David Sodman0cc69182017-11-17 12:12:07 -0800661 hwcInfo.bufferCache.getHwcBuffer(getBE().compositionInfo.mBufferSlot,
662 getBE().compositionInfo.mBuffer, &hwcSlot, &hwcBuffer);
David Sodman0c69cad2017-08-21 12:12:51 -0700663
Chia-I Wub28c6742017-12-27 10:59:54 -0800664 auto acquireFence = mConsumer->getCurrentFence();
David Sodman0c69cad2017-08-21 12:12:51 -0700665 error = hwcLayer->setBuffer(hwcSlot, hwcBuffer, acquireFence);
666 if (error != HWC2::Error::None) {
David Sodman9eeae692017-11-02 10:53:32 -0700667 ALOGE("[%s] Failed to set buffer %p: %s (%d)", mName.string(),
David Sodman0cc69182017-11-17 12:12:07 -0800668 getBE().compositionInfo.mBuffer->handle, to_string(error).c_str(),
David Sodman9eeae692017-11-02 10:53:32 -0700669 static_cast<int32_t>(error));
David Sodman0c69cad2017-08-21 12:12:51 -0700670 }
671}
672
David Sodman41fdfc92017-11-06 16:09:56 -0800673bool BufferLayer::isOpaque(const Layer::State& s) const {
David Sodman0c69cad2017-08-21 12:12:51 -0700674 // if we don't have a buffer or sidebandStream yet, we're translucent regardless of the
675 // layer's opaque flag.
David Sodman0cc69182017-11-17 12:12:07 -0800676 if ((getBE().compositionInfo.hwc.sidebandStream == nullptr) && (getBE().compositionInfo.mBuffer == nullptr)) {
David Sodman0c69cad2017-08-21 12:12:51 -0700677 return false;
678 }
679
680 // if the layer has the opaque flag, then we're always opaque,
681 // otherwise we use the current buffer's format.
682 return ((s.flags & layer_state_t::eLayerOpaque) != 0) || mCurrentOpacity;
683}
684
685void BufferLayer::onFirstRef() {
686 // Creates a custom BufferQueue for SurfaceFlingerConsumer to use
687 sp<IGraphicBufferProducer> producer;
688 sp<IGraphicBufferConsumer> consumer;
689 BufferQueue::createBufferQueue(&producer, &consumer, true);
690 mProducer = new MonitoredProducer(producer, mFlinger, this);
Chia-I Wub28c6742017-12-27 10:59:54 -0800691 mConsumer = new BufferLayerConsumer(consumer,
Chia-I Wu9f2db772017-11-30 21:06:50 -0800692 mFlinger->getRenderEngine(), mTextureName, this);
Chia-I Wub28c6742017-12-27 10:59:54 -0800693 mConsumer->setConsumerUsageBits(getEffectiveUsage(0));
694 mConsumer->setContentsChangedListener(this);
695 mConsumer->setName(mName);
David Sodman0c69cad2017-08-21 12:12:51 -0700696
697 if (mFlinger->isLayerTripleBufferingDisabled()) {
698 mProducer->setMaxDequeuedBufferCount(2);
699 }
700
701 const sp<const DisplayDevice> hw(mFlinger->getDefaultDisplayDevice());
702 updateTransformHint(hw);
703}
704
705// ---------------------------------------------------------------------------
706// Interface implementation for SurfaceFlingerConsumer::ContentsChangedListener
707// ---------------------------------------------------------------------------
708
709void BufferLayer::onFrameAvailable(const BufferItem& item) {
710 // Add this buffer from our internal queue tracker
711 { // Autolock scope
712 Mutex::Autolock lock(mQueueItemLock);
Lloyd Pique4d234852018-01-22 17:21:36 -0800713 mFlinger->mInterceptor->saveBufferUpdate(this, item.mGraphicBuffer->getWidth(),
714 item.mGraphicBuffer->getHeight(),
715 item.mFrameNumber);
David Sodman0c69cad2017-08-21 12:12:51 -0700716 // Reset the frame number tracker when we receive the first buffer after
717 // a frame number reset
718 if (item.mFrameNumber == 1) {
719 mLastFrameNumberReceived = 0;
720 }
721
722 // Ensure that callbacks are handled in order
723 while (item.mFrameNumber != mLastFrameNumberReceived + 1) {
David Sodman9eeae692017-11-02 10:53:32 -0700724 status_t result = mQueueItemCondition.waitRelative(mQueueItemLock,
725 ms2ns(500));
David Sodman0c69cad2017-08-21 12:12:51 -0700726 if (result != NO_ERROR) {
727 ALOGE("[%s] Timed out waiting on callback", mName.string());
728 }
729 }
730
731 mQueueItems.push_back(item);
732 android_atomic_inc(&mQueuedFrames);
733
734 // Wake up any pending callbacks
735 mLastFrameNumberReceived = item.mFrameNumber;
736 mQueueItemCondition.broadcast();
737 }
738
739 mFlinger->signalLayerUpdate();
740}
741
742void BufferLayer::onFrameReplaced(const BufferItem& item) {
743 { // Autolock scope
744 Mutex::Autolock lock(mQueueItemLock);
745
746 // Ensure that callbacks are handled in order
747 while (item.mFrameNumber != mLastFrameNumberReceived + 1) {
David Sodman9eeae692017-11-02 10:53:32 -0700748 status_t result = mQueueItemCondition.waitRelative(mQueueItemLock,
749 ms2ns(500));
David Sodman0c69cad2017-08-21 12:12:51 -0700750 if (result != NO_ERROR) {
751 ALOGE("[%s] Timed out waiting on callback", mName.string());
752 }
753 }
754
755 if (mQueueItems.empty()) {
756 ALOGE("Can't replace a frame on an empty queue");
757 return;
758 }
759 mQueueItems.editItemAt(mQueueItems.size() - 1) = item;
760
761 // Wake up any pending callbacks
762 mLastFrameNumberReceived = item.mFrameNumber;
763 mQueueItemCondition.broadcast();
764 }
765}
766
767void BufferLayer::onSidebandStreamChanged() {
768 if (android_atomic_release_cas(false, true, &mSidebandStreamChanged) == 0) {
769 // mSidebandStreamChanged was false
770 mFlinger->signalLayerUpdate();
771 }
772}
773
774bool BufferLayer::needsFiltering(const RenderArea& renderArea) const {
775 return mNeedsFiltering || renderArea.needsFiltering();
776}
777
778// As documented in libhardware header, formats in the range
779// 0x100 - 0x1FF are specific to the HAL implementation, and
780// are known to have no alpha channel
781// TODO: move definition for device-specific range into
782// hardware.h, instead of using hard-coded values here.
783#define HARDWARE_IS_DEVICE_FORMAT(f) ((f) >= 0x100 && (f) <= 0x1FF)
784
785bool BufferLayer::getOpacityForFormat(uint32_t format) {
786 if (HARDWARE_IS_DEVICE_FORMAT(format)) {
787 return true;
788 }
789 switch (format) {
790 case HAL_PIXEL_FORMAT_RGBA_8888:
791 case HAL_PIXEL_FORMAT_BGRA_8888:
792 case HAL_PIXEL_FORMAT_RGBA_FP16:
793 case HAL_PIXEL_FORMAT_RGBA_1010102:
794 return false;
795 }
796 // in all other case, we have no blending (also for unknown formats)
797 return true;
798}
799
David Sodman41fdfc92017-11-06 16:09:56 -0800800void BufferLayer::drawWithOpenGL(const RenderArea& renderArea, bool useIdentityTransform) const {
Dan Stoza2713c302018-03-28 17:07:36 -0700801 ATRACE_CALL();
David Sodman0c69cad2017-08-21 12:12:51 -0700802 const State& s(getDrawingState());
803
David Sodman9eeae692017-11-02 10:53:32 -0700804 computeGeometry(renderArea, getBE().mMesh, useIdentityTransform);
David Sodman0c69cad2017-08-21 12:12:51 -0700805
806 /*
807 * NOTE: the way we compute the texture coordinates here produces
808 * different results than when we take the HWC path -- in the later case
809 * the "source crop" is rounded to texel boundaries.
810 * This can produce significantly different results when the texture
811 * is scaled by a large amount.
812 *
813 * The GL code below is more logical (imho), and the difference with
814 * HWC is due to a limitation of the HWC API to integers -- a question
815 * is suspend is whether we should ignore this problem or revert to
816 * GL composition when a buffer scaling is applied (maybe with some
817 * minimal value)? Or, we could make GL behave like HWC -- but this feel
818 * like more of a hack.
819 */
Dan Stoza80d61162017-12-20 15:57:52 -0800820 const Rect bounds{computeBounds()}; // Rounds from FloatRect
David Sodman0c69cad2017-08-21 12:12:51 -0700821
822 Transform t = getTransform();
Dan Stoza80d61162017-12-20 15:57:52 -0800823 Rect win = bounds;
David Sodman0c69cad2017-08-21 12:12:51 -0700824 if (!s.finalCrop.isEmpty()) {
825 win = t.transform(win);
826 if (!win.intersect(s.finalCrop, &win)) {
827 win.clear();
828 }
829 win = t.inverse().transform(win);
Dan Stoza80d61162017-12-20 15:57:52 -0800830 if (!win.intersect(bounds, &win)) {
David Sodman0c69cad2017-08-21 12:12:51 -0700831 win.clear();
832 }
833 }
834
835 float left = float(win.left) / float(s.active.w);
836 float top = float(win.top) / float(s.active.h);
837 float right = float(win.right) / float(s.active.w);
838 float bottom = float(win.bottom) / float(s.active.h);
839
840 // TODO: we probably want to generate the texture coords with the mesh
841 // here we assume that we only have 4 vertices
David Sodman9eeae692017-11-02 10:53:32 -0700842 Mesh::VertexArray<vec2> texCoords(getBE().mMesh.getTexCoordArray<vec2>());
David Sodman0c69cad2017-08-21 12:12:51 -0700843 texCoords[0] = vec2(left, 1.0f - top);
844 texCoords[1] = vec2(left, 1.0f - bottom);
845 texCoords[2] = vec2(right, 1.0f - bottom);
846 texCoords[3] = vec2(right, 1.0f - top);
847
Lloyd Pique144e1162017-12-20 16:44:52 -0800848 auto& engine(mFlinger->getRenderEngine());
David Sodman0c69cad2017-08-21 12:12:51 -0700849 engine.setupLayerBlending(mPremultipliedAlpha, isOpaque(s), false /* disableTexture */,
850 getColor());
David Sodman0c69cad2017-08-21 12:12:51 -0700851 engine.setSourceDataSpace(mCurrentState.dataSpace);
Chia-I Wu5c6e4632018-01-11 08:54:38 -0800852
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700853 if (mCurrentState.dataSpace == ui::Dataspace::BT2020_ITU_PQ &&
Chia-I Wu5c6e4632018-01-11 08:54:38 -0800854 mConsumer->getCurrentApi() == NATIVE_WINDOW_API_MEDIA &&
855 getBE().compositionInfo.mBuffer->getPixelFormat() == HAL_PIXEL_FORMAT_RGBA_1010102) {
856 engine.setSourceY410BT2020(true);
857 }
858
David Sodman9eeae692017-11-02 10:53:32 -0700859 engine.drawMesh(getBE().mMesh);
David Sodman0c69cad2017-08-21 12:12:51 -0700860 engine.disableBlending();
Chia-I Wu5c6e4632018-01-11 08:54:38 -0800861
862 engine.setSourceY410BT2020(false);
David Sodman0c69cad2017-08-21 12:12:51 -0700863}
864
865uint32_t BufferLayer::getProducerStickyTransform() const {
866 int producerStickyTransform = 0;
867 int ret = mProducer->query(NATIVE_WINDOW_STICKY_TRANSFORM, &producerStickyTransform);
868 if (ret != OK) {
869 ALOGW("%s: Error %s (%d) while querying window sticky transform.", __FUNCTION__,
870 strerror(-ret), ret);
871 return 0;
872 }
873 return static_cast<uint32_t>(producerStickyTransform);
874}
875
876bool BufferLayer::latchUnsignaledBuffers() {
877 static bool propertyLoaded = false;
878 static bool latch = false;
879 static std::mutex mutex;
880 std::lock_guard<std::mutex> lock(mutex);
881 if (!propertyLoaded) {
882 char value[PROPERTY_VALUE_MAX] = {};
883 property_get("debug.sf.latch_unsignaled", value, "0");
884 latch = atoi(value);
885 propertyLoaded = true;
886 }
887 return latch;
888}
889
890uint64_t BufferLayer::getHeadFrameNumber() const {
891 Mutex::Autolock lock(mQueueItemLock);
892 if (!mQueueItems.empty()) {
893 return mQueueItems[0].mFrameNumber;
894 } else {
895 return mCurrentFrameNumber;
896 }
897}
898
899bool BufferLayer::headFenceHasSignaled() const {
David Sodman0c69cad2017-08-21 12:12:51 -0700900 if (latchUnsignaledBuffers()) {
901 return true;
902 }
903
904 Mutex::Autolock lock(mQueueItemLock);
905 if (mQueueItems.empty()) {
906 return true;
907 }
908 if (mQueueItems[0].mIsDroppable) {
909 // Even though this buffer's fence may not have signaled yet, it could
910 // be replaced by another buffer before it has a chance to, which means
911 // that it's possible to get into a situation where a buffer is never
912 // able to be latched. To avoid this, grab this buffer anyway.
913 return true;
914 }
David Sodman9eeae692017-11-02 10:53:32 -0700915 return mQueueItems[0].mFenceTime->getSignalTime() !=
916 Fence::SIGNAL_TIME_PENDING;
David Sodman0c69cad2017-08-21 12:12:51 -0700917}
918
919uint32_t BufferLayer::getEffectiveScalingMode() const {
920 if (mOverrideScalingMode >= 0) {
921 return mOverrideScalingMode;
922 }
923 return mCurrentScalingMode;
924}
925
926// ----------------------------------------------------------------------------
927// transaction
928// ----------------------------------------------------------------------------
929
930void BufferLayer::notifyAvailableFrames() {
931 auto headFrameNumber = getHeadFrameNumber();
932 bool headFenceSignaled = headFenceHasSignaled();
933 Mutex::Autolock lock(mLocalSyncPointMutex);
934 for (auto& point : mLocalSyncPoints) {
935 if (headFrameNumber >= point->getFrameNumber() && headFenceSignaled) {
936 point->setFrameAvailable();
937 }
938 }
939}
940
941sp<IGraphicBufferProducer> BufferLayer::getProducer() const {
942 return mProducer;
943}
944
945// ---------------------------------------------------------------------------
946// h/w composer set-up
947// ---------------------------------------------------------------------------
948
949bool BufferLayer::allTransactionsSignaled() {
950 auto headFrameNumber = getHeadFrameNumber();
951 bool matchingFramesFound = false;
952 bool allTransactionsApplied = true;
953 Mutex::Autolock lock(mLocalSyncPointMutex);
954
955 for (auto& point : mLocalSyncPoints) {
956 if (point->getFrameNumber() > headFrameNumber) {
957 break;
958 }
959 matchingFramesFound = true;
960
961 if (!point->frameIsAvailable()) {
962 // We haven't notified the remote layer that the frame for
963 // this point is available yet. Notify it now, and then
964 // abort this attempt to latch.
965 point->setFrameAvailable();
966 allTransactionsApplied = false;
967 break;
968 }
969
970 allTransactionsApplied = allTransactionsApplied && point->transactionIsApplied();
971 }
972 return !matchingFramesFound || allTransactionsApplied;
973}
974
975} // namespace android
976
977#if defined(__gl_h_)
978#error "don't include gl/gl.h in this file"
979#endif
980
981#if defined(__gl2_h_)
982#error "don't include gl2/gl2.h in this file"
983#endif