drm_hwcomposer: Enable VSyncWorker thread as needed

Rather than explicitly enabling and disabling the VSyncWorker thread
from HwcDisplay, move the logic to enable/disable the thread into
VSyncWorker, and enable it based on whether HwcDisplay has requested
vsync timeline events, or timeline tracking.

This simplifies the public interface for VSyncWorker, and removes the
need for holding the global lock to check whether the thread should be
enabled or not.

Change-Id: Ic1632a19b268ea1d4ed2d8ec8704ef531481211c
Signed-off-by: Drew Davenport <ddavenport@google.com>
diff --git a/hwc2_device/HwcDisplay.cpp b/hwc2_device/HwcDisplay.cpp
index 5dff79c..b39d8c5 100644
--- a/hwc2_device/HwcDisplay.cpp
+++ b/hwc2_device/HwcDisplay.cpp
@@ -266,7 +266,6 @@
 
   // Enable vsync events until the mode has been applied.
   vsync_worker_->SetVsyncTimestampTracking(true);
-  vsync_worker_->VSyncControl(true);
 
   return ConfigError::kNone;
 }
@@ -314,15 +313,7 @@
 HWC2::Error HwcDisplay::Init() {
   ChosePreferredConfig();
 
-  auto vsw_callbacks = (VSyncWorkerCallbacks){
-      .out_event =
-          [this](int64_t timestamp) {
-            const std::unique_lock lock(hwc_->GetResMan().GetMainLock());
-            if (!vsync_event_en_) {
-              vsync_worker_->VSyncControl(false);
-            }
-          },
-  };
+  auto vsw_callbacks = (VSyncWorkerCallbacks){};
 
   if (type_ != HWC2::DisplayType::Virtual) {
     vsync_worker_ = VSyncWorker::CreateInstance(pipeline_, vsw_callbacks);
@@ -1071,7 +1062,6 @@
       hwc->SendVsyncEventToClient(id, timestamp, period_ns);
     };
     vsync_worker_->SetTimestampCallback(callback);
-    vsync_worker_->VSyncControl(true);
   } else {
     vsync_worker_->SetTimestampCallback(std::nullopt);
   }
@@ -1171,7 +1161,6 @@
                                               ->desiredTimeNanos;
 
   vsync_worker_->SetVsyncTimestampTracking(true);
-  vsync_worker_->VSyncControl(true);
 
   return HWC2::Error::None;
 }