]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/cfb/cfbpolypnt.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / programs / Xserver / cfb / cfbpolypnt.c
1 /************************************************************
2
3 Copyright (c) 1989  X Consortium
4
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:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
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.
21
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.
25
26 ********************************************************/
27
28 /* $XConsortium: cfbpolypnt.c,v 5.17 94/04/17 20:28:57 dpw Exp $ */
29 /* $XFree86: xc/programs/Xserver/cfb/cfbpolypnt.c,v 3.0 1996/06/29 09:05:47 dawes Exp $ */
30
31 #include "X.h"
32 #include "gcstruct.h"
33 #include "windowstr.h"
34 #include "pixmapstr.h"
35 #include "regionstr.h"
36 #include "scrnintstr.h"
37 #include "cfb.h"
38 #include "cfbmskbits.h"
39
40 #define isClipped(c,ul,lr)  ((((c) - (ul)) | ((lr) - (c))) & ClipMask)
41
42 /* WARNING: pbox contains two shorts. This code assumes they are packed
43  * and can be referenced together as an INT32.
44  */
45
46 #define PointLoop(fill) { \
47     for (nbox = REGION_NUM_RECTS(cclip), pbox = REGION_RECTS(cclip); \
48          --nbox >= 0; \
49          pbox++) \
50     { \
51         c1 = *((INT32 *) &pbox->x1) - off; \
52         c2 = *((INT32 *) &pbox->x2) - off - 0x00010001; \
53         for (ppt = (INT32 *) pptInit, i = npt; --i >= 0;) \
54         { \
55             pt = *ppt++; \
56             if (!isClipped(pt,c1,c2)) { \
57                 fill \
58             } \
59         } \
60     } \
61 }
62
63 #if PSZ == 24
64 # include "cfbrrop24.h"
65 #endif
66
67 void
68 cfbPolyPoint(pDrawable, pGC, mode, npt, pptInit)
69     DrawablePtr pDrawable;
70     GCPtr pGC;
71     int mode;
72     int npt;
73     xPoint *pptInit;
74 {
75     register INT32   pt;
76     register INT32   c1, c2;
77     register unsigned long   ClipMask = 0x80008000;
78     register unsigned long   xor;
79 #ifdef PIXEL_ADDR
80     register PixelType   *addrp;
81     register int    npwidth;
82     PixelType       *addrpt;
83 #else
84     register unsigned long    *addrl;
85     register int    nlwidth;
86     register int    xoffset;
87     unsigned long   *addrlt;
88 #endif
89 #if PSZ == 24
90     RROP_DECLARE
91     register int xtmp;
92     register PixelType *p;
93 #endif
94     register INT32  *ppt;
95     RegionPtr       cclip;
96     int             nbox;
97     register int    i;
98     register BoxPtr pbox;
99     unsigned long   and;
100     int             rop = pGC->alu;
101     int             off;
102     cfbPrivGCPtr    devPriv;
103     xPoint          *pptPrev;
104
105     devPriv =cfbGetGCPrivate(pGC);
106     rop = devPriv->rop;
107     if (rop == GXnoop)
108         return;
109     cclip = devPriv->pCompositeClip;
110     xor = devPriv->xor;
111     if ((mode == CoordModePrevious) && (npt > 1))
112     {
113         for (pptPrev = pptInit + 1, i = npt - 1; --i >= 0; pptPrev++)
114         {
115             pptPrev->x += (pptPrev-1)->x;
116             pptPrev->y += (pptPrev-1)->y;
117         }
118     }
119     off = *((int *) &pDrawable->x);
120     off -= (off & 0x8000) << 1;
121 #ifdef PIXEL_ADDR
122     cfbGetPixelWidthAndPointer(pDrawable, npwidth, addrp);
123 #if PSZ == 24
124     addrp = addrp + pDrawable->y * npwidth;
125 #else
126     addrp = addrp + pDrawable->y * npwidth + pDrawable->x;
127 #endif
128     if (rop == GXcopy)
129     {
130 #if PSZ == 24
131       RROP_COPY_SETUP(xor)
132 #endif
133         if (!(npwidth & (npwidth - 1)))
134         {
135             npwidth = ffs(npwidth) - 1;
136 #if PSZ == 24
137             PointLoop(
138                       xtmp = pDrawable->x + intToX(pt);
139                       p = addrp + (intToY(pt) << npwidth) + ((xtmp * 3) >>2);
140                       RROP_SOLID24_COPY(p, xtmp))
141 #else
142             PointLoop(*(addrp + (intToY(pt) << npwidth) + intToX(pt)) = xor;)
143 #endif
144         }
145 #ifdef sun
146         else if (npwidth == 1152)
147         {
148             register int    y;
149             PointLoop(y = intToY(pt); *(addrp + (y << 10) + (y << 7) + intToX(pt)) = xor;)
150         }
151 #endif
152         else
153         {
154 #if PSZ == 24
155             PointLoop(
156                       xtmp = pDrawable->x + intToX(pt);
157                       p = addrp + intToY(pt) * npwidth + ((xtmp * 3) >> 2);
158                       RROP_SOLID24_COPY(p, xtmp))
159 #else
160             PointLoop(*(addrp + intToY(pt) * npwidth + intToX(pt)) = xor;)
161 #endif
162         }
163     }
164     else
165     {
166         and = devPriv->and;
167 #if PSZ == 24
168         RROP_SET_SETUP(xor, and)
169         PointLoop(  
170                   xtmp = pDrawable->x + intToX(pt);
171                   p = addrp + intToY(pt) * npwidth + ((xtmp * 3) >> 2);
172                   RROP_SOLID24_SET(p, xtmp))
173 #else
174         PointLoop(  addrpt = addrp + intToY(pt) * npwidth + intToX(pt);
175                     *addrpt = DoRRop (*addrpt, and, xor);)
176 #endif
177     }
178 #else /* !PIXEL_ADDR */
179     cfbGetLongWidthAndPointer(pDrawable, nlwidth, addrl);
180     addrl = addrl + pDrawable->y * nlwidth + (pDrawable->x >> PWSH);
181     xoffset = pDrawable->x & PIM;
182     and = devPriv->and;
183 #if PSZ == 24
184     PointLoop(   addrlt = addrl + intToY(pt) * nlwidth
185                            + ((intToX(pt) + xoffset) >> PWSH);
186                    *addrlt = DoRRop (*addrlt,
187                            and | ~cfbmask[(intToX(pt) + xoffset) & PIM],
188                            xor & cfbmask[(intToX(pt) + xoffset) & PIM]);
189              )
190 #else
191     PointLoop(   addrlt = addrl + intToY(pt) * nlwidth
192                            + ((intToX(pt) + xoffset) >> PWSH);
193                    *addrlt = DoRRop (*addrlt,
194                            and | ~cfbmask[((intToX(pt) + xoffset) & 3)<<1],
195                            xor & cfbmask[((intToX(pt) + xoffset) & 3)<<1]);
196              )
197 #endif
198 #endif /* PIXEL_ADDR */
199 }