drm_hwcomposer: Move vsync tracking into VSyncWorker

Track the timestamp of the last vsync event in VSyncWorker, and provide
an interface for HwcDisplay to enable/disable tracking, and to query the
most recent timestamp.

Moving this into VSyncWorker avoids the need for the VSyncWorker thread
to acquire the global lock.

Change-Id: Ib79d9a6dc5e0f7d6a36ca01dbcda5434a0f582a4
Signed-off-by: Drew Davenport <ddavenport@google.com>
diff --git a/drm/VSyncWorker.h b/drm/VSyncWorker.h
index aff34d8..f0367ae 100644
--- a/drm/VSyncWorker.h
+++ b/drm/VSyncWorker.h
@@ -43,6 +43,12 @@
   // Set the expected vsync period.
   void SetVsyncPeriodNs(uint32_t vsync_period_ns);
 
+  // Enable vsync timestamp tracking. GetLastVsyncTimestamp will return 0 if
+  // vsync tracking is disabled, or if no vsync has happened since it was
+  // enabled.
+  void SetVsyncTimestampTracking(bool enabled);
+  uint32_t GetLastVsyncTimestamp();
+
   void StopThread();
 
  private:
@@ -66,6 +72,8 @@
   static constexpr uint32_t kDefaultVSPeriodNs = 16666666;
   // Needs to be threadsafe.
   uint32_t vsync_period_ns_ = kDefaultVSPeriodNs;
+  bool enable_vsync_timestamps_ = false;
+  uint32_t last_vsync_timestamp_ = 0;
 
   std::condition_variable cv_;
   std::thread vswt_;