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
20 #define NONAMELESSUNION
30 #include "ddrawex_private.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(ddrawex);
35 /******************************************************************************
36 * Helper functions for COM management
37 ******************************************************************************/
38 static IDirectDrawImpl *impl_from_dd1(IDirectDraw *iface)
40 return (IDirectDrawImpl *)((char*)iface - FIELD_OFFSET(IDirectDrawImpl, IDirectDraw_Vtbl));
42 static IDirectDraw *dd1_from_impl(IDirectDrawImpl *This)
44 return (IDirectDraw *) &This->IDirectDraw_Vtbl;
47 static IDirectDrawImpl *impl_from_dd2(IDirectDraw2 *iface)
49 return (IDirectDrawImpl *)((char*)iface - FIELD_OFFSET(IDirectDrawImpl, IDirectDraw2_Vtbl));
51 static IDirectDraw2 *dd2_from_impl(IDirectDrawImpl *This)
53 return (IDirectDraw2 *) &This->IDirectDraw2_Vtbl;
56 static IDirectDrawImpl *impl_from_dd3(IDirectDraw3 *iface)
58 return (IDirectDrawImpl *)((char*)iface - FIELD_OFFSET(IDirectDrawImpl, IDirectDraw3_Vtbl));
60 static IDirectDraw3 *dd3_from_impl(IDirectDrawImpl *This)
62 return (IDirectDraw3 *) &This->IDirectDraw3_Vtbl;
65 static IDirectDrawImpl *impl_from_dd4(IDirectDraw4 *iface)
67 return (IDirectDrawImpl *)((char*)iface - FIELD_OFFSET(IDirectDrawImpl, IDirectDraw4_Vtbl));
69 static IDirectDraw4 *dd4_from_impl(IDirectDrawImpl *This)
71 return (IDirectDraw4 *) &This->IDirectDraw4_Vtbl;
74 /******************************************************************************
75 * IDirectDraw4 -> ddraw.dll wrappers
76 ******************************************************************************/
78 IDirectDraw4Impl_QueryInterface(IDirectDraw4 *iface,
82 IDirectDrawImpl *This = impl_from_dd4(iface);
84 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(refiid), obj);
89 return DDERR_INVALIDPARAMS;
92 if (IsEqualGUID( &IID_IDirectDraw7, refiid ) )
94 WARN("IDirectDraw7 not allowed in ddrawex.dll\n");
97 else if ( IsEqualGUID( &IID_IUnknown, refiid ) ||
98 IsEqualGUID( &IID_IDirectDraw4, refiid ) )
100 *obj = dd4_from_impl(This);
101 TRACE("(%p) Returning IDirectDraw4 interface at %p\n", This, *obj);
102 IDirectDraw4_AddRef((IDirectDraw4 *) *obj);
104 else if ( IsEqualGUID( &IID_IDirectDraw3, refiid ) )
106 *obj = dd3_from_impl(This);
107 TRACE("(%p) Returning IDirectDraw3 interface at %p\n", This, *obj);
108 IDirectDraw3_AddRef((IDirectDraw3 *) *obj);
110 else if ( IsEqualGUID( &IID_IDirectDraw2, refiid ) )
112 *obj = dd2_from_impl(This);
113 TRACE("(%p) Returning IDirectDraw2 interface at %p\n", This, *obj);
114 IDirectDraw2_AddRef((IDirectDraw2 *) *obj);
116 else if ( IsEqualGUID( &IID_IDirectDraw, refiid ) )
118 *obj = dd1_from_impl(This);
119 TRACE("(%p) Returning IDirectDraw interface at %p\n", This, *obj);
120 IDirectDraw_AddRef((IDirectDraw *) *obj);
122 else if ( IsEqualGUID( &IID_IDirect3D , refiid ) ||
123 IsEqualGUID( &IID_IDirect3D2 , refiid ) ||
124 IsEqualGUID( &IID_IDirect3D3 , refiid ) ||
125 IsEqualGUID( &IID_IDirect3D7 , refiid ) )
127 WARN("Direct3D not allowed in ddrawex.dll\n");
128 return E_NOINTERFACE;
130 /* Unknown interface */
133 ERR("(%p)->(%s, %p): No interface found\n", This, debugstr_guid(refiid), obj);
134 return E_NOINTERFACE;
136 TRACE("Returning S_OK\n");
140 static HRESULT WINAPI
141 IDirectDraw3Impl_QueryInterface(IDirectDraw3 *iface,
145 IDirectDrawImpl *This = impl_from_dd3(iface);
146 TRACE("Thunking to IDirectDraw4\n");
147 return IDirectDraw4_QueryInterface(dd4_from_impl(This), refiid, obj);
150 static HRESULT WINAPI
151 IDirectDraw2Impl_QueryInterface(IDirectDraw2 *iface,
155 IDirectDrawImpl *This = impl_from_dd2(iface);
156 TRACE("Thunking to IDirectDraw4\n");
157 return IDirectDraw4_QueryInterface(dd4_from_impl(This), refiid, obj);
160 static HRESULT WINAPI
161 IDirectDrawImpl_QueryInterface(IDirectDraw *iface,
165 IDirectDrawImpl *This = impl_from_dd1(iface);
166 TRACE("Thunking to IDirectDraw4\n");
167 return IDirectDraw4_QueryInterface(dd4_from_impl(This), refiid, obj);
171 IDirectDraw4Impl_AddRef(IDirectDraw4 *iface)
173 IDirectDrawImpl *This = impl_from_dd4(iface);
174 ULONG ref = InterlockedIncrement(&This->ref);
176 TRACE("(%p) : incrementing refcount from %u.\n", This, ref - 1);
182 IDirectDraw3Impl_AddRef(IDirectDraw3 *iface)
184 IDirectDrawImpl *This = impl_from_dd3(iface);
185 TRACE("Thunking to IDirectDraw4\n");
186 return IDirectDraw4_AddRef(dd4_from_impl(This));
190 IDirectDraw2Impl_AddRef(IDirectDraw2 *iface)
192 IDirectDrawImpl *This = impl_from_dd2(iface);
193 TRACE("Thunking to IDirectDraw4\n");
194 return IDirectDraw4_AddRef(dd4_from_impl(This));
198 IDirectDrawImpl_AddRef(IDirectDraw *iface)
200 IDirectDrawImpl *This = impl_from_dd1(iface);
201 TRACE("Thunking to IDirectDraw4\n");
202 return IDirectDraw4_AddRef(dd4_from_impl(This));
206 IDirectDraw4Impl_Release(IDirectDraw4 *iface)
208 IDirectDrawImpl *This = impl_from_dd4(iface);
209 ULONG ref = InterlockedDecrement(&This->ref);
211 TRACE("(%p) : decrementing refcount to %u.\n", This, ref);
215 TRACE("Destroying object\n");
216 IDirectDraw4_Release(This->parent);
217 HeapFree(GetProcessHeap(), 0, This);
223 IDirectDraw3Impl_Release(IDirectDraw3 *iface)
225 IDirectDrawImpl *This = impl_from_dd3(iface);
226 TRACE("Thunking to IDirectDraw4\n");
227 return IDirectDraw4_Release(dd4_from_impl(This));
231 IDirectDraw2Impl_Release(IDirectDraw2 *iface)
233 IDirectDrawImpl *This = impl_from_dd2(iface);
234 TRACE("Thunking to IDirectDraw4\n");
235 return IDirectDraw4_Release(dd4_from_impl(This));
239 IDirectDrawImpl_Release(IDirectDraw *iface)
241 IDirectDrawImpl *This = impl_from_dd1(iface);
242 TRACE("Thunking to IDirectDraw4\n");
243 return IDirectDraw4_Release(dd4_from_impl(This));
246 static HRESULT WINAPI
247 IDirectDraw4Impl_Compact(IDirectDraw4 *iface)
249 IDirectDrawImpl *This = impl_from_dd4(iface);
250 TRACE("(%p)\n", This);
252 return IDirectDraw4_Compact(This->parent);
255 static HRESULT WINAPI
256 IDirectDraw3Impl_Compact(IDirectDraw3 *iface)
258 IDirectDrawImpl *This = impl_from_dd3(iface);
259 TRACE("Thunking to IDirectDraw4\n");
260 return IDirectDraw4_Compact(dd4_from_impl(This));
263 static HRESULT WINAPI
264 IDirectDraw2Impl_Compact(IDirectDraw2 *iface)
266 IDirectDrawImpl *This = impl_from_dd2(iface);
267 TRACE("Thunking to IDirectDraw4\n");
268 return IDirectDraw4_Compact(dd4_from_impl(This));
271 static HRESULT WINAPI
272 IDirectDrawImpl_Compact(IDirectDraw *iface)
274 IDirectDrawImpl *This = impl_from_dd1(iface);
275 TRACE("Thunking to IDirectDraw4\n");
276 return IDirectDraw4_Compact(dd4_from_impl(This));
279 static HRESULT WINAPI
280 IDirectDraw4Impl_CreateClipper(IDirectDraw4 *iface,
282 IDirectDrawClipper **clipper,
285 IDirectDrawImpl *This = impl_from_dd4(iface);
286 TRACE("(%p)->(0x%08x, %p, %p)\n", This, Flags, clipper, UnkOuter);
290 /* This may require a wrapper interface for clippers too which handles this */
291 FIXME("Test and implement Aggregation for ddrawex clippers\n");
294 return IDirectDraw4_CreateClipper(This->parent, Flags, clipper, UnkOuter);
297 static HRESULT WINAPI
298 IDirectDraw3Impl_CreateClipper(IDirectDraw3 *iface,
300 IDirectDrawClipper **clipper,
303 IDirectDrawImpl *This = impl_from_dd3(iface);
304 TRACE("Thunking to IDirectDraw4\n");
305 return IDirectDraw4_CreateClipper(dd4_from_impl(This), Flags, clipper, UnkOuter);
308 static HRESULT WINAPI
309 IDirectDraw2Impl_CreateClipper(IDirectDraw2 *iface,
311 IDirectDrawClipper **clipper,
314 IDirectDrawImpl *This = impl_from_dd2(iface);
315 TRACE("Thunking to IDirectDraw4\n");
316 return IDirectDraw4_CreateClipper(dd4_from_impl(This), Flags, clipper, UnkOuter);
319 static HRESULT WINAPI
320 IDirectDrawImpl_CreateClipper(IDirectDraw *iface,
322 IDirectDrawClipper **clipper,
325 IDirectDrawImpl *This = impl_from_dd1(iface);
326 TRACE("Thunking to IDirectDraw4\n");
327 return IDirectDraw4_CreateClipper(dd4_from_impl(This), Flags, clipper, UnkOuter);
330 static HRESULT WINAPI
331 IDirectDraw4Impl_CreatePalette(IDirectDraw4 *iface,
333 PALETTEENTRY *ColorTable,
334 IDirectDrawPalette **Palette,
337 IDirectDrawImpl *This = impl_from_dd4(iface);
338 TRACE("(%p)(0x%08x,%p,%p,%p)\n", This, Flags, ColorTable, Palette, UnkOuter);
342 /* This may require a wrapper interface for palettes too which handles this */
343 FIXME("Test and implement Aggregation for ddrawex palettes\n");
346 return IDirectDraw4_CreatePalette(This->parent, Flags, ColorTable, Palette, UnkOuter);
349 static HRESULT WINAPI
350 IDirectDraw3Impl_CreatePalette(IDirectDraw3 *iface,
352 PALETTEENTRY *ColorTable,
353 IDirectDrawPalette **Palette,
356 IDirectDrawImpl *This = impl_from_dd3(iface);
357 TRACE("Thunking to IDirectDraw4\n");
358 return IDirectDraw4_CreatePalette(dd4_from_impl(This), Flags, ColorTable, Palette, UnkOuter);
361 static HRESULT WINAPI
362 IDirectDraw2Impl_CreatePalette(IDirectDraw2 *iface,
364 PALETTEENTRY *ColorTable,
365 IDirectDrawPalette **Palette,
368 IDirectDrawImpl *This = impl_from_dd2(iface);
369 TRACE("Thunking to IDirectDraw4\n");
370 return IDirectDraw4_CreatePalette(dd4_from_impl(This), Flags, ColorTable, Palette, UnkOuter);
373 static HRESULT WINAPI
374 IDirectDrawImpl_CreatePalette(IDirectDraw *iface,
376 PALETTEENTRY *ColorTable,
377 IDirectDrawPalette **Palette,
380 IDirectDrawImpl *This = impl_from_dd1(iface);
381 TRACE("Thunking to IDirectDraw4\n");
382 return IDirectDraw4_CreatePalette(dd4_from_impl(This), Flags, ColorTable, Palette, UnkOuter);
385 static HRESULT WINAPI
386 IDirectDraw4Impl_CreateSurface(IDirectDraw4 *iface,
387 DDSURFACEDESC2 *DDSD,
388 IDirectDrawSurface4 **Surf,
391 IDirectDrawImpl *This = impl_from_dd4(iface);
393 const DWORD perm_dc_flags = DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
395 TRACE("(%p)(%p, %p, %p)\n", This, DDSD, Surf, UnkOuter);
399 /* Handle this in this dll. Don't forward the UnkOuter to ddraw.dll */
400 FIXME("Implement aggregation for ddrawex surfaces\n");
403 /* plain ddraw.dll refuses to create a surface that has both VIDMEM and SYSMEM flags
404 * set. In ddrawex this succeeds, and the GetDC() call changes the behavior. The DC
405 * is permanently valid, and the surface can be locked between GetDC() and ReleaseDC()
406 * calls. GetDC() can be called more than once too
408 if((DDSD->ddsCaps.dwCaps & perm_dc_flags) == perm_dc_flags)
411 DDSD->ddsCaps.dwCaps &= ~DDSCAPS_VIDEOMEMORY;
412 DDSD->ddsCaps.dwCaps |= DDSCAPS_OWNDC;
416 permanent_dc = FALSE;
419 hr = IDirectDraw4_CreateSurface(This->parent, DDSD, Surf, UnkOuter);
420 *Surf = dds_get_outer(*Surf);
421 if(permanent_dc) prepare_permanent_dc(*Surf);
425 void DDSD_to_DDSD2(const DDSURFACEDESC *in, DDSURFACEDESC2 *out)
427 memset(out, 0, sizeof(*out));
428 out->dwSize = sizeof(*out);
429 out->dwFlags = in->dwFlags;
430 if(in->dwFlags & DDSD_WIDTH) out->dwWidth = in->dwWidth;
431 if(in->dwFlags & DDSD_HEIGHT) out->dwHeight = in->dwHeight;
432 if(in->dwFlags & DDSD_PIXELFORMAT) out->u4.ddpfPixelFormat = in->ddpfPixelFormat;
433 if(in->dwFlags & DDSD_CAPS) out->ddsCaps.dwCaps = in->ddsCaps.dwCaps;
434 if(in->dwFlags & DDSD_PITCH) out->u1.lPitch = in->u1.lPitch;
435 if(in->dwFlags & DDSD_BACKBUFFERCOUNT) out->dwBackBufferCount = in->dwBackBufferCount;
436 if(in->dwFlags & DDSD_ZBUFFERBITDEPTH) out->u2.dwMipMapCount = in->u2.dwZBufferBitDepth; /* same union */
437 if(in->dwFlags & DDSD_ALPHABITDEPTH) out->dwAlphaBitDepth = in->dwAlphaBitDepth;
438 /* DDraw(native, and wine) does not set the DDSD_LPSURFACE, so always copy */
439 out->lpSurface = in->lpSurface;
440 if(in->dwFlags & DDSD_CKDESTOVERLAY) out->u3.ddckCKDestOverlay = in->ddckCKDestOverlay;
441 if(in->dwFlags & DDSD_CKDESTBLT) out->ddckCKDestBlt = in->ddckCKDestBlt;
442 if(in->dwFlags & DDSD_CKSRCOVERLAY) out->ddckCKSrcOverlay = in->ddckCKSrcOverlay;
443 if(in->dwFlags & DDSD_CKSRCBLT) out->ddckCKSrcBlt = in->ddckCKSrcBlt;
444 if(in->dwFlags & DDSD_MIPMAPCOUNT) out->u2.dwMipMapCount = in->u2.dwMipMapCount;
445 if(in->dwFlags & DDSD_REFRESHRATE) out->u2.dwRefreshRate = in->u2.dwRefreshRate;
446 if(in->dwFlags & DDSD_LINEARSIZE) out->u1.dwLinearSize = in->u1.dwLinearSize;
447 /* Does not exist in DDSURFACEDESC:
448 * DDSD_TEXTURESTAGE, DDSD_FVF, DDSD_SRCVBHANDLE,
452 void DDSD2_to_DDSD(const DDSURFACEDESC2 *in, DDSURFACEDESC *out)
454 memset(out, 0, sizeof(*out));
455 out->dwSize = sizeof(*out);
456 out->dwFlags = in->dwFlags;
457 if(in->dwFlags & DDSD_WIDTH) out->dwWidth = in->dwWidth;
458 if(in->dwFlags & DDSD_HEIGHT) out->dwHeight = in->dwHeight;
459 if(in->dwFlags & DDSD_PIXELFORMAT) out->ddpfPixelFormat = in->u4.ddpfPixelFormat;
460 if(in->dwFlags & DDSD_CAPS) out->ddsCaps.dwCaps = in->ddsCaps.dwCaps;
461 if(in->dwFlags & DDSD_PITCH) out->u1.lPitch = in->u1.lPitch;
462 if(in->dwFlags & DDSD_BACKBUFFERCOUNT) out->dwBackBufferCount = in->dwBackBufferCount;
463 if(in->dwFlags & DDSD_ZBUFFERBITDEPTH) out->u2.dwZBufferBitDepth = in->u2.dwMipMapCount; /* same union */
464 if(in->dwFlags & DDSD_ALPHABITDEPTH) out->dwAlphaBitDepth = in->dwAlphaBitDepth;
465 /* DDraw(native, and wine) does not set the DDSD_LPSURFACE, so always copy */
466 out->lpSurface = in->lpSurface;
467 if(in->dwFlags & DDSD_CKDESTOVERLAY) out->ddckCKDestOverlay = in->u3.ddckCKDestOverlay;
468 if(in->dwFlags & DDSD_CKDESTBLT) out->ddckCKDestBlt = in->ddckCKDestBlt;
469 if(in->dwFlags & DDSD_CKSRCOVERLAY) out->ddckCKSrcOverlay = in->ddckCKSrcOverlay;
470 if(in->dwFlags & DDSD_CKSRCBLT) out->ddckCKSrcBlt = in->ddckCKSrcBlt;
471 if(in->dwFlags & DDSD_MIPMAPCOUNT) out->u2.dwMipMapCount = in->u2.dwMipMapCount;
472 if(in->dwFlags & DDSD_REFRESHRATE) out->u2.dwRefreshRate = in->u2.dwRefreshRate;
473 if(in->dwFlags & DDSD_LINEARSIZE) out->u1.dwLinearSize = in->u1.dwLinearSize;
474 /* Does not exist in DDSURFACEDESC:
475 * DDSD_TEXTURESTAGE, DDSD_FVF, DDSD_SRCVBHANDLE,
477 if(in->dwFlags & DDSD_TEXTURESTAGE) WARN("Does not exist in DDSURFACEDESC: DDSD_TEXTURESTAGE\n");
478 if(in->dwFlags & DDSD_FVF) WARN("Does not exist in DDSURFACEDESC: DDSD_FVF\n");
479 if(in->dwFlags & DDSD_SRCVBHANDLE) WARN("Does not exist in DDSURFACEDESC: DDSD_SRCVBHANDLE\n");
480 out->dwFlags &= ~(DDSD_TEXTURESTAGE | DDSD_FVF | DDSD_SRCVBHANDLE);
483 static HRESULT WINAPI
484 IDirectDraw3Impl_CreateSurface(IDirectDraw3 *iface,
486 IDirectDrawSurface **Surf,
489 IDirectDrawImpl *This = impl_from_dd3(iface);
490 DDSURFACEDESC2 ddsd2;
491 IDirectDrawSurface4 *surf4 = NULL;
493 TRACE("Thunking to IDirectDraw4\n");
495 DDSD_to_DDSD2(DDSD, &ddsd2);
497 hr = IDirectDraw4_CreateSurface(dd4_from_impl(This), &ddsd2, &surf4, UnkOuter);
504 TRACE("Got surface %p\n", surf4);
505 IDirectDrawSurface4_QueryInterface(surf4, &IID_IDirectDrawSurface, (void **) Surf);
506 IDirectDrawSurface4_Release(surf4);
510 static HRESULT WINAPI
511 IDirectDraw2Impl_CreateSurface(IDirectDraw2 *iface,
513 IDirectDrawSurface **Surf,
516 IDirectDrawImpl *This = impl_from_dd2(iface);
517 TRACE("Thunking to IDirectDraw3\n");
518 return IDirectDraw3_CreateSurface(dd3_from_impl(This), DDSD, Surf, UnkOuter);
521 static HRESULT WINAPI
522 IDirectDrawImpl_CreateSurface(IDirectDraw *iface,
524 IDirectDrawSurface **Surf,
527 IDirectDrawImpl *This = impl_from_dd1(iface);
528 TRACE("Thunking to IDirectDraw3\n");
529 return IDirectDraw3_CreateSurface(dd3_from_impl(This), DDSD, Surf, UnkOuter);
532 static HRESULT WINAPI
533 IDirectDraw4Impl_DuplicateSurface(IDirectDraw4 *iface,
534 IDirectDrawSurface4 *src,
535 IDirectDrawSurface4 **dst)
537 IDirectDrawImpl *This = impl_from_dd4(iface);
538 FIXME("(%p)->(%p,%p). Create a wrapper surface\n", This, src, dst);
540 return IDirectDraw4_DuplicateSurface(This->parent, dds_get_inner(src), dst);
543 static HRESULT WINAPI
544 IDirectDraw3Impl_DuplicateSurface(IDirectDraw3 *iface,
545 IDirectDrawSurface *src,
546 IDirectDrawSurface **dst)
548 IDirectDrawImpl *This = impl_from_dd3(iface);
549 IDirectDrawSurface4 *src_4;
550 IDirectDrawSurface4 *dst_4;
553 TRACE("Thunking to IDirectDraw4\n");
554 IDirectDrawSurface_QueryInterface(src, &IID_IDirectDrawSurface4, (void **) &src_4);
555 hr = IDirectDraw4_DuplicateSurface(dd4_from_impl(This), src_4, &dst_4);
556 IDirectDrawSurface4_Release(src_4);
563 IDirectDrawSurface4_QueryInterface(dst_4, &IID_IDirectDrawSurface, (void **) dst);
564 IDirectDrawSurface4_Release(dst_4);
568 static HRESULT WINAPI
569 IDirectDraw2Impl_DuplicateSurface(IDirectDraw2 *iface,
570 IDirectDrawSurface *src,
571 IDirectDrawSurface **dst)
573 IDirectDrawImpl *This = impl_from_dd2(iface);
574 TRACE("Thunking to IDirectDraw3\n");
575 return IDirectDraw3_DuplicateSurface(dd3_from_impl(This), src, dst);
578 static HRESULT WINAPI
579 IDirectDrawImpl_DuplicateSurface(IDirectDraw *iface,
580 IDirectDrawSurface *src,
581 IDirectDrawSurface **dst)
583 IDirectDrawImpl *This = impl_from_dd1(iface);
584 TRACE("Thunking to IDirectDraw3\n");
585 return IDirectDraw3_DuplicateSurface(dd3_from_impl(This), src, dst);
588 static HRESULT WINAPI
589 IDirectDraw4Impl_EnumDisplayModes(IDirectDraw4 *iface,
591 DDSURFACEDESC2 *DDSD,
593 LPDDENUMMODESCALLBACK2 cb)
595 IDirectDrawImpl *This = impl_from_dd4(iface);
596 TRACE("(%p)->(0x%08x,%p,%p,%p)\n", This, Flags, DDSD, Context, cb);
598 return IDirectDraw4_EnumDisplayModes(This->parent, Flags, DDSD, Context, cb);
603 LPDDENUMMODESCALLBACK orig_cb;
607 static HRESULT WINAPI
608 enum_modes_cb2(DDSURFACEDESC2 *ddsd2, void *vctx)
610 struct enummodes_ctx *ctx = vctx;
613 DDSD2_to_DDSD(ddsd2, &ddsd);
614 return ctx->orig_cb(&ddsd, ctx->orig_ctx);
617 static HRESULT WINAPI
618 IDirectDraw3Impl_EnumDisplayModes(IDirectDraw3 *iface,
622 LPDDENUMMODESCALLBACK cb)
624 IDirectDrawImpl *This = impl_from_dd3(iface);
625 DDSURFACEDESC2 ddsd2;
626 struct enummodes_ctx ctx;
627 TRACE("(%p)->(0x%08x,%p,%p,%p): Thunking to IDirectDraw4\n", This, Flags, DDSD, Context, cb);
629 DDSD_to_DDSD2(DDSD, &ddsd2);
631 ctx.orig_ctx = Context;
632 return IDirectDraw4_EnumDisplayModes(dd4_from_impl(This), Flags, &ddsd2, &ctx, enum_modes_cb2);
635 static HRESULT WINAPI
636 IDirectDraw2Impl_EnumDisplayModes(IDirectDraw2 *iface,
640 LPDDENUMMODESCALLBACK cb)
642 IDirectDrawImpl *This = impl_from_dd2(iface);
643 TRACE("(%p)->(0x%08x,%p,%p,%p): Thunking to IDirectDraw3\n", This, Flags, DDSD, Context, cb);
644 return IDirectDraw3_EnumDisplayModes(dd3_from_impl(This), Flags, DDSD, Context, cb);
647 static HRESULT WINAPI
648 IDirectDrawImpl_EnumDisplayModes(IDirectDraw *iface,
652 LPDDENUMMODESCALLBACK cb)
654 IDirectDrawImpl *This = impl_from_dd1(iface);
655 TRACE("(%p)->(0x%08x,%p,%p,%p): Thunking to IDirectDraw3\n", This, Flags, DDSD, Context, cb);
656 return IDirectDraw3_EnumDisplayModes(dd3_from_impl(This), Flags, DDSD, Context, cb);
659 struct enumsurfaces4_ctx
661 LPDDENUMSURFACESCALLBACK2 orig_cb;
665 static HRESULT WINAPI
666 enum_surfaces_wrapper(IDirectDrawSurface4 *surf4, DDSURFACEDESC2 *ddsd2, void *vctx)
668 struct enumsurfaces4_ctx *ctx = vctx;
669 IDirectDrawSurface4 *outer = dds_get_outer(surf4);
670 IDirectDrawSurface4_AddRef(outer);
671 IDirectDrawSurface4_Release(surf4);
672 TRACE("Returning wrapper surface %p for enumerated inner surface %p\n", outer, surf4);
673 return ctx->orig_cb(outer, ddsd2, ctx->orig_ctx);
676 static HRESULT WINAPI
677 IDirectDraw4Impl_EnumSurfaces(IDirectDraw4 *iface,
679 DDSURFACEDESC2 *DDSD,
681 LPDDENUMSURFACESCALLBACK2 Callback)
683 IDirectDrawImpl *This = impl_from_dd4(iface);
684 struct enumsurfaces4_ctx ctx;
685 TRACE("(%p)->(0x%08x,%p,%p,%p)\n", This, Flags, DDSD, Context, Callback);
687 ctx.orig_cb = Callback;
688 ctx.orig_ctx = Context;
689 return IDirectDraw4Impl_EnumSurfaces(This->parent, Flags, DDSD, &ctx, enum_surfaces_wrapper);
692 struct enumsurfaces_ctx
694 LPDDENUMSURFACESCALLBACK orig_cb;
698 static HRESULT WINAPI
699 enum_surfaces_cb2(IDirectDrawSurface4 *surf4, DDSURFACEDESC2 *ddsd2, void *vctx)
701 struct enumsurfaces_ctx *ctx = vctx;
702 IDirectDrawSurface *surf1;
705 /* Keep the reference, it goes to the application */
706 IDirectDrawSurface4_QueryInterface(surf4, &IID_IDirectDrawSurface, (void **) &surf1);
707 /* Release the reference this function got */
708 IDirectDrawSurface4_Release(surf4);
710 DDSD2_to_DDSD(ddsd2, &ddsd);
711 return ctx->orig_cb(surf1, &ddsd, ctx->orig_ctx);
714 static HRESULT WINAPI
715 IDirectDraw3Impl_EnumSurfaces(IDirectDraw3 *iface,
719 LPDDENUMSURFACESCALLBACK Callback)
721 IDirectDrawImpl *This = impl_from_dd3(iface);
722 DDSURFACEDESC2 ddsd2;
723 struct enumsurfaces_ctx ctx;
724 TRACE("(%p)->(0x%08x,%p,%p,%p): Thunking to IDirectDraw4\n", This, Flags, DDSD, Context, Callback);
726 DDSD_to_DDSD2(DDSD, &ddsd2);
727 ctx.orig_cb = Callback;
728 ctx.orig_ctx = Context;
729 return IDirectDraw4_EnumSurfaces(dd4_from_impl(This), Flags, &ddsd2, &ctx, enum_surfaces_cb2);
732 static HRESULT WINAPI
733 IDirectDraw2Impl_EnumSurfaces(IDirectDraw2 *iface,
737 LPDDENUMSURFACESCALLBACK Callback)
739 IDirectDrawImpl *This = impl_from_dd2(iface);
740 TRACE("(%p)->(0x%08x,%p,%p,%p): Thunking to IDirectDraw3\n", This, Flags, DDSD, Context, Callback);
741 return IDirectDraw3_EnumSurfaces(dd3_from_impl(This), Flags, DDSD, Context, Callback);
744 static HRESULT WINAPI
745 IDirectDrawImpl_EnumSurfaces(IDirectDraw *iface,
749 LPDDENUMSURFACESCALLBACK Callback)
751 IDirectDrawImpl *This = impl_from_dd1(iface);
752 TRACE("(%p)->(0x%08x,%p,%p,%p): Thunking to IDirectDraw3\n", This, Flags, DDSD, Context, Callback);
753 return IDirectDraw3_EnumSurfaces(dd3_from_impl(This), Flags, DDSD, Context, Callback);
756 static HRESULT WINAPI
757 IDirectDraw4Impl_FlipToGDISurface(IDirectDraw4 *iface)
759 IDirectDrawImpl *This = impl_from_dd4(iface);
760 TRACE("(%p)\n", This);
762 return IDirectDraw4_FlipToGDISurface(This->parent);
765 static HRESULT WINAPI
766 IDirectDraw3Impl_FlipToGDISurface(IDirectDraw3 *iface)
768 IDirectDrawImpl *This = impl_from_dd3(iface);
769 TRACE("(%p). Thunking to IDirectDraw4\n", This);
770 return IDirectDraw4_FlipToGDISurface(dd4_from_impl(This));
773 static HRESULT WINAPI
774 IDirectDraw2Impl_FlipToGDISurface(IDirectDraw2 *iface)
776 IDirectDrawImpl *This = impl_from_dd2(iface);
777 TRACE("(%p). Thunking to IDirectDraw4\n", This);
778 return IDirectDraw4_FlipToGDISurface(dd4_from_impl(This));
781 static HRESULT WINAPI
782 IDirectDrawImpl_FlipToGDISurface(IDirectDraw *iface)
784 IDirectDrawImpl *This = impl_from_dd1(iface);
785 TRACE("(%p). Thunking to IDirectDraw4\n", This);
786 return IDirectDraw4_FlipToGDISurface(dd4_from_impl(This));
789 static HRESULT WINAPI
790 IDirectDraw4Impl_GetCaps(IDirectDraw4 *iface,
794 IDirectDrawImpl *This = impl_from_dd4(iface);
795 TRACE("(%p)->(%p,%p)\n", This, DriverCaps, HELCaps);
796 return IDirectDraw4_GetCaps(This->parent, DriverCaps, HELCaps);
799 static HRESULT WINAPI
800 IDirectDraw3Impl_GetCaps(IDirectDraw3 *iface,
804 IDirectDrawImpl *This = impl_from_dd3(iface);
805 TRACE("(%p)->(%p,%p). Thunking to IDirectDraw4\n", This, DriverCaps, HELCaps);
806 return IDirectDraw4_GetCaps(dd4_from_impl(This), DriverCaps, HELCaps);
809 static HRESULT WINAPI
810 IDirectDraw2Impl_GetCaps(IDirectDraw2 *iface,
814 IDirectDrawImpl *This = impl_from_dd2(iface);
815 TRACE("(%p)->(%p,%p). Thunking to IDirectDraw4\n", This, DriverCaps, HELCaps);
816 return IDirectDraw4_GetCaps(dd4_from_impl(This), DriverCaps, HELCaps);
819 static HRESULT WINAPI
820 IDirectDrawImpl_GetCaps(IDirectDraw *iface,
824 IDirectDrawImpl *This = impl_from_dd1(iface);
825 TRACE("(%p)->(%p,%p). Thunking to IDirectDraw4\n", This, DriverCaps, HELCaps);
826 return IDirectDraw4_GetCaps(dd4_from_impl(This), DriverCaps, HELCaps);
829 static HRESULT WINAPI
830 IDirectDraw4Impl_GetDisplayMode(IDirectDraw4 *iface,
831 DDSURFACEDESC2 *DDSD)
833 IDirectDrawImpl *This = impl_from_dd4(iface);
834 TRACE("(%p)->(%p)\n", This, DDSD);
835 return IDirectDraw4_GetDisplayMode(This->parent, DDSD);
838 static HRESULT WINAPI
839 IDirectDraw3Impl_GetDisplayMode(IDirectDraw3 *iface,
842 IDirectDrawImpl *This = impl_from_dd3(iface);
843 DDSURFACEDESC2 ddsd2;
846 TRACE("(%p)->(%p): Thunking to IDirectDraw4\n", This, DDSD);
847 hr = IDirectDraw4_GetDisplayMode(dd4_from_impl(This), &ddsd2);
848 DDSD2_to_DDSD(&ddsd2, DDSD);
852 static HRESULT WINAPI
853 IDirectDraw2Impl_GetDisplayMode(IDirectDraw2 *iface,
856 IDirectDrawImpl *This = impl_from_dd2(iface);
857 TRACE("(%p)->(%p): Thunking to IDirectDraw3\n", This, DDSD);
858 return IDirectDraw3_GetDisplayMode(dd3_from_impl(This), DDSD);
861 static HRESULT WINAPI
862 IDirectDrawImpl_GetDisplayMode(IDirectDraw *iface,
865 IDirectDrawImpl *This = impl_from_dd1(iface);
866 TRACE("(%p)->(%p): Thunking to IDirectDraw3\n", This, DDSD);
867 return IDirectDraw3_GetDisplayMode(dd3_from_impl(This), DDSD);
870 static HRESULT WINAPI
871 IDirectDraw4Impl_GetFourCCCodes(IDirectDraw4 *iface,
875 IDirectDrawImpl *This = impl_from_dd4(iface);
876 TRACE("(%p)->(%p, %p):\n", This, NumCodes, Codes);
877 return IDirectDraw4_GetFourCCCodes(This->parent, NumCodes, Codes);
880 static HRESULT WINAPI
881 IDirectDraw3Impl_GetFourCCCodes(IDirectDraw3 *iface,
885 IDirectDrawImpl *This = impl_from_dd3(iface);
886 TRACE("(%p)->(%p, %p): Thunking to IDirectDraw4\n", This, NumCodes, Codes);
887 return IDirectDraw4_GetFourCCCodes(dd4_from_impl(This), NumCodes, Codes);
890 static HRESULT WINAPI
891 IDirectDraw2Impl_GetFourCCCodes(IDirectDraw2 *iface,
895 IDirectDrawImpl *This = impl_from_dd2(iface);
896 TRACE("(%p)->(%p, %p): Thunking to IDirectDraw4\n", This, NumCodes, Codes);
897 return IDirectDraw4_GetFourCCCodes(dd4_from_impl(This), NumCodes, Codes);
900 static HRESULT WINAPI
901 IDirectDrawImpl_GetFourCCCodes(IDirectDraw *iface,
905 IDirectDrawImpl *This = impl_from_dd1(iface);
906 TRACE("(%p)->(%p, %p): Thunking to IDirectDraw4\n", This, NumCodes, Codes);
907 return IDirectDraw4_GetFourCCCodes(dd4_from_impl(This), NumCodes, Codes);
910 static HRESULT WINAPI
911 IDirectDraw4Impl_GetGDISurface(IDirectDraw4 *iface,
912 IDirectDrawSurface4 **GDISurface)
914 IDirectDrawImpl *This = impl_from_dd4(iface);
915 IDirectDrawSurface4 *inner = NULL;
917 TRACE("(%p)->(%p)\n", This, GDISurface);
919 hr = IDirectDraw4_GetGDISurface(This->parent, &inner);
922 *GDISurface = dds_get_outer(inner);
923 IDirectDrawSurface4_AddRef(*GDISurface);
924 IDirectDrawSurface4_Release(inner);
933 static HRESULT WINAPI
934 IDirectDraw3Impl_GetGDISurface(IDirectDraw3 *iface,
935 IDirectDrawSurface **GDISurface)
937 IDirectDrawImpl *This = impl_from_dd3(iface);
938 IDirectDrawSurface4 *surf4;
940 TRACE("(%p)->(%p): Thunking to IDirectDraw4\n", This, GDISurface);
942 hr = IDirectDraw4_GetGDISurface(dd4_from_impl(This), &surf4);
948 /* Release the reference we got from the DDraw4 call, and pass a reference to the caller */
949 IDirectDrawSurface4_QueryInterface(surf4, &IID_IDirectDrawSurface, (void **) GDISurface);
950 IDirectDrawSurface4_Release(surf4);
954 static HRESULT WINAPI
955 IDirectDraw2Impl_GetGDISurface(IDirectDraw2 *iface,
956 IDirectDrawSurface **GDISurface)
958 IDirectDrawImpl *This = impl_from_dd2(iface);
959 TRACE("(%p)->(%p): Thunking to IDirectDraw3\n", This, GDISurface);
960 return IDirectDraw3_GetGDISurface(dd3_from_impl(This), GDISurface);
963 static HRESULT WINAPI
964 IDirectDrawImpl_GetGDISurface(IDirectDraw *iface,
965 IDirectDrawSurface **GDISurface)
967 IDirectDrawImpl *This = impl_from_dd1(iface);
968 TRACE("(%p)->(%p): Thunking to IDirectDraw3\n", This, GDISurface);
969 return IDirectDraw3_GetGDISurface(dd3_from_impl(This), GDISurface);
972 static HRESULT WINAPI
973 IDirectDraw4Impl_GetMonitorFrequency(IDirectDraw4 *iface,
976 IDirectDrawImpl *This = impl_from_dd4(iface);
977 TRACE("(%p)->(%p)\n", This, Freq);
978 return IDirectDraw4_GetMonitorFrequency(This->parent, Freq);
981 static HRESULT WINAPI
982 IDirectDraw3Impl_GetMonitorFrequency(IDirectDraw3 *iface,
985 IDirectDrawImpl *This = impl_from_dd3(iface);
986 TRACE("(%p)->(%p): Thunking to IDirectDraw4\n", This, Freq);
987 return IDirectDraw4_GetMonitorFrequency(dd4_from_impl(This), Freq);
990 static HRESULT WINAPI
991 IDirectDraw2Impl_GetMonitorFrequency(IDirectDraw2 *iface,
994 IDirectDrawImpl *This = impl_from_dd2(iface);
995 TRACE("(%p)->(%p): Thunking to IDirectDraw4\n", This, Freq);
996 return IDirectDraw4_GetMonitorFrequency(dd4_from_impl(This), Freq);
999 static HRESULT WINAPI
1000 IDirectDrawImpl_GetMonitorFrequency(IDirectDraw *iface,
1003 IDirectDrawImpl *This = impl_from_dd1(iface);
1004 TRACE("(%p)->(%p): Thunking to IDirectDraw4\n", This, Freq);
1005 return IDirectDraw4_GetMonitorFrequency(dd4_from_impl(This), Freq);
1008 static HRESULT WINAPI
1009 IDirectDraw4Impl_GetScanLine(IDirectDraw4 *iface,
1012 IDirectDrawImpl *This = impl_from_dd4(iface);
1013 TRACE("(%p)->(%p)\n", This, Scanline);
1014 return IDirectDraw4_GetScanLine(This->parent, Scanline);
1017 static HRESULT WINAPI
1018 IDirectDraw3Impl_GetScanLine(IDirectDraw3 *iface,
1021 IDirectDrawImpl *This = impl_from_dd3(iface);
1022 TRACE("(%p)->(%p): Thunking to IDirectDraw4\n", This, Scanline);
1023 return IDirectDraw4_GetScanLine(dd4_from_impl(This), Scanline);
1026 static HRESULT WINAPI
1027 IDirectDraw2Impl_GetScanLine(IDirectDraw2 *iface,
1030 IDirectDrawImpl *This = impl_from_dd2(iface);
1031 TRACE("(%p)->(%p): Thunking to IDirectDraw4\n", This, Scanline);
1032 return IDirectDraw4_GetScanLine(dd4_from_impl(This), Scanline);
1035 static HRESULT WINAPI
1036 IDirectDrawImpl_GetScanLine(IDirectDraw *iface,
1039 IDirectDrawImpl *This = impl_from_dd1(iface);
1040 TRACE("(%p)->(%p): Thunking to IDirectDraw4\n", This, Scanline);
1041 return IDirectDraw4_GetScanLine(dd4_from_impl(This), Scanline);
1044 static HRESULT WINAPI
1045 IDirectDraw4Impl_GetVerticalBlankStatus(IDirectDraw4 *iface,
1048 IDirectDrawImpl *This = impl_from_dd4(iface);
1049 TRACE("(%p)->(%p)\n", This, status);
1050 return IDirectDraw4_GetVerticalBlankStatus(This->parent, status);
1053 static HRESULT WINAPI
1054 IDirectDraw3Impl_GetVerticalBlankStatus(IDirectDraw3 *iface,
1057 IDirectDrawImpl *This = impl_from_dd3(iface);
1058 TRACE("(%p)->(%p): Thunking to IDirectDraw4\n", This, status);
1059 return IDirectDraw4_GetVerticalBlankStatus(dd4_from_impl(This), status);
1062 static HRESULT WINAPI
1063 IDirectDraw2Impl_GetVerticalBlankStatus(IDirectDraw2 *iface,
1066 IDirectDrawImpl *This = impl_from_dd2(iface);
1067 TRACE("(%p)->(%p): Thunking to IDirectDraw4\n", This, status);
1068 return IDirectDraw4_GetVerticalBlankStatus(dd4_from_impl(This), status);
1071 static HRESULT WINAPI
1072 IDirectDrawImpl_GetVerticalBlankStatus(IDirectDraw *iface,
1075 IDirectDrawImpl *This = impl_from_dd1(iface);
1076 TRACE("(%p)->(%p): Thunking to IDirectDraw4\n", This, status);
1077 return IDirectDraw4_GetVerticalBlankStatus(dd4_from_impl(This), status);
1080 static HRESULT WINAPI
1081 IDirectDraw4Impl_Initialize(IDirectDraw4 *iface,
1084 IDirectDrawImpl *This = impl_from_dd4(iface);
1085 TRACE("(%p)->(%s)\n", This, debugstr_guid(Guid));
1086 return IDirectDraw4_Initialize(This->parent, Guid);
1089 static HRESULT WINAPI
1090 IDirectDraw3Impl_Initialize(IDirectDraw3 *iface,
1093 IDirectDrawImpl *This = impl_from_dd3(iface);
1094 TRACE("(%p)->(%s): Thunking to IDirectDraw4\n", This, debugstr_guid(Guid));
1095 return IDirectDraw4_Initialize(dd4_from_impl(This), Guid);
1098 static HRESULT WINAPI
1099 IDirectDraw2Impl_Initialize(IDirectDraw2 *iface,
1102 IDirectDrawImpl *This = impl_from_dd2(iface);
1103 TRACE("(%p)->(%s): Thunking to IDirectDraw4\n", This, debugstr_guid(Guid));
1104 return IDirectDraw4_Initialize(dd4_from_impl(This), Guid);
1107 static HRESULT WINAPI
1108 IDirectDrawImpl_Initialize(IDirectDraw *iface,
1111 IDirectDrawImpl *This = impl_from_dd1(iface);
1112 TRACE("(%p)->(%s): Thunking to IDirectDraw4\n", This, debugstr_guid(Guid));
1113 return IDirectDraw4_Initialize(dd4_from_impl(This), Guid);
1116 static HRESULT WINAPI
1117 IDirectDraw4Impl_RestoreDisplayMode(IDirectDraw4 *iface)
1119 IDirectDrawImpl *This = impl_from_dd4(iface);
1120 TRACE("(%p)\n", This);
1121 return IDirectDraw4_RestoreDisplayMode(This->parent);
1124 static HRESULT WINAPI
1125 IDirectDraw3Impl_RestoreDisplayMode(IDirectDraw3 *iface)
1127 IDirectDrawImpl *This = impl_from_dd3(iface);
1128 TRACE("(%p): Thunking to IDirectDraw4\n", This);
1129 return IDirectDraw4_RestoreDisplayMode(dd4_from_impl(This));
1132 static HRESULT WINAPI
1133 IDirectDraw2Impl_RestoreDisplayMode(IDirectDraw2 *iface)
1135 IDirectDrawImpl *This = impl_from_dd2(iface);
1136 TRACE("(%p): Thunking to IDirectDraw4\n", This);
1137 return IDirectDraw4_RestoreDisplayMode(dd4_from_impl(This));
1140 static HRESULT WINAPI
1141 IDirectDrawImpl_RestoreDisplayMode(IDirectDraw *iface)
1143 IDirectDrawImpl *This = impl_from_dd1(iface);
1144 TRACE("(%p): Thunking to IDirectDraw4\n", This);
1145 return IDirectDraw4_RestoreDisplayMode(dd4_from_impl(This));
1148 static HRESULT WINAPI
1149 IDirectDraw4Impl_SetCooperativeLevel(IDirectDraw4 *iface,
1153 IDirectDrawImpl *This = impl_from_dd4(iface);
1154 TRACE("(%p)->(%p, 0x%08x)\n", This, hwnd, cooplevel);
1155 return IDirectDraw4_SetCooperativeLevel(This->parent, hwnd, cooplevel);
1158 static HRESULT WINAPI
1159 IDirectDraw3Impl_SetCooperativeLevel(IDirectDraw3 *iface,
1163 IDirectDrawImpl *This = impl_from_dd3(iface);
1164 TRACE("(%p)->(%p, 0x%08x): Thunking to IDirectDraw4\n", This, hwnd, cooplevel);
1165 return IDirectDraw4_SetCooperativeLevel(dd4_from_impl(This), hwnd, cooplevel);
1168 static HRESULT WINAPI
1169 IDirectDraw2Impl_SetCooperativeLevel(IDirectDraw2 *iface,
1173 IDirectDrawImpl *This = impl_from_dd2(iface);
1174 TRACE("(%p)->(%p, 0x%08x): Thunking to IDirectDraw4\n", This, hwnd, cooplevel);
1175 return IDirectDraw4_SetCooperativeLevel(dd4_from_impl(This), hwnd, cooplevel);
1178 static HRESULT WINAPI
1179 IDirectDrawImpl_SetCooperativeLevel(IDirectDraw *iface,
1183 IDirectDrawImpl *This = impl_from_dd1(iface);
1184 TRACE("(%p)->(%p, 0x%08x): Thunking to IDirectDraw4\n", This, hwnd, cooplevel);
1185 return IDirectDraw4_SetCooperativeLevel(dd4_from_impl(This), hwnd, cooplevel);
1188 static HRESULT WINAPI
1189 IDirectDraw4Impl_SetDisplayMode(IDirectDraw4 *iface,
1196 IDirectDrawImpl *This = impl_from_dd4(iface);
1197 TRACE("(%p)->(%u, %u, %u, %u, 0x%08x)\n", This, Width, Height, BPP, RefreshRate, Flags);
1198 return IDirectDraw4_SetDisplayMode(This->parent, Width, Height, BPP, RefreshRate, Flags);
1201 static HRESULT WINAPI
1202 IDirectDraw3Impl_SetDisplayMode(IDirectDraw3 *iface,
1209 IDirectDrawImpl *This = impl_from_dd3(iface);
1210 TRACE("(%p)->(%u, %u, %u, %u, 0x%08x): Thunking to IDirectDraw4\n", This, Width, Height, BPP, RefreshRate, Flags);
1211 return IDirectDraw3_SetDisplayMode(dd4_from_impl(This), Width, Height, BPP, RefreshRate, Flags);
1214 static HRESULT WINAPI
1215 IDirectDraw2Impl_SetDisplayMode(IDirectDraw2 *iface,
1222 IDirectDrawImpl *This = impl_from_dd2(iface);
1223 TRACE("(%p)->(%u, %u, %u, %u, 0x%08x): Thunking to IDirectDraw4\n", This, Width, Height, BPP, RefreshRate, Flags);
1224 return IDirectDraw3_SetDisplayMode(dd4_from_impl(This), Width, Height, BPP, RefreshRate, Flags);
1227 static HRESULT WINAPI
1228 IDirectDrawImpl_SetDisplayMode(IDirectDraw *iface,
1233 IDirectDrawImpl *This = impl_from_dd1(iface);
1234 TRACE("(%p)->(%u, %u, %u): Thunking to IDirectDraw4\n", This, Width, Height, BPP);
1235 return IDirectDraw3_SetDisplayMode(dd4_from_impl(This), Width, Height, BPP, 0, 0);
1238 static HRESULT WINAPI
1239 IDirectDraw4Impl_WaitForVerticalBlank(IDirectDraw4 *iface,
1243 IDirectDrawImpl *This = impl_from_dd4(iface);
1244 TRACE("(%p)->(0x%08x, %p)\n", This, Flags, h);
1245 return IDirectDraw4_WaitForVerticalBlank(This->parent, Flags, h);
1248 static HRESULT WINAPI
1249 IDirectDraw3Impl_WaitForVerticalBlank(IDirectDraw3 *iface,
1253 IDirectDrawImpl *This = impl_from_dd3(iface);
1254 TRACE("(%p)->(0x%08x, %p): Thunking to IDirectDraw4\n", This, Flags, h);
1255 return IDirectDraw4_WaitForVerticalBlank(dd4_from_impl(This), Flags, h);
1258 static HRESULT WINAPI
1259 IDirectDraw2Impl_WaitForVerticalBlank(IDirectDraw2 *iface,
1263 IDirectDrawImpl *This = impl_from_dd2(iface);
1264 TRACE("(%p)->(0x%08x, %p): Thunking to IDirectDraw4\n", This, Flags, h);
1265 return IDirectDraw4_WaitForVerticalBlank(dd4_from_impl(This), Flags, h);
1268 static HRESULT WINAPI
1269 IDirectDrawImpl_WaitForVerticalBlank(IDirectDraw *iface,
1273 IDirectDrawImpl *This = impl_from_dd1(iface);
1274 TRACE("(%p)->(0x%08x, %p): Thunking to IDirectDraw4\n", This, Flags, h);
1275 return IDirectDraw4_WaitForVerticalBlank(dd4_from_impl(This), Flags, h);
1278 static HRESULT WINAPI
1279 IDirectDraw4Impl_GetAvailableVidMem(IDirectDraw4 *iface,
1284 IDirectDrawImpl *This = impl_from_dd4(iface);
1285 TRACE("(%p)->(%p, %p, %p)\n", This, Caps, total, free);
1286 return IDirectDraw4_GetAvailableVidMem(This->parent, Caps, total, free);
1289 static HRESULT WINAPI
1290 IDirectDraw3Impl_GetAvailableVidMem(IDirectDraw3 *iface,
1295 IDirectDrawImpl *This = impl_from_dd3(iface);
1297 TRACE("(%p)->(%p, %p, %p): Thunking to IDirectDraw4\n", This, Caps, total, free);
1298 memset(&caps2, 0, sizeof(caps2));
1299 caps2.dwCaps = Caps->dwCaps;
1300 return IDirectDraw4_GetAvailableVidMem(dd4_from_impl(This), &caps2, total, free);
1303 static HRESULT WINAPI
1304 IDirectDraw2Impl_GetAvailableVidMem(IDirectDraw2 *iface,
1309 IDirectDrawImpl *This = impl_from_dd2(iface);
1311 TRACE("(%p)->(%p, %p, %p): Thunking to IDirectDraw4\n", This, Caps, total, free);
1312 memset(&caps2, 0, sizeof(caps2));
1313 caps2.dwCaps = Caps->dwCaps;
1314 return IDirectDraw4_GetAvailableVidMem(dd4_from_impl(This), &caps2, total, free);
1317 static HRESULT WINAPI
1318 IDirectDraw4Impl_GetSurfaceFromDC(IDirectDraw4 *iface,
1320 IDirectDrawSurface4 **Surface)
1322 IDirectDrawImpl *This = impl_from_dd4(iface);
1323 IDirectDrawSurface4 *inner;
1325 TRACE("(%p)->(%p, %p)\n", This, hdc, Surface);
1326 hr = IDirectDraw4_GetSurfaceFromDC(This->parent,hdc, &inner);
1329 *Surface = dds_get_outer(inner);
1330 IDirectDrawSurface4_AddRef(*Surface);
1331 IDirectDrawSurface4_Release(inner);
1341 static HRESULT WINAPI
1342 IDirectDraw3Impl_GetSurfaceFromDC(IDirectDraw3 *iface,
1344 IDirectDrawSurface **Surface)
1346 IDirectDrawImpl *This = impl_from_dd3(iface);
1347 IDirectDrawSurface4 *surf4;
1349 TRACE("(%p)->(%p, %p): Thunking to IDirectDraw4\n", This, hdc, Surface);
1351 hr = IDirectDraw4_GetSurfaceFromDC(dd4_from_impl(This), hdc, &surf4);
1357 IDirectDrawSurface4_QueryInterface(surf4, &IID_IDirectDrawSurface, (void **) Surface);
1358 IDirectDrawSurface4_Release(surf4);
1362 static HRESULT WINAPI
1363 IDirectDraw4Impl_RestoreAllSurfaces(IDirectDraw4 *iface)
1365 IDirectDrawImpl *This = impl_from_dd4(iface);
1366 TRACE("(%p)\n", This);
1367 return IDirectDraw4_RestoreAllSurfaces(This->parent);
1370 static HRESULT WINAPI
1371 IDirectDraw4Impl_TestCooperativeLevel(IDirectDraw4 *iface)
1373 IDirectDrawImpl *This = impl_from_dd4(iface);
1374 TRACE("(%p)\n", This);
1375 return IDirectDraw4_TestCooperativeLevel(This->parent);
1378 static HRESULT WINAPI
1379 IDirectDraw4Impl_GetDeviceIdentifier(IDirectDraw4 *iface,
1380 DDDEVICEIDENTIFIER *DDDI,
1383 IDirectDrawImpl *This = impl_from_dd4(iface);
1384 TRACE("(%p)->(%p,0x%08x)\n", This, DDDI, Flags);
1385 return IDirectDraw4_GetDeviceIdentifier(This->parent, DDDI, Flags);
1388 static const IDirectDrawVtbl IDirectDraw1_Vtbl =
1390 IDirectDrawImpl_QueryInterface,
1391 IDirectDrawImpl_AddRef,
1392 IDirectDrawImpl_Release,
1393 IDirectDrawImpl_Compact,
1394 IDirectDrawImpl_CreateClipper,
1395 IDirectDrawImpl_CreatePalette,
1396 IDirectDrawImpl_CreateSurface,
1397 IDirectDrawImpl_DuplicateSurface,
1398 IDirectDrawImpl_EnumDisplayModes,
1399 IDirectDrawImpl_EnumSurfaces,
1400 IDirectDrawImpl_FlipToGDISurface,
1401 IDirectDrawImpl_GetCaps,
1402 IDirectDrawImpl_GetDisplayMode,
1403 IDirectDrawImpl_GetFourCCCodes,
1404 IDirectDrawImpl_GetGDISurface,
1405 IDirectDrawImpl_GetMonitorFrequency,
1406 IDirectDrawImpl_GetScanLine,
1407 IDirectDrawImpl_GetVerticalBlankStatus,
1408 IDirectDrawImpl_Initialize,
1409 IDirectDrawImpl_RestoreDisplayMode,
1410 IDirectDrawImpl_SetCooperativeLevel,
1411 IDirectDrawImpl_SetDisplayMode,
1412 IDirectDrawImpl_WaitForVerticalBlank,
1415 static const IDirectDraw2Vtbl IDirectDraw2_Vtbl =
1417 IDirectDraw2Impl_QueryInterface,
1418 IDirectDraw2Impl_AddRef,
1419 IDirectDraw2Impl_Release,
1420 IDirectDraw2Impl_Compact,
1421 IDirectDraw2Impl_CreateClipper,
1422 IDirectDraw2Impl_CreatePalette,
1423 IDirectDraw2Impl_CreateSurface,
1424 IDirectDraw2Impl_DuplicateSurface,
1425 IDirectDraw2Impl_EnumDisplayModes,
1426 IDirectDraw2Impl_EnumSurfaces,
1427 IDirectDraw2Impl_FlipToGDISurface,
1428 IDirectDraw2Impl_GetCaps,
1429 IDirectDraw2Impl_GetDisplayMode,
1430 IDirectDraw2Impl_GetFourCCCodes,
1431 IDirectDraw2Impl_GetGDISurface,
1432 IDirectDraw2Impl_GetMonitorFrequency,
1433 IDirectDraw2Impl_GetScanLine,
1434 IDirectDraw2Impl_GetVerticalBlankStatus,
1435 IDirectDraw2Impl_Initialize,
1436 IDirectDraw2Impl_RestoreDisplayMode,
1437 IDirectDraw2Impl_SetCooperativeLevel,
1438 IDirectDraw2Impl_SetDisplayMode,
1439 IDirectDraw2Impl_WaitForVerticalBlank,
1440 IDirectDraw2Impl_GetAvailableVidMem
1443 static const IDirectDraw3Vtbl IDirectDraw3_Vtbl =
1445 IDirectDraw3Impl_QueryInterface,
1446 IDirectDraw3Impl_AddRef,
1447 IDirectDraw3Impl_Release,
1448 IDirectDraw3Impl_Compact,
1449 IDirectDraw3Impl_CreateClipper,
1450 IDirectDraw3Impl_CreatePalette,
1451 IDirectDraw3Impl_CreateSurface,
1452 IDirectDraw3Impl_DuplicateSurface,
1453 IDirectDraw3Impl_EnumDisplayModes,
1454 IDirectDraw3Impl_EnumSurfaces,
1455 IDirectDraw3Impl_FlipToGDISurface,
1456 IDirectDraw3Impl_GetCaps,
1457 IDirectDraw3Impl_GetDisplayMode,
1458 IDirectDraw3Impl_GetFourCCCodes,
1459 IDirectDraw3Impl_GetGDISurface,
1460 IDirectDraw3Impl_GetMonitorFrequency,
1461 IDirectDraw3Impl_GetScanLine,
1462 IDirectDraw3Impl_GetVerticalBlankStatus,
1463 IDirectDraw3Impl_Initialize,
1464 IDirectDraw3Impl_RestoreDisplayMode,
1465 IDirectDraw3Impl_SetCooperativeLevel,
1466 IDirectDraw3Impl_SetDisplayMode,
1467 IDirectDraw3Impl_WaitForVerticalBlank,
1468 IDirectDraw3Impl_GetAvailableVidMem,
1469 IDirectDraw3Impl_GetSurfaceFromDC,
1472 static const IDirectDraw4Vtbl IDirectDraw4_Vtbl =
1474 IDirectDraw4Impl_QueryInterface,
1475 IDirectDraw4Impl_AddRef,
1476 IDirectDraw4Impl_Release,
1477 IDirectDraw4Impl_Compact,
1478 IDirectDraw4Impl_CreateClipper,
1479 IDirectDraw4Impl_CreatePalette,
1480 IDirectDraw4Impl_CreateSurface,
1481 IDirectDraw4Impl_DuplicateSurface,
1482 IDirectDraw4Impl_EnumDisplayModes,
1483 IDirectDraw4Impl_EnumSurfaces,
1484 IDirectDraw4Impl_FlipToGDISurface,
1485 IDirectDraw4Impl_GetCaps,
1486 IDirectDraw4Impl_GetDisplayMode,
1487 IDirectDraw4Impl_GetFourCCCodes,
1488 IDirectDraw4Impl_GetGDISurface,
1489 IDirectDraw4Impl_GetMonitorFrequency,
1490 IDirectDraw4Impl_GetScanLine,
1491 IDirectDraw4Impl_GetVerticalBlankStatus,
1492 IDirectDraw4Impl_Initialize,
1493 IDirectDraw4Impl_RestoreDisplayMode,
1494 IDirectDraw4Impl_SetCooperativeLevel,
1495 IDirectDraw4Impl_SetDisplayMode,
1496 IDirectDraw4Impl_WaitForVerticalBlank,
1497 IDirectDraw4Impl_GetAvailableVidMem,
1498 IDirectDraw4Impl_GetSurfaceFromDC,
1499 IDirectDraw4Impl_RestoreAllSurfaces,
1500 IDirectDraw4Impl_TestCooperativeLevel,
1501 IDirectDraw4Impl_GetDeviceIdentifier
1504 /*******************************************************************************
1505 * IDirectDrawFactoryImpl_CreateDirectDraw
1506 *******************************************************************************/
1508 IDirectDrawFactoryImpl_CreateDirectDraw(IDirectDrawFactory* iface,
1511 DWORD dwCoopLevelFlags,
1513 IUnknown *pUnkOuter,
1514 IDirectDraw **ppDirectDraw)
1517 IDirectDrawImpl *object = NULL;
1518 IDirectDraw *parent = NULL;
1520 TRACE("(%p)->(%s,%p,0x%08x,0x%08x,%p,%p)\n", iface, debugstr_guid(pGUID), hWnd, dwCoopLevelFlags,
1521 dwReserved, pUnkOuter, ppDirectDraw);
1525 FIXME("Implement aggregation in ddrawex's IDirectDraw interface\n");
1528 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1531 ERR("Out of memory\n");
1536 object->IDirectDraw_Vtbl = &IDirectDraw1_Vtbl;
1537 object->IDirectDraw2_Vtbl = &IDirectDraw2_Vtbl;
1538 object->IDirectDraw3_Vtbl = &IDirectDraw3_Vtbl;
1539 object->IDirectDraw4_Vtbl = &IDirectDraw4_Vtbl;
1541 hr = DirectDrawCreate(pGUID, &parent, NULL);
1542 if (FAILED(hr)) goto err;
1544 hr = IDirectDraw_QueryInterface(parent, &IID_IDirectDraw4, (void **) &object->parent);
1545 if(FAILED(hr)) goto err;
1547 hr = IDirectDraw_SetCooperativeLevel(dd1_from_impl(object), hWnd, dwCoopLevelFlags);
1548 if (FAILED(hr)) goto err;
1550 *ppDirectDraw = dd1_from_impl(object);
1551 IDirectDraw_Release(parent);
1555 if(object && object->parent) IDirectDraw4_Release(object->parent);
1556 if(parent) IDirectDraw_Release(parent);
1557 HeapFree(GetProcessHeap(), 0, object);
1558 *ppDirectDraw = NULL;
1562 IDirectDraw4 *dd_get_inner(IDirectDraw4 *outer)
1564 IDirectDrawImpl *This = impl_from_dd4(outer);
1565 return This->parent;