aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-05-13 09:40:10 -0400
committerGitHub <noreply@github.com>2017-05-13 09:40:10 -0400
commit66e02e97ec3322b6453bf0db227fd2cd6c39c819 (patch)
tree39c0753b4d5aa7fdc61c1db0bc380559f050ba6a /backend
parent537096807efebad8dab2b5573187dbf0d2337810 (diff)
parent409065ba2ecd34d249383704f9a63b4894f55dba (diff)
Merge pull request #4 from ascent12/refresh
More accurate refresh rates (mHz)
Diffstat (limited to 'backend')
-rw-r--r--backend/drm/drm.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/backend/drm/drm.c b/backend/drm/drm.c
index a8e8c9ae..db75853d 100644
--- a/backend/drm/drm.c
+++ b/backend/drm/drm.c
@@ -249,6 +249,20 @@ static struct wlr_output_impl output_impl = {
.destroy = wlr_drm_output_destroy,
};
+static int32_t calculate_refresh_rate(drmModeModeInfo *mode) {
+ int32_t refresh = (mode->clock * 1000000LL / mode->htotal +
+ mode->vtotal / 2) / mode->vtotal;
+
+ if (mode->flags & DRM_MODE_FLAG_INTERLACE)
+ refresh *= 2;
+ if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
+ refresh /= 2;
+ if (mode->vscan > 1)
+ refresh /= mode->vscan;
+
+ return refresh;
+}
+
static void scan_property_ids(int fd, drmModeConnector *conn,
struct wlr_output_state *output) {
for (int i = 0; i < conn->count_props; ++i) {
@@ -347,14 +361,12 @@ void wlr_drm_scan_connectors(struct wlr_backend_state *state) {
struct wlr_output_mode *mode = calloc(1,
sizeof(struct wlr_output_mode));
mode->width = _state->mode.hdisplay;
- // TODO: Calculate more accurate refresh rate
- // TODO: Check that this refresh rate is mHz
mode->height = _state->mode.vdisplay;
+ mode->refresh = calculate_refresh_rate(&_state->mode);
mode->state = _state;
- wlr_log(L_INFO, " %"PRIu16"@%"PRIu16"@%"PRIu32,
- _state->mode.hdisplay, _state->mode.vdisplay,
- _state->mode.vrefresh);
+ wlr_log(L_INFO, " %"PRId32"@%"PRId32"@%"PRId32,
+ mode->width, mode->height, mode->refresh);
list_add(wlr_output->modes, mode);
}