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

Commit 98fca268 authored by Alec Mouri's avatar Alec Mouri Committed by Ana Krulec
Browse files

[SurfaceFlinger] add minimum frame count for early gl offsets.

This is to avoid edge case behavior by rapidly switching in and out
of gl composition, causing poor vsync timelines.

Bug: 132997413
Test: systrace
Change-Id: I4665f34f7e027a7883cfb5e47e14f41d845d1298
(cherry picked from commit 5a102100)
Merged-In: I4665f34f7e027a7883cfb5e47e14f41d845d1298
parent 9b586699
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -35,6 +35,11 @@ private:
    // sending new transactions.
    const int MIN_EARLY_FRAME_COUNT_TRANSACTION = 2;

    // Number of frames we'll keep the early gl phase offsets once they are activated.
    // This acts as a low-pass filter to avoid scenarios where we rapidly
    // switch in and out of gl composition.
    const int MIN_EARLY_GL_FRAME_COUNT_TRANSACTION = 2;

public:
    struct Offsets {
        nsecs_t sf;
@@ -130,10 +135,14 @@ public:
            mRemainingEarlyFrameCount--;
            updateOffsetsNeeded = true;
        }
        if (usedRenderEngine != mLastFrameUsedRenderEngine) {
            mLastFrameUsedRenderEngine = usedRenderEngine;
        if (usedRenderEngine) {
            mRemainingRenderEngineUsageCount = MIN_EARLY_GL_FRAME_COUNT_TRANSACTION;
            updateOffsetsNeeded = true;
        } else if (mRemainingRenderEngineUsageCount > 0) {
            mRemainingRenderEngineUsageCount--;
            updateOffsetsNeeded = true;
        }

        if (updateOffsetsNeeded) {
            updateOffsets();
        }
@@ -145,7 +154,7 @@ public:
        if (mTransactionStart == Scheduler::TransactionStart::EARLY ||
            mRemainingEarlyFrameCount > 0 || mRefreshRateChangePending) {
            return mEarlyOffsets;
        } else if (mLastFrameUsedRenderEngine) {
        } else if (mRemainingRenderEngineUsageCount > 0) {
            return mEarlyGlOffsets;
        } else {
            return mLateOffsets;
@@ -195,9 +204,9 @@ private:

    std::atomic<Scheduler::TransactionStart> mTransactionStart =
            Scheduler::TransactionStart::NORMAL;
    std::atomic<bool> mLastFrameUsedRenderEngine = false;
    std::atomic<bool> mRefreshRateChangePending = false;
    std::atomic<int> mRemainingEarlyFrameCount = 0;
    std::atomic<int> mRemainingRenderEngineUsageCount = 0;
};

} // namespace android