xf86-video-intel: Branch 'dri2-swapbuffers' - 2 commits - src/drmmode_display.c src/i830_dri.c src/i830.h

Kristian Høgsberg krh at kemper.freedesktop.org
Fri Jul 17 17:22:04 PDT 2009


 src/drmmode_display.c |   72 ++++++++++++++++++++++++++++++++------------------
 src/i830.h            |    2 -
 src/i830_dri.c        |   28 ++++---------------
 3 files changed, 54 insertions(+), 48 deletions(-)

New commits:
commit 5448c35a3e31226bdb13d46db3efb5519cc4d36e
Author: Kristian Høgsberg <krh at redhat.com>
Date:   Fri Jul 17 12:21:22 2009 -0400

    Pass void * token back in DRI2SwapComplete()

diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 5b7d785..6fd5836 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -46,7 +46,7 @@ typedef struct {
     int cpp;
     
     drmEventContext event_context;
-    DrawablePtr swap_drawable;
+    void *swap_data;
     int old_fb_id;
 } drmmode_rec, *drmmode_ptr;
 
@@ -1101,7 +1101,8 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
 }
 
 Bool
-drmmode_do_pageflip(DrawablePtr pDraw, dri_bo *new_front, dri_bo *old_front)
+drmmode_do_pageflip(DrawablePtr pDraw, dri_bo *new_front, dri_bo *old_front,
+		    void *data)
 {
     ScreenPtr pScreen = pDraw->pScreen;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
@@ -1139,7 +1140,7 @@ drmmode_do_pageflip(DrawablePtr pDraw, dri_bo *new_front, dri_bo *old_front)
 
 	    drmmode_crtc = crtc->driver_private;
 	    crtc_id = drmmode_crtc->mode_crtc->crtc_id;
-	    drmmode->swap_drawable = pDraw;
+	    drmmode->swap_data = data;
 	    if (drmModePageFlip(drmmode->fd, crtc_id, drmmode->fb_id, drmmode)) {
 		    xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
 			       "flip queue failed: %s\n", strerror(errno));
@@ -1178,7 +1179,7 @@ drmmode_page_flip_handler(int fd,
 
     drmModeRmFB(drmmode->fd, drmmode->old_fb_id);
 
-    DRI2SwapComplete(drmmode->swap_drawable);
+    DRI2SwapComplete(drmmode->swap_data);
 }
 
 static void
diff --git a/src/i830.h b/src/i830.h
index b4f5d7a..51a87cb 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -690,7 +690,7 @@ extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, int fd, int cpp);
 extern int drmmode_get_pipe_from_crtc_id(drm_intel_bufmgr *bufmgr, xf86CrtcPtr crtc);
 extern int drmmode_output_dpms_status(xf86OutputPtr output);
 extern Bool drmmode_do_pageflip(DrawablePtr pDraw, dri_bo *new_front,
-				dri_bo *old_front);
+				dri_bo *old_front, void *data);
 
 extern Bool i830_crtc_on(xf86CrtcPtr crtc);
 extern int i830_crtc_to_pipe(xf86CrtcPtr crtc);
diff --git a/src/i830_dri.c b/src/i830_dri.c
index ad9a371..b34b9b7 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -366,7 +366,8 @@ I830DRI2CopyRegion(DrawablePtr pDraw, RegionPtr pRegion,
  *     and back buffers
  */
 static Bool
-I830DRI2SwapBuffers(DrawablePtr pDraw, DRI2BufferPtr front, DRI2BufferPtr back)
+I830DRI2SwapBuffers(DrawablePtr pDraw,
+		    DRI2BufferPtr front, DRI2BufferPtr back, void *data)
 {
     ScreenPtr pScreen = pDraw->pScreen;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
@@ -399,7 +400,7 @@ I830DRI2SwapBuffers(DrawablePtr pDraw, DRI2BufferPtr front, DRI2BufferPtr back)
 
     /* Page flip the full screen buffer */
     return drmmode_do_pageflip(pDraw, i830_get_pixmap_bo(front_priv->pPixmap),
-			       i830_get_pixmap_bo(back_priv->pPixmap));
+			       i830_get_pixmap_bo(back_priv->pPixmap), data);
 }
 #endif
 
commit 376fe1f9caa00d7e18704589d760d8398fb21cf2
Author: Kristian Høgsberg <krh at redhat.com>
Date:   Fri Jul 17 11:30:33 2009 -0400

    Notify DRI2 asynchronously when page flip is finished
    
    This lets DRI2 suspend just the swapping client instead of the entire
    server.  When the swap is done, the drm fd becomes readable and we
    call back into DRI2 so it can resume the client.

diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 03b494d..5b7d785 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -44,6 +44,10 @@ typedef struct {
     uint32_t fb_id;
     drmModeResPtr mode_res;
     int cpp;
+    
+    drmEventContext event_context;
+    DrawablePtr swap_drawable;
+    int old_fb_id;
 } drmmode_rec, *drmmode_ptr;
 
 typedef struct {
@@ -1106,15 +1110,13 @@ drmmode_do_pageflip(DrawablePtr pDraw, dri_bo *new_front, dri_bo *old_front)
     drmmode_crtc_private_ptr drmmode_crtc = config->crtc[0]->driver_private;
     drmmode_ptr drmmode = drmmode_crtc->drmmode;
     unsigned int pitch = pScrn->displayWidth * pI830->cpp;
-    int i, old_fb_id;
+    int i;
     unsigned int crtc_id;
-    struct pollfd drmpoll;
-    drmEventContext handler = { .page_flip_handler = NULL };
 
     /*
      * Create a new handle for the back buffer
      */
-    old_fb_id = drmmode->fb_id;
+    drmmode->old_fb_id = drmmode->fb_id;
     if (drmModeAddFB(drmmode->fd, pScrn->virtualX, pScrn->virtualY,
 		     pScrn->depth, pScrn->bitsPerPixel, pitch,
 		     new_front->handle, &drmmode->fb_id))
@@ -1137,40 +1139,23 @@ drmmode_do_pageflip(DrawablePtr pDraw, dri_bo *new_front, dri_bo *old_front)
 
 	    drmmode_crtc = crtc->driver_private;
 	    crtc_id = drmmode_crtc->mode_crtc->crtc_id;
-	    if (drmModePageFlip(drmmode->fd, crtc_id, drmmode->fb_id, NULL)) {
+	    drmmode->swap_drawable = pDraw;
+	    if (drmModePageFlip(drmmode->fd, crtc_id, drmmode->fb_id, drmmode)) {
 		    xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
 			       "flip queue failed: %s\n", strerror(errno));
 		    goto error_undo;
 	    }
     }
 
-retry:
-    drmpoll.fd = drmmode->fd;
-    drmpoll.events = POLLIN;
-    if (poll(&drmpoll, 1, -1) < 0) {
-	    if (errno == EINTR)
-		    goto retry;
-	    xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "poll failed: %s\n",
-		       strerror(errno));
-	    goto error_undo;
-    }
-
-    drmHandleEvent(drmmode->fd, &handler);
-
-    dri_bo_pin(new_front, 0);
-    dri_bo_unpin(new_front);
-
     pScrn->fbOffset = new_front->offset;
     pI830->front_buffer->bo = new_front;
     pI830->front_buffer->offset = new_front->offset;
 
-    drmModeRmFB(drmmode->fd, old_fb_id);
-
     return TRUE;
 
 error_undo:
     drmModeRmFB(drmmode->fd, drmmode->fb_id);
-    drmmode->fb_id = old_fb_id;
+    drmmode->fb_id = drmmode->old_fb_id;
 
 error_out:
     xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Page flip failed: %s\n",
@@ -1182,6 +1167,34 @@ static const xf86CrtcConfigFuncsRec drmmode_xf86crtc_config_funcs = {
 	drmmode_xf86crtc_resize
 };
 
+static void
+drmmode_page_flip_handler(int fd,
+			  unsigned int frame, 
+			  unsigned int tv_sec,
+			  unsigned int tv_usec,
+			  void *user_data)
+{
+    drmmode_ptr drmmode = user_data;
+
+    drmModeRmFB(drmmode->fd, drmmode->old_fb_id);
+
+    DRI2SwapComplete(drmmode->swap_drawable);
+}
+
+static void
+drm_wakeup_handler(pointer data, int err, pointer read_mask)
+{
+    drmmode_ptr drmmode = data;
+
+    if (FD_ISSET(drmmode->fd, (fd_set *) read_mask))
+	drmHandleEvent(drmmode->fd, &drmmode->event_context);
+}
+
+static void
+drm_block_handler(pointer data, struct timeval **tv, pointer read_mask)
+{
+}
+
 Bool drmmode_pre_init(ScrnInfoPtr pScrn, int fd, int cpp)
 {
 	xf86CrtcConfigPtr   xf86_config;
@@ -1221,6 +1234,14 @@ Bool drmmode_pre_init(ScrnInfoPtr pScrn, int fd, int cpp)
 		xf86DrvMsg(pScrn->scrnIndex, X_INFO,
 			   "Kernel page flipping support detected, enabling\n");
 		pI830->use_swap_buffers = TRUE;
+
+		drmmode->event_context.version = DRM_EVENT_CONTEXT_VERSION;
+		drmmode->event_context.page_flip_handler =
+		    drmmode_page_flip_handler;
+		AddGeneralSocket(fd);
+		RegisterBlockAndWakeupHandlers(drm_block_handler,
+					       drm_wakeup_handler,
+					       drmmode);
 	}
 
 	return TRUE;
diff --git a/src/i830_dri.c b/src/i830_dri.c
index 0f38d09..ad9a371 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -357,25 +357,6 @@ I830DRI2CopyRegion(DrawablePtr pDraw, RegionPtr pRegion,
 }
 
 #if DRI2INFOREC_VERSION >= 4
-/* Check various flip constraints (drawable parameters vs screen params) */
-static Bool
-i830_flip_ok(DrawablePtr pDraw)
-{
-    ScreenPtr pScreen = pDraw->pScreen;
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    I830Ptr pI830 = I830PTR(pScrn);
-
-    if (pI830->shadow_present)
-	return FALSE;
-    if (pDraw->width != pScrn->virtualX)
-	return FALSE;
-    if (pDraw->height != pScrn->virtualY)
-	return FALSE;
-    if (pDraw->depth != pScrn->depth)
-	return FALSE;
-
-    return TRUE;
-}
 
 /*
  * DRI2SwapBuffers should try to do a buffer swap if possible, however:
@@ -388,6 +369,8 @@ static Bool
 I830DRI2SwapBuffers(DrawablePtr pDraw, DRI2BufferPtr front, DRI2BufferPtr back)
 {
     ScreenPtr pScreen = pDraw->pScreen;
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    I830Ptr pI830 = I830PTR(pScrn);
     I830DRI2BufferPrivatePtr front_priv, back_priv;
     dri_bo *tmp_bo;
     int tmp;
@@ -395,7 +378,7 @@ I830DRI2SwapBuffers(DrawablePtr pDraw, DRI2BufferPtr front, DRI2BufferPtr back)
     front_priv = front->driverPrivate;
     back_priv = back->driverPrivate;
 
-    if (!i830_flip_ok(pDraw))
+    if (pI830->shadow_present)
 	return FALSE;
 
     /* Swap BO names so DRI works */


More information about the xorg-commit mailing list