- Merge from trunk up to r45543
[reactos.git] / dll / directx / wine / ddraw / ddraw_thunks.c
1 /* Direct Draw Thunks and old vtables
2 * Copyright 2000 TransGaming Technologies Inc.
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #include "config.h"
20 #include "wine/port.h"
21
22 #include <assert.h>
23 #include <stdarg.h>
24 #include <string.h>
25 #include <stdlib.h>
26
27 #define COBJMACROS
28 #define NONAMELESSUNION
29
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winerror.h"
33 #include "wingdi.h"
34 #include "wine/exception.h"
35
36 #include "ddraw.h"
37 #include "d3d.h"
38
39 #include "ddraw_private.h"
40 #include "wine/debug.h"
41
42 WINE_DEFAULT_DEBUG_CHANNEL(ddraw_thunk);
43 WINE_DECLARE_DEBUG_CHANNEL(ddraw);
44
45 static HRESULT WINAPI
46 IDirectDrawImpl_QueryInterface(LPDIRECTDRAW This, REFIID iid, LPVOID *ppObj)
47 {
48 return IDirectDraw7_QueryInterface((IDirectDraw7 *)ddraw_from_ddraw1(This), iid, ppObj);
49 }
50
51 static HRESULT WINAPI
52 IDirectDraw2Impl_QueryInterface(LPDIRECTDRAW2 This, REFIID iid, LPVOID *ppObj)
53 {
54 return IDirectDraw7_QueryInterface((IDirectDraw7 *)ddraw_from_ddraw2(This), iid, ppObj);
55 }
56
57 static HRESULT WINAPI
58 IDirectDraw4Impl_QueryInterface(LPDIRECTDRAW4 This, REFIID iid, LPVOID *ppObj)
59 {
60 return IDirectDraw7_QueryInterface((IDirectDraw7 *)ddraw_from_ddraw4(This), iid, ppObj);
61 }
62
63 static ULONG WINAPI
64 IDirectDrawImpl_AddRef(LPDIRECTDRAW iface)
65 {
66 IDirectDrawImpl *This = ddraw_from_ddraw1(iface);
67 ULONG ref = InterlockedIncrement(&This->ref1);
68
69 TRACE("(%p) : incrementing IDirectDraw refcount from %u.\n", This, ref -1);
70
71 if(ref == 1) InterlockedIncrement(&This->numIfaces);
72
73 return ref;
74 }
75
76 static ULONG WINAPI
77 IDirectDraw2Impl_AddRef(LPDIRECTDRAW2 iface)
78 {
79 IDirectDrawImpl *This = ddraw_from_ddraw2(iface);
80 ULONG ref = InterlockedIncrement(&This->ref2);
81
82 TRACE("(%p) : incrementing IDirectDraw2 refcount from %u.\n", This, ref -1);
83
84 if(ref == 1) InterlockedIncrement(&This->numIfaces);
85
86 return ref;
87 }
88
89 static ULONG WINAPI
90 IDirectDraw4Impl_AddRef(LPDIRECTDRAW4 iface)
91 {
92 IDirectDrawImpl *This = ddraw_from_ddraw4(iface);
93 ULONG ref = InterlockedIncrement(&This->ref4);
94
95 TRACE("(%p) : incrementing IDirectDraw4 refcount from %u.\n", This, ref -1);
96
97 if(ref == 1) InterlockedIncrement(&This->numIfaces);
98
99 return ref;
100 }
101
102 static ULONG WINAPI
103 IDirectDrawImpl_Release(LPDIRECTDRAW iface)
104 {
105 IDirectDrawImpl *This = ddraw_from_ddraw1(iface);
106 ULONG ref = InterlockedDecrement(&This->ref1);
107
108 TRACE_(ddraw)("(%p)->() decrementing IDirectDraw refcount from %u.\n", This, ref +1);
109
110 if(ref == 0)
111 {
112 ULONG ifacecount = InterlockedDecrement(&This->numIfaces);
113 if(ifacecount == 0) IDirectDrawImpl_Destroy(This);
114 }
115
116 return ref;
117 }
118
119 static ULONG WINAPI
120 IDirectDraw2Impl_Release(LPDIRECTDRAW2 iface)
121 {
122 IDirectDrawImpl *This = ddraw_from_ddraw2(iface);
123 ULONG ref = InterlockedDecrement(&This->ref2);
124
125 TRACE_(ddraw)("(%p)->() decrementing IDirectDraw2 refcount from %u.\n", This, ref +1);
126
127 if(ref == 0)
128 {
129 ULONG ifacecount = InterlockedDecrement(&This->numIfaces);
130 if(ifacecount == 0) IDirectDrawImpl_Destroy(This);
131 }
132
133 return ref;
134 }
135
136 static ULONG WINAPI
137 IDirectDraw4Impl_Release(LPDIRECTDRAW4 iface)
138 {
139 IDirectDrawImpl *This = ddraw_from_ddraw4(iface);
140 ULONG ref = InterlockedDecrement(&This->ref4);
141
142 TRACE_(ddraw)("(%p)->() decrementing IDirectDraw4 refcount from %u.\n", This, ref +1);
143
144 if(ref == 0)
145 {
146 ULONG ifacecount = InterlockedDecrement(&This->numIfaces);
147 if(ifacecount == 0) IDirectDrawImpl_Destroy(This);
148 }
149
150 return ref;
151 }
152
153 static HRESULT WINAPI
154 IDirectDrawImpl_Compact(LPDIRECTDRAW This)
155 {
156 return IDirectDraw7_Compact((IDirectDraw7 *)ddraw_from_ddraw1(This));
157 }
158
159 static HRESULT WINAPI
160 IDirectDraw2Impl_Compact(LPDIRECTDRAW2 This)
161 {
162 return IDirectDraw7_Compact((IDirectDraw7 *)ddraw_from_ddraw2(This));
163 }
164
165 static HRESULT WINAPI
166 IDirectDraw4Impl_Compact(LPDIRECTDRAW4 This)
167 {
168 return IDirectDraw7_Compact((IDirectDraw7 *)ddraw_from_ddraw4(This));
169 }
170
171 static HRESULT WINAPI
172 IDirectDrawImpl_CreateClipper(LPDIRECTDRAW This, DWORD dwFlags,
173 LPDIRECTDRAWCLIPPER *ppClipper,
174 IUnknown *pUnkOuter)
175 {
176 return IDirectDraw7_CreateClipper((IDirectDraw7 *)ddraw_from_ddraw1(This), dwFlags, ppClipper, pUnkOuter);
177 }
178
179 static HRESULT WINAPI
180 IDirectDraw2Impl_CreateClipper(LPDIRECTDRAW2 This, DWORD dwFlags,
181 LPDIRECTDRAWCLIPPER *ppClipper,
182 IUnknown *pUnkOuter)
183 {
184 return IDirectDraw7_CreateClipper((IDirectDraw7 *)ddraw_from_ddraw2(This), dwFlags, ppClipper, pUnkOuter);
185 }
186
187 static HRESULT WINAPI
188 IDirectDraw4Impl_CreateClipper(LPDIRECTDRAW4 This, DWORD dwFlags,
189 LPDIRECTDRAWCLIPPER *ppClipper,
190 IUnknown *pUnkOuter)
191 {
192 return IDirectDraw7_CreateClipper((IDirectDraw7 *)ddraw_from_ddraw4(This), dwFlags, ppClipper, pUnkOuter);
193 }
194
195 static HRESULT WINAPI
196 IDirectDrawImpl_CreatePalette(LPDIRECTDRAW This, DWORD dwFlags,
197 LPPALETTEENTRY pEntries,
198 LPDIRECTDRAWPALETTE *ppPalette,
199 IUnknown *pUnkOuter)
200 {
201 HRESULT hr;
202 hr = IDirectDraw7_CreatePalette((IDirectDraw7 *)ddraw_from_ddraw1(This), dwFlags, pEntries, ppPalette, pUnkOuter);
203 if(SUCCEEDED(hr) && *ppPalette)
204 {
205 IDirectDrawPaletteImpl *impl = (IDirectDrawPaletteImpl *)*ppPalette;
206 IDirectDraw7_Release((IDirectDraw7 *)ddraw_from_ddraw1(This));
207 impl->ifaceToRelease = NULL;
208
209 }
210 return hr;
211 }
212
213 static HRESULT WINAPI
214 IDirectDraw2Impl_CreatePalette(LPDIRECTDRAW2 This, DWORD dwFlags,
215 LPPALETTEENTRY pEntries,
216 LPDIRECTDRAWPALETTE *ppPalette,
217 IUnknown *pUnkOuter)
218 {
219 HRESULT hr;
220 hr = IDirectDraw7_CreatePalette((IDirectDraw7 *)ddraw_from_ddraw2(This), dwFlags, pEntries, ppPalette, pUnkOuter);
221 if(SUCCEEDED(hr) && *ppPalette)
222 {
223 IDirectDrawPaletteImpl *impl = (IDirectDrawPaletteImpl *)*ppPalette;
224 IDirectDraw7_Release((IDirectDraw7 *)ddraw_from_ddraw2(This));
225 impl->ifaceToRelease = NULL;
226 }
227 return hr;
228 }
229
230 static HRESULT WINAPI
231 IDirectDraw4Impl_CreatePalette(LPDIRECTDRAW4 This, DWORD dwFlags,
232 LPPALETTEENTRY pEntries,
233 LPDIRECTDRAWPALETTE *ppPalette,
234 IUnknown *pUnkOuter)
235 {
236 HRESULT hr;
237 hr = IDirectDraw7_CreatePalette((IDirectDraw7 *)ddraw_from_ddraw4(This), dwFlags, pEntries, ppPalette, pUnkOuter);
238 if(SUCCEEDED(hr) && *ppPalette)
239 {
240 IDirectDrawPaletteImpl *impl = (IDirectDrawPaletteImpl *)*ppPalette;
241 IDirectDraw7_Release((IDirectDraw7 *)ddraw_from_ddraw4(This));
242 IDirectDraw4_AddRef(This);
243 impl->ifaceToRelease = (IUnknown *) This;
244 }
245 return hr;
246 }
247
248 /* Must set all attached surfaces (e.g. mipmaps) versions as well */
249 static void set_surf_version(IDirectDrawSurfaceImpl *surf, int version)
250 {
251 int i;
252 TRACE("%p->version(%d) = %d\n", surf, surf->version, version);
253 surf->version = version;
254 for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
255 {
256 if(!surf->complex_array[i]) break;
257 set_surf_version(surf->complex_array[i], version);
258 }
259 while( (surf = surf->next_attached) )
260 {
261 set_surf_version(surf, version);
262 }
263 }
264
265 static HRESULT WINAPI
266 IDirectDrawImpl_CreateSurface(LPDIRECTDRAW This, LPDDSURFACEDESC pSDesc,
267 LPDIRECTDRAWSURFACE *ppSurface,
268 IUnknown *pUnkOuter)
269 {
270 LPDIRECTDRAWSURFACE7 pSurface7;
271 IDirectDrawSurfaceImpl *impl;
272 HRESULT hr;
273
274 /* Remove front buffer flag, this causes failure in v7, and its added to normal
275 * primaries anyway
276 */
277 pSDesc->ddsCaps.dwCaps &= ~DDSCAPS_FRONTBUFFER;
278 /* the LPDDSURFACEDESC -> LPDDSURFACEDESC2 conversion should be ok,
279 * since the data layout is the same */
280 hr = IDirectDraw7_CreateSurface((IDirectDraw7 *)ddraw_from_ddraw1(This),
281 (LPDDSURFACEDESC2)pSDesc, &pSurface7, pUnkOuter);
282 if (FAILED(hr))
283 {
284 *ppSurface = NULL;
285 return hr;
286 }
287
288 impl = (IDirectDrawSurfaceImpl *)pSurface7;
289 *ppSurface = (IDirectDrawSurface *)&impl->IDirectDrawSurface3_vtbl;
290 set_surf_version(impl, 1);
291 IDirectDraw7_Release((IDirectDraw7 *)ddraw_from_ddraw1(This));
292 impl->ifaceToRelease = NULL;
293 return hr;
294 }
295
296 static HRESULT WINAPI
297 IDirectDraw2Impl_CreateSurface(LPDIRECTDRAW2 This, LPDDSURFACEDESC pSDesc,
298 LPDIRECTDRAWSURFACE *ppSurface,
299 IUnknown *pUnkOuter)
300 {
301 LPDIRECTDRAWSURFACE7 pSurface7;
302 IDirectDrawSurfaceImpl *impl;
303 HRESULT hr;
304
305 hr = IDirectDraw7_CreateSurface((IDirectDraw7 *)ddraw_from_ddraw2(This),
306 (LPDDSURFACEDESC2)pSDesc, &pSurface7, pUnkOuter);
307 if (FAILED(hr))
308 {
309 *ppSurface = NULL;
310 return hr;
311 }
312 impl = (IDirectDrawSurfaceImpl *)pSurface7;
313 *ppSurface = (IDirectDrawSurface *)&impl->IDirectDrawSurface3_vtbl;
314 set_surf_version(impl, 2);
315 IDirectDraw7_Release((IDirectDraw7 *)ddraw_from_ddraw2(This));
316 impl->ifaceToRelease = NULL;
317 return hr;
318 }
319
320 static HRESULT WINAPI
321 IDirectDraw4Impl_CreateSurface(LPDIRECTDRAW4 This, LPDDSURFACEDESC2 pSDesc,
322 LPDIRECTDRAWSURFACE4 *ppSurface,
323 IUnknown *pUnkOuter)
324 {
325 HRESULT hr;
326 IDirectDrawSurfaceImpl *impl;
327
328 hr = IDirectDraw7_CreateSurface((IDirectDraw7 *)ddraw_from_ddraw4(This),
329 pSDesc, (LPDIRECTDRAWSURFACE7 *)ppSurface, pUnkOuter);
330 impl = (IDirectDrawSurfaceImpl *)*ppSurface;
331 if(SUCCEEDED(hr) && impl)
332 {
333 set_surf_version(impl, 4);
334 IDirectDraw7_Release((IDirectDraw7 *)ddraw_from_ddraw4(This));
335 IDirectDraw4_AddRef(This);
336 impl->ifaceToRelease = (IUnknown *) This;
337 }
338 return hr;
339 }
340
341 static HRESULT WINAPI
342 IDirectDrawImpl_DuplicateSurface(LPDIRECTDRAW This, LPDIRECTDRAWSURFACE pSrc,
343 LPDIRECTDRAWSURFACE *ppDst)
344 {
345 LPDIRECTDRAWSURFACE7 pDst7;
346 HRESULT hr;
347
348 hr = IDirectDraw7_DuplicateSurface((IDirectDraw7 *)ddraw_from_ddraw1(This),
349 pSrc ? (IDirectDrawSurface7 *)surface_from_surface3((IDirectDrawSurface3 *)pSrc) : NULL, &pDst7);
350
351 /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
352 * IDirectDrawSurface vtable layout at the beginning */
353 *ppDst = pDst7 ? (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)pDst7)->IDirectDrawSurface3_vtbl : NULL;
354
355 return hr;
356 }
357
358 static HRESULT WINAPI
359 IDirectDraw2Impl_DuplicateSurface(LPDIRECTDRAW2 This, LPDIRECTDRAWSURFACE pSrc,
360 LPDIRECTDRAWSURFACE *ppDst)
361 {
362 LPDIRECTDRAWSURFACE7 pDst7;
363 HRESULT hr;
364
365 hr = IDirectDraw7_DuplicateSurface((IDirectDraw7 *)ddraw_from_ddraw2(This),
366 pSrc ? (IDirectDrawSurface7 *)surface_from_surface3((IDirectDrawSurface3 *)pSrc) : NULL, &pDst7);
367
368 /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
369 * IDirectDrawSurface vtable layout at the beginning */
370 *ppDst = pDst7 ? (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)pDst7)->IDirectDrawSurface3_vtbl : NULL;
371
372 return hr;
373 }
374
375 static HRESULT WINAPI
376 IDirectDraw4Impl_DuplicateSurface(LPDIRECTDRAW4 This,
377 LPDIRECTDRAWSURFACE4 pSrc,
378 LPDIRECTDRAWSURFACE4 *ppDst)
379 {
380 return IDirectDraw7_DuplicateSurface((IDirectDraw7 *)ddraw_from_ddraw4(This),
381 (LPDIRECTDRAWSURFACE7)pSrc, (LPDIRECTDRAWSURFACE7 *)ppDst);
382 }
383
384 struct displaymodescallback_context
385 {
386 LPDDENUMMODESCALLBACK func;
387 LPVOID context;
388 };
389
390 static HRESULT CALLBACK
391 EnumDisplayModesCallbackThunk(LPDDSURFACEDESC2 pDDSD2, LPVOID context)
392 {
393 DDSURFACEDESC DDSD;
394 struct displaymodescallback_context *cbcontext = context;
395
396 memcpy(&DDSD,pDDSD2,sizeof(DDSD));
397 DDSD.dwSize = sizeof(DDSD);
398
399 return cbcontext->func(&DDSD, cbcontext->context);
400 }
401
402 static HRESULT WINAPI
403 IDirectDrawImpl_EnumDisplayModes(LPDIRECTDRAW This, DWORD dwFlags,
404 LPDDSURFACEDESC pDDSD, LPVOID context,
405 LPDDENUMMODESCALLBACK cb)
406 {
407 struct displaymodescallback_context cbcontext;
408
409 cbcontext.func = cb;
410 cbcontext.context = context;
411
412 return IDirectDraw7_EnumDisplayModes((IDirectDraw7 *)ddraw_from_ddraw1(This),
413 dwFlags, (LPDDSURFACEDESC2)pDDSD, &cbcontext, EnumDisplayModesCallbackThunk);
414 }
415
416 static HRESULT WINAPI
417 IDirectDraw2Impl_EnumDisplayModes(LPDIRECTDRAW2 This, DWORD dwFlags,
418 LPDDSURFACEDESC pDDSD, LPVOID context,
419 LPDDENUMMODESCALLBACK cb)
420 {
421 struct displaymodescallback_context cbcontext;
422
423 cbcontext.func = cb;
424 cbcontext.context = context;
425
426 return IDirectDraw7_EnumDisplayModes((IDirectDraw7 *)ddraw_from_ddraw2(This),
427 dwFlags, (LPDDSURFACEDESC2)pDDSD, &cbcontext, EnumDisplayModesCallbackThunk);
428 }
429
430 static HRESULT WINAPI
431 IDirectDraw4Impl_EnumDisplayModes(LPDIRECTDRAW4 This, DWORD dwFlags,
432 LPDDSURFACEDESC2 pDDSD, LPVOID context,
433 LPDDENUMMODESCALLBACK2 cb)
434 {
435 return IDirectDraw7_EnumDisplayModes((IDirectDraw7 *)ddraw_from_ddraw4(This), dwFlags, pDDSD, context, cb);
436 }
437
438 struct surfacescallback_context
439 {
440 LPDDENUMSURFACESCALLBACK func;
441 LPVOID context;
442 };
443
444 static HRESULT CALLBACK
445 EnumSurfacesCallbackThunk(LPDIRECTDRAWSURFACE7 pSurf, LPDDSURFACEDESC2 pDDSD,
446 LPVOID context)
447 {
448 struct surfacescallback_context *cbcontext = context;
449
450 /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
451 * IDirectDrawSurface vtable layout at the beginning */
452 return cbcontext->func(
453 pSurf ? (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)pSurf)->IDirectDrawSurface3_vtbl : NULL,
454 (LPDDSURFACEDESC)pDDSD, cbcontext->context);
455 }
456
457 static HRESULT WINAPI
458 IDirectDrawImpl_EnumSurfaces(LPDIRECTDRAW This, DWORD dwFlags,
459 LPDDSURFACEDESC pDDSD, LPVOID context,
460 LPDDENUMSURFACESCALLBACK cb)
461 {
462 struct surfacescallback_context cbcontext;
463
464 cbcontext.func = cb;
465 cbcontext.context = context;
466
467 return IDirectDraw7_EnumSurfaces((IDirectDraw7 *)ddraw_from_ddraw1(This),
468 dwFlags, (LPDDSURFACEDESC2)pDDSD, &cbcontext, EnumSurfacesCallbackThunk);
469 }
470
471 static HRESULT WINAPI
472 IDirectDraw2Impl_EnumSurfaces(LPDIRECTDRAW2 This, DWORD dwFlags,
473 LPDDSURFACEDESC pDDSD, LPVOID context,
474 LPDDENUMSURFACESCALLBACK cb)
475 {
476 struct surfacescallback_context cbcontext;
477
478 cbcontext.func = cb;
479 cbcontext.context = context;
480
481 return IDirectDraw7_EnumSurfaces((IDirectDraw7 *)ddraw_from_ddraw2(This),
482 dwFlags, (LPDDSURFACEDESC2)pDDSD, &cbcontext, EnumSurfacesCallbackThunk);
483 }
484
485 static HRESULT WINAPI
486 IDirectDraw4Impl_EnumSurfaces(LPDIRECTDRAW4 This, DWORD dwFlags,
487 LPDDSURFACEDESC2 pDDSD, LPVOID context,
488 LPDDENUMSURFACESCALLBACK2 cb)
489 {
490 return IDirectDraw7_EnumSurfaces((IDirectDraw7 *)ddraw_from_ddraw4(This),
491 dwFlags, pDDSD, context, (LPDDENUMSURFACESCALLBACK7)cb);
492 }
493
494 static HRESULT WINAPI
495 IDirectDrawImpl_FlipToGDISurface(LPDIRECTDRAW This)
496 {
497 return IDirectDraw7_FlipToGDISurface((IDirectDraw7 *)ddraw_from_ddraw1(This));
498 }
499
500 static HRESULT WINAPI
501 IDirectDraw2Impl_FlipToGDISurface(LPDIRECTDRAW2 This)
502 {
503 return IDirectDraw7_FlipToGDISurface((IDirectDraw7 *)ddraw_from_ddraw2(This));
504 }
505
506 static HRESULT WINAPI
507 IDirectDraw4Impl_FlipToGDISurface(LPDIRECTDRAW4 This)
508 {
509 return IDirectDraw7_FlipToGDISurface((IDirectDraw7 *)ddraw_from_ddraw4(This));
510 }
511
512 static HRESULT WINAPI
513 IDirectDrawImpl_GetCaps(LPDIRECTDRAW This, LPDDCAPS pDDC1, LPDDCAPS pDDC2)
514 {
515 return IDirectDraw7_GetCaps((IDirectDraw7 *)ddraw_from_ddraw1(This), pDDC1, pDDC2);
516 }
517
518 static HRESULT WINAPI
519 IDirectDraw2Impl_GetCaps(LPDIRECTDRAW2 This, LPDDCAPS pDDC1, LPDDCAPS pDDC2)
520 {
521 return IDirectDraw7_GetCaps((IDirectDraw7 *)ddraw_from_ddraw2(This), pDDC1, pDDC2);
522 }
523
524 static HRESULT WINAPI
525 IDirectDraw4Impl_GetCaps(LPDIRECTDRAW4 This, LPDDCAPS pDDC1, LPDDCAPS pDDC2)
526 {
527 return IDirectDraw7_GetCaps((IDirectDraw7 *)ddraw_from_ddraw4(This), pDDC1, pDDC2);
528 }
529
530 static HRESULT WINAPI
531 IDirectDrawImpl_GetDisplayMode(LPDIRECTDRAW This, LPDDSURFACEDESC pDDSD)
532 {
533 return IDirectDraw7_GetDisplayMode((IDirectDraw7 *)ddraw_from_ddraw1(This), (LPDDSURFACEDESC2)pDDSD);
534 }
535
536 static HRESULT WINAPI
537 IDirectDraw2Impl_GetDisplayMode(LPDIRECTDRAW2 This, LPDDSURFACEDESC pDDSD)
538 {
539 return IDirectDraw7_GetDisplayMode((IDirectDraw7 *)ddraw_from_ddraw2(This), (LPDDSURFACEDESC2)pDDSD);
540 }
541
542 static HRESULT WINAPI
543 IDirectDraw4Impl_GetDisplayMode(LPDIRECTDRAW4 This, LPDDSURFACEDESC2 pDDSD)
544 {
545 return IDirectDraw7_GetDisplayMode((IDirectDraw7 *)ddraw_from_ddraw4(This), (LPDDSURFACEDESC2)pDDSD);
546 }
547
548 static HRESULT WINAPI
549 IDirectDrawImpl_GetFourCCCodes(LPDIRECTDRAW This, LPDWORD lpNumCodes,
550 LPDWORD lpCodes)
551 {
552 return IDirectDraw7_GetFourCCCodes((IDirectDraw7 *)ddraw_from_ddraw1(This), lpNumCodes, lpCodes);
553 }
554
555 static HRESULT WINAPI
556 IDirectDraw2Impl_GetFourCCCodes(LPDIRECTDRAW2 This, LPDWORD lpNumCodes,
557 LPDWORD lpCodes)
558 {
559 return IDirectDraw7_GetFourCCCodes((IDirectDraw7 *)ddraw_from_ddraw2(This), lpNumCodes, lpCodes);
560 }
561
562 static HRESULT WINAPI
563 IDirectDraw4Impl_GetFourCCCodes(LPDIRECTDRAW4 This, LPDWORD lpNumCodes,
564 LPDWORD lpCodes)
565 {
566 return IDirectDraw7_GetFourCCCodes((IDirectDraw7 *)ddraw_from_ddraw4(This), lpNumCodes, lpCodes);
567 }
568
569 static HRESULT WINAPI
570 IDirectDrawImpl_GetGDISurface(LPDIRECTDRAW This, LPDIRECTDRAWSURFACE *ppSurf)
571 {
572 LPDIRECTDRAWSURFACE7 pSurf7;
573 HRESULT hr;
574
575 hr = IDirectDraw7_GetGDISurface((IDirectDraw7 *)ddraw_from_ddraw1(This), &pSurf7);
576
577 /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
578 * IDirectDrawSurface vtable layout at the beginning */
579 *ppSurf = pSurf7 ? (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)pSurf7)->IDirectDrawSurface3_vtbl : NULL;
580
581 return hr;
582 }
583
584 static HRESULT WINAPI
585 IDirectDraw2Impl_GetGDISurface(LPDIRECTDRAW2 This, LPDIRECTDRAWSURFACE *ppSurf)
586 {
587 LPDIRECTDRAWSURFACE7 pSurf7;
588 HRESULT hr;
589
590 hr = IDirectDraw7_GetGDISurface((IDirectDraw7 *)ddraw_from_ddraw2(This), &pSurf7);
591
592 /* This coercion is safe, since the IDirectDrawSurface3 vtable has the
593 * IDirectDrawSurface vtable layout at the beginning */
594 *ppSurf = pSurf7 ? (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)pSurf7)->IDirectDrawSurface3_vtbl : NULL;
595
596 return hr;
597 }
598
599 static HRESULT WINAPI
600 IDirectDraw4Impl_GetGDISurface(LPDIRECTDRAW4 This,
601 LPDIRECTDRAWSURFACE4 *ppSurf)
602 {
603 return IDirectDraw7_GetGDISurface((IDirectDraw7 *)ddraw_from_ddraw4(This), (LPDIRECTDRAWSURFACE7 *)ppSurf);
604 }
605
606 static HRESULT WINAPI
607 IDirectDrawImpl_GetMonitorFrequency(LPDIRECTDRAW This, LPDWORD pdwFreq)
608 {
609 return IDirectDraw7_GetMonitorFrequency((IDirectDraw7 *)ddraw_from_ddraw1(This), pdwFreq);
610 }
611
612 static HRESULT WINAPI
613 IDirectDraw2Impl_GetMonitorFrequency(LPDIRECTDRAW2 This, LPDWORD pdwFreq)
614 {
615 return IDirectDraw7_GetMonitorFrequency((IDirectDraw7 *)ddraw_from_ddraw2(This), pdwFreq);
616 }
617
618 static HRESULT WINAPI
619 IDirectDraw4Impl_GetMonitorFrequency(LPDIRECTDRAW4 This, LPDWORD pdwFreq)
620 {
621 return IDirectDraw7_GetMonitorFrequency((IDirectDraw7 *)ddraw_from_ddraw4(This), pdwFreq);
622 }
623
624 static HRESULT WINAPI
625 IDirectDrawImpl_GetScanLine(LPDIRECTDRAW This, LPDWORD pdwLine)
626 {
627 return IDirectDraw7_GetScanLine((IDirectDraw7 *)ddraw_from_ddraw1(This), pdwLine);
628 }
629
630 static HRESULT WINAPI
631 IDirectDraw2Impl_GetScanLine(LPDIRECTDRAW2 This, LPDWORD pdwLine)
632 {
633 return IDirectDraw7_GetScanLine((IDirectDraw7 *)ddraw_from_ddraw2(This), pdwLine);
634 }
635
636 static HRESULT WINAPI
637 IDirectDraw4Impl_GetScanLine(LPDIRECTDRAW4 This, LPDWORD pdwLine)
638 {
639 return IDirectDraw7_GetScanLine((IDirectDraw7 *)ddraw_from_ddraw4(This), pdwLine);
640 }
641
642 static HRESULT WINAPI
643 IDirectDrawImpl_GetVerticalBlankStatus(LPDIRECTDRAW This, LPBOOL lpbIsInVB)
644 {
645 return IDirectDraw7_GetVerticalBlankStatus((IDirectDraw7 *)ddraw_from_ddraw1(This), lpbIsInVB);
646 }
647
648 static HRESULT WINAPI
649 IDirectDraw2Impl_GetVerticalBlankStatus(LPDIRECTDRAW2 This, LPBOOL lpbIsInVB)
650 {
651 return IDirectDraw7_GetVerticalBlankStatus((IDirectDraw7 *)ddraw_from_ddraw2(This), lpbIsInVB);
652 }
653
654 static HRESULT WINAPI
655 IDirectDraw4Impl_GetVerticalBlankStatus(LPDIRECTDRAW4 This, LPBOOL lpbIsInVB)
656 {
657 return IDirectDraw7_GetVerticalBlankStatus((IDirectDraw7 *)ddraw_from_ddraw4(This), lpbIsInVB);
658 }
659
660 static HRESULT WINAPI
661 IDirectDrawImpl_Initialize(LPDIRECTDRAW iface, LPGUID pGUID)
662 {
663 IDirectDrawImpl *This = ddraw_from_ddraw1(iface);
664 HRESULT ret_value;
665
666 ret_value = IDirectDraw7_Initialize((IDirectDraw7 *)This, pGUID);
667
668 return ret_value;
669 }
670
671 static HRESULT WINAPI
672 IDirectDraw2Impl_Initialize(LPDIRECTDRAW2 iface, LPGUID pGUID)
673 {
674 IDirectDrawImpl *This = ddraw_from_ddraw2(iface);
675 HRESULT ret_value;
676
677 ret_value = IDirectDraw7_Initialize((IDirectDraw7 *)This, pGUID);
678
679 return ret_value;
680 }
681
682 static HRESULT WINAPI
683 IDirectDraw4Impl_Initialize(LPDIRECTDRAW4 iface, LPGUID pGUID)
684 {
685 IDirectDrawImpl *This = ddraw_from_ddraw4(iface);
686 HRESULT ret_value;
687
688 ret_value = IDirectDraw7_Initialize((IDirectDraw7 *)This, pGUID);
689
690 return ret_value;
691 }
692
693
694 static HRESULT WINAPI
695 IDirectDrawImpl_RestoreDisplayMode(LPDIRECTDRAW This)
696 {
697 return IDirectDraw7_RestoreDisplayMode((IDirectDraw7 *)ddraw_from_ddraw1(This));
698 }
699
700 static HRESULT WINAPI
701 IDirectDraw2Impl_RestoreDisplayMode(LPDIRECTDRAW2 This)
702 {
703 return IDirectDraw7_RestoreDisplayMode((IDirectDraw7 *)ddraw_from_ddraw2(This));
704 }
705
706 static HRESULT WINAPI
707 IDirectDraw4Impl_RestoreDisplayMode(LPDIRECTDRAW4 This)
708 {
709 return IDirectDraw7_RestoreDisplayMode((IDirectDraw7 *)ddraw_from_ddraw4(This));
710 }
711
712 static HRESULT WINAPI
713 IDirectDrawImpl_SetCooperativeLevel(LPDIRECTDRAW This, HWND hWnd,
714 DWORD dwFlags)
715 {
716 return IDirectDraw7_SetCooperativeLevel((IDirectDraw7 *)ddraw_from_ddraw1(This), hWnd, dwFlags);
717 }
718
719 static HRESULT WINAPI
720 IDirectDraw2Impl_SetCooperativeLevel(LPDIRECTDRAW2 This, HWND hWnd,
721 DWORD dwFlags)
722 {
723 return IDirectDraw7_SetCooperativeLevel((IDirectDraw7 *)ddraw_from_ddraw2(This), hWnd, dwFlags);
724 }
725
726 static HRESULT WINAPI
727 IDirectDraw4Impl_SetCooperativeLevel(LPDIRECTDRAW4 This, HWND hWnd,
728 DWORD dwFlags)
729 {
730 return IDirectDraw7_SetCooperativeLevel((IDirectDraw7 *)ddraw_from_ddraw4(This), hWnd, dwFlags);
731 }
732
733 static HRESULT WINAPI
734 IDirectDrawImpl_SetDisplayMode(LPDIRECTDRAW This, DWORD a, DWORD b, DWORD c)
735 {
736 return IDirectDraw7_SetDisplayMode((IDirectDraw7 *)ddraw_from_ddraw1(This), a, b, c, 0, 0);
737 }
738
739 static HRESULT WINAPI
740 IDirectDraw2Impl_SetDisplayMode(LPDIRECTDRAW2 This, DWORD a, DWORD b, DWORD c,
741 DWORD d, DWORD e)
742 {
743 return IDirectDraw7_SetDisplayMode((IDirectDraw7 *)ddraw_from_ddraw2(This), a, b, c, d, e);
744 }
745
746 static HRESULT WINAPI
747 IDirectDraw4Impl_SetDisplayMode(LPDIRECTDRAW4 This, DWORD a, DWORD b, DWORD c,
748 DWORD d, DWORD e)
749 {
750 return IDirectDraw7_SetDisplayMode((IDirectDraw7 *)ddraw_from_ddraw4(This), a, b, c, d, e);
751 }
752
753 static HRESULT WINAPI
754 IDirectDrawImpl_WaitForVerticalBlank(LPDIRECTDRAW This, DWORD dwFlags,
755 HANDLE hEvent)
756 {
757 return IDirectDraw7_WaitForVerticalBlank((IDirectDraw7 *)ddraw_from_ddraw1(This), dwFlags, hEvent);
758 }
759
760 static HRESULT WINAPI
761 IDirectDraw2Impl_WaitForVerticalBlank(LPDIRECTDRAW2 This, DWORD dwFlags,
762 HANDLE hEvent)
763 {
764 return IDirectDraw7_WaitForVerticalBlank((IDirectDraw7 *)ddraw_from_ddraw2(This), dwFlags, hEvent);
765 }
766
767 static HRESULT WINAPI
768 IDirectDraw4Impl_WaitForVerticalBlank(LPDIRECTDRAW4 This, DWORD dwFlags,
769 HANDLE hEvent)
770 {
771 return IDirectDraw7_WaitForVerticalBlank((IDirectDraw7 *)ddraw_from_ddraw4(This), dwFlags, hEvent);
772 }
773
774 static HRESULT WINAPI
775 IDirectDraw2Impl_GetAvailableVidMem(LPDIRECTDRAW2 This, LPDDSCAPS pCaps,
776 LPDWORD pdwTotal, LPDWORD pdwFree)
777 {
778 DDSCAPS2 Caps2;
779 DDRAW_Convert_DDSCAPS_1_To_2(pCaps, &Caps2);
780
781 return IDirectDraw7_GetAvailableVidMem((IDirectDraw7 *)ddraw_from_ddraw2(This), &Caps2, pdwTotal, pdwFree);
782 }
783
784 static HRESULT WINAPI
785 IDirectDraw4Impl_GetAvailableVidMem(LPDIRECTDRAW4 This, LPDDSCAPS2 pCaps,
786 LPDWORD pdwTotal, LPDWORD pdwFree)
787 {
788 return IDirectDraw7_GetAvailableVidMem((IDirectDraw7 *)ddraw_from_ddraw4(This), pCaps, pdwTotal, pdwFree);
789 }
790
791 static HRESULT WINAPI
792 IDirectDraw4Impl_GetSurfaceFromDC(LPDIRECTDRAW4 This, HDC hDC,
793 LPDIRECTDRAWSURFACE4 *pSurf)
794 {
795 return IDirectDraw7_GetSurfaceFromDC((IDirectDraw7 *)ddraw_from_ddraw4(This), hDC, (LPDIRECTDRAWSURFACE7 *)pSurf);
796 }
797
798 static HRESULT WINAPI
799 IDirectDraw4Impl_RestoreAllSurfaces(LPDIRECTDRAW4 This)
800 {
801 return IDirectDraw7_RestoreAllSurfaces((IDirectDraw7 *)ddraw_from_ddraw4(This));
802 }
803
804 static HRESULT WINAPI
805 IDirectDraw4Impl_TestCooperativeLevel(LPDIRECTDRAW4 This)
806 {
807 return IDirectDraw7_TestCooperativeLevel((IDirectDraw7 *)ddraw_from_ddraw4(This));
808 }
809
810 static HRESULT WINAPI
811 IDirectDraw4Impl_GetDeviceIdentifier(LPDIRECTDRAW4 This,
812 LPDDDEVICEIDENTIFIER pDDDI, DWORD dwFlags)
813 {
814 DDDEVICEIDENTIFIER2 DDDI2;
815 HRESULT hr;
816
817 hr = IDirectDraw7_GetDeviceIdentifier((IDirectDraw7 *)ddraw_from_ddraw4(This), &DDDI2, dwFlags);
818
819 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&DDDI2, pDDDI);
820
821 return hr;
822 }
823
824 const IDirectDrawVtbl IDirectDraw1_Vtbl =
825 {
826 IDirectDrawImpl_QueryInterface,
827 IDirectDrawImpl_AddRef,
828 IDirectDrawImpl_Release,
829 IDirectDrawImpl_Compact,
830 IDirectDrawImpl_CreateClipper,
831 IDirectDrawImpl_CreatePalette,
832 IDirectDrawImpl_CreateSurface,
833 IDirectDrawImpl_DuplicateSurface,
834 IDirectDrawImpl_EnumDisplayModes,
835 IDirectDrawImpl_EnumSurfaces,
836 IDirectDrawImpl_FlipToGDISurface,
837 IDirectDrawImpl_GetCaps,
838 IDirectDrawImpl_GetDisplayMode,
839 IDirectDrawImpl_GetFourCCCodes,
840 IDirectDrawImpl_GetGDISurface,
841 IDirectDrawImpl_GetMonitorFrequency,
842 IDirectDrawImpl_GetScanLine,
843 IDirectDrawImpl_GetVerticalBlankStatus,
844 IDirectDrawImpl_Initialize,
845 IDirectDrawImpl_RestoreDisplayMode,
846 IDirectDrawImpl_SetCooperativeLevel,
847 IDirectDrawImpl_SetDisplayMode,
848 IDirectDrawImpl_WaitForVerticalBlank,
849 };
850
851 const IDirectDraw2Vtbl IDirectDraw2_Vtbl =
852 {
853 IDirectDraw2Impl_QueryInterface,
854 IDirectDraw2Impl_AddRef,
855 IDirectDraw2Impl_Release,
856 IDirectDraw2Impl_Compact,
857 IDirectDraw2Impl_CreateClipper,
858 IDirectDraw2Impl_CreatePalette,
859 IDirectDraw2Impl_CreateSurface,
860 IDirectDraw2Impl_DuplicateSurface,
861 IDirectDraw2Impl_EnumDisplayModes,
862 IDirectDraw2Impl_EnumSurfaces,
863 IDirectDraw2Impl_FlipToGDISurface,
864 IDirectDraw2Impl_GetCaps,
865 IDirectDraw2Impl_GetDisplayMode,
866 IDirectDraw2Impl_GetFourCCCodes,
867 IDirectDraw2Impl_GetGDISurface,
868 IDirectDraw2Impl_GetMonitorFrequency,
869 IDirectDraw2Impl_GetScanLine,
870 IDirectDraw2Impl_GetVerticalBlankStatus,
871 IDirectDraw2Impl_Initialize,
872 IDirectDraw2Impl_RestoreDisplayMode,
873 IDirectDraw2Impl_SetCooperativeLevel,
874 IDirectDraw2Impl_SetDisplayMode,
875 IDirectDraw2Impl_WaitForVerticalBlank,
876 IDirectDraw2Impl_GetAvailableVidMem
877 };
878
879 const IDirectDraw4Vtbl IDirectDraw4_Vtbl =
880 {
881 IDirectDraw4Impl_QueryInterface,
882 IDirectDraw4Impl_AddRef,
883 IDirectDraw4Impl_Release,
884 IDirectDraw4Impl_Compact,
885 IDirectDraw4Impl_CreateClipper,
886 IDirectDraw4Impl_CreatePalette,
887 IDirectDraw4Impl_CreateSurface,
888 IDirectDraw4Impl_DuplicateSurface,
889 IDirectDraw4Impl_EnumDisplayModes,
890 IDirectDraw4Impl_EnumSurfaces,
891 IDirectDraw4Impl_FlipToGDISurface,
892 IDirectDraw4Impl_GetCaps,
893 IDirectDraw4Impl_GetDisplayMode,
894 IDirectDraw4Impl_GetFourCCCodes,
895 IDirectDraw4Impl_GetGDISurface,
896 IDirectDraw4Impl_GetMonitorFrequency,
897 IDirectDraw4Impl_GetScanLine,
898 IDirectDraw4Impl_GetVerticalBlankStatus,
899 IDirectDraw4Impl_Initialize,
900 IDirectDraw4Impl_RestoreDisplayMode,
901 IDirectDraw4Impl_SetCooperativeLevel,
902 IDirectDraw4Impl_SetDisplayMode,
903 IDirectDraw4Impl_WaitForVerticalBlank,
904 IDirectDraw4Impl_GetAvailableVidMem,
905 IDirectDraw4Impl_GetSurfaceFromDC,
906 IDirectDraw4Impl_RestoreAllSurfaces,
907 IDirectDraw4Impl_TestCooperativeLevel,
908 IDirectDraw4Impl_GetDeviceIdentifier
909 };