drm_hwcomposer: Remove redundant vsync timestamp
Vsync timestamp was being tracked in two values. One was used for
approximating the next timestamp when waiting for vblank failed, and the
other was used when vsync timestamp tracking was enabled.
Add a new bool to track whether a vsync has been recorded since a caller
enabled vsync timestamp tracking, and return the value of
vsync_timestamp_ if it is fresh.
Change-Id: I0129510d9ce7d72db8f1c64fa2178d2ce7836e81
Signed-off-by: Drew Davenport <ddavenport@google.com>
diff --git a/drm/VSyncWorker.cpp b/drm/VSyncWorker.cpp
index 5b3071d..7ec1c28 100644
--- a/drm/VSyncWorker.cpp
+++ b/drm/VSyncWorker.cpp
@@ -71,9 +71,9 @@
const std::lock_guard<std::mutex> lock(mutex_);
enable_vsync_timestamps_ = enabled;
if (enabled) {
- // Reset the last timestamp so the caller knows if a vsync timestamp is
- // fresh or not.
- last_vsync_timestamp_ = 0;
+ // Reset the freshness flag to ensure that only a fresh timestamp is
+ // returned from GetLastVsyncTimestamp.
+ last_timestamp_is_fresh_ = false;
}
}
UpdateVSyncControl();
@@ -81,7 +81,7 @@
uint32_t VSyncWorker::GetLastVsyncTimestamp() {
const std::lock_guard<std::mutex> lock(mutex_);
- return last_vsync_timestamp_;
+ return last_timestamp_is_fresh_ ? last_timestamp_.value_or(0) : 0;
}
void VSyncWorker::SetTimestampCallback(
@@ -206,7 +206,7 @@
if (!enabled_)
continue;
if (enable_vsync_timestamps_) {
- last_vsync_timestamp_ = timestamp;
+ last_timestamp_is_fresh_ = true;
}
vsync_callback = callback_;
vsync_period_ns = vsync_period_ns_;
diff --git a/drm/VSyncWorker.h b/drm/VSyncWorker.h
index 784f85d..8e410f4 100644
--- a/drm/VSyncWorker.h
+++ b/drm/VSyncWorker.h
@@ -75,7 +75,7 @@
static constexpr uint32_t kDefaultVSPeriodNs = 16666666;
uint32_t vsync_period_ns_ GUARDED_BY(mutex_) = kDefaultVSPeriodNs;
bool enable_vsync_timestamps_ GUARDED_BY(mutex_) = false;
- uint32_t last_vsync_timestamp_ GUARDED_BY(mutex_) = 0;
+ bool last_timestamp_is_fresh_ GUARDED_BY(mutex_) = false;
std::optional<VsyncTimestampCallback> callback_ GUARDED_BY(mutex_);
std::condition_variable cv_;