drm_hwcomposer: Add VSyncWorker::GetNextVsyncTimestamp
Add a function to approximate when the next vsync after a given
timestamp will be.
This can be used to support expectedPresentTime functionality to
determine if a pending property set should be committed immediately or
for a future vsync.
Change-Id: I6b1f0182d3416b0ffa361f54e6695b2894eb842a
Signed-off-by: Drew Davenport <ddavenport@google.com>
diff --git a/drm/VSyncWorker.cpp b/drm/VSyncWorker.cpp
index 7ec1c28..4b08515 100644
--- a/drm/VSyncWorker.cpp
+++ b/drm/VSyncWorker.cpp
@@ -84,6 +84,11 @@
return last_timestamp_is_fresh_ ? last_timestamp_.value_or(0) : 0;
}
+int64_t VSyncWorker::GetNextVsyncTimestamp(int64_t time) {
+ const std::lock_guard<std::mutex> lock(mutex_);
+ return GetPhasedVSync(vsync_period_ns_, time);
+}
+
void VSyncWorker::SetTimestampCallback(
std::optional<VsyncTimestampCallback> &&callback) {
{
diff --git a/drm/VSyncWorker.h b/drm/VSyncWorker.h
index 8e410f4..e8ed24b 100644
--- a/drm/VSyncWorker.h
+++ b/drm/VSyncWorker.h
@@ -50,6 +50,10 @@
void SetVsyncTimestampTracking(bool enabled);
uint32_t GetLastVsyncTimestamp();
+ // Get the next predicted vsync timestamp after |time|, based on the last
+ // recorded vsync timestamp and the current vsync period.
+ int64_t GetNextVsyncTimestamp(int64_t time);
+
void StopThread();
private: