kernel32: Do not omit mandatory argument to DeviceIoControl.
[wine.git] / dlls / ddrawex / ddraw.c
blobaf23c89b721e4c34cb1a86d38f0083a10756adbb
1 /*
2 * Copyright 2008 Stefan Dösinger for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
20 #define NONAMELESSUNION
22 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
27 #include "ddraw.h"
28 #include "d3d.h"
30 #include "ddrawex_private.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(ddrawex);
35 static struct ddrawex *impl_from_IDirectDraw(IDirectDraw *iface)
37 return CONTAINING_RECORD(iface, struct ddrawex, IDirectDraw_iface);
40 static struct ddrawex *impl_from_IDirectDraw2(IDirectDraw2 *iface)
42 return CONTAINING_RECORD(iface, struct ddrawex, IDirectDraw2_iface);
45 static struct ddrawex *impl_from_IDirectDraw3(IDirectDraw3 *iface)
47 return CONTAINING_RECORD(iface, struct ddrawex, IDirectDraw3_iface);
50 static struct ddrawex *impl_from_IDirectDraw4(IDirectDraw4 *iface)
52 return CONTAINING_RECORD(iface, struct ddrawex, IDirectDraw4_iface);
55 static HRESULT WINAPI ddrawex4_QueryInterface(IDirectDraw4 *iface, REFIID riid, void **out)
57 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
59 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
61 if (!riid)
63 *out = NULL;
64 return DDERR_INVALIDPARAMS;
67 if (IsEqualGUID(&IID_IDirectDraw4, riid)
68 || IsEqualGUID(&IID_IUnknown, riid))
70 *out = &ddrawex->IDirectDraw4_iface;
72 else if (IsEqualGUID(&IID_IDirectDraw3, riid))
74 *out = &ddrawex->IDirectDraw3_iface;
76 else if (IsEqualGUID(&IID_IDirectDraw2, riid))
78 *out = &ddrawex->IDirectDraw2_iface;
80 else if (IsEqualGUID(&IID_IDirectDraw, riid))
82 *out = &ddrawex->IDirectDraw_iface;
84 else
86 *out = NULL;
87 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
88 return E_NOINTERFACE;
91 IUnknown_AddRef((IUnknown *)*out);
92 return S_OK;
95 static HRESULT WINAPI ddrawex3_QueryInterface(IDirectDraw3 *iface, REFIID riid, void **out)
97 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
99 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
101 return ddrawex4_QueryInterface(&ddrawex->IDirectDraw4_iface, riid, out);
104 static HRESULT WINAPI ddrawex2_QueryInterface(IDirectDraw2 *iface, REFIID riid, void **out)
106 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
108 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
110 return ddrawex4_QueryInterface(&ddrawex->IDirectDraw4_iface, riid, out);
113 static HRESULT WINAPI ddrawex1_QueryInterface(IDirectDraw *iface, REFIID riid, void **out)
115 struct ddrawex *ddrawex = impl_from_IDirectDraw(iface);
117 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
119 return ddrawex4_QueryInterface(&ddrawex->IDirectDraw4_iface, riid, out);
122 static ULONG WINAPI ddrawex4_AddRef(IDirectDraw4 *iface)
124 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
125 ULONG refcount = InterlockedIncrement(&ddrawex->ref);
127 TRACE("%p increasing refcount to %u.\n", iface, refcount);
129 return refcount;
132 static ULONG WINAPI ddrawex3_AddRef(IDirectDraw3 *iface)
134 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
136 TRACE("iface %p.\n", iface);
138 return ddrawex4_AddRef(&ddrawex->IDirectDraw4_iface);
141 static ULONG WINAPI ddrawex2_AddRef(IDirectDraw2 *iface)
143 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
145 TRACE("iface %p.\n", iface);
147 return ddrawex4_AddRef(&ddrawex->IDirectDraw4_iface);
150 static ULONG WINAPI ddrawex1_AddRef(IDirectDraw *iface)
152 struct ddrawex *ddrawex = impl_from_IDirectDraw(iface);
154 TRACE("iface %p.\n", iface);
156 return ddrawex4_AddRef(&ddrawex->IDirectDraw4_iface);
159 static ULONG WINAPI ddrawex4_Release(IDirectDraw4 *iface)
161 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
162 ULONG refcount = InterlockedDecrement(&ddrawex->ref);
164 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
166 if (!refcount)
168 IDirectDraw4_Release(ddrawex->parent);
169 HeapFree(GetProcessHeap(), 0, ddrawex);
172 return refcount;
175 static ULONG WINAPI ddrawex3_Release(IDirectDraw3 *iface)
177 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
179 TRACE("iface %p.\n", iface);
181 return ddrawex4_Release(&ddrawex->IDirectDraw4_iface);
184 static ULONG WINAPI ddrawex2_Release(IDirectDraw2 *iface)
186 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
188 TRACE("iface %p.\n", iface);
190 return ddrawex4_Release(&ddrawex->IDirectDraw4_iface);
193 static ULONG WINAPI ddrawex1_Release(IDirectDraw *iface)
195 struct ddrawex *ddrawex = impl_from_IDirectDraw(iface);
197 TRACE("iface %p.\n", iface);
199 return ddrawex4_Release(&ddrawex->IDirectDraw4_iface);
202 static HRESULT WINAPI ddrawex4_Compact(IDirectDraw4 *iface)
204 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
206 TRACE("iface %p.\n", iface);
208 return IDirectDraw4_Compact(ddrawex->parent);
211 static HRESULT WINAPI ddrawex3_Compact(IDirectDraw3 *iface)
213 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
215 TRACE("iface %p.\n", iface);
217 return ddrawex4_Compact(&ddrawex->IDirectDraw4_iface);
220 static HRESULT WINAPI ddrawex2_Compact(IDirectDraw2 *iface)
222 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
224 TRACE("iface %p.\n", iface);
226 return ddrawex4_Compact(&ddrawex->IDirectDraw4_iface);
229 static HRESULT WINAPI ddrawex1_Compact(IDirectDraw *iface)
231 struct ddrawex *ddrawex = impl_from_IDirectDraw(iface);
233 TRACE("iface %p.\n", iface);
235 return ddrawex4_Compact(&ddrawex->IDirectDraw4_iface);
238 static HRESULT WINAPI ddrawex4_CreateClipper(IDirectDraw4 *iface, DWORD flags,
239 IDirectDrawClipper **clipper, IUnknown *outer_unknown)
241 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
243 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
244 iface, flags, clipper, outer_unknown);
246 /* This may require a wrapper interface for clippers too which handles this. */
247 if (outer_unknown)
248 FIXME("Test and implement aggregation for ddrawex clippers.\n");
250 return IDirectDraw4_CreateClipper(ddrawex->parent, flags, clipper, outer_unknown);
253 static HRESULT WINAPI ddrawex3_CreateClipper(IDirectDraw3 *iface, DWORD flags,
254 IDirectDrawClipper **clipper, IUnknown *outer_unknown)
256 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
258 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
259 iface, flags, clipper, outer_unknown);
261 return ddrawex4_CreateClipper(&ddrawex->IDirectDraw4_iface, flags, clipper, outer_unknown);
264 static HRESULT WINAPI ddrawex2_CreateClipper(IDirectDraw2 *iface, DWORD flags,
265 IDirectDrawClipper **clipper, IUnknown *outer_unknown)
267 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
269 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
270 iface, flags, clipper, outer_unknown);
272 return ddrawex4_CreateClipper(&ddrawex->IDirectDraw4_iface, flags, clipper, outer_unknown);
275 static HRESULT WINAPI ddrawex1_CreateClipper(IDirectDraw *iface, DWORD flags,
276 IDirectDrawClipper **clipper, IUnknown *outer_unknown)
278 struct ddrawex *ddrawex = impl_from_IDirectDraw(iface);
280 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
281 iface, flags, clipper, outer_unknown);
283 return ddrawex4_CreateClipper(&ddrawex->IDirectDraw4_iface, flags, clipper, outer_unknown);
286 static HRESULT WINAPI ddrawex4_CreatePalette(IDirectDraw4 *iface, DWORD flags,
287 PALETTEENTRY *entries, IDirectDrawPalette **palette, IUnknown *outer_unknown)
289 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
291 TRACE("iface %p, flags %#x. entries %p, palette %p, outer_unknown %p.\n",
292 iface, flags, entries, palette, outer_unknown);
294 /* This may require a wrapper interface for palettes too which handles this. */
295 if (outer_unknown)
296 FIXME("Test and implement aggregation for ddrawex palettes.\n");
298 return IDirectDraw4_CreatePalette(ddrawex->parent, flags, entries, palette, outer_unknown);
301 static HRESULT WINAPI ddrawex3_CreatePalette(IDirectDraw3 *iface, DWORD flags,
302 PALETTEENTRY *entries, IDirectDrawPalette **palette, IUnknown *outer_unknown)
304 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
306 TRACE("iface %p, flags %#x. entries %p, palette %p, outer_unknown %p.\n",
307 iface, flags, entries, palette, outer_unknown);
309 return ddrawex4_CreatePalette(&ddrawex->IDirectDraw4_iface, flags, entries, palette, outer_unknown);
312 static HRESULT WINAPI ddrawex2_CreatePalette(IDirectDraw2 *iface, DWORD flags,
313 PALETTEENTRY *entries, IDirectDrawPalette **palette, IUnknown *outer_unknown)
315 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
317 TRACE("iface %p, flags %#x. entries %p, palette %p, outer_unknown %p.\n",
318 iface, flags, entries, palette, outer_unknown);
320 return ddrawex4_CreatePalette(&ddrawex->IDirectDraw4_iface, flags, entries, palette, outer_unknown);
323 static HRESULT WINAPI ddrawex1_CreatePalette(IDirectDraw *iface, DWORD flags,
324 PALETTEENTRY *entries, IDirectDrawPalette **palette, IUnknown *outer_unknown)
326 struct ddrawex *ddrawex = impl_from_IDirectDraw(iface);
328 TRACE("iface %p, flags %#x. entries %p, palette %p, outer_unknown %p.\n",
329 iface, flags, entries, palette, outer_unknown);
331 return ddrawex4_CreatePalette(&ddrawex->IDirectDraw4_iface, flags, entries, palette, outer_unknown);
334 static HRESULT WINAPI ddrawex4_CreateSurface(IDirectDraw4 *iface, DDSURFACEDESC2 *desc,
335 IDirectDrawSurface4 **surface, IUnknown *outer_unknown)
337 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
338 HRESULT hr;
339 const DWORD perm_dc_flags = DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
340 BOOL permanent_dc;
342 TRACE("iface %p, desc %p, surface %p, outer_unknown %p.\n",
343 iface, desc, surface, outer_unknown);
345 /* Handle this in this dll. Don't forward the outer_unknown to ddraw.dll. */
346 if (outer_unknown)
347 FIXME("Implement aggregation for ddrawex surfaces.\n");
349 /* Plain ddraw.dll refuses to create a surface that has both VIDMEM and
350 * SYSMEM flags set. In ddrawex this succeeds, and the GetDC() call
351 * changes the behavior. The DC is permanently valid, and the surface can
352 * be locked between GetDC() and ReleaseDC() calls. GetDC() can be called
353 * more than once too. */
354 if ((desc->ddsCaps.dwCaps & perm_dc_flags) == perm_dc_flags)
356 permanent_dc = TRUE;
357 desc->ddsCaps.dwCaps &= ~DDSCAPS_VIDEOMEMORY;
358 desc->ddsCaps.dwCaps |= DDSCAPS_OWNDC;
360 else
362 permanent_dc = FALSE;
365 hr = IDirectDraw4_CreateSurface(ddrawex->parent, desc, surface, outer_unknown);
366 *surface = dds_get_outer(*surface);
367 if (permanent_dc)
368 prepare_permanent_dc(*surface);
370 return hr;
373 void DDSD_to_DDSD2(const DDSURFACEDESC *in, DDSURFACEDESC2 *out)
375 memset(out, 0, sizeof(*out));
376 out->dwSize = sizeof(*out);
377 out->dwFlags = in->dwFlags;
378 if(in->dwFlags & DDSD_WIDTH) out->dwWidth = in->dwWidth;
379 if(in->dwFlags & DDSD_HEIGHT) out->dwHeight = in->dwHeight;
380 if(in->dwFlags & DDSD_PIXELFORMAT) out->u4.ddpfPixelFormat = in->ddpfPixelFormat;
381 if(in->dwFlags & DDSD_CAPS) out->ddsCaps.dwCaps = in->ddsCaps.dwCaps;
382 if(in->dwFlags & DDSD_PITCH) out->u1.lPitch = in->u1.lPitch;
383 if(in->dwFlags & DDSD_BACKBUFFERCOUNT) out->dwBackBufferCount = in->dwBackBufferCount;
384 if(in->dwFlags & DDSD_ZBUFFERBITDEPTH) out->u2.dwMipMapCount = in->u2.dwZBufferBitDepth; /* same union */
385 if(in->dwFlags & DDSD_ALPHABITDEPTH) out->dwAlphaBitDepth = in->dwAlphaBitDepth;
386 /* DDraw(native, and wine) does not set the DDSD_LPSURFACE, so always copy */
387 out->lpSurface = in->lpSurface;
388 if(in->dwFlags & DDSD_CKDESTOVERLAY) out->u3.ddckCKDestOverlay = in->ddckCKDestOverlay;
389 if(in->dwFlags & DDSD_CKDESTBLT) out->ddckCKDestBlt = in->ddckCKDestBlt;
390 if(in->dwFlags & DDSD_CKSRCOVERLAY) out->ddckCKSrcOverlay = in->ddckCKSrcOverlay;
391 if(in->dwFlags & DDSD_CKSRCBLT) out->ddckCKSrcBlt = in->ddckCKSrcBlt;
392 if(in->dwFlags & DDSD_MIPMAPCOUNT) out->u2.dwMipMapCount = in->u2.dwMipMapCount;
393 if(in->dwFlags & DDSD_REFRESHRATE) out->u2.dwRefreshRate = in->u2.dwRefreshRate;
394 if(in->dwFlags & DDSD_LINEARSIZE) out->u1.dwLinearSize = in->u1.dwLinearSize;
395 /* Does not exist in DDSURFACEDESC:
396 * DDSD_TEXTURESTAGE, DDSD_FVF, DDSD_SRCVBHANDLE,
400 void DDSD2_to_DDSD(const DDSURFACEDESC2 *in, DDSURFACEDESC *out)
402 memset(out, 0, sizeof(*out));
403 out->dwSize = sizeof(*out);
404 out->dwFlags = in->dwFlags;
405 if(in->dwFlags & DDSD_WIDTH) out->dwWidth = in->dwWidth;
406 if(in->dwFlags & DDSD_HEIGHT) out->dwHeight = in->dwHeight;
407 if(in->dwFlags & DDSD_PIXELFORMAT) out->ddpfPixelFormat = in->u4.ddpfPixelFormat;
408 if(in->dwFlags & DDSD_CAPS) out->ddsCaps.dwCaps = in->ddsCaps.dwCaps;
409 if(in->dwFlags & DDSD_PITCH) out->u1.lPitch = in->u1.lPitch;
410 if(in->dwFlags & DDSD_BACKBUFFERCOUNT) out->dwBackBufferCount = in->dwBackBufferCount;
411 if(in->dwFlags & DDSD_ZBUFFERBITDEPTH) out->u2.dwZBufferBitDepth = in->u2.dwMipMapCount; /* same union */
412 if(in->dwFlags & DDSD_ALPHABITDEPTH) out->dwAlphaBitDepth = in->dwAlphaBitDepth;
413 /* DDraw(native, and wine) does not set the DDSD_LPSURFACE, so always copy */
414 out->lpSurface = in->lpSurface;
415 if(in->dwFlags & DDSD_CKDESTOVERLAY) out->ddckCKDestOverlay = in->u3.ddckCKDestOverlay;
416 if(in->dwFlags & DDSD_CKDESTBLT) out->ddckCKDestBlt = in->ddckCKDestBlt;
417 if(in->dwFlags & DDSD_CKSRCOVERLAY) out->ddckCKSrcOverlay = in->ddckCKSrcOverlay;
418 if(in->dwFlags & DDSD_CKSRCBLT) out->ddckCKSrcBlt = in->ddckCKSrcBlt;
419 if(in->dwFlags & DDSD_MIPMAPCOUNT) out->u2.dwMipMapCount = in->u2.dwMipMapCount;
420 if(in->dwFlags & DDSD_REFRESHRATE) out->u2.dwRefreshRate = in->u2.dwRefreshRate;
421 if(in->dwFlags & DDSD_LINEARSIZE) out->u1.dwLinearSize = in->u1.dwLinearSize;
422 /* Does not exist in DDSURFACEDESC:
423 * DDSD_TEXTURESTAGE, DDSD_FVF, DDSD_SRCVBHANDLE,
425 if(in->dwFlags & DDSD_TEXTURESTAGE) WARN("Does not exist in DDSURFACEDESC: DDSD_TEXTURESTAGE\n");
426 if(in->dwFlags & DDSD_FVF) WARN("Does not exist in DDSURFACEDESC: DDSD_FVF\n");
427 if(in->dwFlags & DDSD_SRCVBHANDLE) WARN("Does not exist in DDSURFACEDESC: DDSD_SRCVBHANDLE\n");
428 out->dwFlags &= ~(DDSD_TEXTURESTAGE | DDSD_FVF | DDSD_SRCVBHANDLE);
431 static HRESULT WINAPI ddrawex3_CreateSurface(IDirectDraw3 *iface, DDSURFACEDESC *desc,
432 IDirectDrawSurface **surface, IUnknown *outer_unknown)
434 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
435 DDSURFACEDESC2 ddsd2;
436 IDirectDrawSurface4 *surf4 = NULL;
437 HRESULT hr;
439 TRACE("iface %p, desc %p, surface %p, outer_unknown %p.\n",
440 iface, desc, surface, outer_unknown);
442 DDSD_to_DDSD2(desc, &ddsd2);
443 if (FAILED(hr = ddrawex4_CreateSurface(&ddrawex->IDirectDraw4_iface, &ddsd2, &surf4, outer_unknown)))
445 *surface = NULL;
446 return hr;
449 TRACE("Got surface %p\n", surf4);
450 IDirectDrawSurface4_QueryInterface(surf4, &IID_IDirectDrawSurface, (void **)surface);
451 IDirectDrawSurface4_Release(surf4);
452 return hr;
455 static HRESULT WINAPI ddrawex2_CreateSurface(IDirectDraw2 *iface, DDSURFACEDESC *desc,
456 IDirectDrawSurface **surface, IUnknown *outer_unknown)
458 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
460 TRACE("iface %p, desc %p, surface %p, outer_unknown %p.\n",
461 iface, desc, surface, outer_unknown);
463 return ddrawex3_CreateSurface(&ddrawex->IDirectDraw3_iface, desc, surface, outer_unknown);
466 static HRESULT WINAPI ddrawex1_CreateSurface(IDirectDraw *iface, DDSURFACEDESC *desc,
467 IDirectDrawSurface **surface, IUnknown *outer_unknown)
469 struct ddrawex *ddrawex = impl_from_IDirectDraw(iface);
471 TRACE("iface %p, desc %p, surface %p, outer_unknown %p.\n",
472 iface, desc, surface, outer_unknown);
474 return ddrawex3_CreateSurface(&ddrawex->IDirectDraw3_iface, desc, surface, outer_unknown);
477 static HRESULT WINAPI ddrawex4_DuplicateSurface(IDirectDraw4 *iface,
478 IDirectDrawSurface4 *src, IDirectDrawSurface4 **dst)
480 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
481 struct ddrawex_surface *src_impl = unsafe_impl_from_IDirectDrawSurface4(src);
483 TRACE("iface %p, src %p, dst %p.\n", iface, src, dst);
484 FIXME("Create a wrapper surface.\n");
486 return IDirectDraw4_DuplicateSurface(ddrawex->parent, src_impl ? src_impl->parent : NULL, dst);
489 static HRESULT WINAPI ddrawex3_DuplicateSurface(IDirectDraw3 *iface,
490 IDirectDrawSurface *src, IDirectDrawSurface **dst)
492 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
493 IDirectDrawSurface4 *src_4;
494 IDirectDrawSurface4 *dst_4;
495 HRESULT hr;
497 TRACE("iface %p, src %p, dst %p.\n", iface, src, dst);
499 IDirectDrawSurface_QueryInterface(src, &IID_IDirectDrawSurface4, (void **)&src_4);
500 hr = ddrawex4_DuplicateSurface(&ddrawex->IDirectDraw4_iface, src_4, &dst_4);
501 IDirectDrawSurface4_Release(src_4);
502 if (FAILED(hr))
504 *dst = NULL;
505 return hr;
508 IDirectDrawSurface4_QueryInterface(dst_4, &IID_IDirectDrawSurface, (void **)dst);
509 IDirectDrawSurface4_Release(dst_4);
511 return hr;
514 static HRESULT WINAPI ddrawex2_DuplicateSurface(IDirectDraw2 *iface,
515 IDirectDrawSurface *src, IDirectDrawSurface **dst)
517 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
519 TRACE("iface %p, src %p, dst %p.\n", iface, src, dst);
521 return ddrawex3_DuplicateSurface(&ddrawex->IDirectDraw3_iface, src, dst);
524 static HRESULT WINAPI ddrawex1_DuplicateSurface(IDirectDraw *iface,
525 IDirectDrawSurface *src, IDirectDrawSurface **dst)
527 struct ddrawex *ddrawex = impl_from_IDirectDraw(iface);
529 TRACE("iface %p, src %p, dst %p.\n", iface, src, dst);
531 return ddrawex3_DuplicateSurface(&ddrawex->IDirectDraw3_iface, src, dst);
534 static HRESULT WINAPI ddrawex4_EnumDisplayModes(IDirectDraw4 *iface, DWORD flags,
535 DDSURFACEDESC2 *desc, void *ctx, LPDDENUMMODESCALLBACK2 cb)
537 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
539 TRACE("iface %p, flags %#x, desc %p, ctx %p, cb %p.\n", iface, flags, desc, ctx, cb);
541 return IDirectDraw4_EnumDisplayModes(ddrawex->parent, flags, desc, ctx, cb);
544 struct enummodes_ctx
546 LPDDENUMMODESCALLBACK orig_cb;
547 void *orig_ctx;
550 static HRESULT WINAPI
551 enum_modes_cb2(DDSURFACEDESC2 *ddsd2, void *vctx)
553 struct enummodes_ctx *ctx = vctx;
554 DDSURFACEDESC ddsd;
556 DDSD2_to_DDSD(ddsd2, &ddsd);
557 return ctx->orig_cb(&ddsd, ctx->orig_ctx);
560 static HRESULT WINAPI ddrawex3_EnumDisplayModes(IDirectDraw3 *iface, DWORD flags,
561 DDSURFACEDESC *desc, void *ctx, LPDDENUMMODESCALLBACK cb)
563 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
564 struct enummodes_ctx cb_ctx;
565 DDSURFACEDESC2 ddsd2;
567 TRACE("iface %p, flags %#x, desc %p, ctx %p, cb %p.\n", iface, flags, desc, ctx, cb);
569 DDSD_to_DDSD2(desc, &ddsd2);
570 cb_ctx.orig_cb = cb;
571 cb_ctx.orig_ctx = ctx;
572 return ddrawex4_EnumDisplayModes(&ddrawex->IDirectDraw4_iface, flags, &ddsd2, &cb_ctx, enum_modes_cb2);
575 static HRESULT WINAPI ddrawex2_EnumDisplayModes(IDirectDraw2 *iface, DWORD flags,
576 DDSURFACEDESC *desc, void *ctx, LPDDENUMMODESCALLBACK cb)
578 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
580 TRACE("iface %p, flags %#x, desc %p, ctx %p, cb %p.\n", iface, flags, desc, ctx, cb);
582 return ddrawex3_EnumDisplayModes(&ddrawex->IDirectDraw3_iface, flags, desc, ctx, cb);
585 static HRESULT WINAPI ddrawex1_EnumDisplayModes(IDirectDraw *iface, DWORD flags,
586 DDSURFACEDESC *desc, void *ctx, LPDDENUMMODESCALLBACK cb)
588 struct ddrawex *ddrawex = impl_from_IDirectDraw(iface);
590 TRACE("iface %p, flags %#x, desc %p, ctx %p, cb %p.\n", iface, flags, desc, ctx, cb);
592 return ddrawex3_EnumDisplayModes(&ddrawex->IDirectDraw3_iface, flags, desc, ctx, cb);
595 struct enumsurfaces4_ctx
597 LPDDENUMSURFACESCALLBACK2 orig_cb;
598 void *orig_ctx;
601 static HRESULT WINAPI
602 enum_surfaces_wrapper(IDirectDrawSurface4 *surf4, DDSURFACEDESC2 *ddsd2, void *vctx)
604 struct enumsurfaces4_ctx *ctx = vctx;
605 IDirectDrawSurface4 *outer = dds_get_outer(surf4);
606 IDirectDrawSurface4_AddRef(outer);
607 IDirectDrawSurface4_Release(surf4);
608 TRACE("Returning wrapper surface %p for enumerated inner surface %p\n", outer, surf4);
609 return ctx->orig_cb(outer, ddsd2, ctx->orig_ctx);
612 static HRESULT WINAPI ddrawex4_EnumSurfaces(IDirectDraw4 *iface, DWORD flags,
613 DDSURFACEDESC2 *desc, void *ctx, LPDDENUMSURFACESCALLBACK2 cb)
615 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
616 struct enumsurfaces4_ctx cb_ctx;
618 TRACE("iface %p, flags %#x, desc %p, ctx %p, cb %p.\n", iface, flags, desc, ctx, cb);
620 cb_ctx.orig_cb = cb;
621 cb_ctx.orig_ctx = ctx;
622 return IDirectDraw4_EnumSurfaces(ddrawex->parent, flags, desc, &cb_ctx, enum_surfaces_wrapper);
625 struct enumsurfaces_ctx
627 LPDDENUMSURFACESCALLBACK orig_cb;
628 void *orig_ctx;
631 static HRESULT WINAPI
632 enum_surfaces_cb2(IDirectDrawSurface4 *surf4, DDSURFACEDESC2 *ddsd2, void *vctx)
634 struct enumsurfaces_ctx *ctx = vctx;
635 IDirectDrawSurface *surf1;
636 DDSURFACEDESC ddsd;
638 /* Keep the reference, it goes to the application */
639 IDirectDrawSurface4_QueryInterface(surf4, &IID_IDirectDrawSurface, (void **) &surf1);
640 /* Release the reference this function got */
641 IDirectDrawSurface4_Release(surf4);
643 DDSD2_to_DDSD(ddsd2, &ddsd);
644 return ctx->orig_cb(surf1, &ddsd, ctx->orig_ctx);
647 static HRESULT WINAPI ddrawex3_EnumSurfaces(IDirectDraw3 *iface, DWORD flags,
648 DDSURFACEDESC *desc, void *ctx, LPDDENUMSURFACESCALLBACK cb)
650 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
651 DDSURFACEDESC2 ddsd2;
652 struct enumsurfaces_ctx cb_ctx;
654 TRACE("iface %p, flags %#x, desc %p, ctx %p, cb %p.\n", iface, flags, desc, ctx, cb);
656 DDSD_to_DDSD2(desc, &ddsd2);
657 cb_ctx.orig_cb = cb;
658 cb_ctx.orig_ctx = ctx;
659 return ddrawex4_EnumSurfaces(&ddrawex->IDirectDraw4_iface, flags, &ddsd2, &cb_ctx, enum_surfaces_cb2);
662 static HRESULT WINAPI ddrawex2_EnumSurfaces(IDirectDraw2 *iface, DWORD flags,
663 DDSURFACEDESC *desc, void *ctx, LPDDENUMSURFACESCALLBACK cb)
665 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
667 TRACE("iface %p, flags %#x, desc %p, ctx %p, cb %p.\n", iface, flags, desc, ctx, cb);
669 return ddrawex3_EnumSurfaces(&ddrawex->IDirectDraw3_iface, flags, desc, ctx, cb);
672 static HRESULT WINAPI ddrawex1_EnumSurfaces(IDirectDraw *iface, DWORD flags,
673 DDSURFACEDESC *desc, void *ctx, LPDDENUMSURFACESCALLBACK cb)
675 struct ddrawex *ddrawex = impl_from_IDirectDraw(iface);
677 TRACE("iface %p, flags %#x, desc %p, ctx %p, cb %p.\n", iface, flags, desc, ctx, cb);
679 return ddrawex3_EnumSurfaces(&ddrawex->IDirectDraw3_iface, flags, desc, ctx, cb);
682 static HRESULT WINAPI ddrawex4_FlipToGDISurface(IDirectDraw4 *iface)
684 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
686 TRACE("iface %p.\n", iface);
688 return IDirectDraw4_FlipToGDISurface(ddrawex->parent);
691 static HRESULT WINAPI ddrawex3_FlipToGDISurface(IDirectDraw3 *iface)
693 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
695 TRACE("iface %p.\n", iface);
697 return ddrawex4_FlipToGDISurface(&ddrawex->IDirectDraw4_iface);
700 static HRESULT WINAPI ddrawex2_FlipToGDISurface(IDirectDraw2 *iface)
702 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
704 TRACE("iface %p.\n", iface);
706 return ddrawex4_FlipToGDISurface(&ddrawex->IDirectDraw4_iface);
709 static HRESULT WINAPI ddrawex1_FlipToGDISurface(IDirectDraw *iface)
711 struct ddrawex *ddrawex = impl_from_IDirectDraw(iface);
713 TRACE("iface %p.\n", iface);
715 return ddrawex4_FlipToGDISurface(&ddrawex->IDirectDraw4_iface);
718 static HRESULT WINAPI ddrawex4_GetCaps(IDirectDraw4 *iface, DDCAPS *driver_caps, DDCAPS *hel_caps)
720 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
722 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface, driver_caps, hel_caps);
724 return IDirectDraw4_GetCaps(ddrawex->parent, driver_caps, hel_caps);
727 static HRESULT WINAPI ddrawex3_GetCaps(IDirectDraw3 *iface, DDCAPS *driver_caps, DDCAPS *hel_caps)
729 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
731 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface, driver_caps, hel_caps);
733 return ddrawex4_GetCaps(&ddrawex->IDirectDraw4_iface, driver_caps, hel_caps);
736 static HRESULT WINAPI ddrawex2_GetCaps(IDirectDraw2 *iface, DDCAPS *driver_caps, DDCAPS *hel_caps)
738 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
740 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface, driver_caps, hel_caps);
742 return ddrawex4_GetCaps(&ddrawex->IDirectDraw4_iface, driver_caps, hel_caps);
745 static HRESULT WINAPI ddrawex1_GetCaps(IDirectDraw *iface, DDCAPS *driver_caps, DDCAPS *hel_caps)
747 struct ddrawex *ddrawex = impl_from_IDirectDraw(iface);
749 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface, driver_caps, hel_caps);
751 return ddrawex4_GetCaps(&ddrawex->IDirectDraw4_iface, driver_caps, hel_caps);
754 static HRESULT WINAPI ddrawex4_GetDisplayMode(IDirectDraw4 *iface, DDSURFACEDESC2 *desc)
756 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
758 TRACE("iface %p, desc %p.\n", iface, desc);
760 return IDirectDraw4_GetDisplayMode(ddrawex->parent, desc);
763 static HRESULT WINAPI ddrawex3_GetDisplayMode(IDirectDraw3 *iface, DDSURFACEDESC *desc)
765 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
766 DDSURFACEDESC2 ddsd2;
767 HRESULT hr;
769 TRACE("iface %p, desc %p.\n", iface, desc);
771 hr = ddrawex4_GetDisplayMode(&ddrawex->IDirectDraw4_iface, &ddsd2);
772 DDSD2_to_DDSD(&ddsd2, desc);
774 return hr;
777 static HRESULT WINAPI ddrawex2_GetDisplayMode(IDirectDraw2 *iface, DDSURFACEDESC *desc)
779 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
781 TRACE("iface %p, desc %p.\n", iface, desc);
783 return ddrawex3_GetDisplayMode(&ddrawex->IDirectDraw3_iface, desc);
786 static HRESULT WINAPI ddrawex1_GetDisplayMode(IDirectDraw *iface, DDSURFACEDESC *desc)
788 struct ddrawex *ddrawex = impl_from_IDirectDraw(iface);
790 TRACE("iface %p, desc %p.\n", iface, desc);
792 return ddrawex3_GetDisplayMode(&ddrawex->IDirectDraw3_iface, desc);
795 static HRESULT WINAPI ddrawex4_GetFourCCCodes(IDirectDraw4 *iface, DWORD *code_count, DWORD *codes)
797 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
799 TRACE("iface %p, code_count %p, codes %p.\n", iface, code_count, codes);
801 return IDirectDraw4_GetFourCCCodes(ddrawex->parent, code_count, codes);
804 static HRESULT WINAPI ddrawex3_GetFourCCCodes(IDirectDraw3 *iface, DWORD *code_count, DWORD *codes)
806 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
808 TRACE("iface %p, code_count %p, codes %p.\n", iface, code_count, codes);
810 return ddrawex4_GetFourCCCodes(&ddrawex->IDirectDraw4_iface, code_count, codes);
813 static HRESULT WINAPI ddrawex2_GetFourCCCodes(IDirectDraw2 *iface, DWORD *code_count, DWORD *codes)
815 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
817 TRACE("iface %p, code_count %p, codes %p.\n", iface, code_count, codes);
819 return ddrawex4_GetFourCCCodes(&ddrawex->IDirectDraw4_iface, code_count, codes);
822 static HRESULT WINAPI ddrawex1_GetFourCCCodes(IDirectDraw *iface, DWORD *code_count, DWORD *codes)
824 struct ddrawex *ddrawex = impl_from_IDirectDraw(iface);
826 TRACE("iface %p, code_count %p, codes %p.\n", iface, code_count, codes);
828 return ddrawex4_GetFourCCCodes(&ddrawex->IDirectDraw4_iface, code_count, codes);
831 static HRESULT WINAPI ddrawex4_GetGDISurface(IDirectDraw4 *iface, IDirectDrawSurface4 **gdi_surface)
833 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
834 IDirectDrawSurface4 *inner = NULL;
835 HRESULT hr;
837 TRACE("iface %p, gdi_surface %p.\n", iface, gdi_surface);
839 if (FAILED(hr = IDirectDraw4_GetGDISurface(ddrawex->parent, &inner)))
841 *gdi_surface = NULL;
842 return hr;
845 *gdi_surface = dds_get_outer(inner);
846 IDirectDrawSurface4_AddRef(*gdi_surface);
847 IDirectDrawSurface4_Release(inner);
848 return hr;
851 static HRESULT WINAPI ddrawex3_GetGDISurface(IDirectDraw3 *iface, IDirectDrawSurface **gdi_surface)
853 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
854 IDirectDrawSurface4 *surf4;
855 HRESULT hr;
857 TRACE("iface %p, gdi_surface %p.\n", iface, gdi_surface);
859 if (FAILED(hr = ddrawex4_GetGDISurface(&ddrawex->IDirectDraw4_iface, &surf4)))
861 *gdi_surface = NULL;
862 return hr;
865 IDirectDrawSurface4_QueryInterface(surf4, &IID_IDirectDrawSurface, (void **)gdi_surface);
866 IDirectDrawSurface4_Release(surf4);
867 return hr;
870 static HRESULT WINAPI ddrawex2_GetGDISurface(IDirectDraw2 *iface, IDirectDrawSurface **gdi_surface)
872 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
874 TRACE("iface %p, gdi_surface %p.\n", iface, gdi_surface);
876 return ddrawex3_GetGDISurface(&ddrawex->IDirectDraw3_iface, gdi_surface);
879 static HRESULT WINAPI ddrawex1_GetGDISurface(IDirectDraw *iface, IDirectDrawSurface **gdi_surface)
881 struct ddrawex *ddrawex = impl_from_IDirectDraw(iface);
883 TRACE("iface %p, gdi_surface %p.\n", iface, gdi_surface);
885 return ddrawex3_GetGDISurface(&ddrawex->IDirectDraw3_iface, gdi_surface);
888 static HRESULT WINAPI ddrawex4_GetMonitorFrequency(IDirectDraw4 *iface, DWORD *frequency)
890 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
892 TRACE("iface %p, frequency %p.\n", iface, frequency);
894 return IDirectDraw4_GetMonitorFrequency(ddrawex->parent, frequency);
897 static HRESULT WINAPI ddrawex3_GetMonitorFrequency(IDirectDraw3 *iface, DWORD *frequency)
899 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
901 TRACE("iface %p, frequency %p.\n", iface, frequency);
903 return ddrawex4_GetMonitorFrequency(&ddrawex->IDirectDraw4_iface, frequency);
906 static HRESULT WINAPI ddrawex2_GetMonitorFrequency(IDirectDraw2 *iface, DWORD *frequency)
908 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
910 TRACE("iface %p, frequency %p.\n", iface, frequency);
912 return ddrawex4_GetMonitorFrequency(&ddrawex->IDirectDraw4_iface, frequency);
915 static HRESULT WINAPI ddrawex1_GetMonitorFrequency(IDirectDraw *iface, DWORD *frequency)
917 struct ddrawex *ddrawex = impl_from_IDirectDraw(iface);
919 TRACE("iface %p, frequency %p.\n", iface, frequency);
921 return ddrawex4_GetMonitorFrequency(&ddrawex->IDirectDraw4_iface, frequency);
924 static HRESULT WINAPI ddrawex4_GetScanLine(IDirectDraw4 *iface, DWORD *line)
926 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
928 TRACE("iface %p, line %p.\n", iface, line);
930 return IDirectDraw4_GetScanLine(ddrawex->parent, line);
933 static HRESULT WINAPI ddrawex3_GetScanLine(IDirectDraw3 *iface, DWORD *line)
935 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
937 TRACE("iface %p, line %p.\n", iface, line);
939 return ddrawex4_GetScanLine(&ddrawex->IDirectDraw4_iface, line);
942 static HRESULT WINAPI ddrawex2_GetScanLine(IDirectDraw2 *iface, DWORD *line)
944 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
946 TRACE("iface %p, line %p.\n", iface, line);
948 return ddrawex4_GetScanLine(&ddrawex->IDirectDraw4_iface, line);
951 static HRESULT WINAPI ddrawex1_GetScanLine(IDirectDraw *iface, DWORD *line)
953 struct ddrawex *ddrawex = impl_from_IDirectDraw(iface);
955 TRACE("iface %p, line %p.\n", iface, line);
957 return ddrawex4_GetScanLine(&ddrawex->IDirectDraw4_iface, line);
960 static HRESULT WINAPI ddrawex4_GetVerticalBlankStatus(IDirectDraw4 *iface, BOOL *status)
962 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
964 TRACE("iface %p, status %p.\n", iface, status);
966 return IDirectDraw4_GetVerticalBlankStatus(ddrawex->parent, status);
969 static HRESULT WINAPI ddrawex3_GetVerticalBlankStatus(IDirectDraw3 *iface, BOOL *status)
971 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
973 TRACE("iface %p, status %p.\n", iface, status);
975 return ddrawex4_GetVerticalBlankStatus(&ddrawex->IDirectDraw4_iface, status);
978 static HRESULT WINAPI ddrawex2_GetVerticalBlankStatus(IDirectDraw2 *iface, BOOL *status)
980 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
982 TRACE("iface %p, status %p.\n", iface, status);
984 return ddrawex4_GetVerticalBlankStatus(&ddrawex->IDirectDraw4_iface, status);
987 static HRESULT WINAPI ddrawex1_GetVerticalBlankStatus(IDirectDraw *iface, BOOL *status)
989 struct ddrawex *ddrawex = impl_from_IDirectDraw(iface);
991 TRACE("iface %p, status %p.\n", iface, status);
993 return ddrawex4_GetVerticalBlankStatus(&ddrawex->IDirectDraw4_iface, status);
996 static HRESULT WINAPI ddrawex4_Initialize(IDirectDraw4 *iface, GUID *guid)
998 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
1000 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
1002 return IDirectDraw4_Initialize(ddrawex->parent, guid);
1005 static HRESULT WINAPI ddrawex3_Initialize(IDirectDraw3 *iface, GUID *guid)
1007 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
1009 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
1011 return ddrawex4_Initialize(&ddrawex->IDirectDraw4_iface, guid);
1014 static HRESULT WINAPI ddrawex2_Initialize(IDirectDraw2 *iface, GUID *guid)
1016 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
1018 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
1020 return ddrawex4_Initialize(&ddrawex->IDirectDraw4_iface, guid);
1023 static HRESULT WINAPI ddrawex1_Initialize(IDirectDraw *iface, GUID *guid)
1025 struct ddrawex *ddrawex = impl_from_IDirectDraw(iface);
1027 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
1029 return ddrawex4_Initialize(&ddrawex->IDirectDraw4_iface, guid);
1032 static HRESULT WINAPI ddrawex4_RestoreDisplayMode(IDirectDraw4 *iface)
1034 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
1036 TRACE("iface %p.\n", iface);
1038 return IDirectDraw4_RestoreDisplayMode(ddrawex->parent);
1041 static HRESULT WINAPI ddrawex3_RestoreDisplayMode(IDirectDraw3 *iface)
1043 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
1045 TRACE("iface %p.\n", iface);
1047 return ddrawex4_RestoreDisplayMode(&ddrawex->IDirectDraw4_iface);
1050 static HRESULT WINAPI ddrawex2_RestoreDisplayMode(IDirectDraw2 *iface)
1052 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
1054 TRACE("iface %p.\n", iface);
1056 return ddrawex4_RestoreDisplayMode(&ddrawex->IDirectDraw4_iface);
1059 static HRESULT WINAPI ddrawex1_RestoreDisplayMode(IDirectDraw *iface)
1061 struct ddrawex *ddrawex = impl_from_IDirectDraw(iface);
1063 TRACE("iface %p.\n", iface);
1065 return ddrawex4_RestoreDisplayMode(&ddrawex->IDirectDraw4_iface);
1068 static HRESULT WINAPI ddrawex4_SetCooperativeLevel(IDirectDraw4 *iface, HWND window, DWORD flags)
1070 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
1072 TRACE("iface %p, window %p, flags %#x.\n", iface, window, flags);
1074 return IDirectDraw4_SetCooperativeLevel(ddrawex->parent, window, flags);
1077 static HRESULT WINAPI ddrawex3_SetCooperativeLevel(IDirectDraw3 *iface, HWND window, DWORD flags)
1079 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
1081 TRACE("iface %p, window %p, flags %#x.\n", iface, window, flags);
1083 return ddrawex4_SetCooperativeLevel(&ddrawex->IDirectDraw4_iface, window, flags);
1086 static HRESULT WINAPI ddrawex2_SetCooperativeLevel(IDirectDraw2 *iface, HWND window, DWORD flags)
1088 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
1090 TRACE("iface %p, window %p, flags %#x.\n", iface, window, flags);
1092 return ddrawex4_SetCooperativeLevel(&ddrawex->IDirectDraw4_iface, window, flags);
1095 static HRESULT WINAPI ddrawex1_SetCooperativeLevel(IDirectDraw *iface, HWND window, DWORD flags)
1097 struct ddrawex *ddrawex = impl_from_IDirectDraw(iface);
1099 TRACE("iface %p, window %p, flags %#x.\n", iface, window, flags);
1101 return ddrawex4_SetCooperativeLevel(&ddrawex->IDirectDraw4_iface, window, flags);
1104 static HRESULT WINAPI ddrawex4_SetDisplayMode(IDirectDraw4 *iface, DWORD width,
1105 DWORD height, DWORD bpp, DWORD refresh_rate, DWORD flags)
1107 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
1109 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1110 iface, width, height, bpp, refresh_rate, flags);
1112 return IDirectDraw4_SetDisplayMode(ddrawex->parent, width, height, bpp, refresh_rate, flags);
1115 static HRESULT WINAPI ddrawex3_SetDisplayMode(IDirectDraw3 *iface, DWORD width,
1116 DWORD height, DWORD bpp, DWORD refresh_rate, DWORD flags)
1118 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
1120 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1121 iface, width, height, bpp, refresh_rate, flags);
1123 return ddrawex4_SetDisplayMode(&ddrawex->IDirectDraw4_iface, width, height, bpp, refresh_rate, flags);
1126 static HRESULT WINAPI ddrawex2_SetDisplayMode(IDirectDraw2 *iface, DWORD width,
1127 DWORD height, DWORD bpp, DWORD refresh_rate, DWORD flags)
1129 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
1131 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1132 iface, width, height, bpp, refresh_rate, flags);
1134 return ddrawex4_SetDisplayMode(&ddrawex->IDirectDraw4_iface, width, height, bpp, refresh_rate, flags);
1137 static HRESULT WINAPI ddrawex1_SetDisplayMode(IDirectDraw *iface, DWORD width,
1138 DWORD height, DWORD bpp)
1140 struct ddrawex *ddrawex = impl_from_IDirectDraw(iface);
1142 TRACE("iface %p, width %u, height %u, bpp %u.\n", iface, width, height, bpp);
1144 return ddrawex4_SetDisplayMode(&ddrawex->IDirectDraw4_iface, width, height, bpp, 0, 0);
1147 static HRESULT WINAPI ddrawex4_WaitForVerticalBlank(IDirectDraw4 *iface, DWORD flags, HANDLE event)
1149 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
1151 TRACE("iface %p, flags %#x, event %p.\n", iface, flags, event);
1153 return IDirectDraw4_WaitForVerticalBlank(ddrawex->parent, flags, event);
1156 static HRESULT WINAPI ddrawex3_WaitForVerticalBlank(IDirectDraw3 *iface, DWORD flags, HANDLE event)
1158 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
1160 TRACE("iface %p, flags %#x, event %p.\n", iface, flags, event);
1162 return ddrawex4_WaitForVerticalBlank(&ddrawex->IDirectDraw4_iface, flags, event);
1165 static HRESULT WINAPI ddrawex2_WaitForVerticalBlank(IDirectDraw2 *iface, DWORD flags, HANDLE event)
1167 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
1169 TRACE("iface %p, flags %#x, event %p.\n", iface, flags, event);
1171 return ddrawex4_WaitForVerticalBlank(&ddrawex->IDirectDraw4_iface, flags, event);
1174 static HRESULT WINAPI ddrawex1_WaitForVerticalBlank(IDirectDraw *iface, DWORD flags, HANDLE event)
1176 struct ddrawex *ddrawex = impl_from_IDirectDraw(iface);
1178 TRACE("iface %p, flags %#x, event %p.\n", iface, flags, event);
1180 return ddrawex4_WaitForVerticalBlank(&ddrawex->IDirectDraw4_iface, flags, event);
1183 static HRESULT WINAPI ddrawex4_GetAvailableVidMem(IDirectDraw4 *iface,
1184 DDSCAPS2 *caps, DWORD *total, DWORD *free)
1186 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
1188 TRACE("iface %p, caps %p, total %p, free %p.\n", iface, caps, total, free);
1190 return IDirectDraw4_GetAvailableVidMem(ddrawex->parent, caps, total, free);
1193 static HRESULT WINAPI ddrawex3_GetAvailableVidMem(IDirectDraw3 *iface,
1194 DDSCAPS *caps, DWORD *total, DWORD *free)
1196 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
1197 DDSCAPS2 caps2;
1199 TRACE("iface %p, caps %p, total %p, free %p.\n", iface, caps, total, free);
1201 memset(&caps2, 0, sizeof(caps2));
1202 caps2.dwCaps = caps->dwCaps;
1203 return ddrawex4_GetAvailableVidMem(&ddrawex->IDirectDraw4_iface, &caps2, total, free);
1206 static HRESULT WINAPI ddrawex2_GetAvailableVidMem(IDirectDraw2 *iface,
1207 DDSCAPS *caps, DWORD *total, DWORD *free)
1209 struct ddrawex *ddrawex = impl_from_IDirectDraw2(iface);
1210 DDSCAPS2 caps2;
1212 TRACE("iface %p, caps %p, total %p, free %p.\n", iface, caps, total, free);
1214 memset(&caps2, 0, sizeof(caps2));
1215 caps2.dwCaps = caps->dwCaps;
1216 return ddrawex4_GetAvailableVidMem(&ddrawex->IDirectDraw4_iface, &caps2, total, free);
1219 static HRESULT WINAPI ddrawex4_GetSurfaceFromDC(IDirectDraw4 *iface,
1220 HDC dc, IDirectDrawSurface4 **surface)
1222 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
1224 TRACE("iface %p, dc %p, surface %p.\n", iface, dc, surface);
1226 return IDirectDraw4_GetSurfaceFromDC(ddrawex->parent, dc, surface);
1229 static HRESULT WINAPI ddrawex3_GetSurfaceFromDC(IDirectDraw3 *iface,
1230 HDC dc, IDirectDrawSurface **surface)
1232 struct ddrawex *ddrawex = impl_from_IDirectDraw3(iface);
1233 IDirectDrawSurface4 *surf4, *outer;
1234 IDirectDrawSurface *inner;
1235 HRESULT hr;
1237 TRACE("iface %p, dc %p, surface %p.\n", iface, dc, surface);
1239 if (!surface)
1240 return E_POINTER;
1242 if (FAILED(hr = IDirectDraw4_GetSurfaceFromDC(ddrawex->parent, dc, (IDirectDrawSurface4 **)&inner)))
1244 *surface = NULL;
1245 return hr;
1248 hr = IDirectDrawSurface_QueryInterface(inner, &IID_IDirectDrawSurface4, (void **)&surf4);
1249 IDirectDrawSurface_Release(inner);
1250 if (FAILED(hr))
1252 *surface = NULL;
1253 return hr;
1256 outer = dds_get_outer(surf4);
1257 hr = IDirectDrawSurface4_QueryInterface(outer, &IID_IDirectDrawSurface, (void **)surface);
1258 IDirectDrawSurface4_Release(surf4);
1259 return hr;
1262 static HRESULT WINAPI ddrawex4_RestoreAllSurfaces(IDirectDraw4 *iface)
1264 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
1266 TRACE("iface %p.\n", iface);
1268 return IDirectDraw4_RestoreAllSurfaces(ddrawex->parent);
1271 static HRESULT WINAPI ddrawex4_TestCooperativeLevel(IDirectDraw4 *iface)
1273 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
1275 TRACE("iface %p.\n", iface);
1277 return IDirectDraw4_TestCooperativeLevel(ddrawex->parent);
1280 static HRESULT WINAPI ddrawex4_GetDeviceIdentifier(IDirectDraw4 *iface,
1281 DDDEVICEIDENTIFIER *identifier, DWORD flags)
1283 struct ddrawex *ddrawex = impl_from_IDirectDraw4(iface);
1285 TRACE("iface %p, identifier %p, flags %#x.\n", iface, identifier, flags);
1287 return IDirectDraw4_GetDeviceIdentifier(ddrawex->parent, identifier, flags);
1290 static const IDirectDraw4Vtbl ddrawex4_vtbl =
1292 ddrawex4_QueryInterface,
1293 ddrawex4_AddRef,
1294 ddrawex4_Release,
1295 ddrawex4_Compact,
1296 ddrawex4_CreateClipper,
1297 ddrawex4_CreatePalette,
1298 ddrawex4_CreateSurface,
1299 ddrawex4_DuplicateSurface,
1300 ddrawex4_EnumDisplayModes,
1301 ddrawex4_EnumSurfaces,
1302 ddrawex4_FlipToGDISurface,
1303 ddrawex4_GetCaps,
1304 ddrawex4_GetDisplayMode,
1305 ddrawex4_GetFourCCCodes,
1306 ddrawex4_GetGDISurface,
1307 ddrawex4_GetMonitorFrequency,
1308 ddrawex4_GetScanLine,
1309 ddrawex4_GetVerticalBlankStatus,
1310 ddrawex4_Initialize,
1311 ddrawex4_RestoreDisplayMode,
1312 ddrawex4_SetCooperativeLevel,
1313 ddrawex4_SetDisplayMode,
1314 ddrawex4_WaitForVerticalBlank,
1315 ddrawex4_GetAvailableVidMem,
1316 ddrawex4_GetSurfaceFromDC,
1317 ddrawex4_RestoreAllSurfaces,
1318 ddrawex4_TestCooperativeLevel,
1319 ddrawex4_GetDeviceIdentifier,
1322 static const IDirectDraw3Vtbl ddrawex3_vtbl =
1324 ddrawex3_QueryInterface,
1325 ddrawex3_AddRef,
1326 ddrawex3_Release,
1327 ddrawex3_Compact,
1328 ddrawex3_CreateClipper,
1329 ddrawex3_CreatePalette,
1330 ddrawex3_CreateSurface,
1331 ddrawex3_DuplicateSurface,
1332 ddrawex3_EnumDisplayModes,
1333 ddrawex3_EnumSurfaces,
1334 ddrawex3_FlipToGDISurface,
1335 ddrawex3_GetCaps,
1336 ddrawex3_GetDisplayMode,
1337 ddrawex3_GetFourCCCodes,
1338 ddrawex3_GetGDISurface,
1339 ddrawex3_GetMonitorFrequency,
1340 ddrawex3_GetScanLine,
1341 ddrawex3_GetVerticalBlankStatus,
1342 ddrawex3_Initialize,
1343 ddrawex3_RestoreDisplayMode,
1344 ddrawex3_SetCooperativeLevel,
1345 ddrawex3_SetDisplayMode,
1346 ddrawex3_WaitForVerticalBlank,
1347 ddrawex3_GetAvailableVidMem,
1348 ddrawex3_GetSurfaceFromDC,
1351 static const IDirectDraw2Vtbl ddrawex2_vtbl =
1353 ddrawex2_QueryInterface,
1354 ddrawex2_AddRef,
1355 ddrawex2_Release,
1356 ddrawex2_Compact,
1357 ddrawex2_CreateClipper,
1358 ddrawex2_CreatePalette,
1359 ddrawex2_CreateSurface,
1360 ddrawex2_DuplicateSurface,
1361 ddrawex2_EnumDisplayModes,
1362 ddrawex2_EnumSurfaces,
1363 ddrawex2_FlipToGDISurface,
1364 ddrawex2_GetCaps,
1365 ddrawex2_GetDisplayMode,
1366 ddrawex2_GetFourCCCodes,
1367 ddrawex2_GetGDISurface,
1368 ddrawex2_GetMonitorFrequency,
1369 ddrawex2_GetScanLine,
1370 ddrawex2_GetVerticalBlankStatus,
1371 ddrawex2_Initialize,
1372 ddrawex2_RestoreDisplayMode,
1373 ddrawex2_SetCooperativeLevel,
1374 ddrawex2_SetDisplayMode,
1375 ddrawex2_WaitForVerticalBlank,
1376 ddrawex2_GetAvailableVidMem,
1379 static const IDirectDrawVtbl ddrawex1_vtbl =
1381 ddrawex1_QueryInterface,
1382 ddrawex1_AddRef,
1383 ddrawex1_Release,
1384 ddrawex1_Compact,
1385 ddrawex1_CreateClipper,
1386 ddrawex1_CreatePalette,
1387 ddrawex1_CreateSurface,
1388 ddrawex1_DuplicateSurface,
1389 ddrawex1_EnumDisplayModes,
1390 ddrawex1_EnumSurfaces,
1391 ddrawex1_FlipToGDISurface,
1392 ddrawex1_GetCaps,
1393 ddrawex1_GetDisplayMode,
1394 ddrawex1_GetFourCCCodes,
1395 ddrawex1_GetGDISurface,
1396 ddrawex1_GetMonitorFrequency,
1397 ddrawex1_GetScanLine,
1398 ddrawex1_GetVerticalBlankStatus,
1399 ddrawex1_Initialize,
1400 ddrawex1_RestoreDisplayMode,
1401 ddrawex1_SetCooperativeLevel,
1402 ddrawex1_SetDisplayMode,
1403 ddrawex1_WaitForVerticalBlank,
1406 HRESULT WINAPI ddrawex_factory_CreateDirectDraw(IDirectDrawFactory *iface, GUID *guid, HWND window,
1407 DWORD coop_level, DWORD reserved, IUnknown *outer_unknown, IDirectDraw **ddraw)
1409 IDirectDraw *parent = NULL;
1410 struct ddrawex *object;
1411 HRESULT hr;
1413 TRACE("iface %p, guid %s, window %p, coop_level %#x, reserved %#x, outer_unknown %p, ddraw %p.\n",
1414 iface, debugstr_guid(guid), window, coop_level, reserved, outer_unknown, ddraw);
1416 if (outer_unknown)
1417 FIXME("Implement aggregation in ddrawex's IDirectDraw interface.\n");
1419 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1420 return E_OUTOFMEMORY;
1422 object->ref = 1;
1423 object->IDirectDraw_iface.lpVtbl = &ddrawex1_vtbl;
1424 object->IDirectDraw2_iface.lpVtbl = &ddrawex2_vtbl;
1425 object->IDirectDraw3_iface.lpVtbl = &ddrawex3_vtbl;
1426 object->IDirectDraw4_iface.lpVtbl = &ddrawex4_vtbl;
1428 if (FAILED(hr = DirectDrawCreate(guid, &parent, NULL)))
1429 goto err;
1430 if (FAILED(hr = IDirectDraw_QueryInterface(parent, &IID_IDirectDraw4, (void **)&object->parent)))
1431 goto err;
1432 if (FAILED(hr = IDirectDraw_SetCooperativeLevel(&object->IDirectDraw_iface, window, coop_level)))
1433 goto err;
1435 *ddraw = &object->IDirectDraw_iface;
1436 IDirectDraw_Release(parent);
1437 return DD_OK;
1439 err:
1440 if(object && object->parent) IDirectDraw4_Release(object->parent);
1441 if(parent) IDirectDraw_Release(parent);
1442 HeapFree(GetProcessHeap(), 0, object);
1443 *ddraw = NULL;
1444 return hr;
1447 IDirectDraw4 *dd_get_inner(IDirectDraw4 *outer)
1449 struct ddrawex *ddrawex = impl_from_IDirectDraw4(outer);
1451 if (outer->lpVtbl != &ddrawex4_vtbl)
1452 return NULL;
1453 return ddrawex->parent;