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