glx: Replace DRI2SwapBuffers() custom protocol with XCB.
authorEric Anholt <eric@anholt.net>
Tue, 25 Sep 2012 19:26:39 +0000 (12:26 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 9 Oct 2012 21:32:03 +0000 (14:32 -0700)
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
src/glx/dri2.c
src/glx/dri2.h
src/glx/dri2_glx.c

index c77ef7b71422d47c3548e604c253e1cf62cfe6c0..bcd1f9c90117d8105fb01dcbc0751d6fa08b2de4 100644 (file)
@@ -541,48 +541,4 @@ DRI2CopyRegion(Display * dpy, XID drawable, XserverRegion region,
    SyncHandle();
 }
 
-#ifdef X_DRI2SwapBuffers
-static void
-load_swap_req(xDRI2SwapBuffersReq *req, CARD64 target, CARD64 divisor,
-            CARD64 remainder)
-{
-    req->target_msc_hi = target >> 32;
-    req->target_msc_lo = target & 0xffffffff;
-    req->divisor_hi = divisor >> 32;
-    req->divisor_lo = divisor & 0xffffffff;
-    req->remainder_hi = remainder >> 32;
-    req->remainder_lo = remainder & 0xffffffff;
-}
-
-static CARD64
-vals_to_card64(CARD32 lo, CARD32 hi)
-{
-    return (CARD64)hi << 32 | lo;
-}
-
-void DRI2SwapBuffers(Display *dpy, XID drawable, CARD64 target_msc,
-                    CARD64 divisor, CARD64 remainder, CARD64 *count)
-{
-    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
-    xDRI2SwapBuffersReq *req;
-    xDRI2SwapBuffersReply rep;
-
-    XextSimpleCheckExtension (dpy, info, dri2ExtensionName);
-
-    LockDisplay(dpy);
-    GetReq(DRI2SwapBuffers, req);
-    req->reqType = info->codes->major_opcode;
-    req->dri2ReqType = X_DRI2SwapBuffers;
-    req->drawable = drawable;
-    load_swap_req(req, target_msc, divisor, remainder);
-
-    _XReply(dpy, (xReply *)&rep, 0, xFalse);
-
-    *count = vals_to_card64(rep.swap_lo, rep.swap_hi);
-
-    UnlockDisplay(dpy);
-    SyncHandle();
-}
-#endif
-
 #endif /* GLX_DIRECT_RENDERING */
index 179e8f91cc6c7deb18dfc40a2df4bf9ce4118f8e..a6fe66e136dd8ca268fad5c57408b1dc127bdccf 100644 (file)
@@ -85,8 +85,4 @@ DRI2CopyRegion(Display * dpy, XID drawable,
                XserverRegion region,
                CARD32 dest, CARD32 src);
 
-extern void
-DRI2SwapBuffers(Display *dpy, XID drawable, CARD64 target_msc, CARD64 divisor,
-               CARD64 remainder, CARD64 *count);
-
 #endif
index 49a2179bbf025c4d7afb844c99f9749e8e4f9439..ee07e6060100c5abb4f540a4717744b1adbb4af2 100644 (file)
@@ -737,7 +737,13 @@ dri2SwapBuffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
        __dri2CopySubBuffer(pdraw, 0, 0, priv->width, priv->height,
                           __DRI2_THROTTLE_SWAPBUFFER);
     } else {
-#ifdef X_DRI2SwapBuffers
+       xcb_connection_t *c = XGetXCBConnection(pdraw->psc->dpy);
+       xcb_dri2_swap_buffers_cookie_t swap_buffers_cookie;
+       xcb_dri2_swap_buffers_reply_t *swap_buffers_reply;
+       uint32_t target_msc_hi, target_msc_lo;
+       uint32_t divisor_hi, divisor_lo;
+       uint32_t remainder_hi, remainder_lo;
+
        if (psc->f) {
           struct glx_context *gc = __glXGetCurrentContext();
 
@@ -748,9 +754,30 @@ dri2SwapBuffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
 
        dri2Throttle(psc, priv, __DRI2_THROTTLE_SWAPBUFFER);
 
-       DRI2SwapBuffers(psc->base.dpy, pdraw->xDrawable,
-                      target_msc, divisor, remainder, &ret);
-#endif
+       split_counter(target_msc, &target_msc_hi, &target_msc_lo);
+       split_counter(divisor, &divisor_hi, &divisor_lo);
+       split_counter(remainder, &remainder_hi, &remainder_lo);
+
+       swap_buffers_cookie =
+          xcb_dri2_swap_buffers_unchecked(c, pdraw->xDrawable,
+                                          target_msc_hi, target_msc_lo,
+                                          divisor_hi, divisor_lo,
+                                          remainder_hi, remainder_lo);
+       /* Immediately wait on the swapbuffers reply.  If we didn't, we'd have
+        * to do so some time before reusing a (non-pageflipped) backbuffer.
+        * Otherwise, the new rendering could get ahead of the X Server's
+        * dispatch of the swapbuffer and you'd display garbage.
+        *
+        * We use XSync() first to reap the invalidate events through the event
+        * filter, to ensure that the next drawing doesn't use an invalidated
+        * buffer.
+        */
+       XSync(pdraw->psc->dpy, False);
+       swap_buffers_reply =
+          xcb_dri2_swap_buffers_reply(c, swap_buffers_cookie, NULL);
+       ret = merge_counter(swap_buffers_reply->swap_hi,
+                           swap_buffers_reply->swap_lo);
+       free(swap_buffers_reply);
     }
 
     if (psc->show_fps) {