blob: 3c3eab602a672a48977d5cc69c074c6cb65b47b7 [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 Sodman0cf8f8d2017-12-20 18:19:45 -0800163 if (CC_UNLIKELY(mActiveBuffer == 0)) {
David Sodman0c69cad2017-08-21 12:12:51 -0700164 // the texture has not been created yet, this Layer has
165 // in fact never been drawn into. This happens frequently with
166 // SurfaceView because the WindowManager can't know when the client
167 // has drawn the first time.
168
169 // If there is nothing under us, we paint the screen in black, otherwise
170 // we just skip this update.
171
172 // figure out if there is something below us
173 Region under;
174 bool finished = false;
175 mFlinger->mDrawingState.traverseInZOrder([&](Layer* layer) {
176 if (finished || layer == static_cast<BufferLayer const*>(this)) {
177 finished = true;
178 return;
179 }
180 under.orSelf(renderArea.getTransform().transform(layer->visibleRegion));
181 });
182 // if not everything below us is covered, we plug the holes!
183 Region holes(clip.subtract(under));
184 if (!holes.isEmpty()) {
185 clearWithOpenGL(renderArea, 0, 0, 0, 1);
186 }
187 return;
188 }
189
190 // Bind the current buffer to the GL texture, and wait for it to be
191 // ready for us to draw into.
Chia-I Wub28c6742017-12-27 10:59:54 -0800192 status_t err = mConsumer->bindTextureImage();
David Sodman0c69cad2017-08-21 12:12:51 -0700193 if (err != NO_ERROR) {
194 ALOGW("onDraw: bindTextureImage failed (err=%d)", err);
195 // Go ahead and draw the buffer anyway; no matter what we do the screen
196 // is probably going to have something visibly wrong.
197 }
198
199 bool blackOutLayer = isProtected() || (isSecure() && !renderArea.isSecure());
200
Lloyd Pique144e1162017-12-20 16:44:52 -0800201 auto& engine(mFlinger->getRenderEngine());
David Sodman0c69cad2017-08-21 12:12:51 -0700202
203 if (!blackOutLayer) {
204 // TODO: we could be more subtle with isFixedSize()
205 const bool useFiltering = getFiltering() || needsFiltering(renderArea) || isFixedSize();
206
207 // Query the texture matrix given our current filtering mode.
208 float textureMatrix[16];
Chia-I Wub28c6742017-12-27 10:59:54 -0800209 mConsumer->setFilteringEnabled(useFiltering);
210 mConsumer->getTransformMatrix(textureMatrix);
David Sodman0c69cad2017-08-21 12:12:51 -0700211
212 if (getTransformToDisplayInverse()) {
213 /*
214 * the code below applies the primary display's inverse transform to
215 * the texture transform
216 */
217 uint32_t transform = DisplayDevice::getPrimaryDisplayOrientationTransform();
218 mat4 tr = inverseOrientation(transform);
219
220 /**
221 * TODO(b/36727915): This is basically a hack.
222 *
223 * Ensure that regardless of the parent transformation,
224 * this buffer is always transformed from native display
225 * orientation to display orientation. For example, in the case
226 * of a camera where the buffer remains in native orientation,
227 * we want the pixels to always be upright.
228 */
229 sp<Layer> p = mDrawingParent.promote();
230 if (p != nullptr) {
231 const auto parentTransform = p->getTransform();
232 tr = tr * inverseOrientation(parentTransform.getOrientation());
233 }
234
235 // and finally apply it to the original texture matrix
236 const mat4 texTransform(mat4(static_cast<const float*>(textureMatrix)) * tr);
237 memcpy(textureMatrix, texTransform.asArray(), sizeof(textureMatrix));
238 }
239
240 // Set things up for texturing.
David Sodman0cf8f8d2017-12-20 18:19:45 -0800241 mTexture.setDimensions(mActiveBuffer->getWidth(), mActiveBuffer->getHeight());
David Sodman0c69cad2017-08-21 12:12:51 -0700242 mTexture.setFiltering(useFiltering);
243 mTexture.setMatrix(textureMatrix);
244
245 engine.setupLayerTexturing(mTexture);
246 } else {
247 engine.setupLayerBlackedOut();
248 }
249 drawWithOpenGL(renderArea, useIdentityTransform);
250 engine.disableTexturing();
251}
252
David Sodmaneb085e02017-10-05 18:49:04 -0700253void BufferLayer::onLayerDisplayed(const sp<Fence>& releaseFence) {
Chia-I Wub28c6742017-12-27 10:59:54 -0800254 mConsumer->setReleaseFence(releaseFence);
David Sodmaneb085e02017-10-05 18:49:04 -0700255}
David Sodmaneb085e02017-10-05 18:49:04 -0700256
257void BufferLayer::abandon() {
Chia-I Wub28c6742017-12-27 10:59:54 -0800258 mConsumer->abandon();
David Sodmaneb085e02017-10-05 18:49:04 -0700259}
260
261bool BufferLayer::shouldPresentNow(const DispSync& dispSync) const {
262 if (mSidebandStreamChanged || mAutoRefresh) {
263 return true;
264 }
265
266 Mutex::Autolock lock(mQueueItemLock);
267 if (mQueueItems.empty()) {
268 return false;
269 }
270 auto timestamp = mQueueItems[0].mTimestamp;
Chia-I Wub28c6742017-12-27 10:59:54 -0800271 nsecs_t expectedPresent = mConsumer->computeExpectedPresent(dispSync);
David Sodmaneb085e02017-10-05 18:49:04 -0700272
273 // Ignore timestamps more than a second in the future
274 bool isPlausible = timestamp < (expectedPresent + s2ns(1));
275 ALOGW_IF(!isPlausible,
276 "[%s] Timestamp %" PRId64 " seems implausible "
277 "relative to expectedPresent %" PRId64,
278 mName.string(), timestamp, expectedPresent);
279
280 bool isDue = timestamp < expectedPresent;
281 return isDue || !isPlausible;
282}
283
284void BufferLayer::setTransformHint(uint32_t orientation) const {
Chia-I Wub28c6742017-12-27 10:59:54 -0800285 mConsumer->setTransformHint(orientation);
David Sodmaneb085e02017-10-05 18:49:04 -0700286}
287
David Sodman0c69cad2017-08-21 12:12:51 -0700288bool BufferLayer::onPreComposition(nsecs_t refreshStartTime) {
289 if (mBufferLatched) {
290 Mutex::Autolock lock(mFrameEventHistoryMutex);
David Sodman0cf8f8d2017-12-20 18:19:45 -0800291 mFrameEventHistory.addPreComposition(mCurrentFrameNumber, refreshStartTime);
David Sodman0c69cad2017-08-21 12:12:51 -0700292 }
293 mRefreshPending = false;
David Sodman0cf8f8d2017-12-20 18:19:45 -0800294 return mQueuedFrames > 0 || mSidebandStreamChanged || mAutoRefresh;
David Sodman0c69cad2017-08-21 12:12:51 -0700295}
David Sodmaneb085e02017-10-05 18:49:04 -0700296bool BufferLayer::onPostComposition(const std::shared_ptr<FenceTime>& glDoneFence,
297 const std::shared_ptr<FenceTime>& presentFence,
298 const CompositorTiming& compositorTiming) {
299 // mFrameLatencyNeeded is true when a new frame was latched for the
300 // composition.
301 if (!mFrameLatencyNeeded) return false;
302
303 // Update mFrameEventHistory.
304 {
305 Mutex::Autolock lock(mFrameEventHistoryMutex);
David Sodman0cf8f8d2017-12-20 18:19:45 -0800306 mFrameEventHistory.addPostComposition(mCurrentFrameNumber, glDoneFence, presentFence,
307 compositorTiming);
David Sodmaneb085e02017-10-05 18:49:04 -0700308 }
309
310 // Update mFrameTracker.
Chia-I Wub28c6742017-12-27 10:59:54 -0800311 nsecs_t desiredPresentTime = mConsumer->getTimestamp();
David Sodmaneb085e02017-10-05 18:49:04 -0700312 mFrameTracker.setDesiredPresentTime(desiredPresentTime);
313
Yiwei Zhangfaf3ded2018-05-02 17:37:17 -0700314 const std::string layerName(getName().c_str());
315 mTimeStats.setDesiredTime(layerName, mCurrentFrameNumber, desiredPresentTime);
316
Chia-I Wub28c6742017-12-27 10:59:54 -0800317 std::shared_ptr<FenceTime> frameReadyFence = mConsumer->getCurrentFenceTime();
David Sodmaneb085e02017-10-05 18:49:04 -0700318 if (frameReadyFence->isValid()) {
319 mFrameTracker.setFrameReadyFence(std::move(frameReadyFence));
320 } else {
321 // There was no fence for this frame, so assume that it was ready
322 // to be presented at the desired present time.
323 mFrameTracker.setFrameReadyTime(desiredPresentTime);
324 }
325
326 if (presentFence->isValid()) {
Yiwei Zhangfaf3ded2018-05-02 17:37:17 -0700327 mTimeStats.setPresentFence(layerName, mCurrentFrameNumber, presentFence);
David Sodmaneb085e02017-10-05 18:49:04 -0700328 mFrameTracker.setActualPresentFence(std::shared_ptr<FenceTime>(presentFence));
329 } else {
330 // The HWC doesn't support present fences, so use the refresh
331 // timestamp instead.
Yiwei Zhangfaf3ded2018-05-02 17:37:17 -0700332 const nsecs_t actualPresentTime =
333 mFlinger->getHwComposer().getRefreshTimestamp(HWC_DISPLAY_PRIMARY);
334 mTimeStats.setPresentTime(layerName, mCurrentFrameNumber, actualPresentTime);
335 mFrameTracker.setActualPresentTime(actualPresentTime);
David Sodmaneb085e02017-10-05 18:49:04 -0700336 }
337
338 mFrameTracker.advanceFrame();
339 mFrameLatencyNeeded = false;
340 return true;
341}
342
343std::vector<OccupancyTracker::Segment> BufferLayer::getOccupancyHistory(bool forceFlush) {
344 std::vector<OccupancyTracker::Segment> history;
Chia-I Wub28c6742017-12-27 10:59:54 -0800345 status_t result = mConsumer->getOccupancyHistory(forceFlush, &history);
David Sodmaneb085e02017-10-05 18:49:04 -0700346 if (result != NO_ERROR) {
347 ALOGW("[%s] Failed to obtain occupancy history (%d)", mName.string(), result);
348 return {};
349 }
350 return history;
351}
352
353bool BufferLayer::getTransformToDisplayInverse() const {
Chia-I Wub28c6742017-12-27 10:59:54 -0800354 return mConsumer->getTransformToDisplayInverse();
David Sodmaneb085e02017-10-05 18:49:04 -0700355}
David Sodman0c69cad2017-08-21 12:12:51 -0700356
David Sodman0c69cad2017-08-21 12:12:51 -0700357void BufferLayer::releasePendingBuffer(nsecs_t dequeueReadyTime) {
Chia-I Wub28c6742017-12-27 10:59:54 -0800358 if (!mConsumer->releasePendingBuffer()) {
David Sodman0c69cad2017-08-21 12:12:51 -0700359 return;
360 }
361
David Sodman0cf8f8d2017-12-20 18:19:45 -0800362 auto releaseFenceTime = 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 Sodman0cf8f8d2017-12-20 18:19:45 -0800415 sp<GraphicBuffer> oldBuffer = mActiveBuffer;
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 Sodman0cf8f8d2017-12-20 18:19:45 -0800428 getProducerStickyTransform() != 0, mName.string(), mOverrideScalingMode,
429 mFreezeGeometryUpdates);
430 status_t updateResult = mConsumer->updateTexImage(&r, mFlinger->mPrimaryDispSync, &mAutoRefresh,
431 &queuedBuffer, mLastFrameNumberReceived);
David Sodman0c69cad2017-08-21 12:12:51 -0700432 if (updateResult == BufferQueue::PRESENT_LATER) {
433 // Producer doesn't want buffer to be displayed yet. Signal a
434 // layer update so we check again at the next opportunity.
435 mFlinger->signalLayerUpdate();
436 return outDirtyRegion;
Chia-I Wu0cb75ac2017-11-27 15:56:04 -0800437 } else if (updateResult == BufferLayerConsumer::BUFFER_REJECTED) {
David Sodman0c69cad2017-08-21 12:12:51 -0700438 // If the buffer has been rejected, remove it from the shadow queue
439 // and return early
440 if (queuedBuffer) {
441 Mutex::Autolock lock(mQueueItemLock);
Yiwei Zhangfaf3ded2018-05-02 17:37:17 -0700442 mTimeStats.removeTimeRecord(getName().c_str(), mQueueItems[0].mFrameNumber);
David Sodman0c69cad2017-08-21 12:12:51 -0700443 mQueueItems.removeAt(0);
444 android_atomic_dec(&mQueuedFrames);
445 }
446 return outDirtyRegion;
447 } else if (updateResult != NO_ERROR || mUpdateTexImageFailed) {
448 // This can occur if something goes wrong when trying to create the
449 // EGLImage for this buffer. If this happens, the buffer has already
450 // been released, so we need to clean up the queue and bug out
451 // early.
452 if (queuedBuffer) {
453 Mutex::Autolock lock(mQueueItemLock);
454 mQueueItems.clear();
455 android_atomic_and(0, &mQueuedFrames);
Yiwei Zhangfaf3ded2018-05-02 17:37:17 -0700456 mTimeStats.clearLayerRecord(getName().c_str());
David Sodman0c69cad2017-08-21 12:12:51 -0700457 }
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) {
Yiwei Zhangfaf3ded2018-05-02 17:37:17 -0700477 mTimeStats.removeTimeRecord(getName().c_str(), mQueueItems[0].mFrameNumber);
David Sodman0c69cad2017-08-21 12:12:51 -0700478 mQueueItems.removeAt(0);
479 android_atomic_dec(&mQueuedFrames);
480 }
481
Yiwei Zhangfaf3ded2018-05-02 17:37:17 -0700482 const std::string layerName(getName().c_str());
483 mTimeStats.setAcquireFence(layerName, currentFrameNumber, mQueueItems[0].mFenceTime);
484 mTimeStats.setLatchTime(layerName, currentFrameNumber, latchTime);
485
David Sodman0c69cad2017-08-21 12:12:51 -0700486 mQueueItems.removeAt(0);
487 }
488
489 // Decrement the queued-frames count. Signal another event if we
490 // have more frames pending.
David Sodman0cf8f8d2017-12-20 18:19:45 -0800491 if ((queuedBuffer && android_atomic_dec(&mQueuedFrames) > 1) || mAutoRefresh) {
David Sodman0c69cad2017-08-21 12:12:51 -0700492 mFlinger->signalLayerUpdate();
493 }
494
495 // update the active buffer
David Sodman0cf8f8d2017-12-20 18:19:45 -0800496 mActiveBuffer = mConsumer->getCurrentBuffer(&mActiveBufferSlot);
497 getBE().compositionInfo.mBuffer = mActiveBuffer;
498 getBE().compositionInfo.mBufferSlot = mActiveBufferSlot;
499
500 if (mActiveBuffer == nullptr) {
David Sodman0c69cad2017-08-21 12:12:51 -0700501 // this can only happen if the very first buffer was rejected.
502 return outDirtyRegion;
503 }
504
505 mBufferLatched = true;
506 mPreviousFrameNumber = mCurrentFrameNumber;
Chia-I Wub28c6742017-12-27 10:59:54 -0800507 mCurrentFrameNumber = mConsumer->getFrameNumber();
David Sodman0c69cad2017-08-21 12:12:51 -0700508
509 {
510 Mutex::Autolock lock(mFrameEventHistoryMutex);
511 mFrameEventHistory.addLatch(mCurrentFrameNumber, latchTime);
David Sodman0c69cad2017-08-21 12:12:51 -0700512 }
513
514 mRefreshPending = true;
515 mFrameLatencyNeeded = true;
Peiyong Lin566a3b42018-01-09 18:22:43 -0800516 if (oldBuffer == nullptr) {
David Sodman0c69cad2017-08-21 12:12:51 -0700517 // the first time we receive a buffer, we need to trigger a
518 // geometry invalidation.
519 recomputeVisibleRegions = true;
520 }
521
Peiyong Lin923e7c52018-04-16 14:16:37 -0700522 // Dataspace::V0_SRGB and Dataspace::V0_SRGB_LINEAR are not legacy
523 // data space, however since framework doesn't distinguish them out of
524 // legacy SRGB, we have to treat them as the same for now.
525 // UNKNOWN is treated as legacy SRGB when the connected api is EGL.
526 ui::Dataspace dataSpace = mConsumer->getCurrentDataSpace();
527 switch (dataSpace) {
528 case ui::Dataspace::V0_SRGB:
529 dataSpace = ui::Dataspace::SRGB;
530 break;
531 case ui::Dataspace::V0_SRGB_LINEAR:
532 dataSpace = ui::Dataspace::SRGB_LINEAR;
533 break;
534 case ui::Dataspace::UNKNOWN:
535 if (mConsumer->getCurrentApi() == NATIVE_WINDOW_API_EGL) {
536 dataSpace = ui::Dataspace::SRGB;
537 }
538 break;
539 default:
540 break;
541 }
542 setDataSpace(dataSpace);
David Sodman0c69cad2017-08-21 12:12:51 -0700543
Chia-I Wub28c6742017-12-27 10:59:54 -0800544 Rect crop(mConsumer->getCurrentCrop());
545 const uint32_t transform(mConsumer->getCurrentTransform());
546 const uint32_t scalingMode(mConsumer->getCurrentScalingMode());
David Sodman0cf8f8d2017-12-20 18:19:45 -0800547 if ((crop != mCurrentCrop) || (transform != mCurrentTransform) ||
David Sodman0c69cad2017-08-21 12:12:51 -0700548 (scalingMode != mCurrentScalingMode)) {
549 mCurrentCrop = crop;
550 mCurrentTransform = transform;
551 mCurrentScalingMode = scalingMode;
552 recomputeVisibleRegions = true;
553 }
554
Peiyong Lin566a3b42018-01-09 18:22:43 -0800555 if (oldBuffer != nullptr) {
David Sodman0cf8f8d2017-12-20 18:19:45 -0800556 uint32_t bufWidth = mActiveBuffer->getWidth();
557 uint32_t bufHeight = mActiveBuffer->getHeight();
558 if (bufWidth != uint32_t(oldBuffer->width) || bufHeight != uint32_t(oldBuffer->height)) {
David Sodman0c69cad2017-08-21 12:12:51 -0700559 recomputeVisibleRegions = true;
560 }
561 }
562
David Sodman0cf8f8d2017-12-20 18:19:45 -0800563 mCurrentOpacity = getOpacityForFormat(mActiveBuffer->format);
David Sodman0c69cad2017-08-21 12:12:51 -0700564 if (oldOpacity != isOpaque(s)) {
565 recomputeVisibleRegions = true;
566 }
567
568 // Remove any sync points corresponding to the buffer which was just
569 // latched
570 {
571 Mutex::Autolock lock(mLocalSyncPointMutex);
572 auto point = mLocalSyncPoints.begin();
573 while (point != mLocalSyncPoints.end()) {
574 if (!(*point)->frameIsAvailable() || !(*point)->transactionIsApplied()) {
575 // This sync point must have been added since we started
576 // latching. Don't drop it yet.
577 ++point;
578 continue;
579 }
580
581 if ((*point)->getFrameNumber() <= mCurrentFrameNumber) {
582 point = mLocalSyncPoints.erase(point);
583 } else {
584 ++point;
585 }
586 }
587 }
588
589 // FIXME: postedRegion should be dirty & bounds
590 Region dirtyRegion(Rect(s.active.w, s.active.h));
591
592 // transform the dirty region to window-manager space
593 outDirtyRegion = (getTransform().transform(dirtyRegion));
594
595 return outDirtyRegion;
596}
597
David Sodmaneb085e02017-10-05 18:49:04 -0700598void BufferLayer::setDefaultBufferSize(uint32_t w, uint32_t h) {
Chia-I Wub28c6742017-12-27 10:59:54 -0800599 mConsumer->setDefaultBufferSize(w, h);
David Sodmaneb085e02017-10-05 18:49:04 -0700600}
601
David Sodman0c69cad2017-08-21 12:12:51 -0700602void BufferLayer::setPerFrameData(const sp<const DisplayDevice>& displayDevice) {
603 // Apply this display's projection's viewport to the visible region
604 // before giving it to the HWC HAL.
605 const Transform& tr = displayDevice->getTransform();
606 const auto& viewport = displayDevice->getViewport();
607 Region visible = tr.transform(visibleRegion.intersect(viewport));
608 auto hwcId = displayDevice->getHwcDisplayId();
Chia-I Wu30505fb2018-03-26 16:20:31 -0700609 auto& hwcInfo = getBE().mHwcLayers[hwcId];
610 auto& hwcLayer = hwcInfo.layer;
611 auto error = (*hwcLayer)->setVisibleRegion(visible);
612 if (error != HWC2::Error::None) {
613 ALOGE("[%s] Failed to set visible region: %s (%d)", mName.string(),
614 to_string(error).c_str(), static_cast<int32_t>(error));
615 visible.dump(LOG_TAG);
616 }
David Sodman0c69cad2017-08-21 12:12:51 -0700617
Chia-I Wu30505fb2018-03-26 16:20:31 -0700618 error = (*hwcLayer)->setSurfaceDamage(surfaceDamageRegion);
619 if (error != HWC2::Error::None) {
620 ALOGE("[%s] Failed to set surface damage: %s (%d)", mName.string(),
621 to_string(error).c_str(), static_cast<int32_t>(error));
622 surfaceDamageRegion.dump(LOG_TAG);
623 }
David Sodman0c69cad2017-08-21 12:12:51 -0700624
625 // Sideband layers
David Sodman0cc69182017-11-17 12:12:07 -0800626 if (getBE().compositionInfo.hwc.sidebandStream.get()) {
David Sodman0c69cad2017-08-21 12:12:51 -0700627 setCompositionType(hwcId, HWC2::Composition::Sideband);
Chia-I Wu30505fb2018-03-26 16:20:31 -0700628 ALOGV("[%s] Requesting Sideband composition", mName.string());
629 error = (*hwcLayer)->setSidebandStream(getBE().compositionInfo.hwc.sidebandStream->handle());
630 if (error != HWC2::Error::None) {
631 ALOGE("[%s] Failed to set sideband stream %p: %s (%d)", mName.string(),
632 getBE().compositionInfo.hwc.sidebandStream->handle(), to_string(error).c_str(),
633 static_cast<int32_t>(error));
634 }
David Sodman0c69cad2017-08-21 12:12:51 -0700635 return;
636 }
637
David Sodman0c69cad2017-08-21 12:12:51 -0700638 // Device or Cursor layers
639 if (mPotentialCursor) {
640 ALOGV("[%s] Requesting Cursor composition", mName.string());
641 setCompositionType(hwcId, HWC2::Composition::Cursor);
642 } else {
643 ALOGV("[%s] Requesting Device composition", mName.string());
644 setCompositionType(hwcId, HWC2::Composition::Device);
645 }
646
Chia-I Wu30505fb2018-03-26 16:20:31 -0700647 ALOGV("setPerFrameData: dataspace = %d", mDrawingState.dataSpace);
648 error = (*hwcLayer)->setDataspace(mDrawingState.dataSpace);
649 if (error != HWC2::Error::None) {
650 ALOGE("[%s] Failed to set dataspace %d: %s (%d)", mName.string(), mDrawingState.dataSpace,
651 to_string(error).c_str(), static_cast<int32_t>(error));
652 }
653
654 const HdrMetadata& metadata = mConsumer->getCurrentHdrMetadata();
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700655 error = (*hwcLayer)->setPerFrameMetadata(displayDevice->getSupportedPerFrameMetadata(), metadata);
Chia-I Wu30505fb2018-03-26 16:20:31 -0700656 if (error != HWC2::Error::None && error != HWC2::Error::Unsupported) {
657 ALOGE("[%s] Failed to set hdrMetadata: %s (%d)", mName.string(),
658 to_string(error).c_str(), static_cast<int32_t>(error));
659 }
660
661 uint32_t hwcSlot = 0;
662 sp<GraphicBuffer> hwcBuffer;
663 getBE().mHwcLayers[hwcId].bufferCache.getHwcBuffer(mActiveBufferSlot, mActiveBuffer, &hwcSlot,
664 &hwcBuffer);
David Sodman0c69cad2017-08-21 12:12:51 -0700665
Chia-I Wub28c6742017-12-27 10:59:54 -0800666 auto acquireFence = mConsumer->getCurrentFence();
Chia-I Wu30505fb2018-03-26 16:20:31 -0700667 error = (*hwcLayer)->setBuffer(hwcSlot, hwcBuffer, acquireFence);
668 if (error != HWC2::Error::None) {
669 ALOGE("[%s] Failed to set buffer %p: %s (%d)", mName.string(),
670 getBE().compositionInfo.mBuffer->handle, to_string(error).c_str(),
671 static_cast<int32_t>(error));
672 }
David Sodman0c69cad2017-08-21 12:12:51 -0700673}
674
David Sodman41fdfc92017-11-06 16:09:56 -0800675bool BufferLayer::isOpaque(const Layer::State& s) const {
David Sodman0c69cad2017-08-21 12:12:51 -0700676 // if we don't have a buffer or sidebandStream yet, we're translucent regardless of the
677 // layer's opaque flag.
David Sodman0cf8f8d2017-12-20 18:19:45 -0800678 if ((getBE().compositionInfo.hwc.sidebandStream == nullptr) && (mActiveBuffer == nullptr)) {
David Sodman0c69cad2017-08-21 12:12:51 -0700679 return false;
680 }
681
682 // if the layer has the opaque flag, then we're always opaque,
683 // otherwise we use the current buffer's format.
684 return ((s.flags & layer_state_t::eLayerOpaque) != 0) || mCurrentOpacity;
685}
686
687void BufferLayer::onFirstRef() {
688 // Creates a custom BufferQueue for SurfaceFlingerConsumer to use
689 sp<IGraphicBufferProducer> producer;
690 sp<IGraphicBufferConsumer> consumer;
691 BufferQueue::createBufferQueue(&producer, &consumer, true);
692 mProducer = new MonitoredProducer(producer, mFlinger, this);
David Sodman0cf8f8d2017-12-20 18:19:45 -0800693 mConsumer = new BufferLayerConsumer(consumer, mFlinger->getRenderEngine(), mTextureName, this);
Chia-I Wub28c6742017-12-27 10:59:54 -0800694 mConsumer->setConsumerUsageBits(getEffectiveUsage(0));
695 mConsumer->setContentsChangedListener(this);
696 mConsumer->setName(mName);
David Sodman0c69cad2017-08-21 12:12:51 -0700697
698 if (mFlinger->isLayerTripleBufferingDisabled()) {
699 mProducer->setMaxDequeuedBufferCount(2);
700 }
701
702 const sp<const DisplayDevice> hw(mFlinger->getDefaultDisplayDevice());
703 updateTransformHint(hw);
704}
705
706// ---------------------------------------------------------------------------
707// Interface implementation for SurfaceFlingerConsumer::ContentsChangedListener
708// ---------------------------------------------------------------------------
709
710void BufferLayer::onFrameAvailable(const BufferItem& item) {
711 // Add this buffer from our internal queue tracker
712 { // Autolock scope
713 Mutex::Autolock lock(mQueueItemLock);
Lloyd Pique4dccc412018-01-22 17:21:36 -0800714 mFlinger->mInterceptor->saveBufferUpdate(this, item.mGraphicBuffer->getWidth(),
715 item.mGraphicBuffer->getHeight(),
716 item.mFrameNumber);
David Sodman0c69cad2017-08-21 12:12:51 -0700717 // Reset the frame number tracker when we receive the first buffer after
718 // a frame number reset
719 if (item.mFrameNumber == 1) {
720 mLastFrameNumberReceived = 0;
721 }
722
723 // Ensure that callbacks are handled in order
724 while (item.mFrameNumber != mLastFrameNumberReceived + 1) {
David Sodman0cf8f8d2017-12-20 18:19:45 -0800725 status_t result = mQueueItemCondition.waitRelative(mQueueItemLock, 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 Sodman0cf8f8d2017-12-20 18:19:45 -0800748 status_t result = mQueueItemCondition.waitRelative(mQueueItemLock, ms2ns(500));
David Sodman0c69cad2017-08-21 12:12:51 -0700749 if (result != NO_ERROR) {
750 ALOGE("[%s] Timed out waiting on callback", mName.string());
751 }
752 }
753
754 if (mQueueItems.empty()) {
755 ALOGE("Can't replace a frame on an empty queue");
756 return;
757 }
758 mQueueItems.editItemAt(mQueueItems.size() - 1) = item;
759
760 // Wake up any pending callbacks
761 mLastFrameNumberReceived = item.mFrameNumber;
762 mQueueItemCondition.broadcast();
763 }
764}
765
766void BufferLayer::onSidebandStreamChanged() {
767 if (android_atomic_release_cas(false, true, &mSidebandStreamChanged) == 0) {
768 // mSidebandStreamChanged was false
769 mFlinger->signalLayerUpdate();
770 }
771}
772
773bool BufferLayer::needsFiltering(const RenderArea& renderArea) const {
774 return mNeedsFiltering || renderArea.needsFiltering();
775}
776
777// As documented in libhardware header, formats in the range
778// 0x100 - 0x1FF are specific to the HAL implementation, and
779// are known to have no alpha channel
780// TODO: move definition for device-specific range into
781// hardware.h, instead of using hard-coded values here.
782#define HARDWARE_IS_DEVICE_FORMAT(f) ((f) >= 0x100 && (f) <= 0x1FF)
783
784bool BufferLayer::getOpacityForFormat(uint32_t format) {
785 if (HARDWARE_IS_DEVICE_FORMAT(format)) {
786 return true;
787 }
788 switch (format) {
789 case HAL_PIXEL_FORMAT_RGBA_8888:
790 case HAL_PIXEL_FORMAT_BGRA_8888:
791 case HAL_PIXEL_FORMAT_RGBA_FP16:
792 case HAL_PIXEL_FORMAT_RGBA_1010102:
793 return false;
794 }
795 // in all other case, we have no blending (also for unknown formats)
796 return true;
797}
798
David Sodman41fdfc92017-11-06 16:09:56 -0800799void BufferLayer::drawWithOpenGL(const RenderArea& renderArea, bool useIdentityTransform) const {
Dan Stoza84d619e2018-03-28 17:07:36 -0700800 ATRACE_CALL();
David Sodman0c69cad2017-08-21 12:12:51 -0700801 const State& s(getDrawingState());
802
David Sodman9eeae692017-11-02 10:53:32 -0700803 computeGeometry(renderArea, getBE().mMesh, useIdentityTransform);
David Sodman0c69cad2017-08-21 12:12:51 -0700804
805 /*
806 * NOTE: the way we compute the texture coordinates here produces
807 * different results than when we take the HWC path -- in the later case
808 * the "source crop" is rounded to texel boundaries.
809 * This can produce significantly different results when the texture
810 * is scaled by a large amount.
811 *
812 * The GL code below is more logical (imho), and the difference with
813 * HWC is due to a limitation of the HWC API to integers -- a question
814 * is suspend is whether we should ignore this problem or revert to
815 * GL composition when a buffer scaling is applied (maybe with some
816 * minimal value)? Or, we could make GL behave like HWC -- but this feel
817 * like more of a hack.
818 */
Dan Stoza80d61162017-12-20 15:57:52 -0800819 const Rect bounds{computeBounds()}; // Rounds from FloatRect
David Sodman0c69cad2017-08-21 12:12:51 -0700820
821 Transform t = getTransform();
Dan Stoza80d61162017-12-20 15:57:52 -0800822 Rect win = bounds;
David Sodman0c69cad2017-08-21 12:12:51 -0700823 if (!s.finalCrop.isEmpty()) {
824 win = t.transform(win);
825 if (!win.intersect(s.finalCrop, &win)) {
826 win.clear();
827 }
828 win = t.inverse().transform(win);
Dan Stoza80d61162017-12-20 15:57:52 -0800829 if (!win.intersect(bounds, &win)) {
David Sodman0c69cad2017-08-21 12:12:51 -0700830 win.clear();
831 }
832 }
833
834 float left = float(win.left) / float(s.active.w);
835 float top = float(win.top) / float(s.active.h);
836 float right = float(win.right) / float(s.active.w);
837 float bottom = float(win.bottom) / float(s.active.h);
838
839 // TODO: we probably want to generate the texture coords with the mesh
840 // here we assume that we only have 4 vertices
David Sodman9eeae692017-11-02 10:53:32 -0700841 Mesh::VertexArray<vec2> texCoords(getBE().mMesh.getTexCoordArray<vec2>());
David Sodman0c69cad2017-08-21 12:12:51 -0700842 texCoords[0] = vec2(left, 1.0f - top);
843 texCoords[1] = vec2(left, 1.0f - bottom);
844 texCoords[2] = vec2(right, 1.0f - bottom);
845 texCoords[3] = vec2(right, 1.0f - top);
846
bohu21566132018-03-27 14:36:34 -0700847 auto& engine(mFlinger->getRenderEngine());
848 engine.setupLayerBlending(mPremultipliedAlpha, isOpaque(s), false /* disableTexture */,
849 getColor());
850 engine.setSourceDataSpace(mCurrentState.dataSpace);
Chia-I Wu5c6e4632018-01-11 08:54:38 -0800851
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700852 if (mCurrentState.dataSpace == ui::Dataspace::BT2020_ITU_PQ &&
Chia-I Wu5c6e4632018-01-11 08:54:38 -0800853 mConsumer->getCurrentApi() == NATIVE_WINDOW_API_MEDIA &&
854 getBE().compositionInfo.mBuffer->getPixelFormat() == HAL_PIXEL_FORMAT_RGBA_1010102) {
bohu21566132018-03-27 14:36:34 -0700855 engine.setSourceY410BT2020(true);
Chia-I Wu5c6e4632018-01-11 08:54:38 -0800856 }
bohu21566132018-03-27 14:36:34 -0700857
858 engine.drawMesh(getBE().mMesh);
859 engine.disableBlending();
860
861 engine.setSourceY410BT2020(false);
David Sodman0c69cad2017-08-21 12:12:51 -0700862}
863
864uint32_t BufferLayer::getProducerStickyTransform() const {
865 int producerStickyTransform = 0;
866 int ret = mProducer->query(NATIVE_WINDOW_STICKY_TRANSFORM, &producerStickyTransform);
867 if (ret != OK) {
868 ALOGW("%s: Error %s (%d) while querying window sticky transform.", __FUNCTION__,
869 strerror(-ret), ret);
870 return 0;
871 }
872 return static_cast<uint32_t>(producerStickyTransform);
873}
874
875bool BufferLayer::latchUnsignaledBuffers() {
876 static bool propertyLoaded = false;
877 static bool latch = false;
878 static std::mutex mutex;
879 std::lock_guard<std::mutex> lock(mutex);
880 if (!propertyLoaded) {
881 char value[PROPERTY_VALUE_MAX] = {};
882 property_get("debug.sf.latch_unsignaled", value, "0");
883 latch = atoi(value);
884 propertyLoaded = true;
885 }
886 return latch;
887}
888
889uint64_t BufferLayer::getHeadFrameNumber() const {
890 Mutex::Autolock lock(mQueueItemLock);
891 if (!mQueueItems.empty()) {
892 return mQueueItems[0].mFrameNumber;
893 } else {
894 return mCurrentFrameNumber;
895 }
896}
897
898bool BufferLayer::headFenceHasSignaled() const {
David Sodman0c69cad2017-08-21 12:12:51 -0700899 if (latchUnsignaledBuffers()) {
900 return true;
901 }
902
903 Mutex::Autolock lock(mQueueItemLock);
904 if (mQueueItems.empty()) {
905 return true;
906 }
907 if (mQueueItems[0].mIsDroppable) {
908 // Even though this buffer's fence may not have signaled yet, it could
909 // be replaced by another buffer before it has a chance to, which means
910 // that it's possible to get into a situation where a buffer is never
911 // able to be latched. To avoid this, grab this buffer anyway.
912 return true;
913 }
David Sodman0cf8f8d2017-12-20 18:19:45 -0800914 return mQueueItems[0].mFenceTime->getSignalTime() != Fence::SIGNAL_TIME_PENDING;
David Sodman0c69cad2017-08-21 12:12:51 -0700915}
916
917uint32_t BufferLayer::getEffectiveScalingMode() const {
918 if (mOverrideScalingMode >= 0) {
919 return mOverrideScalingMode;
920 }
921 return mCurrentScalingMode;
922}
923
924// ----------------------------------------------------------------------------
925// transaction
926// ----------------------------------------------------------------------------
927
928void BufferLayer::notifyAvailableFrames() {
929 auto headFrameNumber = getHeadFrameNumber();
930 bool headFenceSignaled = headFenceHasSignaled();
931 Mutex::Autolock lock(mLocalSyncPointMutex);
932 for (auto& point : mLocalSyncPoints) {
933 if (headFrameNumber >= point->getFrameNumber() && headFenceSignaled) {
934 point->setFrameAvailable();
935 }
936 }
937}
938
939sp<IGraphicBufferProducer> BufferLayer::getProducer() const {
940 return mProducer;
941}
942
943// ---------------------------------------------------------------------------
944// h/w composer set-up
945// ---------------------------------------------------------------------------
946
947bool BufferLayer::allTransactionsSignaled() {
948 auto headFrameNumber = getHeadFrameNumber();
949 bool matchingFramesFound = false;
950 bool allTransactionsApplied = true;
951 Mutex::Autolock lock(mLocalSyncPointMutex);
952
953 for (auto& point : mLocalSyncPoints) {
954 if (point->getFrameNumber() > headFrameNumber) {
955 break;
956 }
957 matchingFramesFound = true;
958
959 if (!point->frameIsAvailable()) {
960 // We haven't notified the remote layer that the frame for
961 // this point is available yet. Notify it now, and then
962 // abort this attempt to latch.
963 point->setFrameAvailable();
964 allTransactionsApplied = false;
965 break;
966 }
967
968 allTransactionsApplied = allTransactionsApplied && point->transactionIsApplied();
969 }
970 return !matchingFramesFound || allTransactionsApplied;
971}
972
973} // namespace android
974
975#if defined(__gl_h_)
976#error "don't include gl/gl.h in this file"
977#endif
978
979#if defined(__gl2_h_)
980#error "don't include gl2/gl2.h in this file"
981#endif