]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/cfb/cfbzerarc.c
Support RDP5 logon packets.
[rdpsrv] / Xserver / programs / Xserver / cfb / cfbzerarc.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: cfbzerarc.c /main/24 1995/12/06 16:58:51 dpw $ */
29 /* $XFree86: xc/programs/Xserver/cfb/cfbzerarc.c,v 3.0 1996/06/29 09:05:57 dawes Exp $ */
30
31 /* Derived from:
32  * "Algorithm for drawing ellipses or hyperbolae with a digital plotter"
33  * by M. L. V. Pitteway
34  * The Computer Journal, November 1967, Volume 10, Number 3, pp. 282-289
35  */
36
37 #include "X.h"
38 #include "Xprotostr.h"
39 #include "miscstruct.h"
40 #include "gcstruct.h"
41 #include "pixmapstr.h"
42 #include "scrnintstr.h"
43 #include "cfb.h"
44 #include "cfbmskbits.h"
45 #include "mizerarc.h"
46 #include "cfbrrop.h"
47 #include "mi.h"
48
49 #ifdef PIXEL_ADDR
50
51 static void
52 RROP_NAME(cfbZeroArcSS8) (pDraw, pGC, arc)
53     DrawablePtr pDraw;
54     GCPtr pGC;
55     xArc *arc;
56 {
57     miZeroArcRec info;
58     Bool do360;
59     register int x;
60     PixelType *addrp;
61     register PixelType *yorgp, *yorgop;
62 #if PSZ == 24
63     int xorg, xorg3, xorgo, xorgo3;
64     register int xtmp;
65 #endif
66     RROP_DECLARE
67     register int yoffset;
68     int npwidth, dyoffset;
69     register int y, a, b, d, mask;
70     register int k1, k3, dx, dy;
71
72     cfbGetPixelWidthAndPointer(pDraw,npwidth, addrp)
73
74     RROP_FETCH_GC (pGC);
75     do360 = miZeroArcSetup(arc, &info, TRUE);
76     yorgp = addrp + ((info.yorg + pDraw->y) * npwidth);
77     yorgop = addrp + ((info.yorgo + pDraw->y) * npwidth);
78     info.xorg += pDraw->x;
79     info.xorgo += pDraw->x;
80 #if PSZ == 24
81     xorg = info.xorg;
82     xorg3 = xorg * 3;
83     info.xorg = (info.xorg * 3) >> 2;
84     xorgo = info.xorgo;
85     xorgo3 = xorgo * 3; 
86     info.xorgo = (info.xorgo * 3) >> 2;
87 #endif
88     MIARCSETUP();
89     yoffset = y ? npwidth : 0;
90     dyoffset = 0;
91     mask = info.initialMask;
92     if (!(arc->width & 1))
93     {
94 #if PSZ == 24
95         if (mask & 2)
96             RROP_SOLID24((yorgp + info.xorgo), xorgo);
97         if (mask & 8)
98             RROP_SOLID24((yorgop + info.xorgo), xorgo);
99 #else
100         if (mask & 2)
101             RROP_SOLID((yorgp + info.xorgo));
102         if (mask & 8)
103             RROP_SOLID((yorgop + info.xorgo));
104 #endif /* PSZ == 24 */
105     }
106     if (!info.end.x || !info.end.y)
107     {
108         mask = info.end.mask;
109         info.end = info.altend;
110     }
111     if (do360 && (arc->width == arc->height) && !(arc->width & 1))
112     {
113         register int xoffset = npwidth;
114 #if PSZ == 24
115         PixelType *yorghb = yorgp + (info.h * npwidth);
116         register int tmp1, tmp2, tmp1_3, tmp2_3;
117
118         tmp1 = xorg + info.h;
119         tmp1_3 = tmp1 * 3;
120         tmp2 = xorg - info.h;
121         tmp2_3 = tmp2 * 3;
122         while (1)
123         {
124             xtmp = (xorg3 + x * 3) >> 2;
125             RROP_SOLID24(yorgp + yoffset + xtmp, xorg + x);
126             RROP_SOLID24(yorgop - yoffset + xtmp, xorg + x);
127             xtmp = (xorg3 - x * 3) >> 2;
128             RROP_SOLID24(yorgp + yoffset + xtmp, xorg - x);
129             RROP_SOLID24(yorgop - yoffset + xtmp, xorg - x);
130             if (a < 0)
131                 break;
132             xtmp = (tmp1_3 - y * 3) >> 2;
133             RROP_SOLID24(yorghb - xoffset + xtmp, tmp1 - y);
134             RROP_SOLID24(yorghb + xoffset + xtmp, tmp1 - y);
135             xtmp = (tmp2_3 + y * 3) >> 2;
136             RROP_SOLID24(yorghb - xoffset + xtmp, tmp2 + y);
137             RROP_SOLID24(yorghb + xoffset + xtmp, tmp2 + y);
138             xoffset += npwidth;
139             MIARCCIRCLESTEP(yoffset += npwidth;);
140         }
141 #else
142         PixelType *yorghb = yorgp + (info.h * npwidth) + info.xorg;
143         PixelType *yorgohb = yorghb - info.h;
144
145         yorgp += info.xorg;
146         yorgop += info.xorg;
147         yorghb += info.h;
148         while (1)
149         {
150             RROP_SOLID(yorgp + yoffset + x);
151             RROP_SOLID(yorgp + yoffset - x);
152             RROP_SOLID(yorgop - yoffset - x);
153             RROP_SOLID(yorgop - yoffset + x);
154             if (a < 0)
155                 break;
156             RROP_SOLID(yorghb - xoffset - y);
157             RROP_SOLID(yorgohb - xoffset + y);
158             RROP_SOLID(yorgohb + xoffset + y);
159             RROP_SOLID(yorghb + xoffset - y);
160             xoffset += npwidth;
161             MIARCCIRCLESTEP(yoffset += npwidth;);
162         }
163         yorgp -= info.xorg;
164         yorgop -= info.xorg;
165 #endif /* PSZ == 24 */
166         x = info.w;
167         yoffset = info.h * npwidth;
168     }
169     else if (do360)
170     {
171         while (y < info.h || x < info.w)
172         {
173             MIARCOCTANTSHIFT(dyoffset = npwidth;);
174 #if PSZ == 24
175             xtmp = (xorg3 + x * 3) >> 2;
176             RROP_SOLID24(yorgp + yoffset + xtmp, xorg + x);
177             RROP_SOLID24(yorgop - yoffset + xtmp, xorg + x);
178             xtmp = (xorgo3 - x * 3) >> 2;
179             RROP_SOLID24(yorgp + yoffset + xtmp, xorgo - x);
180             RROP_SOLID24(yorgop - yoffset + xtmp, xorgo - x);
181 #else
182             RROP_SOLID(yorgp + yoffset + info.xorg + x);
183             RROP_SOLID(yorgp + yoffset + info.xorgo - x);
184             RROP_SOLID(yorgop - yoffset + info.xorgo - x);
185             RROP_SOLID(yorgop - yoffset + info.xorg + x);
186 #endif
187             MIARCSTEP(yoffset += dyoffset;, yoffset += npwidth;);
188         }
189     }
190     else
191     {
192         while (y < info.h || x < info.w)
193         {
194             MIARCOCTANTSHIFT(dyoffset = npwidth;);
195             if ((x == info.start.x) || (y == info.start.y))
196             {
197                 mask = info.start.mask;
198                 info.start = info.altstart;
199             }
200 #if PSZ == 24
201             if (mask & 1){
202               xtmp = (xorg3 + x * 3) >> 2;
203               RROP_SOLID24(yorgp + yoffset + xtmp, xorg + x);
204             }
205             if (mask & 2){
206               xtmp = (xorgo3 - x * 3) >> 2;
207               RROP_SOLID24(yorgp + yoffset + xtmp, xorgo - x);
208             }
209             if (mask & 4){
210               xtmp = (xorgo3 - x * 3) >> 2;
211               RROP_SOLID24(yorgop - yoffset + xtmp, xorgo - x);
212             }
213             if (mask & 8){
214               xtmp = (xorg3 + x * 3) >> 2;
215               RROP_SOLID24(yorgop - yoffset + xtmp, xorg + x);
216             }
217 #else
218             if (mask & 1)
219                 RROP_SOLID(yorgp + yoffset + info.xorg + x);
220             if (mask & 2)
221                 RROP_SOLID(yorgp + yoffset + info.xorgo - x);
222             if (mask & 4)
223                 RROP_SOLID(yorgop - yoffset + info.xorgo - x);
224             if (mask & 8)
225                 RROP_SOLID(yorgop - yoffset + info.xorg + x);
226 #endif /* PSZ == 24 */
227             if ((x == info.end.x) || (y == info.end.y))
228             {
229                 mask = info.end.mask;
230                 info.end = info.altend;
231             }
232             MIARCSTEP(yoffset += dyoffset;, yoffset += npwidth;);
233         }
234     }
235     if ((x == info.start.x) || (y == info.start.y))
236         mask = info.start.mask;
237 #if PSZ == 24
238     if (mask & 1){
239       xtmp = (xorg3 + x * 3) >> 2;
240       RROP_SOLID24(yorgp + yoffset + xtmp, xorg + x);
241     }
242     if (mask & 4){
243       xtmp = (xorgo3 - x * 3) >> 2;
244       RROP_SOLID24(yorgop - yoffset + xtmp, xorgo - x);
245     }
246 #else
247     if (mask & 1)
248         RROP_SOLID(yorgp + yoffset + info.xorg + x);
249     if (mask & 4)
250         RROP_SOLID(yorgop - yoffset + info.xorgo - x);
251 #endif /* PSZ == 24 */
252     if (arc->height & 1)
253     {
254 #if PSZ == 24
255         if (mask & 2){
256           xtmp = (xorgo3 - x * 3) >> 2;
257           RROP_SOLID24(yorgp + yoffset + xtmp, xorgo - x);
258         }
259         if (mask & 8){
260           xtmp = (xorg3 + x * 3) >> 2;
261           RROP_SOLID24(yorgop - yoffset + xtmp, xorg + x);
262         }
263 #else
264         if (mask & 2)
265             RROP_SOLID(yorgp + yoffset + info.xorgo - x);
266         if (mask & 8)
267             RROP_SOLID(yorgop - yoffset + info.xorg + x);
268 #endif /* PSZ == 24 */
269     }
270 }
271
272 void
273 RROP_NAME (cfbZeroPolyArcSS8) (pDraw, pGC, narcs, parcs)
274     register DrawablePtr        pDraw;
275     GCPtr       pGC;
276     int         narcs;
277     xArc        *parcs;
278 {
279     register xArc *arc;
280     register int i;
281     BoxRec box;
282     int x2, y2;
283     RegionPtr cclip;
284
285     cclip = cfbGetCompositeClip(pGC);
286     for (arc = parcs, i = narcs; --i >= 0; arc++)
287     {
288         if (miCanZeroArc(arc))
289         {
290             box.x1 = arc->x + pDraw->x;
291             box.y1 = arc->y + pDraw->y;
292             /*
293              * Because box.x2 and box.y2 get truncated to 16 bits, and the
294              * RECT_IN_REGION test treats the resulting number as a signed
295              * integer, the RECT_IN_REGION test alone can go the wrong way.
296              * This can result in a server crash because the rendering
297              * routines in this file deal directly with cpu addresses
298              * of pixels to be stored, and do not clip or otherwise check
299              * that all such addresses are within their respective pixmaps.
300              * So we only allow the RECT_IN_REGION test to be used for
301              * values that can be expressed correctly in a signed short.
302              */
303             x2 = box.x1 + (int)arc->width + 1;
304             box.x2 = x2;
305             y2 = box.y1 + (int)arc->height + 1;
306             box.y2 = y2;
307             if ( (x2 <= MAXSHORT) && (y2 <= MAXSHORT) &&
308                     (RECT_IN_REGION(pDraw->pScreen, cclip, &box) == rgnIN) )
309                 RROP_NAME (cfbZeroArcSS8) (pDraw, pGC, arc);
310             else
311                 miZeroPolyArc(pDraw, pGC, 1, arc);
312         }
313         else
314             miPolyArc(pDraw, pGC, 1, arc);
315     }
316 }
317
318 #endif