---
 src/glx/dri2_glx.c    |   99 +++++++++++++++++++++++++++++++++++++++++++++++--
 src/glx/glx_pbuffer.c |    8 ++--
 2 files changed, 98 insertions(+), 9 deletions(-)

diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c
index 7ce5775..d0f284d 100644
--- a/src/glx/dri2_glx.c
+++ b/src/glx/dri2_glx.c
@@ -50,6 +50,7 @@
 #include "xf86drm.h"
 #include "dri2.h"
 #include "dri_common.h"
+#include "assert.h"
 
 /* From xmlpool/options.h, user exposed so should be stable */
 #define DRI_CONF_VBLANK_NEVER 0
@@ -352,7 +353,7 @@ dri2DestroyDrawable(__GLXDRIdrawable *base)
     * knowing when the application is done with it.  The server will
     * destroy the DRI2 drawable when it destroys the X drawable or the
     * client exits anyway. */
-   if (pdraw->base.xDrawable != pdraw->base.drawable)
+   if (pdraw->base.xDrawable && pdraw->base.xDrawable != pdraw->base.drawable)
       DRI2DestroyDrawable(psc->base.dpy, pdraw->base.xDrawable);
 
    free(pdraw);
@@ -397,7 +398,8 @@ dri2CreateDrawable(struct glx_screen *base, XID xDrawable,
       break;
    }
 
-   DRI2CreateDrawable(psc->base.dpy, xDrawable);
+   if (xDrawable)
+       DRI2CreateDrawable(psc->base.dpy, xDrawable);
 
    dpyPriv = __glXInitialize(psc->base.dpy);
    pdp = (struct dri2_display *)dpyPriv->dri2Display;;
@@ -412,7 +414,7 @@ dri2CreateDrawable(struct glx_screen *base, XID xDrawable,
       return NULL;
    }
 
-   if (__glxHashInsert(pdp->dri2Hash, xDrawable, pdraw)) {
+   if (xDrawable && __glxHashInsert(pdp->dri2Hash, xDrawable, pdraw)) {
       (*psc->core->destroyDrawable) (pdraw->driDrawable);
       DRI2DestroyDrawable(psc->base.dpy, xDrawable);
       free(pdraw);
@@ -877,6 +879,83 @@ dri2GetBuffers(__DRIdrawable * driDrawable,
    return pdraw->buffers;
 }
 
+/* get_aux_bo() and dri2PbufferGetBuffers() come from
+ * src/egl/drivers/dri2/platform_drm.c, 
+ * Mentioned functions work with a struct dri2_drawable instead
+ * of a struct dri2_egl_surface, but the general idea 
+ * is the same.
+ */
+
+static int
+get_aux_bo(struct dri2_drawable *pdraw,
+           unsigned int attachment, 
+           unsigned int format, 
+           __DRIbuffer *buffer) {
+    __DRIbuffer *b = NULL;
+    struct dri2_screen *psc = (struct dri2_screen *) pdraw->base.psc;
+
+    b = psc->dri2->allocateBuffer(psc->driScreen,
+                                attachment,
+                                format,
+                                pdraw->width,
+                                pdraw->height);
+
+   if (b == NULL)
+      return -1;
+
+   memcpy(buffer, b, sizeof *buffer);
+   return 0;
+}
+
+
+static __DRIbuffer *
+dri2PbufferGetBuffers(__DRIdrawable * driDrawable,
+                      int *width, 
+                      int *height,
+                      unsigned int *attachments, 
+                      int count,
+                      int *out_count, 
+                      void *loaderPrivate) {
+   struct dri2_drawable *pdraw = loaderPrivate;
+   int i, j;
+
+   /* ask for size of buffers */
+   glXQueryGLXPbufferSGIX(pdraw->base.psc->dpy,
+                                                 pdraw->base.drawable,
+                                                 GLX_WIDTH,
+                                                 (unsigned int*)&pdraw->width);
+
+   glXQueryGLXPbufferSGIX(pdraw->base.psc->dpy,
+                                                 pdraw->base.drawable,
+                                                 GLX_HEIGHT,
+                                                 (unsigned 
int*)&pdraw->height);
+
+   if ((!pdraw->width) || (!pdraw->height))
+          return NULL;
+
+   pdraw->bufferCount = 0;
+   for (i = 0, j = 0; i < 2 * count; i += 2, j++) {
+        assert(attachments[i] < __DRI_BUFFER_COUNT);
+        assert(pdraw->bufferCount < 5);
+
+        if (get_aux_bo(pdraw, attachments[i], attachments[i + 1],
+                &pdraw->buffers[j]) < 0) {
+            ErrorMessageF("failed to allocate aux buffer");
+            return NULL;
+        }
+   }
+
+   *out_count = j;
+   if (j == 0)
+      return NULL;
+
+   *width = pdraw->width;
+   *height = pdraw->height;
+
+   return pdraw->buffers;
+}
+
+
 static __DRIbuffer *
 dri2GetBuffersWithFormat(__DRIdrawable * driDrawable,
                          int *width, int *height,
@@ -886,6 +965,17 @@ dri2GetBuffersWithFormat(__DRIdrawable * driDrawable,
    struct dri2_drawable *pdraw = loaderPrivate;
    DRI2Buffer *buffers;
 
+   /* If xDrawable is None we're asked for buffers for a pbuffer. */
+   if (pdraw->base.xDrawable == None)
+      return dri2PbufferGetBuffers(driDrawable, 
+                                   width, 
+                                   height,
+                                   attachments, 
+                                   count, 
+                                   out_count,
+                                   loaderPrivate);
+
+
    buffers = DRI2GetBuffersWithFormat(pdraw->base.psc->dpy,
                                       pdraw->base.xDrawable,
                                       width, height, attachments,
@@ -927,7 +1017,8 @@ dri2SetSwapInterval(__GLXDRIdrawable *pdraw, int interval)
       break;
    }
 
-   xcb_dri2_swap_interval(c, priv->base.xDrawable, interval);
+   if (priv->base.xDrawable)
+          xcb_dri2_swap_interval(c, priv->base.xDrawable, interval);
    priv->swap_interval = interval;
 
    return 0;
diff --git a/src/glx/glx_pbuffer.c b/src/glx/glx_pbuffer.c
index f11305a..9aa1217 100644
--- a/src/glx/glx_pbuffer.c
+++ b/src/glx/glx_pbuffer.c
@@ -491,7 +491,6 @@ CreatePbuffer(Display * dpy, struct glx_config *config,
    CARD32 *data;
    CARD8 opcode;
    unsigned int i;
-   Pixmap pixmap;
    GLboolean glx_1_3 = GL_FALSE;
 
    i = 0;
@@ -554,12 +553,11 @@ CreatePbuffer(Display * dpy, struct glx_config *config,
    UnlockDisplay(dpy);
    SyncHandle();
 
-   pixmap = XCreatePixmap(dpy, RootWindow(dpy, config->screen),
-                         width, height, config->rgbBits);
+   /* Passing None as the X drawable ID indicates that we're createing a
+    * pbuffer. */
 
-   if (!CreateDRIDrawable(dpy, config, pixmap, id, attrib_list, i)) {
+   if (!CreateDRIDrawable(dpy, config, None, id, attrib_list, i)) {
       CARD32 o = glx_1_3 ? X_GLXDestroyPbuffer : 
X_GLXvop_DestroyGLXPbufferSGIX;
-      XFreePixmap(dpy, pixmap);
       protocolDestroyDrawable(dpy, id, o);
       id = None;
    }
-- 
1.7.10.4

--------------------------------------------------------------------

Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial 
Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | 
Kapital zakladowy 200.000 PLN.

Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i 
moze zawierac informacje poufne. W razie przypadkowego otrzymania tej 
wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; 
jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione.
This e-mail and any attachments may contain confidential material for the sole 
use of the intended recipient(s). If you are not the intended recipient, please 
contact the sender and delete all copies; any review or distribution by others 
is strictly prohibited.

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to