Implement ResetDC and PHYSICALOFFSET[X|Y] devcaps.
[wine] / dlls / ddraw / helper.c
1
2 /*              DirectDraw Base Functions
3  *
4  * Copyright 1997-1999 Marcus Meissner
5  * Copyright 1998 Lionel Ulmer (most of Direct3D stuff)
6  * Copyright 2000 TransGaming Technologies Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include "config.h"
24
25 #include <stddef.h>
26
27 #include "d3d.h"
28 #include "ddraw.h"
29 #include "winerror.h"
30
31 #include "wine/exception.h"
32 #include "ddraw_private.h"
33
34 #include "wine/debug.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
37
38 /******************************************************************************
39  *              debug output functions
40  */
41 typedef struct
42 {
43     DWORD val;
44     const char* name;
45 } flag_info;
46
47 #define FE(x) { x, #x }
48
49 typedef struct
50 {
51     DWORD val;
52     const char* name;
53     void (*func)(const void *);
54     ptrdiff_t offset;
55 } member_info;
56
57 #define ME(x,f,e) { x, #x, (void (*)(const void *))(f), offsetof(STRUCT, e) }
58
59 static void DDRAW_dump_flags(DWORD flags, const flag_info* names,
60                              size_t num_names)
61 {
62     unsigned int        i;
63
64     for (i=0; i < num_names; i++)
65         if (names[i].val & flags)
66             DPRINTF("%s ", names[i].name);
67
68     DPRINTF("\n");
69 }
70
71 static void DDRAW_dump_members(DWORD flags, const void* data,
72                                const member_info* mems, size_t num_mems)
73 {
74     unsigned int i;
75
76     for (i=0; i < num_mems; i++)
77     {
78         if (mems[i].val & flags)
79         {
80             DPRINTF(" - %s : ", mems[i].name);
81             mems[i].func((const char *)data + mems[i].offset);
82             DPRINTF("\n");
83         }
84     }
85 }
86
87 void DDRAW_dump_DDBLTFX(DWORD flagmask)
88 {
89     static const flag_info flags[] =
90         {
91             FE(DDBLTFX_ARITHSTRETCHY),
92             FE(DDBLTFX_MIRRORLEFTRIGHT),
93             FE(DDBLTFX_MIRRORUPDOWN),
94             FE(DDBLTFX_NOTEARING),
95             FE(DDBLTFX_ROTATE180),
96             FE(DDBLTFX_ROTATE270),
97             FE(DDBLTFX_ROTATE90),
98             FE(DDBLTFX_ZBUFFERRANGE),
99             FE(DDBLTFX_ZBUFFERBASEDEST)
100         };
101
102     DDRAW_dump_flags(flagmask, flags, sizeof(flags)/sizeof(flags[0]));
103 }
104
105 void DDRAW_dump_DDBLTFAST(DWORD flagmask)
106 {
107     static const flag_info flags[] =
108         {
109             FE(DDBLTFAST_NOCOLORKEY),
110             FE(DDBLTFAST_SRCCOLORKEY),
111             FE(DDBLTFAST_DESTCOLORKEY),
112             FE(DDBLTFAST_WAIT)
113         };
114
115     DDRAW_dump_flags(flagmask, flags, sizeof(flags)/sizeof(flags[0]));
116 }
117
118 void DDRAW_dump_DDBLT(DWORD flagmask)
119 {
120     static const flag_info flags[] =
121         {
122             FE(DDBLT_ALPHADEST),
123             FE(DDBLT_ALPHADESTCONSTOVERRIDE),
124             FE(DDBLT_ALPHADESTNEG),
125             FE(DDBLT_ALPHADESTSURFACEOVERRIDE),
126             FE(DDBLT_ALPHAEDGEBLEND),
127             FE(DDBLT_ALPHASRC),
128             FE(DDBLT_ALPHASRCCONSTOVERRIDE),
129             FE(DDBLT_ALPHASRCNEG),
130             FE(DDBLT_ALPHASRCSURFACEOVERRIDE),
131             FE(DDBLT_ASYNC),
132             FE(DDBLT_COLORFILL),
133             FE(DDBLT_DDFX),
134             FE(DDBLT_DDROPS),
135             FE(DDBLT_KEYDEST),
136             FE(DDBLT_KEYDESTOVERRIDE),
137             FE(DDBLT_KEYSRC),
138             FE(DDBLT_KEYSRCOVERRIDE),
139             FE(DDBLT_ROP),
140             FE(DDBLT_ROTATIONANGLE),
141             FE(DDBLT_ZBUFFER),
142             FE(DDBLT_ZBUFFERDESTCONSTOVERRIDE),
143             FE(DDBLT_ZBUFFERDESTOVERRIDE),
144             FE(DDBLT_ZBUFFERSRCCONSTOVERRIDE),
145             FE(DDBLT_ZBUFFERSRCOVERRIDE),
146             FE(DDBLT_WAIT),
147             FE(DDBLT_DEPTHFILL)
148     };
149
150     DDRAW_dump_flags(flagmask, flags, sizeof(flags)/sizeof(flags[0]));
151 }
152
153 void DDRAW_dump_DDSCAPS(const DDSCAPS2 *in)
154 {
155     static const flag_info flags[] = 
156         {
157             FE(DDSCAPS_RESERVED1),
158             FE(DDSCAPS_ALPHA),
159             FE(DDSCAPS_BACKBUFFER),
160             FE(DDSCAPS_COMPLEX),
161             FE(DDSCAPS_FLIP),
162             FE(DDSCAPS_FRONTBUFFER),
163             FE(DDSCAPS_OFFSCREENPLAIN),
164             FE(DDSCAPS_OVERLAY),
165             FE(DDSCAPS_PALETTE),
166             FE(DDSCAPS_PRIMARYSURFACE),
167             FE(DDSCAPS_PRIMARYSURFACELEFT),
168             FE(DDSCAPS_SYSTEMMEMORY),
169             FE(DDSCAPS_TEXTURE),
170             FE(DDSCAPS_3DDEVICE),
171             FE(DDSCAPS_VIDEOMEMORY),
172             FE(DDSCAPS_VISIBLE),
173             FE(DDSCAPS_WRITEONLY),
174             FE(DDSCAPS_ZBUFFER),
175             FE(DDSCAPS_OWNDC),
176             FE(DDSCAPS_LIVEVIDEO),
177             FE(DDSCAPS_HWCODEC),
178             FE(DDSCAPS_MODEX),
179             FE(DDSCAPS_MIPMAP),
180             FE(DDSCAPS_RESERVED2),
181             FE(DDSCAPS_ALLOCONLOAD),
182             FE(DDSCAPS_VIDEOPORT),
183             FE(DDSCAPS_LOCALVIDMEM),
184             FE(DDSCAPS_NONLOCALVIDMEM),
185             FE(DDSCAPS_STANDARDVGAMODE),
186             FE(DDSCAPS_OPTIMIZED)
187     };
188
189     DDRAW_dump_flags(in->dwCaps, flags, sizeof(flags)/sizeof(flags[0]));
190 }
191
192 void DDRAW_dump_pixelformat_flag(DWORD flagmask)
193 {
194     static const flag_info flags[] =
195         {
196             FE(DDPF_ALPHAPIXELS),
197             FE(DDPF_ALPHA),
198             FE(DDPF_FOURCC),
199             FE(DDPF_PALETTEINDEXED4),
200             FE(DDPF_PALETTEINDEXEDTO8),
201             FE(DDPF_PALETTEINDEXED8),
202             FE(DDPF_RGB),
203             FE(DDPF_COMPRESSED),
204             FE(DDPF_RGBTOYUV),
205             FE(DDPF_YUV),
206             FE(DDPF_ZBUFFER),
207             FE(DDPF_PALETTEINDEXED1),
208             FE(DDPF_PALETTEINDEXED2),
209             FE(DDPF_ZPIXELS)
210     };
211
212     DDRAW_dump_flags(flagmask, flags, sizeof(flags)/sizeof(flags[0]));
213 }
214
215 void DDRAW_dump_paletteformat(DWORD dwFlags)
216 {
217     static const flag_info flags[] =
218         {
219             FE(DDPCAPS_4BIT),
220             FE(DDPCAPS_8BITENTRIES),
221             FE(DDPCAPS_8BIT),
222             FE(DDPCAPS_INITIALIZE),
223             FE(DDPCAPS_PRIMARYSURFACE),
224             FE(DDPCAPS_PRIMARYSURFACELEFT),
225             FE(DDPCAPS_ALLOW256),
226             FE(DDPCAPS_VSYNC),
227             FE(DDPCAPS_1BIT),
228             FE(DDPCAPS_2BIT),
229             FE(DDPCAPS_ALPHA)
230     };
231
232     DDRAW_dump_flags(dwFlags, flags, sizeof(flags)/sizeof(flags[0]));
233 }
234
235 void DDRAW_dump_pixelformat(const DDPIXELFORMAT *pf) {
236     DPRINTF("( ");
237     DDRAW_dump_pixelformat_flag(pf->dwFlags);
238     if (pf->dwFlags & DDPF_FOURCC) {
239         DPRINTF(", dwFourCC code '%c%c%c%c' (0x%08lx) - %ld bits per pixel",
240                 (unsigned char)( pf->dwFourCC     &0xff),
241                 (unsigned char)((pf->dwFourCC>> 8)&0xff),
242                 (unsigned char)((pf->dwFourCC>>16)&0xff),
243                 (unsigned char)((pf->dwFourCC>>24)&0xff),
244                 pf->dwFourCC,
245                 pf->u1.dwYUVBitCount
246         );
247     }
248     if (pf->dwFlags & DDPF_RGB) {
249         char *cmd;
250         DPRINTF(", RGB bits: %ld, ", pf->u1.dwRGBBitCount);
251         switch (pf->u1.dwRGBBitCount) {
252         case 4: cmd = "%1lx"; break;
253         case 8: cmd = "%02lx"; break;
254         case 16: cmd = "%04lx"; break;
255         case 24: cmd = "%06lx"; break;
256         case 32: cmd = "%08lx"; break;
257         default: ERR("Unexpected bit depth !\n"); cmd = "%d"; break;
258         }
259         DPRINTF(" R "); DPRINTF(cmd, pf->u2.dwRBitMask);
260         DPRINTF(" G "); DPRINTF(cmd, pf->u3.dwGBitMask);
261         DPRINTF(" B "); DPRINTF(cmd, pf->u4.dwBBitMask);
262         if (pf->dwFlags & DDPF_ALPHAPIXELS) {
263             DPRINTF(" A "); DPRINTF(cmd, pf->u5.dwRGBAlphaBitMask);
264         }
265         if (pf->dwFlags & DDPF_ZPIXELS) {
266             DPRINTF(" Z "); DPRINTF(cmd, pf->u5.dwRGBZBitMask);
267         }
268     }
269     if (pf->dwFlags & DDPF_ZBUFFER) {
270         DPRINTF(", Z bits : %ld", pf->u1.dwZBufferBitDepth);
271     }
272     if (pf->dwFlags & DDPF_ALPHA) {
273         DPRINTF(", Alpha bits : %ld", pf->u1.dwAlphaBitDepth);
274     }
275     DPRINTF(")");
276 }
277
278 void DDRAW_dump_colorkeyflag(DWORD ck)
279 {
280     static const flag_info flags[] =
281         {
282             FE(DDCKEY_COLORSPACE),
283             FE(DDCKEY_DESTBLT),
284             FE(DDCKEY_DESTOVERLAY),
285             FE(DDCKEY_SRCBLT),
286             FE(DDCKEY_SRCOVERLAY)
287     };
288
289     DDRAW_dump_flags(ck, flags, sizeof(flags)/sizeof(flags[0]));
290 }
291
292 static void DDRAW_dump_DWORD(const void *in) {
293     DPRINTF("%ld", *((const DWORD *) in));
294 }
295 static void DDRAW_dump_PTR(const void *in) {
296     DPRINTF("%p", *((const void **) in));
297 }
298 void DDRAW_dump_DDCOLORKEY(const DDCOLORKEY *ddck) {
299     DPRINTF(" Low : %ld  - High : %ld", ddck->dwColorSpaceLowValue, ddck->dwColorSpaceHighValue);
300 }
301
302 void DDRAW_dump_surface_desc(const DDSURFACEDESC2 *lpddsd)
303 {
304 #define STRUCT DDSURFACEDESC2
305     static const member_info members[] =
306         {
307             ME(DDSD_CAPS, DDRAW_dump_DDSCAPS, ddsCaps),
308             ME(DDSD_HEIGHT, DDRAW_dump_DWORD, dwHeight),
309             ME(DDSD_WIDTH, DDRAW_dump_DWORD, dwWidth),
310             ME(DDSD_PITCH, DDRAW_dump_DWORD, u1.lPitch),
311             ME(DDSD_LINEARSIZE, DDRAW_dump_DWORD, u1.dwLinearSize),
312             ME(DDSD_BACKBUFFERCOUNT, DDRAW_dump_DWORD, dwBackBufferCount),
313             ME(DDSD_MIPMAPCOUNT, DDRAW_dump_DWORD, u2.dwMipMapCount),
314             ME(DDSD_REFRESHRATE, DDRAW_dump_DWORD, u2.dwRefreshRate),
315             ME(DDSD_ALPHABITDEPTH, DDRAW_dump_DWORD, dwAlphaBitDepth),
316             ME(DDSD_LPSURFACE, DDRAW_dump_PTR, lpSurface),
317             ME(DDSD_CKDESTOVERLAY, DDRAW_dump_DDCOLORKEY, u3.ddckCKDestOverlay),
318             ME(DDSD_CKDESTBLT, DDRAW_dump_DDCOLORKEY, ddckCKDestBlt),
319             ME(DDSD_CKSRCOVERLAY, DDRAW_dump_DDCOLORKEY, ddckCKSrcOverlay),
320             ME(DDSD_CKSRCBLT, DDRAW_dump_DDCOLORKEY, ddckCKSrcBlt),
321             ME(DDSD_PIXELFORMAT, DDRAW_dump_pixelformat, u4.ddpfPixelFormat)
322         };
323
324     DDRAW_dump_members(lpddsd->dwFlags, lpddsd, members,
325                        sizeof(members)/sizeof(members[0]));
326 }
327
328 void DDRAW_dump_cooperativelevel(DWORD cooplevel)
329 {
330     static const flag_info flags[] =
331         {
332             FE(DDSCL_FULLSCREEN),
333             FE(DDSCL_ALLOWREBOOT),
334             FE(DDSCL_NOWINDOWCHANGES),
335             FE(DDSCL_NORMAL),
336             FE(DDSCL_ALLOWMODEX),
337             FE(DDSCL_EXCLUSIVE),
338             FE(DDSCL_SETFOCUSWINDOW),
339             FE(DDSCL_SETDEVICEWINDOW),
340             FE(DDSCL_CREATEDEVICEWINDOW)
341     };
342
343     if (TRACE_ON(ddraw))
344     {
345         DPRINTF(" - ");
346         DDRAW_dump_flags(cooplevel, flags, sizeof(flags)/sizeof(flags[0]));
347     }
348 }