xref: /OK3568_Linux_fs/external/xserver/fb/fbline.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright © 1998 Keith Packard
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Permission to use, copy, modify, distribute, and sell this software and its
5*4882a593Smuzhiyun  * documentation for any purpose is hereby granted without fee, provided that
6*4882a593Smuzhiyun  * the above copyright notice appear in all copies and that both that
7*4882a593Smuzhiyun  * copyright notice and this permission notice appear in supporting
8*4882a593Smuzhiyun  * documentation, and that the name of Keith Packard not be used in
9*4882a593Smuzhiyun  * advertising or publicity pertaining to distribution of the software without
10*4882a593Smuzhiyun  * specific, written prior permission.  Keith Packard makes no
11*4882a593Smuzhiyun  * representations about the suitability of this software for any purpose.  It
12*4882a593Smuzhiyun  * is provided "as is" without express or implied warranty.
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15*4882a593Smuzhiyun  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16*4882a593Smuzhiyun  * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17*4882a593Smuzhiyun  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18*4882a593Smuzhiyun  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19*4882a593Smuzhiyun  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20*4882a593Smuzhiyun  * PERFORMANCE OF THIS SOFTWARE.
21*4882a593Smuzhiyun  */
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun #ifdef HAVE_DIX_CONFIG_H
24*4882a593Smuzhiyun #include <dix-config.h>
25*4882a593Smuzhiyun #endif
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun #include "fb.h"
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun static void
fbZeroLine(DrawablePtr pDrawable,GCPtr pGC,int mode,int npt,DDXPointPtr ppt)30*4882a593Smuzhiyun fbZeroLine(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt, DDXPointPtr ppt)
31*4882a593Smuzhiyun {
32*4882a593Smuzhiyun     int x1, y1, x2, y2;
33*4882a593Smuzhiyun     int x, y;
34*4882a593Smuzhiyun     int dashOffset;
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun     x = pDrawable->x;
37*4882a593Smuzhiyun     y = pDrawable->y;
38*4882a593Smuzhiyun     x1 = ppt->x;
39*4882a593Smuzhiyun     y1 = ppt->y;
40*4882a593Smuzhiyun     dashOffset = pGC->dashOffset;
41*4882a593Smuzhiyun     while (--npt) {
42*4882a593Smuzhiyun         ++ppt;
43*4882a593Smuzhiyun         x2 = ppt->x;
44*4882a593Smuzhiyun         y2 = ppt->y;
45*4882a593Smuzhiyun         if (mode == CoordModePrevious) {
46*4882a593Smuzhiyun             x2 += x1;
47*4882a593Smuzhiyun             y2 += y1;
48*4882a593Smuzhiyun         }
49*4882a593Smuzhiyun         fbSegment(pDrawable, pGC, x1 + x, y1 + y,
50*4882a593Smuzhiyun                   x2 + x, y2 + y,
51*4882a593Smuzhiyun                   npt == 1 && pGC->capStyle != CapNotLast, &dashOffset);
52*4882a593Smuzhiyun         x1 = x2;
53*4882a593Smuzhiyun         y1 = y2;
54*4882a593Smuzhiyun     }
55*4882a593Smuzhiyun }
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun static void
fbZeroSegment(DrawablePtr pDrawable,GCPtr pGC,int nseg,xSegment * pSegs)58*4882a593Smuzhiyun fbZeroSegment(DrawablePtr pDrawable, GCPtr pGC, int nseg, xSegment * pSegs)
59*4882a593Smuzhiyun {
60*4882a593Smuzhiyun     int dashOffset;
61*4882a593Smuzhiyun     int x, y;
62*4882a593Smuzhiyun     Bool drawLast = pGC->capStyle != CapNotLast;
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun     x = pDrawable->x;
65*4882a593Smuzhiyun     y = pDrawable->y;
66*4882a593Smuzhiyun     while (nseg--) {
67*4882a593Smuzhiyun         dashOffset = pGC->dashOffset;
68*4882a593Smuzhiyun         fbSegment(pDrawable, pGC,
69*4882a593Smuzhiyun                   pSegs->x1 + x, pSegs->y1 + y,
70*4882a593Smuzhiyun                   pSegs->x2 + x, pSegs->y2 + y, drawLast, &dashOffset);
71*4882a593Smuzhiyun         pSegs++;
72*4882a593Smuzhiyun     }
73*4882a593Smuzhiyun }
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun void
fbFixCoordModePrevious(int npt,DDXPointPtr ppt)76*4882a593Smuzhiyun fbFixCoordModePrevious(int npt, DDXPointPtr ppt)
77*4882a593Smuzhiyun {
78*4882a593Smuzhiyun     int x, y;
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun     x = ppt->x;
81*4882a593Smuzhiyun     y = ppt->y;
82*4882a593Smuzhiyun     npt--;
83*4882a593Smuzhiyun     while (npt--) {
84*4882a593Smuzhiyun         ppt++;
85*4882a593Smuzhiyun         x = (ppt->x += x);
86*4882a593Smuzhiyun         y = (ppt->y += y);
87*4882a593Smuzhiyun     }
88*4882a593Smuzhiyun }
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun void
fbPolyLine(DrawablePtr pDrawable,GCPtr pGC,int mode,int npt,DDXPointPtr ppt)91*4882a593Smuzhiyun fbPolyLine(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt, DDXPointPtr ppt)
92*4882a593Smuzhiyun {
93*4882a593Smuzhiyun     void (*line) (DrawablePtr, GCPtr, int mode, int npt, DDXPointPtr ppt);
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun     if (pGC->lineWidth == 0) {
96*4882a593Smuzhiyun         line = fbZeroLine;
97*4882a593Smuzhiyun         if (pGC->fillStyle == FillSolid &&
98*4882a593Smuzhiyun             pGC->lineStyle == LineSolid &&
99*4882a593Smuzhiyun             RegionNumRects(fbGetCompositeClip(pGC)) == 1) {
100*4882a593Smuzhiyun             switch (pDrawable->bitsPerPixel) {
101*4882a593Smuzhiyun             case 8:
102*4882a593Smuzhiyun                 line = fbPolyline8;
103*4882a593Smuzhiyun                 break;
104*4882a593Smuzhiyun             case 16:
105*4882a593Smuzhiyun                 line = fbPolyline16;
106*4882a593Smuzhiyun                 break;
107*4882a593Smuzhiyun             case 32:
108*4882a593Smuzhiyun                 line = fbPolyline32;
109*4882a593Smuzhiyun                 break;
110*4882a593Smuzhiyun             }
111*4882a593Smuzhiyun         }
112*4882a593Smuzhiyun     }
113*4882a593Smuzhiyun     else {
114*4882a593Smuzhiyun         if (pGC->lineStyle != LineSolid)
115*4882a593Smuzhiyun             line = miWideDash;
116*4882a593Smuzhiyun         else
117*4882a593Smuzhiyun             line = miWideLine;
118*4882a593Smuzhiyun     }
119*4882a593Smuzhiyun     (*line) (pDrawable, pGC, mode, npt, ppt);
120*4882a593Smuzhiyun }
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun void
fbPolySegment(DrawablePtr pDrawable,GCPtr pGC,int nseg,xSegment * pseg)123*4882a593Smuzhiyun fbPolySegment(DrawablePtr pDrawable, GCPtr pGC, int nseg, xSegment * pseg)
124*4882a593Smuzhiyun {
125*4882a593Smuzhiyun     void (*seg) (DrawablePtr pDrawable, GCPtr pGC, int nseg, xSegment * pseg);
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun     if (pGC->lineWidth == 0) {
128*4882a593Smuzhiyun         seg = fbZeroSegment;
129*4882a593Smuzhiyun         if (pGC->fillStyle == FillSolid &&
130*4882a593Smuzhiyun             pGC->lineStyle == LineSolid &&
131*4882a593Smuzhiyun             RegionNumRects(fbGetCompositeClip(pGC)) == 1) {
132*4882a593Smuzhiyun             switch (pDrawable->bitsPerPixel) {
133*4882a593Smuzhiyun             case 8:
134*4882a593Smuzhiyun                 seg = fbPolySegment8;
135*4882a593Smuzhiyun                 break;
136*4882a593Smuzhiyun             case 16:
137*4882a593Smuzhiyun                 seg = fbPolySegment16;
138*4882a593Smuzhiyun                 break;
139*4882a593Smuzhiyun             case 32:
140*4882a593Smuzhiyun                 seg = fbPolySegment32;
141*4882a593Smuzhiyun                 break;
142*4882a593Smuzhiyun             }
143*4882a593Smuzhiyun         }
144*4882a593Smuzhiyun     }
145*4882a593Smuzhiyun     else {
146*4882a593Smuzhiyun         seg = miPolySegment;
147*4882a593Smuzhiyun     }
148*4882a593Smuzhiyun     (*seg) (pDrawable, pGC, nseg, pseg);
149*4882a593Smuzhiyun }
150