When modechanging on X11, try to match configured refresh rate.

This commit is contained in:
Themaister 2014-07-13 19:23:08 +02:00
parent b1270496a3
commit 45205cc5d7
2 changed files with 16 additions and 14 deletions

View File

@ -34,6 +34,7 @@
#include <unistd.h>
#include <sched.h>
#include <sys/time.h>
#include <math.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
@ -599,19 +600,11 @@ static bool gfx_ctx_set_video_mode(void *data,
if (width != g_connector->modes[i].hdisplay || height != g_connector->modes[i].vdisplay)
continue;
if (!g_drm_mode)
float diff = fabsf(g_connector->modes[i].vrefresh - g_settings.video.refresh_rate);
if (!g_drm_mode || diff < minimum_fps_diff)
{
g_drm_mode = &g_connector->modes[i];
minimum_fps_diff = g_drm_mode->vrefresh - g_settings.video.refresh_rate;
}
else
{
float diff = g_connector->modes[i].vrefresh - g_settings.video.refresh_rate;
if (diff < minimum_fps_diff)
{
g_drm_mode = &g_connector->modes[i];
minimum_fps_diff = diff;
}
minimum_fps_diff = diff;
}
}
}

View File

@ -18,6 +18,7 @@
#include <stdlib.h>
#include <string.h>
#include <X11/Xatom.h>
#include <math.h>
#include "../image/image.h"
#include "../../general.h"
#include "../../input/input_common.h"
@ -146,13 +147,21 @@ static bool get_video_mode(Display *dpy, unsigned width, unsigned height, XF86Vi
*desktop_mode = *modes[0];
bool ret = false;
float minimum_fps_diff = 0.0f;
for (i = 0; i < num_modes; i++)
{
if (modes[i]->hdisplay == width && modes[i]->vdisplay == height)
const XF86VidModeModeInfo *m = modes[i];
if (m->hdisplay == width && m->vdisplay == height)
{
*mode = *modes[i];
float refresh = m->dotclock * 1000.0f / (m->htotal * m->vtotal);
float diff = fabsf(refresh - g_settings.video.refresh_rate);
if (!ret || diff < minimum_fps_diff)
{
*mode = *m;
minimum_fps_diff = diff;
}
ret = true;
break;
}
}