]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/mfb/mfbpushpxl.c
Support RDP5 logon packets.
[rdpsrv] / Xserver / programs / Xserver / mfb / mfbpushpxl.c
1 /***********************************************************
2
3 Copyright (c) 1987  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 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
28
29                         All Rights Reserved
30
31 Permission to use, copy, modify, and distribute this software and its 
32 documentation for any purpose and without fee is hereby granted, 
33 provided that the above copyright notice appear in all copies and that
34 both that copyright notice and this permission notice appear in 
35 supporting documentation, and that the name of Digital not be
36 used in advertising or publicity pertaining to distribution of the
37 software without specific, written prior permission.  
38
39 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
45 SOFTWARE.
46
47 ******************************************************************/
48 /* $XConsortium: mfbpushpxl.c,v 5.6 94/04/17 20:28:31 dpw Exp $ */
49
50 #include "X.h"
51 #include "gcstruct.h"
52 #include "scrnintstr.h"
53 #include "pixmapstr.h"
54 #include "miscstruct.h"
55 #include "maskbits.h"
56 #include "regionstr.h"
57 #include "mfb.h"
58
59 /*  mfbSolidPP is courtesy of xhacks@csri.toronto.edu
60
61     For fillStyle==FillSolid, a monochrome PushPixels can be reduced to
62     a ROP in the following way:  (Note that the ROP is the same as the
63     result of ROP(src=0x3,dst=0x5))
64
65                         src=0011 0000 0011
66                         dst=0101 0101 0101
67                         rop      fg=0 fg=1
68         GXclear         0x0 0000 0100 0100 0
69         GXand           0x1 0001 0100 0101  s&d
70         GXandReverse    0x2 0010 0100 0110 s&~d
71         GXcopy          0x3 0011 0100 0111 s
72         GXandInverted   0x4 0100 0101 0100 ~s&d
73         GXnoop          0x5 0101 0101 0101 d
74         GXxor           0x6 0110 0101 0110 s^d
75         GXor            0x7 0111 0101 0111 s|d
76         GXnor           0x8 1000 0110 0100 ~s&~d
77         GXequiv         0x9 1001 0110 0101 ~s^d
78         GXinvert        0xa 1010 0110 0110 ~d
79         GXorReverse     0xb 1011 0110 0111 s|~d
80         GXcopyInverted  0xc 1100 0111 0100 ~s
81         GXorInverted    0xd 1101 0111 0101 ~s|d
82         GXnand          0xe 1110 0111 0110 ~s|~d
83         GXset           0xf 1111 0111 0111 1
84
85 For src=0: newRop = 0x4|(rop>>2)
86 For src=1: newRop = 0x4|(rop&3)
87 */
88
89 /* mfbSolidPP -- squeegees the forground color of pGC through pBitMap
90  * into pDrawable.  pBitMap is a stencil (dx by dy of it is used, it may
91  * be bigger) which is placed on the drawable at xOrg, yOrg.  Where a 1 bit
92  * is set in the bitmap, the fill style is put onto the drawable using
93  * the GC's logical function. The drawable is not changed where the bitmap
94  * has a zero bit or outside the area covered by the stencil.
95  */
96 void
97 mfbSolidPP(pGC, pBitMap, pDrawable, dx, dy, xOrg, yOrg)
98     GCPtr       pGC;
99     PixmapPtr   pBitMap;
100     DrawablePtr pDrawable;
101     int         dx, dy, xOrg, yOrg;
102 {
103     unsigned char alu;
104     RegionRec rgnDst;
105     DDXPointPtr pptSrc;
106     BoxRec srcBox;
107     register DDXPointPtr ppt;
108     register BoxPtr pbox;
109     int i;
110
111     if (!pGC->planemask & 1) return;
112
113     /* compute the reduced rop function */
114     alu = pGC->alu;
115     if (!(pGC->fgPixel&1)) alu >>= 2;
116     alu = (alu & 0x3) | 0x4;
117     if (alu == GXnoop) return;
118
119     srcBox.x1 = xOrg;
120     srcBox.y1 = yOrg;
121     srcBox.x2 = xOrg + dx;
122     srcBox.y2 = yOrg + dy;
123     REGION_INIT(pGC->pScreen, &rgnDst, &srcBox, 1);
124
125     /* clip the shape of the dst to the destination composite clip */
126     REGION_INTERSECT(pGC->pScreen, &rgnDst, &rgnDst,
127         ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip);
128
129     if (!REGION_NIL(&rgnDst))
130     {
131         i = REGION_NUM_RECTS(&rgnDst);
132         pptSrc = (DDXPointPtr)ALLOCATE_LOCAL(i * sizeof(DDXPointRec));
133         if(pptSrc)
134         {
135             for (pbox = REGION_RECTS(&rgnDst), ppt = pptSrc;
136                  --i >= 0;
137                  pbox++, ppt++)
138             {
139                 ppt->x = pbox->x1 - xOrg;
140                 ppt->y = pbox->y1 - yOrg;
141             }
142             mfbDoBitblt((DrawablePtr)pBitMap, pDrawable, alu, &rgnDst, pptSrc);
143             DEALLOCATE_LOCAL(pptSrc);
144         }
145     }
146     REGION_UNINIT(pGC->pScreen, &rgnDst);
147 }
148
149 #define NPT 128
150
151 /* mfbPushPixels -- squeegees the forground color of pGC through pBitMap
152  * into pDrawable.  pBitMap is a stencil (dx by dy of it is used, it may
153  * be bigger) which is placed on the drawable at xOrg, yOrg.  Where a 1 bit
154  * is set in the bitmap, the fill style is put onto the drawable using
155  * the GC's logical function. The drawable is not changed where the bitmap
156  * has a zero bit or outside the area covered by the stencil.
157  */
158 void
159 mfbPushPixels(pGC, pBitMap, pDrawable, dx, dy, xOrg, yOrg)
160     GCPtr       pGC;
161     PixmapPtr   pBitMap;
162     DrawablePtr pDrawable;
163     int         dx, dy, xOrg, yOrg;
164 {
165     int         h, dxDivPPW, ibEnd;
166     PixelType *pwLineStart;
167     register PixelType  *pw, *pwEnd;
168     register PixelType mask;
169     register int ib;
170     register PixelType w;
171     register int ipt;           /* index into above arrays */
172     Bool        fInBox;
173     DDXPointRec pt[NPT];
174     int         width[NPT];
175
176     /* Now scan convert the pixmap and use the result to call fillspans in
177      * in the drawable with the original GC */
178     ipt = 0;
179     dxDivPPW = dx/PPW;
180     for(h = 0; h < dy; h++)
181     {
182
183         pw = (PixelType *)
184              (((char *)(pBitMap->devPrivate.ptr))+(h * pBitMap->devKind));
185         pwLineStart = pw;
186         /* Process all words which are fully in the pixmap */
187         
188         fInBox = FALSE;
189         pwEnd = pwLineStart + dxDivPPW;
190         while(pw  < pwEnd)
191         {
192             w = *pw;
193             mask = endtab[1];
194             for(ib = 0; ib < PPW; ib++)
195             {
196                 if(w & mask)
197                 {
198                     if(!fInBox)
199                     {
200                         pt[ipt].x = ((pw - pwLineStart) << PWSH) + ib + xOrg;
201                         pt[ipt].y = h + yOrg;
202                         /* start new box */
203                         fInBox = TRUE;
204                     }
205                 }
206                 else
207                 {
208                     if(fInBox)
209                     {
210                         width[ipt] = ((pw - pwLineStart) << PWSH) + 
211                                      ib + xOrg - pt[ipt].x;
212                         if (++ipt >= NPT)
213                         {
214                             (*pGC->ops->FillSpans)(pDrawable, pGC, NPT, pt,
215                                               width, TRUE);
216                             ipt = 0;
217                         }
218                         /* end box */
219                         fInBox = FALSE;
220                     }
221                 }
222                 mask = SCRRIGHT(mask, 1);
223             }
224             pw++;
225         }
226         ibEnd = dx & PIM;
227         if(ibEnd)
228         {
229             /* Process final partial word on line */
230             w = *pw;
231             mask = endtab[1];
232             for(ib = 0; ib < ibEnd; ib++)
233             {
234                 if(w & mask)
235                 {
236                     if(!fInBox)
237                     {
238                         /* start new box */
239                         pt[ipt].x = ((pw - pwLineStart) << PWSH) + ib + xOrg;
240                         pt[ipt].y = h + yOrg;
241                         fInBox = TRUE;
242                     }
243                 }
244                 else
245                 {
246                     if(fInBox)
247                     {
248                         /* end box */
249                         width[ipt] = ((pw - pwLineStart) << PWSH) + 
250                                      ib + xOrg - pt[ipt].x;
251                         if (++ipt >= NPT)
252                         {
253                             (*pGC->ops->FillSpans)(pDrawable, pGC, NPT, pt,
254                                               width, TRUE);
255                             ipt = 0;
256                         }
257                         fInBox = FALSE;
258                     }
259                 }
260                 mask = SCRRIGHT(mask, 1);
261             }
262         }
263         /* If scanline ended with last bit set, end the box */
264         if(fInBox)
265         {
266             width[ipt] = dx + xOrg - pt[ipt].x;
267             if (++ipt >= NPT)
268             {
269                 (*pGC->ops->FillSpans)(pDrawable, pGC, NPT, pt, width, TRUE);
270                 ipt = 0;
271             }
272         }
273     }
274     /* Flush any remaining spans */
275     if (ipt)
276     {
277         (*pGC->ops->FillSpans)(pDrawable, pGC, ipt, pt, width, TRUE);
278     }
279 }