SF: Extract SurfaceFlinger::wouldPresentEarly
Short-circuit a few fetches and arithmetic operations.
Bug: 241285475
Test: libscheduler_test after Idf9f43b37f3479c94a478d154eaa46f43e0c6c9d
Change-Id: Ib40794cca0c44f8151ca9f37ba58ac4d892c66ee
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 38f8db0..7171adc 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -2146,7 +2146,13 @@
}));
}
-auto SurfaceFlinger::getPreviousPresentFence(TimePoint frameTime, Period vsyncPeriod)
+bool SurfaceFlinger::wouldPresentEarly(TimePoint frameTime, Period vsyncPeriod) const {
+ const bool isThreeVsyncsAhead = mExpectedPresentTime - frameTime > 2 * vsyncPeriod;
+ return isThreeVsyncsAhead ||
+ mPreviousPresentFences[0].fenceTime->getSignalTime() != Fence::SIGNAL_TIME_PENDING;
+}
+
+auto SurfaceFlinger::getPreviousPresentFence(TimePoint frameTime, Period vsyncPeriod) const
-> const FenceTimePtr& {
const bool isTwoVsyncsAhead = mExpectedPresentTime - frameTime > vsyncPeriod;
const size_t i = static_cast<size_t>(isTwoVsyncsAhead);
@@ -2610,21 +2616,14 @@
refreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::milliseconds(mDebugFlashDelay);
}
- const auto prevVsyncTime = mExpectedPresentTime - mScheduler->getVsyncSchedule()->period();
- const auto hwcMinWorkDuration = mVsyncConfiguration->getCurrentConfigs().hwcMinWorkDuration;
-
const Period vsyncPeriod = mScheduler->getVsyncSchedule()->period();
- const bool threeVsyncsAhead = mExpectedPresentTime - frameTime > 2 * vsyncPeriod;
- // We should wait for the earliest present time if HWC doesn't support ExpectedPresentTime,
- // and the next vsync is not already taken by the previous frame.
- const bool waitForEarliestPresent =
- !getHwComposer().getComposer()->isSupported(
- Hwc2::Composer::OptionalFeature::ExpectedPresentTime) &&
- (threeVsyncsAhead ||
- mPreviousPresentFences[0].fenceTime->getSignalTime() != Fence::SIGNAL_TIME_PENDING);
+ if (!getHwComposer().getComposer()->isSupported(
+ Hwc2::Composer::OptionalFeature::ExpectedPresentTime) &&
+ wouldPresentEarly(frameTime, vsyncPeriod)) {
+ const auto prevVsyncTime = mExpectedPresentTime - vsyncPeriod;
+ const auto hwcMinWorkDuration = mVsyncConfiguration->getCurrentConfigs().hwcMinWorkDuration;
- if (waitForEarliestPresent) {
refreshArgs.earliestPresentTime = prevVsyncTime - hwcMinWorkDuration;
}