summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/drmmode_display.c25
-rw-r--r--src/drmmode_display.h5
2 files changed, 30 insertions, 0 deletions
diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 13e65fa3..5db58daa 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 microseconds 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 b63ec8eb..add2ee48 100644
--- a/src/drmmode_display.h
+++ b/src/drmmode_display.h
@@ -34,6 +34,10 @@
#include "radeon_probe.h"
+#ifndef DRM_CAP_TIMESTAMP_MONOTONIC
+#define DRM_CAP_TIMESTAMP_MONOTONIC 0x6
+#endif
+
typedef struct {
int fd;
unsigned fb_id;
@@ -115,6 +119,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