glx: Don't refer to the request buffer outside of {L,Unl}ockDisplay
[mesa.git] / src / glx / glx_pbuffer.c
index 15bfb1591916e1cd0c51a7cd65027e190fb0c3f7..5c76c74a2c16f3a1a6434a7456c23117e315fba9 100644 (file)
@@ -77,16 +77,15 @@ warn_GLX_1_3(Display * dpy, const char *function_name)
  * \note
  * This function dynamically determines whether to use the SGIX_pbuffer
  * version of the protocol or the GLX 1.3 version of the protocol.
- *
- * \todo
- * This function needs to be modified to work with direct-rendering drivers.
  */
 static void
 ChangeDrawableAttribute(Display * dpy, GLXDrawable drawable,
                         const CARD32 * attribs, size_t num_attribs)
 {
    struct glx_display *priv = __glXInitialize(dpy);
+#ifdef GLX_DIRECT_RENDERING
    __GLXDRIdrawable *pdraw;
+#endif
    CARD32 *output;
    CARD8 opcode;
    int i;
@@ -95,8 +94,6 @@ ChangeDrawableAttribute(Display * dpy, GLXDrawable drawable,
       return;
    }
 
-   pdraw = GetGLXDRIDrawable(dpy, drawable);
-
    opcode = __glXSetupForCommand(dpy);
    if (!opcode)
       return;
@@ -106,7 +103,7 @@ ChangeDrawableAttribute(Display * dpy, GLXDrawable drawable,
    if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) {
       xGLXChangeDrawableAttributesReq *req;
 
-      GetReqExtra(GLXChangeDrawableAttributes, 8 + (8 * num_attribs), req);
+      GetReqExtra(GLXChangeDrawableAttributes, 8 * num_attribs, req);
       output = (CARD32 *) (req + 1);
 
       req->reqType = opcode;
@@ -117,7 +114,7 @@ ChangeDrawableAttribute(Display * dpy, GLXDrawable drawable,
    else {
       xGLXVendorPrivateWithReplyReq *vpreq;
 
-      GetReqExtra(GLXVendorPrivateWithReply, 4 + (8 * num_attribs), vpreq);
+      GetReqExtra(GLXVendorPrivateWithReply, 8 + (8 * num_attribs), vpreq);
       output = (CARD32 *) (vpreq + 1);
 
       vpreq->reqType = opcode;
@@ -125,7 +122,8 @@ ChangeDrawableAttribute(Display * dpy, GLXDrawable drawable,
       vpreq->vendorCode = X_GLXvop_ChangeDrawableAttributesSGIX;
 
       output[0] = (CARD32) drawable;
-      output++;
+      output[1] = num_attribs;
+      output += 2;
    }
 
    (void) memcpy(output, attribs, sizeof(CARD32) * 2 * num_attribs);
@@ -133,6 +131,12 @@ ChangeDrawableAttribute(Display * dpy, GLXDrawable drawable,
    UnlockDisplay(dpy);
    SyncHandle();
 
+#ifdef GLX_DIRECT_RENDERING
+   pdraw = GetGLXDRIDrawable(dpy, drawable);
+
+   if (!pdraw)
+      return;
+
    for (i = 0; i < num_attribs; i++) {
       switch(attribs[i * 2]) {
       case GLX_EVENT_MASK:
@@ -141,6 +145,7 @@ ChangeDrawableAttribute(Display * dpy, GLXDrawable drawable,
         break;
       }
    }
+#endif
 
    return;
 }
@@ -216,12 +221,14 @@ DestroyDRIDrawable(Display *dpy, GLXDrawable drawable, int destroy_xdrawable)
 {
    struct glx_display *const priv = __glXInitialize(dpy);
    __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
+   XID xid;
 
    if (pdraw != NULL) {
-      if (destroy_xdrawable)
-         XFreePixmap(pdraw->psc->dpy, pdraw->xDrawable);
+      xid = pdraw->xDrawable;
       (*pdraw->destroyDrawable) (pdraw);
       __glxHashDelete(priv->drawHash, drawable);
+      if (destroy_xdrawable)
+         XFreePixmap(priv->dpy, xid);
    }
 }
 
@@ -255,9 +262,6 @@ DestroyDRIDrawable(Display *dpy, GLXDrawable drawable, int destroy_xdrawable)
  * The number of attributes returned is likely to be small, probably less than
  * 10.  Given that, this routine should try to use an array on the stack to
  * capture the reply rather than always calling Xmalloc.
- *
- * \todo
- * This function needs to be modified to work with direct-rendering drivers.
  */
 static int
 GetDrawableAttribute(Display * dpy, GLXDrawable drawable,
@@ -291,7 +295,7 @@ GetDrawableAttribute(Display * dpy, GLXDrawable drawable,
    if (use_glx_1_3) {
       xGLXGetDrawableAttributesReq *req;
 
-      GetReqExtra(GLXGetDrawableAttributes, 4, req);
+      GetReq(GLXGetDrawableAttributes, req);
       req->reqType = opcode;
       req->glxCode = X_GLXGetDrawableAttributes;
       req->drawable = drawable;
@@ -362,9 +366,6 @@ GetDrawableAttribute(Display * dpy, GLXDrawable drawable,
 
 /**
  * Create a non-pbuffer GLX drawable.
- *
- * \todo
- * This function needs to be modified to work with direct-rendering drivers.
  */
 static GLXDrawable
 CreateDrawable(Display *dpy, struct glx_config *config,
@@ -374,6 +375,7 @@ CreateDrawable(Display *dpy, struct glx_config *config,
    CARD32 *data;
    unsigned int i;
    CARD8 opcode;
+   GLXDrawable xid;
 
    i = 0;
    if (attrib_list) {
@@ -394,7 +396,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)
@@ -403,9 +405,9 @@ CreateDrawable(Display *dpy, struct glx_config *config,
    UnlockDisplay(dpy);
    SyncHandle();
 
-   CreateDRIDrawable(dpy, config, drawable, req->glxwindow, attrib_list, i);
+   CreateDRIDrawable(dpy, config, drawable, xid, attrib_list, i);
 
-   return req->glxwindow;
+   return xid;
 }
 
 
@@ -429,7 +431,7 @@ DestroyDrawable(Display * dpy, GLXDrawable drawable, CARD32 glxCode)
 
    LockDisplay(dpy);
 
-   GetReqExtra(GLXDestroyPbuffer, 4, req);
+   GetReq(GLXDestroyPbuffer, req);
    req->reqType = opcode;
    req->glxCode = glxCode;
    req->pbuffer = (GLXPbuffer) drawable;
@@ -452,9 +454,6 @@ DestroyDrawable(Display * dpy, GLXDrawable drawable, CARD32 glxCode)
  * \note
  * This function dynamically determines whether to use the SGIX_pbuffer
  * version of the protocol or the GLX 1.3 version of the protocol.
- *
- * \todo
- * This function needs to be modified to work with direct-rendering drivers.
  */
 static GLXDrawable
 CreatePbuffer(Display * dpy, struct glx_config *config,