libGL: Pull the drawable hash back out in the generic code.
authorKristian Høgsberg <krh@redhat.com>
Wed, 12 Mar 2008 06:18:12 +0000 (02:18 -0400)
committerKristian Høgsberg <krh@redhat.com>
Wed, 12 Mar 2008 06:18:12 +0000 (02:18 -0400)
This will be shared between dri and dri2 code.

src/glx/x11/dri_glx.c
src/glx/x11/glxclient.h
src/glx/x11/glxcmds.c
src/glx/x11/glxext.c

index a6581465bc20c3479c40148e424d45e990bc8d1d..08e419c1efb1ea825761a39a48447881c528b1e9 100644 (file)
@@ -742,6 +742,14 @@ static __GLXDRIcontext *driCreateContext(__GLXscreenConfigs *psc,
     return NULL;
 }
 
+static void driDestroyDrawable(__GLXDRIdrawable *pdraw)
+{
+    __GLXscreenConfigs *psc = pdraw->psc;
+
+    (*pdraw->driDrawable.destroyDrawable)(&pdraw->driDrawable);
+    XF86DRIDestroyDrawable(psc->dpy, psc->scr, pdraw->drawable);
+    Xfree(pdraw);
+}
 
 static __GLXDRIdrawable *driCreateDrawable(__GLXscreenConfigs *psc,
                                           GLXDrawable drawable,
@@ -777,12 +785,7 @@ static __GLXDRIdrawable *driCreateDrawable(__GLXscreenConfigs *psc,
        return NULL;
     }
 
-    if (__glxHashInsert(psc->drawHash, drawable, pdraw)) {
-       (*pdraw->driDrawable.destroyDrawable)(&pdraw->driDrawable);
-       XF86DRIDestroyDrawable(psc->dpy, psc->scr, drawable);
-       Xfree(pdraw);
-       return NULL;
-    }
+    pdraw->destroyDrawable = driDestroyDrawable;
 
     return pdraw;
 }
@@ -793,8 +796,6 @@ static void driDestroyScreen(__GLXscreenConfigs *psc)
     if (psc->__driScreen.private)
        (*psc->__driScreen.destroyScreen)(&psc->__driScreen);
     psc->__driScreen.private = NULL;
-    if (psc->drawHash)
-       __glxHashDestroy(psc->drawHash);
     if (psc->driver)
        dlclose(psc->driver);
 }
@@ -810,11 +811,6 @@ static __GLXDRIscreen *driCreateScreen(__GLXscreenConfigs *psc, int screen,
     if (psp == NULL)
        return NULL;
 
-    /* Create drawable hash */
-    psc->drawHash = __glxHashCreate();
-    if ( psc->drawHash == NULL )
-       return NULL;
-
     /* Initialize per screen dynamic client GLX extensions */
     psc->ext_list_first_time = GL_TRUE;
 
index 259add759587fb178bdeb937a2719831bc642079..730caf73024b1dccb551b5e494600c9772f841b4 100644 (file)
@@ -132,6 +132,8 @@ struct __GLXDRIcontextRec {
 };
 
 struct __GLXDRIdrawableRec {
+    void (*destroyDrawable)(__GLXDRIdrawable *drawable);
+
     XID drawable;
     __GLXscreenConfigs *psc;
     __DRIdrawable driDrawable;
index 1437ea54425ba03a4db4a4ed3435fd2522be790b..adf53116745aedc1b8ea7ed5bc239ff7aad063b4 100644 (file)
@@ -99,10 +99,8 @@ static void GarbageCollectDRIDrawables(Display *dpy, __GLXscreenConfigs *sc)
            if (!windowExistsFlag) {
                /* Destroy the local drawable data, if the drawable no
                   longer exists in the Xserver */
-               (*pdraw->driDrawable.destroyDrawable)(&pdraw->driDrawable);
-               XF86DRIDestroyDrawable(dpy, sc->scr, draw);
+               (*pdraw->destroyDrawable)(pdraw);
                 __glxHashDelete(sc->drawHash, draw);
-               Xfree(pdraw);
            }
        } while (__glxHashNext(sc->drawHash, &draw, (void *)&pdraw) == 1);
     }
index 077398fe33f55a5d19181cde8a1e70814c393c1e..1d9be2974145ef0ee406f02cf07820360d52751f 100644 (file)
@@ -350,6 +350,8 @@ static void FreeScreenConfigs(__GLXdisplayPrivate *priv)
 #ifdef GLX_DIRECT_RENDERING
        if (psc->driScreen)
            psc->driScreen->destroyScreen(psc);
+       if (psc->drawHash)
+           __glxHashDestroy(psc->drawHash);
 #endif
     }
     XFree((char*) priv->screenConfigs);
@@ -772,8 +774,15 @@ static Bool AllocAndFetchScreenConfigs(Display *dpy, __GLXdisplayPrivate *priv)
        psc->scr = i;
        psc->dpy = dpy;
 #ifdef GLX_DIRECT_RENDERING
-       if (priv->driDisplay)
+       if (priv->driDisplay) {
+           /* Create drawable hash */
+           psc->drawHash = __glxHashCreate();
+           if (psc->drawHash == NULL)
+               continue;
            psc->driScreen = (*priv->driDisplay->createScreen)(psc, i, priv);
+           if (psc->driScreen == NULL)
+               __glxHashDestroy(psc->drawHash);
+       }
 #endif
     }
     SyncHandle();
@@ -1192,7 +1201,13 @@ FetchDRIDrawable(Display *dpy, GLXDrawable drawable, GLXContext gc)
     if (__glxHashLookup(psc->drawHash, drawable, (void *) &pdraw) == 0)
        return pdraw;
 
-    return psc->driScreen->createDrawable(psc, drawable, gc);
+    pdraw = psc->driScreen->createDrawable(psc, drawable, gc);
+    if (__glxHashInsert(psc->drawHash, drawable, pdraw)) {
+       (*pdraw->destroyDrawable)(pdraw);
+       return NULL;
+    }
+
+    return pdraw;
 }
 #endif /* GLX_DIRECT_RENDERING */