Release 20000326.
[wine/gsoc-2012-control.git] / graphics / x11drv / bitblt.c
bloba27ff0d56d76e8a2b667aa82927091685c768a7f
1 /*
2 * GDI bit-blit operations
4 * Copyright 1993, 1994 Alexandre Julliard
5 */
7 #include "config.h"
9 #ifndef X_DISPLAY_MISSING
11 #include <X11/Intrinsic.h>
12 #include "ts_xlib.h"
14 #include <assert.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include "bitmap.h"
18 #include "callback.h"
19 #include "color.h"
20 #include "dc.h"
21 #include "metafile.h"
22 #include "options.h"
23 #include "x11drv.h"
24 #include "debugtools.h"
26 DEFAULT_DEBUG_CHANNEL(bitblt)
29 #define DST 0 /* Destination drawable */
30 #define SRC 1 /* Source drawable */
31 #define TMP 2 /* Temporary drawable */
32 #define PAT 3 /* Pattern (brush) in destination DC */
34 #define OP(src,dst,rop) (OP_ARGS(src,dst) << 4 | (rop))
35 #define OP_ARGS(src,dst) (((src) << 2) | (dst))
37 #define OP_SRC(opcode) ((opcode) >> 6)
38 #define OP_DST(opcode) (((opcode) >> 4) & 3)
39 #define OP_SRCDST(opcode) ((opcode) >> 4)
40 #define OP_ROP(opcode) ((opcode) & 0x0f)
42 #define MAX_OP_LEN 6 /* Longest opcode + 1 for the terminating 0 */
44 #define SWAP_INT32(i1,i2) \
45 do { INT __t = *(i1); *(i1) = *(i2); *(i2) = __t; } while(0)
47 static const unsigned char BITBLT_Opcodes[256][MAX_OP_LEN] =
49 { OP(PAT,DST,GXclear) }, /* 0x00 0 */
50 { OP(PAT,SRC,GXor), OP(SRC,DST,GXnor) }, /* 0x01 ~(D|(P|S)) */
51 { OP(PAT,SRC,GXnor), OP(SRC,DST,GXand) }, /* 0x02 D&~(P|S) */
52 { OP(PAT,SRC,GXnor) }, /* 0x03 ~(P|S) */
53 { OP(PAT,DST,GXnor), OP(SRC,DST,GXand) }, /* 0x04 S&~(D|P) */
54 { OP(PAT,DST,GXnor) }, /* 0x05 ~(D|P) */
55 { OP(SRC,DST,GXequiv), OP(PAT,DST,GXnor), }, /* 0x06 ~(P|~(D^S)) */
56 { OP(SRC,DST,GXand), OP(PAT,DST,GXnor) }, /* 0x07 ~(P|(D&S)) */
57 { OP(PAT,DST,GXandInverted), OP(SRC,DST,GXand) },/* 0x08 S&D&~P */
58 { OP(SRC,DST,GXxor), OP(PAT,DST,GXnor) }, /* 0x09 ~(P|(D^S)) */
59 { OP(PAT,DST,GXandInverted) }, /* 0x0a D&~P */
60 { OP(SRC,DST,GXandReverse), OP(PAT,DST,GXnor) }, /* 0x0b ~(P|(S&~D)) */
61 { OP(PAT,SRC,GXandInverted) }, /* 0x0c S&~P */
62 { OP(SRC,DST,GXandInverted), OP(PAT,DST,GXnor) },/* 0x0d ~(P|(D&~S)) */
63 { OP(SRC,DST,GXnor), OP(PAT,DST,GXnor) }, /* 0x0e ~(P|~(D|S)) */
64 { OP(PAT,DST,GXcopyInverted) }, /* 0x0f ~P */
65 { OP(SRC,DST,GXnor), OP(PAT,DST,GXand) }, /* 0x10 P&~(S|D) */
66 { OP(SRC,DST,GXnor) }, /* 0x11 ~(D|S) */
67 { OP(PAT,DST,GXequiv), OP(SRC,DST,GXnor) }, /* 0x12 ~(S|~(D^P)) */
68 { OP(PAT,DST,GXand), OP(SRC,DST,GXnor) }, /* 0x13 ~(S|(D&P)) */
69 { OP(PAT,SRC,GXequiv), OP(SRC,DST,GXnor) }, /* 0x14 ~(D|~(P^S)) */
70 { OP(PAT,SRC,GXand), OP(SRC,DST,GXnor) }, /* 0x15 ~(D|(P&S)) */
71 { OP(SRC,TMP,GXcopy), OP(PAT,TMP,GXnand),
72 OP(TMP,DST,GXand), OP(SRC,DST,GXxor),
73 OP(PAT,DST,GXxor) }, /* 0x16 P^S^(D&~(P&S) */
74 { OP(SRC,TMP,GXcopy), OP(SRC,DST,GXxor),
75 OP(PAT,SRC,GXxor), OP(SRC,DST,GXand),
76 OP(TMP,DST,GXequiv) }, /* 0x17 ~S^((S^P)&(S^D))*/
77 { OP(PAT,SRC,GXxor), OP(PAT,DST,GXxor),
78 OP(SRC,DST,GXand) }, /* 0x18 (S^P)&(D^P) */
79 { OP(SRC,TMP,GXcopy), OP(PAT,TMP,GXnand),
80 OP(TMP,DST,GXand), OP(SRC,DST,GXequiv) }, /* 0x19 ~S^(D&~(P&S)) */
81 { OP(PAT,SRC,GXand), OP(SRC,DST,GXor),
82 OP(PAT,DST,GXxor) }, /* 0x1a P^(D|(S&P)) */
83 { OP(SRC,TMP,GXcopy), OP(PAT,TMP,GXxor),
84 OP(TMP,DST,GXand), OP(SRC,DST,GXequiv) }, /* 0x1b ~S^(D&(P^S)) */
85 { OP(PAT,DST,GXand), OP(SRC,DST,GXor),
86 OP(PAT,DST,GXxor) }, /* 0x1c P^(S|(D&P)) */
87 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXxor),
88 OP(SRC,DST,GXand), OP(TMP,DST,GXequiv) }, /* 0x1d ~D^(S&(D^P)) */
89 { OP(SRC,DST,GXor), OP(PAT,DST,GXxor) }, /* 0x1e P^(D|S) */
90 { OP(SRC,DST,GXor), OP(PAT,DST,GXnand) }, /* 0x1f ~(P&(D|S)) */
91 { OP(PAT,SRC,GXandReverse), OP(SRC,DST,GXand) }, /* 0x20 D&(P&~S) */
92 { OP(PAT,DST,GXxor), OP(SRC,DST,GXnor) }, /* 0x21 ~(S|(D^P)) */
93 { OP(SRC,DST,GXandInverted) }, /* 0x22 ~S&D */
94 { OP(PAT,DST,GXandReverse), OP(SRC,DST,GXnor) }, /* 0x23 ~(S|(P&~D)) */
95 { OP(SRC,DST,GXxor), OP(PAT,SRC,GXxor),
96 OP(SRC,DST,GXand) }, /* 0x24 (S^P)&(S^D) */
97 { OP(PAT,SRC,GXnand), OP(SRC,DST,GXand),
98 OP(PAT,DST,GXequiv) }, /* 0x25 ~P^(D&~(S&P)) */
99 { OP(SRC,TMP,GXcopy), OP(PAT,TMP,GXand),
100 OP(TMP,DST,GXor), OP(SRC,DST,GXxor) }, /* 0x26 S^(D|(S&P)) */
101 { OP(SRC,TMP,GXcopy), OP(PAT,TMP,GXequiv),
102 OP(TMP,DST,GXor), OP(SRC,DST,GXxor) }, /* 0x27 S^(D|~(P^S)) */
103 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXand) }, /* 0x28 D&(P^S) */
104 { OP(SRC,TMP,GXcopy), OP(PAT,TMP,GXand),
105 OP(TMP,DST,GXor), OP(SRC,DST,GXxor),
106 OP(PAT,DST,GXequiv) }, /* 0x29 ~P^S^(D|(P&S)) */
107 { OP(PAT,SRC,GXnand), OP(SRC,DST,GXand) }, /* 0x2a D&~(P&S) */
108 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXxor),
109 OP(PAT,DST,GXxor), OP(SRC,DST,GXand),
110 OP(TMP,DST,GXequiv) }, /* 0x2b ~S^((P^S)&(P^D))*/
111 { OP(SRC,DST,GXor), OP(PAT,DST,GXand),
112 OP(SRC,DST,GXxor) }, /* 0x2c S^(P&(S|D)) */
113 { OP(SRC,DST,GXorReverse), OP(PAT,DST,GXxor) }, /* 0x2d P^(S|~D) */
114 { OP(PAT,DST,GXxor), OP(SRC,DST,GXor),
115 OP(PAT,DST,GXxor) }, /* 0x2e P^(S|(D^P)) */
116 { OP(SRC,DST,GXorReverse), OP(PAT,DST,GXnand) }, /* 0x2f ~(P&(S|~D)) */
117 { OP(PAT,SRC,GXandReverse) }, /* 0x30 P&~S */
118 { OP(PAT,DST,GXandInverted), OP(SRC,DST,GXnor) },/* 0x31 ~(S|(D&~P)) */
119 { OP(SRC,DST,GXor), OP(PAT,DST,GXor),
120 OP(SRC,DST,GXxor) }, /* 0x32 S^(D|P|S) */
121 { OP(SRC,DST,GXcopyInverted) }, /* 0x33 ~S */
122 { OP(SRC,DST,GXand), OP(PAT,DST,GXor),
123 OP(SRC,DST,GXxor) }, /* 0x34 S^(P|(D&S)) */
124 { OP(SRC,DST,GXequiv), OP(PAT,DST,GXor),
125 OP(SRC,DST,GXxor) }, /* 0x35 S^(P|~(D^S)) */
126 { OP(PAT,DST,GXor), OP(SRC,DST,GXxor) }, /* 0x36 S^(D|P) */
127 { OP(PAT,DST,GXor), OP(SRC,DST,GXnand) }, /* 0x37 ~(S&(D|P)) */
128 { OP(PAT,DST,GXor), OP(SRC,DST,GXand),
129 OP(PAT,DST,GXxor) }, /* 0x38 P^(S&(D|P)) */
130 { OP(PAT,DST,GXorReverse), OP(SRC,DST,GXxor) }, /* 0x39 S^(P|~D) */
131 { OP(SRC,DST,GXxor), OP(PAT,DST,GXor),
132 OP(SRC,DST,GXxor) }, /* 0x3a S^(P|(D^S)) */
133 { OP(PAT,DST,GXorReverse), OP(SRC,DST,GXnand) }, /* 0x3b ~(S&(P|~D)) */
134 { OP(PAT,SRC,GXxor) }, /* 0x3c P^S */
135 { OP(SRC,DST,GXnor), OP(PAT,DST,GXor),
136 OP(SRC,DST,GXxor) }, /* 0x3d S^(P|~(D|S)) */
137 { OP(SRC,DST,GXandInverted), OP(PAT,DST,GXor),
138 OP(SRC,DST,GXxor) }, /* 0x3e S^(P|(D&~S)) */
139 { OP(PAT,SRC,GXnand) }, /* 0x3f ~(P&S) */
140 { OP(SRC,DST,GXandReverse), OP(PAT,DST,GXand) }, /* 0x40 P&S&~D */
141 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXnor) }, /* 0x41 ~(D|(P^S)) */
142 { OP(DST,SRC,GXxor), OP(PAT,DST,GXxor),
143 OP(SRC,DST,GXand) }, /* 0x42 (S^D)&(P^D) */
144 { OP(SRC,DST,GXnand), OP(PAT,DST,GXand),
145 OP(SRC,DST,GXequiv) }, /* 0x43 ~S^(P&~(D&S)) */
146 { OP(SRC,DST,GXandReverse) }, /* 0x44 S&~D */
147 { OP(PAT,SRC,GXandReverse), OP(SRC,DST,GXnor) }, /* 0x45 ~(D|(P&~S)) */
148 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXand),
149 OP(SRC,DST,GXor), OP(TMP,DST,GXxor) }, /* 0x46 D^(S|(P&D)) */
150 { OP(PAT,DST,GXxor), OP(SRC,DST,GXand),
151 OP(PAT,DST,GXequiv) }, /* 0x47 ~P^(S&(D^P)) */
152 { OP(PAT,DST,GXxor), OP(SRC,DST,GXand) }, /* 0x48 S&(P^D) */
153 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXand),
154 OP(SRC,DST,GXor), OP(TMP,DST,GXxor),
155 OP(PAT,DST,GXequiv) }, /* 0x49 ~P^D^(S|(P&D)) */
156 { OP(DST,SRC,GXor), OP(PAT,SRC,GXand),
157 OP(SRC,DST,GXxor) }, /* 0x4a D^(P&(S|D)) */
158 { OP(SRC,DST,GXorInverted), OP(PAT,DST,GXxor) }, /* 0x4b P^(D|~S) */
159 { OP(PAT,DST,GXnand), OP(SRC,DST,GXand) }, /* 0x4c S&~(D&P) */
160 { OP(SRC,TMP,GXcopy), OP(SRC,DST,GXxor),
161 OP(PAT,SRC,GXxor), OP(SRC,DST,GXor),
162 OP(TMP,DST,GXequiv) }, /* 0x4d ~S^((S^P)|(S^D))*/
163 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXor),
164 OP(PAT,DST,GXxor) }, /* 0x4e P^(D|(S^P)) */
165 { OP(SRC,DST,GXorInverted), OP(PAT,DST,GXnand) },/* 0x4f ~(P&(D|~S)) */
166 { OP(PAT,DST,GXandReverse) }, /* 0x50 P&~D */
167 { OP(PAT,SRC,GXandInverted), OP(SRC,DST,GXnor) },/* 0x51 ~(D|(S&~P)) */
168 { OP(DST,SRC,GXand), OP(PAT,SRC,GXor),
169 OP(SRC,DST,GXxor) }, /* 0x52 D^(P|(S&D)) */
170 { OP(SRC,DST,GXxor), OP(PAT,DST,GXand),
171 OP(SRC,DST,GXequiv) }, /* 0x53 ~S^(P&(D^S)) */
172 { OP(PAT,SRC,GXnor), OP(SRC,DST,GXnor) }, /* 0x54 ~(D|~(P|S)) */
173 { OP(PAT,DST,GXinvert) }, /* 0x55 ~D */
174 { OP(PAT,SRC,GXor), OP(SRC,DST,GXxor) }, /* 0x56 D^(P|S) */
175 { OP(PAT,SRC,GXor), OP(SRC,DST,GXnand) }, /* 0x57 ~(D&(P|S)) */
176 { OP(PAT,SRC,GXor), OP(SRC,DST,GXand),
177 OP(PAT,DST,GXxor) }, /* 0x58 P^(D&(P|S)) */
178 { OP(PAT,SRC,GXorReverse), OP(SRC,DST,GXxor) }, /* 0x59 D^(P|~S) */
179 { OP(PAT,DST,GXxor) }, /* 0x5a D^P */
180 { OP(DST,SRC,GXnor), OP(PAT,SRC,GXor),
181 OP(SRC,DST,GXxor) }, /* 0x5b D^(P|~(S|D)) */
182 { OP(DST,SRC,GXxor), OP(PAT,SRC,GXor),
183 OP(SRC,DST,GXxor) }, /* 0x5c D^(P|(S^D)) */
184 { OP(PAT,SRC,GXorReverse), OP(SRC,DST,GXnand) }, /* 0x5d ~(D&(P|~S)) */
185 { OP(DST,SRC,GXandInverted), OP(PAT,SRC,GXor),
186 OP(SRC,DST,GXxor) }, /* 0x5e D^(P|(S&~D)) */
187 { OP(PAT,DST,GXnand) }, /* 0x5f ~(D&P) */
188 { OP(SRC,DST,GXxor), OP(PAT,DST,GXand) }, /* 0x60 P&(D^S) */
189 { OP(DST,TMP,GXcopy), OP(SRC,DST,GXand),
190 OP(PAT,DST,GXor), OP(SRC,DST,GXxor),
191 OP(TMP,DST,GXequiv) }, /* 0x61 ~D^S^(P|(D&S)) */
192 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXor),
193 OP(SRC,DST,GXand), OP(TMP,DST,GXxor) }, /* 0x62 D^(S&(P|D)) */
194 { OP(PAT,DST,GXorInverted), OP(SRC,DST,GXxor) }, /* 0x63 S^(D|~P) */
195 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXor),
196 OP(SRC,DST,GXand), OP(TMP,DST,GXxor) }, /* 0x64 S^(D&(P|S)) */
197 { OP(PAT,SRC,GXorInverted), OP(SRC,DST,GXxor) }, /* 0x65 D^(S|~P) */
198 { OP(SRC,DST,GXxor) }, /* 0x66 S^D */
199 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXnor),
200 OP(SRC,DST,GXor), OP(TMP,DST,GXxor) }, /* 0x67 S^(D|~(S|P) */
201 { OP(DST,TMP,GXcopy), OP(SRC,DST,GXnor),
202 OP(PAT,DST,GXor), OP(SRC,DST,GXxor),
203 OP(TMP,DST,GXequiv) }, /* 0x68 ~D^S^(P|~(D|S))*/
204 { OP(SRC,DST,GXxor), OP(PAT,DST,GXequiv) }, /* 0x69 ~P^(D^S) */
205 { OP(PAT,SRC,GXand), OP(SRC,DST,GXxor) }, /* 0x6a D^(P&S) */
206 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXor),
207 OP(SRC,DST,GXand), OP(TMP,DST,GXxor),
208 OP(PAT,DST,GXequiv) }, /* 0x6b ~P^S^(D&(P|S)) */
209 { OP(PAT,DST,GXand), OP(SRC,DST,GXxor) }, /* 0x6c S^(D&P) */
210 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXor),
211 OP(SRC,DST,GXand), OP(TMP,DST,GXxor),
212 OP(PAT,DST,GXequiv) }, /* 0x6d ~P^D^(S&(P|D)) */
213 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXorReverse),
214 OP(SRC,DST,GXand), OP(TMP,DST,GXxor) }, /* 0x6e S^(D&(P|~S)) */
215 { OP(SRC,DST,GXequiv), OP(PAT,DST,GXnand) }, /* 0x6f ~(P&~(S^D)) */
216 { OP(SRC,DST,GXnand), OP(PAT,DST,GXand) }, /* 0x70 P&~(D&S) */
217 { OP(SRC,TMP,GXcopy), OP(DST,SRC,GXxor),
218 OP(PAT,DST,GXxor), OP(SRC,DST,GXand),
219 OP(TMP,DST,GXequiv) }, /* 0x71 ~S^((S^D)&(P^D))*/
220 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXxor),
221 OP(SRC,DST,GXor), OP(TMP,DST,GXxor) }, /* 0x72 S^(D|(P^S)) */
222 { OP(PAT,DST,GXorInverted), OP(SRC,DST,GXnand) },/* 0x73 ~(S&(D|~P)) */
223 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXxor),
224 OP(SRC,DST,GXor), OP(TMP,DST,GXxor) }, /* 0x74 D^(S|(P^D)) */
225 { OP(PAT,SRC,GXorInverted), OP(SRC,DST,GXnand) },/* 0x75 ~(D&(S|~P)) */
226 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXandReverse),
227 OP(SRC,DST,GXor), OP(TMP,DST,GXxor) }, /* 0x76 S^(D|(P&~S)) */
228 { OP(SRC,DST,GXnand) }, /* 0x77 ~(S&D) */
229 { OP(SRC,DST,GXand), OP(PAT,DST,GXxor) }, /* 0x78 P^(D&S) */
230 { OP(DST,TMP,GXcopy), OP(SRC,DST,GXor),
231 OP(PAT,DST,GXand), OP(SRC,DST,GXxor),
232 OP(TMP,DST,GXequiv) }, /* 0x79 ~D^S^(P&(D|S)) */
233 { OP(DST,SRC,GXorInverted), OP(PAT,SRC,GXand),
234 OP(SRC,DST,GXxor) }, /* 0x7a D^(P&(S|~D)) */
235 { OP(PAT,DST,GXequiv), OP(SRC,DST,GXnand) }, /* 0x7b ~(S&~(D^P)) */
236 { OP(SRC,DST,GXorInverted), OP(PAT,DST,GXand),
237 OP(SRC,DST,GXxor) }, /* 0x7c S^(P&(D|~S)) */
238 { OP(PAT,SRC,GXequiv), OP(SRC,DST,GXnand) }, /* 0x7d ~(D&~(P^S)) */
239 { OP(SRC,DST,GXxor), OP(PAT,SRC,GXxor),
240 OP(SRC,DST,GXor) }, /* 0x7e (S^P)|(S^D) */
241 { OP(PAT,SRC,GXand), OP(SRC,DST,GXnand) }, /* 0x7f ~(D&P&S) */
242 { OP(PAT,SRC,GXand), OP(SRC,DST,GXand) }, /* 0x80 D&P&S */
243 { OP(SRC,DST,GXxor), OP(PAT,SRC,GXxor),
244 OP(SRC,DST,GXnor) }, /* 0x81 ~((S^P)|(S^D)) */
245 { OP(PAT,SRC,GXequiv), OP(SRC,DST,GXand) }, /* 0x82 D&~(P^S) */
246 { OP(SRC,DST,GXorInverted), OP(PAT,DST,GXand),
247 OP(SRC,DST,GXequiv) }, /* 0x83 ~S^(P&(D|~S)) */
248 { OP(PAT,DST,GXequiv), OP(SRC,DST,GXand) }, /* 0x84 S&~(D^P) */
249 { OP(PAT,SRC,GXorInverted), OP(SRC,DST,GXand),
250 OP(PAT,DST,GXequiv) }, /* 0x85 ~P^(D&(S|~P)) */
251 { OP(DST,TMP,GXcopy), OP(SRC,DST,GXor),
252 OP(PAT,DST,GXand), OP(SRC,DST,GXxor),
253 OP(TMP,DST,GXxor) }, /* 0x86 D^S^(P&(D|S)) */
254 { OP(SRC,DST,GXand), OP(PAT,DST,GXequiv) }, /* 0x87 ~P^(D&S) */
255 { OP(SRC,DST,GXand) }, /* 0x88 S&D */
256 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXandReverse),
257 OP(SRC,DST,GXor), OP(TMP,DST,GXequiv) }, /* 0x89 ~S^(D|(P&~S)) */
258 { OP(PAT,SRC,GXorInverted), OP(SRC,DST,GXand) }, /* 0x8a D&(S|~P) */
259 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXxor),
260 OP(SRC,DST,GXor), OP(TMP,DST,GXequiv) }, /* 0x8b ~D^(S|(P^D)) */
261 { OP(PAT,DST,GXorInverted), OP(SRC,DST,GXand) }, /* 0x8c S&(D|~P) */
262 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXxor),
263 OP(SRC,DST,GXor), OP(TMP,DST,GXequiv) }, /* 0x8d ~S^(D|(P^S)) */
264 { OP(SRC,TMP,GXcopy), OP(DST,SRC,GXxor),
265 OP(PAT,DST,GXxor), OP(SRC,DST,GXand),
266 OP(TMP,DST,GXxor) }, /* 0x8e S^((S^D)&(P^D))*/
267 { OP(SRC,DST,GXnand), OP(PAT,DST,GXnand) }, /* 0x8f ~(P&~(D&S)) */
268 { OP(SRC,DST,GXequiv), OP(PAT,DST,GXand) }, /* 0x90 P&~(D^S) */
269 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXorReverse),
270 OP(SRC,DST,GXand), OP(TMP,DST,GXequiv) }, /* 0x91 ~S^(D&(P|~S)) */
271 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXor),
272 OP(SRC,DST,GXand), OP(PAT,DST,GXxor),
273 OP(TMP,DST,GXxor) }, /* 0x92 D^P^(S&(D|P)) */
274 { OP(PAT,DST,GXand), OP(SRC,DST,GXequiv) }, /* 0x93 ~S^(P&D) */
275 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXor),
276 OP(SRC,DST,GXand), OP(PAT,DST,GXxor),
277 OP(TMP,DST,GXxor) }, /* 0x94 S^P^(D&(P|S)) */
278 { OP(PAT,SRC,GXand), OP(SRC,DST,GXequiv) }, /* 0x95 ~D^(P&S) */
279 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXxor) }, /* 0x96 D^P^S */
280 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXnor),
281 OP(SRC,DST,GXor), OP(PAT,DST,GXxor),
282 OP(TMP,DST,GXxor) }, /* 0x97 S^P^(D|~(P|S)) */
283 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXnor),
284 OP(SRC,DST,GXor), OP(TMP,DST,GXequiv) }, /* 0x98 ~S^(D|~(P|S)) */
285 { OP(SRC,DST,GXequiv) }, /* 0x99 ~S^D */
286 { OP(PAT,SRC,GXandReverse), OP(SRC,DST,GXxor) }, /* 0x9a D^(P&~S) */
287 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXor),
288 OP(SRC,DST,GXand), OP(TMP,DST,GXequiv) }, /* 0x9b ~S^(D&(P|S)) */
289 { OP(PAT,DST,GXandReverse), OP(SRC,DST,GXxor) }, /* 0x9c S^(P&~D) */
290 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXor),
291 OP(SRC,DST,GXand), OP(TMP,DST,GXequiv) }, /* 0x9d ~D^(S&(P|D)) */
292 { OP(DST,TMP,GXcopy), OP(SRC,DST,GXand),
293 OP(PAT,DST,GXor), OP(SRC,DST,GXxor),
294 OP(TMP,DST,GXxor) }, /* 0x9e D^S^(P|(D&S)) */
295 { OP(SRC,DST,GXxor), OP(PAT,DST,GXnand) }, /* 0x9f ~(P&(D^S)) */
296 { OP(PAT,DST,GXand) }, /* 0xa0 D&P */
297 { OP(PAT,SRC,GXandInverted), OP(SRC,DST,GXor),
298 OP(PAT,DST,GXequiv) }, /* 0xa1 ~P^(D|(S&~P)) */
299 { OP(PAT,SRC,GXorReverse), OP(SRC,DST,GXand) }, /* 0xa2 D&(P|~S) */
300 { OP(DST,SRC,GXxor), OP(PAT,SRC,GXor),
301 OP(SRC,DST,GXequiv) }, /* 0xa3 ~D^(P|(S^D)) */
302 { OP(PAT,SRC,GXnor), OP(SRC,DST,GXor),
303 OP(PAT,DST,GXequiv) }, /* 0xa4 ~P^(D|~(S|P)) */
304 { OP(PAT,DST,GXequiv) }, /* 0xa5 ~P^D */
305 { OP(PAT,SRC,GXandInverted), OP(SRC,DST,GXxor) },/* 0xa6 D^(S&~P) */
306 { OP(PAT,SRC,GXor), OP(SRC,DST,GXand),
307 OP(PAT,DST,GXequiv) }, /* 0xa7 ~P^(D&(S|P)) */
308 { OP(PAT,SRC,GXor), OP(SRC,DST,GXand) }, /* 0xa8 D&(P|S) */
309 { OP(PAT,SRC,GXor), OP(SRC,DST,GXequiv) }, /* 0xa9 ~D^(P|S) */
310 { OP(SRC,DST,GXnoop) }, /* 0xaa D */
311 { OP(PAT,SRC,GXnor), OP(SRC,DST,GXor) }, /* 0xab D|~(P|S) */
312 { OP(SRC,DST,GXxor), OP(PAT,DST,GXand),
313 OP(SRC,DST,GXxor) }, /* 0xac S^(P&(D^S)) */
314 { OP(DST,SRC,GXand), OP(PAT,SRC,GXor),
315 OP(SRC,DST,GXequiv) }, /* 0xad ~D^(P|(S&D)) */
316 { OP(PAT,SRC,GXandInverted), OP(SRC,DST,GXor) }, /* 0xae D|(S&~P) */
317 { OP(PAT,DST,GXorInverted) }, /* 0xaf D|~P */
318 { OP(SRC,DST,GXorInverted), OP(PAT,DST,GXand) }, /* 0xb0 P&(D|~S) */
319 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXor),
320 OP(PAT,DST,GXequiv) }, /* 0xb1 ~P^(D|(S^P)) */
321 { OP(SRC,TMP,GXcopy), OP(SRC,DST,GXxor),
322 OP(PAT,SRC,GXxor), OP(SRC,DST,GXor),
323 OP(TMP,DST,GXxor) }, /* 0xb2 S^((S^P)|(S^D))*/
324 { OP(PAT,DST,GXnand), OP(SRC,DST,GXnand) }, /* 0xb3 ~(S&~(D&P)) */
325 { OP(SRC,DST,GXandReverse), OP(PAT,DST,GXxor) }, /* 0xb4 P^(S&~D) */
326 { OP(DST,SRC,GXor), OP(PAT,SRC,GXand),
327 OP(SRC,DST,GXequiv) }, /* 0xb5 ~D^(P&(S|D)) */
328 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXand),
329 OP(SRC,DST,GXor), OP(PAT,DST,GXxor),
330 OP(TMP,DST,GXxor) }, /* 0xb6 D^P^(S|(D&P)) */
331 { OP(PAT,DST,GXxor), OP(SRC,DST,GXnand) }, /* 0xb7 ~(S&(D^P)) */
332 { OP(PAT,DST,GXxor), OP(SRC,DST,GXand),
333 OP(PAT,DST,GXxor) }, /* 0xb8 P^(S&(D^P)) */
334 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXand),
335 OP(SRC,DST,GXor), OP(TMP,DST,GXequiv) }, /* 0xb9 ~D^(S|(P&D)) */
336 { OP(PAT,SRC,GXandReverse), OP(SRC,DST,GXor) }, /* 0xba D|(P&~S) */
337 { OP(SRC,DST,GXorInverted) }, /* 0xbb ~S|D */
338 { OP(SRC,DST,GXnand), OP(PAT,DST,GXand),
339 OP(SRC,DST,GXxor) }, /* 0xbc S^(P&~(D&S)) */
340 { OP(DST,SRC,GXxor), OP(PAT,DST,GXxor),
341 OP(SRC,DST,GXnand) }, /* 0xbd ~((S^D)&(P^D)) */
342 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXor) }, /* 0xbe D|(P^S) */
343 { OP(PAT,SRC,GXnand), OP(SRC,DST,GXor) }, /* 0xbf D|~(P&S) */
344 { OP(PAT,SRC,GXand) }, /* 0xc0 P&S */
345 { OP(SRC,DST,GXandInverted), OP(PAT,DST,GXor),
346 OP(SRC,DST,GXequiv) }, /* 0xc1 ~S^(P|(D&~S)) */
347 { OP(SRC,DST,GXnor), OP(PAT,DST,GXor),
348 OP(SRC,DST,GXequiv) }, /* 0xc2 ~S^(P|~(D|S)) */
349 { OP(PAT,SRC,GXequiv) }, /* 0xc3 ~P^S */
350 { OP(PAT,DST,GXorReverse), OP(SRC,DST,GXand) }, /* 0xc4 S&(P|~D) */
351 { OP(SRC,DST,GXxor), OP(PAT,DST,GXor),
352 OP(SRC,DST,GXequiv) }, /* 0xc5 ~S^(P|(D^S)) */
353 { OP(PAT,DST,GXandInverted), OP(SRC,DST,GXxor) },/* 0xc6 S^(D&~P) */
354 { OP(PAT,DST,GXor), OP(SRC,DST,GXand),
355 OP(PAT,DST,GXequiv) }, /* 0xc7 ~P^(S&(D|P)) */
356 { OP(PAT,DST,GXor), OP(SRC,DST,GXand) }, /* 0xc8 S&(D|P) */
357 { OP(PAT,DST,GXor), OP(SRC,DST,GXequiv) }, /* 0xc9 ~S^(P|D) */
358 { OP(DST,SRC,GXxor), OP(PAT,SRC,GXand),
359 OP(SRC,DST,GXxor) }, /* 0xca D^(P&(S^D)) */
360 { OP(SRC,DST,GXand), OP(PAT,DST,GXor),
361 OP(SRC,DST,GXequiv) }, /* 0xcb ~S^(P|(D&S)) */
362 { OP(SRC,DST,GXcopy) }, /* 0xcc S */
363 { OP(PAT,DST,GXnor), OP(SRC,DST,GXor) }, /* 0xcd S|~(D|P) */
364 { OP(PAT,DST,GXandInverted), OP(SRC,DST,GXor) }, /* 0xce S|(D&~P) */
365 { OP(PAT,SRC,GXorInverted) }, /* 0xcf S|~P */
366 { OP(SRC,DST,GXorReverse), OP(PAT,DST,GXand) }, /* 0xd0 P&(S|~D) */
367 { OP(PAT,DST,GXxor), OP(SRC,DST,GXor),
368 OP(PAT,DST,GXequiv) }, /* 0xd1 ~P^(S|(D^P)) */
369 { OP(SRC,DST,GXandInverted), OP(PAT,DST,GXxor) },/* 0xd2 P^(D&~S) */
370 { OP(SRC,DST,GXor), OP(PAT,DST,GXand),
371 OP(SRC,DST,GXequiv) }, /* 0xd3 ~S^(P&(D|S)) */
372 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXxor),
373 OP(PAT,DST,GXxor), OP(SRC,DST,GXand),
374 OP(TMP,DST,GXxor) }, /* 0xd4 S^((S^P)&(D^P))*/
375 { OP(PAT,SRC,GXnand), OP(SRC,DST,GXnand) }, /* 0xd5 ~(D&~(P&S)) */
376 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXand),
377 OP(SRC,DST,GXor), OP(PAT,DST,GXxor),
378 OP(TMP,DST,GXxor) }, /* 0xd6 S^P^(D|(P&S)) */
379 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXnand) }, /* 0xd7 ~(D&(P^S)) */
380 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXand),
381 OP(PAT,DST,GXxor) }, /* 0xd8 P^(D&(S^P)) */
382 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXand),
383 OP(SRC,DST,GXor), OP(TMP,DST,GXequiv) }, /* 0xd9 ~S^(D|(P&S)) */
384 { OP(DST,SRC,GXnand), OP(PAT,SRC,GXand),
385 OP(SRC,DST,GXxor) }, /* 0xda D^(P&~(S&D)) */
386 { OP(SRC,DST,GXxor), OP(PAT,SRC,GXxor),
387 OP(SRC,DST,GXnand) }, /* 0xdb ~((S^P)&(S^D)) */
388 { OP(PAT,DST,GXandReverse), OP(SRC,DST,GXor) }, /* 0xdc S|(P&~D) */
389 { OP(SRC,DST,GXorReverse) }, /* 0xdd S|~D */
390 { OP(PAT,DST,GXxor), OP(SRC,DST,GXor) }, /* 0xde S|(D^P) */
391 { OP(PAT,DST,GXnand), OP(SRC,DST,GXor) }, /* 0xdf S|~(D&P) */
392 { OP(SRC,DST,GXor), OP(PAT,DST,GXand) }, /* 0xe0 P&(D|S) */
393 { OP(SRC,DST,GXor), OP(PAT,DST,GXequiv) }, /* 0xe1 ~P^(D|S) */
394 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXxor),
395 OP(SRC,DST,GXand), OP(TMP,DST,GXxor) }, /* 0xe2 D^(S&(P^D)) */
396 { OP(PAT,DST,GXand), OP(SRC,DST,GXor),
397 OP(PAT,DST,GXequiv) }, /* 0xe3 ~P^(S|(D&P)) */
398 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXxor),
399 OP(SRC,DST,GXand), OP(TMP,DST,GXxor) }, /* 0xe4 S^(D&(P^S)) */
400 { OP(PAT,SRC,GXand), OP(SRC,DST,GXor),
401 OP(PAT,DST,GXequiv) }, /* 0xe5 ~P^(D|(S&P)) */
402 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXnand),
403 OP(SRC,DST,GXand), OP(TMP,DST,GXxor) }, /* 0xe6 S^(D&~(P&S)) */
404 { OP(PAT,SRC,GXxor), OP(PAT,DST,GXxor),
405 OP(SRC,DST,GXnand) }, /* 0xe7 ~((S^P)&(D^P)) */
406 { OP(SRC,TMP,GXcopy), OP(SRC,DST,GXxor),
407 OP(PAT,SRC,GXxor), OP(SRC,DST,GXand),
408 OP(TMP,DST,GXxor) }, /* 0xe8 S^((S^P)&(S^D))*/
409 { OP(DST,TMP,GXcopy), OP(SRC,DST,GXnand),
410 OP(PAT,DST,GXand), OP(SRC,DST,GXxor),
411 OP(TMP,DST,GXequiv) }, /* 0xe9 ~D^S^(P&~(S&D))*/
412 { OP(PAT,SRC,GXand), OP(SRC,DST,GXor) }, /* 0xea D|(P&S) */
413 { OP(PAT,SRC,GXequiv), OP(SRC,DST,GXor) }, /* 0xeb D|~(P^S) */
414 { OP(PAT,DST,GXand), OP(SRC,DST,GXor) }, /* 0xec S|(D&P) */
415 { OP(PAT,DST,GXequiv), OP(SRC,DST,GXor) }, /* 0xed S|~(D^P) */
416 { OP(SRC,DST,GXor) }, /* 0xee S|D */
417 { OP(PAT,DST,GXorInverted), OP(SRC,DST,GXor) }, /* 0xef S|D|~P */
418 { OP(PAT,DST,GXcopy) }, /* 0xf0 P */
419 { OP(SRC,DST,GXnor), OP(PAT,DST,GXor) }, /* 0xf1 P|~(D|S) */
420 { OP(SRC,DST,GXandInverted), OP(PAT,DST,GXor) }, /* 0xf2 P|(D&~S) */
421 { OP(PAT,SRC,GXorReverse) }, /* 0xf3 P|~S */
422 { OP(SRC,DST,GXandReverse), OP(PAT,DST,GXor) }, /* 0xf4 P|(S&~D) */
423 { OP(PAT,DST,GXorReverse) }, /* 0xf5 P|~D */
424 { OP(SRC,DST,GXxor), OP(PAT,DST,GXor) }, /* 0xf6 P|(D^S) */
425 { OP(SRC,DST,GXnand), OP(PAT,DST,GXor) }, /* 0xf7 P|~(S&D) */
426 { OP(SRC,DST,GXand), OP(PAT,DST,GXor) }, /* 0xf8 P|(D&S) */
427 { OP(SRC,DST,GXequiv), OP(PAT,DST,GXor) }, /* 0xf9 P|~(D^S) */
428 { OP(PAT,DST,GXor) }, /* 0xfa D|P */
429 { OP(PAT,SRC,GXorReverse), OP(SRC,DST,GXor) }, /* 0xfb D|P|~S */
430 { OP(PAT,SRC,GXor) }, /* 0xfc P|S */
431 { OP(SRC,DST,GXorReverse), OP(PAT,DST,GXor) }, /* 0xfd P|S|~D */
432 { OP(SRC,DST,GXor), OP(PAT,DST,GXor) }, /* 0xfe P|D|S */
433 { OP(PAT,DST,GXset) } /* 0xff 1 */
437 #ifdef BITBLT_TEST /* Opcodes test */
439 static int do_bitop( int s, int d, int rop )
441 int res;
442 switch(rop)
444 case GXclear: res = 0; break;
445 case GXand: res = s & d; break;
446 case GXandReverse: res = s & ~d; break;
447 case GXcopy: res = s; break;
448 case GXandInverted: res = ~s & d; break;
449 case GXnoop: res = d; break;
450 case GXxor: res = s ^ d; break;
451 case GXor: res = s | d; break;
452 case GXnor: res = ~(s | d); break;
453 case GXequiv: res = ~s ^ d; break;
454 case GXinvert: res = ~d; break;
455 case GXorReverse: res = s | ~d; break;
456 case GXcopyInverted: res = ~s; break;
457 case GXorInverted: res = ~s | d; break;
458 case GXnand: res = ~(s & d); break;
459 case GXset: res = 1; break;
461 return res & 1;
464 main()
466 int rop, i, res, src, dst, pat, tmp, dstUsed;
467 const BYTE *opcode;
469 for (rop = 0; rop < 256; rop++)
471 res = dstUsed = 0;
472 for (i = 0; i < 8; i++)
474 pat = (i >> 2) & 1;
475 src = (i >> 1) & 1;
476 dst = i & 1;
477 for (opcode = BITBLT_Opcodes[rop]; *opcode; opcode++)
479 switch(*opcode >> 4)
481 case OP_ARGS(DST,TMP):
482 tmp = do_bitop( dst, tmp, *opcode & 0xf );
483 break;
484 case OP_ARGS(DST,SRC):
485 src = do_bitop( dst, src, *opcode & 0xf );
486 break;
487 case OP_ARGS(SRC,TMP):
488 tmp = do_bitop( src, tmp, *opcode & 0xf );
489 break;
490 case OP_ARGS(SRC,DST):
491 dst = do_bitop( src, dst, *opcode & 0xf );
492 dstUsed = 1;
493 break;
494 case OP_ARGS(PAT,TMP):
495 tmp = do_bitop( pat, tmp, *opcode & 0xf );
496 break;
497 case OP_ARGS(PAT,DST):
498 dst = do_bitop( pat, dst, *opcode & 0xf );
499 dstUsed = 1;
500 break;
501 case OP_ARGS(PAT,SRC):
502 src = do_bitop( pat, src, *opcode & 0xf );
503 break;
504 case OP_ARGS(TMP,DST):
505 dst = do_bitop( tmp, dst, *opcode & 0xf );
506 dstUsed = 1;
507 break;
508 case OP_ARGS(TMP,SRC):
509 src = do_bitop( tmp, src, *opcode & 0xf );
510 break;
511 default:
512 printf( "Invalid opcode %x\n", *opcode );
515 if (!dstUsed) dst = src;
516 if (dst) res |= 1 << i;
518 if (res != rop) printf( "%02x: ERROR, res=%02x\n", rop, res );
522 #endif /* BITBLT_TEST */
525 /***********************************************************************
526 * perfect_graphics
528 * Favor correctness or speed?
530 static inline int perfect_graphics(void)
532 static int perfect = -1;
533 if (perfect == -1) perfect = PROFILE_GetWineIniBool( "x11drv", "PerfectGraphics", 0 );
534 return perfect;
537 /***********************************************************************
538 * BITBLT_StretchRow
540 * Stretch a row of pixels. Helper function for BITBLT_StretchImage.
542 static void BITBLT_StretchRow( int *rowSrc, int *rowDst,
543 INT startDst, INT widthDst,
544 INT xinc, INT xoff, WORD mode )
546 register INT xsrc = xinc * startDst + xoff;
547 rowDst += startDst;
548 switch(mode)
550 case STRETCH_ANDSCANS:
551 for(; widthDst > 0; widthDst--, xsrc += xinc)
552 *rowDst++ &= rowSrc[xsrc >> 16];
553 break;
554 case STRETCH_ORSCANS:
555 for(; widthDst > 0; widthDst--, xsrc += xinc)
556 *rowDst++ |= rowSrc[xsrc >> 16];
557 break;
558 case STRETCH_DELETESCANS:
559 for(; widthDst > 0; widthDst--, xsrc += xinc)
560 *rowDst++ = rowSrc[xsrc >> 16];
561 break;
566 /***********************************************************************
567 * BITBLT_ShrinkRow
569 * Shrink a row of pixels. Helper function for BITBLT_StretchImage.
571 static void BITBLT_ShrinkRow( int *rowSrc, int *rowDst,
572 INT startSrc, INT widthSrc,
573 INT xinc, INT xoff, WORD mode )
575 register INT xdst = xinc * startSrc + xoff;
576 rowSrc += startSrc;
577 switch(mode)
579 case STRETCH_ORSCANS:
580 for(; widthSrc > 0; widthSrc--, xdst += xinc)
581 rowDst[xdst >> 16] |= *rowSrc++;
582 break;
583 case STRETCH_ANDSCANS:
584 for(; widthSrc > 0; widthSrc--, xdst += xinc)
585 rowDst[xdst >> 16] &= *rowSrc++;
586 break;
587 case STRETCH_DELETESCANS:
588 for(; widthSrc > 0; widthSrc--, xdst += xinc)
589 rowDst[xdst >> 16] = *rowSrc++;
590 break;
595 /***********************************************************************
596 * BITBLT_GetRow
598 * Retrieve a row from an image. Helper function for BITBLT_StretchImage.
600 static void BITBLT_GetRow( XImage *image, int *pdata, INT row,
601 INT start, INT width, INT depthDst,
602 int fg, int bg, BOOL swap)
604 register INT i;
606 assert( (row >= 0) && (row < image->height) );
607 assert( (start >= 0) && (width <= image->width) );
609 pdata += swap ? start+width-1 : start;
610 if (image->depth == depthDst) /* color -> color */
612 if (X11DRV_PALETTE_XPixelToPalette && (depthDst != 1))
613 if (swap) for (i = 0; i < width; i++)
614 *pdata-- = X11DRV_PALETTE_XPixelToPalette[XGetPixel( image, i, row )];
615 else for (i = 0; i < width; i++)
616 *pdata++ = X11DRV_PALETTE_XPixelToPalette[XGetPixel( image, i, row )];
617 else
618 if (swap) for (i = 0; i < width; i++)
619 *pdata-- = XGetPixel( image, i, row );
620 else for (i = 0; i < width; i++)
621 *pdata++ = XGetPixel( image, i, row );
623 else
625 if (image->depth == 1) /* monochrome -> color */
627 if (X11DRV_PALETTE_XPixelToPalette)
629 fg = X11DRV_PALETTE_XPixelToPalette[fg];
630 bg = X11DRV_PALETTE_XPixelToPalette[bg];
632 if (swap) for (i = 0; i < width; i++)
633 *pdata-- = XGetPixel( image, i, row ) ? bg : fg;
634 else for (i = 0; i < width; i++)
635 *pdata++ = XGetPixel( image, i, row ) ? bg : fg;
637 else /* color -> monochrome */
639 if (swap) for (i = 0; i < width; i++)
640 *pdata-- = (XGetPixel( image, i, row ) == bg) ? 1 : 0;
641 else for (i = 0; i < width; i++)
642 *pdata++ = (XGetPixel( image, i, row ) == bg) ? 1 : 0;
648 /***********************************************************************
649 * BITBLT_StretchImage
651 * Stretch an X image.
652 * FIXME: does not work for full 32-bit coordinates.
654 static void BITBLT_StretchImage( XImage *srcImage, XImage *dstImage,
655 INT widthSrc, INT heightSrc,
656 INT widthDst, INT heightDst,
657 RECT *visRectSrc, RECT *visRectDst,
658 int foreground, int background, WORD mode )
660 int *rowSrc, *rowDst, *pixel;
661 char *pdata;
662 INT xinc, xoff, yinc, ysrc, ydst;
663 register INT x, y;
664 BOOL hstretch, vstretch, hswap, vswap;
666 hswap = ((int)widthSrc * widthDst) < 0;
667 vswap = ((int)heightSrc * heightDst) < 0;
668 widthSrc = abs(widthSrc);
669 heightSrc = abs(heightSrc);
670 widthDst = abs(widthDst);
671 heightDst = abs(heightDst);
673 if (!(rowSrc = (int *)HeapAlloc( GetProcessHeap(), 0,
674 (widthSrc+widthDst)*sizeof(int) ))) return;
675 rowDst = rowSrc + widthSrc;
677 /* When stretching, all modes are the same, and DELETESCANS is faster */
678 if ((widthSrc < widthDst) && (heightSrc < heightDst))
679 mode = STRETCH_DELETESCANS;
681 if (mode != STRETCH_DELETESCANS)
682 memset( rowDst, (mode == STRETCH_ANDSCANS) ? 0xff : 0x00,
683 widthDst*sizeof(int) );
685 hstretch = (widthSrc < widthDst);
686 vstretch = (heightSrc < heightDst);
688 if (hstretch)
690 xinc = ((int)widthSrc << 16) / widthDst;
691 xoff = ((widthSrc << 16) - (xinc * widthDst)) / 2;
693 else
695 xinc = ((int)widthDst << 16) / widthSrc;
696 xoff = ((widthDst << 16) - (xinc * widthSrc)) / 2;
699 if (vstretch)
701 yinc = ((int)heightSrc << 16) / heightDst;
702 ydst = visRectDst->top;
703 if (vswap)
705 ysrc = yinc * (heightDst - ydst - 1);
706 yinc = -yinc;
708 else
709 ysrc = yinc * ydst;
711 for ( ; (ydst < visRectDst->bottom); ysrc += yinc, ydst++)
713 if (((ysrc >> 16) < visRectSrc->top) ||
714 ((ysrc >> 16) >= visRectSrc->bottom)) continue;
716 /* Retrieve a source row */
717 BITBLT_GetRow( srcImage, rowSrc, (ysrc >> 16) - visRectSrc->top,
718 hswap ? widthSrc - visRectSrc->right
719 : visRectSrc->left,
720 visRectSrc->right - visRectSrc->left,
721 dstImage->depth, foreground, background, hswap );
723 /* Stretch or shrink it */
724 if (hstretch)
725 BITBLT_StretchRow( rowSrc, rowDst, visRectDst->left,
726 visRectDst->right - visRectDst->left,
727 xinc, xoff, mode );
728 else BITBLT_ShrinkRow( rowSrc, rowDst,
729 hswap ? widthSrc - visRectSrc->right
730 : visRectSrc->left,
731 visRectSrc->right - visRectSrc->left,
732 xinc, xoff, mode );
734 /* Store the destination row */
735 pixel = rowDst + visRectDst->right - 1;
736 y = ydst - visRectDst->top;
737 for (x = visRectDst->right-visRectDst->left-1; x >= 0; x--)
738 XPutPixel( dstImage, x, y, *pixel-- );
739 if (mode != STRETCH_DELETESCANS)
740 memset( rowDst, (mode == STRETCH_ANDSCANS) ? 0xff : 0x00,
741 widthDst*sizeof(int) );
743 /* Make copies of the destination row */
745 pdata = dstImage->data + dstImage->bytes_per_line * y;
746 while (((ysrc + yinc) >> 16 == ysrc >> 16) &&
747 (ydst < visRectDst->bottom-1))
749 memcpy( pdata + dstImage->bytes_per_line, pdata,
750 dstImage->bytes_per_line );
751 pdata += dstImage->bytes_per_line;
752 ysrc += yinc;
753 ydst++;
757 else /* Shrinking */
759 yinc = ((int)heightDst << 16) / heightSrc;
760 ysrc = visRectSrc->top;
761 ydst = ((heightDst << 16) - (yinc * heightSrc)) / 2;
762 if (vswap)
764 ydst += yinc * (heightSrc - ysrc - 1);
765 yinc = -yinc;
767 else
768 ydst += yinc * ysrc;
770 for( ; (ysrc < visRectSrc->bottom); ydst += yinc, ysrc++)
772 if (((ydst >> 16) < visRectDst->top) ||
773 ((ydst >> 16) >= visRectDst->bottom)) continue;
775 /* Retrieve a source row */
776 BITBLT_GetRow( srcImage, rowSrc, ysrc - visRectSrc->top,
777 hswap ? widthSrc - visRectSrc->right
778 : visRectSrc->left,
779 visRectSrc->right - visRectSrc->left,
780 dstImage->depth, foreground, background, hswap );
782 /* Stretch or shrink it */
783 if (hstretch)
784 BITBLT_StretchRow( rowSrc, rowDst, visRectDst->left,
785 visRectDst->right - visRectDst->left,
786 xinc, xoff, mode );
787 else BITBLT_ShrinkRow( rowSrc, rowDst,
788 hswap ? widthSrc - visRectSrc->right
789 : visRectSrc->left,
790 visRectSrc->right - visRectSrc->left,
791 xinc, xoff, mode );
793 /* Merge several source rows into the destination */
794 if (mode == STRETCH_DELETESCANS)
796 /* Simply skip the overlapping rows */
797 while (((ydst + yinc) >> 16 == ydst >> 16) &&
798 (ysrc < visRectSrc->bottom-1))
800 ydst += yinc;
801 ysrc++;
804 else if (((ydst + yinc) >> 16 == ydst >> 16) &&
805 (ysrc < visRectSrc->bottom-1))
806 continue; /* Restart loop for next overlapping row */
808 /* Store the destination row */
809 pixel = rowDst + visRectDst->right - 1;
810 y = (ydst >> 16) - visRectDst->top;
811 for (x = visRectDst->right-visRectDst->left-1; x >= 0; x--)
812 XPutPixel( dstImage, x, y, *pixel-- );
813 if (mode != STRETCH_DELETESCANS)
814 memset( rowDst, (mode == STRETCH_ANDSCANS) ? 0xff : 0x00,
815 widthDst*sizeof(int) );
818 HeapFree( GetProcessHeap(), 0, rowSrc );
822 /***********************************************************************
823 * BITBLT_GetSrcAreaStretch
825 * Retrieve an area from the source DC, stretching and mapping all the
826 * pixels to Windows colors.
828 static void BITBLT_GetSrcAreaStretch( DC *dcSrc, DC *dcDst,
829 Pixmap pixmap, GC gc,
830 INT xSrc, INT ySrc,
831 INT widthSrc, INT heightSrc,
832 INT xDst, INT yDst,
833 INT widthDst, INT heightDst,
834 RECT *visRectSrc, RECT *visRectDst )
836 XImage *imageSrc, *imageDst;
837 X11DRV_PDEVICE *physDevSrc = (X11DRV_PDEVICE *)dcSrc->physDev;
838 X11DRV_PDEVICE *physDevDst = (X11DRV_PDEVICE *)dcDst->physDev;
840 RECT rectSrc = *visRectSrc;
841 RECT rectDst = *visRectDst;
843 if (widthSrc < 0) xSrc += widthSrc;
844 if (widthDst < 0) xDst += widthDst;
845 if (heightSrc < 0) ySrc += heightSrc;
846 if (heightDst < 0) yDst += heightDst;
847 rectSrc.left -= xSrc;
848 rectSrc.right -= xSrc;
849 rectSrc.top -= ySrc;
850 rectSrc.bottom -= ySrc;
851 rectDst.left -= xDst;
852 rectDst.right -= xDst;
853 rectDst.top -= yDst;
854 rectDst.bottom -= yDst;
856 /* FIXME: avoid BadMatch errors */
857 imageSrc = XGetImage( display, physDevSrc->drawable,
858 visRectSrc->left, visRectSrc->top,
859 visRectSrc->right - visRectSrc->left,
860 visRectSrc->bottom - visRectSrc->top,
861 AllPlanes, ZPixmap );
862 XCREATEIMAGE( imageDst, rectDst.right - rectDst.left,
863 rectDst.bottom - rectDst.top, dcDst->w.bitsPerPixel );
864 BITBLT_StretchImage( imageSrc, imageDst, widthSrc, heightSrc,
865 widthDst, heightDst, &rectSrc, &rectDst,
866 physDevDst->textPixel, dcDst->w.bitsPerPixel != 1 ?
867 physDevDst->backgroundPixel :
868 physDevSrc->backgroundPixel,
869 dcDst->w.stretchBltMode );
870 XPutImage( display, pixmap, gc, imageDst, 0, 0, 0, 0,
871 rectDst.right - rectDst.left, rectDst.bottom - rectDst.top );
872 XDestroyImage( imageSrc );
873 XDestroyImage( imageDst );
877 /***********************************************************************
878 * BITBLT_GetSrcArea
880 * Retrieve an area from the source DC, mapping all the
881 * pixels to Windows colors.
883 static void BITBLT_GetSrcArea( DC *dcSrc, DC *dcDst, Pixmap pixmap, GC gc,
884 INT xSrc, INT ySrc, RECT *visRectSrc )
886 XImage *imageSrc, *imageDst;
887 register INT x, y;
888 INT width = visRectSrc->right - visRectSrc->left;
889 INT height = visRectSrc->bottom - visRectSrc->top;
890 X11DRV_PDEVICE *physDevSrc = (X11DRV_PDEVICE *)dcSrc->physDev;
891 X11DRV_PDEVICE *physDevDst = (X11DRV_PDEVICE *)dcDst->physDev;
893 if (dcSrc->w.bitsPerPixel == dcDst->w.bitsPerPixel)
895 if (!X11DRV_PALETTE_XPixelToPalette ||
896 (dcDst->w.bitsPerPixel == 1)) /* monochrome -> monochrome */
898 XCopyArea( display, physDevSrc->drawable, pixmap, gc,
899 visRectSrc->left, visRectSrc->top, width, height, 0, 0);
901 else /* color -> color */
903 if (dcSrc->w.flags & DC_MEMORY)
904 imageSrc = XGetImage( display, physDevSrc->drawable,
905 visRectSrc->left, visRectSrc->top,
906 width, height, AllPlanes, ZPixmap );
907 else
909 /* Make sure we don't get a BadMatch error */
910 XCopyArea( display, physDevSrc->drawable, pixmap, gc,
911 visRectSrc->left, visRectSrc->top,
912 width, height, 0, 0);
913 imageSrc = XGetImage( display, pixmap, 0, 0, width, height,
914 AllPlanes, ZPixmap );
916 for (y = 0; y < height; y++)
917 for (x = 0; x < width; x++)
918 XPutPixel(imageSrc, x, y,
919 X11DRV_PALETTE_XPixelToPalette[XGetPixel(imageSrc, x, y)]);
920 XPutImage( display, pixmap, gc, imageSrc,
921 0, 0, 0, 0, width, height );
922 XDestroyImage( imageSrc );
925 else
927 if (dcSrc->w.bitsPerPixel == 1) /* monochrome -> color */
929 if (X11DRV_PALETTE_XPixelToPalette)
931 XSetBackground( display, gc,
932 X11DRV_PALETTE_XPixelToPalette[physDevDst->textPixel] );
933 XSetForeground( display, gc,
934 X11DRV_PALETTE_XPixelToPalette[physDevDst->backgroundPixel]);
936 else
938 XSetBackground( display, gc, physDevDst->textPixel );
939 XSetForeground( display, gc, physDevDst->backgroundPixel );
941 XCopyPlane( display, physDevSrc->drawable, pixmap, gc,
942 visRectSrc->left, visRectSrc->top,
943 width, height, 0, 0, 1 );
945 else /* color -> monochrome */
947 /* FIXME: avoid BadMatch error */
948 imageSrc = XGetImage( display, physDevSrc->drawable,
949 visRectSrc->left, visRectSrc->top,
950 width, height, AllPlanes, ZPixmap );
951 XCREATEIMAGE( imageDst, width, height, dcDst->w.bitsPerPixel );
952 for (y = 0; y < height; y++)
953 for (x = 0; x < width; x++)
954 XPutPixel(imageDst, x, y, (XGetPixel(imageSrc,x,y) ==
955 physDevSrc->backgroundPixel) );
956 XPutImage( display, pixmap, gc, imageDst,
957 0, 0, 0, 0, width, height );
958 XDestroyImage( imageSrc );
959 XDestroyImage( imageDst );
965 /***********************************************************************
966 * BITBLT_GetDstArea
968 * Retrieve an area from the destination DC, mapping all the
969 * pixels to Windows colors.
971 static void BITBLT_GetDstArea(DC *dc, Pixmap pixmap, GC gc, RECT *visRectDst)
973 INT width = visRectDst->right - visRectDst->left;
974 INT height = visRectDst->bottom - visRectDst->top;
975 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
977 if (!X11DRV_PALETTE_XPixelToPalette || (dc->w.bitsPerPixel == 1) ||
978 (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL) )
980 XCopyArea( display, physDev->drawable, pixmap, gc,
981 visRectDst->left, visRectDst->top, width, height, 0, 0 );
983 else
985 register INT x, y;
986 XImage *image;
988 if (dc->w.flags & DC_MEMORY)
989 image = XGetImage( display, physDev->drawable,
990 visRectDst->left, visRectDst->top,
991 width, height, AllPlanes, ZPixmap );
992 else
994 /* Make sure we don't get a BadMatch error */
995 XCopyArea( display, physDev->drawable, pixmap, gc,
996 visRectDst->left, visRectDst->top, width, height, 0, 0);
997 image = XGetImage( display, pixmap, 0, 0, width, height,
998 AllPlanes, ZPixmap );
1000 for (y = 0; y < height; y++)
1001 for (x = 0; x < width; x++)
1002 XPutPixel( image, x, y,
1003 X11DRV_PALETTE_XPixelToPalette[XGetPixel( image, x, y )]);
1004 XPutImage( display, pixmap, gc, image, 0, 0, 0, 0, width, height );
1005 XDestroyImage( image );
1010 /***********************************************************************
1011 * BITBLT_PutDstArea
1013 * Put an area back into the destination DC, mapping the pixel
1014 * colors to X pixels.
1016 static void BITBLT_PutDstArea(DC *dc, Pixmap pixmap, GC gc, RECT *visRectDst)
1018 INT width = visRectDst->right - visRectDst->left;
1019 INT height = visRectDst->bottom - visRectDst->top;
1020 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
1022 /* !X11DRV_PALETTE_PaletteToXPixel is _NOT_ enough */
1024 if (!X11DRV_PALETTE_PaletteToXPixel || (dc->w.bitsPerPixel == 1) ||
1025 (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_VIRTUAL) )
1027 XCopyArea( display, pixmap, physDev->drawable, gc, 0, 0,
1028 width, height, visRectDst->left, visRectDst->top );
1030 else
1032 register INT x, y;
1033 XImage *image = XGetImage( display, pixmap, 0, 0, width, height,
1034 AllPlanes, ZPixmap );
1035 for (y = 0; y < height; y++)
1036 for (x = 0; x < width; x++)
1038 XPutPixel( image, x, y,
1039 X11DRV_PALETTE_PaletteToXPixel[XGetPixel( image, x, y )]);
1041 XPutImage( display, physDev->drawable, gc, image, 0, 0,
1042 visRectDst->left, visRectDst->top, width, height );
1043 XDestroyImage( image );
1048 /***********************************************************************
1049 * BITBLT_GetVisRectangles
1051 * Get the source and destination visible rectangles for StretchBlt().
1052 * Return FALSE if one of the rectangles is empty.
1054 static BOOL BITBLT_GetVisRectangles( DC *dcDst, INT xDst, INT yDst,
1055 INT widthDst, INT heightDst,
1056 DC *dcSrc, INT xSrc, INT ySrc,
1057 INT widthSrc, INT heightSrc,
1058 RECT *visRectSrc, RECT *visRectDst )
1060 RECT rect, clipRect;
1062 /* Get the destination visible rectangle */
1064 rect.left = xDst;
1065 rect.top = yDst;
1066 rect.right = xDst + widthDst;
1067 rect.bottom = yDst + heightDst;
1068 if (widthDst < 0) SWAP_INT32( &rect.left, &rect.right );
1069 if (heightDst < 0) SWAP_INT32( &rect.top, &rect.bottom );
1070 GetRgnBox( dcDst->w.hGCClipRgn, &clipRect );
1071 if (!IntersectRect( visRectDst, &rect, &clipRect )) return FALSE;
1073 /* Get the source visible rectangle */
1075 if (!dcSrc) return TRUE;
1076 rect.left = xSrc;
1077 rect.top = ySrc;
1078 rect.right = xSrc + widthSrc;
1079 rect.bottom = ySrc + heightSrc;
1080 if (widthSrc < 0) SWAP_INT32( &rect.left, &rect.right );
1081 if (heightSrc < 0) SWAP_INT32( &rect.top, &rect.bottom );
1082 /* Apparently the clipping and visible regions are only for output,
1083 so just check against totalExtent here to avoid BadMatch errors */
1084 if (!IntersectRect( visRectSrc, &rect, &dcSrc->w.totalExtent ))
1085 return FALSE;
1087 /* Intersect the rectangles */
1089 if ((widthSrc == widthDst) && (heightSrc == heightDst)) /* no stretching */
1091 visRectSrc->left += xDst - xSrc;
1092 visRectSrc->right += xDst - xSrc;
1093 visRectSrc->top += yDst - ySrc;
1094 visRectSrc->bottom += yDst - ySrc;
1095 if (!IntersectRect( &rect, visRectSrc, visRectDst )) return FALSE;
1096 *visRectSrc = *visRectDst = rect;
1097 visRectSrc->left += xSrc - xDst;
1098 visRectSrc->right += xSrc - xDst;
1099 visRectSrc->top += ySrc - yDst;
1100 visRectSrc->bottom += ySrc - yDst;
1102 else /* stretching */
1104 /* Map source rectangle into destination coordinates */
1105 rect.left = xDst + (visRectSrc->left - xSrc)*widthDst/widthSrc;
1106 rect.top = yDst + (visRectSrc->top - ySrc)*heightDst/heightSrc;
1107 rect.right = xDst + ((visRectSrc->right - xSrc)*widthDst)/widthSrc;
1108 rect.bottom = yDst + ((visRectSrc->bottom - ySrc)*heightDst)/heightSrc;
1109 if (rect.left > rect.right) SWAP_INT32( &rect.left, &rect.right );
1110 if (rect.top > rect.bottom) SWAP_INT32( &rect.top, &rect.bottom );
1112 /* Avoid rounding errors */
1113 rect.left--;
1114 rect.top--;
1115 rect.right++;
1116 rect.bottom++;
1117 if (!IntersectRect( visRectDst, &rect, visRectDst )) return FALSE;
1119 /* Map destination rectangle back to source coordinates */
1120 rect = *visRectDst;
1121 rect.left = xSrc + (visRectDst->left - xDst)*widthSrc/widthDst;
1122 rect.top = ySrc + (visRectDst->top - yDst)*heightSrc/heightDst;
1123 rect.right = xSrc + ((visRectDst->right - xDst)*widthSrc)/widthDst;
1124 rect.bottom = ySrc + ((visRectDst->bottom - yDst)*heightSrc)/heightDst;
1125 if (rect.left > rect.right) SWAP_INT32( &rect.left, &rect.right );
1126 if (rect.top > rect.bottom) SWAP_INT32( &rect.top, &rect.bottom );
1128 /* Avoid rounding errors */
1129 rect.left--;
1130 rect.top--;
1131 rect.right++;
1132 rect.bottom++;
1133 if (!IntersectRect( visRectSrc, &rect, visRectSrc )) return FALSE;
1135 return TRUE;
1139 /***********************************************************************
1140 * BITBLT_InternalStretchBlt
1142 * Implementation of PatBlt(), BitBlt() and StretchBlt().
1144 static BOOL BITBLT_InternalStretchBlt( DC *dcDst, INT xDst, INT yDst,
1145 INT widthDst, INT heightDst,
1146 DC *dcSrc, INT xSrc, INT ySrc,
1147 INT widthSrc, INT heightSrc,
1148 DWORD rop )
1150 BOOL usePat, useSrc, useDst, destUsed, fStretch, fNullBrush;
1151 RECT visRectDst, visRectSrc;
1152 INT width, height;
1153 const BYTE *opcode;
1154 Pixmap pixmaps[3] = { 0, 0, 0 }; /* pixmaps for DST, SRC, TMP */
1155 GC tmpGC = 0;
1156 X11DRV_PDEVICE *physDevSrc = NULL;
1157 X11DRV_PDEVICE *physDevDst = (X11DRV_PDEVICE *)dcDst->physDev;
1159 /* compensate for off-by-one shifting for negative widths and heights */
1160 if (widthDst < 0)
1161 ++xDst;
1162 if (heightDst < 0)
1163 ++yDst;
1164 if (widthSrc < 0)
1165 ++xSrc;
1166 if (heightSrc < 0)
1167 ++ySrc;
1169 if(dcSrc) physDevSrc = (X11DRV_PDEVICE *)dcSrc->physDev;
1170 usePat = (((rop >> 4) & 0x0f0000) != (rop & 0x0f0000));
1171 useSrc = (((rop >> 2) & 0x330000) != (rop & 0x330000));
1172 useDst = (((rop >> 1) & 0x550000) != (rop & 0x550000));
1173 if (!dcSrc && useSrc) return FALSE;
1175 /* Map the coordinates to device coords */
1177 xDst = dcDst->w.DCOrgX + XLPTODP( dcDst, xDst );
1178 yDst = dcDst->w.DCOrgY + YLPTODP( dcDst, yDst );
1180 /* Here we have to round to integers, not truncate */
1181 widthDst = MulDiv(widthDst, dcDst->vportExtX, dcDst->wndExtX);
1182 heightDst = MulDiv(heightDst, dcDst->vportExtY, dcDst->wndExtY);
1184 TRACE(" vportdst=%d,%d-%d,%d wnddst=%d,%d-%d,%d\n",
1185 dcDst->vportOrgX, dcDst->vportOrgY,
1186 dcDst->vportExtX, dcDst->vportExtY,
1187 dcDst->wndOrgX, dcDst->wndOrgY,
1188 dcDst->wndExtX, dcDst->wndExtY );
1189 TRACE(" rectdst=%d,%d-%d,%d orgdst=%d,%d\n",
1190 xDst, yDst, widthDst, heightDst,
1191 dcDst->w.DCOrgX, dcDst->w.DCOrgY );
1193 if (useSrc)
1195 xSrc = dcSrc->w.DCOrgX + XLPTODP( dcSrc, xSrc );
1196 ySrc = dcSrc->w.DCOrgY + YLPTODP( dcSrc, ySrc );
1197 widthSrc = widthSrc * dcSrc->vportExtX / dcSrc->wndExtX;
1198 heightSrc = heightSrc * dcSrc->vportExtY / dcSrc->wndExtY;
1199 fStretch = (widthSrc != widthDst) || (heightSrc != heightDst);
1200 TRACE(" vportsrc=%d,%d-%d,%d wndsrc=%d,%d-%d,%d\n",
1201 dcSrc->vportOrgX, dcSrc->vportOrgY,
1202 dcSrc->vportExtX, dcSrc->vportExtY,
1203 dcSrc->wndOrgX, dcSrc->wndOrgY,
1204 dcSrc->wndExtX, dcSrc->wndExtY );
1205 TRACE(" rectsrc=%d,%d-%d,%d orgsrc=%d,%d\n",
1206 xSrc, ySrc, widthSrc, heightSrc,
1207 dcSrc->w.DCOrgX, dcSrc->w.DCOrgY );
1208 if (!BITBLT_GetVisRectangles( dcDst, xDst, yDst, widthDst, heightDst,
1209 dcSrc, xSrc, ySrc, widthSrc, heightSrc,
1210 &visRectSrc, &visRectDst ))
1211 return TRUE;
1212 TRACE(" vissrc=%d,%d-%d,%d visdst=%d,%d-%d,%d\n",
1213 visRectSrc.left, visRectSrc.top,
1214 visRectSrc.right, visRectSrc.bottom,
1215 visRectDst.left, visRectDst.top,
1216 visRectDst.right, visRectDst.bottom );
1218 else
1220 fStretch = FALSE;
1221 if (!BITBLT_GetVisRectangles( dcDst, xDst, yDst, widthDst, heightDst,
1222 NULL, 0, 0, 0, 0, NULL, &visRectDst ))
1223 return TRUE;
1224 TRACE(" vissrc=none visdst=%d,%d-%d,%d\n",
1225 visRectDst.left, visRectDst.top,
1226 visRectDst.right, visRectDst.bottom );
1229 width = visRectDst.right - visRectDst.left;
1230 height = visRectDst.bottom - visRectDst.top;
1232 if (!fStretch) switch(rop) /* A few optimisations */
1234 case BLACKNESS: /* 0x00 */
1235 if ((dcDst->w.bitsPerPixel == 1) || !X11DRV_PALETTE_PaletteToXPixel)
1236 XSetFunction( display, physDevDst->gc, GXclear );
1237 else
1239 XSetFunction( display, physDevDst->gc, GXcopy );
1240 XSetForeground( display, physDevDst->gc, X11DRV_PALETTE_PaletteToXPixel[0] );
1241 XSetFillStyle( display, physDevDst->gc, FillSolid );
1243 XFillRectangle( display, physDevDst->drawable, physDevDst->gc,
1244 visRectDst.left, visRectDst.top, width, height );
1245 return TRUE;
1247 case DSTINVERT: /* 0x55 */
1248 if ((dcDst->w.bitsPerPixel == 1) || !X11DRV_PALETTE_PaletteToXPixel ||
1249 !perfect_graphics())
1251 XSetFunction( display, physDevDst->gc, GXinvert );
1253 if( X11DRV_PALETTE_PaletteFlags & (X11DRV_PALETTE_PRIVATE | X11DRV_PALETTE_VIRTUAL) )
1254 XSetFunction( display, physDevDst->gc, GXinvert);
1255 else
1257 /* Xor is much better when we do not have full colormap. */
1258 /* Using white^black ensures that we invert at least black */
1259 /* and white. */
1260 Pixel xor_pix = (WhitePixelOfScreen(X11DRV_GetXScreen()) ^
1261 BlackPixelOfScreen(X11DRV_GetXScreen()));
1262 XSetFunction( display, physDevDst->gc, GXxor );
1263 XSetForeground( display, physDevDst->gc, xor_pix);
1264 XSetFillStyle( display, physDevDst->gc, FillSolid );
1266 XFillRectangle( display, physDevDst->drawable, physDevDst->gc,
1267 visRectDst.left, visRectDst.top, width, height );
1268 return TRUE;
1270 break;
1272 case PATINVERT: /* 0x5a */
1273 if (perfect_graphics()) break;
1274 if (X11DRV_SetupGCForBrush( dcDst ))
1276 XSetFunction( display, physDevDst->gc, GXxor );
1277 XFillRectangle( display, physDevDst->drawable, physDevDst->gc,
1278 visRectDst.left, visRectDst.top, width, height );
1280 return TRUE;
1282 case 0xa50065:
1283 if (perfect_graphics()) break;
1284 if (X11DRV_SetupGCForBrush( dcDst ))
1286 XSetFunction( display, physDevDst->gc, GXequiv );
1287 XFillRectangle( display, physDevDst->drawable, physDevDst->gc,
1288 visRectDst.left, visRectDst.top, width, height );
1290 return TRUE;
1292 case SRCCOPY: /* 0xcc */
1293 if (dcSrc->w.bitsPerPixel == dcDst->w.bitsPerPixel)
1295 BOOL expose = !(dcSrc->w.flags & DC_MEMORY) && !(dcDst->w.flags & DC_MEMORY);
1296 if ( expose ) XSetGraphicsExposures( display, physDevDst->gc, True );
1297 XSetFunction( display, physDevDst->gc, GXcopy );
1298 XCopyArea( display, physDevSrc->drawable,
1299 physDevDst->drawable, physDevDst->gc,
1300 visRectSrc.left, visRectSrc.top,
1301 width, height, visRectDst.left, visRectDst.top );
1302 if ( expose ) XSetGraphicsExposures( display, physDevDst->gc, False );
1303 return TRUE;
1305 if (dcSrc->w.bitsPerPixel == 1)
1307 BOOL expose = !(dcSrc->w.flags & DC_MEMORY) && !(dcDst->w.flags & DC_MEMORY);
1308 XSetBackground( display, physDevDst->gc, physDevDst->textPixel );
1309 XSetForeground( display, physDevDst->gc,
1310 physDevDst->backgroundPixel );
1311 XSetFunction( display, physDevDst->gc, GXcopy );
1312 if ( expose ) XSetGraphicsExposures( display, physDevDst->gc, True );
1313 XCopyPlane( display, physDevSrc->drawable,
1314 physDevDst->drawable, physDevDst->gc,
1315 visRectSrc.left, visRectSrc.top,
1316 width, height, visRectDst.left, visRectDst.top, 1 );
1317 if ( expose ) XSetGraphicsExposures( display, physDevDst->gc, False );
1318 return TRUE;
1320 break;
1322 case PATCOPY: /* 0xf0 */
1323 if (!X11DRV_SetupGCForBrush( dcDst )) return TRUE;
1324 XSetFunction( display, physDevDst->gc, GXcopy );
1325 XFillRectangle( display, physDevDst->drawable, physDevDst->gc,
1326 visRectDst.left, visRectDst.top, width, height );
1327 return TRUE;
1329 case WHITENESS: /* 0xff */
1330 if ((dcDst->w.bitsPerPixel == 1) || !X11DRV_PALETTE_PaletteToXPixel)
1331 XSetFunction( display, physDevDst->gc, GXset );
1332 else
1334 XSetFunction( display, physDevDst->gc, GXcopy );
1335 XSetForeground( display, physDevDst->gc,
1336 WhitePixelOfScreen( X11DRV_GetXScreen() ));
1337 XSetFillStyle( display, physDevDst->gc, FillSolid );
1339 XFillRectangle( display, physDevDst->drawable, physDevDst->gc,
1340 visRectDst.left, visRectDst.top, width, height );
1341 return TRUE;
1344 tmpGC = XCreateGC( display, physDevDst->drawable, 0, NULL );
1345 XSetGraphicsExposures( display, tmpGC, False );
1346 pixmaps[DST] = XCreatePixmap( display, X11DRV_GetXRootWindow(), width, height,
1347 dcDst->w.bitsPerPixel );
1348 if (useSrc)
1350 pixmaps[SRC] = XCreatePixmap( display, X11DRV_GetXRootWindow(), width, height,
1351 dcDst->w.bitsPerPixel );
1352 if (fStretch)
1353 BITBLT_GetSrcAreaStretch( dcSrc, dcDst, pixmaps[SRC], tmpGC,
1354 xSrc, ySrc, widthSrc, heightSrc,
1355 xDst, yDst, widthDst, heightDst,
1356 &visRectSrc, &visRectDst );
1357 else
1358 BITBLT_GetSrcArea( dcSrc, dcDst, pixmaps[SRC], tmpGC,
1359 xSrc, ySrc, &visRectSrc );
1361 if (useDst) BITBLT_GetDstArea( dcDst, pixmaps[DST], tmpGC, &visRectDst );
1362 if (usePat) fNullBrush = !X11DRV_SetupGCForPatBlt( dcDst, tmpGC, TRUE );
1363 else fNullBrush = FALSE;
1364 destUsed = FALSE;
1366 for (opcode = BITBLT_Opcodes[(rop >> 16) & 0xff]; *opcode; opcode++)
1368 if (OP_DST(*opcode) == DST) destUsed = TRUE;
1369 XSetFunction( display, tmpGC, OP_ROP(*opcode) );
1370 switch(OP_SRCDST(*opcode))
1372 case OP_ARGS(DST,TMP):
1373 case OP_ARGS(SRC,TMP):
1374 if (!pixmaps[TMP])
1375 pixmaps[TMP] = XCreatePixmap( display, X11DRV_GetXRootWindow(),
1376 width, height,
1377 dcDst->w.bitsPerPixel );
1378 /* fall through */
1379 case OP_ARGS(DST,SRC):
1380 case OP_ARGS(SRC,DST):
1381 case OP_ARGS(TMP,SRC):
1382 case OP_ARGS(TMP,DST):
1383 XCopyArea( display, pixmaps[OP_SRC(*opcode)],
1384 pixmaps[OP_DST(*opcode)], tmpGC,
1385 0, 0, width, height, 0, 0 );
1386 break;
1388 case OP_ARGS(PAT,TMP):
1389 if (!pixmaps[TMP] && !fNullBrush)
1390 pixmaps[TMP] = XCreatePixmap( display, X11DRV_GetXRootWindow(),
1391 width, height,
1392 dcDst->w.bitsPerPixel );
1393 /* fall through */
1394 case OP_ARGS(PAT,DST):
1395 case OP_ARGS(PAT,SRC):
1396 if (!fNullBrush)
1397 XFillRectangle( display, pixmaps[OP_DST(*opcode)],
1398 tmpGC, 0, 0, width, height );
1399 break;
1402 XSetFunction( display, physDevDst->gc, GXcopy );
1403 BITBLT_PutDstArea( dcDst, pixmaps[destUsed ? DST : SRC],
1404 physDevDst->gc, &visRectDst );
1405 XFreePixmap( display, pixmaps[DST] );
1406 if (pixmaps[SRC]) XFreePixmap( display, pixmaps[SRC] );
1407 if (pixmaps[TMP]) XFreePixmap( display, pixmaps[TMP] );
1408 XFreeGC( display, tmpGC );
1409 return TRUE;
1412 struct StretchBlt_params
1414 DC *dcDst;
1415 INT xDst;
1416 INT yDst;
1417 INT widthDst;
1418 INT heightDst;
1419 DC *dcSrc;
1420 INT xSrc;
1421 INT ySrc;
1422 INT widthSrc;
1423 INT heightSrc;
1424 DWORD rop;
1427 /***********************************************************************
1428 * BITBLT_DoStretchBlt
1430 * Wrapper function for BITBLT_InternalStretchBlt
1431 * to use with CALL_LARGE_STACK.
1433 static int BITBLT_DoStretchBlt( const struct StretchBlt_params *p )
1435 return (int)BITBLT_InternalStretchBlt( p->dcDst, p->xDst, p->yDst,
1436 p->widthDst, p->heightDst,
1437 p->dcSrc, p->xSrc, p->ySrc,
1438 p->widthSrc, p->heightSrc, p->rop );
1441 /***********************************************************************
1442 * X11DRV_PatBlt
1444 BOOL X11DRV_PatBlt( DC *dc, INT left, INT top,
1445 INT width, INT height, DWORD rop )
1447 struct StretchBlt_params params;
1448 BOOL result;
1450 params.dcDst = dc;
1451 params.xDst = left;
1452 params.yDst = top;
1453 params.widthDst = width;
1454 params.heightDst = height;
1455 params.dcSrc = NULL;
1456 params.xSrc = 0;
1457 params.ySrc = 0;
1458 params.widthSrc = 0;
1459 params.heightSrc = 0;
1460 params.rop = rop;
1462 if (dc->w.flags & DC_DIRTY) CLIPPING_UpdateGCRegion( dc );
1464 X11DRV_DIB_UpdateDIBSection( dc, FALSE );
1465 EnterCriticalSection( &X11DRV_CritSection );
1466 result = (BOOL)CALL_LARGE_STACK( BITBLT_DoStretchBlt, &params );
1467 LeaveCriticalSection( &X11DRV_CritSection );
1468 X11DRV_DIB_UpdateDIBSection( dc, TRUE );
1469 return result;
1473 /***********************************************************************
1474 * X11DRV_BitBlt
1476 BOOL X11DRV_BitBlt( DC *dcDst, INT xDst, INT yDst,
1477 INT width, INT height, DC *dcSrc,
1478 INT xSrc, INT ySrc, DWORD rop )
1480 struct StretchBlt_params params;
1481 BOOL result;
1483 params.dcDst = dcDst;
1484 params.xDst = xDst;
1485 params.yDst = yDst;
1486 params.widthDst = width;
1487 params.heightDst = height;
1488 params.dcSrc = dcSrc;
1489 params.xSrc = xSrc;
1490 params.ySrc = ySrc;
1491 params.widthSrc = width;
1492 params.heightSrc = height;
1493 params.rop = rop;
1495 X11DRV_DIB_UpdateDIBSection( dcDst, FALSE );
1496 X11DRV_DIB_UpdateDIBSection( dcSrc, FALSE );
1498 if (dcDst->w.flags & DC_DIRTY) CLIPPING_UpdateGCRegion( dcDst );
1499 if (dcSrc && (dcSrc->w.flags & DC_DIRTY)) CLIPPING_UpdateGCRegion( dcSrc );
1501 EnterCriticalSection( &X11DRV_CritSection );
1502 result = (BOOL)CALL_LARGE_STACK( BITBLT_DoStretchBlt, &params );
1503 LeaveCriticalSection( &X11DRV_CritSection );
1504 X11DRV_DIB_UpdateDIBSection( dcDst, TRUE );
1505 return result;
1509 /***********************************************************************
1510 * X11DRV_StretchBlt
1512 BOOL X11DRV_StretchBlt( DC *dcDst, INT xDst, INT yDst,
1513 INT widthDst, INT heightDst,
1514 DC *dcSrc, INT xSrc, INT ySrc,
1515 INT widthSrc, INT heightSrc, DWORD rop )
1517 struct StretchBlt_params params;
1518 BOOL result;
1520 params.dcDst = dcDst;
1521 params.xDst = xDst;
1522 params.yDst = yDst;
1523 params.widthDst = widthDst;
1524 params.heightDst = heightDst;
1525 params.dcSrc = dcSrc;
1526 params.xSrc = xSrc;
1527 params.ySrc = ySrc;
1528 params.widthSrc = widthSrc;
1529 params.heightSrc = heightSrc;
1530 params.rop = rop;
1532 X11DRV_DIB_UpdateDIBSection( dcDst, FALSE );
1533 X11DRV_DIB_UpdateDIBSection( dcSrc, FALSE );
1535 if (dcDst->w.flags & DC_DIRTY) CLIPPING_UpdateGCRegion( dcDst );
1536 if (dcSrc && (dcSrc->w.flags & DC_DIRTY)) CLIPPING_UpdateGCRegion( dcSrc );
1538 EnterCriticalSection( &X11DRV_CritSection );
1539 result = (BOOL)CALL_LARGE_STACK( BITBLT_DoStretchBlt, &params );
1540 LeaveCriticalSection( &X11DRV_CritSection );
1541 X11DRV_DIB_UpdateDIBSection( dcDst, TRUE );
1542 return result;
1545 #endif /* !defined(X_DISPLAY_MISSING) */