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