drm_hwcomposer: Calculate vsync period consistently
Calculating the vsync period can yield different results depending on
floating point precision and ordering of operations.
Calcuate the vsync period in one place for consistency.
Change-Id: I968e4976ec5d546f66ffe3e0f7dd404cd934a60c
Signed-off-by: Drew Davenport <ddavenport@google.com>
diff --git a/drm/DrmMode.h b/drm/DrmMode.h
index c5790a5..5450daf 100644
--- a/drm/DrmMode.h
+++ b/drm/DrmMode.h
@@ -48,6 +48,12 @@
(float)(mode_.vtotal * mode_.htotal) * 1000.0F;
}
+ auto GetVSyncPeriodNs() const {
+ static const int kNanosecondsPerSecond = 1E9;
+ return static_cast<int32_t>(kNanosecondsPerSecond *
+ double(1 / GetVRefresh()));
+ }
+
auto GetName() const {
return std::string(mode_.name) + "@" + std::to_string(GetVRefresh());
}