Skip to content

Commit

Permalink
Fix vsync-drm
Browse files Browse the repository at this point in the history
  • Loading branch information
Avi-D-coder committed Dec 21, 2018
1 parent fa98564 commit 09e372c
Showing 1 changed file with 36 additions and 27 deletions.
63 changes: 36 additions & 27 deletions src/vsync.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,44 @@
#include "opengl.h"
#endif

#ifdef CONFIG_VSYNC_DRM
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <drm.h>
#include <errno.h>
#include <sys/ioctl.h>
#endif

#include "vsync.h"

#ifdef CONFIG_VSYNC_DRM
/**
* Wait for next VSync, DRM method.
*
* Stolen from: https://github.com/MythTV/mythtv/blob/master/mythtv/libs/libmythtv/vsync.cpp
*/
static int
vsync_drm_wait(session_t *ps) {
int ret = -1;
drm_wait_vblank_t vbl;

vbl.request.type = _DRM_VBLANK_RELATIVE,
vbl.request.sequence = 1;

do {
ret = ioctl(ps->drm_fd, DRM_IOCTL_WAIT_VBLANK, &vbl);
vbl.request.type &= ~_DRM_VBLANK_RELATIVE;
} while (ret && errno == EINTR);

if (ret)
log_error("VBlank ioctl did not work, unimplemented in this drmver?");

return ret;

}
#endif

/**
* Initialize DRM VSync.
*
Expand Down Expand Up @@ -168,33 +204,6 @@ bool (*const VSYNC_FUNCS_INIT[NUM_VSYNC])(session_t *ps) = {
[VSYNC_OPENGL_MSWC ] = vsync_opengl_mswc_init,
};

#ifdef CONFIG_VSYNC_DRM
/**
* Wait for next VSync, DRM method.
*
* Stolen from: https://github.com/MythTV/mythtv/blob/master/mythtv/libs/libmythtv/vsync.cpp
*/
static int
vsync_drm_wait(session_t *ps) {
int ret = -1;
drm_wait_vblank_t vbl;

vbl.request.type = _DRM_VBLANK_RELATIVE,
vbl.request.sequence = 1;

do {
ret = ioctl(ps->drm_fd, DRM_IOCTL_WAIT_VBLANK, &vbl);
vbl.request.type &= ~_DRM_VBLANK_RELATIVE;
} while (ret && errno == EINTR);

if (ret)
log_error("VBlank ioctl did not work, unimplemented in this drmver?");

return ret;

}
#endif

#ifdef CONFIG_OPENGL
/**
* Wait for next VSync, OpenGL method.
Expand Down

0 comments on commit 09e372c

Please sign in to comment.