[PATCH 01/10] dbe: Cleanup in CloseScreen hook not ext CloseDown

Adam Jackson ajax at redhat.com
Thu Oct 17 09:34:29 PDT 2013


From: Robert Bragg <robert at linux.intel.com>

Instead of registering an extension CloseDownProc when adding the dbe
extension this patch hooks into pScreen->CloseScreen so that the chain
of pScreen->DestroyWindow hooks remains valid until all windows have
been destroyed. Previously it was possible for DbeResetProc to be called
before the root window had been destroyed and the unwrapping of
pScreen->DestroyWindow would clobber the chain of callbacks.

This is needed for xwayland to be able to know when the root window is
destroyed so it can unredirect root sub-windows.

Reviewed-by: Adam Jackson <ajax at redhat.com>
---
 dbe/dbe.c       | 41 +++++++++++++++++++++--------------------
 dbe/dbestruct.h |  1 +
 2 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/dbe/dbe.c b/dbe/dbe.c
index 5524615..8d8bfb9 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -288,8 +288,8 @@ ProcDbeAllocateBackBufferName(ClientPtr client)
 
             /* malloc/realloc a new array and initialize all elements to 0. */
             pDbeWindowPriv->IDs = (XID *) realloc(pIDs,
-                                                  (pDbeWindowPriv->
-                                                   maxAvailableIDs +
+                                                  (pDbeWindowPriv->maxAvailableIDs
+                                                   +
                                                    DBE_INCR_MAX_IDS) *
                                                   sizeof(XID));
             if (!pDbeWindowPriv->IDs) {
@@ -464,7 +464,7 @@ ProcDbeSwapBuffers(ClientPtr client)
         return BadAlloc;
 
     /* Get to the swap info appended to the end of the request. */
-    dbeSwapInfo = (xDbeSwapInfo *) &stuff[1];
+    dbeSwapInfo = (xDbeSwapInfo *) & stuff[1];
 
     /* Allocate array to record swap information. */
     swapInfo = (DbeSwapInfoPtr) malloc(nStuff * sizeof(DbeSwapInfoRec));
@@ -1230,7 +1230,7 @@ DbeWindowPrivDelete(pointer pDbeWinPriv, XID id)
 
 /******************************************************************************
  *
- * DBE DIX Procedure: DbeResetProc
+ * DBE DIX Procedure: DbeCloseScreen
  *
  * Description:
  *
@@ -1239,25 +1239,23 @@ DbeWindowPrivDelete(pointer pDbeWinPriv, XID id)
  *     other tasks related to shutting down the extension.
  *
  *****************************************************************************/
-static void
-DbeResetProc(ExtensionEntry * extEntry)
+static Bool
+DbeCloseScreen(ScreenPtr pScreen)
 {
-    int i;
-    ScreenPtr pScreen;
-    DbeScreenPrivPtr pDbeScreenPriv;
+    DbeScreenPrivPtr pDbeScreenPriv = DBE_SCREEN_PRIV(pScreen);
 
-    for (i = 0; i < screenInfo.numScreens; i++) {
-        pScreen = screenInfo.screens[i];
-        pDbeScreenPriv = DBE_SCREEN_PRIV(pScreen);
+    if (pDbeScreenPriv) {
+        /* Unwrap DestroyWindow, which was wrapped in DbeExtensionInit(). */
+        pScreen->DestroyWindow = pDbeScreenPriv->DestroyWindow;
 
-        if (pDbeScreenPriv) {
-            /* Unwrap DestroyWindow, which was wrapped in DbeExtensionInit(). */
-            pScreen->DestroyWindow = pDbeScreenPriv->DestroyWindow;
-            pScreen->PositionWindow = pDbeScreenPriv->PositionWindow;
-            free(pDbeScreenPriv);
-        }
+        /* Unwrap CloseScreen, which was wrapped in DbeExtensionInit(). */
+        pScreen->CloseScreen = pDbeScreenPriv->CloseScreen;
+
+        free(pDbeScreenPriv);
     }
-}                               /* DbeResetProc() */
+
+    return (*pScreen->CloseScreen) (pScreen);
+}                               /* DbeCloseScreen */
 
 /******************************************************************************
  *
@@ -1427,6 +1425,9 @@ DbeExtensionInit(void)
 
                 pDbeScreenPriv->DestroyWindow = pScreen->DestroyWindow;
                 pScreen->DestroyWindow = DbeDestroyWindow;
+
+                pDbeScreenPriv->CloseScreen = pScreen->CloseScreen;
+                pScreen->CloseScreen = DbeCloseScreen;
             }
             else {
                 /* DDX initialization failed.  Stub the screen. */
@@ -1454,7 +1455,7 @@ DbeExtensionInit(void)
     /* Now add the extension. */
     extEntry = AddExtension(DBE_PROTOCOL_NAME, DbeNumberEvents,
                             DbeNumberErrors, ProcDbeDispatch, SProcDbeDispatch,
-                            DbeResetProc, StandardMinorOpcode);
+                            NULL, StandardMinorOpcode);
 
     dbeErrorBase = extEntry->errorBase;
     SetResourceTypeErrorValue(dbeWindowPrivResType,
diff --git a/dbe/dbestruct.h b/dbe/dbestruct.h
index 2002066..7733d0e 100644
--- a/dbe/dbestruct.h
+++ b/dbe/dbestruct.h
@@ -176,6 +176,7 @@ typedef struct _DbeScreenPrivRec {
      */
     PositionWindowProcPtr PositionWindow;
     DestroyWindowProcPtr DestroyWindow;
+    CloseScreenProcPtr CloseScreen;
 
     /* Per-screen DIX routines */
     Bool (*SetupBackgroundPainter) (WindowPtr /*pWin */ ,
-- 
1.8.3.1



More information about the xorg-devel mailing list