drm_hwcomposer: Set vsync period for vsync thread

Make HwcDisplay set the VsyncWorker's vsync_period whenever it changes,
rather than having VsyncWorker query the vsync_period from HwcDisplay.

Doing so prevents the VsyncWorker thread from needing to acquire the
global lock to read HwcDisplay's state.

The original change called GetVsyncPeriod, which checks the vsync period
for the mode that is currently committed to the kernel based on
HwcDisplay::configs_.active_config_id, so call
VsyncWorker::SetVsyncPeriod whenever active_config_id is set.

Change-Id: Ie301c47e2496748117db8cca8a6ee9691e723c74
Signed-off-by: Drew Davenport <ddavenport@google.com>
diff --git a/drm/VSyncWorker.h b/drm/VSyncWorker.h
index 2a4c7c8..2ee7f37 100644
--- a/drm/VSyncWorker.h
+++ b/drm/VSyncWorker.h
@@ -28,7 +28,6 @@
 
 struct VSyncWorkerCallbacks {
   std::function<void(uint64_t /*timestamp*/)> out_event;
-  std::function<uint32_t()> get_vperiod_ns;
 };
 
 class VSyncWorker {
@@ -40,6 +39,10 @@
       -> std::shared_ptr<VSyncWorker>;
 
   void VSyncControl(bool enabled);
+
+  // Set the expected vsync period.
+  void SetVsyncPeriodNs(uint32_t vsync_period_ns);
+
   void StopThread();
 
  private:
@@ -59,6 +62,9 @@
   bool thread_exit_ = false;
   int64_t last_timestamp_ = -1;
 
+  // Needs to be threadsafe.
+  uint32_t vsync_period_ns_ = 0;
+
   std::condition_variable cv_;
   std::thread vswt_;
   std::mutex mutex_;