blob: a6caf29df83bd7f6743f1d02b844c561a86b2b28 [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 Sodman0cf8f8d2017-12-20 18:19:45 -0800101 const sp<GraphicBuffer>& buffer(mActiveBuffer);
102 return (buffer != 0) && (buffer->getUsage() & GRALLOC_USAGE_PROTECTED);
David Sodman0c69cad2017-08-21 12:12:51 -0700103}
104
105bool BufferLayer::isVisible() const {
106 return !(isHiddenByPolicy()) && getAlpha() > 0.0f &&
David Sodman0cf8f8d2017-12-20 18:19:45 -0800107 (mActiveBuffer != nullptr || getBE().compositionInfo.hwc.sidebandStream != nullptr);
David Sodman0c69cad2017-08-21 12:12:51 -0700108}
109
110bool BufferLayer::isFixedSize() const {
111 return getEffectiveScalingMode() != NATIVE_WINDOW_SCALING_MODE_FREEZE;
112}
113
114status_t BufferLayer::setBuffers(uint32_t w, uint32_t h, PixelFormat format, uint32_t flags) {
115 uint32_t const maxSurfaceDims =
116 min(mFlinger->getMaxTextureSize(), mFlinger->getMaxViewportDims());
117
118 // never allow a surface larger than what our underlying GL implementation
119 // can handle.
120 if ((uint32_t(w) > maxSurfaceDims) || (uint32_t(h) > maxSurfaceDims)) {
121 ALOGE("dimensions too large %u x %u", uint32_t(w), uint32_t(h));
122 return BAD_VALUE;
123 }
124
125 mFormat = format;
126
127 mPotentialCursor = (flags & ISurfaceComposerClient::eCursorWindow) ? true : false;
128 mProtectedByApp = (flags & ISurfaceComposerClient::eProtectedByApp) ? true : false;
129 mCurrentOpacity = getOpacityForFormat(format);
130
Chia-I Wub28c6742017-12-27 10:59:54 -0800131 mConsumer->setDefaultBufferSize(w, h);
132 mConsumer->setDefaultBufferFormat(format);
133 mConsumer->setConsumerUsageBits(getEffectiveUsage(0));
David Sodman0c69cad2017-08-21 12:12:51 -0700134
135 return NO_ERROR;
136}
137
138static constexpr mat4 inverseOrientation(uint32_t transform) {
David Sodman41fdfc92017-11-06 16:09:56 -0800139 const mat4 flipH(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1);
140 const mat4 flipV(1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1);
141 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 -0700142 mat4 tr;
143
144 if (transform & NATIVE_WINDOW_TRANSFORM_ROT_90) {
145 tr = tr * rot90;
146 }
147 if (transform & NATIVE_WINDOW_TRANSFORM_FLIP_H) {
148 tr = tr * flipH;
149 }
150 if (transform & NATIVE_WINDOW_TRANSFORM_FLIP_V) {
151 tr = tr * flipV;
152 }
153 return inverse(tr);
154}
155
156/*
157 * onDraw will draw the current layer onto the presentable buffer
158 */
159void BufferLayer::onDraw(const RenderArea& renderArea, const Region& clip,
160 bool useIdentityTransform) const {
161 ATRACE_CALL();
162
David Sodmandc5e0622018-01-05 23:10:57 -0800163 CompositionInfo& compositionInfo = getBE().compositionInfo;
164
David Sodman0cf8f8d2017-12-20 18:19:45 -0800165 if (CC_UNLIKELY(mActiveBuffer == 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 Sodman0cf8f8d2017-12-20 18:19:45 -0800243 mTexture.setDimensions(mActiveBuffer->getWidth(), mActiveBuffer->getHeight());
David Sodman0c69cad2017-08-21 12:12:51 -0700244 mTexture.setFiltering(useFiltering);
245 mTexture.setMatrix(textureMatrix);
David Sodmandc5e0622018-01-05 23:10:57 -0800246 compositionInfo.re.texture = mTexture;
David Sodman0c69cad2017-08-21 12:12:51 -0700247
248 engine.setupLayerTexturing(mTexture);
249 } else {
250 engine.setupLayerBlackedOut();
251 }
252 drawWithOpenGL(renderArea, useIdentityTransform);
253 engine.disableTexturing();
254}
255
David Sodmandc5e0622018-01-05 23:10:57 -0800256void BufferLayer::drawNow(const RenderArea& renderArea, bool useIdentityTransform) const {
257 CompositionInfo& compositionInfo = getBE().compositionInfo;
258 auto& engine(mFlinger->getRenderEngine());
259
260 draw(renderArea, useIdentityTransform);
261
262 engine.setupLayerTexturing(compositionInfo.re.texture);
263 engine.setupLayerBlending(compositionInfo.re.preMultipliedAlpha, compositionInfo.re.opaque,
264 false, compositionInfo.re.color);
265 engine.setSourceDataSpace(compositionInfo.hwc.dataspace);
266 engine.setSourceY410BT2020(compositionInfo.re.Y410BT2020);
267 engine.drawMesh(getBE().getMesh());
268 engine.disableBlending();
269 engine.disableTexturing();
270 engine.setSourceY410BT2020(false);
271}
272
David Sodmaneb085e02017-10-05 18:49:04 -0700273void BufferLayer::onLayerDisplayed(const sp<Fence>& releaseFence) {
Chia-I Wub28c6742017-12-27 10:59:54 -0800274 mConsumer->setReleaseFence(releaseFence);
David Sodmaneb085e02017-10-05 18:49:04 -0700275}
David Sodmaneb085e02017-10-05 18:49:04 -0700276
277void BufferLayer::abandon() {
Chia-I Wub28c6742017-12-27 10:59:54 -0800278 mConsumer->abandon();
David Sodmaneb085e02017-10-05 18:49:04 -0700279}
280
281bool BufferLayer::shouldPresentNow(const DispSync& dispSync) const {
282 if (mSidebandStreamChanged || mAutoRefresh) {
283 return true;
284 }
285
286 Mutex::Autolock lock(mQueueItemLock);
287 if (mQueueItems.empty()) {
288 return false;
289 }
290 auto timestamp = mQueueItems[0].mTimestamp;
Chia-I Wub28c6742017-12-27 10:59:54 -0800291 nsecs_t expectedPresent = mConsumer->computeExpectedPresent(dispSync);
David Sodmaneb085e02017-10-05 18:49:04 -0700292
293 // Ignore timestamps more than a second in the future
294 bool isPlausible = timestamp < (expectedPresent + s2ns(1));
295 ALOGW_IF(!isPlausible,
296 "[%s] Timestamp %" PRId64 " seems implausible "
297 "relative to expectedPresent %" PRId64,
298 mName.string(), timestamp, expectedPresent);
299
300 bool isDue = timestamp < expectedPresent;
301 return isDue || !isPlausible;
302}
303
304void BufferLayer::setTransformHint(uint32_t orientation) const {
Chia-I Wub28c6742017-12-27 10:59:54 -0800305 mConsumer->setTransformHint(orientation);
David Sodmaneb085e02017-10-05 18:49:04 -0700306}
307
David Sodman0c69cad2017-08-21 12:12:51 -0700308bool BufferLayer::onPreComposition(nsecs_t refreshStartTime) {
309 if (mBufferLatched) {
310 Mutex::Autolock lock(mFrameEventHistoryMutex);
David Sodman0cf8f8d2017-12-20 18:19:45 -0800311 mFrameEventHistory.addPreComposition(mCurrentFrameNumber, refreshStartTime);
David Sodman0c69cad2017-08-21 12:12:51 -0700312 }
313 mRefreshPending = false;
David Sodman0cf8f8d2017-12-20 18:19:45 -0800314 return mQueuedFrames > 0 || mSidebandStreamChanged || mAutoRefresh;
David Sodman0c69cad2017-08-21 12:12:51 -0700315}
David Sodmaneb085e02017-10-05 18:49:04 -0700316bool BufferLayer::onPostComposition(const std::shared_ptr<FenceTime>& glDoneFence,
317 const std::shared_ptr<FenceTime>& presentFence,
318 const CompositorTiming& compositorTiming) {
319 // mFrameLatencyNeeded is true when a new frame was latched for the
320 // composition.
321 if (!mFrameLatencyNeeded) return false;
322
323 // Update mFrameEventHistory.
324 {
325 Mutex::Autolock lock(mFrameEventHistoryMutex);
David Sodman0cf8f8d2017-12-20 18:19:45 -0800326 mFrameEventHistory.addPostComposition(mCurrentFrameNumber, glDoneFence, presentFence,
327 compositorTiming);
David Sodmaneb085e02017-10-05 18:49:04 -0700328 }
329
330 // Update mFrameTracker.
Chia-I Wub28c6742017-12-27 10:59:54 -0800331 nsecs_t desiredPresentTime = mConsumer->getTimestamp();
David Sodmaneb085e02017-10-05 18:49:04 -0700332 mFrameTracker.setDesiredPresentTime(desiredPresentTime);
333
Chia-I Wub28c6742017-12-27 10:59:54 -0800334 std::shared_ptr<FenceTime> frameReadyFence = mConsumer->getCurrentFenceTime();
David Sodmaneb085e02017-10-05 18:49:04 -0700335 if (frameReadyFence->isValid()) {
336 mFrameTracker.setFrameReadyFence(std::move(frameReadyFence));
337 } else {
338 // There was no fence for this frame, so assume that it was ready
339 // to be presented at the desired present time.
340 mFrameTracker.setFrameReadyTime(desiredPresentTime);
341 }
342
343 if (presentFence->isValid()) {
344 mFrameTracker.setActualPresentFence(std::shared_ptr<FenceTime>(presentFence));
345 } else {
346 // The HWC doesn't support present fences, so use the refresh
347 // timestamp instead.
348 mFrameTracker.setActualPresentTime(
349 mFlinger->getHwComposer().getRefreshTimestamp(HWC_DISPLAY_PRIMARY));
350 }
351
352 mFrameTracker.advanceFrame();
353 mFrameLatencyNeeded = false;
354 return true;
355}
356
357std::vector<OccupancyTracker::Segment> BufferLayer::getOccupancyHistory(bool forceFlush) {
358 std::vector<OccupancyTracker::Segment> history;
Chia-I Wub28c6742017-12-27 10:59:54 -0800359 status_t result = mConsumer->getOccupancyHistory(forceFlush, &history);
David Sodmaneb085e02017-10-05 18:49:04 -0700360 if (result != NO_ERROR) {
361 ALOGW("[%s] Failed to obtain occupancy history (%d)", mName.string(), result);
362 return {};
363 }
364 return history;
365}
366
367bool BufferLayer::getTransformToDisplayInverse() const {
Chia-I Wub28c6742017-12-27 10:59:54 -0800368 return mConsumer->getTransformToDisplayInverse();
David Sodmaneb085e02017-10-05 18:49:04 -0700369}
David Sodman0c69cad2017-08-21 12:12:51 -0700370
David Sodman0c69cad2017-08-21 12:12:51 -0700371void BufferLayer::releasePendingBuffer(nsecs_t dequeueReadyTime) {
Chia-I Wub28c6742017-12-27 10:59:54 -0800372 if (!mConsumer->releasePendingBuffer()) {
David Sodman0c69cad2017-08-21 12:12:51 -0700373 return;
374 }
375
David Sodman0cf8f8d2017-12-20 18:19:45 -0800376 auto releaseFenceTime = std::make_shared<FenceTime>(mConsumer->getPrevFinalReleaseFence());
David Sodman0c69cad2017-08-21 12:12:51 -0700377 mReleaseTimeline.updateSignalTimes();
378 mReleaseTimeline.push(releaseFenceTime);
379
380 Mutex::Autolock lock(mFrameEventHistoryMutex);
381 if (mPreviousFrameNumber != 0) {
382 mFrameEventHistory.addRelease(mPreviousFrameNumber, dequeueReadyTime,
383 std::move(releaseFenceTime));
384 }
385}
David Sodman0c69cad2017-08-21 12:12:51 -0700386
387Region BufferLayer::latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime) {
388 ATRACE_CALL();
389
390 if (android_atomic_acquire_cas(true, false, &mSidebandStreamChanged) == 0) {
391 // mSidebandStreamChanged was true
Chia-I Wub28c6742017-12-27 10:59:54 -0800392 mSidebandStream = mConsumer->getSidebandStream();
David Sodman386c22e2017-11-09 16:34:46 -0800393 // replicated in LayerBE until FE/BE is ready to be synchronized
David Sodman0cc69182017-11-17 12:12:07 -0800394 getBE().compositionInfo.hwc.sidebandStream = mSidebandStream;
Peiyong Lin566a3b42018-01-09 18:22:43 -0800395 if (getBE().compositionInfo.hwc.sidebandStream != nullptr) {
David Sodman0c69cad2017-08-21 12:12:51 -0700396 setTransactionFlags(eTransactionNeeded);
397 mFlinger->setTransactionFlags(eTraversalNeeded);
398 }
399 recomputeVisibleRegions = true;
400
401 const State& s(getDrawingState());
402 return getTransform().transform(Region(Rect(s.active.w, s.active.h)));
403 }
404
405 Region outDirtyRegion;
406 if (mQueuedFrames <= 0 && !mAutoRefresh) {
407 return outDirtyRegion;
408 }
409
410 // if we've already called updateTexImage() without going through
411 // a composition step, we have to skip this layer at this point
412 // because we cannot call updateTeximage() without a corresponding
413 // compositionComplete() call.
414 // we'll trigger an update in onPreComposition().
415 if (mRefreshPending) {
416 return outDirtyRegion;
417 }
418
419 // If the head buffer's acquire fence hasn't signaled yet, return and
420 // try again later
421 if (!headFenceHasSignaled()) {
422 mFlinger->signalLayerUpdate();
423 return outDirtyRegion;
424 }
425
426 // Capture the old state of the layer for comparisons later
427 const State& s(getDrawingState());
428 const bool oldOpacity = isOpaque(s);
David Sodman0cf8f8d2017-12-20 18:19:45 -0800429 sp<GraphicBuffer> oldBuffer = mActiveBuffer;
David Sodman0c69cad2017-08-21 12:12:51 -0700430
431 if (!allTransactionsSignaled()) {
432 mFlinger->signalLayerUpdate();
433 return outDirtyRegion;
434 }
435
436 // This boolean is used to make sure that SurfaceFlinger's shadow copy
437 // of the buffer queue isn't modified when the buffer queue is returning
438 // BufferItem's that weren't actually queued. This can happen in shared
439 // buffer mode.
440 bool queuedBuffer = false;
441 LayerRejecter r(mDrawingState, getCurrentState(), recomputeVisibleRegions,
David Sodman0cf8f8d2017-12-20 18:19:45 -0800442 getProducerStickyTransform() != 0, mName.string(), mOverrideScalingMode,
443 mFreezeGeometryUpdates);
444 status_t updateResult = mConsumer->updateTexImage(&r, mFlinger->mPrimaryDispSync, &mAutoRefresh,
445 &queuedBuffer, mLastFrameNumberReceived);
David Sodman0c69cad2017-08-21 12:12:51 -0700446 if (updateResult == BufferQueue::PRESENT_LATER) {
447 // Producer doesn't want buffer to be displayed yet. Signal a
448 // layer update so we check again at the next opportunity.
449 mFlinger->signalLayerUpdate();
450 return outDirtyRegion;
Chia-I Wu0cb75ac2017-11-27 15:56:04 -0800451 } else if (updateResult == BufferLayerConsumer::BUFFER_REJECTED) {
David Sodman0c69cad2017-08-21 12:12:51 -0700452 // If the buffer has been rejected, remove it from the shadow queue
453 // and return early
454 if (queuedBuffer) {
455 Mutex::Autolock lock(mQueueItemLock);
456 mQueueItems.removeAt(0);
457 android_atomic_dec(&mQueuedFrames);
458 }
459 return outDirtyRegion;
460 } else if (updateResult != NO_ERROR || mUpdateTexImageFailed) {
461 // This can occur if something goes wrong when trying to create the
462 // EGLImage for this buffer. If this happens, the buffer has already
463 // been released, so we need to clean up the queue and bug out
464 // early.
465 if (queuedBuffer) {
466 Mutex::Autolock lock(mQueueItemLock);
467 mQueueItems.clear();
468 android_atomic_and(0, &mQueuedFrames);
469 }
470
471 // Once we have hit this state, the shadow queue may no longer
472 // correctly reflect the incoming BufferQueue's contents, so even if
473 // updateTexImage starts working, the only safe course of action is
474 // to continue to ignore updates.
475 mUpdateTexImageFailed = true;
476
477 return outDirtyRegion;
478 }
479
480 if (queuedBuffer) {
481 // Autolock scope
Chia-I Wub28c6742017-12-27 10:59:54 -0800482 auto currentFrameNumber = mConsumer->getFrameNumber();
David Sodman0c69cad2017-08-21 12:12:51 -0700483
484 Mutex::Autolock lock(mQueueItemLock);
485
486 // Remove any stale buffers that have been dropped during
487 // updateTexImage
488 while (mQueueItems[0].mFrameNumber != currentFrameNumber) {
489 mQueueItems.removeAt(0);
490 android_atomic_dec(&mQueuedFrames);
491 }
492
493 mQueueItems.removeAt(0);
494 }
495
496 // Decrement the queued-frames count. Signal another event if we
497 // have more frames pending.
David Sodman0cf8f8d2017-12-20 18:19:45 -0800498 if ((queuedBuffer && android_atomic_dec(&mQueuedFrames) > 1) || mAutoRefresh) {
David Sodman0c69cad2017-08-21 12:12:51 -0700499 mFlinger->signalLayerUpdate();
500 }
501
502 // update the active buffer
David Sodman0cf8f8d2017-12-20 18:19:45 -0800503 mActiveBuffer = mConsumer->getCurrentBuffer(&mActiveBufferSlot);
504 getBE().compositionInfo.mBuffer = mActiveBuffer;
505 getBE().compositionInfo.mBufferSlot = mActiveBufferSlot;
506
507 if (mActiveBuffer == nullptr) {
David Sodman0c69cad2017-08-21 12:12:51 -0700508 // this can only happen if the very first buffer was rejected.
509 return outDirtyRegion;
510 }
511
512 mBufferLatched = true;
513 mPreviousFrameNumber = mCurrentFrameNumber;
Chia-I Wub28c6742017-12-27 10:59:54 -0800514 mCurrentFrameNumber = mConsumer->getFrameNumber();
David Sodman0c69cad2017-08-21 12:12:51 -0700515
516 {
517 Mutex::Autolock lock(mFrameEventHistoryMutex);
518 mFrameEventHistory.addLatch(mCurrentFrameNumber, latchTime);
David Sodman0c69cad2017-08-21 12:12:51 -0700519 }
520
521 mRefreshPending = true;
522 mFrameLatencyNeeded = true;
Peiyong Lin566a3b42018-01-09 18:22:43 -0800523 if (oldBuffer == nullptr) {
David Sodman0c69cad2017-08-21 12:12:51 -0700524 // the first time we receive a buffer, we need to trigger a
525 // geometry invalidation.
526 recomputeVisibleRegions = true;
527 }
528
Chia-I Wub28c6742017-12-27 10:59:54 -0800529 setDataSpace(mConsumer->getCurrentDataSpace());
David Sodman0c69cad2017-08-21 12:12:51 -0700530
Chia-I Wub28c6742017-12-27 10:59:54 -0800531 Rect crop(mConsumer->getCurrentCrop());
532 const uint32_t transform(mConsumer->getCurrentTransform());
533 const uint32_t scalingMode(mConsumer->getCurrentScalingMode());
David Sodman0cf8f8d2017-12-20 18:19:45 -0800534 if ((crop != mCurrentCrop) || (transform != mCurrentTransform) ||
David Sodman0c69cad2017-08-21 12:12:51 -0700535 (scalingMode != mCurrentScalingMode)) {
536 mCurrentCrop = crop;
537 mCurrentTransform = transform;
538 mCurrentScalingMode = scalingMode;
539 recomputeVisibleRegions = true;
540 }
541
Peiyong Lin566a3b42018-01-09 18:22:43 -0800542 if (oldBuffer != nullptr) {
David Sodman0cf8f8d2017-12-20 18:19:45 -0800543 uint32_t bufWidth = mActiveBuffer->getWidth();
544 uint32_t bufHeight = mActiveBuffer->getHeight();
545 if (bufWidth != uint32_t(oldBuffer->width) || bufHeight != uint32_t(oldBuffer->height)) {
David Sodman0c69cad2017-08-21 12:12:51 -0700546 recomputeVisibleRegions = true;
547 }
548 }
549
David Sodman0cf8f8d2017-12-20 18:19:45 -0800550 mCurrentOpacity = getOpacityForFormat(mActiveBuffer->format);
David Sodman0c69cad2017-08-21 12:12:51 -0700551 if (oldOpacity != isOpaque(s)) {
552 recomputeVisibleRegions = true;
553 }
554
555 // Remove any sync points corresponding to the buffer which was just
556 // latched
557 {
558 Mutex::Autolock lock(mLocalSyncPointMutex);
559 auto point = mLocalSyncPoints.begin();
560 while (point != mLocalSyncPoints.end()) {
561 if (!(*point)->frameIsAvailable() || !(*point)->transactionIsApplied()) {
562 // This sync point must have been added since we started
563 // latching. Don't drop it yet.
564 ++point;
565 continue;
566 }
567
568 if ((*point)->getFrameNumber() <= mCurrentFrameNumber) {
569 point = mLocalSyncPoints.erase(point);
570 } else {
571 ++point;
572 }
573 }
574 }
575
576 // FIXME: postedRegion should be dirty & bounds
577 Region dirtyRegion(Rect(s.active.w, s.active.h));
578
579 // transform the dirty region to window-manager space
580 outDirtyRegion = (getTransform().transform(dirtyRegion));
581
582 return outDirtyRegion;
583}
584
David Sodmaneb085e02017-10-05 18:49:04 -0700585void BufferLayer::setDefaultBufferSize(uint32_t w, uint32_t h) {
Chia-I Wub28c6742017-12-27 10:59:54 -0800586 mConsumer->setDefaultBufferSize(w, h);
David Sodmaneb085e02017-10-05 18:49:04 -0700587}
588
David Sodman0c69cad2017-08-21 12:12:51 -0700589void BufferLayer::setPerFrameData(const sp<const DisplayDevice>& displayDevice) {
590 // Apply this display's projection's viewport to the visible region
591 // before giving it to the HWC HAL.
592 const Transform& tr = displayDevice->getTransform();
593 const auto& viewport = displayDevice->getViewport();
594 Region visible = tr.transform(visibleRegion.intersect(viewport));
595 auto hwcId = displayDevice->getHwcDisplayId();
David Sodman6f65f3e2017-11-03 14:28:09 -0700596 auto& hwcInfo = getBE().mHwcLayers[hwcId];
David Sodman0c69cad2017-08-21 12:12:51 -0700597 auto& hwcLayer = hwcInfo.layer;
David Sodman5d89c1d2017-12-14 15:54:51 -0800598 auto error = (*hwcLayer)->setVisibleRegion(visible);
David Sodman0c69cad2017-08-21 12:12:51 -0700599 if (error != HWC2::Error::None) {
600 ALOGE("[%s] Failed to set visible region: %s (%d)", mName.string(),
601 to_string(error).c_str(), static_cast<int32_t>(error));
602 visible.dump(LOG_TAG);
603 }
604
David Sodman5d89c1d2017-12-14 15:54:51 -0800605 error = (*hwcLayer)->setSurfaceDamage(surfaceDamageRegion);
David Sodman0c69cad2017-08-21 12:12:51 -0700606 if (error != HWC2::Error::None) {
607 ALOGE("[%s] Failed to set surface damage: %s (%d)", mName.string(),
608 to_string(error).c_str(), static_cast<int32_t>(error));
609 surfaceDamageRegion.dump(LOG_TAG);
610 }
611
612 // Sideband layers
David Sodman0cc69182017-11-17 12:12:07 -0800613 if (getBE().compositionInfo.hwc.sidebandStream.get()) {
David Sodman0c69cad2017-08-21 12:12:51 -0700614 setCompositionType(hwcId, HWC2::Composition::Sideband);
615 ALOGV("[%s] Requesting Sideband composition", mName.string());
David Sodman5d89c1d2017-12-14 15:54:51 -0800616 error = (*hwcLayer)->setSidebandStream(getBE().compositionInfo.hwc.sidebandStream->handle());
David Sodman0c69cad2017-08-21 12:12:51 -0700617 if (error != HWC2::Error::None) {
618 ALOGE("[%s] Failed to set sideband stream %p: %s (%d)", mName.string(),
David Sodman0cc69182017-11-17 12:12:07 -0800619 getBE().compositionInfo.hwc.sidebandStream->handle(), to_string(error).c_str(),
David Sodman9eeae692017-11-02 10:53:32 -0700620 static_cast<int32_t>(error));
David Sodman0c69cad2017-08-21 12:12:51 -0700621 }
622 return;
623 }
624
David Sodman0c69cad2017-08-21 12:12:51 -0700625 // Device or Cursor layers
626 if (mPotentialCursor) {
627 ALOGV("[%s] Requesting Cursor composition", mName.string());
628 setCompositionType(hwcId, HWC2::Composition::Cursor);
629 } else {
630 ALOGV("[%s] Requesting Device composition", mName.string());
631 setCompositionType(hwcId, HWC2::Composition::Device);
632 }
633
Peiyong Lin13170c82018-01-22 18:55:51 -0800634 ALOGV("setPerFrameData: dataspace = %d", mDrawingState.dataSpace);
David Sodman5d89c1d2017-12-14 15:54:51 -0800635 error = (*hwcLayer)->setDataspace(mDrawingState.dataSpace);
David Sodman0c69cad2017-08-21 12:12:51 -0700636 if (error != HWC2::Error::None) {
Peiyong Lin13170c82018-01-22 18:55:51 -0800637 ALOGE("[%s] Failed to set dataspace %d: %s (%d)", mName.string(), mDrawingState.dataSpace,
David Sodman0c69cad2017-08-21 12:12:51 -0700638 to_string(error).c_str(), static_cast<int32_t>(error));
639 }
640
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700641 const HdrMetadata& metadata = mConsumer->getCurrentHdrMetadata();
David Sodman5d89c1d2017-12-14 15:54:51 -0800642 error = (*hwcLayer)->setHdrMetadata(metadata);
Courtney Goeltzenleuchter301bb302018-03-12 11:12:42 -0600643 if (error != HWC2::Error::None && error != HWC2::Error::Unsupported) {
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700644 ALOGE("[%s] Failed to set hdrMetadata: %s (%d)", mName.string(),
645 to_string(error).c_str(), static_cast<int32_t>(error));
646 }
647
David Sodman0c69cad2017-08-21 12:12:51 -0700648 uint32_t hwcSlot = 0;
649 sp<GraphicBuffer> hwcBuffer;
David Sodman0cf8f8d2017-12-20 18:19:45 -0800650 getBE().mHwcLayers[hwcId].bufferCache.getHwcBuffer(mActiveBufferSlot, mActiveBuffer, &hwcSlot,
651 &hwcBuffer);
David Sodman0c69cad2017-08-21 12:12:51 -0700652
Chia-I Wub28c6742017-12-27 10:59:54 -0800653 auto acquireFence = mConsumer->getCurrentFence();
David Sodman5d89c1d2017-12-14 15:54:51 -0800654 error = (*hwcLayer)->setBuffer(hwcSlot, hwcBuffer, acquireFence);
David Sodman0c69cad2017-08-21 12:12:51 -0700655 if (error != HWC2::Error::None) {
David Sodman9eeae692017-11-02 10:53:32 -0700656 ALOGE("[%s] Failed to set buffer %p: %s (%d)", mName.string(),
David Sodman0cc69182017-11-17 12:12:07 -0800657 getBE().compositionInfo.mBuffer->handle, to_string(error).c_str(),
David Sodman9eeae692017-11-02 10:53:32 -0700658 static_cast<int32_t>(error));
David Sodman0c69cad2017-08-21 12:12:51 -0700659 }
660}
661
David Sodman41fdfc92017-11-06 16:09:56 -0800662bool BufferLayer::isOpaque(const Layer::State& s) const {
David Sodman0c69cad2017-08-21 12:12:51 -0700663 // if we don't have a buffer or sidebandStream yet, we're translucent regardless of the
664 // layer's opaque flag.
David Sodman0cf8f8d2017-12-20 18:19:45 -0800665 if ((getBE().compositionInfo.hwc.sidebandStream == nullptr) && (mActiveBuffer == nullptr)) {
David Sodman0c69cad2017-08-21 12:12:51 -0700666 return false;
667 }
668
669 // if the layer has the opaque flag, then we're always opaque,
670 // otherwise we use the current buffer's format.
671 return ((s.flags & layer_state_t::eLayerOpaque) != 0) || mCurrentOpacity;
672}
673
674void BufferLayer::onFirstRef() {
675 // Creates a custom BufferQueue for SurfaceFlingerConsumer to use
676 sp<IGraphicBufferProducer> producer;
677 sp<IGraphicBufferConsumer> consumer;
678 BufferQueue::createBufferQueue(&producer, &consumer, true);
679 mProducer = new MonitoredProducer(producer, mFlinger, this);
David Sodman0cf8f8d2017-12-20 18:19:45 -0800680 mConsumer = new BufferLayerConsumer(consumer, mFlinger->getRenderEngine(), mTextureName, this);
Chia-I Wub28c6742017-12-27 10:59:54 -0800681 mConsumer->setConsumerUsageBits(getEffectiveUsage(0));
682 mConsumer->setContentsChangedListener(this);
683 mConsumer->setName(mName);
David Sodman0c69cad2017-08-21 12:12:51 -0700684
685 if (mFlinger->isLayerTripleBufferingDisabled()) {
686 mProducer->setMaxDequeuedBufferCount(2);
687 }
688
689 const sp<const DisplayDevice> hw(mFlinger->getDefaultDisplayDevice());
690 updateTransformHint(hw);
691}
692
693// ---------------------------------------------------------------------------
694// Interface implementation for SurfaceFlingerConsumer::ContentsChangedListener
695// ---------------------------------------------------------------------------
696
697void BufferLayer::onFrameAvailable(const BufferItem& item) {
698 // Add this buffer from our internal queue tracker
699 { // Autolock scope
700 Mutex::Autolock lock(mQueueItemLock);
Lloyd Pique4dccc412018-01-22 17:21:36 -0800701 mFlinger->mInterceptor->saveBufferUpdate(this, item.mGraphicBuffer->getWidth(),
702 item.mGraphicBuffer->getHeight(),
703 item.mFrameNumber);
David Sodman0c69cad2017-08-21 12:12:51 -0700704 // Reset the frame number tracker when we receive the first buffer after
705 // a frame number reset
706 if (item.mFrameNumber == 1) {
707 mLastFrameNumberReceived = 0;
708 }
709
710 // Ensure that callbacks are handled in order
711 while (item.mFrameNumber != mLastFrameNumberReceived + 1) {
David Sodman0cf8f8d2017-12-20 18:19:45 -0800712 status_t result = mQueueItemCondition.waitRelative(mQueueItemLock, ms2ns(500));
David Sodman0c69cad2017-08-21 12:12:51 -0700713 if (result != NO_ERROR) {
714 ALOGE("[%s] Timed out waiting on callback", mName.string());
715 }
716 }
717
718 mQueueItems.push_back(item);
719 android_atomic_inc(&mQueuedFrames);
720
721 // Wake up any pending callbacks
722 mLastFrameNumberReceived = item.mFrameNumber;
723 mQueueItemCondition.broadcast();
724 }
725
726 mFlinger->signalLayerUpdate();
727}
728
729void BufferLayer::onFrameReplaced(const BufferItem& item) {
730 { // Autolock scope
731 Mutex::Autolock lock(mQueueItemLock);
732
733 // Ensure that callbacks are handled in order
734 while (item.mFrameNumber != mLastFrameNumberReceived + 1) {
David Sodman0cf8f8d2017-12-20 18:19:45 -0800735 status_t result = mQueueItemCondition.waitRelative(mQueueItemLock, ms2ns(500));
David Sodman0c69cad2017-08-21 12:12:51 -0700736 if (result != NO_ERROR) {
737 ALOGE("[%s] Timed out waiting on callback", mName.string());
738 }
739 }
740
741 if (mQueueItems.empty()) {
742 ALOGE("Can't replace a frame on an empty queue");
743 return;
744 }
745 mQueueItems.editItemAt(mQueueItems.size() - 1) = item;
746
747 // Wake up any pending callbacks
748 mLastFrameNumberReceived = item.mFrameNumber;
749 mQueueItemCondition.broadcast();
750 }
751}
752
753void BufferLayer::onSidebandStreamChanged() {
754 if (android_atomic_release_cas(false, true, &mSidebandStreamChanged) == 0) {
755 // mSidebandStreamChanged was false
756 mFlinger->signalLayerUpdate();
757 }
758}
759
760bool BufferLayer::needsFiltering(const RenderArea& renderArea) const {
761 return mNeedsFiltering || renderArea.needsFiltering();
762}
763
764// As documented in libhardware header, formats in the range
765// 0x100 - 0x1FF are specific to the HAL implementation, and
766// are known to have no alpha channel
767// TODO: move definition for device-specific range into
768// hardware.h, instead of using hard-coded values here.
769#define HARDWARE_IS_DEVICE_FORMAT(f) ((f) >= 0x100 && (f) <= 0x1FF)
770
771bool BufferLayer::getOpacityForFormat(uint32_t format) {
772 if (HARDWARE_IS_DEVICE_FORMAT(format)) {
773 return true;
774 }
775 switch (format) {
776 case HAL_PIXEL_FORMAT_RGBA_8888:
777 case HAL_PIXEL_FORMAT_BGRA_8888:
778 case HAL_PIXEL_FORMAT_RGBA_FP16:
779 case HAL_PIXEL_FORMAT_RGBA_1010102:
780 return false;
781 }
782 // in all other case, we have no blending (also for unknown formats)
783 return true;
784}
785
David Sodman41fdfc92017-11-06 16:09:56 -0800786void BufferLayer::drawWithOpenGL(const RenderArea& renderArea, bool useIdentityTransform) const {
David Sodman0c69cad2017-08-21 12:12:51 -0700787 const State& s(getDrawingState());
788
David Sodman9eeae692017-11-02 10:53:32 -0700789 computeGeometry(renderArea, getBE().mMesh, useIdentityTransform);
David Sodman0c69cad2017-08-21 12:12:51 -0700790
791 /*
792 * NOTE: the way we compute the texture coordinates here produces
793 * different results than when we take the HWC path -- in the later case
794 * the "source crop" is rounded to texel boundaries.
795 * This can produce significantly different results when the texture
796 * is scaled by a large amount.
797 *
798 * The GL code below is more logical (imho), and the difference with
799 * HWC is due to a limitation of the HWC API to integers -- a question
800 * is suspend is whether we should ignore this problem or revert to
801 * GL composition when a buffer scaling is applied (maybe with some
802 * minimal value)? Or, we could make GL behave like HWC -- but this feel
803 * like more of a hack.
804 */
Dan Stoza80d61162017-12-20 15:57:52 -0800805 const Rect bounds{computeBounds()}; // Rounds from FloatRect
David Sodman0c69cad2017-08-21 12:12:51 -0700806
807 Transform t = getTransform();
Dan Stoza80d61162017-12-20 15:57:52 -0800808 Rect win = bounds;
David Sodman0c69cad2017-08-21 12:12:51 -0700809 if (!s.finalCrop.isEmpty()) {
810 win = t.transform(win);
811 if (!win.intersect(s.finalCrop, &win)) {
812 win.clear();
813 }
814 win = t.inverse().transform(win);
Dan Stoza80d61162017-12-20 15:57:52 -0800815 if (!win.intersect(bounds, &win)) {
David Sodman0c69cad2017-08-21 12:12:51 -0700816 win.clear();
817 }
818 }
819
820 float left = float(win.left) / float(s.active.w);
821 float top = float(win.top) / float(s.active.h);
822 float right = float(win.right) / float(s.active.w);
823 float bottom = float(win.bottom) / float(s.active.h);
824
825 // TODO: we probably want to generate the texture coords with the mesh
826 // here we assume that we only have 4 vertices
David Sodman9eeae692017-11-02 10:53:32 -0700827 Mesh::VertexArray<vec2> texCoords(getBE().mMesh.getTexCoordArray<vec2>());
David Sodman0c69cad2017-08-21 12:12:51 -0700828 texCoords[0] = vec2(left, 1.0f - top);
829 texCoords[1] = vec2(left, 1.0f - bottom);
830 texCoords[2] = vec2(right, 1.0f - bottom);
831 texCoords[3] = vec2(right, 1.0f - top);
832
David Sodmandc5e0622018-01-05 23:10:57 -0800833 getBE().compositionInfo.re.preMultipliedAlpha = mPremultipliedAlpha;
834 getBE().compositionInfo.re.opaque = isOpaque(s);
835 getBE().compositionInfo.re.disableTexture = false;
836 getBE().compositionInfo.re.color = getColor();
837 getBE().compositionInfo.hwc.dataspace = mCurrentState.dataSpace;
Chia-I Wu5c6e4632018-01-11 08:54:38 -0800838
Chia-I Wu8d2651e2018-01-24 12:18:49 -0800839 if (mCurrentState.dataSpace == HAL_DATASPACE_BT2020_ITU_PQ &&
Chia-I Wu5c6e4632018-01-11 08:54:38 -0800840 mConsumer->getCurrentApi() == NATIVE_WINDOW_API_MEDIA &&
841 getBE().compositionInfo.mBuffer->getPixelFormat() == HAL_PIXEL_FORMAT_RGBA_1010102) {
David Sodmandc5e0622018-01-05 23:10:57 -0800842 getBE().compositionInfo.re.Y410BT2020 = true;
Chia-I Wu5c6e4632018-01-11 08:54:38 -0800843 }
David Sodman0c69cad2017-08-21 12:12:51 -0700844}
845
846uint32_t BufferLayer::getProducerStickyTransform() const {
847 int producerStickyTransform = 0;
848 int ret = mProducer->query(NATIVE_WINDOW_STICKY_TRANSFORM, &producerStickyTransform);
849 if (ret != OK) {
850 ALOGW("%s: Error %s (%d) while querying window sticky transform.", __FUNCTION__,
851 strerror(-ret), ret);
852 return 0;
853 }
854 return static_cast<uint32_t>(producerStickyTransform);
855}
856
857bool BufferLayer::latchUnsignaledBuffers() {
858 static bool propertyLoaded = false;
859 static bool latch = false;
860 static std::mutex mutex;
861 std::lock_guard<std::mutex> lock(mutex);
862 if (!propertyLoaded) {
863 char value[PROPERTY_VALUE_MAX] = {};
864 property_get("debug.sf.latch_unsignaled", value, "0");
865 latch = atoi(value);
866 propertyLoaded = true;
867 }
868 return latch;
869}
870
871uint64_t BufferLayer::getHeadFrameNumber() const {
872 Mutex::Autolock lock(mQueueItemLock);
873 if (!mQueueItems.empty()) {
874 return mQueueItems[0].mFrameNumber;
875 } else {
876 return mCurrentFrameNumber;
877 }
878}
879
880bool BufferLayer::headFenceHasSignaled() const {
David Sodman0c69cad2017-08-21 12:12:51 -0700881 if (latchUnsignaledBuffers()) {
882 return true;
883 }
884
885 Mutex::Autolock lock(mQueueItemLock);
886 if (mQueueItems.empty()) {
887 return true;
888 }
889 if (mQueueItems[0].mIsDroppable) {
890 // Even though this buffer's fence may not have signaled yet, it could
891 // be replaced by another buffer before it has a chance to, which means
892 // that it's possible to get into a situation where a buffer is never
893 // able to be latched. To avoid this, grab this buffer anyway.
894 return true;
895 }
David Sodman0cf8f8d2017-12-20 18:19:45 -0800896 return mQueueItems[0].mFenceTime->getSignalTime() != Fence::SIGNAL_TIME_PENDING;
David Sodman0c69cad2017-08-21 12:12:51 -0700897}
898
899uint32_t BufferLayer::getEffectiveScalingMode() const {
900 if (mOverrideScalingMode >= 0) {
901 return mOverrideScalingMode;
902 }
903 return mCurrentScalingMode;
904}
905
906// ----------------------------------------------------------------------------
907// transaction
908// ----------------------------------------------------------------------------
909
910void BufferLayer::notifyAvailableFrames() {
911 auto headFrameNumber = getHeadFrameNumber();
912 bool headFenceSignaled = headFenceHasSignaled();
913 Mutex::Autolock lock(mLocalSyncPointMutex);
914 for (auto& point : mLocalSyncPoints) {
915 if (headFrameNumber >= point->getFrameNumber() && headFenceSignaled) {
916 point->setFrameAvailable();
917 }
918 }
919}
920
921sp<IGraphicBufferProducer> BufferLayer::getProducer() const {
922 return mProducer;
923}
924
925// ---------------------------------------------------------------------------
926// h/w composer set-up
927// ---------------------------------------------------------------------------
928
929bool BufferLayer::allTransactionsSignaled() {
930 auto headFrameNumber = getHeadFrameNumber();
931 bool matchingFramesFound = false;
932 bool allTransactionsApplied = true;
933 Mutex::Autolock lock(mLocalSyncPointMutex);
934
935 for (auto& point : mLocalSyncPoints) {
936 if (point->getFrameNumber() > headFrameNumber) {
937 break;
938 }
939 matchingFramesFound = true;
940
941 if (!point->frameIsAvailable()) {
942 // We haven't notified the remote layer that the frame for
943 // this point is available yet. Notify it now, and then
944 // abort this attempt to latch.
945 point->setFrameAvailable();
946 allTransactionsApplied = false;
947 break;
948 }
949
950 allTransactionsApplied = allTransactionsApplied && point->transactionIsApplied();
951 }
952 return !matchingFramesFound || allTransactionsApplied;
953}
954
955} // namespace android
956
957#if defined(__gl_h_)
958#error "don't include gl/gl.h in this file"
959#endif
960
961#if defined(__gl2_h_)
962#error "don't include gl2/gl2.h in this file"
963#endif