[PATCH v3 11/11] glx: Cleanup DRI2Drawable

Pauli ext-pauli.nieminen at nokia.com
Wed Feb 16 02:21:45 PST 2011


From: Pauli Nieminen <ext-pauli.nieminen at nokia.com>

glx should cleanup DRI2Drawable when GLXDrawable is destroyed.

v3:
* Fix resource destruction order between GLX and DRI2 when client
  disconnects.

Signed-off-by: Pauli Nieminen <ext-pauli.nieminen at nokia.com>
---
 glx/glxdri2.c          |   12 ++++++++++++
 hw/xfree86/dri2/dri2.c |   18 ++++++++++++++++++
 hw/xfree86/dri2/dri2.h |   18 ++++++++++++++++++
 3 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index 027615a..37b522a 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -89,6 +89,8 @@ struct __GLXDRIdrawable {
     __DRIdrawable	*driDrawable;
     __GLXDRIscreen	*screen;
     DRI2DrawablePtr     pDRI2Draw;
+    XID                 id;
+    ClientPtr           client;
 
     /* Dimensions as last reported by DRI2GetBuffers. */
     int width;
@@ -102,6 +104,12 @@ __glXDRIdrawableDestroy(__GLXdrawable *drawable)
 {
     __GLXDRIdrawable *private = (__GLXDRIdrawable *) drawable;
     const __DRIcoreExtension *core = private->screen->core;
+    DRI2DrawablePtr pTmp;
+
+    pTmp = DRI2DrawableUnref(private->pDRI2Draw);
+
+    if (pTmp)
+	DRI2DestroyDrawable(private->client, pTmp, private->id);
     
     (*core->destroyDrawable)(private->driDrawable);
 
@@ -479,6 +487,10 @@ __glXDRIscreenCreateDrawable(ClientPtr client,
     }
 
     private->pDRI2Draw = DRI2GetDrawable(pDraw);
+    private->id        = drawId;
+    private->client    = client;
+
+    DRI2DrawableRef(private->pDRI2Draw);
 
     private->driDrawable =
 	(*driScreen->dri2->createNewDrawable)(driScreen->driScreen,
diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
index 4b31447..4085ccb 100644
--- a/hw/xfree86/dri2/dri2.c
+++ b/hw/xfree86/dri2/dri2.c
@@ -426,6 +426,24 @@ static int DRI2DrawableGone(pointer p, XID id)
     return Success;
 }
 
+void
+DRI2DrawableRef(DRI2DrawablePtr pPriv)
+{
+    pPriv->refcnt++;
+}
+
+DRI2DrawablePtr
+DRI2DrawableUnref(DRI2DrawablePtr pPriv)
+{
+    pPriv->refcnt--;
+
+    if (pPriv->refcnt > 0)
+	return pPriv;
+
+    DRI2DrawableGone(pPriv, 0);
+    return NULL;
+}
+
 static int
 find_attachment(DRI2DrawablePtr pPriv, unsigned attachment)
 {
diff --git a/hw/xfree86/dri2/dri2.h b/hw/xfree86/dri2/dri2.h
index 7b49e7f..bdd4d04 100644
--- a/hw/xfree86/dri2/dri2.h
+++ b/hw/xfree86/dri2/dri2.h
@@ -350,6 +350,24 @@ extern _X_EXPORT DRI2DrawablePtr DRI2GetDrawable(DrawablePtr pDraw);
  */
 extern _X_EXPORT unsigned char DRI2DrawableGetType(DRI2DrawablePtr pPriv);
 
+/**
+ * Notify DRI2 that there is long living reference to the drawable.
+ *
+ * If someone needs long living reference to DRI2 drawable that may out live
+ * the DRI2 client resource the caller has to notify DRI2 about the reference.
+ *
+ * \param pPriv DRI2 private drawable
+ */
+extern _X_EXPORT void DRI2DrawableRef(DRI2DrawablePtr pPriv);
+
+/**
+ * Free long living reference to DRI2Drawable
+ *
+ * \param pPriv DRI2 private drawable
+ * \return pointer DRI2Drawable or NULL if DRI2Drawable was freed
+ */
+extern _X_EXPORT DRI2DrawablePtr DRI2DrawableUnref(DRI2DrawablePtr pPriv);
+
 extern _X_EXPORT int DRI2LookupDrawableComplex(ClientPtr client,
                                                XID id,
                                                DRI2DrawablePtr *pPriv);
-- 
1.7.0.4



More information about the xorg-devel mailing list