dri: Allow config options to be passed to the loader through extensions.
[mesa.git] / src / glx / glx_pbuffer.c
index 0e74e7ccd0e92fe4c773f26259c89eb2b8cd0756..183fbaaa5004d03b1ea271edfa5ef0ca710bd782 100644 (file)
 #ifdef GLX_USE_APPLEGL
 #include <pthread.h>
 #include "apple_glx_drawable.h"
-#include "glx_error.h"
 #endif
 
+#include "glx_error.h"
+
 #define WARN_ONCE_GLX_1_3(a, b) {              \
                static int warned=1;            \
                if(warned) {                    \
@@ -241,7 +242,7 @@ CreateDRIDrawable(Display *dpy, const struct glx_config * fbconfig,
                  XID drawable, XID glxdrawable,
                  const int *attrib_list, size_t num_attribs)
 {
-    return GL_FALSE;
+    return GL_TRUE;
 }
 
 static void
@@ -279,7 +280,16 @@ GetDrawableAttribute(Display * dpy, GLXDrawable drawable,
    unsigned int num_attributes;
    GLboolean use_glx_1_3;
 
-   if ((dpy == NULL) || (drawable == 0)) {
+   if (dpy == NULL)
+      return 0;
+
+   /* Page 38 (page 52 of the PDF) of glxencode1.3.pdf says:
+    *
+    *     "If drawable is not a valid GLX drawable, a GLXBadDrawable error is
+    *     generated."
+    */
+   if (drawable == 0) {
+      __glXSendError(dpy, GLXBadDrawable, 0, X_GLXGetDrawableAttributes, false);
       return 0;
    }
 
@@ -326,7 +336,7 @@ GetDrawableAttribute(Display * dpy, GLXDrawable drawable,
    length = reply.length;
    if (length) {
       num_attributes = (use_glx_1_3) ? reply.numAttribs : length / 2;
-      data = (CARD32 *) Xmalloc(length * sizeof(CARD32));
+      data = malloc(length * sizeof(CARD32));
       if (data == NULL) {
          /* Throw data on the floor */
          _XEatData(dpy, length);
@@ -357,7 +367,7 @@ GetDrawableAttribute(Display * dpy, GLXDrawable drawable,
          }
 #endif
 
-         Xfree(data);
+         free(data);
       }
    }
 
@@ -396,6 +406,7 @@ CreateDrawable(Display *dpy, struct glx_config *config,
                Drawable drawable, const int *attrib_list, CARD8 glxCode)
 {
    xGLXCreateWindowReq *req;
+   struct glx_drawable *glxDraw;
    CARD32 *data;
    unsigned int i;
    CARD8 opcode;
@@ -411,6 +422,10 @@ CreateDrawable(Display *dpy, struct glx_config *config,
    if (!opcode)
       return None;
 
+   glxDraw = malloc(sizeof(*glxDraw));
+   if (!glxDraw)
+      return None;
+
    LockDisplay(dpy);
    GetReqExtra(GLXCreateWindow, 8 * i, req);
    data = (CARD32 *) (req + 1);
@@ -429,6 +444,11 @@ CreateDrawable(Display *dpy, struct glx_config *config,
    UnlockDisplay(dpy);
    SyncHandle();
 
+   if (InitGLXDrawable(dpy, glxDraw, drawable, xid)) {
+      free(glxDraw);
+      return None;
+   }
+
    if (!CreateDRIDrawable(dpy, config, drawable, xid, attrib_list, i)) {
       if (glxCode == X_GLXCreatePixmap)
          glxCode = X_GLXDestroyPixmap;
@@ -454,6 +474,7 @@ DestroyDrawable(Display * dpy, GLXDrawable drawable, CARD32 glxCode)
 
    protocolDestroyDrawable(dpy, drawable, glxCode);
 
+   DestroyGLXDrawable(dpy, drawable);
    DestroyDRIDrawable(dpy, drawable, GL_FALSE);
 
    return;
@@ -896,7 +917,7 @@ glXCreateWindow(Display * dpy, GLXFBConfig config, Window win,
       return None;
    }
 
-   XFree(visinfo);
+   free(visinfo);
 
    return win;
 #else