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_;