]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/mfb/mergerop.h
Support RDP5 logon packets.
[rdpsrv] / Xserver / programs / Xserver / mfb / mergerop.h
1 /*
2  * $XConsortium: mergerop.h,v 1.11 95/06/08 23:20:39 gildea Exp $
3  * $XFree86: xc/programs/Xserver/mfb/mergerop.h,v 3.1 1996/06/29 09:10:20 dawes Exp $
4  *
5 Copyright (c) 1989  X Consortium
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
20 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24 Except as contained in this notice, the name of the X Consortium shall not be
25 used in advertising or otherwise to promote the sale, use or other dealings
26 in this Software without prior written authorization from the X Consortium.
27  *
28  * Author:  Keith Packard, MIT X Consortium
29  */
30
31 #ifndef _MERGEROP_H_
32 #define _MERGEROP_H_
33
34 #ifndef GXcopy
35 #include "X.h"
36 #endif
37
38 typedef struct _mergeRopBits {
39     unsigned long   ca1, cx1, ca2, cx2;
40 } mergeRopRec, *mergeRopPtr;
41
42 extern mergeRopRec      mergeRopBits[16];
43
44 #if PPW != PGSZ /* cfb */
45 #define DeclareMergeRop() unsigned long   _ca1, _cx1, _ca2, _cx2;
46 #define DeclarePrebuiltMergeRop()       unsigned long   _cca, _ccx;
47 #else /* mfb */
48 #define DeclareMergeRop() unsigned long   _ca1, _cx1, _ca2, _cx2;
49 #define DeclarePrebuiltMergeRop()       unsigned long   _cca, _ccx;
50 #endif
51
52 #if PPW != PGSZ /* cfb */
53 #define InitializeMergeRop(alu,pm) {\
54     unsigned long   _pm; \
55     mergeRopPtr  _bits; \
56     _pm = PFILL(pm); \
57     _bits = &mergeRopBits[alu]; \
58     _ca1 = _bits->ca1 &  _pm; \
59     _cx1 = _bits->cx1 | ~_pm; \
60     _ca2 = _bits->ca2 &  _pm; \
61     _cx2 = _bits->cx2 &  _pm; \
62 }
63 #else /* mfb */
64 #define InitializeMergeRop(alu,pm) {\
65     mergeRopPtr  _bits; \
66     _bits = &mergeRopBits[alu]; \
67     _ca1 = _bits->ca1; \
68     _cx1 = _bits->cx1; \
69     _ca2 = _bits->ca2; \
70     _cx2 = _bits->cx2; \
71 }
72 #endif
73
74 /* AND has higher precedence than XOR */
75
76 #define DoMergeRop(src, dst) \
77     ((dst) & ((src) & _ca1 ^ _cx1) ^ ((src) & _ca2 ^ _cx2))
78
79 #define DoMergeRop24(src,dst,index) {\
80         register int idx = ((index) & 3)<< 1; \
81         *(dst) = (((*(dst)) & cfbrmask[idx]) | (((*(dst)) & cfbmask[idx]) & \
82         ((((src) & _ca1 ^ _cx1)<<cfb24Shift[idx])&cfbmask[idx]) ^ \
83         ((((src) & _ca2 ^ _cx2)<<cfb24Shift[idx])&cfbmask[idx]))); \
84         idx++; \
85         (dst)++; \
86         *(dst) = (((*(dst)) & cfbrmask[idx]) | (((*(dst)) & cfbmask[idx]) & \
87         ((((src) & _ca1 ^ _cx1)>>cfb24Shift[idx])&cfbmask[idx]) ^ \
88         ((((src) & _ca2 ^ _cx2)>>cfb24Shift[idx])&cfbmask[idx]))); \
89         (dst)--; \
90         }
91
92 #define DoPrebuiltMergeRop(dst) ((dst) & _cca ^ _ccx)
93
94 #define DoPrebuiltMergeRop24(dst,index) { \
95         register int idx = ((index) & 3)<< 1; \
96         *(dst) = (((*(dst)) & cfbrmask[idx]) | (((*(dst)) & cfbmask[idx]) &\
97         (( _cca <<cfb24Shift[idx])&cfbmask[idx]) ^ \
98         (( _ccx <<cfb24Shift[idx])&cfbmask[idx]))); \
99         idx++; \
100         (dst)++; \
101         *(dst) = (((*(dst)) & cfbrmask[idx]) | (((*(dst)) & cfbmask[idx]) &\
102         (( _cca >>cfb24Shift[idx])&cfbmask[idx]) ^ \
103         (( _ccx >>cfb24Shift[idx])&cfbmask[idx]))); \
104         (dst)--; \
105         }
106
107 #define DoMaskPrebuiltMergeRop(dst,mask) \
108     ((dst) & (_cca | ~(mask)) ^ (_ccx & (mask)))
109
110 #define PrebuildMergeRop(src) ((_cca = (src) & _ca1 ^ _cx1), \
111                                (_ccx = (src) & _ca2 ^ _cx2))
112
113 #define DoMaskMergeRop(src, dst, mask) \
114     ((dst) & (((src) & _ca1 ^ _cx1) | ~(mask)) ^ (((src) & _ca2 ^ _cx2) & (mask)))
115
116 #define DoMaskMergeRop24(src, dst, mask, index)  {\
117         register int idx = ((index) & 3)<< 1; \
118         *(dst) = (((*(dst)) & cfbrmask[idx]) | (((*(dst)) & cfbmask[idx]) & \
119         ((((((src) & _ca1 ^ _cx1) |(~mask))<<cfb24Shift[idx])&cfbmask[idx]) ^ \
120         (((((src) & _ca2 ^ _cx2)&(mask))<<cfb24Shift[idx])&cfbmask[idx])))); \
121         idx++; \
122         (dst)++; \
123         *(dst) = (((*(dst)) & cfbrmask[idx]) | (((*(dst)) & cfbmask[idx]) & \
124         ((((((src) & _ca1 ^ _cx1) |(~mask))>>cfb24Shift[idx])&cfbmask[idx]) ^ \
125         (((((src) & _ca2 ^ _cx2)&(mask))>>cfb24Shift[idx])&cfbmask[idx])))); \
126         (dst)--; \
127         }
128
129 #ifndef MROP
130 #define MROP 0
131 #endif
132
133 #define Mclear          (1<<GXclear)
134 #define Mand            (1<<GXand)
135 #define MandReverse     (1<<GXandReverse)
136 #define Mcopy           (1<<GXcopy)
137 #define MandInverted    (1<<GXandInverted)
138 #define Mnoop           (1<<GXnoop)
139 #define Mxor            (1<<GXxor)
140 #define Mor             (1<<GXor)
141 #define Mnor            (1<<GXnor)
142 #define Mequiv          (1<<GXequiv)
143 #define Minvert         (1<<GXinvert)
144 #define MorReverse      (1<<GXorReverse)
145 #define McopyInverted   (1<<GXcopyInverted)
146 #define MorInverted     (1<<GXorInverted)
147 #define Mnand           (1<<GXnand)
148 #define Mset            (1<<GXset)
149
150 #define MROP_PIXEL24(pix, idx) \
151         (((*(pix) & cfbmask[(idx)<<1]) >> cfb24Shift[(idx)<<1])| \
152         ((*((pix)+1) & cfbmask[((idx)<<1)+1]) << cfb24Shift[((idx)<<1)+1]))
153
154 #define MROP_SOLID24P(src,dst,sindex, index) \
155         MROP_SOLID24(MROP_PIXEL24(src,sindex),dst,index)
156 #define MROP_MASK24P(src,dst,mask,sindex,index) \
157         MROP_MASK24(MROP_PIXEL24(src,sindex),dst,mask,index)
158
159 #if (MROP) == Mcopy
160 #define MROP_DECLARE()
161 #define MROP_DECLARE_REG()
162 #define MROP_INITIALIZE(alu,pm)
163 #define MROP_SOLID(src,dst)     (src)
164 #define MROP_SOLID24(src,dst,index)         {\
165         register int idx = ((index) & 3)<< 1; \
166         *(dst) = (*(dst) & cfbrmask[idx])|(((src)<<cfb24Shift[idx])&cfbmask[idx]); \
167         idx++; \
168         *((dst)+1) = (*((dst)+1) & cfbrmask[idx])|(((src)>>cfb24Shift[idx])&cfbmask[idx]); \
169         }
170 #define MROP_MASK(src,dst,mask) ((dst) & ~(mask) | (src) & (mask))
171 #define MROP_MASK24(src,dst,mask,index) {\
172         register int idx = ((index) & 3)<< 1; \
173         *(dst) = (*(dst) & cfbrmask[idx] &(~(((mask)<< cfb24Shift[idx])&cfbmask[idx])) | \
174                 ((((src)&(mask))<<cfb24Shift[idx])&cfbmask[idx])); \
175         idx++; \
176         *((dst)+1) = (*((dst)+1) & cfbrmask[idx] &(~(((mask)>>cfb24Shift[idx])&cfbmask[idx])) | \
177                 ((((src)&(mask))>>cfb24Shift[idx])&cfbmask[idx])); \
178         }
179 #define MROP_NAME(prefix)       MROP_NAME_CAT(prefix,Copy)
180 #endif
181
182 #if (MROP) == McopyInverted
183 #define MROP_DECLARE()
184 #define MROP_DECLARE_REG()
185 #define MROP_INITIALIZE(alu,pm)
186 #define MROP_SOLID(src,dst)     (~(src))
187 #define MROP_SOLID24(src,dst,index)         {\
188         register int idx = ((index) & 3)<< 1; \
189         *(dst) = (*(dst) & cfbrmask[idx])|(((~(src))<<cfb24Shift[idx])&cfbmask[idx]); \
190         idx++; \
191         (dst)++; \
192         *(dst) = (*(dst) & cfbrmask[idx])|(((~(src))>>cfb24Shift[idx])&cfbmask[idx]); \
193         (dst)--; \
194         }
195 #define MROP_MASK(src,dst,mask) ((dst) & ~(mask) | (~(src)) & (mask))
196 #define MROP_MASK24(src,dst,mask,index) {\
197         register int idx = ((index) & 3)<< 1; \
198         *(dst) = (*(dst) & cfbrmask[idx] &(~(((mask)<< cfb24Shift[idx])&cfbmask[idx])) | \
199                 ((((~(src))&(mask))<<cfb24Shift[idx])&cfbmask[idx])); \
200         idx++; \
201         (dst)++; \
202         *(dst) = (*(dst) & cfbrmask[idx] &(~(((mask)>>cfb24Shift[idx])&cfbmask[idx])) | \
203                 ((((~(src))&(mask))>>cfb24Shift[idx])&cfbmask[idx])); \
204         (dst)--; \
205         }
206 #define MROP_NAME(prefix)       MROP_NAME_CAT(prefix,CopyInverted)
207 #endif
208
209 #if (MROP) == Mxor
210 #define MROP_DECLARE()
211 #define MROP_DECLARE_REG()
212 #define MROP_INITIALIZE(alu,pm)
213 #define MROP_SOLID(src,dst)     ((src) ^ (dst))
214 #define MROP_SOLID24(src,dst,index)         {\
215         register int idx = ((index) & 3)<< 1; \
216         *(dst) ^= (((src)<<cfb24Shift[idx])&cfbmask[idx]); \
217         idx++; \
218         (dst)++; \
219         *(dst) ^= (((src)>>cfb24Shift[idx])&cfbmask[idx]); \
220         (dst)--; \
221         }
222 #define MROP_MASK(src,dst,mask) (((src) & (mask)) ^ (dst))
223 #define MROP_MASK24(src,dst,mask,index) {\
224         register int idx = ((index) & 3)<< 1; \
225         *(dst) ^= ((((src)&(mask))<<cfb24Shift[idx])&cfbmask[idx]); \
226         idx++; \
227         (dst)++; \
228         *(dst) ^= ((((src)&(mask))>>cfb24Shift[idx])&cfbmask[idx]); \
229         (dst)--; \
230         }
231 #define MROP_NAME(prefix)       MROP_NAME_CAT(prefix,Xor)
232 #endif
233
234 #if (MROP) == Mor
235 #define MROP_DECLARE()
236 #define MROP_DECLARE_REG()
237 #define MROP_INITIALIZE(alu,pm)
238 #define MROP_SOLID(src,dst)     ((src) | (dst))
239 #define MROP_SOLID24(src,dst,index)         {\
240         register int idx = ((index) & 3)<< 1; \
241         *(dst) |= (((src)<<cfb24Shift[idx])&cfbmask[idx]); \
242         idx++; \
243         (dst)++; \
244         *(dst) |= (((src)>>cfb24Shift[idx])&cfbmask[idx]); \
245         (dst)--; \
246         }
247 #define MROP_MASK(src,dst,mask) (((src) & (mask)) | (dst))
248 #define MROP_MASK24(src,dst,mask,index) {\
249         register int idx = ((index) & 3)<< 1; \
250         *(dst) |= ((((src)&(mask))<<cfb24Shift[idx])&cfbmask[idx]); \
251         idx++; \
252         (dst)++; \
253         *(dst) |= ((((src)&(mask))>>cfb24Shift[idx])&cfbmask[idx]); \
254         (dst)--; \
255         }
256 #define MROP_NAME(prefix)       MROP_NAME_CAT(prefix,Or)
257 #endif
258
259 #if (MROP) == (Mcopy|Mxor|MandReverse|Mor)
260 #define MROP_DECLARE()  unsigned long _ca1, _cx1;
261 #define MROP_DECLARE_REG()      register MROP_DECLARE()
262 #define MROP_INITIALIZE(alu,pm) { \
263     mergeRopPtr  _bits; \
264     _bits = &mergeRopBits[alu]; \
265     _ca1 = _bits->ca1; \
266     _cx1 = _bits->cx1; \
267 }
268 #define MROP_SOLID(src,dst) \
269     ((dst) & ((src) & _ca1 ^ _cx1) ^ (src))
270 #define MROP_MASK(src,dst,mask) \
271     ((dst) & (((src) & _ca1 ^ _cx1) | ~(mask)) ^ ((src) & (mask)))
272 #define MROP_NAME(prefix)       MROP_NAME_CAT(prefix,CopyXorAndReverseOr)
273 #define MROP_PREBUILD(src)      PrebuildMergeRop(src)
274 #define MROP_PREBUILT_DECLARE() DeclarePrebuiltMergeRop()
275 #define MROP_PREBUILT_SOLID(src,dst)    DoPrebuiltMergeRop(dst)
276 #define MROP_PREBUILT_SOLID24(src,dst,index)    DoPrebuiltMergeRop24(dst,index)
277 #define MROP_PREBUILT_MASK(src,dst,mask)    DoMaskPrebuiltMergeRop(dst,mask)
278 #define MROP_PREBUILT_MASK24(src,dst,mask,index)    DoMaskPrebuiltMergeRop24(dst,mask,index)
279 #endif
280
281 #if (MROP) == 0
282 #define MROP_DECLARE()  DeclareMergeRop()
283 #define MROP_DECLARE_REG()      register DeclareMergeRop()
284 #define MROP_INITIALIZE(alu,pm) InitializeMergeRop(alu,pm)
285 #define MROP_SOLID(src,dst)     DoMergeRop(src,dst)
286 #define MROP_SOLID24(src,dst,index)     DoMergeRop24(src,dst,index)
287 #define MROP_MASK(src,dst,mask) DoMaskMergeRop(src, dst, mask)
288 #define MROP_MASK24(src,dst,mask,index) DoMaskMergeRop24(src, dst, mask,index)
289 #define MROP_NAME(prefix)       MROP_NAME_CAT(prefix,General)
290 #define MROP_PREBUILD(src)      PrebuildMergeRop(src)
291 #define MROP_PREBUILT_DECLARE() DeclarePrebuiltMergeRop()
292 #define MROP_PREBUILT_SOLID(src,dst)    DoPrebuiltMergeRop(dst)
293 #define MROP_PREBUILT_SOLID24(src,dst,index)    DoPrebuiltMergeRop24(dst,index)
294 #define MROP_PREBUILT_MASK(src,dst,mask)    DoMaskPrebuiltMergeRop(dst,mask)
295 #define MROP_PREBUILT_MASK24(src,dst,mask,index) \
296         DoMaskPrebuiltMergeRop24(dst,mask,index)
297 #endif
298
299 #ifndef MROP_PREBUILD
300 #define MROP_PREBUILD(src)
301 #define MROP_PREBUILT_DECLARE()
302 #define MROP_PREBUILT_SOLID(src,dst)    MROP_SOLID(src,dst)
303 #define MROP_PREBUILT_SOLID24(src,dst,index)    MROP_SOLID24(src,dst,index)
304 #define MROP_PREBUILT_MASK(src,dst,mask)    MROP_MASK(src,dst,mask)
305 #define MROP_PREBUILT_MASK24(src,dst,mask,index) MROP_MASK24(src,dst,mask,index)
306 #endif
307
308 #if (defined(__STDC__) && !defined(UNIXCPP)) || defined(ANSICPP)
309 #define MROP_NAME_CAT(prefix,suffix)    prefix##suffix
310 #else
311 #define MROP_NAME_CAT(prefix,suffix)    prefix/**/suffix
312 #endif
313
314 #endif