1 /***********************************************************
3 Copyright (c) 1987 X Consortium
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of the X Consortium shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from the X Consortium.
27 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
31 Permission to use, copy, modify, and distribute this software and its
32 documentation for any purpose and without fee is hereby granted,
33 provided that the above copyright notice appear in all copies and that
34 both that copyright notice and this permission notice appear in
35 supporting documentation, and that the name of Digital not be
36 used in advertising or publicity pertaining to distribution of the
37 software without specific, written prior permission.
39 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47 ******************************************************************/
49 #ifdef HAVE_DIX_CONFIG_H
50 #include <dix-config.h>
57 #include "windowstr.h"
58 #include "pixmapstr.h"
59 #include "regionstr.h"
60 #include "scrnintstr.h"
67 /* single-pixel lines on a color frame buffer
70 horizontal lines are always drawn left to right; we have to
71 move the endpoints right by one after they're swapped.
72 horizontal lines will be confined to a single band of a
73 region. the code finds that band (giving up if the lower
74 bound of the band is above the line we're drawing); then it
75 finds the first box in that band that contains part of the
76 line. we clip the line to subsequent boxes in that band.
77 vertical lines are always drawn top to bottom (y-increasing.)
78 this requires adding one to the y-coordinate of each endpoint
82 when clipping a sloped line, we bring the second point inside
83 the clipping box, rather than one beyond it, and then add 1 to
84 the length of the line before drawing it. this lets us use
85 the same box for finding the outcodes for both endpoints. since
86 the equation for clipping the second endpoint to an edge gives us
87 1 beyond the edge, we then have to move the point towards the
88 first point by one step on the major axis.
89 eventually, there will be a diagram here to explain what's going
90 on. the method uses Cohen-Sutherland outcodes to determine
91 outsideness, and a method similar to Pike's layers for doing the
98 afbSegmentSS(pDrawable
, pGC
, nseg
, pSeg
)
99 DrawablePtr pDrawable
;
102 register xSegment
*pSeg
;
104 afbLineSS(pDrawable
, pGC
, mode
, npt
, pptInit
)
105 DrawablePtr pDrawable
;
107 int mode
; /* Origin or Previous */
108 int npt
; /* number of points */
115 register BoxPtr pbox
;
117 register DDXPointPtr ppt
; /* pointer to list of translated points */
120 unsigned int oc1
; /* outcode of point 1 */
121 unsigned int oc2
; /* outcode of point 2 */
123 PixelType
*addrlBase
; /* pointer to start of drawable */
124 int nlwidth
; /* width in longwords of destination pixmap */
125 int xorg
, yorg
; /* origin of window */
127 int adx
; /* abs values of dx and dy */
129 int signdx
; /* sign of dx and dy */
131 int e
, e1
, e2
; /* bresenham error and increments */
132 int len
; /* length of segment */
133 int axis
; /* major axis */
135 unsigned int bias
= miGetZeroLineBias(pDrawable
->pScreen
);
138 PixelType
*addrl
; /* address of destination pixmap */
142 unsigned char *rrops
;
144 /* a bunch of temporaries */
149 cclip
= pGC
->pCompositeClip
;
150 rrops
= ((afbPrivGC
*)(pGC
->devPrivates
[afbGCPrivateIndex
].ptr
))->rrops
;
151 pboxInit
= REGION_RECTS(cclip
);
152 nboxInit
= REGION_NUM_RECTS(cclip
);
154 afbGetPixelWidthSizeDepthAndPointer(pDrawable
, nlwidth
, sizeDst
, depthDst
,
172 x1
= pSeg
->x1
+ xorg
;
173 y1
= pSeg
->y1
+ yorg
;
174 x2
= pSeg
->x2
+ xorg
;
175 y2
= pSeg
->y2
+ yorg
;
181 if (mode
== CoordModePrevious
) {
189 if (x1
== x2
) /* vertical line */
191 /* make the line go top to bottom of screen, keeping
201 if (pGC
->capStyle
!= CapNotLast
)
206 else if (pGC
->capStyle
!= CapNotLast
)
209 /* get to first band that might contain part of line */
210 while ((nbox
) && (pbox
->y2
<= y1
)) {
216 /* stop when lower edge of box is beyond end of line */
217 while((nbox
) && (y2
>= pbox
->y1
)) {
218 if ((x1
>= pbox
->x1
) && (x1
< pbox
->x2
)) {
220 /* this box has part of the line in it */
221 y1t
= max(y1
, pbox
->y1
);
222 y2t
= min(y2
, pbox
->y2
);
224 afbVertS(addrlBase
, nlwidth
, sizeDst
, depthDst
, x1
, y1t
,
225 y2t
-y1t
, rrops
); /* @@@ NEXT PLANE PASSED @@@ */
234 } else if (y1
== y2
) /* horizontal line */ {
235 /* force line from left to right, keeping
245 if (pGC
->capStyle
!= CapNotLast
)
250 else if (pGC
->capStyle
!= CapNotLast
)
254 /* find the correct band */
255 while( (nbox
) && (pbox
->y2
<= y1
)) {
260 /* try to draw the line, if we haven't gone beyond it */
261 if ((nbox
) && (pbox
->y1
<= y1
)) {
264 /* when we leave this band, we're done */
266 while((nbox
) && (pbox
->y1
== tmp
)) {
269 if (pbox
->x2
<= x1
) {
270 /* skip boxes until one might contain start point */
276 /* stop if left of box is beyond right of line */
277 if (pbox
->x1
>= x2
) {
282 x1t
= max(x1
, pbox
->x1
);
283 x2t
= min(x2
, pbox
->x2
);
285 afbHorzS(addrlBase
, nlwidth
, sizeDst
, depthDst
, x1t
, y1
,
286 x2t
-x1t
, rrops
); /* @@@ NEXT PLANE PASSED @@@ */
295 else /* sloped line */
297 CalcLineDeltas(x1
, y1
, x2
, y2
, adx
, ady
,
298 signdx
, signdy
, 1, 1, octant
);
303 e2
= e1
- (adx
<< 1);
308 e2
= e1
- (ady
<< 1);
310 SetYMajorOctant(octant
);
313 FIXUP_ERROR(e
, octant
, bias
);
315 /* we have bresenham parameters and two points.
316 all we have to do now is clip and draw.
322 OUTCODES(oc1
, x1
, y1
, pbox
);
323 OUTCODES(oc2
, x2
, y2
, pbox
);
324 if ((oc1
| oc2
) == 0) {
330 if (pGC
->capStyle
!= CapNotLast
)
333 afbBresS(addrlBase
, nlwidth
, sizeDst
, depthDst
, signdx
, signdy
,
334 axis
, x1
, y1
, e
, e1
, e2
, len
, rrops
); /* @@@ NEXT PLANE PASSED @@@ */
336 } else if (oc1
& oc2
) {
339 int new_x1
= x1
, new_y1
= y1
, new_x2
= x2
, new_y2
= y2
;
340 int clip1
= 0, clip2
= 0;
344 if (miZeroClipLine(pbox
->x1
, pbox
->y1
, pbox
->x2
-1,
346 &new_x1
, &new_y1
, &new_x2
, &new_y2
,
347 adx
, ady
, &clip1
, &clip2
,
348 octant
, bias
, oc1
, oc2
) == -1) {
354 len
= abs(new_x2
- new_x1
);
356 len
= abs(new_y2
- new_y1
);
358 if (clip2
!= 0 || pGC
->capStyle
!= CapNotLast
)
364 /* unwind bresenham error term to first point */
366 clipdx
= abs(new_x1
- x1
);
367 clipdy
= abs(new_y1
- y1
);
369 err
= e
+((clipdy
*e2
) + ((clipdx
-clipdy
)*e1
));
371 err
= e
+((clipdx
*e2
) + ((clipdy
-clipdx
)*e1
));
375 afbBresS(addrlBase
, nlwidth
, sizeDst
, depthDst
, signdx
,
376 signdy
, axis
, new_x1
, new_y1
, err
, e1
, e2
, len
,
377 rrops
); /* @@@ NEXT PLANE PASSED @@@ */
381 } /* while (nbox--) */
383 } /* while (nline--) */
387 /* paint the last point if the end style isn't CapNotLast.
388 (Assume that a projecting, butt, or round cap that is one
389 pixel wide is the same as the single pixel of the endpoint.)
392 if ((pGC
->capStyle
!= CapNotLast
) &&
393 ((ppt
->x
+ xorg
!= pptInit
->x
+ pDrawable
->x
) ||
394 (ppt
->y
+ yorg
!= pptInit
->y
+ pDrawable
->y
) ||
395 (ppt
== pptInit
+ 1))) {
399 if ((x2
>= pbox
->x1
) && (y2
>= pbox
->y1
) && (x2
< pbox
->x2
) &&
401 for (d
= 0; d
< depthDst
; d
++) {
402 addrl
= afbScanline(addrlBase
, x2
, y2
, nlwidth
);
403 addrlBase
+= sizeDst
; /* @@@ NEXT PLANE @@@ */
407 *addrl
&= mfbGetrmask(x2
& PIM
);
410 *addrl
|= mfbGetmask(x2
& PIM
);
413 *addrl
^= mfbGetmask(x2
& PIM
);
418 } /* for (d = ...) */
428 * Draw dashed 1-pixel lines.
433 afbSegmentSD(pDrawable
, pGC
, nseg
, pSeg
)
434 DrawablePtr pDrawable
;
437 register xSegment
*pSeg
;
439 afbLineSD(pDrawable
, pGC
, mode
, npt
, pptInit
)
440 DrawablePtr pDrawable
;
442 int mode
; /* Origin or Previous */
443 int npt
; /* number of points */
450 register BoxPtr pbox
;
452 register DDXPointPtr ppt
; /* pointer to list of translated points */
455 register unsigned int oc1
; /* outcode of point 1 */
456 register unsigned int oc2
; /* outcode of point 2 */
458 PixelType
*addrlBase
; /* address of destination pixmap */
459 int nlwidth
; /* width in longwords of destination pixmap */
462 int xorg
, yorg
; /* origin of window */
464 int adx
; /* abs values of dx and dy */
466 int signdx
; /* sign of dx and dy */
468 int e
, e1
, e2
; /* bresenham error and increments */
469 int len
; /* length of segment */
470 int axis
; /* major axis */
472 unsigned int bias
= miGetZeroLineBias(pDrawable
->pScreen
);
475 unsigned char *rrops
;
476 unsigned char bgrrops
[AFB_MAX_DEPTH
];
477 unsigned char *pDash
;
482 int dashIndexTmp
, dashOffsetTmp
;
489 cclip
= pGC
->pCompositeClip
;
490 rrops
= ((afbPrivGC
*)(pGC
->devPrivates
[afbGCPrivateIndex
].ptr
))->rrops
;
491 pboxInit
= REGION_RECTS(cclip
);
492 nboxInit
= REGION_NUM_RECTS(cclip
);
494 afbGetPixelWidthSizeDepthAndPointer(pDrawable
, nlwidth
, sizeDst
, depthDst
,
497 /* compute initial dash values */
499 pDash
= (unsigned char *) pGC
->dash
;
500 numInDashList
= pGC
->numInDashList
;
501 isDoubleDash
= (pGC
->lineStyle
== LineDoubleDash
);
504 miStepDash ((int)pGC
->dashOffset
, &dashIndex
, pDash
,
505 numInDashList
, &dashOffset
);
508 afbReduceRop (pGC
->alu
, pGC
->bgPixel
, pGC
->planemask
, pGC
->depth
,
526 x1
= pSeg
->x1
+ xorg
;
527 y1
= pSeg
->y1
+ yorg
;
528 x2
= pSeg
->x2
+ xorg
;
529 y2
= pSeg
->y2
+ yorg
;
535 if (mode
== CoordModePrevious
) {
543 CalcLineDeltas(x1
, y1
, x2
, y2
, adx
, ady
, signdx
, signdy
,
549 e2
= e1
- (adx
<< 1);
555 e2
= e1
- (ady
<< 1);
558 SetYMajorOctant(octant
);
561 FIXUP_ERROR(e
, octant
, bias
);
563 /* we have bresenham parameters and two points.
564 all we have to do now is clip and draw.
570 OUTCODES(oc1
, x1
, y1
, pbox
);
571 OUTCODES(oc2
, x2
, y2
, pbox
);
572 if ((oc1
| oc2
) == 0) {
574 if (pGC
->capStyle
!= CapNotLast
)
576 dashIndexTmp
= dashIndex
;
577 dashOffsetTmp
= dashOffset
;
578 afbBresD(&dashIndexTmp
, pDash
, numInDashList
, &dashOffsetTmp
,
579 isDoubleDash
, addrlBase
, nlwidth
, sizeDst
, depthDst
,
580 signdx
, signdy
, axis
, x1
, y1
, e
, e1
, e2
, unclippedlen
,
581 rrops
, bgrrops
); /* @@@ NEXT PLANE PASSED @@@ */
584 afbBresD(&dashIndex
, pDash
, numInDashList
, &dashOffset
,
585 isDoubleDash
, addrlBase
, nlwidth
, sizeDst
, depthDst
,
586 signdx
, signdy
, axis
, x1
, y1
, e
, e1
, e2
, unclippedlen
,
587 rrops
, bgrrops
); /* @@@ NEXT PLANE PASSED @@@ */
590 } else if (oc1
& oc2
) {
592 } else /* have to clip */ {
593 int new_x1
= x1
, new_y1
= y1
, new_x2
= x2
, new_y2
= y2
;
594 int clip1
= 0, clip2
= 0;
598 if (miZeroClipLine(pbox
->x1
, pbox
->y1
, pbox
->x2
-1, pbox
->y2
-1,
599 &new_x1
, &new_y1
, &new_x2
, &new_y2
,
600 adx
, ady
, &clip1
, &clip2
,
601 octant
, bias
, oc1
, oc2
) == -1) {
605 dashIndexTmp
= dashIndex
;
606 dashOffsetTmp
= dashOffset
;
611 dlen
= abs(new_x1
- x1
);
613 dlen
= abs(new_y1
- y1
);
614 miStepDash (dlen
, &dashIndexTmp
, pDash
,
615 numInDashList
, &dashOffsetTmp
);
618 len
= abs(new_x2
- new_x1
);
620 len
= abs(new_y2
- new_y1
);
622 if (clip2
!= 0 || pGC
->capStyle
!= CapNotLast
)
628 /* unwind bresenham error term to first point */
630 clipdx
= abs(new_x1
- x1
);
631 clipdy
= abs(new_y1
- y1
);
633 err
= e
+((clipdy
*e2
) + ((clipdx
-clipdy
)*e1
));
635 err
= e
+((clipdx
*e2
) + ((clipdy
-clipdx
)*e1
));
639 afbBresD(&dashIndexTmp
, pDash
, numInDashList
, &dashOffsetTmp
,
640 isDoubleDash
, addrlBase
, nlwidth
, sizeDst
, depthDst
,
641 signdx
, signdy
, axis
, new_x1
, new_y1
, err
, e1
, e2
,
642 len
, rrops
, bgrrops
); /* @@@ NEXT PLANE PASSED @@@ */
646 } /* while (nbox--) */
649 * walk the dash list around to the next line
651 miStepDash (unclippedlen
, &dashIndex
, pDash
,
652 numInDashList
, &dashOffset
);
655 } /* while (nline--) */
658 /* paint the last point if the end style isn't CapNotLast.
659 (Assume that a projecting, butt, or round cap that is one
660 pixel wide is the same as the single pixel of the endpoint.)
663 if ((pGC
->capStyle
!= CapNotLast
) &&
664 ((dashIndex
& 1) == 0 || isDoubleDash
) &&
665 ((ppt
->x
+ xorg
!= pptInit
->x
+ pDrawable
->x
) ||
666 (ppt
->y
+ yorg
!= pptInit
->y
+ pDrawable
->y
) ||
667 (ppt
== pptInit
+ 1))) {
671 if ((x2
>= pbox
->x1
) && (y2
>= pbox
->y1
) && (x2
< pbox
->x2
) &&
675 for (d
= 0; d
< depthDst
; d
++) {
676 addrl
= afbScanline(addrlBase
, x2
, y2
, nlwidth
);
677 addrlBase
+= sizeDst
; /* @@@ NEXT PLANE @@@ */
685 *addrl
&= mfbGetrmask(x2
& PIM
);
688 *addrl
|= mfbGetmask(x2
& PIM
);
692 *addrl
^= mfbGetmask(x2
& PIM
);
698 } /* for (d = ...) */