#include "X.h"
#include "gcstruct.h"
#include "windowstr.h"
#include "pixmapstr.h"
#include "regionstr.h"
#include "scrnintstr.h"
#include "mistruct.h"
#include "cfb.h"
#include "cfbmskbits.h"
#include "miline.h"
void
#ifdef POLYSEGMENT
cfbSegmentSS (pDrawable, pGC, nseg, pSeg)
DrawablePtr pDrawable;
GCPtr pGC;
int nseg;
register xSegment *pSeg;
#else
cfbLineSS (pDrawable, pGC, mode, npt, pptInit)
DrawablePtr pDrawable;
GCPtr pGC;
int mode;
int npt;
DDXPointPtr pptInit;
#endif
{
int nboxInit;
register int nbox;
BoxPtr pboxInit;
register BoxPtr pbox;
#ifndef POLYSEGMENT
register DDXPointPtr ppt;
#endif
unsigned int oc1;
unsigned int oc2;
CfbBits *addrl;
int nlwidth;
int xorg, yorg;
int adx;
int ady;
int signdx;
int signdy;
int e, e1, e2;
int len;
int axis;
int octant;
unsigned int bias = miGetZeroLineBias(pDrawable->pScreen);
int tmp;
register int y1, y2;
register int x1, x2;
RegionPtr cclip;
cfbPrivGCPtr devPriv;
CfbBits xor, and;
int alu;
devPriv = cfbGetGCPrivate(pGC);
cclip = pGC->pCompositeClip;
pboxInit = REGION_RECTS(cclip);
nboxInit = REGION_NUM_RECTS(cclip);
cfbGetLongWidthAndPointer (pDrawable, nlwidth, addrl)
alu = devPriv->rop;
xor = devPriv->xor;
and = devPriv->and;
xorg = pDrawable->x;
yorg = pDrawable->y;
#ifdef POLYSEGMENT
while (nseg--)
#else
ppt = pptInit;
x2 = ppt->x + xorg;
y2 = ppt->y + yorg;
while(--npt)
#endif
{
nbox = nboxInit;
pbox = pboxInit;
#ifdef POLYSEGMENT
x1 = pSeg->x1 + xorg;
y1 = pSeg->y1 + yorg;
x2 = pSeg->x2 + xorg;
y2 = pSeg->y2 + yorg;
pSeg++;
#else
x1 = x2;
y1 = y2;
++ppt;
if (mode == CoordModePrevious)
{
xorg = x1;
yorg = y1;
}
x2 = ppt->x + xorg;
y2 = ppt->y + yorg;
#endif
if (x1 == x2)
{
if (y1 > y2)
{
register int tmp;
tmp = y2;
y2 = y1 + 1;
y1 = tmp + 1;
#ifdef POLYSEGMENT
if (pGC->capStyle != CapNotLast)
y1--;
#endif
}
#ifdef POLYSEGMENT
else if (pGC->capStyle != CapNotLast)
y2++;
#endif
while ((nbox) && (pbox->y2 <= y1))
{
pbox++;
nbox--;
}
if (nbox)
{
while((nbox) && (y2 >= pbox->y1))
{
if ((x1 >= pbox->x1) && (x1 < pbox->x2))
{
int y1t, y2t;
y1t = max(y1, pbox->y1);
y2t = min(y2, pbox->y2);
if (y1t != y2t)
{
cfbVertS (alu, and, xor,
addrl, nlwidth,
x1, y1t, y2t-y1t);
}
}
nbox--;
pbox++;
}
}
#ifndef POLYSEGMENT
y2 = ppt->y + yorg;
#endif
}
else if (y1 == y2)
{
if (x1 > x2)
{
register int tmp;
tmp = x2;
x2 = x1 + 1;
x1 = tmp + 1;
#ifdef POLYSEGMENT
if (pGC->capStyle != CapNotLast)
x1--;
#endif
}
#ifdef POLYSEGMENT
else if (pGC->capStyle != CapNotLast)
x2++;
#endif
while( (nbox) && (pbox->y2 <= y1))
{
pbox++;
nbox--;
}
if ((nbox) && (pbox->y1 <= y1))
{
tmp = pbox->y1;
while((nbox) && (pbox->y1 == tmp))
{
int x1t, x2t;
if (pbox->x2 <= x1)
{
nbox--;
pbox++;
continue;
}
if (pbox->x1 >= x2)
{
nbox = 0;
break;
}
x1t = max(x1, pbox->x1);
x2t = min(x2, pbox->x2);
if (x1t != x2t)
{
cfbHorzS (alu, and, xor,
addrl, nlwidth,
x1t, y1, x2t-x1t);
}
nbox--;
pbox++;
}
}
#ifndef POLYSEGMENT
x2 = ppt->x + xorg;
#endif
}
else
{
CalcLineDeltas(x1, y1, x2, y2, adx, ady, signdx, signdy,
1, 1, octant);
if (adx > ady)
{
axis = X_AXIS;
e1 = ady << 1;
e2 = e1 - (adx << 1);
e = e1 - adx;
}
else
{
axis = Y_AXIS;
e1 = adx << 1;
e2 = e1 - (ady << 1);
e = e1 - ady;
SetYMajorOctant(octant);
}
FIXUP_ERROR(e, octant, bias);
while(nbox--)
{
oc1 = 0;
oc2 = 0;
OUTCODES(oc1, x1, y1, pbox);
OUTCODES(oc2, x2, y2, pbox);
if ((oc1 | oc2) == 0)
{
if (axis == X_AXIS)
len = adx;
else
len = ady;
#ifdef POLYSEGMENT
if (pGC->capStyle != CapNotLast)
len++;
#endif
cfbBresS (alu, and, xor,
addrl, nlwidth,
signdx, signdy, axis, x1, y1,
e, e1, e2, len);
break;
}
else if (oc1 & oc2)
{
pbox++;
}
else
{
int new_x1 = x1, new_y1 = y1, new_x2 = x2, new_y2 = y2;
int clip1 = 0, clip2 = 0;
int clipdx, clipdy;
int err;
if (miZeroClipLine(pbox->x1, pbox->y1, pbox->x2-1,
pbox->y2-1,
&new_x1, &new_y1, &new_x2, &new_y2,
adx, ady, &clip1, &clip2,
octant, bias, oc1, oc2) == -1)
{
pbox++;
continue;
}
if (axis == X_AXIS)
len = abs(new_x2 - new_x1);
else
len = abs(new_y2 - new_y1);
#ifdef POLYSEGMENT
if (clip2 != 0 || pGC->capStyle != CapNotLast)
len++;
#else
len += (clip2 != 0);
#endif
if (len)
{
if (clip1)
{
clipdx = abs(new_x1 - x1);
clipdy = abs(new_y1 - y1);
if (axis == X_AXIS)
err = e+((clipdy*e2) + ((clipdx-clipdy)*e1));
else
err = e+((clipdx*e2) + ((clipdy-clipdx)*e1));
}
else
err = e;
cfbBresS(alu, and, xor,
addrl, nlwidth,
signdx, signdy, axis, new_x1, new_y1,
err, e1, e2, len);
}
pbox++;
}
}
}
}
#ifndef POLYSEGMENT
if ((pGC->capStyle != CapNotLast) &&
((ppt->x + xorg != pptInit->x + pDrawable->x) ||
(ppt->y + yorg != pptInit->y + pDrawable->y) ||
(ppt == pptInit + 1)))
{
nbox = nboxInit;
pbox = pboxInit;
while (nbox--)
{
if ((x2 >= pbox->x1) &&
(y2 >= pbox->y1) &&
(x2 < pbox->x2) &&
(y2 < pbox->y2))
{
CfbBits mask;
CfbBits scrbits;
#if PSZ == 24
mask = cfbmask[(x2 & 3)<<1];
addrl += (y2 * nlwidth) + ((x2*3) >> 2);
#else
mask = cfbmask[x2 & PIM];
addrl += (y2 * nlwidth) + (x2 >> PWSH);
#endif
scrbits = *addrl;
*addrl = (scrbits & ~mask) |
(DoRRop (scrbits, and, xor) & mask);
break;
}
else
pbox++;
}
}
#endif
}
void
#ifdef POLYSEGMENT
cfbSegmentSD (pDrawable, pGC, nseg, pSeg)
DrawablePtr pDrawable;
register GCPtr pGC;
int nseg;
register xSegment *pSeg;
#else
cfbLineSD( pDrawable, pGC, mode, npt, pptInit)
DrawablePtr pDrawable;
register GCPtr pGC;
int mode;
int npt;
DDXPointPtr pptInit;
#endif
{
int nboxInit;
register int nbox;
BoxPtr pboxInit;
register BoxPtr pbox;
#ifndef POLYSEGMENT
register DDXPointPtr ppt;
#endif
register unsigned int oc1;
register unsigned int oc2;
CfbBits *addrl;
int nlwidth;
int xorg, yorg;
int adx;
int ady;
int signdx;
int signdy;
int e, e1, e2;
int len;
int axis;
int octant;
unsigned int bias = miGetZeroLineBias(pDrawable->pScreen);
int x1, x2, y1, y2;
RegionPtr cclip;
cfbRRopRec rrops[2];
unsigned char *pDash;
int dashOffset;
int numInDashList;
int dashIndex;
int isDoubleDash;
int dashIndexTmp, dashOffsetTmp;
int unclippedlen;
cfbPrivGCPtr devPriv;
devPriv = cfbGetGCPrivate(pGC);
cclip = pGC->pCompositeClip;
rrops[0].rop = devPriv->rop;
rrops[0].and = devPriv->and;
rrops[0].xor = devPriv->xor;
if (pGC->alu == GXcopy)
{
rrops[1].rop = GXcopy;
rrops[1].and = 0;
rrops[1].xor = PFILL (pGC->bgPixel);
}
else
{
rrops[1].rop = cfbReduceRasterOp (pGC->alu,
pGC->bgPixel, pGC->planemask,
&rrops[1].and, &rrops[1].xor);
}
pboxInit = REGION_RECTS(cclip);
nboxInit = REGION_NUM_RECTS(cclip);
cfbGetLongWidthAndPointer (pDrawable, nlwidth, addrl)
pDash = (unsigned char *) pGC->dash;
numInDashList = pGC->numInDashList;
isDoubleDash = (pGC->lineStyle == LineDoubleDash);
dashIndex = 0;
dashOffset = 0;
miStepDash ((int)pGC->dashOffset, &dashIndex, pDash,
numInDashList, &dashOffset);
xorg = pDrawable->x;
yorg = pDrawable->y;
#ifdef POLYSEGMENT
while (nseg--)
#else
ppt = pptInit;
x2 = ppt->x + xorg;
y2 = ppt->y + yorg;
while(--npt)
#endif
{
nbox = nboxInit;
pbox = pboxInit;
#ifdef POLYSEGMENT
x1 = pSeg->x1 + xorg;
y1 = pSeg->y1 + yorg;
x2 = pSeg->x2 + xorg;
y2 = pSeg->y2 + yorg;
pSeg++;
#else
x1 = x2;
y1 = y2;
++ppt;
if (mode == CoordModePrevious)
{
xorg = x1;
yorg = y1;
}
x2 = ppt->x + xorg;
y2 = ppt->y + yorg;
#endif
CalcLineDeltas(x1, y1, x2, y2, adx, ady, signdx, signdy, 1, 1, octant);
if (adx > ady)
{
axis = X_AXIS;
e1 = ady << 1;
e2 = e1 - (adx << 1);
e = e1 - adx;
unclippedlen = adx;
}
else
{
axis = Y_AXIS;
e1 = adx << 1;
e2 = e1 - (ady << 1);
e = e1 - ady;
unclippedlen = ady;
SetYMajorOctant(octant);
}
FIXUP_ERROR(e, octant, bias);
while(nbox--)
{
oc1 = 0;
oc2 = 0;
OUTCODES(oc1, x1, y1, pbox);
OUTCODES(oc2, x2, y2, pbox);
if ((oc1 | oc2) == 0)
{
#ifdef POLYSEGMENT
if (pGC->capStyle != CapNotLast)
unclippedlen++;
dashIndexTmp = dashIndex;
dashOffsetTmp = dashOffset;
cfbBresD (rrops,
&dashIndexTmp, pDash, numInDashList,
&dashOffsetTmp, isDoubleDash,
addrl, nlwidth,
signdx, signdy, axis, x1, y1,
e, e1, e2, unclippedlen);
break;
#else
cfbBresD (rrops,
&dashIndex, pDash, numInDashList,
&dashOffset, isDoubleDash,
addrl, nlwidth,
signdx, signdy, axis, x1, y1,
e, e1, e2, unclippedlen);
goto dontStep;
#endif
}
else if (oc1 & oc2)
{
pbox++;
}
else
{
int new_x1 = x1, new_y1 = y1, new_x2 = x2, new_y2 = y2;
int clip1 = 0, clip2 = 0;
int clipdx, clipdy;
int err;
if (miZeroClipLine(pbox->x1, pbox->y1, pbox->x2-1,
pbox->y2-1,
&new_x1, &new_y1, &new_x2, &new_y2,
adx, ady, &clip1, &clip2,
octant, bias, oc1, oc2) == -1)
{
pbox++;
continue;
}
dashIndexTmp = dashIndex;
dashOffsetTmp = dashOffset;
if (clip1)
{
int dlen;
if (axis == X_AXIS)
dlen = abs(new_x1 - x1);
else
dlen = abs(new_y1 - y1);
miStepDash (dlen, &dashIndexTmp, pDash,
numInDashList, &dashOffsetTmp);
}
if (axis == X_AXIS)
len = abs(new_x2 - new_x1);
else
len = abs(new_y2 - new_y1);
#ifdef POLYSEGMENT
if (clip2 != 0 || pGC->capStyle != CapNotLast)
len++;
#else
len += (clip2 != 0);
#endif
if (len)
{
if (clip1)
{
clipdx = abs(new_x1 - x1);
clipdy = abs(new_y1 - y1);
if (axis == X_AXIS)
err = e+((clipdy*e2) + ((clipdx-clipdy)*e1));
else
err = e+((clipdx*e2) + ((clipdy-clipdx)*e1));
}
else
err = e;
cfbBresD (rrops,
&dashIndexTmp, pDash, numInDashList,
&dashOffsetTmp, isDoubleDash,
addrl, nlwidth,
signdx, signdy, axis, new_x1, new_y1,
err, e1, e2, len);
}
pbox++;
}
}
#ifndef POLYSEGMENT
miStepDash (unclippedlen, &dashIndex, pDash,
numInDashList, &dashOffset);
dontStep: ;
#endif
}
#ifndef POLYSEGMENT
if ((pGC->capStyle != CapNotLast) &&
((dashIndex & 1) == 0 || isDoubleDash) &&
((ppt->x + xorg != pptInit->x + pDrawable->x) ||
(ppt->y + yorg != pptInit->y + pDrawable->y) ||
(ppt == pptInit + 1)))
{
nbox = nboxInit;
pbox = pboxInit;
while (nbox--)
{
if ((x2 >= pbox->x1) &&
(y2 >= pbox->y1) &&
(x2 < pbox->x2) &&
(y2 < pbox->y2))
{
CfbBits mask;
int pix;
pix = 0;
if (dashIndex & 1)
pix = 1;
#if PSZ == 24
mask = cfbmask[(x2 & 3)<<1];
addrl += (y2 * nlwidth) + ((x2 *3)>> 2);
#else
mask = cfbmask[x2 & PIM];
addrl += (y2 * nlwidth) + (x2 >> PWSH);
#endif
*addrl = DoMaskRRop (*addrl, rrops[pix].and, rrops[pix].xor, mask);
break;
}
else
pbox++;
}
}
#endif
}