[PATCH 08/14] DRI2: Split out helper for getting UST and MSC of a specific CRTC

Michel Dänzer michel at daenzer.net
Wed Mar 11 23:10:50 PDT 2015


From: Michel Dänzer <michel.daenzer at amd.com>

Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
---
 src/drmmode_display.c | 27 +++++++++++++++++++++++++++
 src/drmmode_display.h |  1 +
 src/radeon_dri2.c     | 32 ++++++++++++--------------------
 3 files changed, 40 insertions(+), 20 deletions(-)

diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index fc9d8a0..e90a33f 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -245,6 +245,33 @@ int drmmode_get_current_ust(int drm_fd, CARD64 *ust)
 	return 0;
 }
 
+/*
+ * Get current frame count and frame count timestamp of the crtc.
+ */
+int drmmode_crtc_get_ust_msc(xf86CrtcPtr crtc, CARD64 *ust, CARD64 *msc)
+{
+    ScrnInfoPtr scrn = crtc->scrn;
+    RADEONInfoPtr info = RADEONPTR(scrn);
+    drmVBlank vbl;
+    int ret;
+
+    vbl.request.type = DRM_VBLANK_RELATIVE;
+    vbl.request.type |= radeon_populate_vbl_request_type(crtc);
+    vbl.request.sequence = 0;
+
+    ret = drmWaitVBlank(info->dri2.drm_fd, &vbl);
+    if (ret) {
+	xf86DrvMsg(scrn->scrnIndex, X_WARNING,
+		   "get vblank counter failed: %s\n", strerror(errno));
+	return ret;
+    }
+
+    *ust = ((CARD64)vbl.reply.tval_sec * 1000000) + vbl.reply.tval_usec;
+    *msc = vbl.reply.sequence;
+
+    return Success;
+}
+
 static void
 drmmode_do_crtc_dpms(xf86CrtcPtr crtc, int mode)
 {
diff --git a/src/drmmode_display.h b/src/drmmode_display.h
index b313460..6f883c0 100644
--- a/src/drmmode_display.h
+++ b/src/drmmode_display.h
@@ -132,6 +132,7 @@ Bool radeon_do_pageflip(ScrnInfoPtr scrn, ClientPtr client,
 			struct radeon_bo *new_front, uint64_t id, void *data,
 			int ref_crtc_hw_id, radeon_drm_handler_proc handler,
 			radeon_drm_abort_proc abort);
+int drmmode_crtc_get_ust_msc(xf86CrtcPtr crtc, CARD64 *ust, CARD64 *msc);
 int drmmode_get_current_ust(int drm_fd, CARD64 *ust);
 
 #endif
diff --git a/src/radeon_dri2.c b/src/radeon_dri2.c
index 97164b6..ee04be8 100644
--- a/src/radeon_dri2.c
+++ b/src/radeon_dri2.c
@@ -952,17 +952,13 @@ CARD32 radeon_dri2_extrapolate_msc_delay(xf86CrtcPtr crtc, CARD64 *target_msc,
 }
 
 /*
- * Get current frame count and frame count timestamp, based on drawable's
- * crtc.
+ * Get current interpolated frame count and frame count timestamp, based on
+ * drawable's crtc.
  */
 static int radeon_dri2_get_msc(DrawablePtr draw, CARD64 *ust, CARD64 *msc)
 {
-    ScreenPtr screen = draw->pScreen;
-    ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
-    RADEONInfoPtr info = RADEONPTR(scrn);
-    drmVBlank vbl;
-    int ret;
     xf86CrtcPtr crtc = radeon_dri2_drawable_crtc(draw, TRUE);
+    int ret;
 
     /* Drawable not displayed, make up a value */
     if (crtc == NULL) {
@@ -970,25 +966,20 @@ static int radeon_dri2_get_msc(DrawablePtr draw, CARD64 *ust, CARD64 *msc)
         *msc = 0;
         return TRUE;
     }
+
     if (radeon_crtc_is_enabled(crtc)) {
 	/* CRTC is running, read vblank counter and timestamp */
-	vbl.request.type = DRM_VBLANK_RELATIVE;
-	vbl.request.type |= radeon_populate_vbl_request_type(crtc);
-	vbl.request.sequence = 0;
+	ret = drmmode_crtc_get_ust_msc(crtc, ust, msc);
 
-	ret = drmWaitVBlank(info->dri2.drm_fd, &vbl);
-	if (ret) {
-	    xf86DrvMsg(scrn->scrnIndex, X_WARNING,
-		       "get vblank counter failed: %s\n", strerror(errno));
-	    return FALSE;
+	if (ret != Success) {
+	    *msc += radeon_get_interpolated_vblanks(crtc);
+	    *msc &= 0xffffffff;
 	}
-
-	*ust = ((CARD64)vbl.reply.tval_sec * 1000000) + vbl.reply.tval_usec;
-	*msc = vbl.reply.sequence + radeon_get_interpolated_vblanks(crtc);
-	*msc &= 0xffffffff;
     } else {
 	/* CRTC is not running, extrapolate MSC and timestamp */
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+	ScrnInfoPtr scrn = crtc->scrn;
+	RADEONInfoPtr info = RADEONPTR(scrn);
 	CARD64 now, delta_t, delta_seq;
 
 	if (!drmmode_crtc->dpms_last_ust)
@@ -1011,7 +1002,8 @@ static int radeon_dri2_get_msc(DrawablePtr draw, CARD64 *ust, CARD64 *msc)
 	*msc += delta_seq;
 	*msc &= 0xffffffff;
     }
-    return TRUE;
+
+    return ret == Success;
 }
 
 static
-- 
2.1.4



More information about the xorg-driver-ati mailing list