DRI2: add SwapBuffers support
authorJesse Barnes <jbarnes@virtuousgeek.org>
Fri, 17 Jul 2009 07:30:29 +0000 (03:30 -0400)
committerJesse Barnes <jbarnes@virtuousgeek.org>
Fri, 8 Jan 2010 17:29:50 +0000 (12:29 -0500)
Support the new DRI2 protocol request, DRI2SwapBuffers, in both direct
and indirect rendering context.  This request allows the display server
to optimize back->front swaps (e.g. through page flipping) and allows us
to more easily support other GLX features like swap interval and the OML
sync extension in DRI2.

Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
configure.ac
include/GL/internal/dri_interface.h
src/glx/x11/dri2.c
src/glx/x11/dri2.h
src/glx/x11/dri2_glx.c
src/mesa/drivers/dri/common/dri_util.c
src/mesa/drivers/dri/common/dri_util.h

index b2a969bc8c9477e0500a6f6eeb2f1c7ab3785891..fd300504bf76e87bd28bffdd5b844fc86dc6e588 100644 (file)
@@ -20,7 +20,7 @@ AC_CANONICAL_HOST
 dnl Versions for external dependencies
 LIBDRM_REQUIRED=2.4.15
 LIBDRM_RADEON_REQUIRED=2.4.17
-DRI2PROTO_REQUIRED=1.99.3
+DRI2PROTO_REQUIRED=2.2
 
 dnl Check for progs
 AC_PROG_CPP
index 910c9166b5ef0757eb192a615c81ebf3c273fd38..ec6238f873420401741a3544c70215ceaca55768 100644 (file)
@@ -262,10 +262,22 @@ struct __DRItexBufferExtensionRec {
  * Used by drivers that implement DRI2
  */
 #define __DRI2_FLUSH "DRI2_Flush"
-#define __DRI2_FLUSH_VERSION 1
+#define __DRI2_FLUSH_VERSION 2
 struct __DRI2flushExtensionRec {
     __DRIextension base;
     void (*flush)(__DRIdrawable *drawable);
+
+    /**
+     * Flush all rendering queue in the driver to the drm and
+     * invalidate all buffers.  The driver will call out to
+     * getBuffers/getBuffersWithFormat before it starts rendering
+     * again.
+     *
+     * \param drawable the drawable to flush and invalidate
+     *
+     * \since 2
+     */
+    void (*flushInvalidate)(__DRIdrawable *drawable);
 };
 
 
index dad04470a00a52321707490efea5df91792f5831..a0f8901d42db634422694d8303425b6b844261f7 100644 (file)
@@ -380,4 +380,20 @@ DRI2CopyRegion(Display * dpy, XID drawable, XserverRegion region,
    SyncHandle();
 }
 
+void DRI2SwapBuffers(Display *dpy, XID drawable)
+{
+    XExtDisplayInfo *info = DRI2FindDisplay(dpy);
+    xDRI2SwapBuffersReq *req;
+
+    XextSimpleCheckExtension (dpy, info, dri2ExtensionName);
+
+    LockDisplay(dpy);
+    GetReq(DRI2SwapBuffers, req);
+    req->reqType = info->codes->major_opcode;
+    req->dri2ReqType = X_DRI2SwapBuffers;
+    req->drawable = drawable;
+    UnlockDisplay(dpy);
+    SyncHandle();
+}
+
 #endif /* GLX_DIRECT_RENDERING */
index a6fe66e136dd8ca268fad5c57408b1dc127bdccf..ba6eff5e4f72621bfa66b605f901d9192af2a4d9 100644 (file)
@@ -85,4 +85,7 @@ DRI2CopyRegion(Display * dpy, XID drawable,
                XserverRegion region,
                CARD32 dest, CARD32 src);
 
+extern void
+DRI2SwapBuffers(Display *dpy, XID drawable);
+
 #endif
index 89efe3ab292ebdf5e9ec5e3011346037cb8d3007..114cad2ae7da23019293e9c621c80077504e09c4 100644 (file)
@@ -35,6 +35,7 @@
 #include <X11/Xlib.h>
 #include <X11/extensions/Xfixes.h>
 #include <X11/extensions/Xdamage.h>
+#include "glapi.h"
 #include "glxclient.h"
 #include "glcontextmodes.h"
 #include "xf86dri.h"
@@ -64,6 +65,7 @@ struct __GLXDRIdisplayPrivateRec
    int driMajor;
    int driMinor;
    int driPatch;
+   int swapAvailable;
 };
 
 struct __GLXDRIcontextPrivateRec
@@ -240,7 +242,7 @@ dri2SwapBuffers(__GLXDRIdrawable * pdraw)
 }
 
 static void
-dri2WaitX(__GLXDRIdrawable * pdraw)
+dri2WaitX(__GLXDRIdrawable *pdraw)
 {
    __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw;
    XRectangle xrect;
@@ -342,6 +344,31 @@ process_buffers(__GLXDRIdrawablePrivate * pdraw, DRI2Buffer * buffers,
 
 }
 
+static void dri2SwapBuffers(__GLXDRIdrawable *pdraw)
+{
+    __GLXDRIdrawablePrivate *priv = (__GLXDRIdrawablePrivate *) pdraw;
+    __GLXdisplayPrivate *dpyPriv = __glXInitialize(priv->base.psc->dpy);
+    __GLXDRIdisplayPrivate *pdp =
+       (__GLXDRIdisplayPrivate *)dpyPriv->dri2Display;
+    __GLXscreenConfigs *psc = pdraw->psc;
+
+#ifdef __DRI2_FLUSH
+    if (pdraw->psc->f)
+       (*pdraw->psc->f->flush)(pdraw->driDrawable);
+#endif
+
+    /* Old servers can't handle swapbuffers */
+    if (!pdp->swapAvailable)
+       return dri2CopySubBuffer(pdraw, 0, 0, priv->width, priv->height);
+
+    DRI2SwapBuffers(pdraw->psc->dpy, pdraw->drawable);
+
+#if __DRI2_FLUSH_VERSION >= 2
+    if (pdraw->psc->f)
+       (*pdraw->psc->f->flushInvalidate)(pdraw->driDrawable);
+#endif
+}
+
 static __DRIbuffer *
 dri2GetBuffers(__DRIdrawable * driDrawable,
                int *width, int *height,
@@ -559,6 +586,9 @@ dri2CreateDisplay(Display * dpy)
    }
 
    pdp->driPatch = 0;
+   pdp->swapAvailable = 0;
+   if (pdp->driMinor >= 2)
+      pdp->swapAvailable = 1;
 
    pdp->base.destroyDisplay = dri2DestroyDisplay;
    pdp->base.createScreen = dri2CreateScreen;
index 547f18a009e324a0a8702bff709d7877e90b801d..cd271ede091d71c163f2a8e494b08e2fa0f7be42 100644 (file)
@@ -454,6 +454,7 @@ driCreateNewDrawable(__DRIscreen *psp, const __DRIconfig *config,
 
     pdp->driScreenPriv = psp;
     pdp->driContextPriv = &psp->dummyContextPriv;
+    pdp->validBuffers = GL_FALSE;
 
     if (!(*psp->DriverAPI.CreateBuffer)(psp, pdp, &config->modes,
                                        renderType == GLX_PIXMAP_BIT)) {
index c95a5c8299a11c672527137bea9f78b4bbea3cf6..c3046d6b186a181fb7f7ee61a2e3a5887ea546b9 100644 (file)
@@ -380,6 +380,8 @@ struct __DRIdrawableRec {
      * GLX_MESA_swap_control.
      */
     unsigned int swap_interval;
+
+    GLboolean validBuffers;
 };
 
 /**