SF: wait instead of presenting early
If SurfaceFlinger duration is configured to a larger value
than the vsync period, there might be a chance that SF would
present the frame too early, if its actual duration is much shorter
than anticipating. To prevent this, we wait until the vsync occurs
before calling to hwc::present.
Bug: 185949581
Test: Configure large SF duration and observe systrace
Change-Id: Ic0c112a2808036d0f2e14a345c401fa56c2d29ab
diff --git a/services/surfaceflinger/Scheduler/Scheduler.cpp b/services/surfaceflinger/Scheduler/Scheduler.cpp
index 1d25c72..57bd045 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.cpp
+++ b/services/surfaceflinger/Scheduler/Scheduler.cpp
@@ -927,4 +927,11 @@
}
}
+std::chrono::steady_clock::time_point Scheduler::getPreviousVsyncFrom(
+ nsecs_t expectedPresentTime) const {
+ const auto presentTime = std::chrono::nanoseconds(expectedPresentTime);
+ const auto vsyncPeriod = std::chrono::nanoseconds(mVsyncSchedule.tracker->currentPeriod());
+ return std::chrono::steady_clock::time_point(presentTime - vsyncPeriod);
+}
+
} // namespace android