Skip to content

Commit b541d1e

Browse files
authored
gfx/drm: fix mode vrefresh calculation (#16376)
When using an interlaced/doublescan mode, the vertical refresh rate is mis-calculated. Replaced the current calc method with the one from libdrm's 'modetest' utility [1]. [1] https://gitlab.freedesktop.org/mesa/drm/-/blob/main/tests/modetest/modetest.c?ref_type=heads#L140
1 parent 8bb7173 commit b541d1e

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

gfx/common/drm_common.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,19 @@ bool drm_get_connector(int fd, unsigned monitor_index)
123123

124124
float drm_calc_refresh_rate(drmModeModeInfo *mode)
125125
{
126-
float refresh_rate = (mode->clock * 1000.0f) / (mode->htotal * mode->vtotal);
127-
return refresh_rate;
126+
unsigned int num, den;
127+
128+
num = mode->clock;
129+
den = mode->htotal * mode->vtotal;
130+
131+
if (mode->flags & DRM_MODE_FLAG_INTERLACE)
132+
num *= 2;
133+
if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
134+
den *= 2;
135+
if (mode->vscan > 1)
136+
den *= mode->vscan;
137+
138+
return num * 1000.0f / den;
128139
}
129140

130141
bool drm_get_encoder(int fd)

0 commit comments

Comments
 (0)