From 5a1021000dabfad591dc1afa6525b7165c046bf9 Mon Sep 17 00:00:00 2001 From: Alec Mouri Date: Thu, 23 May 2019 07:14:20 -0700 Subject: [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 --- services/surfaceflinger/Scheduler/VSyncModulator.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/services/surfaceflinger/Scheduler/VSyncModulator.h b/services/surfaceflinger/Scheduler/VSyncModulator.h index 81a7864cdb..72f90505c6 100644 --- a/services/surfaceflinger/Scheduler/VSyncModulator.h +++ b/services/surfaceflinger/Scheduler/VSyncModulator.h @@ -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 mTransactionStart = Scheduler::TransactionStart::NORMAL; - std::atomic mLastFrameUsedRenderEngine = false; std::atomic mRefreshRateChangePending = false; std::atomic mRemainingEarlyFrameCount = 0; + std::atomic mRemainingRenderEngineUsageCount = 0; }; } // namespace android -- cgit v1.2.3-59-g8ed1b