miwideline: Factor out span buffer allocation.

Signed-off-by: Jamey Sharp <jamey@minilop.net>
Reviewed-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
This commit is contained in:
Jamey Sharp 2010-05-08 13:38:00 -07:00
parent c9e7ca4404
commit 83f7ec9727

View File

@ -52,6 +52,21 @@ from The Open Group.
#include "miwideline.h" #include "miwideline.h"
#include "mi.h" #include "mi.h"
static Bool
InitSpans(Spans *spans, size_t nspans)
{
spans->points = malloc(nspans * sizeof (*spans->points));
if (!spans->points)
return FALSE;
spans->widths = malloc(nspans * sizeof (*spans->widths));
if (!spans->widths)
{
free(spans->points);
return FALSE;
}
return TRUE;
}
/* /*
* interface data to span-merging polygon filler * interface data to span-merging polygon filler
*/ */
@ -110,9 +125,7 @@ miFillPolyHelper (DrawablePtr pDrawable, GCPtr pGC, unsigned long pixel,
int left_height = 0, right_height = 0; int left_height = 0, right_height = 0;
DDXPointPtr ppt; DDXPointPtr ppt;
DDXPointPtr pptInit = NULL;
int *pwidth; int *pwidth;
int *pwidthInit = NULL;
XID oldPixel; XID oldPixel;
int xorg; int xorg;
Spans spanRec; Spans spanRec;
@ -120,19 +133,12 @@ miFillPolyHelper (DrawablePtr pDrawable, GCPtr pGC, unsigned long pixel,
left_height = 0; left_height = 0;
right_height = 0; right_height = 0;
if (!InitSpans(&spanRec, overall_height))
return;
ppt = spanRec.points;
pwidth = spanRec.widths;
if (!spanData) if (!spanData)
{ {
pptInit = malloc(overall_height * sizeof(*ppt));
if (!pptInit)
return;
pwidthInit = malloc(overall_height * sizeof(*pwidth));
if (!pwidthInit)
{
free(pptInit);
return;
}
ppt = pptInit;
pwidth = pwidthInit;
oldPixel = pGC->fgPixel; oldPixel = pGC->fgPixel;
if (pixel != oldPixel) if (pixel != oldPixel)
{ {
@ -141,20 +147,6 @@ miFillPolyHelper (DrawablePtr pDrawable, GCPtr pGC, unsigned long pixel,
ValidateGC (pDrawable, pGC); ValidateGC (pDrawable, pGC);
} }
} }
else
{
spanRec.points = malloc(overall_height * sizeof (*ppt));
if (!spanRec.points)
return;
spanRec.widths = malloc(overall_height * sizeof (int));
if (!spanRec.widths)
{
free(spanRec.points);
return;
}
ppt = spanRec.points;
pwidth = spanRec.widths;
}
xorg = 0; xorg = 0;
if (pGC->miTranslate) if (pGC->miTranslate)
@ -226,11 +218,12 @@ miFillPolyHelper (DrawablePtr pDrawable, GCPtr pGC, unsigned long pixel,
} }
} }
} }
spanRec.count = ppt - spanRec.points;
if (!spanData) if (!spanData)
{ {
(*pGC->ops->FillSpans) (pDrawable, pGC, ppt - pptInit, pptInit, pwidthInit, TRUE); (*pGC->ops->FillSpans) (pDrawable, pGC, spanRec.count, spanRec.points, spanRec.widths, TRUE);
free(pwidthInit); free(spanRec.widths);
free(pptInit); free(spanRec.points);
if (pixel != oldPixel) if (pixel != oldPixel)
{ {
dixChangeGC (NullClient, pGC, GCForeground, &oldPixel, NULL); dixChangeGC (NullClient, pGC, GCForeground, &oldPixel, NULL);
@ -238,11 +231,8 @@ miFillPolyHelper (DrawablePtr pDrawable, GCPtr pGC, unsigned long pixel,
} }
} }
else else
{
spanRec.count = ppt - spanRec.points;
AppendSpanGroup (pGC, pixel, &spanRec, spanData); AppendSpanGroup (pGC, pixel, &spanRec, spanData);
} }
}
static void static void
miFillRectPolyHelper ( miFillRectPolyHelper (
@ -283,15 +273,8 @@ miFillRectPolyHelper (
} }
else else
{ {
spanRec.points = malloc(h * sizeof (*ppt)); if (!InitSpans(&spanRec, h))
if (!spanRec.points)
return; return;
spanRec.widths = malloc(h * sizeof (int));
if (!spanRec.widths)
{
free(spanRec.points);
return;
}
ppt = spanRec.points; ppt = spanRec.points;
pwidth = spanRec.widths; pwidth = spanRec.widths;
@ -1058,8 +1041,6 @@ miLineArc (
double yorg, double yorg,
Bool isInt) Bool isInt)
{ {
DDXPointPtr points;
int *widths;
int xorgi = 0, yorgi = 0; int xorgi = 0, yorgi = 0;
XID oldPixel; XID oldPixel;
Spans spanRec; Spans spanRec;
@ -1105,17 +1086,10 @@ miLineArc (
} }
isInt = FALSE; isInt = FALSE;
} }
if (!InitSpans(&spanRec, pGC->lineWidth))
return;
if (!spanData) if (!spanData)
{ {
points = malloc(sizeof(DDXPointRec) * pGC->lineWidth);
if (!points)
return;
widths = malloc(sizeof(int) * pGC->lineWidth);
if (!widths)
{
free(points);
return;
}
oldPixel = pGC->fgPixel; oldPixel = pGC->fgPixel;
if (pixel != oldPixel) if (pixel != oldPixel)
{ {
@ -1124,32 +1098,19 @@ miLineArc (
ValidateGC (pDraw, pGC); ValidateGC (pDraw, pGC);
} }
} }
else
{
points = malloc(pGC->lineWidth * sizeof (DDXPointRec));
if (!points)
return;
widths = malloc(pGC->lineWidth * sizeof (int));
if (!widths)
{
free(points);
return;
}
spanRec.points = points;
spanRec.widths = widths;
}
if (isInt) if (isInt)
n = miLineArcI(pDraw, pGC, xorgi, yorgi, points, widths); n = miLineArcI(pDraw, pGC, xorgi, yorgi, spanRec.points, spanRec.widths);
else else
n = miLineArcD(pDraw, pGC, xorg, yorg, points, widths, n = miLineArcD(pDraw, pGC, xorg, yorg, spanRec.points, spanRec.widths,
&edge1, edgey1, edgeleft1, &edge1, edgey1, edgeleft1,
&edge2, edgey2, edgeleft2); &edge2, edgey2, edgeleft2);
spanRec.count = n;
if (!spanData) if (!spanData)
{ {
(*pGC->ops->FillSpans)(pDraw, pGC, n, points, widths, TRUE); (*pGC->ops->FillSpans)(pDraw, pGC, spanRec.count, spanRec.points, spanRec.widths, TRUE);
free(widths); free(spanRec.widths);
free(points); free(spanRec.points);
if (pixel != oldPixel) if (pixel != oldPixel)
{ {
dixChangeGC(NullClient, pGC, GCForeground, &oldPixel, NULL); dixChangeGC(NullClient, pGC, GCForeground, &oldPixel, NULL);
@ -1157,11 +1118,8 @@ miLineArc (
} }
} }
else else
{
spanRec.count = n;
AppendSpanGroup (pGC, pixel, &spanRec, spanData); AppendSpanGroup (pGC, pixel, &spanRec, spanData);
} }
}
static void static void
miLineProjectingCap (DrawablePtr pDrawable, GCPtr pGC, unsigned long pixel, miLineProjectingCap (DrawablePtr pDrawable, GCPtr pGC, unsigned long pixel,