[PATCH 09/11] DRI2: move rename and rework radeon_dri2_deferred_swap

Ilija Hadzic ilijahadzic at gmail.com
Sun Apr 28 13:07:54 PDT 2013


radeon_dri2_deferred_swap will be used to generate
real events (not just fallbacks) so now it needs to
generate real timestamp and frame counter. Also
this function will be used both by schedule_swap
and wait_msc, so give it a more generic name:
radeon_dri2_deferred_event

Signed-off-by: Ilija Hadzic <ihadzic at research.bell-labs.com>
---
 src/radeon_dri2.c | 61 ++++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 49 insertions(+), 12 deletions(-)

diff --git a/src/radeon_dri2.c b/src/radeon_dri2.c
index 4c2f06e..02ccc55 100644
--- a/src/radeon_dri2.c
+++ b/src/radeon_dri2.c
@@ -980,6 +980,51 @@ static int radeon_dri2_get_msc(DrawablePtr draw, CARD64 *ust, CARD64 *msc)
     return TRUE;
 }
 
+static
+CARD32 radeon_dri2_deferred_event(OsTimerPtr timer, CARD32 now, pointer data)
+{
+    DRI2FrameEventPtr event_info = (DRI2FrameEventPtr)data;
+    DrawablePtr drawable;
+    ScreenPtr screen;
+    ScrnInfoPtr scrn;
+    RADEONInfoPtr info;
+    int status;
+    CARD64 drm_now;
+    int ret;
+    unsigned int tv_sec, tv_usec;
+
+    TimerFree(timer);
+
+    /*
+     * This is emulated event, so its time is current time, which we
+     * have to get in DRM-compatible form (which is a bit messy given
+     * the information that we have at this point). Can't use now argument
+     * because DRM event time may come from monotonic clock, while
+     * DIX timer facility uses real-time clock.
+     */
+    status = dixLookupDrawable(&drawable, event_info->drawable_id, serverClient,
+			       M_ANY, DixWriteAccess);
+    if (status != Success) {
+	ErrorF("%s cannot lookup drawable\n", __func__);
+	radeon_dri2_frame_event_handler(0, 0, 0, data);
+	return 0;
+    }
+    screen = drawable->pScreen;
+    scrn = xf86ScreenToScrn(screen);
+    info = RADEONPTR(scrn);
+    ret = drmmode_get_current_ust(info->dri2.drm_fd, &drm_now);
+    if (ret) {
+	xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+		   "%s cannot get current time\n", __func__);
+	radeon_dri2_frame_event_handler(0, 0, 0, data);
+	return 0;
+    }
+    tv_sec = drm_now / 1000000;
+    tv_usec = drm_now - tv_sec * 1000000;
+    radeon_dri2_frame_event_handler(event_info->frame, tv_sec, tv_usec, data);
+    return 0;
+}
+
 /*
  * Request a DRM event when the requested conditions will be satisfied.
  *
@@ -1168,14 +1213,6 @@ void radeon_dri2_flip_event_handler(unsigned int frame, unsigned int tv_sec,
     free(flip);
 }
 
-static
-CARD32 radeon_dri2_deferred_swap(OsTimerPtr timer, CARD32 now, pointer data)
-{
-    TimerFree(timer);
-    radeon_dri2_frame_event_handler(0, 0, 0, data);
-    return 0;
-}
-
 /*
  * ScheduleSwap is responsible for requesting a DRM vblank event for the
  * appropriate frame.
@@ -1260,7 +1297,7 @@ static int radeon_dri2_schedule_swap(ClientPtr client, DrawablePtr draw,
 	delay = radeon_dri2_extrapolate_msc_delay(crtc, target_msc,
 						  divisor, remainder);
 	swap_info->frame = *target_msc;
-	TimerSet(NULL, 0, delay, radeon_dri2_deferred_swap, swap_info);
+	TimerSet(NULL, 0, delay, radeon_dri2_deferred_event, swap_info);
 	return TRUE;
     }
 
@@ -1273,7 +1310,7 @@ static int radeon_dri2_schedule_swap(ClientPtr client, DrawablePtr draw,
         xf86DrvMsg(scrn->scrnIndex, X_WARNING,
                 "first get vblank counter failed: %s\n",
                 strerror(errno));
-	TimerSet(NULL, 0, FALLBACK_SWAP_DELAY, radeon_dri2_deferred_swap,
+	TimerSet(NULL, 0, FALLBACK_SWAP_DELAY, radeon_dri2_deferred_event,
 		 swap_info);
 	*target_msc = 0;
 	return TRUE;
@@ -1327,7 +1364,7 @@ static int radeon_dri2_schedule_swap(ClientPtr client, DrawablePtr draw,
             xf86DrvMsg(scrn->scrnIndex, X_WARNING,
                     "divisor 0 get vblank counter failed: %s\n",
                     strerror(errno));
-	    TimerSet(NULL, 0, FALLBACK_SWAP_DELAY, radeon_dri2_deferred_swap,
+	    TimerSet(NULL, 0, FALLBACK_SWAP_DELAY, radeon_dri2_deferred_event,
 		     swap_info);
 	    *target_msc = 0;
             return TRUE;
@@ -1377,7 +1414,7 @@ static int radeon_dri2_schedule_swap(ClientPtr client, DrawablePtr draw,
         xf86DrvMsg(scrn->scrnIndex, X_WARNING,
                 "final get vblank counter failed: %s\n",
                 strerror(errno));
-	TimerSet(NULL, 0, FALLBACK_SWAP_DELAY, radeon_dri2_deferred_swap,
+	TimerSet(NULL, 0, FALLBACK_SWAP_DELAY, radeon_dri2_deferred_event,
 		 swap_info);
 	*target_msc = 0;
 	return TRUE;
-- 
1.8.1.5



More information about the xorg-driver-ati mailing list