[PATCH xserver] dix: Call screen block/wakeup handlers closest to blocking [v3]

Keith Packard keithp at keithp.com
Thu May 26 23:45:54 UTC 2016


The screen block and wakeup handlers are the only ones which provide a
well known ordering between the wrapping layers; placing these as
close as possible to the server blocking provides a way for the driver
to control the flow of execution correctly.

Switch the shadow code to run in the screen block handler so that it
now occurrs just before the server goes to sleep.

Switch glamor to call down to the driver after it has executed its own
block handler piece, in case the driver needs to perform additional
flushing work after glamor has called glFlush.

These changes ensure that the following modules update the screen in
the correct order:

animated cursors        (uses RegisterBlockAndWakeupHandlers dynamically)
composite               (dynamic wrapping)
misprite                (dynamic wrapping)
shadow                  (static wrapping)
glamor                  (static wrapping)
driver                  (static wrapping)

It looks like there's still a bit of confusion between composite and
misprite; if composite updates after misprite, then it's possible
you'd exit the block handler chain with the cursor left hidden. To fix
that, misprite should be wrapping during ScreenInit time and not
unwrapping. And composite might as well join in that fun, just to make
things consistent.

[v2] Unwrap BlockHandler in shadowCloseScreen (ajax)
[v3] ephyr: Use screen block handler for flushing changes

ephyr needs to make sure it calls glXSwapBuffers after glamor finishes
its rendering. As the screen block handler is now called last, we have
to use that instead of a registered block/wakeup handler to make sure
the GL rendering is done before we copy it to the front buffer.

Signed-off-by: Keith Packard <keithp at keithp.com>
---
 dix/dixutils.c          | 23 +++++++++++++----------
 glamor/glamor.c         |  6 +++---
 hw/kdrive/ephyr/ephyr.c | 43 +++++++++++++++++++++++++++----------------
 hw/kdrive/ephyr/ephyr.h |  2 ++
 miext/shadow/shadow.c   | 20 +++++++-------------
 miext/shadow/shadow.h   |  1 +
 6 files changed, 53 insertions(+), 42 deletions(-)

diff --git a/dix/dixutils.c b/dix/dixutils.c
index b6b0023..3d2e7a3 100644
--- a/dix/dixutils.c
+++ b/dix/dixutils.c
@@ -383,16 +383,19 @@ BlockHandler(void *pTimeout, void *pReadmask)
     int i, j;
 
     ++inHandler;
-    for (i = 0; i < screenInfo.numScreens; i++)
-        (*screenInfo.screens[i]->BlockHandler) (screenInfo.screens[i],
-                                                pTimeout, pReadmask);
-    for (i = 0; i < screenInfo.numGPUScreens; i++)
-        (*screenInfo.gpuscreens[i]->BlockHandler) (screenInfo.gpuscreens[i],
-                                                   pTimeout, pReadmask);
     for (i = 0; i < numHandlers; i++)
         if (!handlers[i].deleted)
             (*handlers[i].BlockHandler) (handlers[i].blockData,
                                          pTimeout, pReadmask);
+
+    for (i = 0; i < screenInfo.numGPUScreens; i++)
+        (*screenInfo.gpuscreens[i]->BlockHandler) (screenInfo.gpuscreens[i],
+                                                   pTimeout, pReadmask);
+
+    for (i = 0; i < screenInfo.numScreens; i++)
+        (*screenInfo.screens[i]->BlockHandler) (screenInfo.screens[i],
+                                                pTimeout, pReadmask);
+
     if (handlerDeleted) {
         for (i = 0; i < numHandlers;)
             if (handlers[i].deleted) {
@@ -418,16 +421,16 @@ WakeupHandler(int result, void *pReadmask)
     int i, j;
 
     ++inHandler;
-    for (i = numHandlers - 1; i >= 0; i--)
-        if (!handlers[i].deleted)
-            (*handlers[i].WakeupHandler) (handlers[i].blockData,
-                                          result, pReadmask);
     for (i = 0; i < screenInfo.numScreens; i++)
         (*screenInfo.screens[i]->WakeupHandler) (screenInfo.screens[i],
                                                  result, pReadmask);
     for (i = 0; i < screenInfo.numGPUScreens; i++)
         (*screenInfo.gpuscreens[i]->WakeupHandler) (screenInfo.gpuscreens[i],
                                                     result, pReadmask);
+    for (i = numHandlers - 1; i >= 0; i--)
+        if (!handlers[i].deleted)
+            (*handlers[i].WakeupHandler) (handlers[i].blockData,
+                                          result, pReadmask);
     if (handlerDeleted) {
         for (i = 0; i < numHandlers;)
             if (handlers[i].deleted) {
diff --git a/glamor/glamor.c b/glamor/glamor.c
index 62b5c3a..7d82ce8 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -264,13 +264,13 @@ _glamor_block_handler(ScreenPtr screen, void *timeout, void *readmask)
 {
     glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
 
+    glamor_make_current(glamor_priv);
+    glFlush();
+
     screen->BlockHandler = glamor_priv->saved_procs.block_handler;
     screen->BlockHandler(screen, timeout, readmask);
     glamor_priv->saved_procs.block_handler = screen->BlockHandler;
     screen->BlockHandler = _glamor_block_handler;
-
-    glamor_make_current(glamor_priv);
-    glFlush();
 }
 
 static void
diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index 2e7c86c..2114c1c 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -337,17 +337,29 @@ ephyrInternalDamageRedisplay(ScreenPtr pScreen)
 }
 
 static void
-ephyrInternalDamageBlockHandler(void *data, OSTimePtr pTimeout, void *pRead)
+ephyrScreenBlockHandler(ScreenPtr pScreen, void *timeout, void *pRead)
 {
-    ScreenPtr pScreen = (ScreenPtr) data;
+    KdScreenPriv(pScreen);
+    KdScreenInfo *screen = pScreenPriv->screen;
+    EphyrScrPriv *scrpriv = screen->driver;
 
-    ephyrInternalDamageRedisplay(pScreen);
-}
+    pScreen->BlockHandler = scrpriv->BlockHandler;
+    (*pScreen->BlockHandler)(pScreen, timeout, pRead);
 
-static void
-ephyrInternalDamageWakeupHandler(void *data, int i, void *LastSelectMask)
-{
-    /* FIXME: Not needed ? */
+    if (scrpriv->pDamage) {
+
+        /* Re-wrap if we're still tracking damage
+         */
+        scrpriv->BlockHandler = pScreen->BlockHandler;
+        pScreen->BlockHandler = ephyrScreenBlockHandler;
+        ephyrInternalDamageRedisplay(pScreen);
+    } else {
+
+        /* Done tracking damage, note that we've left
+         * the block handler unwrapped
+         */
+        scrpriv->BlockHandler = NULL;
+    }
 }
 
 Bool
@@ -362,10 +374,11 @@ ephyrSetInternalDamage(ScreenPtr pScreen)
                                     (DamageDestroyFunc) 0,
                                     DamageReportNone, TRUE, pScreen, pScreen);
 
-    if (!RegisterBlockAndWakeupHandlers(ephyrInternalDamageBlockHandler,
-                                        ephyrInternalDamageWakeupHandler,
-                                        (void *) pScreen))
-        return FALSE;
+    /* Wrap only once */
+    if (scrpriv->BlockHandler == NULL) {
+        scrpriv->BlockHandler = pScreen->BlockHandler;
+        pScreen->BlockHandler = ephyrScreenBlockHandler;
+    }
 
     pPixmap = (*pScreen->GetScreenPixmap) (pScreen);
 
@@ -382,10 +395,7 @@ ephyrUnsetInternalDamage(ScreenPtr pScreen)
     EphyrScrPriv *scrpriv = screen->driver;
 
     DamageDestroy(scrpriv->pDamage);
-
-    RemoveBlockAndWakeupHandlers(ephyrInternalDamageBlockHandler,
-                                 ephyrInternalDamageWakeupHandler,
-                                 (void *) pScreen);
+    scrpriv->pDamage = NULL;
 }
 
 #ifdef RANDR
@@ -736,6 +746,7 @@ ephyrScreenFini(KdScreenInfo * screen)
     if (scrpriv->shadow) {
         KdShadowFbFree(screen);
     }
+    scrpriv->BlockHandler = NULL;
 }
 
 void
diff --git a/hw/kdrive/ephyr/ephyr.h b/hw/kdrive/ephyr/ephyr.h
index f5015f6..7b6e383 100644
--- a/hw/kdrive/ephyr/ephyr.h
+++ b/hw/kdrive/ephyr/ephyr.h
@@ -85,6 +85,8 @@ typedef struct _ephyrScrPriv {
     int mynum;                  /* Screen number */
     unsigned long cmap[256];
 
+    ScreenBlockHandlerProcPtr   BlockHandler;
+
     /**
      * Per-screen Xlib-using state for glamor (private to
      * ephyr_glamor_glx.c)
diff --git a/miext/shadow/shadow.c b/miext/shadow/shadow.c
index 0dd3604a..405c4dd 100644
--- a/miext/shadow/shadow.c
+++ b/miext/shadow/shadow.c
@@ -65,16 +65,15 @@ shadowRedisplay(ScreenPtr pScreen)
 }
 
 static void
-shadowBlockHandler(void *data, OSTimePtr pTimeout, void *pRead)
+shadowBlockHandler(ScreenPtr pScreen, void *timeout, void *pRead)
 {
-    ScreenPtr pScreen = (ScreenPtr) data;
+    shadowBuf(pScreen);
 
     shadowRedisplay(pScreen);
-}
 
-static void
-shadowWakeupHandler(void *data, int i, void *LastSelectMask)
-{
+    unwrap(pBuf, pScreen, BlockHandler);
+    pScreen->BlockHandler(pScreen, timeout, pRead);
+    wrap(pBuf, pScreen, BlockHandler);
 }
 
 static void
@@ -100,6 +99,7 @@ shadowCloseScreen(ScreenPtr pScreen)
 
     unwrap(pBuf, pScreen, GetImage);
     unwrap(pBuf, pScreen, CloseScreen);
+    unwrap(pBuf, pScreen, BlockHandler);
     shadowRemove(pScreen, pBuf->pPixmap);
     DamageDestroy(pBuf->pDamage);
     if (pBuf->pPixmap)
@@ -132,6 +132,7 @@ shadowSetup(ScreenPtr pScreen)
 
     wrap(pBuf, pScreen, CloseScreen);
     wrap(pBuf, pScreen, GetImage);
+    wrap(pBuf, pScreen, BlockHandler);
     pBuf->update = 0;
     pBuf->window = 0;
     pBuf->pPixmap = 0;
@@ -148,10 +149,6 @@ shadowAdd(ScreenPtr pScreen, PixmapPtr pPixmap, ShadowUpdateProc update,
 {
     shadowBuf(pScreen);
 
-    if (!RegisterBlockAndWakeupHandlers(shadowBlockHandler, shadowWakeupHandler,
-                                        (void *) pScreen))
-        return FALSE;
-
     /*
      * Map simple rotation values to bitmasks; fortunately,
      * these are all unique
@@ -192,7 +189,4 @@ shadowRemove(ScreenPtr pScreen, PixmapPtr pPixmap)
         pBuf->closure = 0;
         pBuf->pPixmap = 0;
     }
-
-    RemoveBlockAndWakeupHandlers(shadowBlockHandler, shadowWakeupHandler,
-                                 (void *) pScreen);
 }
diff --git a/miext/shadow/shadow.h b/miext/shadow/shadow.h
index 86fa944..7f22169 100644
--- a/miext/shadow/shadow.h
+++ b/miext/shadow/shadow.h
@@ -54,6 +54,7 @@ typedef struct _shadowBuf {
     /* screen wrappers */
     GetImageProcPtr GetImage;
     CloseScreenProcPtr CloseScreen;
+    ScreenBlockHandlerProcPtr BlockHandler;
 } shadowBufRec;
 
 /* Match defines from randr extension */
-- 
2.8.0.rc3



More information about the xorg-devel mailing list