Make sure DRI drawables are cleaned up when client dies.

The previous scheme didn't work when the client didn't create the core drawable,
e.g. the root or composite overlay window. Use refcounting via special client
resources to fix that.
This commit is contained in:
Michel Dänzer 2007-07-10 09:02:08 +02:00
parent 5957aa6fdc
commit 4abd00dab7
7 changed files with 129 additions and 61 deletions

View File

@ -758,9 +758,16 @@ static __DRIscreen *findScreen(__DRInativeDisplay *dpy, int scrn)
static GLboolean windowExists(__DRInativeDisplay *dpy, __DRIid draw) static GLboolean windowExists(__DRInativeDisplay *dpy, __DRIid draw)
{ {
WindowPtr pWin = (WindowPtr) LookupIDByType(draw, RT_WINDOW); DrawablePtr pDrawable = (DrawablePtr) LookupIDByType(draw, RT_WINDOW);
int unused;
drm_clip_rect_t *pRects;
return pWin == NULL ? GL_FALSE : GL_TRUE; return pDrawable ? DRIGetDrawableInfo(pDrawable->pScreen, pDrawable,
(unsigned*)&unused, (unsigned*)&unused,
&unused, &unused, &unused, &unused,
&unused, &pRects, &unused, &unused,
&unused, &pRects)
: GL_FALSE;
} }
static GLboolean createContext(__DRInativeDisplay *dpy, int screen, static GLboolean createContext(__DRInativeDisplay *dpy, int screen,
@ -815,10 +822,8 @@ createDrawable(__DRInativeDisplay *dpy, int screen,
return GL_FALSE; return GL_FALSE;
__glXDRIenterServer(GL_FALSE); __glXDRIenterServer(GL_FALSE);
retval = DRICreateDrawable(screenInfo.screens[screen], retval = DRICreateDrawable(screenInfo.screens[screen], __pGlxClient,
drawable, pDrawable, hHWDrawable);
pDrawable,
hHWDrawable);
__glXDRIleaveServer(GL_FALSE); __glXDRIleaveServer(GL_FALSE);
return retval; return retval;
} }
@ -834,9 +839,8 @@ destroyDrawable(__DRInativeDisplay *dpy, int screen, __DRIid drawable)
return GL_FALSE; return GL_FALSE;
__glXDRIenterServer(GL_FALSE); __glXDRIenterServer(GL_FALSE);
retval = DRIDestroyDrawable(screenInfo.screens[screen], retval = DRIDestroyDrawable(screenInfo.screens[screen], __pGlxClient,
drawable, pDrawable);
pDrawable);
__glXDRIleaveServer(GL_FALSE); __glXDRIleaveServer(GL_FALSE);
return retval; return retval;
} }
@ -927,7 +931,7 @@ getDrawableInfo(__DRInativeDisplay *dpy, int screen,
*ppBackClipRects = NULL; *ppBackClipRects = NULL;
} }
return GL_TRUE; return retval;
} }
static int static int

View File

@ -61,6 +61,11 @@ xGLXSingleReply __glXReply;
*/ */
static __GLXclientState *__glXClients[MAXCLIENTS + 1]; static __GLXclientState *__glXClients[MAXCLIENTS + 1];
/*
** Client that called into GLX dispatch.
*/
ClientPtr __pGlxClient;
/* /*
** Forward declarations. ** Forward declarations.
*/ */
@ -549,6 +554,8 @@ static int __glXDispatch(ClientPtr client)
GLboolean rendering = opcode <= X_GLXRenderLarge; GLboolean rendering = opcode <= X_GLXRenderLarge;
__glXleaveServer(rendering); __glXleaveServer(rendering);
__pGlxClient = client;
retval = (*proc)(cl, (GLbyte *) stuff); retval = (*proc)(cl, (GLbyte *) stuff);
__glXenterServer(rendering); __glXenterServer(rendering);

View File

@ -110,6 +110,8 @@ void __glXScreenInitVisuals(__GLXscreen *screen);
extern __GLXcontext *__glXLastContext; extern __GLXcontext *__glXLastContext;
extern __GLXcontext *__glXForceCurrent(__GLXclientState*, GLXContextTag, int*); extern __GLXcontext *__glXForceCurrent(__GLXclientState*, GLXContextTag, int*);
extern ClientPtr __pGlxClient;
int __glXError(int error); int __glXError(int error);
/* /*

View File

@ -593,6 +593,10 @@ DRIFinishScreenInit(ScreenPtr pScreen)
pDRIPriv->wrap.WindowExposures = pScreen->WindowExposures; pDRIPriv->wrap.WindowExposures = pScreen->WindowExposures;
pScreen->WindowExposures = pDRIInfo->wrap.WindowExposures; pScreen->WindowExposures = pDRIInfo->wrap.WindowExposures;
} }
pDRIPriv->DestroyWindow = pScreen->DestroyWindow;
pScreen->DestroyWindow = DRIDestroyWindow;
if (pDRIInfo->wrap.CopyWindow) { if (pDRIInfo->wrap.CopyWindow) {
pDRIPriv->wrap.CopyWindow = pScreen->CopyWindow; pDRIPriv->wrap.CopyWindow = pScreen->CopyWindow;
pScreen->CopyWindow = pDRIInfo->wrap.CopyWindow; pScreen->CopyWindow = pDRIInfo->wrap.CopyWindow;
@ -642,6 +646,10 @@ DRICloseScreen(ScreenPtr pScreen)
pScreen->WindowExposures = pDRIPriv->wrap.WindowExposures; pScreen->WindowExposures = pDRIPriv->wrap.WindowExposures;
pDRIPriv->wrap.WindowExposures = NULL; pDRIPriv->wrap.WindowExposures = NULL;
} }
if (pDRIPriv->DestroyWindow) {
pScreen->DestroyWindow = pDRIPriv->DestroyWindow;
pDRIPriv->DestroyWindow = NULL;
}
if (pDRIInfo->wrap.CopyWindow) { if (pDRIInfo->wrap.CopyWindow) {
pScreen->CopyWindow = pDRIPriv->wrap.CopyWindow; pScreen->CopyWindow = pDRIPriv->wrap.CopyWindow;
pDRIPriv->wrap.CopyWindow = NULL; pDRIPriv->wrap.CopyWindow = NULL;
@ -1248,8 +1256,8 @@ DRIDecreaseNumberVisible(ScreenPtr pScreen)
} }
Bool Bool
DRICreateDrawable(ScreenPtr pScreen, Drawable id, DRICreateDrawable(ScreenPtr pScreen, ClientPtr client, DrawablePtr pDrawable,
DrawablePtr pDrawable, drm_drawable_t * hHWDrawable) drm_drawable_t * hHWDrawable)
{ {
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
DRIDrawablePrivPtr pDRIDrawablePriv; DRIDrawablePrivPtr pDRIDrawablePriv;
@ -1291,11 +1299,12 @@ DRICreateDrawable(ScreenPtr pScreen, Drawable id,
if (pDRIDrawablePriv->nrects) if (pDRIDrawablePriv->nrects)
DRIIncreaseNumberVisible(pScreen); DRIIncreaseNumberVisible(pScreen);
/* track this in case this window is destroyed */
AddResource(id, DRIDrawablePrivResType, (pointer)pWin);
} }
/* track this in case the client dies */
AddResource(FakeClientID(client->index), DRIDrawablePrivResType,
(pointer)pDrawable->id);
if (pDRIDrawablePriv->hwDrawable) { if (pDRIDrawablePriv->hwDrawable) {
drmUpdateDrawableInfo(pDRIPriv->drmFD, drmUpdateDrawableInfo(pDRIPriv->drmFD,
pDRIDrawablePriv->hwDrawable, pDRIDrawablePriv->hwDrawable,
@ -1313,21 +1322,59 @@ DRICreateDrawable(ScreenPtr pScreen, Drawable id,
return TRUE; return TRUE;
} }
Bool static void
DRIDestroyDrawable(ScreenPtr pScreen, Drawable id, DrawablePtr pDrawable) DRIDrawablePrivDestroy(WindowPtr pWin)
{ {
DRIDrawablePrivPtr pDRIDrawablePriv; DRIDrawablePrivPtr pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
WindowPtr pWin; ScreenPtr pScreen;
DRIScreenPrivPtr pDRIPriv;
if (!pDRIDrawablePriv)
return;
pScreen = pWin->drawable.pScreen;
pDRIPriv = DRI_SCREEN_PRIV(pScreen);
if (pDRIDrawablePriv->drawableIndex != -1) {
/* bump stamp to force outstanding 3D requests to resync */
pDRIPriv->pSAREA->drawableTable[pDRIDrawablePriv->drawableIndex].stamp
= DRIDrawableValidationStamp++;
/* release drawable table entry */
pDRIPriv->DRIDrawables[pDRIDrawablePriv->drawableIndex] = NULL;
}
pDRIPriv->nrWindows--;
if (pDRIDrawablePriv->nrects)
DRIDecreaseNumberVisible(pScreen);
drmDestroyDrawable(pDRIPriv->drmFD, pDRIDrawablePriv->hwDrawable);
xfree(pDRIDrawablePriv);
pWin->devPrivates[DRIWindowPrivIndex].ptr = NULL;
}
static Bool
DRIDestroyDrawableCB(pointer value, XID id, pointer data)
{
if (value == data) {
/* This calls back DRIDrawablePrivDelete which frees private area */
FreeResourceByType(id, DRIDrawablePrivResType, FALSE);
return TRUE;
}
return FALSE;
}
Bool
DRIDestroyDrawable(ScreenPtr pScreen, ClientPtr client, DrawablePtr pDrawable)
{
if (pDrawable->type == DRAWABLE_WINDOW) { if (pDrawable->type == DRAWABLE_WINDOW) {
pWin = (WindowPtr)pDrawable; LookupClientResourceComplex(client, DRIDrawablePrivResType,
pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin); DRIDestroyDrawableCB,
pDRIDrawablePriv->refCount--; (pointer)pDrawable->id);
if (pDRIDrawablePriv->refCount <= 0) {
/* This calls back DRIDrawablePrivDelete which frees private area */
FreeResourceByType(id, DRIDrawablePrivResType, FALSE);
}
} }
else { /* pixmap (or for GLX 1.3, a PBuffer) */ else { /* pixmap (or for GLX 1.3, a PBuffer) */
/* NOT_DONE */ /* NOT_DONE */
@ -1340,43 +1387,26 @@ DRIDestroyDrawable(ScreenPtr pScreen, Drawable id, DrawablePtr pDrawable)
Bool Bool
DRIDrawablePrivDelete(pointer pResource, XID id) DRIDrawablePrivDelete(pointer pResource, XID id)
{ {
DrawablePtr pDrawable = (DrawablePtr)pResource; WindowPtr pWin;
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pDrawable->pScreen);
DRIDrawablePrivPtr pDRIDrawablePriv;
WindowPtr pWin;
if (pDrawable->type == DRAWABLE_WINDOW) { id = (XID)pResource;
pWin = (WindowPtr)pDrawable; pWin = LookupIDByType(id, RT_WINDOW);
pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
if (pDRIDrawablePriv->drawableIndex != -1) { if (pWin) {
/* bump stamp to force outstanding 3D requests to resync */ DRIDrawablePrivPtr pDRIDrwPriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
pDRIPriv->pSAREA->drawableTable[pDRIDrawablePriv->drawableIndex].stamp
= DRIDrawableValidationStamp++;
/* release drawable table entry */ if (!pDRIDrwPriv)
pDRIPriv->DRIDrawables[pDRIDrawablePriv->drawableIndex] = NULL;
}
if (drmDestroyDrawable(pDRIPriv->drmFD,
pDRIDrawablePriv->hwDrawable)) {
return FALSE; return FALSE;
}
xfree(pDRIDrawablePriv); if (--pDRIDrwPriv->refCount == 0)
pWin->devPrivates[DRIWindowPrivIndex].ptr = NULL; DRIDrawablePrivDestroy(pWin);
pDRIPriv->nrWindows--; return TRUE;
if (REGION_NUM_RECTS(&pWin->clipList))
DRIDecreaseNumberVisible(pDrawable->pScreen);
} }
else { /* pixmap (or for GLX 1.3, a PBuffer) */ else { /* pixmap (or for GLX 1.3, a PBuffer) */
/* NOT_DONE */ /* NOT_DONE */
return FALSE; return FALSE;
} }
return TRUE;
} }
Bool Bool
@ -1884,6 +1914,31 @@ DRITreeTraversal(WindowPtr pWin, pointer data)
return WT_WALKCHILDREN; return WT_WALKCHILDREN;
} }
Bool
DRIDestroyWindow(WindowPtr pWin)
{
ScreenPtr pScreen = pWin->drawable.pScreen;
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
Bool retval = TRUE;
DRIDrawablePrivDestroy(pWin);
/* call lower wrapped functions */
if(pDRIPriv->DestroyWindow) {
/* unwrap */
pScreen->DestroyWindow = pDRIPriv->DestroyWindow;
/* call lower layers */
retval = (*pScreen->DestroyWindow)(pWin);
/* rewrap */
pDRIPriv->DestroyWindow = pScreen->DestroyWindow;
pScreen->DestroyWindow = DRIDestroyWindow;
}
return retval;
}
void void
DRICopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc) DRICopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
{ {

View File

@ -231,12 +231,12 @@ extern Bool DRIDestroyContext(ScreenPtr pScreen, XID context);
extern Bool DRIContextPrivDelete(pointer pResource, XID id); extern Bool DRIContextPrivDelete(pointer pResource, XID id);
extern Bool DRICreateDrawable(ScreenPtr pScreen, extern Bool DRICreateDrawable(ScreenPtr pScreen,
Drawable id, ClientPtr client,
DrawablePtr pDrawable, DrawablePtr pDrawable,
drm_drawable_t * hHWDrawable); drm_drawable_t * hHWDrawable);
extern Bool DRIDestroyDrawable(ScreenPtr pScreen, extern Bool DRIDestroyDrawable(ScreenPtr pScreen,
Drawable id, ClientPtr client,
DrawablePtr pDrawable); DrawablePtr pDrawable);
extern Bool DRIDrawablePrivDelete(pointer pResource, extern Bool DRIDrawablePrivDelete(pointer pResource,
@ -299,6 +299,8 @@ extern void DRIWindowExposures(WindowPtr pWin,
RegionPtr prgn, RegionPtr prgn,
RegionPtr bsreg); RegionPtr bsreg);
extern Bool DRIDestroyWindow(WindowPtr pWin);
extern void DRICopyWindow(WindowPtr pWin, extern void DRICopyWindow(WindowPtr pWin,
DDXPointRec ptOldOrg, DDXPointRec ptOldOrg,
RegionPtr prgnSrc); RegionPtr prgnSrc);

View File

@ -99,6 +99,7 @@ typedef struct _DRIScreenPrivRec
DrawablePtr fullscreen; /* pointer to fullscreen drawable */ DrawablePtr fullscreen; /* pointer to fullscreen drawable */
drm_clip_rect_t fullscreen_rect; /* fake rect for fullscreen mode */ drm_clip_rect_t fullscreen_rect; /* fake rect for fullscreen mode */
DRIWrappedFuncsRec wrap; DRIWrappedFuncsRec wrap;
DestroyWindowProcPtr DestroyWindow;
DrawablePtr DRIDrawables[SAREA_MAX_DRAWABLES]; DrawablePtr DRIDrawables[SAREA_MAX_DRAWABLES];
DRIContextPrivPtr dummyCtxPriv; /* Pointer to dummy context */ DRIContextPrivPtr dummyCtxPriv; /* Pointer to dummy context */
Bool createDummyCtx; Bool createDummyCtx;

View File

@ -404,10 +404,8 @@ ProcXF86DRICreateDrawable(
if (rc != Success) if (rc != Success)
return rc; return rc;
if (!DRICreateDrawable( screenInfo.screens[stuff->screen], if (!DRICreateDrawable(screenInfo.screens[stuff->screen], client,
(Drawable)stuff->drawable, pDrawable, (drm_drawable_t *)&rep.hHWDrawable)) {
pDrawable,
(drm_drawable_t *)&rep.hHWDrawable)) {
return BadValue; return BadValue;
} }
@ -435,9 +433,8 @@ ProcXF86DRIDestroyDrawable(
if (rc != Success) if (rc != Success)
return rc; return rc;
if (!DRIDestroyDrawable( screenInfo.screens[stuff->screen], if (!DRIDestroyDrawable(screenInfo.screens[stuff->screen], client,
(Drawable)stuff->drawable, pDrawable)) {
pDrawable)) {
return BadValue; return BadValue;
} }