drm_hwcomposer: Simplify default vsync period
VSyncWorker::SetVsyncPeriod won't be called with a value of 0, so the
only time the internal vsync period will be zero is if SetVsyncPeriod
was not called.
Set the 60Hz vsync period as a default value, and let the synthetic
vsync code expect it to be set to a reasonable value.
Change-Id: Ie1f83b0c11504acf304cc241923bfa60a5ffd647
Signed-off-by: Drew Davenport <ddavenport@google.com>
diff --git a/drm/VSyncWorker.cpp b/drm/VSyncWorker.cpp
index f4c0710..851e87c 100644
--- a/drm/VSyncWorker.cpp
+++ b/drm/VSyncWorker.cpp
@@ -100,11 +100,7 @@
int VSyncWorker::SyntheticWaitVBlank(int64_t *timestamp) {
auto time_now = ResourceManager::GetTimeMonotonicNs();
- // Default to 60Hz refresh rate
- constexpr uint32_t kDefaultVSPeriodNs = 16666666;
- auto period_ns = vsync_period_ns_ ? vsync_period_ns_ : kDefaultVSPeriodNs;
-
- auto phased_timestamp = GetPhasedVSync(period_ns, time_now);
+ auto phased_timestamp = GetPhasedVSync(vsync_period_ns_, time_now);
struct timespec vsync {};
vsync.tv_sec = int(phased_timestamp / kOneSecondNs);
vsync.tv_nsec = int(phased_timestamp - (vsync.tv_sec * kOneSecondNs));
diff --git a/drm/VSyncWorker.h b/drm/VSyncWorker.h
index 2ee7f37..aff34d8 100644
--- a/drm/VSyncWorker.h
+++ b/drm/VSyncWorker.h
@@ -62,8 +62,10 @@
bool thread_exit_ = false;
int64_t last_timestamp_ = -1;
+ // Default to 60Hz refresh rate
+ static constexpr uint32_t kDefaultVSPeriodNs = 16666666;
// Needs to be threadsafe.
- uint32_t vsync_period_ns_ = 0;
+ uint32_t vsync_period_ns_ = kDefaultVSPeriodNs;
std::condition_variable cv_;
std::thread vswt_;
diff --git a/hwc2_device/HwcDisplay.cpp b/hwc2_device/HwcDisplay.cpp
index f3c0fa0..2260e36 100644
--- a/hwc2_device/HwcDisplay.cpp
+++ b/hwc2_device/HwcDisplay.cpp
@@ -680,7 +680,7 @@
uint32_t prev_vperiod_ns = 0;
GetDisplayVsyncPeriod(&prev_vperiod_ns);
- auto mode_update_commited_ = false;
+ std::optional<uint32_t> new_vsync_period_ns;
if (staged_mode_config_id_ &&
staged_mode_change_time_ <= ResourceManager::GetTimeMonotonicNs()) {
const HwcDisplayConfig *staged_config = GetConfig(
@@ -697,7 +697,7 @@
configs_.active_config_id = staged_mode_config_id_.value();
a_args.display_mode = staged_config->mode;
if (!a_args.test_only) {
- mode_update_commited_ = true;
+ new_vsync_period_ns = staged_config->mode.GetVSyncPeriodNs();
}
}
@@ -773,12 +773,8 @@
return HWC2::Error::BadParameter;
}
- if (mode_update_commited_) {
- const HwcDisplayConfig *new_config = GetCurrentConfig();
- uint32_t new_vsync_period_ns = new_config
- ? new_config->mode.GetVSyncPeriodNs()
- : 0;
- vsync_worker_->SetVsyncPeriodNs(new_vsync_period_ns);
+ 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) {