[PATCH] Replace screen->rgf scratch GC flags with a bit in each GC.

Jamey Sharp jamey at minilop.net
Wed May 19 16:09:58 PDT 2010


This eliminates a poorly-named, poorly-documented field from the
ScreenRec, using a previously-unused flag bit in each GC instead.

Signed-off-by: Jamey Sharp <jamey at minilop.net>
Cc: Adam Jackson <ajax at redhat.com>
---
On Wed, May 19, 2010 at 1:04 PM, Adam Jackson <ajax at nwnk.net> wrote:
> On Wed, 2010-05-19 at 12:23 -0700, Jamey Sharp wrote:
>> Alternatively, use one of the unused flag bits in each GC to mark
>> whether it's free for reuse, and drop this rgf field entirely.
>
> That (using a GC bit) is not a terrible idea at all.

Like this? It's more clear that it's correct after the patches I posted
earlier, to make CreateScratchGC static, but I believe it's correct
regardless.

 dix/dispatch.c       |    1 -
 dix/gc.c             |   20 ++++++++++++--------
 hw/xnest/Screen.c    |    1 -
 include/gcstruct.h   |    3 ++-
 include/scrnintstr.h |    1 -
 5 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/dix/dispatch.c b/dix/dispatch.c
index c86011a..27cb220 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3916,7 +3916,6 @@ AddScreen(
        any of the strings pointed to by argv.  They may be passed to
        multiple screens.
     */
-    pScreen->rgf = ~0L;  /* there are no scratch GCs yet*/
     WindowTable[i] = NullWindow;
     screenInfo.screens[i] = pScreen;
     screenInfo.numScreens++;
diff --git a/dix/gc.c b/dix/gc.c
index 56d5cda..95ee6b8 100644
--- a/dix/gc.c
+++ b/dix/gc.c
@@ -844,6 +844,9 @@ CreateScratchGC(ScreenPtr pScreen, unsigned depth)
     pGC->lastWinOrg.x = 0;
     pGC->lastWinOrg.y = 0;
 
+    /* scratch GCs in the GCperDepth pool start off reusable */
+    pGC->reusable = TRUE;
+
     pGC->stateChanges = GCAllBits;
     if (!(*pScreen->CreateGC)(pGC))
     {
@@ -864,8 +867,10 @@ FreeGCperDepth(int screenNum)
     ppGC = pScreen->GCperDepth;
 
     for (i = 0; i <= pScreen->numDepths; i++)
+    {
 	(void)FreeGC(ppGC[i], (XID)0);
-    pScreen->rgf = ~0L;
+	ppGC[i] = NULL;
+    }
 }
 
 
@@ -878,7 +883,6 @@ CreateGCperDepth(int screenNum)
     GCPtr *ppGC;
 
     pScreen = screenInfo.screens[screenNum];
-    pScreen->rgf = 0;
     ppGC = pScreen->GCperDepth;
     /* do depth 1 separately because it's not included in list */
     if (!(ppGC[0] = CreateScratchGC(pScreen, 1)))
@@ -1097,12 +1101,11 @@ GetScratchGC(unsigned depth, ScreenPtr pScreen)
     GCPtr pGC;
 
     for (i=0; i<=pScreen->numDepths; i++)
-        if ( pScreen->GCperDepth[i]->depth == depth &&
-	     !(pScreen->rgf & (1L << (i+1)))
-	   )
+    {
+	pGC = pScreen->GCperDepth[i];
+	if (pGC && pGC->depth == depth && pGC->reusable)
 	{
-	    pScreen->rgf |= (1L << (i+1));
-            pGC = (pScreen->GCperDepth[i]);
+	    pGC->reusable = FALSE;
 
 	    pGC->alu = GXcopy;
 	    pGC->planemask = ~0;
@@ -1127,6 +1130,7 @@ GetScratchGC(unsigned depth, ScreenPtr pScreen)
 	    pGC->stateChanges = GCAllBits;
 	    return pGC;
 	}
+    }
     /* if we make it this far, need to roll our own */
     pGC = CreateScratchGC(pScreen, depth);
     if (pGC)
@@ -1149,7 +1153,7 @@ FreeScratchGC(GCPtr pGC)
     {
         if ( pScreen->GCperDepth[i] == pGC)
 	{
-	    pScreen->rgf &= ~(1L << (i+1));
+	    pScreen->GCperDepth[i]->reusable = TRUE;
 	    return;
 	}
     }
diff --git a/hw/xnest/Screen.c b/hw/xnest/Screen.c
index 62255b8..0a05ac8 100644
--- a/hw/xnest/Screen.c
+++ b/hw/xnest/Screen.c
@@ -243,7 +243,6 @@ xnestOpenScreen(int index, ScreenPtr pScreen, int argc, char *argv[])
   pScreen->saveUnderSupport = NotUseful;
   pScreen->whitePixel = xnestWhitePixel;
   pScreen->blackPixel = xnestBlackPixel;
-  /* rgf */
   /* GCperDepth */
   /* PixmapPerDepth */
   pScreen->devPrivate = NULL;
diff --git a/include/gcstruct.h b/include/gcstruct.h
index b9fc5ca..68297a9 100644
--- a/include/gcstruct.h
+++ b/include/gcstruct.h
@@ -292,7 +292,8 @@ typedef struct _GC {
     unsigned int	tileIsPixel:1; /* tile is solid pixel */
     unsigned int	fExpose:1;     /* Call exposure handling */
     unsigned int	freeCompClip:1;  /* Free composite clip */
-    unsigned int	unused:14; /* see comment above */
+    unsigned int	reusable:1; /* is this GC in a pool for reuse? */
+    unsigned int	unused:13; /* see comment above */
     unsigned long	planemask;
     unsigned long	fgPixel;
     unsigned long	bgPixel;
diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index 3a77e0c..6f1936c 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -455,7 +455,6 @@ typedef struct _Screen {
     short		minInstalledCmaps, maxInstalledCmaps;
     char                backingStoreSupport, saveUnderSupport;
     unsigned long	whitePixel, blackPixel;
-    unsigned long	rgf;	/* array of flags; she's -- HUNGARIAN */
     GCPtr		GCperDepth[MAXFORMATS+1];
 			/* next field is a stipple to use as default in
 			   a GC.  we don't build default tiles of all depths
-- 
1.7.0



More information about the xorg-devel mailing list