]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/cfb/cfbrrop.c
Support RDP5 logon packets.
[rdpsrv] / Xserver / programs / Xserver / cfb / cfbrrop.c
1 /*
2  * $XConsortium: cfbrrop.c,v 1.8 94/04/17 20:28:59 dpw Exp $
3  *
4 Copyright (c) 1989  X Consortium
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
19 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23 Except as contained in this notice, the name of the X Consortium shall not be
24 used in advertising or otherwise to promote the sale, use or other dealings
25 in this Software without prior written authorization from the X Consortium.
26  *
27  * Author:  Keith Packard, MIT X Consortium
28  */
29
30 /* cfb reduced rasterop computations */
31
32 #include "X.h"
33 #include "Xmd.h"
34 #include "Xproto.h"
35 #include "cfb.h"
36 #include "cfbmskbits.h"
37
38 /* A description:
39  *
40  * There are four possible operations on each bit in the destination word,
41  *
42  *          1   2   3   4
43  *
44  *    0     0   0   1   1
45  *    1     0   1   0   1
46  *
47  * On examination of the reduced rop equation (dst = (dst & and) ^ xor),
48  * these four fall to reduced rops as follows:
49  *
50  *  and     0   1   1   0
51  *  xor     0   0   1   1
52  *
53  * or, (if 'and' is expensive) (dst = (dst | or) ^ xor)
54  *
55  *  or      1   0   0   1
56  *  xor     1   0   1   0
57  *
58  * The trouble with using this later equation is that trivial
59  * rasterop reduction is more difficult; some common rasterops
60  * use complicated expressions of xor/and instead of the simple
61  * ones while other common rasterops are not made any simpler:
62  *
63  * GXcopy:      *dst = ~xor             instead of  *dst = xor
64  * GXand:       *dst = *dst & ~or       instead of  *dst = *dst & and
65  * GXor:        *dst = *dst | or        instead of  *dst = *dst | xor
66  * GXxor:       *dst = *dst ^ xor       instead of  *dst = *dst ^ xor
67  *
68  * If you're really set on using this second mechanism, the changes
69  * are pretty simple.
70  *
71  * All that remains is to provide a mechanism for computing and/xor values
72  * based on the raster op and foreground value.
73  *
74  * The 16 rops fall as follows, with the associated reduced
75  * rop and/xor and or/xor values.  The values in parenthesis following the
76  * reduced values gives an equation using the source value for
77  * the reduced value, and is one of {0, src, ~src, 1} as appropriate.
78  *
79  *      clear           and             andReverse      copy
80  *     src  0   1           0   1           0   1           0   1
81  *  dst 0   0   0       0   0   0       0   0   1       0   0   1
82  *      1   0   0       1   0   1       1   0   0       1   0   1
83  *
84  *  and     0   0 (0)       0   1 (src)     0   1 (src)     0   0 (0)
85  *  xor     0   0 (0)       0   0 (0)       0   1 (src)     0   1 (src)
86  *
87  *  or      1   1 (1)       1   0 (~src)    1   0 (~src)    1   1 (1)
88  *  xor     1   1 (1)       1   0 (~src)    1   1 (1)       1   0 (~src)
89  *
90  *      andInverted     noop            xor             or
91  *     src  0   1           0   1           0   1           0   1
92  *  dst 0   0   0       0   0   0       0   0   1       0   0   1
93  *      1   1   0       1   1   1       1   1   0       1   1   1
94  *
95  *  and     1   0 (~src)    1   1 (1)       1   1 (1)       1   0 (~src)
96  *  xor     0   0 (0)       0   0 (0)       0   1 (src)     0   1 (src)
97  *
98  *  or      0   1 (src)     0   0 (0)       0   0 (0)       0   1 (src)
99  *  xor     0   1 (src)     0   0 (0)       0   1 (src)     0   0 (0)
100  *
101  *      nor             equiv           invert          orReverse
102  *     src  0   1           0   1           0   1           0   1
103  *  dst 0   1   0       0   1   0       0   1   1       0   1   1
104  *      1   0   0       1   0   1       1   0   0       1   0   1
105  *
106  *  and     1   0 (~src)    1   1 (1)       1   1 (1)       1   0 (~src)
107  *  xor     1   0 (~src)    1   0 (~src)    1   1 (1)       1   1 (1)
108  *
109  *  or      0   1 (src)     0   0 (0)       0   0 (0)       0   1 (src)
110  *  xor     1   1 (1)       1   0 (~src)    1   1 (1)       1   0 (~src)
111  *
112  *      copyInverted    orInverted      nand            set
113  *     src  0   1           0   1           0   1           0   1
114  *  dst 0   1   0       0   1   0       0   1   1       0   1   1
115  *      1   1   0       1   1   1       1   1   0       1   1   1
116  *
117  *  and     0   0 (0)       0   1 (src)     0   1 (src)     0   0 (0)
118  *  xor     1   0 (~src)    1   0 (~src)    1   1 (1)       1   1 (1)
119  *
120  *  or      1   1 (1)       1   0 (~src)    1   0 (~src)    1   1 (1)
121  *  xor     0   1 (src)     0   0 (0)       0   1 (src)     0   0 (0)
122  */
123
124 int
125 cfbReduceRasterOp (rop, fg, pm, andp, xorp)
126     int             rop;
127     unsigned long   fg, pm;
128     unsigned long   *andp, *xorp;
129 {
130     unsigned long   and, xor;
131     int             rrop;
132
133     fg = PFILL (fg);
134     pm = PFILL (pm);
135     switch (rop)
136     {
137     case GXclear:
138         and = 0;
139         xor = 0;
140         break;
141     case GXand:
142         and = fg;
143         xor = 0;
144         break;
145     case GXandReverse:
146         and = fg;
147         xor = fg;
148         break;
149     case GXcopy:
150         and = 0;
151         xor = fg;
152         break;
153     case GXandInverted:
154         and = ~fg;
155         xor = 0;
156         break;
157     case GXnoop:
158         and = ~0;
159         xor = 0;
160         break;
161     case GXxor:
162         and = ~0;
163         xor = fg;
164         break;
165     case GXor:
166         and = ~fg;
167         xor = fg;
168         break;
169     case GXnor:
170         and = ~fg;
171         xor = ~fg;
172         break;
173     case GXequiv:
174         and = ~0;
175         xor = ~fg;
176         break;
177     case GXinvert:
178         and = ~0;
179         xor = ~0;
180         break;
181     case GXorReverse:
182         and = ~fg;
183         xor = ~0;
184         break;
185     case GXcopyInverted:
186         and = 0;
187         xor = ~fg;
188         break;
189     case GXorInverted:
190         and = fg;
191         xor = ~fg;
192         break;
193     case GXnand:
194         and = fg;
195         xor = ~0;
196         break;
197     case GXset:
198         and = 0;
199         xor = ~0;
200         break;
201     }
202     and |= ~pm;
203     xor &= pm;
204     *andp = and;
205     *xorp = xor;
206     /* check for some special cases to reduce computation */
207     if (and == 0)
208         rrop = GXcopy;
209     /* nothing checks for GXnoop
210     else if (and == ~0 && xor == 0)
211         rrop = GXnoop;
212     */
213     else if (and == ~0)
214         rrop = GXxor;
215     else if (xor == 0)
216         rrop = GXand;
217     else if ( (and ^ xor) == ~0) /* fix XBUG 6541 */
218         rrop = GXor;
219     else
220         rrop = GXset;   /* rop not reduced */
221     return rrop;
222 }