[PATCH] glx: Track GLX 1.3 style GLX drawables under their X drawa=

=3D?UTF-8?q?Kristian=3D20H=3DC3=3DB8gsberg?=3D krh at bitplanet.net
Thu Apr 15 09:07:16 PDT 2010


ble ID as well
MIME-Version: 1.0
Content-Type: text/plain; charset=3DUTF-8
Content-Transfer-Encoding: 8bit

This ensures that the DrawableGone callback gets called as necessary
when the X drawable goes away.  Otherwise, using a GLX drawable
(say, glXSwapBuffers) in indirect mode after the X drawable has been
destroyed will crash the server.

Signed-off-by: Kristian H=C3=B8gsberg <krh at bitplanet.net>
---
 glx/glxcmds.c |   12 ++++++++++++
 glx/glxext.c  |   11 +++++++++++
 2 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index 77afbf4..04c6d40 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -161,7 +161,11 @@ validGlxDrawable(ClientPtr client, XID id, int type, i=
nt access_mode,
 	return FALSE;
     }
=20
+    /* If the ID of the glx drawable we looked up doesn't match the id
+     * we looked for, it's because we looked it up under the X
+     * drawable ID (see DoCreateGLXDrawable). */
     if (rc =3D=3D BadValue ||
+	(*drawable)->drawId !=3D id ||
 	(type !=3D GLX_DRAWABLE_ANY && type !=3D (*drawable)->type)) {
 	client->errorValue =3D id;
 	switch (type) {
@@ -1128,6 +1132,14 @@ DoCreateGLXDrawable(ClientPtr client, __GLXscreen *p=
GlxScreen, __GLXconfig *conf
 	return BadAlloc;
     }
=20
+    /* Add the glx drawable under the XID of the underlying X drawable
+     * too.  That way we'll get a callback in DrawableGone and can
+     * clean up properly when the drawable is destroyed. */
+    if (!AddResource(pDraw->id, __glXDrawableRes, pGlxDraw)) {
+	pGlxDraw->destroy (pGlxDraw);
+	return BadAlloc;
+    }
+
     return Success;
 }
=20
diff --git a/glx/glxext.c b/glx/glxext.c
index 59bcfbe..89e58b0 100644
--- a/glx/glxext.c
+++ b/glx/glxext.c
@@ -126,6 +126,17 @@ static Bool DrawableGone(__GLXdrawable *glxPriv, XID x=
id)
 {
     __GLXcontext *c;
=20
+    /* If this drawable was created using glx 1.3 drawable
+     * 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 !=3D glxPriv->pDraw->id) {
+	if (xid =3D=3D glxPriv->drawId)
+	    FreeResourceByType(glxPriv->pDraw->id, __glXDrawableRes, TRUE);
+	else
+	    FreeResourceByType(glxPriv->drawId, __glXDrawableRes, TRUE);
+    }
+
     for (c =3D glxAllContexts; c; c =3D c->next) {
 	if (c->isCurrent && (c->drawPriv =3D=3D glxPriv || c->readPriv =3D=3D glx=
Priv)) {
 	    int i;
--=20
1.7.0.1



More information about the xorg-devel mailing list