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/hwc2_device/HwcDisplay.cpp b/hwc2_device/HwcDisplay.cpp
index 2260e36..8d6b0a3 100644
--- a/hwc2_device/HwcDisplay.cpp
+++ b/hwc2_device/HwcDisplay.cpp
@@ -265,8 +265,7 @@
staged_mode_config_id_ = config;
// Enable vsync events until the mode has been applied.
- last_vsync_ts_ = 0;
- vsync_tracking_en_ = true;
+ vsync_worker_->SetVsyncTimestampTracking(true);
vsync_worker_->VSyncControl(true);
return ConfigError::kNone;
@@ -324,10 +323,7 @@
GetDisplayVsyncPeriod(&period_ns);
hwc_->SendVsyncEventToClient(handle_, timestamp, period_ns);
}
- if (vsync_tracking_en_) {
- last_vsync_ts_ = timestamp;
- }
- if (!vsync_event_en_ && !vsync_tracking_en_) {
+ if (!vsync_event_en_) {
vsync_worker_->VSyncControl(false);
}
},
@@ -776,10 +772,12 @@
if (new_vsync_period_ns) {
vsync_worker_->SetVsyncPeriodNs(new_vsync_period_ns.value());
staged_mode_config_id_.reset();
- vsync_tracking_en_ = false;
- if (last_vsync_ts_ != 0) {
+
+ vsync_worker_->SetVsyncTimestampTracking(false);
+ uint32_t last_vsync_ts = vsync_worker_->GetLastVsyncTimestamp();
+ if (last_vsync_ts != 0) {
hwc_->SendVsyncPeriodTimingChangedEventToClient(handle_,
- last_vsync_ts_ +
+ last_vsync_ts +
prev_vperiod_ns);
}
}
@@ -1167,8 +1165,7 @@
outTimeline->newVsyncAppliedTimeNanos = vsyncPeriodChangeConstraints
->desiredTimeNanos;
- last_vsync_ts_ = 0;
- vsync_tracking_en_ = true;
+ vsync_worker_->SetVsyncTimestampTracking(true);
vsync_worker_->VSyncControl(true);
return HWC2::Error::None;