You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
420 lines
16 KiB
420 lines
16 KiB
6 years ago
|
From 9426c5500b72e1fe004fef4c3b259023c4ec49f7 Mon Sep 17 00:00:00 2001
|
||
|
From: Adam Jackson <ajax@redhat.com>
|
||
|
Date: Wed, 1 Mar 2017 16:13:57 -0500
|
||
|
Subject: [PATCH 1/3] miarc: Style cleanup for miWideArc
|
||
|
|
||
|
Outdent, normalize comment formatting, and use 'goto out' idiom for
|
||
|
error paths. No functional change.
|
||
|
|
||
|
Reviewed-by: Keith Packard <keithp@keithp.com>
|
||
|
Signed-off-by: Adam Jackson <ajax@redhat.com>
|
||
|
---
|
||
|
mi/miarc.c | 368 ++++++++++++++++++++++++++++++-------------------------------
|
||
|
1 file changed, 179 insertions(+), 189 deletions(-)
|
||
|
|
||
|
diff --git a/mi/miarc.c b/mi/miarc.c
|
||
|
index 2588ee48a..fed5c9fa3 100644
|
||
|
--- a/mi/miarc.c
|
||
|
+++ b/mi/miarc.c
|
||
|
@@ -894,7 +894,7 @@ miWideArc(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc * parcs)
|
||
|
int xMin, xMax, yMin, yMax;
|
||
|
int pixmapWidth = 0, pixmapHeight = 0;
|
||
|
int xOrg = 0, yOrg = 0;
|
||
|
- int width;
|
||
|
+ int width = pGC->lineWidth;
|
||
|
Bool fTricky;
|
||
|
DrawablePtr pDrawTo;
|
||
|
CARD32 fg, bg;
|
||
|
@@ -904,210 +904,200 @@ miWideArc(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc * parcs)
|
||
|
int iphase;
|
||
|
int halfWidth;
|
||
|
|
||
|
- width = pGC->lineWidth;
|
||
|
if (width == 0 && pGC->lineStyle == LineSolid) {
|
||
|
for (i = narcs, parc = parcs; --i >= 0; parc++)
|
||
|
- miArcSegment(pDraw, pGC, *parc, (miArcFacePtr) 0, (miArcFacePtr) 0);
|
||
|
+ miArcSegment(pDraw, pGC, *parc, NULL, NULL);
|
||
|
fillSpans(pDraw, pGC);
|
||
|
+ return;
|
||
|
}
|
||
|
- else {
|
||
|
- if ((pGC->lineStyle == LineSolid) && narcs) {
|
||
|
- while (parcs->width && parcs->height &&
|
||
|
- (parcs->angle2 >= FULLCIRCLE ||
|
||
|
- parcs->angle2 <= -FULLCIRCLE)) {
|
||
|
- miFillWideEllipse(pDraw, pGC, parcs);
|
||
|
- if (!--narcs)
|
||
|
- return;
|
||
|
- parcs++;
|
||
|
- }
|
||
|
- }
|
||
|
-
|
||
|
- /* Set up pDrawTo and pGCTo based on the rasterop */
|
||
|
- switch (pGC->alu) {
|
||
|
- case GXclear: /* 0 */
|
||
|
- case GXcopy: /* src */
|
||
|
- case GXcopyInverted: /* NOT src */
|
||
|
- case GXset: /* 1 */
|
||
|
- fTricky = FALSE;
|
||
|
- pDrawTo = pDraw;
|
||
|
- pGCTo = pGC;
|
||
|
- break;
|
||
|
- default:
|
||
|
- fTricky = TRUE;
|
||
|
-
|
||
|
- /* find bounding box around arcs */
|
||
|
- xMin = yMin = MAXSHORT;
|
||
|
- xMax = yMax = MINSHORT;
|
||
|
-
|
||
|
- for (i = narcs, parc = parcs; --i >= 0; parc++) {
|
||
|
- xMin = min(xMin, parc->x);
|
||
|
- yMin = min(yMin, parc->y);
|
||
|
- xMax = max(xMax, (parc->x + (int) parc->width));
|
||
|
- yMax = max(yMax, (parc->y + (int) parc->height));
|
||
|
- }
|
||
|
-
|
||
|
- /* expand box to deal with line widths */
|
||
|
- halfWidth = (width + 1) / 2;
|
||
|
- xMin -= halfWidth;
|
||
|
- yMin -= halfWidth;
|
||
|
- xMax += halfWidth;
|
||
|
- yMax += halfWidth;
|
||
|
-
|
||
|
- /* compute pixmap size; limit it to size of drawable */
|
||
|
- xOrg = max(xMin, 0);
|
||
|
- yOrg = max(yMin, 0);
|
||
|
- pixmapWidth = min(xMax, pDraw->width) - xOrg;
|
||
|
- pixmapHeight = min(yMax, pDraw->height) - yOrg;
|
||
|
-
|
||
|
- /* if nothing left, return */
|
||
|
- if ((pixmapWidth <= 0) || (pixmapHeight <= 0))
|
||
|
- return;
|
||
|
-
|
||
|
- for (i = narcs, parc = parcs; --i >= 0; parc++) {
|
||
|
- parc->x -= xOrg;
|
||
|
- parc->y -= yOrg;
|
||
|
- }
|
||
|
- if (pGC->miTranslate) {
|
||
|
- xOrg += pDraw->x;
|
||
|
- yOrg += pDraw->y;
|
||
|
- }
|
||
|
-
|
||
|
- /* set up scratch GC */
|
||
|
-
|
||
|
- pGCTo = GetScratchGC(1, pDraw->pScreen);
|
||
|
- if (!pGCTo)
|
||
|
- return;
|
||
|
- {
|
||
|
- ChangeGCVal gcvals[6];
|
||
|
-
|
||
|
- gcvals[0].val = GXcopy;
|
||
|
- gcvals[1].val = 1;
|
||
|
- gcvals[2].val = 0;
|
||
|
- gcvals[3].val = pGC->lineWidth;
|
||
|
- gcvals[4].val = pGC->capStyle;
|
||
|
- gcvals[5].val = pGC->joinStyle;
|
||
|
- ChangeGC(NullClient, pGCTo, GCFunction |
|
||
|
- GCForeground | GCBackground | GCLineWidth |
|
||
|
- GCCapStyle | GCJoinStyle, gcvals);
|
||
|
- }
|
||
|
|
||
|
- /* allocate a 1 bit deep pixmap of the appropriate size, and
|
||
|
- * validate it */
|
||
|
- pDrawTo = (DrawablePtr) (*pDraw->pScreen->CreatePixmap)
|
||
|
- (pDraw->pScreen, pixmapWidth, pixmapHeight, 1,
|
||
|
- CREATE_PIXMAP_USAGE_SCRATCH);
|
||
|
- if (!pDrawTo) {
|
||
|
- FreeScratchGC(pGCTo);
|
||
|
+ if ((pGC->lineStyle == LineSolid) && narcs) {
|
||
|
+ while (parcs->width && parcs->height &&
|
||
|
+ (parcs->angle2 >= FULLCIRCLE || parcs->angle2 <= -FULLCIRCLE)) {
|
||
|
+ miFillWideEllipse(pDraw, pGC, parcs);
|
||
|
+ if (!--narcs)
|
||
|
return;
|
||
|
- }
|
||
|
- ValidateGC(pDrawTo, pGCTo);
|
||
|
- miClearDrawable(pDrawTo, pGCTo);
|
||
|
+ parcs++;
|
||
|
}
|
||
|
+ }
|
||
|
|
||
|
- fg = pGC->fgPixel;
|
||
|
- bg = pGC->bgPixel;
|
||
|
- if ((pGC->fillStyle == FillTiled) ||
|
||
|
- (pGC->fillStyle == FillOpaqueStippled))
|
||
|
- bg = fg; /* the protocol sez these don't cause color changes */
|
||
|
+ /* Set up pDrawTo and pGCTo based on the rasterop */
|
||
|
+ switch (pGC->alu) {
|
||
|
+ case GXclear: /* 0 */
|
||
|
+ case GXcopy: /* src */
|
||
|
+ case GXcopyInverted: /* NOT src */
|
||
|
+ case GXset: /* 1 */
|
||
|
+ fTricky = FALSE;
|
||
|
+ pDrawTo = pDraw;
|
||
|
+ pGCTo = pGC;
|
||
|
+ break;
|
||
|
+ default:
|
||
|
+ fTricky = TRUE;
|
||
|
+
|
||
|
+ /* find bounding box around arcs */
|
||
|
+ xMin = yMin = MAXSHORT;
|
||
|
+ xMax = yMax = MINSHORT;
|
||
|
+
|
||
|
+ for (i = narcs, parc = parcs; --i >= 0; parc++) {
|
||
|
+ xMin = min(xMin, parc->x);
|
||
|
+ yMin = min(yMin, parc->y);
|
||
|
+ xMax = max(xMax, (parc->x + (int) parc->width));
|
||
|
+ yMax = max(yMax, (parc->y + (int) parc->height));
|
||
|
+ }
|
||
|
+
|
||
|
+ /* expand box to deal with line widths */
|
||
|
+ halfWidth = (width + 1) / 2;
|
||
|
+ xMin -= halfWidth;
|
||
|
+ yMin -= halfWidth;
|
||
|
+ xMax += halfWidth;
|
||
|
+ yMax += halfWidth;
|
||
|
+
|
||
|
+ /* compute pixmap size; limit it to size of drawable */
|
||
|
+ xOrg = max(xMin, 0);
|
||
|
+ yOrg = max(yMin, 0);
|
||
|
+ pixmapWidth = min(xMax, pDraw->width) - xOrg;
|
||
|
+ pixmapHeight = min(yMax, pDraw->height) - yOrg;
|
||
|
+
|
||
|
+ /* if nothing left, return */
|
||
|
+ if ((pixmapWidth <= 0) || (pixmapHeight <= 0))
|
||
|
+ return;
|
||
|
|
||
|
- polyArcs = miComputeArcs(parcs, narcs, pGC);
|
||
|
+ for (i = narcs, parc = parcs; --i >= 0; parc++) {
|
||
|
+ parc->x -= xOrg;
|
||
|
+ parc->y -= yOrg;
|
||
|
+ }
|
||
|
+ if (pGC->miTranslate) {
|
||
|
+ xOrg += pDraw->x;
|
||
|
+ yOrg += pDraw->y;
|
||
|
+ }
|
||
|
|
||
|
- if (!polyArcs) {
|
||
|
- if (fTricky) {
|
||
|
- (*pDraw->pScreen->DestroyPixmap) ((PixmapPtr) pDrawTo);
|
||
|
- FreeScratchGC(pGCTo);
|
||
|
- }
|
||
|
+ /* set up scratch GC */
|
||
|
+ pGCTo = GetScratchGC(1, pDraw->pScreen);
|
||
|
+ if (!pGCTo)
|
||
|
+ return;
|
||
|
+ {
|
||
|
+ ChangeGCVal gcvals[6];
|
||
|
+
|
||
|
+ gcvals[0].val = GXcopy;
|
||
|
+ gcvals[1].val = 1;
|
||
|
+ gcvals[2].val = 0;
|
||
|
+ gcvals[3].val = pGC->lineWidth;
|
||
|
+ gcvals[4].val = pGC->capStyle;
|
||
|
+ gcvals[5].val = pGC->joinStyle;
|
||
|
+ ChangeGC(NullClient, pGCTo, GCFunction |
|
||
|
+ GCForeground | GCBackground | GCLineWidth |
|
||
|
+ GCCapStyle | GCJoinStyle, gcvals);
|
||
|
+ }
|
||
|
+
|
||
|
+ /* allocate a bitmap of the appropriate size, and validate it */
|
||
|
+ pDrawTo = (DrawablePtr) (*pDraw->pScreen->CreatePixmap)
|
||
|
+ (pDraw->pScreen, pixmapWidth, pixmapHeight, 1,
|
||
|
+ CREATE_PIXMAP_USAGE_SCRATCH);
|
||
|
+ if (!pDrawTo) {
|
||
|
+ FreeScratchGC(pGCTo);
|
||
|
return;
|
||
|
}
|
||
|
-
|
||
|
- cap[0] = cap[1] = 0;
|
||
|
- join[0] = join[1] = 0;
|
||
|
- for (iphase = ((pGC->lineStyle == LineDoubleDash) ? 1 : 0);
|
||
|
- iphase >= 0; iphase--) {
|
||
|
- ChangeGCVal gcval;
|
||
|
-
|
||
|
- if (iphase == 1) {
|
||
|
- gcval.val = bg;
|
||
|
- ChangeGC(NullClient, pGC, GCForeground, &gcval);
|
||
|
- ValidateGC(pDraw, pGC);
|
||
|
- }
|
||
|
- else if (pGC->lineStyle == LineDoubleDash) {
|
||
|
- gcval.val = fg;
|
||
|
- ChangeGC(NullClient, pGC, GCForeground, &gcval);
|
||
|
- ValidateGC(pDraw, pGC);
|
||
|
- }
|
||
|
- for (i = 0; i < polyArcs[iphase].narcs; i++) {
|
||
|
- miArcDataPtr arcData;
|
||
|
-
|
||
|
- arcData = &polyArcs[iphase].arcs[i];
|
||
|
- miArcSegment(pDrawTo, pGCTo, arcData->arc,
|
||
|
- &arcData->bounds[RIGHT_END],
|
||
|
- &arcData->bounds[LEFT_END]);
|
||
|
- if (polyArcs[iphase].arcs[i].render) {
|
||
|
- fillSpans(pDrawTo, pGCTo);
|
||
|
- /*
|
||
|
- * don't cap self-joining arcs
|
||
|
- */
|
||
|
- if (polyArcs[iphase].arcs[i].selfJoin &&
|
||
|
- cap[iphase] < polyArcs[iphase].arcs[i].cap)
|
||
|
- cap[iphase]++;
|
||
|
- while (cap[iphase] < polyArcs[iphase].arcs[i].cap) {
|
||
|
- int arcIndex, end;
|
||
|
- miArcDataPtr arcData0;
|
||
|
-
|
||
|
- arcIndex = polyArcs[iphase].caps[cap[iphase]].arcIndex;
|
||
|
- end = polyArcs[iphase].caps[cap[iphase]].end;
|
||
|
- arcData0 = &polyArcs[iphase].arcs[arcIndex];
|
||
|
- miArcCap(pDrawTo, pGCTo,
|
||
|
- &arcData0->bounds[end], end,
|
||
|
- arcData0->arc.x, arcData0->arc.y,
|
||
|
- (double) arcData0->arc.width / 2.0,
|
||
|
- (double) arcData0->arc.height / 2.0);
|
||
|
- ++cap[iphase];
|
||
|
- }
|
||
|
- while (join[iphase] < polyArcs[iphase].arcs[i].join) {
|
||
|
- int arcIndex0, arcIndex1, end0, end1;
|
||
|
- int phase0, phase1;
|
||
|
- miArcDataPtr arcData0, arcData1;
|
||
|
- miArcJoinPtr joinp;
|
||
|
-
|
||
|
- joinp = &polyArcs[iphase].joins[join[iphase]];
|
||
|
- arcIndex0 = joinp->arcIndex0;
|
||
|
- end0 = joinp->end0;
|
||
|
- arcIndex1 = joinp->arcIndex1;
|
||
|
- end1 = joinp->end1;
|
||
|
- phase0 = joinp->phase0;
|
||
|
- phase1 = joinp->phase1;
|
||
|
- arcData0 = &polyArcs[phase0].arcs[arcIndex0];
|
||
|
- arcData1 = &polyArcs[phase1].arcs[arcIndex1];
|
||
|
- miArcJoin(pDrawTo, pGCTo,
|
||
|
- &arcData0->bounds[end0],
|
||
|
- &arcData1->bounds[end1],
|
||
|
- arcData0->arc.x, arcData0->arc.y,
|
||
|
- (double) arcData0->arc.width / 2.0,
|
||
|
- (double) arcData0->arc.height / 2.0,
|
||
|
- arcData1->arc.x, arcData1->arc.y,
|
||
|
- (double) arcData1->arc.width / 2.0,
|
||
|
- (double) arcData1->arc.height / 2.0);
|
||
|
- ++join[iphase];
|
||
|
- }
|
||
|
- if (fTricky) {
|
||
|
- if (pGC->serialNumber != pDraw->serialNumber)
|
||
|
- ValidateGC(pDraw, pGC);
|
||
|
- (*pGC->ops->PushPixels) (pGC, (PixmapPtr) pDrawTo,
|
||
|
- pDraw, pixmapWidth,
|
||
|
- pixmapHeight, xOrg, yOrg);
|
||
|
- miClearDrawable((DrawablePtr) pDrawTo, pGCTo);
|
||
|
- }
|
||
|
+ ValidateGC(pDrawTo, pGCTo);
|
||
|
+ miClearDrawable(pDrawTo, pGCTo);
|
||
|
+ }
|
||
|
+
|
||
|
+ fg = pGC->fgPixel;
|
||
|
+ bg = pGC->bgPixel;
|
||
|
+
|
||
|
+ /* the protocol sez these don't cause color changes */
|
||
|
+ if ((pGC->fillStyle == FillTiled) ||
|
||
|
+ (pGC->fillStyle == FillOpaqueStippled))
|
||
|
+ bg = fg;
|
||
|
+
|
||
|
+ polyArcs = miComputeArcs(parcs, narcs, pGC);
|
||
|
+ if (!polyArcs)
|
||
|
+ goto out;
|
||
|
+
|
||
|
+ cap[0] = cap[1] = 0;
|
||
|
+ join[0] = join[1] = 0;
|
||
|
+ for (iphase = (pGC->lineStyle == LineDoubleDash); iphase >= 0; iphase--) {
|
||
|
+ ChangeGCVal gcval;
|
||
|
+
|
||
|
+ if (iphase == 1) {
|
||
|
+ gcval.val = bg;
|
||
|
+ ChangeGC(NullClient, pGC, GCForeground, &gcval);
|
||
|
+ ValidateGC(pDraw, pGC);
|
||
|
+ }
|
||
|
+ else if (pGC->lineStyle == LineDoubleDash) {
|
||
|
+ gcval.val = fg;
|
||
|
+ ChangeGC(NullClient, pGC, GCForeground, &gcval);
|
||
|
+ ValidateGC(pDraw, pGC);
|
||
|
+ }
|
||
|
+ for (i = 0; i < polyArcs[iphase].narcs; i++) {
|
||
|
+ miArcDataPtr arcData;
|
||
|
+
|
||
|
+ arcData = &polyArcs[iphase].arcs[i];
|
||
|
+ miArcSegment(pDrawTo, pGCTo, arcData->arc,
|
||
|
+ &arcData->bounds[RIGHT_END],
|
||
|
+ &arcData->bounds[LEFT_END]);
|
||
|
+ if (polyArcs[iphase].arcs[i].render) {
|
||
|
+ fillSpans(pDrawTo, pGCTo);
|
||
|
+ /* don't cap self-joining arcs */
|
||
|
+ if (polyArcs[iphase].arcs[i].selfJoin &&
|
||
|
+ cap[iphase] < polyArcs[iphase].arcs[i].cap)
|
||
|
+ cap[iphase]++;
|
||
|
+ while (cap[iphase] < polyArcs[iphase].arcs[i].cap) {
|
||
|
+ int arcIndex, end;
|
||
|
+ miArcDataPtr arcData0;
|
||
|
+
|
||
|
+ arcIndex = polyArcs[iphase].caps[cap[iphase]].arcIndex;
|
||
|
+ end = polyArcs[iphase].caps[cap[iphase]].end;
|
||
|
+ arcData0 = &polyArcs[iphase].arcs[arcIndex];
|
||
|
+ miArcCap(pDrawTo, pGCTo,
|
||
|
+ &arcData0->bounds[end], end,
|
||
|
+ arcData0->arc.x, arcData0->arc.y,
|
||
|
+ (double) arcData0->arc.width / 2.0,
|
||
|
+ (double) arcData0->arc.height / 2.0);
|
||
|
+ ++cap[iphase];
|
||
|
+ }
|
||
|
+ while (join[iphase] < polyArcs[iphase].arcs[i].join) {
|
||
|
+ int arcIndex0, arcIndex1, end0, end1;
|
||
|
+ int phase0, phase1;
|
||
|
+ miArcDataPtr arcData0, arcData1;
|
||
|
+ miArcJoinPtr joinp;
|
||
|
+
|
||
|
+ joinp = &polyArcs[iphase].joins[join[iphase]];
|
||
|
+ arcIndex0 = joinp->arcIndex0;
|
||
|
+ end0 = joinp->end0;
|
||
|
+ arcIndex1 = joinp->arcIndex1;
|
||
|
+ end1 = joinp->end1;
|
||
|
+ phase0 = joinp->phase0;
|
||
|
+ phase1 = joinp->phase1;
|
||
|
+ arcData0 = &polyArcs[phase0].arcs[arcIndex0];
|
||
|
+ arcData1 = &polyArcs[phase1].arcs[arcIndex1];
|
||
|
+ miArcJoin(pDrawTo, pGCTo,
|
||
|
+ &arcData0->bounds[end0],
|
||
|
+ &arcData1->bounds[end1],
|
||
|
+ arcData0->arc.x, arcData0->arc.y,
|
||
|
+ (double) arcData0->arc.width / 2.0,
|
||
|
+ (double) arcData0->arc.height / 2.0,
|
||
|
+ arcData1->arc.x, arcData1->arc.y,
|
||
|
+ (double) arcData1->arc.width / 2.0,
|
||
|
+ (double) arcData1->arc.height / 2.0);
|
||
|
+ ++join[iphase];
|
||
|
+ }
|
||
|
+ if (fTricky) {
|
||
|
+ if (pGC->serialNumber != pDraw->serialNumber)
|
||
|
+ ValidateGC(pDraw, pGC);
|
||
|
+ (*pGC->ops->PushPixels) (pGC, (PixmapPtr) pDrawTo,
|
||
|
+ pDraw, pixmapWidth,
|
||
|
+ pixmapHeight, xOrg, yOrg);
|
||
|
+ miClearDrawable((DrawablePtr) pDrawTo, pGCTo);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
- miFreeArcs(polyArcs, pGC);
|
||
|
+ }
|
||
|
+ miFreeArcs(polyArcs, pGC);
|
||
|
|
||
|
- if (fTricky) {
|
||
|
- (*pGCTo->pScreen->DestroyPixmap) ((PixmapPtr) pDrawTo);
|
||
|
- FreeScratchGC(pGCTo);
|
||
|
- }
|
||
|
+out:
|
||
|
+ if (fTricky) {
|
||
|
+ (*pGCTo->pScreen->DestroyPixmap) ((PixmapPtr) pDrawTo);
|
||
|
+ FreeScratchGC(pGCTo);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
--
|
||
|
2.12.0
|
||
|
|