Squashed commit of the following:
[mesa.git] / src / glx / glx_pbuffer.c
index ad05d95ccb758c7fa494281cb068362533b5261d..6738252a31d724a072ca019c8d276ec509670be8 100644 (file)
@@ -187,7 +187,7 @@ determineTextureFormat(const int *attribs, int numAttribs)
    return 0;
 }
 
-static void
+static GLboolean
 CreateDRIDrawable(Display *dpy, struct glx_config *config,
                  XID drawable, XID glxdrawable,
                  const int *attrib_list, size_t num_attribs)
@@ -198,22 +198,24 @@ CreateDRIDrawable(Display *dpy, struct glx_config *config,
 
    psc = priv->screens[config->screen];
    if (psc->driScreen == NULL)
-      return;
+      return GL_TRUE;
 
    pdraw = psc->driScreen->createDrawable(psc, drawable,
                                          glxdrawable, config);
    if (pdraw == NULL) {
       fprintf(stderr, "failed to create drawable\n");
-      return;
+      return GL_FALSE;
    }
 
    if (__glxHashInsert(priv->drawHash, glxdrawable, pdraw)) {
       (*pdraw->destroyDrawable) (pdraw);
-      return; /* FIXME: Check what we're supposed to do here... */
+      return GL_FALSE;
    }
 
    pdraw->textureTarget = determineTextureTarget(attrib_list, num_attribs);
    pdraw->textureFormat = determineTextureFormat(attrib_list, num_attribs);
+
+   return GL_TRUE;
 }
 
 static void
@@ -234,11 +236,12 @@ DestroyDRIDrawable(Display *dpy, GLXDrawable drawable, int destroy_xdrawable)
 
 #else
 
-static void
+static GLboolean
 CreateDRIDrawable(Display *dpy, const struct glx_config * fbconfig,
                  XID drawable, XID glxdrawable,
                  const int *attrib_list, size_t num_attribs)
 {
+    return GL_FALSE;
 }
 
 static void
@@ -364,6 +367,27 @@ GetDrawableAttribute(Display * dpy, GLXDrawable drawable,
    return 0;
 }
 
+static void
+protocolDestroyDrawable(Display *dpy, GLXDrawable drawable, CARD32 glxCode)
+{
+   xGLXDestroyPbufferReq *req;
+   CARD8 opcode;
+
+   opcode = __glXSetupForCommand(dpy);
+   if (!opcode)
+      return;
+
+   LockDisplay(dpy);
+
+   GetReq(GLXDestroyPbuffer, req);
+   req->reqType = opcode;
+   req->glxCode = glxCode;
+   req->pbuffer = (GLXPbuffer) drawable;
+
+   UnlockDisplay(dpy);
+   SyncHandle();
+}
+
 /**
  * Create a non-pbuffer GLX drawable.
  */
@@ -372,9 +396,11 @@ 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;
+   GLXDrawable xid;
 
    i = 0;
    if (attrib_list) {
@@ -386,6 +412,10 @@ CreateDrawable(Display *dpy, struct glx_config *config,
    if (!opcode)
       return None;
 
+   glxDraw = Xmalloc(sizeof(*glxDraw));
+   if (!glxDraw)
+      return None;
+
    LockDisplay(dpy);
    GetReqExtra(GLXCreateWindow, 8 * i, req);
    data = (CARD32 *) (req + 1);
@@ -395,7 +425,7 @@ CreateDrawable(Display *dpy, struct glx_config *config,
    req->screen = config->screen;
    req->fbconfig = config->fbconfigID;
    req->window = drawable;
-   req->glxwindow = XAllocID(dpy);
+   req->glxwindow = xid = XAllocID(dpy);
    req->numAttribs = i;
 
    if (attrib_list)
@@ -404,9 +434,21 @@ CreateDrawable(Display *dpy, struct glx_config *config,
    UnlockDisplay(dpy);
    SyncHandle();
 
-   CreateDRIDrawable(dpy, config, drawable, req->glxwindow, attrib_list, i);
+   if (InitGLXDrawable(dpy, glxDraw, drawable, xid)) {
+      free(glxDraw);
+      return None;
+   }
 
-   return req->glxwindow;
+   if (!CreateDRIDrawable(dpy, config, drawable, xid, attrib_list, i)) {
+      if (glxCode == X_GLXCreatePixmap)
+         glxCode = X_GLXDestroyPixmap;
+      else
+         glxCode = X_GLXDestroyWindow;
+      protocolDestroyDrawable(dpy, xid, glxCode);
+      xid = None;
+   }
+
+   return xid;
 }
 
 
@@ -416,28 +458,13 @@ CreateDrawable(Display *dpy, struct glx_config *config,
 static void
 DestroyDrawable(Display * dpy, GLXDrawable drawable, CARD32 glxCode)
 {
-   xGLXDestroyPbufferReq *req;
-   CARD8 opcode;
-
    if ((dpy == NULL) || (drawable == 0)) {
       return;
    }
 
+   protocolDestroyDrawable(dpy, drawable, glxCode);
 
-   opcode = __glXSetupForCommand(dpy);
-   if (!opcode)
-      return;
-
-   LockDisplay(dpy);
-
-   GetReq(GLXDestroyPbuffer, req);
-   req->reqType = opcode;
-   req->glxCode = glxCode;
-   req->pbuffer = (GLXPbuffer) drawable;
-
-   UnlockDisplay(dpy);
-   SyncHandle();
-
+   DestroyGLXDrawable(dpy, drawable);
    DestroyDRIDrawable(dpy, drawable, GL_FALSE);
 
    return;
@@ -465,6 +492,7 @@ CreatePbuffer(Display * dpy, struct glx_config *config,
    CARD8 opcode;
    unsigned int i;
    Pixmap pixmap;
+   GLboolean glx_1_3 = GL_FALSE;
 
    i = 0;
    if (attrib_list) {
@@ -483,6 +511,8 @@ CreatePbuffer(Display * dpy, struct glx_config *config,
       xGLXCreatePbufferReq *req;
       unsigned int extra = (size_in_attribs) ? 0 : 2;
 
+      glx_1_3 = GL_TRUE;
+
       GetReqExtra(GLXCreatePbuffer, (8 * (i + extra)), req);
       data = (CARD32 *) (req + 1);
 
@@ -527,7 +557,12 @@ CreatePbuffer(Display * dpy, struct glx_config *config,
    pixmap = XCreatePixmap(dpy, RootWindow(dpy, config->screen),
                          width, height, config->rgbBits);
 
-   CreateDRIDrawable(dpy, config, pixmap, id, attrib_list, i);
+   if (!CreateDRIDrawable(dpy, config, pixmap, id, attrib_list, i)) {
+      CARD32 o = glx_1_3 ? X_GLXDestroyPbuffer : X_GLXvop_DestroyGLXPbufferSGIX;
+      XFreePixmap(dpy, pixmap);
+      protocolDestroyDrawable(dpy, id, o);
+      id = None;
+   }
 
    return id;
 }
@@ -834,7 +869,7 @@ glXCreatePixmap(Display * dpy, GLXFBConfig config, Pixmap pixmap,
    WARN_ONCE_GLX_1_3(dpy, __func__);
 
 #ifdef GLX_USE_APPLEGL
-   const struct glx_config *modes = (const __GLcontextModes *) config;
+   const struct glx_config *modes = (const struct glx_config *) config;
 
    if (apple_glx_pixmap_create(dpy, modes->screen, pixmap, modes))
       return None;