st/xorg: Use the correct DRI2BufferPtr struct on 1.6.4 servers
[mesa.git] / src / gallium / state_trackers / xorg / xorg_dri2.c
index 6431a0fe25452eff4cdacf6c8f197b11bb37e8fb..adc9531dbd3e38fdc005998e56e2ae2386841b54 100644 (file)
@@ -81,11 +81,14 @@ driDoCreateBuffer(DrawablePtr pDraw, DRI2BufferPtr buffer, unsigned int format)
     case DRI2BufferStencil:
 #if defined(DRI2INFOREC_VERSION) && DRI2INFOREC_VERSION > 2
     case DRI2BufferDepthStencil:
+#else
+    /* Works on old X servers because sanity checking is for the weak */
+    case 9:
+#endif
        if (exa_priv->depth_stencil_tex &&
            !pf_is_depth_stencil(exa_priv->depth_stencil_tex->format))
            exa_priv->depth_stencil_tex = NULL;
         /* Fall through */
-#endif
     case DRI2BufferDepth:
        if (exa_priv->depth_stencil_tex)
            pipe_texture_reference(&tex, exa_priv->depth_stencil_tex);
@@ -118,6 +121,7 @@ driDoCreateBuffer(DrawablePtr pDraw, DRI2BufferPtr buffer, unsigned int format)
     }
 
     if (!tex) {
+       exaMoveInPixmap(private->pPixmap);
        xorg_exa_set_shared_usage(private->pPixmap);
        pScreen->ModifyPixmapHeader(private->pPixmap, 0, 0, 0, 0, 0, NULL);
        tex = xorg_exa_get_texture(private->pPixmap);
@@ -133,6 +137,11 @@ driDoCreateBuffer(DrawablePtr pDraw, DRI2BufferPtr buffer, unsigned int format)
     buffer->cpp = 4;
     buffer->driverPrivate = private;
     buffer->flags = 0; /* not tiled */
+#if defined(DRI2INFOREC_VERSION) && DRI2INFOREC_VERSION == 2
+    ((DRI2Buffer2Ptr)buffer)->format = 0;
+#elif defined(DRI2INFOREC_VERSION) && DRI2INFOREC_VERSION >= 3
+    buffer->format = 0;
+#endif
     private->tex = tex;
 
     return TRUE;
@@ -153,12 +162,12 @@ driDoDestroyBuffer(DrawablePtr pDraw, DRI2BufferPtr buffer)
     (*pScreen->DestroyPixmap)(private->pPixmap);
 }
 
-#if defined(DRI2INFOREC_VERSION) && DRI2INFOREC_VERSION > 2
+#if defined(DRI2INFOREC_VERSION) && DRI2INFOREC_VERSION >= 2
 
-static DRI2BufferPtr
+static DRI2Buffer2Ptr
 driCreateBuffer(DrawablePtr pDraw, unsigned int attachment, unsigned int format)
 {
-    DRI2BufferPtr buffer;
+    DRI2Buffer2Ptr buffer;
     BufferPrivatePtr private;
 
     buffer = xcalloc(1, sizeof *buffer);
@@ -173,7 +182,8 @@ driCreateBuffer(DrawablePtr pDraw, unsigned int attachment, unsigned int format)
     buffer->attachment = attachment;
     buffer->driverPrivate = private;
 
-    if (driDoCreateBuffer(pDraw, buffer, format))
+    /* So far it is safe to downcast a DRI2Buffer2Ptr to DRI2BufferPtr */
+    if (driDoCreateBuffer(pDraw, (DRI2BufferPtr)buffer, format))
        return buffer;
 
     xfree(private);
@@ -183,15 +193,16 @@ fail:
 }
 
 static void
-driDestroyBuffer(DrawablePtr pDraw, DRI2BufferPtr buffer)
+driDestroyBuffer(DrawablePtr pDraw, DRI2Buffer2Ptr buffer)
 {
-    driDoDestroyBuffer(pDraw, buffer);
+    /* So far it is safe to downcast a DRI2Buffer2Ptr to DRI2BufferPtr */
+    driDoDestroyBuffer(pDraw, (DRI2BufferPtr)buffer);
 
     xfree(buffer->driverPrivate);
     xfree(buffer);
 }
 
-#else /* DRI2INFOREC_VERSION <= 2 */
+#else /* !defined(DRI2INFOREC_VERSION) || DRI2INFOREC_VERSION < 2 */
 
 static DRI2BufferPtr
 driCreateBuffers(DrawablePtr pDraw, unsigned int *attachments, int count)
@@ -241,7 +252,7 @@ driDestroyBuffers(DrawablePtr pDraw, DRI2BufferPtr buffers, int count)
     }
 }
 
-#endif /* DRI2INFOREC_VERSION */
+#endif /* defined(DRI2INFOREC_VERSION) && DRI2INFOREC_VERSION >= 2 */
 
 static void
 driCopyRegion(DrawablePtr pDraw, RegionPtr pRegion,
@@ -348,7 +359,7 @@ driScreenInit(ScreenPtr pScreen)
     dri2info.driverName = pScrn->driverName;
     dri2info.deviceName = "/dev/dri/card0"; /* FIXME */
 
-#if defined(DRI2INFOREC_VERSION) && DRI2INFOREC_VERSION > 2
+#if defined(DRI2INFOREC_VERSION) && DRI2INFOREC_VERSION >= 2
     dri2info.CreateBuffer = driCreateBuffer;
     dri2info.DestroyBuffer = driDestroyBuffer;
 #else