Fixed a couple of HWND type mismatches.
[wine/multimedia.git] / dlls / ddraw / helper.c
blob79eb52a3416fd6c704412fcd1ddba4c1ed36873a
2 /* DirectDraw Base Functions
4 * Copyright 1997-1999 Marcus Meissner
5 * Copyright 1998 Lionel Ulmer (most of Direct3D stuff)
6 * Copyright 2000 TransGaming Technologies Inc.
7 */
9 #include "config.h"
11 #include <stddef.h>
13 #include "d3d.h"
14 #include "ddraw.h"
15 #include "winerror.h"
17 #include "wine/exception.h"
18 #include "ddraw_private.h"
20 #include "debugtools.h"
22 DEFAULT_DEBUG_CHANNEL(ddraw);
24 /******************************************************************************
25 * debug output functions
27 typedef struct
29 DWORD val;
30 const char* name;
31 } flag_info;
33 #define FE(x) { x, #x }
35 typedef struct
37 DWORD val;
38 const char* name;
39 void (*func)(const void *);
40 ptrdiff_t offset;
41 } member_info;
43 #define ME(x,f,e) { x, #x, (void (*)(const void *))(f), offsetof(STRUCT, e) }
45 static void DDRAW_dump_flags(DWORD flags, const flag_info* names,
46 size_t num_names)
48 unsigned int i;
50 for (i=0; i < num_names; i++)
51 if (names[i].val & flags)
52 DPRINTF("%s ", names[i].name);
54 DPRINTF("\n");
57 static void DDRAW_dump_members(DWORD flags, const void* data,
58 const member_info* mems, size_t num_mems)
60 unsigned int i;
62 for (i=0; i < num_mems; i++)
64 if (mems[i].val & flags)
66 DPRINTF(" - %s : ", mems[i].name);
67 mems[i].func((const char *)data + mems[i].offset);
68 DPRINTF("\n");
73 void DDRAW_dump_DDBLTFX(DWORD flagmask)
75 static const flag_info flags[] =
77 FE(DDBLTFX_ARITHSTRETCHY),
78 FE(DDBLTFX_MIRRORLEFTRIGHT),
79 FE(DDBLTFX_MIRRORUPDOWN),
80 FE(DDBLTFX_NOTEARING),
81 FE(DDBLTFX_ROTATE180),
82 FE(DDBLTFX_ROTATE270),
83 FE(DDBLTFX_ROTATE90),
84 FE(DDBLTFX_ZBUFFERRANGE),
85 FE(DDBLTFX_ZBUFFERBASEDEST)
88 DDRAW_dump_flags(flagmask, flags, sizeof(flags)/sizeof(flags[0]));
91 void DDRAW_dump_DDBLTFAST(DWORD flagmask)
93 static const flag_info flags[] =
95 FE(DDBLTFAST_NOCOLORKEY),
96 FE(DDBLTFAST_SRCCOLORKEY),
97 FE(DDBLTFAST_DESTCOLORKEY),
98 FE(DDBLTFAST_WAIT)
101 DDRAW_dump_flags(flagmask, flags, sizeof(flags)/sizeof(flags[0]));
104 void DDRAW_dump_DDBLT(DWORD flagmask)
106 static const flag_info flags[] =
108 FE(DDBLT_ALPHADEST),
109 FE(DDBLT_ALPHADESTCONSTOVERRIDE),
110 FE(DDBLT_ALPHADESTNEG),
111 FE(DDBLT_ALPHADESTSURFACEOVERRIDE),
112 FE(DDBLT_ALPHAEDGEBLEND),
113 FE(DDBLT_ALPHASRC),
114 FE(DDBLT_ALPHASRCCONSTOVERRIDE),
115 FE(DDBLT_ALPHASRCNEG),
116 FE(DDBLT_ALPHASRCSURFACEOVERRIDE),
117 FE(DDBLT_ASYNC),
118 FE(DDBLT_COLORFILL),
119 FE(DDBLT_DDFX),
120 FE(DDBLT_DDROPS),
121 FE(DDBLT_KEYDEST),
122 FE(DDBLT_KEYDESTOVERRIDE),
123 FE(DDBLT_KEYSRC),
124 FE(DDBLT_KEYSRCOVERRIDE),
125 FE(DDBLT_ROP),
126 FE(DDBLT_ROTATIONANGLE),
127 FE(DDBLT_ZBUFFER),
128 FE(DDBLT_ZBUFFERDESTCONSTOVERRIDE),
129 FE(DDBLT_ZBUFFERDESTOVERRIDE),
130 FE(DDBLT_ZBUFFERSRCCONSTOVERRIDE),
131 FE(DDBLT_ZBUFFERSRCOVERRIDE),
132 FE(DDBLT_WAIT),
133 FE(DDBLT_DEPTHFILL)
136 DDRAW_dump_flags(flagmask, flags, sizeof(flags)/sizeof(flags[0]));
139 void DDRAW_dump_DDSCAPS(const DDSCAPS2 *in)
141 static const flag_info flags[] =
143 FE(DDSCAPS_RESERVED1),
144 FE(DDSCAPS_ALPHA),
145 FE(DDSCAPS_BACKBUFFER),
146 FE(DDSCAPS_COMPLEX),
147 FE(DDSCAPS_FLIP),
148 FE(DDSCAPS_FRONTBUFFER),
149 FE(DDSCAPS_OFFSCREENPLAIN),
150 FE(DDSCAPS_OVERLAY),
151 FE(DDSCAPS_PALETTE),
152 FE(DDSCAPS_PRIMARYSURFACE),
153 FE(DDSCAPS_PRIMARYSURFACELEFT),
154 FE(DDSCAPS_SYSTEMMEMORY),
155 FE(DDSCAPS_TEXTURE),
156 FE(DDSCAPS_3DDEVICE),
157 FE(DDSCAPS_VIDEOMEMORY),
158 FE(DDSCAPS_VISIBLE),
159 FE(DDSCAPS_WRITEONLY),
160 FE(DDSCAPS_ZBUFFER),
161 FE(DDSCAPS_OWNDC),
162 FE(DDSCAPS_LIVEVIDEO),
163 FE(DDSCAPS_HWCODEC),
164 FE(DDSCAPS_MODEX),
165 FE(DDSCAPS_MIPMAP),
166 FE(DDSCAPS_RESERVED2),
167 FE(DDSCAPS_ALLOCONLOAD),
168 FE(DDSCAPS_VIDEOPORT),
169 FE(DDSCAPS_LOCALVIDMEM),
170 FE(DDSCAPS_NONLOCALVIDMEM),
171 FE(DDSCAPS_STANDARDVGAMODE),
172 FE(DDSCAPS_OPTIMIZED)
175 DDRAW_dump_flags(in->dwCaps, flags, sizeof(flags)/sizeof(flags[0]));
178 void DDRAW_dump_pixelformat_flag(DWORD flagmask)
180 static const flag_info flags[] =
182 FE(DDPF_ALPHAPIXELS),
183 FE(DDPF_ALPHA),
184 FE(DDPF_FOURCC),
185 FE(DDPF_PALETTEINDEXED4),
186 FE(DDPF_PALETTEINDEXEDTO8),
187 FE(DDPF_PALETTEINDEXED8),
188 FE(DDPF_RGB),
189 FE(DDPF_COMPRESSED),
190 FE(DDPF_RGBTOYUV),
191 FE(DDPF_YUV),
192 FE(DDPF_ZBUFFER),
193 FE(DDPF_PALETTEINDEXED1),
194 FE(DDPF_PALETTEINDEXED2),
195 FE(DDPF_ZPIXELS)
198 DDRAW_dump_flags(flagmask, flags, sizeof(flags)/sizeof(flags[0]));
201 void DDRAW_dump_paletteformat(DWORD dwFlags)
203 static const flag_info flags[] =
205 FE(DDPCAPS_4BIT),
206 FE(DDPCAPS_8BITENTRIES),
207 FE(DDPCAPS_8BIT),
208 FE(DDPCAPS_INITIALIZE),
209 FE(DDPCAPS_PRIMARYSURFACE),
210 FE(DDPCAPS_PRIMARYSURFACELEFT),
211 FE(DDPCAPS_ALLOW256),
212 FE(DDPCAPS_VSYNC),
213 FE(DDPCAPS_1BIT),
214 FE(DDPCAPS_2BIT),
215 FE(DDPCAPS_ALPHA)
218 DDRAW_dump_flags(dwFlags, flags, sizeof(flags)/sizeof(flags[0]));
221 void DDRAW_dump_pixelformat(const DDPIXELFORMAT *pf) {
222 DPRINTF("( ");
223 DDRAW_dump_pixelformat_flag(pf->dwFlags);
224 if (pf->dwFlags & DDPF_FOURCC) {
225 DPRINTF(", dwFourCC code '%c%c%c%c' (0x%08lx) - %ld bits per pixel",
226 (unsigned char)( pf->dwFourCC &0xff),
227 (unsigned char)((pf->dwFourCC>> 8)&0xff),
228 (unsigned char)((pf->dwFourCC>>16)&0xff),
229 (unsigned char)((pf->dwFourCC>>24)&0xff),
230 pf->dwFourCC,
231 pf->u1.dwYUVBitCount
234 if (pf->dwFlags & DDPF_RGB) {
235 char *cmd;
236 DPRINTF(", RGB bits: %ld, ", pf->u1.dwRGBBitCount);
237 switch (pf->u1.dwRGBBitCount) {
238 case 4: cmd = "%1lx"; break;
239 case 8: cmd = "%02lx"; break;
240 case 16: cmd = "%04lx"; break;
241 case 24: cmd = "%06lx"; break;
242 case 32: cmd = "%08lx"; break;
243 default: ERR("Unexpected bit depth !\n"); cmd = "%d"; break;
245 DPRINTF(" R "); DPRINTF(cmd, pf->u2.dwRBitMask);
246 DPRINTF(" G "); DPRINTF(cmd, pf->u3.dwGBitMask);
247 DPRINTF(" B "); DPRINTF(cmd, pf->u4.dwBBitMask);
248 if (pf->dwFlags & DDPF_ALPHAPIXELS) {
249 DPRINTF(" A "); DPRINTF(cmd, pf->u5.dwRGBAlphaBitMask);
251 if (pf->dwFlags & DDPF_ZPIXELS) {
252 DPRINTF(" Z "); DPRINTF(cmd, pf->u5.dwRGBZBitMask);
255 if (pf->dwFlags & DDPF_ZBUFFER) {
256 DPRINTF(", Z bits : %ld", pf->u1.dwZBufferBitDepth);
258 if (pf->dwFlags & DDPF_ALPHA) {
259 DPRINTF(", Alpha bits : %ld", pf->u1.dwAlphaBitDepth);
261 DPRINTF(")");
264 void DDRAW_dump_colorkeyflag(DWORD ck)
266 static const flag_info flags[] =
268 FE(DDCKEY_COLORSPACE),
269 FE(DDCKEY_DESTBLT),
270 FE(DDCKEY_DESTOVERLAY),
271 FE(DDCKEY_SRCBLT),
272 FE(DDCKEY_SRCOVERLAY)
275 DDRAW_dump_flags(ck, flags, sizeof(flags)/sizeof(flags[0]));
278 static void DDRAW_dump_DWORD(const void *in) {
279 DPRINTF("%ld", *((const DWORD *) in));
281 static void DDRAW_dump_PTR(const void *in) {
282 DPRINTF("%p", *((const void **) in));
284 void DDRAW_dump_DDCOLORKEY(const DDCOLORKEY *ddck) {
285 DPRINTF(" Low : %ld - High : %ld", ddck->dwColorSpaceLowValue, ddck->dwColorSpaceHighValue);
288 void DDRAW_dump_surface_desc(const DDSURFACEDESC2 *lpddsd)
290 #define STRUCT DDSURFACEDESC2
291 static const member_info members[] =
293 ME(DDSD_CAPS, DDRAW_dump_DDSCAPS, ddsCaps),
294 ME(DDSD_HEIGHT, DDRAW_dump_DWORD, dwHeight),
295 ME(DDSD_WIDTH, DDRAW_dump_DWORD, dwWidth),
296 ME(DDSD_PITCH, DDRAW_dump_DWORD, u1.lPitch),
297 ME(DDSD_LINEARSIZE, DDRAW_dump_DWORD, u1.dwLinearSize),
298 ME(DDSD_BACKBUFFERCOUNT, DDRAW_dump_DWORD, dwBackBufferCount),
299 ME(DDSD_MIPMAPCOUNT, DDRAW_dump_DWORD, u2.dwMipMapCount),
300 ME(DDSD_REFRESHRATE, DDRAW_dump_DWORD, u2.dwRefreshRate),
301 ME(DDSD_ALPHABITDEPTH, DDRAW_dump_DWORD, dwAlphaBitDepth),
302 ME(DDSD_LPSURFACE, DDRAW_dump_PTR, lpSurface),
303 ME(DDSD_CKDESTOVERLAY, DDRAW_dump_DDCOLORKEY, u3.ddckCKDestOverlay),
304 ME(DDSD_CKDESTBLT, DDRAW_dump_DDCOLORKEY, ddckCKDestBlt),
305 ME(DDSD_CKSRCOVERLAY, DDRAW_dump_DDCOLORKEY, ddckCKSrcOverlay),
306 ME(DDSD_CKSRCBLT, DDRAW_dump_DDCOLORKEY, ddckCKSrcBlt),
307 ME(DDSD_PIXELFORMAT, DDRAW_dump_pixelformat, u4.ddpfPixelFormat)
310 DDRAW_dump_members(lpddsd->dwFlags, lpddsd, members,
311 sizeof(members)/sizeof(members[0]));
314 void DDRAW_dump_cooperativelevel(DWORD cooplevel)
316 static const flag_info flags[] =
318 FE(DDSCL_FULLSCREEN),
319 FE(DDSCL_ALLOWREBOOT),
320 FE(DDSCL_NOWINDOWCHANGES),
321 FE(DDSCL_NORMAL),
322 FE(DDSCL_ALLOWMODEX),
323 FE(DDSCL_EXCLUSIVE),
324 FE(DDSCL_SETFOCUSWINDOW),
325 FE(DDSCL_SETDEVICEWINDOW),
326 FE(DDSCL_CREATEDEVICEWINDOW)
329 if (TRACE_ON(ddraw))
331 DPRINTF(" - ");
332 DDRAW_dump_flags(cooplevel, flags, sizeof(flags)/sizeof(flags[0]));