Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fe95fd7e authored by Ady Abraham's avatar Ady Abraham
Browse files

SurfaceFlinger: check fence when acquiring buffer with PTS

This is a fix for a condition where SurfaceFlinger may pass
a buffer to HWC before the fence was signaled. This can happen when
presentation timestamp is set and the buffer behind the front of
the queue has current timestamp.

Test: run a scenario that simulate the scenario
      (PTS is always set to the past)
Bug: 123780024
Change-Id: Ib47bc5ebc50136c54b29bd301ad8d059f3dea947
parent 5ef8f96e
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -235,9 +235,28 @@ status_t BufferQueueLayer::updateTexImage(bool& recomputeVisibleRegions, nsecs_t
    const nsecs_t expectedPresentTime = mFlinger->mUseScheduler
            ? mFlinger->mScheduler->mPrimaryDispSync->expectedPresentTime()
            : mFlinger->mPrimaryDispSync->expectedPresentTime();

    // updateTexImage() below might drop the some buffers at the head of the queue if there is a
    // buffer behind them which is timely to be presented. However this buffer may not be signaled
    // yet. The code below makes sure that this wouldn't happen by setting maxFrameNumber to the
    // last buffer that was signaled.
    uint64_t lastSignaledFrameNumber = mLastFrameNumberReceived;
    {
        Mutex::Autolock lock(mQueueItemLock);
        for (int i = 0; i < mQueueItems.size(); i++) {
            bool fenceSignaled =
                    mQueueItems[i].mFenceTime->getSignalTime() != Fence::SIGNAL_TIME_PENDING;
            if (!fenceSignaled) {
                break;
            }
            lastSignaledFrameNumber = mQueueItems[i].mFrameNumber;
        }
    }
    const uint64_t maxFrameNumberToAcquire =
            std::min(mLastFrameNumberReceived.load(), lastSignaledFrameNumber);
    status_t updateResult =
            mConsumer->updateTexImage(&r, expectedPresentTime, &mAutoRefresh, &queuedBuffer,
                                      mLastFrameNumberReceived, releaseFence);
                                      maxFrameNumberToAcquire, releaseFence);
    if (updateResult == BufferQueue::PRESENT_LATER) {
        // Producer doesn't want buffer to be displayed yet.  Signal a
        // layer update so we check again at the next opportunity.