[PATCH 04/14] Simplify miFillPolyHelper and miLineArc.

Jamey Sharp jamey at minilop.net
Sat May 8 16:39:19 PDT 2010


Both functions compute a set of spans and either fill them immediately
or accumulate them into a caller-provided buffer.

Computing the spans used only the miTranslate and lineWidth fields of
pGC, and neither could have been changed by the initial
ChangeGC/ValidateGC pair, so it's safe to compute the spans first.

Then both functions consume the spans the same way, so factor that into
a new fillSpans function.

Signed-off-by: Jamey Sharp <jamey at minilop.net>
---
 mi/miwideline.c |   79 +++++++++++++++++++------------------------------------
 1 files changed, 27 insertions(+), 52 deletions(-)

diff --git a/mi/miwideline.c b/mi/miwideline.c
index 585d4d2..c5203fe 100644
--- a/mi/miwideline.c
+++ b/mi/miwideline.c
@@ -106,6 +106,31 @@ static void miLineArc(DrawablePtr pDraw, GCPtr pGC,
  */
 
 static void
+fillSpans(DrawablePtr pDrawable, GCPtr pGC, unsigned long pixel, Spans *spans, SpanDataPtr spanData)
+{
+    if (!spanData)
+    {
+	XID oldPixel = pGC->fgPixel;
+	if (pixel != oldPixel)
+	{
+	    XID tmpPixel = (XID)pixel;
+	    DoChangeGC (pGC, GCForeground, &tmpPixel, FALSE);
+	    ValidateGC (pDrawable, pGC);
+	}
+	(*pGC->ops->FillSpans) (pDrawable, pGC, spans->count, spans->points, spans->widths, TRUE);
+	xfree (spans->widths);
+	xfree (spans->points);
+	if (pixel != oldPixel)
+	{
+	    DoChangeGC (pGC, GCForeground, &oldPixel, FALSE);
+	    ValidateGC (pDrawable, pGC);
+	}
+    }
+    else
+	AppendSpanGroup (pGC, pixel, spans, spanData);
+}
+
+static void
 miFillPolyHelper (DrawablePtr pDrawable, GCPtr pGC, unsigned long pixel,
 		  SpanDataPtr spanData, int y, int overall_height,
 		  PolyEdgePtr left, PolyEdgePtr right,
@@ -126,27 +151,13 @@ miFillPolyHelper (DrawablePtr pDrawable, GCPtr pGC, unsigned long pixel,
 
     DDXPointPtr ppt;
     int 	*pwidth;
-    XID		oldPixel;
     int		xorg;
     Spans	spanRec;
 
-    left_height = 0;
-    right_height = 0;
-    
     if (!InitSpans(&spanRec, overall_height))
 	return;
     ppt = spanRec.points;
     pwidth = spanRec.widths;
-    if (!spanData)
-    {
-    	oldPixel = pGC->fgPixel;
-    	if (pixel != oldPixel)
-    	{
-	    XID tmpPixel = (XID)pixel;
-    	    DoChangeGC (pGC, GCForeground, &tmpPixel, FALSE);
-    	    ValidateGC (pDrawable, pGC);
-    	}
-    }
 
     xorg = 0;
     if (pGC->miTranslate)
@@ -219,19 +230,7 @@ miFillPolyHelper (DrawablePtr pDrawable, GCPtr pGC, unsigned long pixel,
 	}
     }
     spanRec.count = ppt - spanRec.points;
-    if (!spanData)
-    {
-	(*pGC->ops->FillSpans) (pDrawable, pGC, spanRec.count, spanRec.points, spanRec.widths, TRUE);
-	xfree (spanRec.widths);
-	xfree (spanRec.points);
-    	if (pixel != oldPixel)
-    	{
-	    DoChangeGC (pGC, GCForeground, &oldPixel, FALSE);
-	    ValidateGC (pDrawable, pGC);
-    	}
-    }
-    else
-	AppendSpanGroup (pGC, pixel, &spanRec, spanData);
+    fillSpans (pDrawable, pGC, pixel, &spanRec, spanData);
 }
 
 static void
@@ -1042,7 +1041,6 @@ miLineArc (
     Bool	    	isInt)
 {
     int xorgi = 0, yorgi = 0;
-    XID		oldPixel;
     Spans spanRec;
     int n;
     PolyEdgeRec	edge1, edge2;
@@ -1088,16 +1086,6 @@ miLineArc (
     }
     if (!InitSpans(&spanRec, pGC->lineWidth))
 	return;
-    if (!spanData)
-    {
-    	oldPixel = pGC->fgPixel;
-    	if (pixel != oldPixel)
-    	{
-	    XID tmpPixel = (XID)pixel;
-	    DoChangeGC(pGC, GCForeground, &tmpPixel, FALSE);
-	    ValidateGC (pDraw, pGC);
-    	}
-    }
     if (isInt)
 	n = miLineArcI(pDraw, pGC, xorgi, yorgi, spanRec.points, spanRec.widths);
     else
@@ -1105,20 +1093,7 @@ miLineArc (
 		       &edge1, edgey1, edgeleft1,
 		       &edge2, edgey2, edgeleft2);
     spanRec.count = n;
-
-    if (!spanData)
-    {
-	(*pGC->ops->FillSpans)(pDraw, pGC, spanRec.count, spanRec.points, spanRec.widths, TRUE);
-	xfree(spanRec.widths);
-	xfree(spanRec.points);
-    	if (pixel != oldPixel)
-    	{
-	    DoChangeGC(pGC, GCForeground, &oldPixel, FALSE);
-	    ValidateGC (pDraw, pGC);
-    	}
-    }
-    else
-	AppendSpanGroup (pGC, pixel, &spanRec, spanData);
+    fillSpans (pDraw, pGC, pixel, &spanRec, spanData);
 }
 
 static void
-- 
1.7.0



More information about the xorg-devel mailing list