drm_hwcomposer: Avoid resetting vsync timestamp

last_timestamp_ tracks the most recent timestamp from a vblank event. Do
not reset it when toggling vsync tracking on/off. This allows for
GetPhasedVSync to calculate a more precise approximation of the next
vsync relative to the current time, even if a vsync hasn't happened for
a while.

Reset last_timestamp_ when the vsync period changes, since the phased
vsync calculation is based on the current vsync.

Also change last_timestamp_ to std::optional type.

Change-Id: I101b36f87d6ba8197c321c83ac0bc230fba9cf7e
Signed-off-by: Drew Davenport <ddavenport@google.com>
diff --git a/drm/VSyncWorker.h b/drm/VSyncWorker.h
index 5b97328..784f85d 100644
--- a/drm/VSyncWorker.h
+++ b/drm/VSyncWorker.h
@@ -37,7 +37,8 @@
   auto static CreateInstance(std::shared_ptr<DrmDisplayPipeline> &pipe)
       -> std::unique_ptr<VSyncWorker>;
 
-  // Set the expected vsync period.
+  // Set the expected vsync period. Resets internal timestamp tracking until the
+  // next vsync event is tracked.
   void SetVsyncPeriodNs(uint32_t vsync_period_ns);
 
   // Set or clear a callback to be fired on vsync.
@@ -68,7 +69,7 @@
 
   bool enabled_ GUARDED_BY(mutex_) = false;
   bool thread_exit_ GUARDED_BY(mutex_) = false;
-  int64_t last_timestamp_ GUARDED_BY(mutex_) = -1;
+  std::optional<int64_t> last_timestamp_ GUARDED_BY(mutex_);
 
   // Default to 60Hz refresh rate
   static constexpr uint32_t kDefaultVSPeriodNs = 16666666;