drm_hwcomposer: Convert v_refresh() to float
We convert v_refresh() to return a float and instead of storing it,
compute it on the fly from the pixel clock + htotal/vtotal. This makes
the synthetic vblank computation much more accurate.
Change-Id: I2a0becf75eaca8ace30d176fdc813f3b57ba23a5
diff --git a/drmmode.cpp b/drmmode.cpp
index dce9803..abd3b32 100644
--- a/drmmode.cpp
+++ b/drmmode.cpp
@@ -36,7 +36,6 @@
v_sync_end_(m->vsync_end),
v_total_(m->vtotal),
v_scan_(m->vscan),
- v_refresh_(m->vrefresh),
flags_(m->flags),
type_(m->type),
name_(m->name) {
@@ -55,7 +54,6 @@
v_sync_end_(0),
v_total_(0),
v_scan_(0),
- v_refresh_(0),
flags_(0),
type_(0),
name_("") {
@@ -70,7 +68,7 @@
h_total_ == m.htotal && h_skew_ == m.hskew &&
v_display_ == m.vdisplay && v_sync_start_ == m.vsync_start &&
v_sync_end_ == m.vsync_end && v_total_ == m.vtotal &&
- v_scan_ == m.vscan && v_refresh_ == m.vrefresh && flags_ == m.flags &&
+ v_scan_ == m.vscan && flags_ == m.flags &&
type_ == m.type;
}
@@ -86,7 +84,6 @@
m->vsync_end = v_sync_end_;
m->vtotal = v_total_;
m->vscan = v_scan_;
- m->vrefresh = v_refresh_;
m->flags = flags_;
m->type = type_;
strncpy(m->name, name_.c_str(), DRM_DISPLAY_MODE_LEN);
@@ -144,8 +141,8 @@
return v_scan_;
}
-uint32_t DrmMode::v_refresh() const {
- return v_refresh_;
+float DrmMode::v_refresh() const {
+ return clock_ / (float)(v_total_ * h_total_) * 1000.0f;
}
uint32_t DrmMode::flags() const {
diff --git a/drmmode.h b/drmmode.h
index ab213ef..3088b7a 100644
--- a/drmmode.h
+++ b/drmmode.h
@@ -48,7 +48,7 @@
uint32_t v_sync_end() const;
uint32_t v_total() const;
uint32_t v_scan() const;
- uint32_t v_refresh() const;
+ float v_refresh() const;
uint32_t flags() const;
uint32_t type() const;
@@ -71,7 +71,6 @@
uint32_t v_sync_end_;
uint32_t v_total_;
uint32_t v_scan_;
- uint32_t v_refresh_;
uint32_t flags_;
uint32_t type_;
diff --git a/vsyncworker.cpp b/vsyncworker.cpp
index 9626022..29709f7 100644
--- a/vsyncworker.cpp
+++ b/vsyncworker.cpp
@@ -113,13 +113,13 @@
struct timespec vsync;
int ret = clock_gettime(CLOCK_MONOTONIC, &vsync);
- int64_t refresh = 60; // Default to 60Hz refresh rate
+ float refresh = 60.0f; // Default to 60Hz refresh rate
DrmConnector *conn = drm_->GetConnectorForDisplay(display_);
- if (conn && conn->active_mode().v_refresh())
+ if (conn && conn->active_mode().v_refresh() != 0.0f)
refresh = conn->active_mode().v_refresh();
else
- ALOGW("Vsync worker active with conn=%p refresh=%d\n", conn,
- conn ? conn->active_mode().v_refresh() : -1);
+ ALOGW("Vsync worker active with conn=%p refresh=%f\n", conn,
+ conn ? conn->active_mode().v_refresh() : 0.0f);
int64_t phased_timestamp = GetPhasedVSync(
kOneSecondNs / refresh, vsync.tv_sec * kOneSecondNs + vsync.tv_nsec);