]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/cfb/cfbtile32.c
Support RDP5 logon packets.
[rdpsrv] / Xserver / programs / Xserver / cfb / cfbtile32.c
1 /*
2  * Fill 32 bit tiled rectangles.  Used by both PolyFillRect and PaintWindow.
3  * no depth dependencies.
4  */
5
6 /*
7
8 Copyright (c) 1989  X Consortium
9
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
23 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
24 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
27 Except as contained in this notice, the name of the X Consortium shall not be
28 used in advertising or otherwise to promote the sale, use or other dealings
29 in this Software without prior written authorization from the X Consortium.
30 */
31
32 /* $XConsortium: cfbtile32.c,v 1.8 94/04/17 20:29:05 dpw Exp $ */
33 /* $XFree86: xc/programs/Xserver/cfb/cfbtile32.c,v 3.0 1996/06/29 09:05:53 dawes Exp $ */
34
35 #include "X.h"
36 #include "Xmd.h"
37 #include "servermd.h"
38 #include "gcstruct.h"
39 #include "window.h"
40 #include "pixmapstr.h"
41 #include "scrnintstr.h"
42 #include "windowstr.h"
43
44 #include "cfb.h"
45 #include "cfbmskbits.h"
46 #include "cfb8bit.h"
47
48 #include "mergerop.h"
49
50 #include "mi.h"
51 #include "mispans.h"
52
53 #ifdef sparc
54 #define SHARED_IDCACHE
55 #endif
56
57 #if PSZ == 24
58 #define STORE(p)    (*(p) = MROP_PREBUILT_SOLID(srcpix,*(p)))
59 /*#define STORE24(p,index)    {\
60             register int idx = ((index) & 3)<< 1; \
61             *(p) = (((MROP_PREBUILT_SOLID(srcpix,*(p))<<cfb24Shift[idx])&cfbmask[idx])| \
62                     (*(p)&cfbrmask[idx])); \
63             idx++; \
64             (p)++; \
65             *(p) = (((MROP_PREBUILT_SOLID(srcpix,*(p))>>cfb24Shift[idx])&cfbmask[idx])| \
66                     (*(p)&cfbrmask[idx])); \
67             (p)--; \
68         }*/
69 #define STORE24(p,index)    MROP_PREBUILT_SOLID24(srcpix, (p), index)
70
71 #define STORE_MASK(p,mask)    (*(p) = MROP_PREBUILT_MASK(srcpix,*(p),(mask)))
72 #define QSTORE(p)    ((*(p) = MROP_PREBUILT_SOLID(((srcpix<<24)|srcpix),*(p))), \
73                       (p)++,(*(p) = MROP_PREBUILT_SOLID(((srcpix<<16)|(srcpix>>8)),*(p))), \
74                       (p)++,(*(p) = MROP_PREBUILT_SOLID(((srcpix<<8)|(srcpix>>16)),*(p))))
75
76
77
78 /* XXX TJR: I doubt that this optimised case works (because the non-24 bit case
79    was broken), so I've added the #if 0 below.  Someone who knows what they're
80    doing can re-enable it if they fix it */
81
82 #if (MROP == Mcopy) && defined(FAST_CONSTANT_OFFSET_MODE) && defined(SHARED_IDCACHE) && 0
83 # define Expand(left,right) {\
84     int part = nlwMiddle & ((PGSZB*2)-1); \
85     nlwMiddle *= 3; \
86     nlwMiddle >>= PWSH + 3; \
87     while (h--) { \
88         srcpix = psrc[srcy]; \
89         MROP_PREBUILD(srcpix); \
90         ++srcy; \
91         if (srcy == tileHeight) \
92             srcy = 0; \
93         left \
94         p += part; \
95         switch (part) { \
96         case 7: \
97             STORE24(p - 7, xtmp - 7); \
98         case 6: \
99             STORE24(p - 6, xtmp - 6); \
100         case 5: \
101             STORE24(p - 5, xtmp - 5); \
102         case 4: \
103             STORE24(p - 4, xtmp - 4); \
104         case 3: \
105             STORE24(p - 3, xtmp - 3); \
106         case 2: \
107             STORE24(p - 2, xtmp - 2); \
108         case 1: \
109             STORE24(p - 1, xtmp - 1); \
110         } \
111         nlw = nlwMiddle; \
112         while (nlw) { \
113             STORE24 (p + 0, xtmp + 0); \
114             STORE24 (p + 1, xtmp + 1); \
115             STORE24 (p + 2, xtmp + 2); \
116             STORE24 (p + 3, xtmp + 3); \
117             STORE24 (p + 4, xtmp + 4); \
118             STORE24 (p + 5, xtmp + 5); \
119             STORE24 (p + 6, xtmp + 6); \
120             STORE24 (p + 7, xtmp + 7); \
121             p += 8; \
122             xtmp += 8; \
123             nlw--; \
124         } \
125         right \
126         p += nlwExtra; \
127     } \
128 }
129 #else
130 #define Expand(left,right) {\
131     while (h--) { \
132         srcpix = psrc[srcy]; \
133         MROP_PREBUILD(srcpix); \
134         ++srcy; \
135         if (srcy == tileHeight) \
136             srcy = 0; \
137         left \
138         while (nlw--) \
139         { \
140             STORE24(p,xtmp); \
141             if(xtmp&3) p++; \
142             xtmp++; \
143         } \
144         right \
145         p += nlwExtra; \
146     } \
147 }
148 #endif
149 #else /*PSZ != 24*/
150 #define STORE(p)    (*(p) = MROP_PREBUILT_SOLID(srcpix,*(p)))
151
152 #if (MROP == Mcopy) && defined(FAST_CONSTANT_OFFSET_MODE) && defined(SHARED_IDCACHE)
153 # define Expand(left,right) {\
154     int part = nlwMiddle & 7; \
155     nlwMiddle >>= 3; \
156     while (h--) { \
157         srcpix = psrc[srcy]; \
158         MROP_PREBUILD(srcpix); \
159         ++srcy; \
160         if (srcy == tileHeight) \
161             srcy = 0; \
162         left \
163         p += part; \
164         switch (part) { \
165         case 7: \
166             STORE(p - 7); \
167         case 6: \
168             STORE(p - 6); \
169         case 5: \
170             STORE(p - 5); \
171         case 4: \
172             STORE(p - 4); \
173         case 3: \
174             STORE(p - 3); \
175         case 2: \
176             STORE(p - 2); \
177         case 1: \
178             STORE(p - 1); \
179         } \
180         nlw = nlwMiddle; \
181         while (nlw) { \
182             STORE (p + 0); \
183             STORE (p + 1); \
184             STORE (p + 2); \
185             STORE (p + 3); \
186             STORE (p + 4); \
187             STORE (p + 5); \
188             STORE (p + 6); \
189             STORE (p + 7); \
190             p += 8; \
191             nlw--; \
192         } \
193         right \
194         p += nlwExtra; \
195     } \
196 }
197 #else
198 #define Expand(left,right) {\
199     while (h--) { \
200         srcpix = psrc[srcy]; \
201         MROP_PREBUILD(srcpix); \
202         ++srcy; \
203         if (srcy == tileHeight) \
204             srcy = 0; \
205         left \
206         nlw = nlwMiddle; \
207         while (nlw--) \
208         { \
209             STORE(p); \
210             p++; \
211         } \
212         right \
213         p += nlwExtra; \
214     } \
215 }
216 #endif
217 #endif /*PSZ == 24*/
218
219 void
220 MROP_NAME(cfbFillRectTile32) (pDrawable, pGC, nBox, pBox)
221     DrawablePtr     pDrawable;
222     GCPtr           pGC;
223     int             nBox;       /* number of boxes to fill */
224     BoxPtr          pBox;       /* pointer to list of boxes to fill */
225 {
226     register unsigned long srcpix;      
227     unsigned long *psrc;                /* pointer to bits in tile, if needed */
228     int tileHeight;     /* height of the tile */
229
230     int nlwDst;         /* width in longwords of the dest pixmap */
231     int w;              /* width of current box */
232     register int h;     /* height of current box */
233     register unsigned long startmask;
234     register unsigned long endmask; /* masks for reggedy bits at either end of line */
235     int nlwMiddle;      /* number of longwords between sides of boxes */
236     int nlwExtra;       /* to get from right of box to left of next span */
237     register int nlw;   /* loop version of nlwMiddle */
238     register unsigned long *p;  /* pointer to bits we're writing */
239     int y;              /* current scan line */
240     int srcy;           /* current tile position */
241
242     unsigned long *pbits;/* pointer to start of pixmap */
243     PixmapPtr       tile;       /* rotated, expanded tile */
244     MROP_DECLARE_REG()
245     MROP_PREBUILT_DECLARE()
246 #if PSZ == 24
247     unsigned long xtmp;
248 #endif
249
250     tile = cfbGetGCPrivate(pGC)->pRotatedPixmap;
251     tileHeight = tile->drawable.height;
252     psrc = (unsigned long *)tile->devPrivate.ptr;
253
254     MROP_INITIALIZE(pGC->alu, pGC->planemask);
255
256     cfbGetLongWidthAndPointer (pDrawable, nlwDst, pbits)
257
258     while (nBox--)
259     {
260         w = pBox->x2 - pBox->x1;
261         h = pBox->y2 - pBox->y1;
262         y = pBox->y1;
263 #if PSZ == 24
264         xtmp = pBox->x1;
265         p = pbits + (y * nlwDst) + ((pBox->x1*3) >> 2);
266 /*      p = pbits + (y * nlwDst) + ((pBox->x1>> 2)*3);*/
267 #else
268         p = pbits + (y * nlwDst) + (pBox->x1 >> PWSH);
269 #endif
270         srcy = y % tileHeight;
271
272 #if PSZ == 24
273         if (w == 1  &&  ((pBox->x1 & 3) == 0  ||  (pBox->x1 & 3) == 3))
274 #else
275         if ( ((pBox->x1 & PIM) + w) <= PPW)
276 #endif
277         {
278             maskpartialbits(pBox->x1, w, startmask);
279             nlwExtra = nlwDst;
280             while (h--)
281             {
282                 srcpix = psrc[srcy];
283                 MROP_PREBUILD(srcpix);
284                 ++srcy;
285                 if (srcy == tileHeight)
286                     srcy = 0;
287                 *p = MROP_PREBUILT_MASK (srcpix, *p, startmask);
288                 p += nlwExtra;
289             }
290         }
291         else
292         {
293             maskbits(pBox->x1, w, startmask, endmask, nlwMiddle);
294             nlwExtra = nlwDst - nlwMiddle;
295
296             if (startmask)
297             {
298                 nlwExtra -= 1;
299                 if (endmask)
300                 {
301                     Expand(*p = MROP_PREBUILT_MASK(srcpix, *p, startmask); p++;,
302                            *p = MROP_PREBUILT_MASK(srcpix, *p, endmask);)
303                 }
304                 else
305                 {
306                     Expand(*p = MROP_PREBUILT_MASK(srcpix, *p, startmask); p++;,
307                            ;)
308                 }
309             }
310             else
311             {
312                 if (endmask)
313                 {
314                     Expand(;,
315                            *p = MROP_PREBUILT_MASK(srcpix, *p, endmask);)
316                 }
317                 else
318                 {
319                     Expand(;,
320                            ;)
321                 }
322             }
323         }
324         pBox++;
325     }
326 }
327
328 void
329 MROP_NAME(cfbTile32FS)(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
330     DrawablePtr pDrawable;
331     GCPtr       pGC;
332     int         nInit;                  /* number of spans to fill */
333     DDXPointPtr pptInit;                /* pointer to list of start points */
334     int         *pwidthInit;            /* pointer to list of n widths */
335     int         fSorted;
336 {
337                                 /* next three parameters are post-clip */
338     int                 n;      /* number of spans to fill */
339     DDXPointPtr         ppt;    /* pointer to list of start points */
340     int                 *pwidth;/* pointer to list of n widths */
341     unsigned long       *pbits; /* pointer to start of bitmap */
342     int                 nlwDst; /* width in longwords of bitmap */
343     register unsigned long *p;  /* pointer to current longword in bitmap */
344     register int        w;      /* current span width */
345     register int        nlw;
346     register int        x;
347     register unsigned long startmask;
348     register unsigned long endmask;
349     register unsigned long  srcpix;
350     int                 y;
351     int                 *pwidthFree;/* copies of the pointers to free */
352     DDXPointPtr         pptFree;
353     PixmapPtr           tile;
354     unsigned long       *psrc;  /* pointer to bits in tile */
355     int                 tileHeight;/* height of the tile */
356     MROP_DECLARE_REG ()
357     MROP_PREBUILT_DECLARE()
358 #if PSZ == 24      
359     unsigned long       xtmp;
360 #endif
361
362     n = nInit * miFindMaxBand( cfbGetCompositeClip(pGC) );
363     pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
364     pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
365     if(!pptFree || !pwidthFree)
366     {
367         if (pptFree) DEALLOCATE_LOCAL(pptFree);
368         if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
369         return;
370     }
371     pwidth = pwidthFree;
372     ppt = pptFree;
373     n = miClipSpans( cfbGetCompositeClip(pGC),
374                      pptInit, pwidthInit, nInit,
375                      ppt, pwidth, fSorted);
376
377     tile = cfbGetGCPrivate(pGC)->pRotatedPixmap;
378     tileHeight = tile->drawable.height;
379     psrc = (unsigned long *)tile->devPrivate.ptr;
380
381     MROP_INITIALIZE(pGC->alu, pGC->planemask);
382
383     cfbGetLongWidthAndPointer (pDrawable, nlwDst, pbits)
384
385 #if MROP == Mcopy
386     if (!(tileHeight & (tileHeight-1)))
387     {
388         tileHeight--;
389         while (n--)
390         {
391             x = ppt->x;
392             y = ppt->y;
393             ++ppt;
394             w = *pwidth++;
395 #if PSZ == 24
396 /*          p = pbits + (y * nlwDst) + ((x*3) >> 2);*/
397             xtmp = x;
398             p = pbits + (y * nlwDst) + ((x >> 2)*3);
399 #else
400             p = pbits + (y * nlwDst) + (x >> PWSH);
401 #endif
402             srcpix = psrc[y & tileHeight];
403             MROP_PREBUILD(srcpix);
404     
405 #if PSZ == 24
406             if ((x & 3) + w < 5)
407 #else
408             if ((x & PIM) + w < PPW)
409 #endif
410             {
411                 maskpartialbits(x, w, startmask);
412                 *p = MROP_PREBUILT_MASK (srcpix, *p, startmask);
413             }
414             else
415             {
416                 maskbits(x, w, startmask, endmask, nlw);
417                 if (startmask)
418                 {
419                     *p = MROP_PREBUILT_MASK(srcpix, *p, startmask);
420 #if PSZ == 24
421                     if(xtmp&3) p++;
422                     xtmp++;
423 #else
424                     p++;
425 #endif
426                 }
427                 while (nlw--)
428                 {
429 #if PSZ == 24
430                     STORE24(p,xtmp);
431                     if(xtmp&3) p++;
432                     ++xtmp;
433 #else
434                     STORE(p);
435                     ++p;
436 #endif
437                 }
438                 if (endmask)
439                 {
440                     *p = MROP_PREBUILT_MASK(srcpix, *p, endmask);
441                 }
442             }
443         }
444     }
445     else
446 #endif
447     {
448         while (n--)
449         {
450             x = ppt->x;
451             y = ppt->y;
452             ++ppt;
453             w = *pwidth++;
454 #if PSZ == 24
455 /*          p = pbits + (y * nlwDst) + ((x *3)>> 2);*/
456             p = pbits + (y * nlwDst) + ((x >> 2)*3);
457             xtmp = x;
458 #else
459             p = pbits + (y * nlwDst) + (x >> PWSH);
460 #endif
461             srcpix = psrc[y % tileHeight];
462             MROP_PREBUILD(srcpix);
463     
464 #if PSZ == 24
465             if ((x & 3) + w < 5)
466 #else
467             if ((x & PIM) + w < PPW)
468 #endif
469             {
470                 maskpartialbits(x, w, startmask);
471                 *p = MROP_PREBUILT_MASK (srcpix, *p, startmask);
472             }
473             else
474             {
475                 maskbits(x, w, startmask, endmask, nlw);
476                 if (startmask)
477                 {
478                     *p = MROP_PREBUILT_MASK(srcpix, *p, startmask);
479 #if PSZ == 24
480                     if(xtmp&3)p++;
481                     xtmp++;
482 #else
483                     p++;
484 #endif
485                 }
486                 while (nlw--)
487                 {
488 #if PSZ == 24
489                     STORE24(p,xtmp);
490                     if(xtmp&3)p++;
491                     xtmp++;
492 #else
493                     STORE(p);
494                     ++p;
495 #endif
496                 }
497                 if (endmask)
498                 {
499                     *p = MROP_PREBUILT_MASK(srcpix, *p, endmask);
500                 }
501             }
502         }
503     }
504     DEALLOCATE_LOCAL(pptFree);
505     DEALLOCATE_LOCAL(pwidthFree);
506 }