xref: /OK3568_Linux_fs/external/xserver/mi/miline.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun 
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun 
4*4882a593Smuzhiyun Copyright 1994, 1998  The Open Group
5*4882a593Smuzhiyun 
6*4882a593Smuzhiyun Permission to use, copy, modify, distribute, and sell this software and its
7*4882a593Smuzhiyun documentation for any purpose is hereby granted without fee, provided that
8*4882a593Smuzhiyun the above copyright notice appear in all copies and that both that
9*4882a593Smuzhiyun copyright notice and this permission notice appear in supporting
10*4882a593Smuzhiyun documentation.
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun The above copyright notice and this permission notice shall be included in
13*4882a593Smuzhiyun all copies or substantial portions of the Software.
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*4882a593Smuzhiyun IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*4882a593Smuzhiyun FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18*4882a593Smuzhiyun OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19*4882a593Smuzhiyun AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20*4882a593Smuzhiyun CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun Except as contained in this notice, the name of The Open Group shall not be
23*4882a593Smuzhiyun used in advertising or otherwise to promote the sale, use or other dealings
24*4882a593Smuzhiyun in this Software without prior written authorization from The Open Group.
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun */
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun #ifndef MILINE_H
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun #include "screenint.h"
31*4882a593Smuzhiyun #include "privates.h"
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun /*
34*4882a593Smuzhiyun  * Public definitions used for configuring basic pixelization aspects
35*4882a593Smuzhiyun  * of the sample implementation line-drawing routines provided in
36*4882a593Smuzhiyun  * {mfb,mi,cfb*} at run-time.
37*4882a593Smuzhiyun  */
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun #define XDECREASING	4
40*4882a593Smuzhiyun #define YDECREASING	2
41*4882a593Smuzhiyun #define YMAJOR		1
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun #define OCTANT1		(1 << (YDECREASING))
44*4882a593Smuzhiyun #define OCTANT2		(1 << (YDECREASING|YMAJOR))
45*4882a593Smuzhiyun #define OCTANT3		(1 << (XDECREASING|YDECREASING|YMAJOR))
46*4882a593Smuzhiyun #define OCTANT4		(1 << (XDECREASING|YDECREASING))
47*4882a593Smuzhiyun #define OCTANT5		(1 << (XDECREASING))
48*4882a593Smuzhiyun #define OCTANT6		(1 << (XDECREASING|YMAJOR))
49*4882a593Smuzhiyun #define OCTANT7		(1 << (YMAJOR))
50*4882a593Smuzhiyun #define OCTANT8		(1 << (0))
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun #define XMAJOROCTANTS		(OCTANT1 | OCTANT4 | OCTANT5 | OCTANT8)
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun #define DEFAULTZEROLINEBIAS	(OCTANT2 | OCTANT3 | OCTANT4 | OCTANT5)
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun /*
57*4882a593Smuzhiyun  * Devices can configure the rendering of routines in mi, mfb, and cfb*
58*4882a593Smuzhiyun  * by specifying a thin line bias to be applied to a particular screen
59*4882a593Smuzhiyun  * using the following function.  The bias parameter is an OR'ing of
60*4882a593Smuzhiyun  * the appropriate OCTANT constants defined above to indicate which
61*4882a593Smuzhiyun  * octants to bias a line to prefer an axial step when the Bresenham
62*4882a593Smuzhiyun  * error term is exactly zero.  The octants are mapped as follows:
63*4882a593Smuzhiyun  *
64*4882a593Smuzhiyun  *   \    |    /
65*4882a593Smuzhiyun  *    \ 3 | 2 /
66*4882a593Smuzhiyun  *     \  |  /
67*4882a593Smuzhiyun  *    4 \ | / 1
68*4882a593Smuzhiyun  *       \|/
69*4882a593Smuzhiyun  *   -----------
70*4882a593Smuzhiyun  *       /|\
71*4882a593Smuzhiyun  *    5 / | \ 8
72*4882a593Smuzhiyun  *     /  |  \
73*4882a593Smuzhiyun  *    / 6 | 7 \
74*4882a593Smuzhiyun  *   /    |    \
75*4882a593Smuzhiyun  *
76*4882a593Smuzhiyun  * For more information, see "Ambiguities in Incremental Line Rastering,"
77*4882a593Smuzhiyun  * Jack E. Bresenham, IEEE CG&A, May 1987.
78*4882a593Smuzhiyun  */
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun extern _X_EXPORT void miSetZeroLineBias(ScreenPtr /* pScreen */ ,
81*4882a593Smuzhiyun                                         unsigned int    /* bias */
82*4882a593Smuzhiyun     );
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun /*
85*4882a593Smuzhiyun  * Private definitions needed for drawing thin (zero width) lines
86*4882a593Smuzhiyun  * Used by the mi, mfb, and all cfb* components.
87*4882a593Smuzhiyun  */
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun #define X_AXIS	0
90*4882a593Smuzhiyun #define Y_AXIS	1
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun #define OUT_LEFT  0x08
93*4882a593Smuzhiyun #define OUT_RIGHT 0x04
94*4882a593Smuzhiyun #define OUT_ABOVE 0x02
95*4882a593Smuzhiyun #define OUT_BELOW 0x01
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun #define OUTCODES(_result, _x, _y, _pbox) \
98*4882a593Smuzhiyun     if	    ( (_x) <  (_pbox)->x1) (_result) |= OUT_LEFT; \
99*4882a593Smuzhiyun     else if ( (_x) >= (_pbox)->x2) (_result) |= OUT_RIGHT; \
100*4882a593Smuzhiyun     if	    ( (_y) <  (_pbox)->y1) (_result) |= OUT_ABOVE; \
101*4882a593Smuzhiyun     else if ( (_y) >= (_pbox)->y2) (_result) |= OUT_BELOW;
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun #define MIOUTCODES(outcode, x, y, xmin, ymin, xmax, ymax) \
104*4882a593Smuzhiyun {\
105*4882a593Smuzhiyun      if (x < xmin) outcode |= OUT_LEFT;\
106*4882a593Smuzhiyun      if (x > xmax) outcode |= OUT_RIGHT;\
107*4882a593Smuzhiyun      if (y < ymin) outcode |= OUT_ABOVE;\
108*4882a593Smuzhiyun      if (y > ymax) outcode |= OUT_BELOW;\
109*4882a593Smuzhiyun }
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun #define SWAPINT(i, j) \
112*4882a593Smuzhiyun {  int _t = i;  i = j;  j = _t; }
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun #define SWAPPT(i, j) \
115*4882a593Smuzhiyun {  DDXPointRec _t; _t = i;  i = j; j = _t; }
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun #define SWAPINT_PAIR(x1, y1, x2, y2)\
118*4882a593Smuzhiyun {   int t = x1;  x1 = x2;  x2 = t;\
119*4882a593Smuzhiyun         t = y1;  y1 = y2;  y2 = t;\
120*4882a593Smuzhiyun }
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun #define miGetZeroLineBias(_pScreen) ((unsigned long) (unsigned long*)\
123*4882a593Smuzhiyun     dixLookupPrivate(&(_pScreen)->devPrivates, miZeroLineScreenKey))
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun #define CalcLineDeltas(_x1,_y1,_x2,_y2,_adx,_ady,_sx,_sy,_SX,_SY,_octant) \
126*4882a593Smuzhiyun     (_octant) = 0;				\
127*4882a593Smuzhiyun     (_sx) = (_SX);				\
128*4882a593Smuzhiyun     if (((_adx) = (_x2) - (_x1)) < 0) {		\
129*4882a593Smuzhiyun 	(_adx) = -(_adx);			\
130*4882a593Smuzhiyun 	(_sx = -(_sx));				\
131*4882a593Smuzhiyun 	(_octant) |= XDECREASING;		\
132*4882a593Smuzhiyun     }						\
133*4882a593Smuzhiyun     (_sy) = (_SY);				\
134*4882a593Smuzhiyun     if (((_ady) = (_y2) - (_y1)) < 0) {		\
135*4882a593Smuzhiyun 	(_ady) = -(_ady);			\
136*4882a593Smuzhiyun 	(_sy = -(_sy));				\
137*4882a593Smuzhiyun 	(_octant) |= YDECREASING;		\
138*4882a593Smuzhiyun     }
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun #define SetYMajorOctant(_octant)	((_octant) |= YMAJOR)
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun #define FIXUP_ERROR(_e, _octant, _bias) \
143*4882a593Smuzhiyun     (_e) -= (((_bias) >> (_octant)) & 1)
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun #define IsXMajorOctant(_octant)		(!((_octant) & YMAJOR))
146*4882a593Smuzhiyun #define IsYMajorOctant(_octant)		((_octant) & YMAJOR)
147*4882a593Smuzhiyun #define IsXDecreasingOctant(_octant)	((_octant) & XDECREASING)
148*4882a593Smuzhiyun #define IsYDecreasingOctant(_octant)	((_octant) & YDECREASING)
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun extern _X_EXPORT DevPrivateKeyRec miZeroLineScreenKeyRec;
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun #define miZeroLineScreenKey (&miZeroLineScreenKeyRec)
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun extern _X_EXPORT int miZeroClipLine(int /*xmin */ ,
155*4882a593Smuzhiyun                                     int /*ymin */ ,
156*4882a593Smuzhiyun                                     int /*xmax */ ,
157*4882a593Smuzhiyun                                     int /*ymax */ ,
158*4882a593Smuzhiyun                                     int * /*new_x1 */ ,
159*4882a593Smuzhiyun                                     int * /*new_y1 */ ,
160*4882a593Smuzhiyun                                     int * /*new_x2 */ ,
161*4882a593Smuzhiyun                                     int * /*new_y2 */ ,
162*4882a593Smuzhiyun                                     unsigned int /*adx */ ,
163*4882a593Smuzhiyun                                     unsigned int /*ady */ ,
164*4882a593Smuzhiyun                                     int * /*pt1_clipped */ ,
165*4882a593Smuzhiyun                                     int * /*pt2_clipped */ ,
166*4882a593Smuzhiyun                                     int /*octant */ ,
167*4882a593Smuzhiyun                                     unsigned int /*bias */ ,
168*4882a593Smuzhiyun                                     int /*oc1 */ ,
169*4882a593Smuzhiyun                                     int /*oc2 */
170*4882a593Smuzhiyun     );
171*4882a593Smuzhiyun 
172*4882a593Smuzhiyun #endif                          /* MILINE_H */
173