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_IDirectDraw(IDirectDraw *iface)
40 return CONTAINING_RECORD(iface, IDirectDrawImpl, IDirectDraw_iface);
43 static IDirectDrawImpl *impl_from_IDirectDraw2(IDirectDraw2 *iface)
45 return CONTAINING_RECORD(iface, IDirectDrawImpl, IDirectDraw2_iface);
48 static IDirectDrawImpl *impl_from_IDirectDraw3(IDirectDraw3 *iface)
50 return CONTAINING_RECORD(iface, IDirectDrawImpl, IDirectDraw3_iface);
53 static IDirectDrawImpl *impl_from_IDirectDraw4(IDirectDraw4 *iface)
55 return CONTAINING_RECORD(iface, IDirectDrawImpl, IDirectDraw4_iface);
58 /******************************************************************************
59 * IDirectDraw4 -> ddraw.dll wrappers
60 ******************************************************************************/
61 static HRESULT WINAPI IDirectDraw4Impl_QueryInterface(IDirectDraw4 *iface, REFIID refiid,
64 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
66 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(refiid), obj);
71 return DDERR_INVALIDPARAMS;
74 if (IsEqualGUID( &IID_IDirectDraw7, refiid ) )
76 WARN("IDirectDraw7 not allowed in ddrawex.dll\n");
79 else if ( IsEqualGUID( &IID_IUnknown, refiid ) ||
80 IsEqualGUID( &IID_IDirectDraw4, refiid ) )
82 *obj = &This->IDirectDraw4_iface;
83 TRACE("(%p) Returning IDirectDraw4 interface at %p\n", This, *obj);
84 IDirectDraw4_AddRef(&This->IDirectDraw4_iface);
86 else if ( IsEqualGUID( &IID_IDirectDraw3, refiid ) )
88 *obj = &This->IDirectDraw3_iface;
89 TRACE("(%p) Returning IDirectDraw3 interface at %p\n", This, *obj);
90 IDirectDraw3_AddRef(&This->IDirectDraw3_iface);
92 else if ( IsEqualGUID( &IID_IDirectDraw2, refiid ) )
94 *obj = &This->IDirectDraw2_iface;
95 TRACE("(%p) Returning IDirectDraw2 interface at %p\n", This, *obj);
96 IDirectDraw2_AddRef(&This->IDirectDraw2_iface);
98 else if ( IsEqualGUID( &IID_IDirectDraw, refiid ) )
100 *obj = &This->IDirectDraw_iface;
101 TRACE("(%p) Returning IDirectDraw interface at %p\n", This, *obj);
102 IDirectDraw_AddRef(&This->IDirectDraw_iface);
104 else if ( IsEqualGUID( &IID_IDirect3D , refiid ) ||
105 IsEqualGUID( &IID_IDirect3D2 , refiid ) ||
106 IsEqualGUID( &IID_IDirect3D3 , refiid ) ||
107 IsEqualGUID( &IID_IDirect3D7 , refiid ) )
109 WARN("Direct3D not allowed in ddrawex.dll\n");
110 return E_NOINTERFACE;
112 /* Unknown interface */
115 ERR("(%p)->(%s, %p): No interface found\n", This, debugstr_guid(refiid), obj);
116 return E_NOINTERFACE;
118 TRACE("Returning S_OK\n");
122 static HRESULT WINAPI IDirectDraw3Impl_QueryInterface(IDirectDraw3 *iface, REFIID refiid,
125 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
126 TRACE("Thunking to IDirectDraw4\n");
127 return IDirectDraw4_QueryInterface(&This->IDirectDraw4_iface, refiid, obj);
130 static HRESULT WINAPI IDirectDraw2Impl_QueryInterface(IDirectDraw2 *iface, REFIID refiid,
133 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
134 TRACE("Thunking to IDirectDraw4\n");
135 return IDirectDraw4_QueryInterface(&This->IDirectDraw4_iface, refiid, obj);
138 static HRESULT WINAPI IDirectDrawImpl_QueryInterface(IDirectDraw *iface, REFIID refiid, void **obj)
140 IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
141 TRACE("Thunking to IDirectDraw4\n");
142 return IDirectDraw4_QueryInterface(&This->IDirectDraw4_iface, refiid, obj);
145 static ULONG WINAPI IDirectDraw4Impl_AddRef(IDirectDraw4 *iface)
147 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
148 ULONG ref = InterlockedIncrement(&This->ref);
150 TRACE("(%p) : incrementing refcount from %u.\n", This, ref - 1);
155 static ULONG WINAPI IDirectDraw3Impl_AddRef(IDirectDraw3 *iface)
157 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
158 TRACE("Thunking to IDirectDraw4\n");
159 return IDirectDraw4_AddRef(&This->IDirectDraw4_iface);
162 static ULONG WINAPI IDirectDraw2Impl_AddRef(IDirectDraw2 *iface)
164 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
165 TRACE("Thunking to IDirectDraw4\n");
166 return IDirectDraw4_AddRef(&This->IDirectDraw4_iface);
169 static ULONG WINAPI IDirectDrawImpl_AddRef(IDirectDraw *iface)
171 IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
172 TRACE("Thunking to IDirectDraw4\n");
173 return IDirectDraw4_AddRef(&This->IDirectDraw4_iface);
176 static ULONG WINAPI IDirectDraw4Impl_Release(IDirectDraw4 *iface)
178 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
179 ULONG ref = InterlockedDecrement(&This->ref);
181 TRACE("(%p) : decrementing refcount to %u.\n", This, ref);
185 TRACE("Destroying object\n");
186 IDirectDraw4_Release(This->parent);
187 HeapFree(GetProcessHeap(), 0, This);
192 static ULONG WINAPI IDirectDraw3Impl_Release(IDirectDraw3 *iface)
194 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
195 TRACE("Thunking to IDirectDraw4\n");
196 return IDirectDraw4_Release(&This->IDirectDraw4_iface);
199 static ULONG WINAPI IDirectDraw2Impl_Release(IDirectDraw2 *iface)
201 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
202 TRACE("Thunking to IDirectDraw4\n");
203 return IDirectDraw4_Release(&This->IDirectDraw4_iface);
206 static ULONG WINAPI IDirectDrawImpl_Release(IDirectDraw *iface)
208 IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
209 TRACE("Thunking to IDirectDraw4\n");
210 return IDirectDraw4_Release(&This->IDirectDraw4_iface);
213 static HRESULT WINAPI IDirectDraw4Impl_Compact(IDirectDraw4 *iface)
215 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
216 TRACE("(%p)\n", This);
218 return IDirectDraw4_Compact(This->parent);
221 static HRESULT WINAPI IDirectDraw3Impl_Compact(IDirectDraw3 *iface)
223 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
224 TRACE("Thunking to IDirectDraw4\n");
225 return IDirectDraw4_Compact(&This->IDirectDraw4_iface);
228 static HRESULT WINAPI IDirectDraw2Impl_Compact(IDirectDraw2 *iface)
230 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
231 TRACE("Thunking to IDirectDraw4\n");
232 return IDirectDraw4_Compact(&This->IDirectDraw4_iface);
235 static HRESULT WINAPI IDirectDrawImpl_Compact(IDirectDraw *iface)
237 IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
238 TRACE("Thunking to IDirectDraw4\n");
239 return IDirectDraw4_Compact(&This->IDirectDraw4_iface);
242 static HRESULT WINAPI IDirectDraw4Impl_CreateClipper(IDirectDraw4 *iface, DWORD Flags,
243 IDirectDrawClipper **clipper, IUnknown *UnkOuter)
245 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
246 TRACE("(%p)->(0x%08x, %p, %p)\n", This, Flags, clipper, UnkOuter);
250 /* This may require a wrapper interface for clippers too which handles this */
251 FIXME("Test and implement Aggregation for ddrawex clippers\n");
254 return IDirectDraw4_CreateClipper(This->parent, Flags, clipper, UnkOuter);
257 static HRESULT WINAPI IDirectDraw3Impl_CreateClipper(IDirectDraw3 *iface, DWORD Flags,
258 IDirectDrawClipper **clipper, IUnknown *UnkOuter)
260 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
261 TRACE("Thunking to IDirectDraw4\n");
262 return IDirectDraw4_CreateClipper(&This->IDirectDraw4_iface, Flags, clipper, UnkOuter);
265 static HRESULT WINAPI IDirectDraw2Impl_CreateClipper(IDirectDraw2 *iface, DWORD Flags,
266 IDirectDrawClipper **clipper, IUnknown *UnkOuter)
268 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
269 TRACE("Thunking to IDirectDraw4\n");
270 return IDirectDraw4_CreateClipper(&This->IDirectDraw4_iface, Flags, clipper, UnkOuter);
273 static HRESULT WINAPI IDirectDrawImpl_CreateClipper(IDirectDraw *iface, DWORD Flags,
274 IDirectDrawClipper **clipper, IUnknown *UnkOuter)
276 IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
277 TRACE("Thunking to IDirectDraw4\n");
278 return IDirectDraw4_CreateClipper(&This->IDirectDraw4_iface, Flags, clipper, UnkOuter);
281 static HRESULT WINAPI IDirectDraw4Impl_CreatePalette(IDirectDraw4 *iface, DWORD Flags,
282 PALETTEENTRY *ColorTable, IDirectDrawPalette **Palette, IUnknown *UnkOuter)
284 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
285 TRACE("(%p)(0x%08x,%p,%p,%p)\n", This, Flags, ColorTable, Palette, UnkOuter);
289 /* This may require a wrapper interface for palettes too which handles this */
290 FIXME("Test and implement Aggregation for ddrawex palettes\n");
293 return IDirectDraw4_CreatePalette(This->parent, Flags, ColorTable, Palette, UnkOuter);
296 static HRESULT WINAPI IDirectDraw3Impl_CreatePalette(IDirectDraw3 *iface, DWORD Flags,
297 PALETTEENTRY *ColorTable, IDirectDrawPalette **Palette, IUnknown *UnkOuter)
299 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
300 TRACE("Thunking to IDirectDraw4\n");
301 return IDirectDraw4_CreatePalette(&This->IDirectDraw4_iface, Flags, ColorTable, Palette,
305 static HRESULT WINAPI IDirectDraw2Impl_CreatePalette(IDirectDraw2 *iface, DWORD Flags,
306 PALETTEENTRY *ColorTable, IDirectDrawPalette **Palette, IUnknown *UnkOuter)
308 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
309 TRACE("Thunking to IDirectDraw4\n");
310 return IDirectDraw4_CreatePalette(&This->IDirectDraw4_iface, Flags, ColorTable, Palette,
314 static HRESULT WINAPI IDirectDrawImpl_CreatePalette(IDirectDraw *iface, DWORD Flags,
315 PALETTEENTRY *ColorTable, IDirectDrawPalette **Palette, IUnknown *UnkOuter)
317 IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
318 TRACE("Thunking to IDirectDraw4\n");
319 return IDirectDraw4_CreatePalette(&This->IDirectDraw4_iface, Flags, ColorTable, Palette,
323 static HRESULT WINAPI IDirectDraw4Impl_CreateSurface(IDirectDraw4 *iface, DDSURFACEDESC2 *DDSD,
324 IDirectDrawSurface4 **Surf, IUnknown *UnkOuter)
326 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
328 const DWORD perm_dc_flags = DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
330 TRACE("(%p)(%p, %p, %p)\n", This, DDSD, Surf, UnkOuter);
334 /* Handle this in this dll. Don't forward the UnkOuter to ddraw.dll */
335 FIXME("Implement aggregation for ddrawex surfaces\n");
338 /* plain ddraw.dll refuses to create a surface that has both VIDMEM and SYSMEM flags
339 * set. In ddrawex this succeeds, and the GetDC() call changes the behavior. The DC
340 * is permanently valid, and the surface can be locked between GetDC() and ReleaseDC()
341 * calls. GetDC() can be called more than once too
343 if((DDSD->ddsCaps.dwCaps & perm_dc_flags) == perm_dc_flags)
346 DDSD->ddsCaps.dwCaps &= ~DDSCAPS_VIDEOMEMORY;
347 DDSD->ddsCaps.dwCaps |= DDSCAPS_OWNDC;
351 permanent_dc = FALSE;
354 hr = IDirectDraw4_CreateSurface(This->parent, DDSD, Surf, UnkOuter);
355 *Surf = dds_get_outer(*Surf);
356 if(permanent_dc) prepare_permanent_dc(*Surf);
360 void DDSD_to_DDSD2(const DDSURFACEDESC *in, DDSURFACEDESC2 *out)
362 memset(out, 0, sizeof(*out));
363 out->dwSize = sizeof(*out);
364 out->dwFlags = in->dwFlags;
365 if(in->dwFlags & DDSD_WIDTH) out->dwWidth = in->dwWidth;
366 if(in->dwFlags & DDSD_HEIGHT) out->dwHeight = in->dwHeight;
367 if(in->dwFlags & DDSD_PIXELFORMAT) out->u4.ddpfPixelFormat = in->ddpfPixelFormat;
368 if(in->dwFlags & DDSD_CAPS) out->ddsCaps.dwCaps = in->ddsCaps.dwCaps;
369 if(in->dwFlags & DDSD_PITCH) out->u1.lPitch = in->u1.lPitch;
370 if(in->dwFlags & DDSD_BACKBUFFERCOUNT) out->dwBackBufferCount = in->dwBackBufferCount;
371 if(in->dwFlags & DDSD_ZBUFFERBITDEPTH) out->u2.dwMipMapCount = in->u2.dwZBufferBitDepth; /* same union */
372 if(in->dwFlags & DDSD_ALPHABITDEPTH) out->dwAlphaBitDepth = in->dwAlphaBitDepth;
373 /* DDraw(native, and wine) does not set the DDSD_LPSURFACE, so always copy */
374 out->lpSurface = in->lpSurface;
375 if(in->dwFlags & DDSD_CKDESTOVERLAY) out->u3.ddckCKDestOverlay = in->ddckCKDestOverlay;
376 if(in->dwFlags & DDSD_CKDESTBLT) out->ddckCKDestBlt = in->ddckCKDestBlt;
377 if(in->dwFlags & DDSD_CKSRCOVERLAY) out->ddckCKSrcOverlay = in->ddckCKSrcOverlay;
378 if(in->dwFlags & DDSD_CKSRCBLT) out->ddckCKSrcBlt = in->ddckCKSrcBlt;
379 if(in->dwFlags & DDSD_MIPMAPCOUNT) out->u2.dwMipMapCount = in->u2.dwMipMapCount;
380 if(in->dwFlags & DDSD_REFRESHRATE) out->u2.dwRefreshRate = in->u2.dwRefreshRate;
381 if(in->dwFlags & DDSD_LINEARSIZE) out->u1.dwLinearSize = in->u1.dwLinearSize;
382 /* Does not exist in DDSURFACEDESC:
383 * DDSD_TEXTURESTAGE, DDSD_FVF, DDSD_SRCVBHANDLE,
387 void DDSD2_to_DDSD(const DDSURFACEDESC2 *in, DDSURFACEDESC *out)
389 memset(out, 0, sizeof(*out));
390 out->dwSize = sizeof(*out);
391 out->dwFlags = in->dwFlags;
392 if(in->dwFlags & DDSD_WIDTH) out->dwWidth = in->dwWidth;
393 if(in->dwFlags & DDSD_HEIGHT) out->dwHeight = in->dwHeight;
394 if(in->dwFlags & DDSD_PIXELFORMAT) out->ddpfPixelFormat = in->u4.ddpfPixelFormat;
395 if(in->dwFlags & DDSD_CAPS) out->ddsCaps.dwCaps = in->ddsCaps.dwCaps;
396 if(in->dwFlags & DDSD_PITCH) out->u1.lPitch = in->u1.lPitch;
397 if(in->dwFlags & DDSD_BACKBUFFERCOUNT) out->dwBackBufferCount = in->dwBackBufferCount;
398 if(in->dwFlags & DDSD_ZBUFFERBITDEPTH) out->u2.dwZBufferBitDepth = in->u2.dwMipMapCount; /* same union */
399 if(in->dwFlags & DDSD_ALPHABITDEPTH) out->dwAlphaBitDepth = in->dwAlphaBitDepth;
400 /* DDraw(native, and wine) does not set the DDSD_LPSURFACE, so always copy */
401 out->lpSurface = in->lpSurface;
402 if(in->dwFlags & DDSD_CKDESTOVERLAY) out->ddckCKDestOverlay = in->u3.ddckCKDestOverlay;
403 if(in->dwFlags & DDSD_CKDESTBLT) out->ddckCKDestBlt = in->ddckCKDestBlt;
404 if(in->dwFlags & DDSD_CKSRCOVERLAY) out->ddckCKSrcOverlay = in->ddckCKSrcOverlay;
405 if(in->dwFlags & DDSD_CKSRCBLT) out->ddckCKSrcBlt = in->ddckCKSrcBlt;
406 if(in->dwFlags & DDSD_MIPMAPCOUNT) out->u2.dwMipMapCount = in->u2.dwMipMapCount;
407 if(in->dwFlags & DDSD_REFRESHRATE) out->u2.dwRefreshRate = in->u2.dwRefreshRate;
408 if(in->dwFlags & DDSD_LINEARSIZE) out->u1.dwLinearSize = in->u1.dwLinearSize;
409 /* Does not exist in DDSURFACEDESC:
410 * DDSD_TEXTURESTAGE, DDSD_FVF, DDSD_SRCVBHANDLE,
412 if(in->dwFlags & DDSD_TEXTURESTAGE) WARN("Does not exist in DDSURFACEDESC: DDSD_TEXTURESTAGE\n");
413 if(in->dwFlags & DDSD_FVF) WARN("Does not exist in DDSURFACEDESC: DDSD_FVF\n");
414 if(in->dwFlags & DDSD_SRCVBHANDLE) WARN("Does not exist in DDSURFACEDESC: DDSD_SRCVBHANDLE\n");
415 out->dwFlags &= ~(DDSD_TEXTURESTAGE | DDSD_FVF | DDSD_SRCVBHANDLE);
418 static HRESULT WINAPI IDirectDraw3Impl_CreateSurface(IDirectDraw3 *iface, DDSURFACEDESC *DDSD,
419 IDirectDrawSurface **Surf, IUnknown *UnkOuter)
421 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
422 DDSURFACEDESC2 ddsd2;
423 IDirectDrawSurface4 *surf4 = NULL;
425 TRACE("Thunking to IDirectDraw4\n");
427 DDSD_to_DDSD2(DDSD, &ddsd2);
429 hr = IDirectDraw4_CreateSurface(&This->IDirectDraw4_iface, &ddsd2, &surf4, UnkOuter);
436 TRACE("Got surface %p\n", surf4);
437 IDirectDrawSurface4_QueryInterface(surf4, &IID_IDirectDrawSurface, (void **) Surf);
438 IDirectDrawSurface4_Release(surf4);
442 static HRESULT WINAPI IDirectDraw2Impl_CreateSurface(IDirectDraw2 *iface, DDSURFACEDESC *DDSD,
443 IDirectDrawSurface **Surf, IUnknown *UnkOuter)
445 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
446 TRACE("Thunking to IDirectDraw3\n");
447 return IDirectDraw3_CreateSurface(&This->IDirectDraw3_iface, DDSD, Surf, UnkOuter);
450 static HRESULT WINAPI IDirectDrawImpl_CreateSurface(IDirectDraw *iface, DDSURFACEDESC *DDSD,
451 IDirectDrawSurface **Surf, IUnknown *UnkOuter)
453 IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
454 TRACE("Thunking to IDirectDraw3\n");
455 return IDirectDraw3_CreateSurface(&This->IDirectDraw3_iface, DDSD, Surf, UnkOuter);
458 static HRESULT WINAPI IDirectDraw4Impl_DuplicateSurface(IDirectDraw4 *iface,
459 IDirectDrawSurface4 *src, IDirectDrawSurface4 **dst)
461 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
462 IDirectDrawSurfaceImpl *surf = unsafe_impl_from_IDirectDrawSurface4(src);
464 FIXME("(%p)->(%p,%p). Create a wrapper surface\n", This, src, dst);
466 return IDirectDraw4_DuplicateSurface(This->parent, surf ? surf->parent : NULL, dst);
469 static HRESULT WINAPI IDirectDraw3Impl_DuplicateSurface(IDirectDraw3 *iface,
470 IDirectDrawSurface *src, IDirectDrawSurface **dst)
472 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
473 IDirectDrawSurface4 *src_4;
474 IDirectDrawSurface4 *dst_4;
477 TRACE("Thunking to IDirectDraw4\n");
478 IDirectDrawSurface_QueryInterface(src, &IID_IDirectDrawSurface4, (void **) &src_4);
479 hr = IDirectDraw4_DuplicateSurface(&This->IDirectDraw4_iface, src_4, &dst_4);
480 IDirectDrawSurface4_Release(src_4);
487 IDirectDrawSurface4_QueryInterface(dst_4, &IID_IDirectDrawSurface, (void **) dst);
488 IDirectDrawSurface4_Release(dst_4);
492 static HRESULT WINAPI IDirectDraw2Impl_DuplicateSurface(IDirectDraw2 *iface,
493 IDirectDrawSurface *src, IDirectDrawSurface **dst)
495 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
496 TRACE("Thunking to IDirectDraw3\n");
497 return IDirectDraw3_DuplicateSurface(&This->IDirectDraw3_iface, src, dst);
500 static HRESULT WINAPI IDirectDrawImpl_DuplicateSurface(IDirectDraw *iface, IDirectDrawSurface *src,
501 IDirectDrawSurface **dst)
503 IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
504 TRACE("Thunking to IDirectDraw3\n");
505 return IDirectDraw3_DuplicateSurface(&This->IDirectDraw3_iface, src, dst);
508 static HRESULT WINAPI IDirectDraw4Impl_EnumDisplayModes(IDirectDraw4 *iface, DWORD Flags,
509 DDSURFACEDESC2 *DDSD, void *Context, LPDDENUMMODESCALLBACK2 cb)
511 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
512 TRACE("(%p)->(0x%08x,%p,%p,%p)\n", This, Flags, DDSD, Context, cb);
514 return IDirectDraw4_EnumDisplayModes(This->parent, Flags, DDSD, Context, cb);
519 LPDDENUMMODESCALLBACK orig_cb;
523 static HRESULT WINAPI
524 enum_modes_cb2(DDSURFACEDESC2 *ddsd2, void *vctx)
526 struct enummodes_ctx *ctx = vctx;
529 DDSD2_to_DDSD(ddsd2, &ddsd);
530 return ctx->orig_cb(&ddsd, ctx->orig_ctx);
533 static HRESULT WINAPI IDirectDraw3Impl_EnumDisplayModes(IDirectDraw3 *iface, DWORD Flags,
534 DDSURFACEDESC *DDSD, void *Context, LPDDENUMMODESCALLBACK cb)
536 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
537 DDSURFACEDESC2 ddsd2;
538 struct enummodes_ctx ctx;
539 TRACE("(%p)->(0x%08x,%p,%p,%p): Thunking to IDirectDraw4\n", This, Flags, DDSD, Context, cb);
541 DDSD_to_DDSD2(DDSD, &ddsd2);
543 ctx.orig_ctx = Context;
544 return IDirectDraw4_EnumDisplayModes(&This->IDirectDraw4_iface, Flags, &ddsd2, &ctx,
548 static HRESULT WINAPI IDirectDraw2Impl_EnumDisplayModes(IDirectDraw2 *iface, DWORD Flags,
549 DDSURFACEDESC *DDSD, void *Context, LPDDENUMMODESCALLBACK cb)
551 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
552 TRACE("(%p)->(0x%08x,%p,%p,%p): Thunking to IDirectDraw3\n", This, Flags, DDSD, Context, cb);
553 return IDirectDraw3_EnumDisplayModes(&This->IDirectDraw3_iface, Flags, DDSD, Context, cb);
556 static HRESULT WINAPI IDirectDrawImpl_EnumDisplayModes(IDirectDraw *iface, DWORD Flags,
557 DDSURFACEDESC *DDSD, void *Context, LPDDENUMMODESCALLBACK cb)
559 IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
560 TRACE("(%p)->(0x%08x,%p,%p,%p): Thunking to IDirectDraw3\n", This, Flags, DDSD, Context, cb);
561 return IDirectDraw3_EnumDisplayModes(&This->IDirectDraw3_iface, Flags, DDSD, Context, cb);
564 struct enumsurfaces4_ctx
566 LPDDENUMSURFACESCALLBACK2 orig_cb;
570 static HRESULT WINAPI
571 enum_surfaces_wrapper(IDirectDrawSurface4 *surf4, DDSURFACEDESC2 *ddsd2, void *vctx)
573 struct enumsurfaces4_ctx *ctx = vctx;
574 IDirectDrawSurface4 *outer = dds_get_outer(surf4);
575 IDirectDrawSurface4_AddRef(outer);
576 IDirectDrawSurface4_Release(surf4);
577 TRACE("Returning wrapper surface %p for enumerated inner surface %p\n", outer, surf4);
578 return ctx->orig_cb(outer, ddsd2, ctx->orig_ctx);
581 static HRESULT WINAPI IDirectDraw4Impl_EnumSurfaces(IDirectDraw4 *iface, DWORD Flags,
582 DDSURFACEDESC2 *DDSD, void *Context, LPDDENUMSURFACESCALLBACK2 Callback)
584 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
585 struct enumsurfaces4_ctx ctx;
586 TRACE("(%p)->(0x%08x,%p,%p,%p)\n", This, Flags, DDSD, Context, Callback);
588 ctx.orig_cb = Callback;
589 ctx.orig_ctx = Context;
590 return IDirectDraw4Impl_EnumSurfaces(This->parent, Flags, DDSD, &ctx, enum_surfaces_wrapper);
593 struct enumsurfaces_ctx
595 LPDDENUMSURFACESCALLBACK orig_cb;
599 static HRESULT WINAPI
600 enum_surfaces_cb2(IDirectDrawSurface4 *surf4, DDSURFACEDESC2 *ddsd2, void *vctx)
602 struct enumsurfaces_ctx *ctx = vctx;
603 IDirectDrawSurface *surf1;
606 /* Keep the reference, it goes to the application */
607 IDirectDrawSurface4_QueryInterface(surf4, &IID_IDirectDrawSurface, (void **) &surf1);
608 /* Release the reference this function got */
609 IDirectDrawSurface4_Release(surf4);
611 DDSD2_to_DDSD(ddsd2, &ddsd);
612 return ctx->orig_cb(surf1, &ddsd, ctx->orig_ctx);
615 static HRESULT WINAPI IDirectDraw3Impl_EnumSurfaces(IDirectDraw3 *iface, DWORD Flags,
616 DDSURFACEDESC *DDSD, void *Context, LPDDENUMSURFACESCALLBACK Callback)
618 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
619 DDSURFACEDESC2 ddsd2;
620 struct enumsurfaces_ctx ctx;
621 TRACE("(%p)->(0x%08x,%p,%p,%p): Thunking to IDirectDraw4\n", This, Flags, DDSD, Context, Callback);
623 DDSD_to_DDSD2(DDSD, &ddsd2);
624 ctx.orig_cb = Callback;
625 ctx.orig_ctx = Context;
626 return IDirectDraw4_EnumSurfaces(&This->IDirectDraw4_iface, Flags, &ddsd2, &ctx,
630 static HRESULT WINAPI IDirectDraw2Impl_EnumSurfaces(IDirectDraw2 *iface, DWORD Flags,
631 DDSURFACEDESC *DDSD, void *Context, LPDDENUMSURFACESCALLBACK Callback)
633 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
634 TRACE("(%p)->(0x%08x,%p,%p,%p): Thunking to IDirectDraw3\n", This, Flags, DDSD, Context, Callback);
635 return IDirectDraw3_EnumSurfaces(&This->IDirectDraw3_iface, Flags, DDSD, Context, Callback);
638 static HRESULT WINAPI IDirectDrawImpl_EnumSurfaces(IDirectDraw *iface, DWORD Flags,
639 DDSURFACEDESC *DDSD, void *Context, LPDDENUMSURFACESCALLBACK Callback)
641 IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
642 TRACE("(%p)->(0x%08x,%p,%p,%p): Thunking to IDirectDraw3\n", This, Flags, DDSD, Context, Callback);
643 return IDirectDraw3_EnumSurfaces(&This->IDirectDraw3_iface, Flags, DDSD, Context, Callback);
646 static HRESULT WINAPI IDirectDraw4Impl_FlipToGDISurface(IDirectDraw4 *iface)
648 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
649 TRACE("(%p)\n", This);
651 return IDirectDraw4_FlipToGDISurface(This->parent);
654 static HRESULT WINAPI IDirectDraw3Impl_FlipToGDISurface(IDirectDraw3 *iface)
656 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
657 TRACE("(%p). Thunking to IDirectDraw4\n", This);
658 return IDirectDraw4_FlipToGDISurface(&This->IDirectDraw4_iface);
661 static HRESULT WINAPI IDirectDraw2Impl_FlipToGDISurface(IDirectDraw2 *iface)
663 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
664 TRACE("(%p). Thunking to IDirectDraw4\n", This);
665 return IDirectDraw4_FlipToGDISurface(&This->IDirectDraw4_iface);
668 static HRESULT WINAPI IDirectDrawImpl_FlipToGDISurface(IDirectDraw *iface)
670 IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
671 TRACE("(%p). Thunking to IDirectDraw4\n", This);
672 return IDirectDraw4_FlipToGDISurface(&This->IDirectDraw4_iface);
675 static HRESULT WINAPI IDirectDraw4Impl_GetCaps(IDirectDraw4 *iface, DDCAPS *DriverCaps,
678 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
679 TRACE("(%p)->(%p,%p)\n", This, DriverCaps, HELCaps);
680 return IDirectDraw4_GetCaps(This->parent, DriverCaps, HELCaps);
683 static HRESULT WINAPI IDirectDraw3Impl_GetCaps(IDirectDraw3 *iface, DDCAPS *DriverCaps,
686 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
687 TRACE("(%p)->(%p,%p). Thunking to IDirectDraw4\n", This, DriverCaps, HELCaps);
688 return IDirectDraw4_GetCaps(&This->IDirectDraw4_iface, DriverCaps, HELCaps);
691 static HRESULT WINAPI IDirectDraw2Impl_GetCaps(IDirectDraw2 *iface, DDCAPS *DriverCaps,
694 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
695 TRACE("(%p)->(%p,%p). Thunking to IDirectDraw4\n", This, DriverCaps, HELCaps);
696 return IDirectDraw4_GetCaps(&This->IDirectDraw4_iface, DriverCaps, HELCaps);
699 static HRESULT WINAPI IDirectDrawImpl_GetCaps(IDirectDraw *iface, DDCAPS *DriverCaps,
702 IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
703 TRACE("(%p)->(%p,%p). Thunking to IDirectDraw4\n", This, DriverCaps, HELCaps);
704 return IDirectDraw4_GetCaps(&This->IDirectDraw4_iface, DriverCaps, HELCaps);
707 static HRESULT WINAPI IDirectDraw4Impl_GetDisplayMode(IDirectDraw4 *iface, DDSURFACEDESC2 *DDSD)
709 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
710 TRACE("(%p)->(%p)\n", This, DDSD);
711 return IDirectDraw4_GetDisplayMode(This->parent, DDSD);
714 static HRESULT WINAPI IDirectDraw3Impl_GetDisplayMode(IDirectDraw3 *iface, DDSURFACEDESC *DDSD)
716 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
717 DDSURFACEDESC2 ddsd2;
720 TRACE("(%p)->(%p): Thunking to IDirectDraw4\n", This, DDSD);
721 hr = IDirectDraw4_GetDisplayMode(&This->IDirectDraw4_iface, &ddsd2);
722 DDSD2_to_DDSD(&ddsd2, DDSD);
726 static HRESULT WINAPI IDirectDraw2Impl_GetDisplayMode(IDirectDraw2 *iface, DDSURFACEDESC *DDSD)
728 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
729 TRACE("(%p)->(%p): Thunking to IDirectDraw3\n", This, DDSD);
730 return IDirectDraw3_GetDisplayMode(&This->IDirectDraw3_iface, DDSD);
733 static HRESULT WINAPI IDirectDrawImpl_GetDisplayMode(IDirectDraw *iface, DDSURFACEDESC *DDSD)
735 IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
736 TRACE("(%p)->(%p): Thunking to IDirectDraw3\n", This, DDSD);
737 return IDirectDraw3_GetDisplayMode(&This->IDirectDraw3_iface, DDSD);
740 static HRESULT WINAPI IDirectDraw4Impl_GetFourCCCodes(IDirectDraw4 *iface, DWORD *NumCodes,
743 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
744 TRACE("(%p)->(%p, %p):\n", This, NumCodes, Codes);
745 return IDirectDraw4_GetFourCCCodes(This->parent, NumCodes, Codes);
748 static HRESULT WINAPI IDirectDraw3Impl_GetFourCCCodes(IDirectDraw3 *iface, DWORD *NumCodes,
751 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
752 TRACE("(%p)->(%p, %p): Thunking to IDirectDraw4\n", This, NumCodes, Codes);
753 return IDirectDraw4_GetFourCCCodes(&This->IDirectDraw4_iface, NumCodes, Codes);
756 static HRESULT WINAPI IDirectDraw2Impl_GetFourCCCodes(IDirectDraw2 *iface, DWORD *NumCodes,
759 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
760 TRACE("(%p)->(%p, %p): Thunking to IDirectDraw4\n", This, NumCodes, Codes);
761 return IDirectDraw4_GetFourCCCodes(&This->IDirectDraw4_iface, NumCodes, Codes);
764 static HRESULT WINAPI IDirectDrawImpl_GetFourCCCodes(IDirectDraw *iface, DWORD *NumCodes,
767 IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
768 TRACE("(%p)->(%p, %p): Thunking to IDirectDraw4\n", This, NumCodes, Codes);
769 return IDirectDraw4_GetFourCCCodes(&This->IDirectDraw4_iface, NumCodes, Codes);
772 static HRESULT WINAPI IDirectDraw4Impl_GetGDISurface(IDirectDraw4 *iface,
773 IDirectDrawSurface4 **GDISurface)
775 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
776 IDirectDrawSurface4 *inner = NULL;
778 TRACE("(%p)->(%p)\n", This, GDISurface);
780 hr = IDirectDraw4_GetGDISurface(This->parent, &inner);
783 *GDISurface = dds_get_outer(inner);
784 IDirectDrawSurface4_AddRef(*GDISurface);
785 IDirectDrawSurface4_Release(inner);
794 static HRESULT WINAPI IDirectDraw3Impl_GetGDISurface(IDirectDraw3 *iface,
795 IDirectDrawSurface **GDISurface)
797 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
798 IDirectDrawSurface4 *surf4;
800 TRACE("(%p)->(%p): Thunking to IDirectDraw4\n", This, GDISurface);
802 hr = IDirectDraw4_GetGDISurface(&This->IDirectDraw4_iface, &surf4);
808 /* Release the reference we got from the DDraw4 call, and pass a reference to the caller */
809 IDirectDrawSurface4_QueryInterface(surf4, &IID_IDirectDrawSurface, (void **) GDISurface);
810 IDirectDrawSurface4_Release(surf4);
814 static HRESULT WINAPI IDirectDraw2Impl_GetGDISurface(IDirectDraw2 *iface,
815 IDirectDrawSurface **GDISurface)
817 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
818 TRACE("(%p)->(%p): Thunking to IDirectDraw3\n", This, GDISurface);
819 return IDirectDraw3_GetGDISurface(&This->IDirectDraw3_iface, GDISurface);
822 static HRESULT WINAPI IDirectDrawImpl_GetGDISurface(IDirectDraw *iface,
823 IDirectDrawSurface **GDISurface)
825 IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
826 TRACE("(%p)->(%p): Thunking to IDirectDraw3\n", This, GDISurface);
827 return IDirectDraw3_GetGDISurface(&This->IDirectDraw3_iface, GDISurface);
830 static HRESULT WINAPI IDirectDraw4Impl_GetMonitorFrequency(IDirectDraw4 *iface, DWORD *Freq)
832 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
833 TRACE("(%p)->(%p)\n", This, Freq);
834 return IDirectDraw4_GetMonitorFrequency(This->parent, Freq);
837 static HRESULT WINAPI IDirectDraw3Impl_GetMonitorFrequency(IDirectDraw3 *iface, DWORD *Freq)
839 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
840 TRACE("(%p)->(%p): Thunking to IDirectDraw4\n", This, Freq);
841 return IDirectDraw4_GetMonitorFrequency(&This->IDirectDraw4_iface, Freq);
844 static HRESULT WINAPI IDirectDraw2Impl_GetMonitorFrequency(IDirectDraw2 *iface, DWORD *Freq)
846 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
847 TRACE("(%p)->(%p): Thunking to IDirectDraw4\n", This, Freq);
848 return IDirectDraw4_GetMonitorFrequency(&This->IDirectDraw4_iface, Freq);
851 static HRESULT WINAPI IDirectDrawImpl_GetMonitorFrequency(IDirectDraw *iface, DWORD *Freq)
853 IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
854 TRACE("(%p)->(%p): Thunking to IDirectDraw4\n", This, Freq);
855 return IDirectDraw4_GetMonitorFrequency(&This->IDirectDraw4_iface, Freq);
858 static HRESULT WINAPI IDirectDraw4Impl_GetScanLine(IDirectDraw4 *iface, DWORD *Scanline)
860 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
861 TRACE("(%p)->(%p)\n", This, Scanline);
862 return IDirectDraw4_GetScanLine(This->parent, Scanline);
865 static HRESULT WINAPI IDirectDraw3Impl_GetScanLine(IDirectDraw3 *iface, DWORD *Scanline)
867 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
868 TRACE("(%p)->(%p): Thunking to IDirectDraw4\n", This, Scanline);
869 return IDirectDraw4_GetScanLine(&This->IDirectDraw4_iface, Scanline);
872 static HRESULT WINAPI IDirectDraw2Impl_GetScanLine(IDirectDraw2 *iface, DWORD *Scanline)
874 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
875 TRACE("(%p)->(%p): Thunking to IDirectDraw4\n", This, Scanline);
876 return IDirectDraw4_GetScanLine(&This->IDirectDraw4_iface, Scanline);
879 static HRESULT WINAPI IDirectDrawImpl_GetScanLine(IDirectDraw *iface, DWORD *Scanline)
881 IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
882 TRACE("(%p)->(%p): Thunking to IDirectDraw4\n", This, Scanline);
883 return IDirectDraw4_GetScanLine(&This->IDirectDraw4_iface, Scanline);
886 static HRESULT WINAPI IDirectDraw4Impl_GetVerticalBlankStatus(IDirectDraw4 *iface, BOOL *status)
888 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
889 TRACE("(%p)->(%p)\n", This, status);
890 return IDirectDraw4_GetVerticalBlankStatus(This->parent, status);
893 static HRESULT WINAPI IDirectDraw3Impl_GetVerticalBlankStatus(IDirectDraw3 *iface, BOOL *status)
895 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
896 TRACE("(%p)->(%p): Thunking to IDirectDraw4\n", This, status);
897 return IDirectDraw4_GetVerticalBlankStatus(&This->IDirectDraw4_iface, status);
900 static HRESULT WINAPI IDirectDraw2Impl_GetVerticalBlankStatus(IDirectDraw2 *iface, BOOL *status)
902 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
903 TRACE("(%p)->(%p): Thunking to IDirectDraw4\n", This, status);
904 return IDirectDraw4_GetVerticalBlankStatus(&This->IDirectDraw4_iface, status);
907 static HRESULT WINAPI IDirectDrawImpl_GetVerticalBlankStatus(IDirectDraw *iface, BOOL *status)
909 IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
910 TRACE("(%p)->(%p): Thunking to IDirectDraw4\n", This, status);
911 return IDirectDraw4_GetVerticalBlankStatus(&This->IDirectDraw4_iface, status);
914 static HRESULT WINAPI IDirectDraw4Impl_Initialize(IDirectDraw4 *iface, GUID *Guid)
916 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
917 TRACE("(%p)->(%s)\n", This, debugstr_guid(Guid));
918 return IDirectDraw4_Initialize(This->parent, Guid);
921 static HRESULT WINAPI IDirectDraw3Impl_Initialize(IDirectDraw3 *iface, GUID *Guid)
923 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
924 TRACE("(%p)->(%s): Thunking to IDirectDraw4\n", This, debugstr_guid(Guid));
925 return IDirectDraw4_Initialize(&This->IDirectDraw4_iface, Guid);
928 static HRESULT WINAPI IDirectDraw2Impl_Initialize(IDirectDraw2 *iface, GUID *Guid)
930 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
931 TRACE("(%p)->(%s): Thunking to IDirectDraw4\n", This, debugstr_guid(Guid));
932 return IDirectDraw4_Initialize(&This->IDirectDraw4_iface, Guid);
935 static HRESULT WINAPI IDirectDrawImpl_Initialize(IDirectDraw *iface, GUID *Guid)
937 IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
938 TRACE("(%p)->(%s): Thunking to IDirectDraw4\n", This, debugstr_guid(Guid));
939 return IDirectDraw4_Initialize(&This->IDirectDraw4_iface, Guid);
942 static HRESULT WINAPI IDirectDraw4Impl_RestoreDisplayMode(IDirectDraw4 *iface)
944 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
945 TRACE("(%p)\n", This);
946 return IDirectDraw4_RestoreDisplayMode(This->parent);
949 static HRESULT WINAPI IDirectDraw3Impl_RestoreDisplayMode(IDirectDraw3 *iface)
951 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
952 TRACE("(%p): Thunking to IDirectDraw4\n", This);
953 return IDirectDraw4_RestoreDisplayMode(&This->IDirectDraw4_iface);
956 static HRESULT WINAPI IDirectDraw2Impl_RestoreDisplayMode(IDirectDraw2 *iface)
958 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
959 TRACE("(%p): Thunking to IDirectDraw4\n", This);
960 return IDirectDraw4_RestoreDisplayMode(&This->IDirectDraw4_iface);
963 static HRESULT WINAPI IDirectDrawImpl_RestoreDisplayMode(IDirectDraw *iface)
965 IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
966 TRACE("(%p): Thunking to IDirectDraw4\n", This);
967 return IDirectDraw4_RestoreDisplayMode(&This->IDirectDraw4_iface);
970 static HRESULT WINAPI IDirectDraw4Impl_SetCooperativeLevel(IDirectDraw4 *iface, HWND hwnd,
973 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
974 TRACE("(%p)->(%p, 0x%08x)\n", This, hwnd, cooplevel);
975 return IDirectDraw4_SetCooperativeLevel(This->parent, hwnd, cooplevel);
978 static HRESULT WINAPI IDirectDraw3Impl_SetCooperativeLevel(IDirectDraw3 *iface, HWND hwnd,
981 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
982 TRACE("(%p)->(%p, 0x%08x): Thunking to IDirectDraw4\n", This, hwnd, cooplevel);
983 return IDirectDraw4_SetCooperativeLevel(&This->IDirectDraw4_iface, hwnd, cooplevel);
986 static HRESULT WINAPI IDirectDraw2Impl_SetCooperativeLevel(IDirectDraw2 *iface, HWND hwnd,
989 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
990 TRACE("(%p)->(%p, 0x%08x): Thunking to IDirectDraw4\n", This, hwnd, cooplevel);
991 return IDirectDraw4_SetCooperativeLevel(&This->IDirectDraw4_iface, hwnd, cooplevel);
994 static HRESULT WINAPI IDirectDrawImpl_SetCooperativeLevel(IDirectDraw *iface, HWND hwnd,
997 IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
998 TRACE("(%p)->(%p, 0x%08x): Thunking to IDirectDraw4\n", This, hwnd, cooplevel);
999 return IDirectDraw4_SetCooperativeLevel(&This->IDirectDraw4_iface, hwnd, cooplevel);
1002 static HRESULT WINAPI IDirectDraw4Impl_SetDisplayMode(IDirectDraw4 *iface, DWORD Width,
1003 DWORD Height, DWORD BPP, DWORD RefreshRate, DWORD Flags)
1005 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
1006 TRACE("(%p)->(%u, %u, %u, %u, 0x%08x)\n", This, Width, Height, BPP, RefreshRate, Flags);
1007 return IDirectDraw4_SetDisplayMode(This->parent, Width, Height, BPP, RefreshRate, Flags);
1010 static HRESULT WINAPI IDirectDraw3Impl_SetDisplayMode(IDirectDraw3 *iface, DWORD Width,
1011 DWORD Height, DWORD BPP, DWORD RefreshRate, DWORD Flags)
1013 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
1014 TRACE("(%p)->(%u, %u, %u, %u, 0x%08x): Thunking to IDirectDraw4\n", This, Width, Height, BPP, RefreshRate, Flags);
1015 return IDirectDraw3_SetDisplayMode(&This->IDirectDraw4_iface, Width, Height, BPP, RefreshRate,
1019 static HRESULT WINAPI IDirectDraw2Impl_SetDisplayMode(IDirectDraw2 *iface, DWORD Width,
1020 DWORD Height, DWORD BPP, DWORD RefreshRate, DWORD Flags)
1022 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
1023 TRACE("(%p)->(%u, %u, %u, %u, 0x%08x): Thunking to IDirectDraw4\n", This, Width, Height, BPP, RefreshRate, Flags);
1024 return IDirectDraw3_SetDisplayMode(&This->IDirectDraw4_iface, Width, Height, BPP, RefreshRate,
1028 static HRESULT WINAPI IDirectDrawImpl_SetDisplayMode(IDirectDraw *iface, DWORD Width, DWORD Height,
1031 IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
1032 TRACE("(%p)->(%u, %u, %u): Thunking to IDirectDraw4\n", This, Width, Height, BPP);
1033 return IDirectDraw3_SetDisplayMode(&This->IDirectDraw4_iface, Width, Height, BPP, 0, 0);
1036 static HRESULT WINAPI IDirectDraw4Impl_WaitForVerticalBlank(IDirectDraw4 *iface, DWORD Flags,
1039 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
1040 TRACE("(%p)->(0x%08x, %p)\n", This, Flags, h);
1041 return IDirectDraw4_WaitForVerticalBlank(This->parent, Flags, h);
1044 static HRESULT WINAPI IDirectDraw3Impl_WaitForVerticalBlank(IDirectDraw3 *iface, DWORD Flags,
1047 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
1048 TRACE("(%p)->(0x%08x, %p): Thunking to IDirectDraw4\n", This, Flags, h);
1049 return IDirectDraw4_WaitForVerticalBlank(&This->IDirectDraw4_iface, Flags, h);
1052 static HRESULT WINAPI IDirectDraw2Impl_WaitForVerticalBlank(IDirectDraw2 *iface, DWORD Flags,
1055 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
1056 TRACE("(%p)->(0x%08x, %p): Thunking to IDirectDraw4\n", This, Flags, h);
1057 return IDirectDraw4_WaitForVerticalBlank(&This->IDirectDraw4_iface, Flags, h);
1060 static HRESULT WINAPI IDirectDrawImpl_WaitForVerticalBlank(IDirectDraw *iface, DWORD Flags,
1063 IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
1064 TRACE("(%p)->(0x%08x, %p): Thunking to IDirectDraw4\n", This, Flags, h);
1065 return IDirectDraw4_WaitForVerticalBlank(&This->IDirectDraw4_iface, Flags, h);
1068 static HRESULT WINAPI IDirectDraw4Impl_GetAvailableVidMem(IDirectDraw4 *iface, DDSCAPS2 *Caps,
1069 DWORD *total, DWORD *free)
1071 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
1072 TRACE("(%p)->(%p, %p, %p)\n", This, Caps, total, free);
1073 return IDirectDraw4_GetAvailableVidMem(This->parent, Caps, total, free);
1076 static HRESULT WINAPI IDirectDraw3Impl_GetAvailableVidMem(IDirectDraw3 *iface, DDSCAPS *Caps,
1077 DWORD *total, DWORD *free)
1079 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
1081 TRACE("(%p)->(%p, %p, %p): Thunking to IDirectDraw4\n", This, Caps, total, free);
1082 memset(&caps2, 0, sizeof(caps2));
1083 caps2.dwCaps = Caps->dwCaps;
1084 return IDirectDraw4_GetAvailableVidMem(&This->IDirectDraw4_iface, &caps2, total, free);
1087 static HRESULT WINAPI IDirectDraw2Impl_GetAvailableVidMem(IDirectDraw2 *iface, DDSCAPS *Caps,
1088 DWORD *total, DWORD *free)
1090 IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
1092 TRACE("(%p)->(%p, %p, %p): Thunking to IDirectDraw4\n", This, Caps, total, free);
1093 memset(&caps2, 0, sizeof(caps2));
1094 caps2.dwCaps = Caps->dwCaps;
1095 return IDirectDraw4_GetAvailableVidMem(&This->IDirectDraw4_iface, &caps2, total, free);
1098 static HRESULT WINAPI IDirectDraw4Impl_GetSurfaceFromDC(IDirectDraw4 *iface, HDC hdc,
1099 IDirectDrawSurface4 **Surface)
1101 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
1103 TRACE("(%p)->(%p, %p)\n", This, hdc, Surface);
1104 hr = IDirectDraw4_GetSurfaceFromDC(This->parent,hdc, Surface);
1109 static HRESULT WINAPI IDirectDraw3Impl_GetSurfaceFromDC(IDirectDraw3 *iface, HDC hdc,
1110 IDirectDrawSurface **Surface)
1112 IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
1113 IDirectDrawSurface4 *surf4, *outer;
1114 IDirectDrawSurface *inner;
1116 TRACE("(%p)->(%p, %p): Thunking to IDirectDraw4\n", This, hdc, Surface);
1118 if (!Surface) return E_POINTER;
1120 hr = IDirectDraw4_GetSurfaceFromDC(This->parent, hdc, (IDirectDrawSurface4 **)&inner);
1127 hr = IDirectDrawSurface_QueryInterface(inner, &IID_IDirectDrawSurface4, (void **)&surf4);
1128 IDirectDrawSurface_Release(inner);
1135 outer = dds_get_outer(surf4);
1136 hr = IDirectDrawSurface4_QueryInterface(outer, &IID_IDirectDrawSurface, (void **)Surface);
1137 IDirectDrawSurface4_Release(surf4);
1141 static HRESULT WINAPI IDirectDraw4Impl_RestoreAllSurfaces(IDirectDraw4 *iface)
1143 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
1144 TRACE("(%p)\n", This);
1145 return IDirectDraw4_RestoreAllSurfaces(This->parent);
1148 static HRESULT WINAPI IDirectDraw4Impl_TestCooperativeLevel(IDirectDraw4 *iface)
1150 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
1151 TRACE("(%p)\n", This);
1152 return IDirectDraw4_TestCooperativeLevel(This->parent);
1155 static HRESULT WINAPI IDirectDraw4Impl_GetDeviceIdentifier(IDirectDraw4 *iface,
1156 DDDEVICEIDENTIFIER *DDDI, DWORD Flags)
1158 IDirectDrawImpl *This = impl_from_IDirectDraw4(iface);
1159 TRACE("(%p)->(%p,0x%08x)\n", This, DDDI, Flags);
1160 return IDirectDraw4_GetDeviceIdentifier(This->parent, DDDI, Flags);
1163 static const IDirectDrawVtbl IDirectDraw1_Vtbl =
1165 IDirectDrawImpl_QueryInterface,
1166 IDirectDrawImpl_AddRef,
1167 IDirectDrawImpl_Release,
1168 IDirectDrawImpl_Compact,
1169 IDirectDrawImpl_CreateClipper,
1170 IDirectDrawImpl_CreatePalette,
1171 IDirectDrawImpl_CreateSurface,
1172 IDirectDrawImpl_DuplicateSurface,
1173 IDirectDrawImpl_EnumDisplayModes,
1174 IDirectDrawImpl_EnumSurfaces,
1175 IDirectDrawImpl_FlipToGDISurface,
1176 IDirectDrawImpl_GetCaps,
1177 IDirectDrawImpl_GetDisplayMode,
1178 IDirectDrawImpl_GetFourCCCodes,
1179 IDirectDrawImpl_GetGDISurface,
1180 IDirectDrawImpl_GetMonitorFrequency,
1181 IDirectDrawImpl_GetScanLine,
1182 IDirectDrawImpl_GetVerticalBlankStatus,
1183 IDirectDrawImpl_Initialize,
1184 IDirectDrawImpl_RestoreDisplayMode,
1185 IDirectDrawImpl_SetCooperativeLevel,
1186 IDirectDrawImpl_SetDisplayMode,
1187 IDirectDrawImpl_WaitForVerticalBlank,
1190 static const IDirectDraw2Vtbl IDirectDraw2_Vtbl =
1192 IDirectDraw2Impl_QueryInterface,
1193 IDirectDraw2Impl_AddRef,
1194 IDirectDraw2Impl_Release,
1195 IDirectDraw2Impl_Compact,
1196 IDirectDraw2Impl_CreateClipper,
1197 IDirectDraw2Impl_CreatePalette,
1198 IDirectDraw2Impl_CreateSurface,
1199 IDirectDraw2Impl_DuplicateSurface,
1200 IDirectDraw2Impl_EnumDisplayModes,
1201 IDirectDraw2Impl_EnumSurfaces,
1202 IDirectDraw2Impl_FlipToGDISurface,
1203 IDirectDraw2Impl_GetCaps,
1204 IDirectDraw2Impl_GetDisplayMode,
1205 IDirectDraw2Impl_GetFourCCCodes,
1206 IDirectDraw2Impl_GetGDISurface,
1207 IDirectDraw2Impl_GetMonitorFrequency,
1208 IDirectDraw2Impl_GetScanLine,
1209 IDirectDraw2Impl_GetVerticalBlankStatus,
1210 IDirectDraw2Impl_Initialize,
1211 IDirectDraw2Impl_RestoreDisplayMode,
1212 IDirectDraw2Impl_SetCooperativeLevel,
1213 IDirectDraw2Impl_SetDisplayMode,
1214 IDirectDraw2Impl_WaitForVerticalBlank,
1215 IDirectDraw2Impl_GetAvailableVidMem
1218 static const IDirectDraw3Vtbl IDirectDraw3_Vtbl =
1220 IDirectDraw3Impl_QueryInterface,
1221 IDirectDraw3Impl_AddRef,
1222 IDirectDraw3Impl_Release,
1223 IDirectDraw3Impl_Compact,
1224 IDirectDraw3Impl_CreateClipper,
1225 IDirectDraw3Impl_CreatePalette,
1226 IDirectDraw3Impl_CreateSurface,
1227 IDirectDraw3Impl_DuplicateSurface,
1228 IDirectDraw3Impl_EnumDisplayModes,
1229 IDirectDraw3Impl_EnumSurfaces,
1230 IDirectDraw3Impl_FlipToGDISurface,
1231 IDirectDraw3Impl_GetCaps,
1232 IDirectDraw3Impl_GetDisplayMode,
1233 IDirectDraw3Impl_GetFourCCCodes,
1234 IDirectDraw3Impl_GetGDISurface,
1235 IDirectDraw3Impl_GetMonitorFrequency,
1236 IDirectDraw3Impl_GetScanLine,
1237 IDirectDraw3Impl_GetVerticalBlankStatus,
1238 IDirectDraw3Impl_Initialize,
1239 IDirectDraw3Impl_RestoreDisplayMode,
1240 IDirectDraw3Impl_SetCooperativeLevel,
1241 IDirectDraw3Impl_SetDisplayMode,
1242 IDirectDraw3Impl_WaitForVerticalBlank,
1243 IDirectDraw3Impl_GetAvailableVidMem,
1244 IDirectDraw3Impl_GetSurfaceFromDC,
1247 static const IDirectDraw4Vtbl IDirectDraw4_Vtbl =
1249 IDirectDraw4Impl_QueryInterface,
1250 IDirectDraw4Impl_AddRef,
1251 IDirectDraw4Impl_Release,
1252 IDirectDraw4Impl_Compact,
1253 IDirectDraw4Impl_CreateClipper,
1254 IDirectDraw4Impl_CreatePalette,
1255 IDirectDraw4Impl_CreateSurface,
1256 IDirectDraw4Impl_DuplicateSurface,
1257 IDirectDraw4Impl_EnumDisplayModes,
1258 IDirectDraw4Impl_EnumSurfaces,
1259 IDirectDraw4Impl_FlipToGDISurface,
1260 IDirectDraw4Impl_GetCaps,
1261 IDirectDraw4Impl_GetDisplayMode,
1262 IDirectDraw4Impl_GetFourCCCodes,
1263 IDirectDraw4Impl_GetGDISurface,
1264 IDirectDraw4Impl_GetMonitorFrequency,
1265 IDirectDraw4Impl_GetScanLine,
1266 IDirectDraw4Impl_GetVerticalBlankStatus,
1267 IDirectDraw4Impl_Initialize,
1268 IDirectDraw4Impl_RestoreDisplayMode,
1269 IDirectDraw4Impl_SetCooperativeLevel,
1270 IDirectDraw4Impl_SetDisplayMode,
1271 IDirectDraw4Impl_WaitForVerticalBlank,
1272 IDirectDraw4Impl_GetAvailableVidMem,
1273 IDirectDraw4Impl_GetSurfaceFromDC,
1274 IDirectDraw4Impl_RestoreAllSurfaces,
1275 IDirectDraw4Impl_TestCooperativeLevel,
1276 IDirectDraw4Impl_GetDeviceIdentifier
1279 /*******************************************************************************
1280 * IDirectDrawFactoryImpl_CreateDirectDraw
1281 *******************************************************************************/
1283 IDirectDrawFactoryImpl_CreateDirectDraw(IDirectDrawFactory* iface,
1286 DWORD dwCoopLevelFlags,
1288 IUnknown *pUnkOuter,
1289 IDirectDraw **ppDirectDraw)
1292 IDirectDrawImpl *object = NULL;
1293 IDirectDraw *parent = NULL;
1295 TRACE("(%p)->(%s,%p,0x%08x,0x%08x,%p,%p)\n", iface, debugstr_guid(pGUID), hWnd, dwCoopLevelFlags,
1296 dwReserved, pUnkOuter, ppDirectDraw);
1300 FIXME("Implement aggregation in ddrawex's IDirectDraw interface\n");
1303 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1306 ERR("Out of memory\n");
1311 object->IDirectDraw_iface.lpVtbl = &IDirectDraw1_Vtbl;
1312 object->IDirectDraw2_iface.lpVtbl = &IDirectDraw2_Vtbl;
1313 object->IDirectDraw3_iface.lpVtbl = &IDirectDraw3_Vtbl;
1314 object->IDirectDraw4_iface.lpVtbl = &IDirectDraw4_Vtbl;
1316 hr = DirectDrawCreate(pGUID, &parent, NULL);
1317 if (FAILED(hr)) goto err;
1319 hr = IDirectDraw_QueryInterface(parent, &IID_IDirectDraw4, (void **) &object->parent);
1320 if(FAILED(hr)) goto err;
1322 hr = IDirectDraw_SetCooperativeLevel(&object->IDirectDraw_iface, hWnd, dwCoopLevelFlags);
1323 if (FAILED(hr)) goto err;
1325 *ppDirectDraw = &object->IDirectDraw_iface;
1326 IDirectDraw_Release(parent);
1330 if(object && object->parent) IDirectDraw4_Release(object->parent);
1331 if(parent) IDirectDraw_Release(parent);
1332 HeapFree(GetProcessHeap(), 0, object);
1333 *ppDirectDraw = NULL;
1337 IDirectDraw4 *dd_get_inner(IDirectDraw4 *outer)
1339 IDirectDrawImpl *This = impl_from_IDirectDraw4(outer);
1341 if (outer->lpVtbl != &IDirectDraw4_Vtbl) return NULL;
1342 return This->parent;