[PATCH] dix/gc: consolidate GC object creation in one place

Dave Airlie airlied at gmail.com
Wed May 23 11:26:53 PDT 2012


From: Dave Airlie <airlied at redhat.com>

The standard GC create and scratch GC create were 90% the same really,
and I have a need in the future for creating GC objects without the
other bits, so wanted to avoid a third copy.

Signed-off-by: Dave Airlie <airlied at redhat.com>
---
 dix/gc.c |  108 ++++++++++++++++++++++++++------------------------------------
 1 files changed, 45 insertions(+), 63 deletions(-)

diff --git a/dix/gc.c b/dix/gc.c
index 7be0502..fb013e4 100644
--- a/dix/gc.c
+++ b/dix/gc.c
@@ -458,32 +458,21 @@ ChangeGCXIDs(ClientPtr client, GC * pGC, BITS32 mask, CARD32 *pC32)
     return ChangeGC(client, pGC, mask, vals);
 }
 
-/* CreateGC(pDrawable, mask, pval, pStatus)
-   creates a default GC for the given drawable, using mask to fill
-   in any non-default values.
-   Returns a pointer to the new GC on success, NULL otherwise.
-   returns status of non-default fields in pStatus
-BUG:
-   should check for failure to create default tile
-
-*/
 GCPtr
-CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus,
-         XID gcid, ClientPtr client)
+NewGCObject(ScreenPtr pScreen, int depth)
 {
     GCPtr pGC;
 
     pGC = dixAllocateObjectWithPrivates(GC, PRIVATE_GC);
     if (!pGC) {
-        *pStatus = BadAlloc;
         return (GCPtr) NULL;
     }
 
-    pGC->pScreen = pDrawable->pScreen;
-    pGC->depth = pDrawable->depth;
+    pGC->pScreen = pScreen;
+    pGC->depth = depth;
     pGC->alu = GXcopy;          /* dst <- src */
     pGC->planemask = ~0;
-    pGC->serialNumber = GC_CHANGE_SERIAL_BIT;
+    pGC->serialNumber = 0;
     pGC->funcs = 0;
     pGC->fgPixel = 0;
     pGC->bgPixel = 1;
@@ -496,17 +485,8 @@ CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus,
     pGC->arcMode = ArcPieSlice;
     pGC->tile.pixel = 0;
     pGC->tile.pixmap = NullPixmap;
-    if (mask & GCForeground) {
-        /*
-         * magic special case -- ChangeGC checks for this condition
-         * and snags the Foreground value to create a pseudo default-tile
-         */
-        pGC->tileIsPixel = FALSE;
-    }
-    else {
-        pGC->tileIsPixel = TRUE;
-    }
 
+    pGC->tileIsPixel = TRUE;
     pGC->patOrg.x = 0;
     pGC->patOrg.y = 0;
     pGC->subWindowMode = ClipByChildren;
@@ -521,12 +501,49 @@ CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus,
 
     /* use the default font and stipple */
     pGC->font = defaultFont;
-    defaultFont->refcnt++;
+    if (pGC->font)              /* necessary, because open of default font could fail */
+        pGC->font->refcnt++;
     pGC->stipple = pGC->pScreen->PixmapPerDepth[0];
-    pGC->stipple->refcnt++;
+    if (pGC->stipple)
+        pGC->stipple->refcnt++;
 
     /* this is not a scratch GC */
     pGC->scratch_inuse = FALSE;
+    return pGC;
+}
+
+/* CreateGC(pDrawable, mask, pval, pStatus)
+   creates a default GC for the given drawable, using mask to fill
+   in any non-default values.
+   Returns a pointer to the new GC on success, NULL otherwise.
+   returns status of non-default fields in pStatus
+BUG:
+   should check for failure to create default tile
+
+*/
+GCPtr
+CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus,
+         XID gcid, ClientPtr client)
+{
+    GCPtr pGC;
+
+    pGC = NewGCObject(pDrawable->pScreen, pDrawable->depth);
+    if (!pGC) {
+        *pStatus = BadAlloc;
+        return (GCPtr) NULL;
+    }
+
+    pGC->serialNumber = GC_CHANGE_SERIAL_BIT;
+    if (mask & GCForeground) {
+        /*
+         * magic special case -- ChangeGC checks for this condition
+         * and snags the Foreground value to create a pseudo default-tile
+         */
+        pGC->tileIsPixel = FALSE;
+    }
+    else {
+        pGC->tileIsPixel = TRUE;
+    }
 
     /* security creation/labeling check */
     *pStatus = XaceHook(XACE_RESOURCE_ACCESS, client, gcid, RT_GC, pGC,
@@ -784,45 +801,10 @@ CreateScratchGC(ScreenPtr pScreen, unsigned depth)
 {
     GCPtr pGC;
 
-    pGC = dixAllocateObjectWithPrivates(GC, PRIVATE_GC);
+    pGC = NewGCObject(pScreen, depth);
     if (!pGC)
         return (GCPtr) NULL;
 
-    pGC->pScreen = pScreen;
-    pGC->depth = depth;
-    pGC->alu = GXcopy;          /* dst <- src */
-    pGC->planemask = ~0;
-    pGC->serialNumber = 0;
-    pGC->fgPixel = 0;
-    pGC->bgPixel = 1;
-    pGC->lineWidth = 0;
-    pGC->lineStyle = LineSolid;
-    pGC->capStyle = CapButt;
-    pGC->joinStyle = JoinMiter;
-    pGC->fillStyle = FillSolid;
-    pGC->fillRule = EvenOddRule;
-    pGC->arcMode = ArcPieSlice;
-    pGC->font = defaultFont;
-    if (pGC->font)              /* necessary, because open of default font could fail */
-        pGC->font->refcnt++;
-    pGC->tileIsPixel = TRUE;
-    pGC->tile.pixel = 0;
-    pGC->tile.pixmap = NullPixmap;
-    pGC->stipple = NullPixmap;
-    pGC->patOrg.x = 0;
-    pGC->patOrg.y = 0;
-    pGC->subWindowMode = ClipByChildren;
-    pGC->graphicsExposures = TRUE;
-    pGC->clipOrg.x = 0;
-    pGC->clipOrg.y = 0;
-    pGC->clientClipType = CT_NONE;
-    pGC->dashOffset = 0;
-    pGC->numInDashList = 2;
-    pGC->dash = DefaultDash;
-
-    /* scratch GCs in the GCperDepth pool start off unused */
-    pGC->scratch_inuse = FALSE;
-
     pGC->stateChanges = GCAllBits;
     if (!(*pScreen->CreateGC) (pGC)) {
         FreeGC(pGC, (XID) 0);
-- 
1.7.6



More information about the xorg-devel mailing list