Created
March 6, 2016 12:17
-
-
Save makotokato/9fdf0602981733731d59 to your computer and use it in GitHub Desktop.
get vsync using libdrm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <fcntl.h> | |
#include <unistd.h> | |
#include <sys/time.h> | |
#include "xf86drm.h" | |
// gcc -I/usr/include/libdrm/ -ldrm vsync.c | |
int64_t get_time(void) | |
{ | |
struct timeval now_tv; | |
gettimeofday(&now_tv, NULL); | |
return now_tv.tv_sec * 1000000LL + now_tv.tv_usec; | |
} | |
int main() | |
{ | |
drm_wait_vblank_t blank; | |
int fd; | |
int i; | |
fd = open("/dev/dri/card0", O_RDWR); | |
if (fd < 0) { | |
fprintf(stderr, "open\n"); | |
return -1; | |
} | |
i = 0; | |
while (i++ < 100) { | |
int64_t before = get_time(); | |
blank.request.type = DRM_VBLANK_RELATIVE; | |
blank.request.sequence = 1; | |
if (drmWaitVBlank(fd, (drmVBlankPtr) &blank)) { | |
fprintf(stderr, "drmWaitVBlank\n"); | |
return -1; | |
} | |
printf("%ld\n", get_time() - before); | |
} | |
close(fd); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment