The new helper function retrieves current time in the format
that is compatible with vblank timestamps.

v2: - fix an incorrect statement in a comment
    - add a #define so that don't depend on libdrm patches that
      have not yet been accepted upstream

Signed-off-by: Ilija Hadzic <[email protected]>
---
 src/drmmode_display.c | 25 +++++++++++++++++++++++++
 src/drmmode_display.h |  5 +++++
 2 files changed, 30 insertions(+)

diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 13e65fa..5db58da 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 b63ec8e..add2ee4 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
 
-- 
1.8.1.5

_______________________________________________
xorg-driver-ati mailing list
[email protected]
http://lists.x.org/mailman/listinfo/xorg-driver-ati

Reply via email to