[PATCH 03/22] composite: Only register the block handler when it is required

Pauli ext-pauli.nieminen at nokia.com
Wed Dec 29 11:27:15 PST 2010


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

Even calling block handler that doesn't do much is costly in arm. It
takes a few microseconds each time which adds up to relative high CPU
time because it is done 500+ times per second.

Simple optimization is to register the block handler only when it is
required.

Signed-off-by: Pauli Nieminen <ext-pauli.nieminen at nokia.com>
---
 composite/compalloc.c |   37 ++++++++++++++++++++++++++++++++++++-
 composite/compinit.c  |   33 +--------------------------------
 2 files changed, 37 insertions(+), 33 deletions(-)

diff --git a/composite/compalloc.c b/composite/compalloc.c
index 93571ee..e628c45 100644
--- a/composite/compalloc.c
+++ b/composite/compalloc.c
@@ -48,6 +48,36 @@
 #include "compint.h"
 
 static void
+compScreenUpdate (ScreenPtr pScreen)
+{
+    CompScreenPtr   cs = GetCompScreen (pScreen);
+
+    compCheckTree (pScreen);
+    if (cs->damaged)
+    {
+	compWindowUpdate (pScreen->root);
+	cs->damaged = FALSE;
+    }
+}
+
+static void
+compBlockHandler (int	    i,
+		  pointer   blockData,
+		  pointer   pTimeout,
+		  pointer   pReadmask)
+{
+    ScreenPtr	    pScreen = screenInfo.screens[i];
+    CompScreenPtr   cs = GetCompScreen (pScreen);
+
+    pScreen->BlockHandler = cs->BlockHandler;
+    compScreenUpdate (pScreen);
+    (*pScreen->BlockHandler) (i, blockData, pTimeout, pReadmask);
+
+    /* Next damage will restore the block handler */
+    cs->BlockHandler = NULL;
+}
+
+static void
 compReportDamage (DamagePtr pDamage, RegionPtr pRegion, void *closure)
 {
     WindowPtr	    pWin = (WindowPtr) closure;
@@ -55,7 +85,12 @@ compReportDamage (DamagePtr pDamage, RegionPtr pRegion, void *closure)
     CompScreenPtr   cs = GetCompScreen (pScreen);
     CompWindowPtr   cw = GetCompWindow (pWin);
 
-    cs->damaged = TRUE;
+    if (!cs->damaged) {
+        cs->BlockHandler = pScreen->BlockHandler;
+        pScreen->BlockHandler = compBlockHandler;
+
+        cs->damaged = TRUE;
+    }
     cw->damaged = TRUE;
 }
 
diff --git a/composite/compinit.c b/composite/compinit.c
index 159f7c2..885cc73 100644
--- a/composite/compinit.c
+++ b/composite/compinit.c
@@ -61,7 +61,6 @@ compCloseScreen (int index, ScreenPtr pScreen)
     free(cs->alternateVisuals);
 
     pScreen->CloseScreen = cs->CloseScreen;
-    pScreen->BlockHandler = cs->BlockHandler;
     pScreen->InstallColormap = cs->InstallColormap;
     pScreen->ChangeWindowAttributes = cs->ChangeWindowAttributes;
     pScreen->ReparentWindow = cs->ReparentWindow;
@@ -130,35 +129,6 @@ compChangeWindowAttributes(WindowPtr pWin, unsigned long mask)
     return ret;
 }
 
-static void
-compScreenUpdate (ScreenPtr pScreen)
-{
-    CompScreenPtr   cs = GetCompScreen (pScreen);
-
-    compCheckTree (pScreen);
-    if (cs->damaged)
-    {
-	compWindowUpdate (pScreen->root);
-	cs->damaged = FALSE;
-    }
-}
-
-static void
-compBlockHandler (int	    i,
-		  pointer   blockData,
-		  pointer   pTimeout,
-		  pointer   pReadmask)
-{
-    ScreenPtr	    pScreen = screenInfo.screens[i];
-    CompScreenPtr   cs = GetCompScreen (pScreen);
-
-    pScreen->BlockHandler = cs->BlockHandler;
-    compScreenUpdate (pScreen);
-    (*pScreen->BlockHandler) (i, blockData, pTimeout, pReadmask);
-    cs->BlockHandler = pScreen->BlockHandler;
-    pScreen->BlockHandler = compBlockHandler;
-}
-
 /*
  * Add alternate visuals -- always expose an ARGB32 and RGB24 visual
  */
@@ -387,8 +357,7 @@ compScreenInit (ScreenPtr pScreen)
     cs->ChangeWindowAttributes = pScreen->ChangeWindowAttributes;
     pScreen->ChangeWindowAttributes = compChangeWindowAttributes;
 
-    cs->BlockHandler = pScreen->BlockHandler;
-    pScreen->BlockHandler = compBlockHandler;
+    cs->BlockHandler = NULL;
 
     cs->CloseScreen = pScreen->CloseScreen;
     pScreen->CloseScreen = compCloseScreen;
-- 
1.7.0.4



More information about the xorg-devel mailing list