The new helper function retrieves current time in the format that is compatible with vblank timestamps.
Signed-off-by: Ilija Hadzic <[email protected]> --- src/drmmode_display.c | 25 +++++++++++++++++++++++++ src/drmmode_display.h | 1 + 2 files changed, 26 insertions(+) diff --git a/src/drmmode_display.c b/src/drmmode_display.c index 13e65fa..2b61823 100644 --- a/src/drmmode_display.c +++ b/src/drmmode_display.c @@ -31,6 +31,7 @@ #include <errno.h> #include <sys/ioctl.h> +#include <time.h> #include "micmap.h" #include "xf86cmap.h" #include "radeon.h" @@ -216,6 +217,30 @@ drmmode_ConvertToKMode(ScrnInfoPtr scrn, } +/* + * Retrieves present time in milliseconds that is compatible + * with units used by vblank timestamps. Depending on the kernel + * version and DRM kernel module configuration, the vblank + * timestamp can either be in real time or monotonic time + */ +int drmmode_get_current_ust(int drm_fd, CARD64 *ust) +{ + uint64_t cap_value; + int ret; + struct timespec now; + + ret = drmGetCap(drm_fd, DRM_CAP_TIMESTAMP_MONOTONIC, &cap_value); + if (ret || !cap_value) + /* old kernel or drm_timestamp_monotonic turned off */ + ret = clock_gettime(CLOCK_REALTIME, &now); + else + ret = clock_gettime(CLOCK_MONOTONIC, &now); + if (ret) + return ret; + *ust = ((CARD64)now.tv_sec * 1000000) + ((CARD64)now.tv_nsec / 1000); + return 0; +} + static void drmmode_crtc_dpms(xf86CrtcPtr crtc, int mode) { diff --git a/src/drmmode_display.h b/src/drmmode_display.h index b63ec8e..2e56893 100644 --- a/src/drmmode_display.h +++ b/src/drmmode_display.h @@ -115,6 +115,7 @@ extern int drmmode_get_pitch_align(ScrnInfoPtr scrn, int bpe, uint32_t tiling); extern int drmmode_get_base_align(ScrnInfoPtr scrn, int bpe, uint32_t tiling); Bool radeon_do_pageflip(ScrnInfoPtr scrn, struct radeon_bo *new_front, void *data, int ref_crtc_hw_id); +int drmmode_get_current_ust(int drm_fd, CARD64 *ust); #endif -- 1.8.1.5 _______________________________________________ xorg-driver-ati mailing list [email protected] http://lists.x.org/mailman/listinfo/xorg-driver-ati
