@@ -529,6 +529,7 @@ __glXGetDrawable(__GLXcontext *glxc, GLXDrawable drawId, ClientPtr client,
*error = BadAlloc;
return NULL;
}
+ pGlxDraw->refcnt++;
return pGlxDraw;
}
@@ -1099,8 +1100,10 @@ __glXDrawableInit(__GLXdrawable *drawable,
drawable->pDraw = pDraw;
drawable->type = type;
drawable->drawId = drawId;
+ drawable->otherId = 0;
drawable->config = config;
drawable->eventMask = 0;
+ drawable->refcnt = 0;
return GL_TRUE;
}
@@ -1130,6 +1133,7 @@ DoCreateGLXDrawable(ClientPtr client, __GLXscreen *pGlxScreen,
pGlxDraw->destroy (pGlxDraw);
return BadAlloc;
}
+ pGlxDraw->refcnt++;
/* Add the glx drawable under the XID of the underlying X drawable
* too. That way we'll get a callback in DrawableGone and can
@@ -1139,6 +1143,8 @@ DoCreateGLXDrawable(ClientPtr client, __GLXscreen *pGlxScreen,
pGlxDraw->destroy (pGlxDraw);
return BadAlloc;
}
+ pGlxDraw->refcnt++;
+ pGlxDraw->otherId = pDraw->id;
return Success;
}
@@ -51,8 +51,11 @@ struct __GLXdrawable {
void (*waitX)(__GLXdrawable *);
void (*waitGL)(__GLXdrawable *);
+ int refcnt; /* number of resources handles referencing this */
+
DrawablePtr pDraw;
XID drawId;
+ XID otherId; /* for glx1.3 we need to track the original Drawable as well */
/*
** Either GLX_DRAWABLE_PIXMAP, GLX_DRAWABLE_WINDOW or
@@ -128,13 +128,18 @@ static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
* constructors, we added it as a glx drawable resource under both
* its glx drawable ID and it X drawable ID. Remove the other
* resource now so we don't a callback for freed memory. */
- if (glxPriv->drawId != glxPriv->pDraw->id) {
- if (xid == glxPriv->drawId)
- FreeResourceByType(glxPriv->pDraw->id, __glXDrawableRes, TRUE);
- else
- FreeResourceByType(glxPriv->drawId, __glXDrawableRes, TRUE);
+ if (glxPriv->otherId) {
+ XID other = glxPriv->otherId;
+ glxPriv->otherId = 0;
+ if (xid == other)
+ FreeResourceByType(glxPriv->drawId, __glXDrawableRes, TRUE);
+ else
+ FreeResourceByType(other, __glXDrawableRes, TRUE);
}
+ if (--glxPriv->refcnt)
+ return TRUE;
+
for (c = glxAllContexts; c; c = next) {
next = c->next;
if (c->isCurrent && (c->drawPriv == glxPriv || c->readPriv == glxPriv)) {