2 * Copyright 1997-2000 Marcus Meissner
3 * Copyright 1998-2000 Lionel Ulmer
4 * Copyright 2000-2001 TransGaming Technologies Inc.
5 * Copyright 2006 Stefan Dösinger
6 * Copyright 2008 Denver Gingerich
7 * Copyright 2007-2008, 2011, 2013 Stefan Dösinger for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/port.h"
27 #include "ddraw_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
31 static const struct ddraw
*exclusive_ddraw
;
32 static HWND exclusive_window
;
34 /* Device identifier. Don't relay it to WineD3D */
35 static const DDDEVICEIDENTIFIER2 deviceidentifier
=
37 "vga.dll", /* default 2D driver */
39 { { 0x00010001, 0x00010001 } },
41 /* a8373c10-7ac4-4deb-849a-009844d08b2d */
42 {0xa8373c10,0x7ac4,0x4deb, {0x84,0x9a,0x00,0x98,0x44,0xd0,0x8b,0x2d}},
46 static struct enum_device_entry
48 char interface_name
[100];
49 char device_name
[100];
50 const GUID
*device_guid
;
55 "WINE Direct3D7 Hardware Transform and Lighting acceleration using WineD3D",
57 &IID_IDirect3DTnLHalDevice
,
62 "WINE Direct3D7 Hardware acceleration using WineD3D",
64 &IID_IDirect3DHALDevice
,
69 "WINE Direct3D7 RGB Software Emulation using WineD3D",
71 &IID_IDirect3DRGBDevice
,
75 static void STDMETHODCALLTYPE
ddraw_null_wined3d_object_destroyed(void *parent
) {}
77 const struct wined3d_parent_ops ddraw_null_wined3d_parent_ops
=
79 ddraw_null_wined3d_object_destroyed
,
82 static inline struct ddraw
*impl_from_IDirectDraw(IDirectDraw
*iface
)
84 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw_iface
);
87 static inline struct ddraw
*impl_from_IDirectDraw2(IDirectDraw2
*iface
)
89 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw2_iface
);
92 static inline struct ddraw
*impl_from_IDirectDraw4(IDirectDraw4
*iface
)
94 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw4_iface
);
97 static inline struct ddraw
*impl_from_IDirectDraw7(IDirectDraw7
*iface
)
99 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw7_iface
);
102 static inline struct ddraw
*impl_from_IDirect3D(IDirect3D
*iface
)
104 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D_iface
);
107 static inline struct ddraw
*impl_from_IDirect3D2(IDirect3D2
*iface
)
109 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D2_iface
);
112 static inline struct ddraw
*impl_from_IDirect3D3(IDirect3D3
*iface
)
114 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D3_iface
);
117 static inline struct ddraw
*impl_from_IDirect3D7(IDirect3D7
*iface
)
119 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D7_iface
);
122 static HRESULT WINAPI
ddraw7_QueryInterface(IDirectDraw7
*iface
, REFIID riid
, void **out
)
124 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
126 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
131 return DDERR_INVALIDPARAMS
;
134 /* The refcount unit test revealed that an IDirect3D7 interface can only
135 * be queried from a DirectDraw object that was created as an IDirectDraw7
136 * interface. The older interfaces can query any IDirect3D version except
137 * 7, because they are all initially created as IDirectDraw. This isn't
138 * really crucial behavior, and messy to implement with the common
139 * creation function, so it has been left out here. */
140 if (IsEqualGUID(&IID_IDirectDraw7
, riid
)
141 || IsEqualGUID(&IID_IUnknown
, riid
))
143 *out
= &ddraw
->IDirectDraw7_iface
;
144 TRACE("Returning IDirectDraw7 interface %p.\n", *out
);
146 else if (IsEqualGUID(&IID_IDirectDraw4
, riid
))
148 *out
= &ddraw
->IDirectDraw4_iface
;
149 TRACE("Returning IDirectDraw4 interface %p.\n", *out
);
151 else if (IsEqualGUID(&IID_IDirectDraw2
, riid
))
153 *out
= &ddraw
->IDirectDraw2_iface
;
154 TRACE("Returning IDirectDraw2 interface %p.\n", *out
);
156 else if (IsEqualGUID(&IID_IDirectDraw
, riid
))
158 *out
= &ddraw
->IDirectDraw_iface
;
159 TRACE("Returning IDirectDraw interface %p.\n", *out
);
161 else if (IsEqualGUID(&IID_IDirect3D7
, riid
))
163 ddraw
->d3dversion
= 7;
164 *out
= &ddraw
->IDirect3D7_iface
;
165 TRACE("Returning Direct3D7 interface %p.\n", *out
);
167 else if (IsEqualGUID(&IID_IDirect3D3
, riid
))
169 ddraw
->d3dversion
= 3;
170 *out
= &ddraw
->IDirect3D3_iface
;
171 TRACE("Returning Direct3D3 interface %p.\n", *out
);
173 else if (IsEqualGUID(&IID_IDirect3D2
, riid
))
175 ddraw
->d3dversion
= 2;
176 *out
= &ddraw
->IDirect3D2_iface
;
177 TRACE("Returning Direct3D2 interface %p.\n", *out
);
179 else if (IsEqualGUID(&IID_IDirect3D
, riid
))
181 ddraw
->d3dversion
= 1;
182 *out
= &ddraw
->IDirect3D_iface
;
183 TRACE("Returning Direct3D interface %p.\n", *out
);
185 /* Unknown interface */
188 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
190 return E_NOINTERFACE
;
193 IUnknown_AddRef((IUnknown
*)*out
);
197 static HRESULT WINAPI
ddraw4_QueryInterface(IDirectDraw4
*iface
, REFIID riid
, void **object
)
199 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
201 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
203 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
206 static HRESULT WINAPI
ddraw2_QueryInterface(IDirectDraw2
*iface
, REFIID riid
, void **object
)
208 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
210 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
212 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
215 static HRESULT WINAPI
ddraw1_QueryInterface(IDirectDraw
*iface
, REFIID riid
, void **object
)
217 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
219 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
221 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
224 static HRESULT WINAPI
d3d7_QueryInterface(IDirect3D7
*iface
, REFIID riid
, void **object
)
226 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
228 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
230 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
233 static HRESULT WINAPI
d3d3_QueryInterface(IDirect3D3
*iface
, REFIID riid
, void **object
)
235 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
237 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
239 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
242 static HRESULT WINAPI
d3d2_QueryInterface(IDirect3D2
*iface
, REFIID riid
, void **object
)
244 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
246 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
248 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
251 static HRESULT WINAPI
d3d1_QueryInterface(IDirect3D
*iface
, REFIID riid
, void **object
)
253 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
255 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
257 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
260 /*****************************************************************************
261 * IDirectDraw7::AddRef
263 * Increases the interfaces refcount, basically
265 * DDraw refcounting is a bit tricky. The different DirectDraw interface
266 * versions have individual refcounts, but the IDirect3D interfaces do not.
267 * All interfaces are from one object, that means calling QueryInterface on an
268 * IDirectDraw7 interface for an IDirectDraw4 interface does not create a new
271 * That means all AddRef and Release implementations of IDirectDrawX work
272 * with their own counter, and IDirect3DX::AddRef thunk to IDirectDraw (1),
273 * except of IDirect3D7 which thunks to IDirectDraw7
275 * Returns: The new refcount
277 *****************************************************************************/
278 static ULONG WINAPI
ddraw7_AddRef(IDirectDraw7
*iface
)
280 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
281 ULONG ref
= InterlockedIncrement(&This
->ref7
);
283 TRACE("%p increasing refcount to %u.\n", This
, ref
);
285 if(ref
== 1) InterlockedIncrement(&This
->numIfaces
);
290 static ULONG WINAPI
ddraw4_AddRef(IDirectDraw4
*iface
)
292 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
293 ULONG ref
= InterlockedIncrement(&This
->ref4
);
295 TRACE("%p increasing refcount to %u.\n", This
, ref
);
297 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
302 static ULONG WINAPI
ddraw2_AddRef(IDirectDraw2
*iface
)
304 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
305 ULONG ref
= InterlockedIncrement(&This
->ref2
);
307 TRACE("%p increasing refcount to %u.\n", This
, ref
);
309 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
314 static ULONG WINAPI
ddraw1_AddRef(IDirectDraw
*iface
)
316 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
317 ULONG ref
= InterlockedIncrement(&This
->ref1
);
319 TRACE("%p increasing refcount to %u.\n", This
, ref
);
321 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
326 static ULONG WINAPI
d3d7_AddRef(IDirect3D7
*iface
)
328 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
330 TRACE("iface %p.\n", iface
);
332 return ddraw7_AddRef(&This
->IDirectDraw7_iface
);
335 static ULONG WINAPI
d3d3_AddRef(IDirect3D3
*iface
)
337 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
339 TRACE("iface %p.\n", iface
);
341 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
344 static ULONG WINAPI
d3d2_AddRef(IDirect3D2
*iface
)
346 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
348 TRACE("iface %p.\n", iface
);
350 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
353 static ULONG WINAPI
d3d1_AddRef(IDirect3D
*iface
)
355 struct ddraw
*This
= impl_from_IDirect3D(iface
);
357 TRACE("iface %p.\n", iface
);
359 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
362 void ddraw_destroy_swapchain(struct ddraw
*ddraw
)
364 TRACE("Destroying the swapchain.\n");
366 wined3d_swapchain_decref(ddraw
->wined3d_swapchain
);
367 ddraw
->wined3d_swapchain
= NULL
;
369 if (!(ddraw
->flags
& DDRAW_NO3D
))
373 for (i
= 0; i
< ddraw
->numConvertedDecls
; ++i
)
375 wined3d_vertex_declaration_decref(ddraw
->decls
[i
].decl
);
377 HeapFree(GetProcessHeap(), 0, ddraw
->decls
);
378 ddraw
->numConvertedDecls
= 0;
380 if (FAILED(wined3d_device_uninit_3d(ddraw
->wined3d_device
)))
382 ERR("Failed to uninit 3D.\n");
386 /* Free the d3d window if one was created. */
387 if (ddraw
->d3d_window
&& ddraw
->d3d_window
!= ddraw
->dest_window
)
389 TRACE("Destroying the hidden render window %p.\n", ddraw
->d3d_window
);
390 DestroyWindow(ddraw
->d3d_window
);
391 ddraw
->d3d_window
= 0;
395 ddraw
->flags
&= ~DDRAW_D3D_INITIALIZED
;
399 wined3d_device_uninit_gdi(ddraw
->wined3d_device
);
402 ddraw_set_swapchain_window(ddraw
, NULL
);
404 TRACE("Swapchain destroyed.\n");
407 /*****************************************************************************
410 * Destroys a ddraw object if all refcounts are 0. This is to share code
411 * between the IDirectDrawX::Release functions
414 * This: DirectDraw object to destroy
416 *****************************************************************************/
417 static void ddraw_destroy(struct ddraw
*This
)
419 IDirectDraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, NULL
, DDSCL_NORMAL
);
420 IDirectDraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
422 /* Destroy the device window if we created one */
423 if(This
->devicewindow
!= 0)
425 TRACE(" (%p) Destroying the device window %p\n", This
, This
->devicewindow
);
426 DestroyWindow(This
->devicewindow
);
427 This
->devicewindow
= 0;
430 wined3d_mutex_lock();
431 list_remove(&This
->ddraw_list_entry
);
432 wined3d_mutex_unlock();
434 if (This
->wined3d_swapchain
)
435 ddraw_destroy_swapchain(This
);
436 wined3d_device_decref(This
->wined3d_device
);
437 wined3d_decref(This
->wined3d
);
440 This
->d3ddevice
->ddraw
= NULL
;
442 /* Now free the object */
443 HeapFree(GetProcessHeap(), 0, This
);
446 /*****************************************************************************
447 * IDirectDraw7::Release
449 * Decreases the refcount. If the refcount falls to 0, the object is destroyed
451 * Returns: The new refcount
452 *****************************************************************************/
453 static ULONG WINAPI
ddraw7_Release(IDirectDraw7
*iface
)
455 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
456 ULONG ref
= InterlockedDecrement(&This
->ref7
);
458 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
460 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
466 static ULONG WINAPI
ddraw4_Release(IDirectDraw4
*iface
)
468 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
469 ULONG ref
= InterlockedDecrement(&This
->ref4
);
471 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
473 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
479 static ULONG WINAPI
ddraw2_Release(IDirectDraw2
*iface
)
481 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
482 ULONG ref
= InterlockedDecrement(&This
->ref2
);
484 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
486 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
492 static ULONG WINAPI
ddraw1_Release(IDirectDraw
*iface
)
494 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
495 ULONG ref
= InterlockedDecrement(&This
->ref1
);
497 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
499 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
505 static ULONG WINAPI
d3d7_Release(IDirect3D7
*iface
)
507 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
509 TRACE("iface %p.\n", iface
);
511 return ddraw7_Release(&This
->IDirectDraw7_iface
);
514 static ULONG WINAPI
d3d3_Release(IDirect3D3
*iface
)
516 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
518 TRACE("iface %p.\n", iface
);
520 return ddraw1_Release(&This
->IDirectDraw_iface
);
523 static ULONG WINAPI
d3d2_Release(IDirect3D2
*iface
)
525 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
527 TRACE("iface %p.\n", iface
);
529 return ddraw1_Release(&This
->IDirectDraw_iface
);
532 static ULONG WINAPI
d3d1_Release(IDirect3D
*iface
)
534 struct ddraw
*This
= impl_from_IDirect3D(iface
);
536 TRACE("iface %p.\n", iface
);
538 return ddraw1_Release(&This
->IDirectDraw_iface
);
541 /*****************************************************************************
542 * IDirectDraw methods
543 *****************************************************************************/
545 static HRESULT
ddraw_set_focus_window(struct ddraw
*ddraw
, HWND window
)
547 /* FIXME: This looks wrong, exclusive mode should imply a destination
549 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) && ddraw
->dest_window
)
551 TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET.\n");
552 return DDERR_HWNDALREADYSET
;
555 ddraw
->focuswindow
= window
;
560 static HRESULT
ddraw_attach_d3d_device(struct ddraw
*ddraw
,
561 struct wined3d_swapchain_desc
*swapchain_desc
)
563 HWND window
= swapchain_desc
->device_window
;
566 TRACE("ddraw %p.\n", ddraw
);
568 if (!window
|| window
== GetDesktopWindow())
570 window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "Hidden D3D Window",
571 WS_DISABLED
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
572 NULL
, NULL
, NULL
, NULL
);
575 ERR("Failed to create window, last error %#x.\n", GetLastError());
579 ShowWindow(window
, SW_HIDE
); /* Just to be sure */
580 WARN("No window for the Direct3DDevice, created hidden window %p.\n", window
);
582 swapchain_desc
->device_window
= window
;
586 TRACE("Using existing window %p for Direct3D rendering.\n", window
);
588 ddraw
->d3d_window
= window
;
590 /* Set this NOW, otherwise creating the depth stencil surface will cause a
591 * recursive loop until ram or emulated video memory is full. */
592 ddraw
->flags
|= DDRAW_D3D_INITIALIZED
;
593 hr
= wined3d_device_init_3d(ddraw
->wined3d_device
, swapchain_desc
);
596 ddraw
->flags
&= ~DDRAW_D3D_INITIALIZED
;
600 ddraw
->declArraySize
= 2;
601 ddraw
->decls
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ddraw
->decls
) * ddraw
->declArraySize
);
604 ERR("Error allocating an array for the converted vertex decls.\n");
605 ddraw
->declArraySize
= 0;
606 hr
= wined3d_device_uninit_3d(ddraw
->wined3d_device
);
607 return E_OUTOFMEMORY
;
610 TRACE("Successfully initialized 3D.\n");
615 static HRESULT
ddraw_create_swapchain(struct ddraw
*ddraw
, HWND window
, BOOL windowed
)
617 struct wined3d_swapchain_desc swapchain_desc
;
618 struct wined3d_display_mode mode
;
619 HRESULT hr
= WINED3D_OK
;
621 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
623 ERR("Failed to get display mode.\n");
627 memset(&swapchain_desc
, 0, sizeof(swapchain_desc
));
628 swapchain_desc
.backbuffer_width
= mode
.width
;
629 swapchain_desc
.backbuffer_height
= mode
.height
;
630 swapchain_desc
.backbuffer_format
= mode
.format_id
;
631 swapchain_desc
.swap_effect
= WINED3D_SWAP_EFFECT_COPY
;
632 swapchain_desc
.device_window
= window
;
633 swapchain_desc
.windowed
= windowed
;
634 swapchain_desc
.flags
= WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH
;
636 if (!(ddraw
->flags
& DDRAW_NO3D
))
637 hr
= ddraw_attach_d3d_device(ddraw
, &swapchain_desc
);
639 hr
= wined3d_device_init_gdi(ddraw
->wined3d_device
, &swapchain_desc
);
643 ERR("Failed to create swapchain, hr %#x.\n", hr
);
647 if (!(ddraw
->wined3d_swapchain
= wined3d_device_get_swapchain(ddraw
->wined3d_device
, 0)))
649 ERR("Failed to get swapchain.\n");
650 return DDERR_INVALIDPARAMS
;
653 wined3d_swapchain_incref(ddraw
->wined3d_swapchain
);
654 ddraw_set_swapchain_window(ddraw
, window
);
659 /*****************************************************************************
660 * IDirectDraw7::RestoreDisplayMode
662 * Restores the display mode to what it was at creation time. Basically.
666 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
668 *****************************************************************************/
669 static HRESULT WINAPI
ddraw7_RestoreDisplayMode(IDirectDraw7
*iface
)
671 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
674 TRACE("iface %p.\n", iface
);
676 wined3d_mutex_lock();
678 if (!(ddraw
->flags
& DDRAW_RESTORE_MODE
))
680 wined3d_mutex_unlock();
684 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
686 wined3d_mutex_unlock();
687 return DDERR_NOEXCLUSIVEMODE
;
690 if (SUCCEEDED(hr
= wined3d_set_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, NULL
)))
691 ddraw
->flags
&= ~DDRAW_RESTORE_MODE
;
693 wined3d_mutex_unlock();
698 static HRESULT WINAPI
ddraw4_RestoreDisplayMode(IDirectDraw4
*iface
)
700 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
702 TRACE("iface %p.\n", iface
);
704 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
707 static HRESULT WINAPI
ddraw2_RestoreDisplayMode(IDirectDraw2
*iface
)
709 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
711 TRACE("iface %p.\n", iface
);
713 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
716 static HRESULT WINAPI
ddraw1_RestoreDisplayMode(IDirectDraw
*iface
)
718 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
720 TRACE("iface %p.\n", iface
);
722 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
725 /*****************************************************************************
726 * IDirectDraw7::SetCooperativeLevel
728 * Sets the cooperative level for the DirectDraw object, and the window
729 * assigned to it. The cooperative level determines the general behavior
730 * of the DirectDraw application
732 * Warning: This is quite tricky, as it's not really documented which
733 * cooperative levels can be combined with each other. If a game fails
734 * after this function, try to check the cooperative levels passed on
735 * Windows, and if it returns something different.
737 * If you think that this function caused the failure because it writes a
738 * fixme, be sure to run again with a +ddraw trace.
740 * What is known about cooperative levels (See the ddraw modes test):
741 * DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN.
742 * DDSCL_NORMAL is not compatible with DDSCL_EXCLUSIVE.
743 * Unlike what msdn claims, DDSCL_NORMAL | DDSCL_FULLSCREEN is allowed.
744 * DDSCL_SETFOCUSWINDOW can be passed only in DDSCL_NORMAL mode, but after that
745 * DDSCL_EXCLUSIVE can be activated.
746 * DDSCL_SETFOCUSWINDOW may only be used with DDSCL_NOWINDOWCHANGES or
747 * DDSCL_CREATEDEVICEWINDOW.
749 * Handled flags: DDSCL_NORMAL, DDSCL_FULLSCREEN, DDSCL_EXCLUSIVE,
750 * DDSCL_CREATEDEVICEWINDOW, DDSCL_SETDEVICEWINDOW
751 * DDSCL_SETFOCUSWINDOW (partially),
752 * DDSCL_MULTITHREADED (work in progress)
753 * DDSCL_FPUPRESERVE (see device.c)
755 * Unsure about this: DDSCL_FPUSETUP
757 * These don't seem very important for wine:
758 * DDSCL_ALLOWREBOOT, DDSCL_NOWINDOWCHANGES, DDSCL_ALLOWMODEX
761 * DD_OK if the cooperative level was set successfully
762 * DDERR_INVALIDPARAMS if the passed cooperative level combination is invalid
763 * DDERR_HWNDALREADYSET if DDSCL_SETFOCUSWINDOW is passed in exclusive mode
764 * (Probably others too, have to investigate)
766 *****************************************************************************/
767 static HRESULT
ddraw_set_cooperative_level(struct ddraw
*ddraw
, HWND window
,
768 DWORD cooplevel
, BOOL restore_mode_on_normal
)
770 struct wined3d_rendertarget_view
*rtv
= NULL
, *dsv
= NULL
;
771 struct wined3d_stateblock
*stateblock
;
772 BOOL restore_state
= FALSE
;
775 TRACE("ddraw %p, window %p, flags %#x, restore_mode_on_normal %x.\n", ddraw
, window
, cooplevel
,
776 restore_mode_on_normal
);
777 DDRAW_dump_cooperativelevel(cooplevel
);
779 wined3d_mutex_lock();
781 if (ddraw
->flags
& DDRAW_SCL_RECURSIVE
)
783 WARN("Recursive call, returning DD_OK.\n");
787 ddraw
->flags
|= DDRAW_SCL_RECURSIVE
;
789 /* Tests suggest that we need one of them: */
790 if(!(cooplevel
& (DDSCL_SETFOCUSWINDOW
|
794 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
795 hr
= DDERR_INVALIDPARAMS
;
799 if ((cooplevel
& DDSCL_CREATEDEVICEWINDOW
) && !(cooplevel
& DDSCL_EXCLUSIVE
))
801 WARN("DDSCL_CREATEDEVICEWINDOW requires DDSCL_EXCLUSIVE.\n");
802 hr
= DDERR_INVALIDPARAMS
;
806 /* Handle those levels first which set various hwnds */
807 if ((cooplevel
& DDSCL_SETFOCUSWINDOW
) && !(cooplevel
& DDSCL_CREATEDEVICEWINDOW
))
809 /* This isn't compatible with a lot of flags */
810 if (cooplevel
& (DDSCL_MULTITHREADED
815 | DDSCL_SETDEVICEWINDOW
820 WARN("Called with incompatible flags, returning DDERR_INVALIDPARAMS.\n");
821 hr
= DDERR_INVALIDPARAMS
;
825 hr
= ddraw_set_focus_window(ddraw
, window
);
829 if (cooplevel
& DDSCL_EXCLUSIVE
)
831 if (!(cooplevel
& DDSCL_FULLSCREEN
) || !(window
|| (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)))
833 WARN("DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN and a window.\n");
834 hr
= DDERR_INVALIDPARAMS
;
838 if (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)
842 if (!ddraw
->focuswindow
&& !(cooplevel
& DDSCL_SETFOCUSWINDOW
))
844 WARN("No focus window set.\n");
845 hr
= DDERR_NOFOCUSWINDOW
;
849 device_window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "DirectDrawDeviceWnd",
850 WS_POPUP
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
851 NULL
, NULL
, NULL
, NULL
);
854 ERR("Failed to create window, last error %#x.\n", GetLastError());
859 ShowWindow(device_window
, SW_SHOW
);
860 TRACE("Created a device window %p.\n", device_window
);
862 /* Native apparently leaks the created device window if setting the
863 * focus window below fails. */
864 ddraw
->cooperative_level
|= DDSCL_CREATEDEVICEWINDOW
;
865 ddraw
->devicewindow
= device_window
;
867 if (cooplevel
& DDSCL_SETFOCUSWINDOW
)
875 if (FAILED(hr
= ddraw_set_focus_window(ddraw
, window
)))
879 window
= device_window
;
884 if (ddraw
->cooperative_level
& DDSCL_CREATEDEVICEWINDOW
)
885 DestroyWindow(ddraw
->devicewindow
);
886 ddraw
->devicewindow
= NULL
;
887 ddraw
->focuswindow
= NULL
;
890 if ((cooplevel
& DDSCL_FULLSCREEN
) != (ddraw
->cooperative_level
& DDSCL_FULLSCREEN
) || window
!= ddraw
->dest_window
)
892 if (ddraw
->cooperative_level
& DDSCL_FULLSCREEN
)
893 wined3d_device_restore_fullscreen_window(ddraw
->wined3d_device
, ddraw
->dest_window
, NULL
);
895 if (cooplevel
& DDSCL_FULLSCREEN
)
897 struct wined3d_display_mode display_mode
;
899 wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &display_mode
, NULL
);
900 wined3d_device_setup_fullscreen_window(ddraw
->wined3d_device
, window
,
901 display_mode
.width
, display_mode
.height
);
905 if ((cooplevel
& DDSCL_EXCLUSIVE
) && exclusive_window
!= window
)
907 ddraw
->device_state
= DDRAW_DEVICE_STATE_NOT_RESTORED
;
908 exclusive_window
= window
;
911 if (cooplevel
& DDSCL_MULTITHREADED
&& !(ddraw
->cooperative_level
& DDSCL_MULTITHREADED
))
912 wined3d_device_set_multithreaded(ddraw
->wined3d_device
);
914 if (ddraw
->wined3d_swapchain
)
916 if (!(ddraw
->flags
& DDRAW_NO3D
))
918 restore_state
= TRUE
;
920 if (FAILED(hr
= wined3d_stateblock_create(ddraw
->wined3d_device
, WINED3D_SBT_ALL
, &stateblock
)))
922 ERR("Failed to create stateblock, hr %#x.\n", hr
);
926 wined3d_stateblock_capture(stateblock
);
927 rtv
= wined3d_device_get_rendertarget_view(ddraw
->wined3d_device
, 0);
928 /* Rendering to ddraw->wined3d_frontbuffer. */
929 if (rtv
&& !wined3d_rendertarget_view_get_sub_resource_parent(rtv
))
932 wined3d_rendertarget_view_incref(rtv
);
934 if ((dsv
= wined3d_device_get_depth_stencil_view(ddraw
->wined3d_device
)))
935 wined3d_rendertarget_view_incref(dsv
);
938 ddraw_destroy_swapchain(ddraw
);
941 if (FAILED(hr
= ddraw_create_swapchain(ddraw
, window
, !(cooplevel
& DDSCL_FULLSCREEN
))))
942 ERR("Failed to create swapchain, hr %#x.\n", hr
);
948 wined3d_device_set_depth_stencil_view(ddraw
->wined3d_device
, dsv
);
949 wined3d_rendertarget_view_decref(dsv
);
954 wined3d_device_set_rendertarget_view(ddraw
->wined3d_device
, 0, rtv
, FALSE
);
955 wined3d_rendertarget_view_decref(rtv
);
958 wined3d_stateblock_apply(stateblock
);
959 wined3d_stateblock_decref(stateblock
);
962 if (!(cooplevel
& DDSCL_EXCLUSIVE
) && (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
963 && restore_mode_on_normal
)
965 hr
= ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
967 ERR("RestoreDisplayMode failed\n");
970 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
971 && (window
!= ddraw
->dest_window
|| !(cooplevel
& DDSCL_EXCLUSIVE
)))
972 wined3d_device_release_focus_window(ddraw
->wined3d_device
);
974 if ((cooplevel
& DDSCL_EXCLUSIVE
)
975 && (window
!= ddraw
->dest_window
|| !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)))
977 hr
= wined3d_device_acquire_focus_window(ddraw
->wined3d_device
, window
);
980 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
985 /* Unhandled flags */
986 if (cooplevel
& DDSCL_ALLOWREBOOT
)
987 WARN("Unhandled flag DDSCL_ALLOWREBOOT, harmless\n");
988 if (cooplevel
& DDSCL_ALLOWMODEX
)
989 WARN("Unhandled flag DDSCL_ALLOWMODEX, harmless\n");
990 if (cooplevel
& DDSCL_FPUSETUP
)
991 WARN("Unhandled flag DDSCL_FPUSETUP, harmless\n");
993 if (cooplevel
& DDSCL_EXCLUSIVE
)
994 exclusive_ddraw
= ddraw
;
995 else if (exclusive_ddraw
== ddraw
)
996 exclusive_ddraw
= NULL
;
998 /* Store the cooperative_level */
999 ddraw
->cooperative_level
= cooplevel
;
1000 ddraw
->dest_window
= window
;
1002 TRACE("SetCooperativeLevel returning DD_OK\n");
1005 ddraw
->flags
&= ~DDRAW_SCL_RECURSIVE
;
1006 wined3d_mutex_unlock();
1011 static HRESULT WINAPI
ddraw7_SetCooperativeLevel(IDirectDraw7
*iface
, HWND window
, DWORD flags
)
1013 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1015 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1017 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1020 static HRESULT WINAPI
ddraw4_SetCooperativeLevel(IDirectDraw4
*iface
, HWND window
, DWORD flags
)
1022 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1024 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1026 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1029 static HRESULT WINAPI
ddraw2_SetCooperativeLevel(IDirectDraw2
*iface
, HWND window
, DWORD flags
)
1031 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1033 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1035 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1038 static HRESULT WINAPI
ddraw1_SetCooperativeLevel(IDirectDraw
*iface
, HWND window
, DWORD flags
)
1040 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1043 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1045 hr
= ddraw_set_cooperative_level(ddraw
, window
, flags
, FALSE
);
1047 ddraw
->flags
|= DDRAW_SCL_DDRAW1
;
1051 /*****************************************************************************
1052 * IDirectDraw7::SetDisplayMode
1054 * Sets the display screen resolution, color depth and refresh frequency
1055 * when in fullscreen mode (in theory).
1056 * Possible return values listed in the SDK suggest that this method fails
1057 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
1058 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
1059 * It seems to be valid to pass 0 for With and Height, this has to be tested
1060 * It could mean that the current video mode should be left as-is. (But why
1064 * Height, Width: Screen dimension
1065 * BPP: Color depth in Bits per pixel
1066 * Refreshrate: Screen refresh rate
1067 * Flags: Other stuff
1072 *****************************************************************************/
1073 static HRESULT WINAPI
ddraw7_SetDisplayMode(IDirectDraw7
*iface
, DWORD width
, DWORD height
,
1074 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1076 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1077 struct wined3d_display_mode mode
;
1078 enum wined3d_format_id format
;
1081 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1082 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1084 if (force_refresh_rate
!= 0)
1086 TRACE("ForceRefreshRate overriding passed-in refresh rate (%u Hz) to %u Hz\n",
1087 refresh_rate
, force_refresh_rate
);
1088 refresh_rate
= force_refresh_rate
;
1091 wined3d_mutex_lock();
1093 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
1095 wined3d_mutex_unlock();
1096 return DDERR_NOEXCLUSIVEMODE
;
1099 if (!width
|| !height
)
1101 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here. */
1102 wined3d_mutex_unlock();
1108 case 8: format
= WINED3DFMT_P8_UINT
; break;
1109 case 15: format
= WINED3DFMT_B5G5R5X1_UNORM
; break;
1110 case 16: format
= WINED3DFMT_B5G6R5_UNORM
; break;
1111 case 24: format
= WINED3DFMT_B8G8R8_UNORM
; break;
1112 case 32: format
= WINED3DFMT_B8G8R8X8_UNORM
; break;
1113 default: format
= WINED3DFMT_UNKNOWN
; break;
1117 mode
.height
= height
;
1118 mode
.refresh_rate
= refresh_rate
;
1119 mode
.format_id
= format
;
1120 mode
.scanline_ordering
= WINED3D_SCANLINE_ORDERING_UNKNOWN
;
1122 /* TODO: The possible return values from msdn suggest that the screen mode
1123 * can't be changed if a surface is locked or some drawing is in progress. */
1124 if (SUCCEEDED(hr
= wined3d_set_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
)))
1125 ddraw
->flags
|= DDRAW_RESTORE_MODE
;
1127 wined3d_mutex_unlock();
1131 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1136 static HRESULT WINAPI
ddraw4_SetDisplayMode(IDirectDraw4
*iface
, DWORD width
, DWORD height
,
1137 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1139 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1141 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1142 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1144 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1147 static HRESULT WINAPI
ddraw2_SetDisplayMode(IDirectDraw2
*iface
,
1148 DWORD width
, DWORD height
, DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1150 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1152 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1153 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1155 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1158 static HRESULT WINAPI
ddraw1_SetDisplayMode(IDirectDraw
*iface
, DWORD width
, DWORD height
, DWORD bpp
)
1160 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1162 TRACE("iface %p, width %u, height %u, bpp %u.\n", iface
, width
, height
, bpp
);
1164 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, 0, 0);
1167 void ddraw_d3dcaps1_from_7(D3DDEVICEDESC
*caps1
, D3DDEVICEDESC7
*caps7
)
1169 memset(caps1
, 0, sizeof(*caps1
));
1170 caps1
->dwSize
= sizeof(*caps1
);
1171 caps1
->dwFlags
= D3DDD_COLORMODEL
1173 | D3DDD_TRANSFORMCAPS
1175 | D3DDD_LIGHTINGCAPS
1178 | D3DDD_DEVICERENDERBITDEPTH
1179 | D3DDD_DEVICEZBUFFERBITDEPTH
1180 | D3DDD_MAXBUFFERSIZE
1181 | D3DDD_MAXVERTEXCOUNT
;
1182 caps1
->dcmColorModel
= D3DCOLOR_RGB
;
1183 caps1
->dwDevCaps
= caps7
->dwDevCaps
;
1184 caps1
->dtcTransformCaps
.dwSize
= sizeof(caps1
->dtcTransformCaps
);
1185 caps1
->dtcTransformCaps
.dwCaps
= D3DTRANSFORMCAPS_CLIP
;
1186 caps1
->bClipping
= TRUE
;
1187 caps1
->dlcLightingCaps
.dwSize
= sizeof(caps1
->dlcLightingCaps
);
1188 caps1
->dlcLightingCaps
.dwCaps
= D3DLIGHTCAPS_DIRECTIONAL
1189 | D3DLIGHTCAPS_PARALLELPOINT
1190 | D3DLIGHTCAPS_POINT
1191 | D3DLIGHTCAPS_SPOT
;
1192 caps1
->dlcLightingCaps
.dwLightingModel
= D3DLIGHTINGMODEL_RGB
;
1193 caps1
->dlcLightingCaps
.dwNumLights
= caps7
->dwMaxActiveLights
;
1194 caps1
->dpcLineCaps
= caps7
->dpcLineCaps
;
1195 caps1
->dpcTriCaps
= caps7
->dpcTriCaps
;
1196 caps1
->dwDeviceRenderBitDepth
= caps7
->dwDeviceRenderBitDepth
;
1197 caps1
->dwDeviceZBufferBitDepth
= caps7
->dwDeviceZBufferBitDepth
;
1198 caps1
->dwMaxBufferSize
= 0;
1199 caps1
->dwMaxVertexCount
= 65536;
1200 caps1
->dwMinTextureWidth
= caps7
->dwMinTextureWidth
;
1201 caps1
->dwMinTextureHeight
= caps7
->dwMinTextureHeight
;
1202 caps1
->dwMaxTextureWidth
= caps7
->dwMaxTextureWidth
;
1203 caps1
->dwMaxTextureHeight
= caps7
->dwMaxTextureHeight
;
1204 caps1
->dwMinStippleWidth
= 1;
1205 caps1
->dwMinStippleHeight
= 1;
1206 caps1
->dwMaxStippleWidth
= 32;
1207 caps1
->dwMaxStippleHeight
= 32;
1208 caps1
->dwMaxTextureRepeat
= caps7
->dwMaxTextureRepeat
;
1209 caps1
->dwMaxTextureAspectRatio
= caps7
->dwMaxTextureAspectRatio
;
1210 caps1
->dwMaxAnisotropy
= caps7
->dwMaxAnisotropy
;
1211 caps1
->dvGuardBandLeft
= caps7
->dvGuardBandLeft
;
1212 caps1
->dvGuardBandTop
= caps7
->dvGuardBandTop
;
1213 caps1
->dvGuardBandRight
= caps7
->dvGuardBandRight
;
1214 caps1
->dvGuardBandBottom
= caps7
->dvGuardBandBottom
;
1215 caps1
->dvExtentsAdjust
= caps7
->dvExtentsAdjust
;
1216 caps1
->dwStencilCaps
= caps7
->dwStencilCaps
;
1217 caps1
->dwFVFCaps
= caps7
->dwFVFCaps
;
1218 caps1
->dwTextureOpCaps
= caps7
->dwTextureOpCaps
;
1219 caps1
->wMaxTextureBlendStages
= caps7
->wMaxTextureBlendStages
;
1220 caps1
->wMaxSimultaneousTextures
= caps7
->wMaxSimultaneousTextures
;
1223 HRESULT
ddraw_get_d3dcaps(const struct ddraw
*ddraw
, D3DDEVICEDESC7
*caps
)
1225 WINED3DCAPS wined3d_caps
;
1228 TRACE("ddraw %p, caps %p.\n", ddraw
, caps
);
1230 memset(&wined3d_caps
, 0, sizeof(wined3d_caps
));
1232 wined3d_mutex_lock();
1233 hr
= wined3d_get_device_caps(ddraw
->wined3d
, 0, WINED3D_DEVICE_TYPE_HAL
, &wined3d_caps
);
1234 wined3d_mutex_unlock();
1237 WARN("Failed to get device caps, hr %#x.\n", hr
);
1241 caps
->dwDevCaps
= wined3d_caps
.DevCaps
;
1242 caps
->dpcLineCaps
.dwMiscCaps
= wined3d_caps
.PrimitiveMiscCaps
;
1243 caps
->dpcLineCaps
.dwRasterCaps
= wined3d_caps
.RasterCaps
;
1244 caps
->dpcLineCaps
.dwZCmpCaps
= wined3d_caps
.ZCmpCaps
;
1245 caps
->dpcLineCaps
.dwSrcBlendCaps
= wined3d_caps
.SrcBlendCaps
;
1246 caps
->dpcLineCaps
.dwDestBlendCaps
= wined3d_caps
.DestBlendCaps
;
1247 caps
->dpcLineCaps
.dwAlphaCmpCaps
= wined3d_caps
.AlphaCmpCaps
;
1248 caps
->dpcLineCaps
.dwShadeCaps
= wined3d_caps
.ShadeCaps
;
1249 caps
->dpcLineCaps
.dwTextureCaps
= wined3d_caps
.TextureCaps
;
1250 caps
->dpcLineCaps
.dwTextureFilterCaps
= wined3d_caps
.TextureFilterCaps
;
1251 caps
->dpcLineCaps
.dwTextureAddressCaps
= wined3d_caps
.TextureAddressCaps
;
1253 caps
->dwMaxTextureWidth
= wined3d_caps
.MaxTextureWidth
;
1254 caps
->dwMaxTextureHeight
= wined3d_caps
.MaxTextureHeight
;
1256 caps
->dwMaxTextureRepeat
= wined3d_caps
.MaxTextureRepeat
;
1257 caps
->dwMaxTextureAspectRatio
= wined3d_caps
.MaxTextureAspectRatio
;
1258 caps
->dwMaxAnisotropy
= wined3d_caps
.MaxAnisotropy
;
1259 caps
->dvMaxVertexW
= wined3d_caps
.MaxVertexW
;
1261 caps
->dvGuardBandLeft
= wined3d_caps
.GuardBandLeft
;
1262 caps
->dvGuardBandTop
= wined3d_caps
.GuardBandTop
;
1263 caps
->dvGuardBandRight
= wined3d_caps
.GuardBandRight
;
1264 caps
->dvGuardBandBottom
= wined3d_caps
.GuardBandBottom
;
1266 caps
->dvExtentsAdjust
= wined3d_caps
.ExtentsAdjust
;
1267 caps
->dwStencilCaps
= wined3d_caps
.StencilCaps
;
1269 caps
->dwFVFCaps
= wined3d_caps
.FVFCaps
;
1270 caps
->dwTextureOpCaps
= wined3d_caps
.TextureOpCaps
;
1272 caps
->dwVertexProcessingCaps
= wined3d_caps
.VertexProcessingCaps
;
1273 caps
->dwMaxActiveLights
= wined3d_caps
.MaxActiveLights
;
1275 /* Remove all non-d3d7 caps */
1276 caps
->dwDevCaps
&= (
1277 D3DDEVCAPS_FLOATTLVERTEX
| D3DDEVCAPS_SORTINCREASINGZ
| D3DDEVCAPS_SORTDECREASINGZ
|
1278 D3DDEVCAPS_SORTEXACT
| D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
|
1279 D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
| D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
|
1280 D3DDEVCAPS_TEXTUREVIDEOMEMORY
| D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
|
1281 D3DDEVCAPS_TEXTURENONLOCALVIDMEM
| D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
1282 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
1283 D3DDEVCAPS_HWRASTERIZATION
);
1285 caps
->dwStencilCaps
&= (
1286 D3DSTENCILCAPS_KEEP
| D3DSTENCILCAPS_ZERO
| D3DSTENCILCAPS_REPLACE
|
1287 D3DSTENCILCAPS_INCRSAT
| D3DSTENCILCAPS_DECRSAT
| D3DSTENCILCAPS_INVERT
|
1288 D3DSTENCILCAPS_INCR
| D3DSTENCILCAPS_DECR
);
1292 caps
->dwTextureOpCaps
&= (
1293 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_SELECTARG2
|
1294 D3DTEXOPCAPS_MODULATE
| D3DTEXOPCAPS_MODULATE2X
| D3DTEXOPCAPS_MODULATE4X
|
1295 D3DTEXOPCAPS_ADD
| D3DTEXOPCAPS_ADDSIGNED
| D3DTEXOPCAPS_ADDSIGNED2X
|
1296 D3DTEXOPCAPS_SUBTRACT
| D3DTEXOPCAPS_ADDSMOOTH
| D3DTEXOPCAPS_BLENDTEXTUREALPHA
|
1297 D3DTEXOPCAPS_BLENDFACTORALPHA
| D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
| D3DTEXOPCAPS_BLENDCURRENTALPHA
|
1298 D3DTEXOPCAPS_PREMODULATE
| D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
|
1299 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
| D3DTEXOPCAPS_BUMPENVMAP
|
1300 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
| D3DTEXOPCAPS_DOTPRODUCT3
);
1302 caps
->dwVertexProcessingCaps
&= (
1303 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_VERTEXFOG
|
1304 D3DVTXPCAPS_DIRECTIONALLIGHTS
| D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
);
1306 caps
->dpcLineCaps
.dwMiscCaps
&= (
1307 D3DPMISCCAPS_MASKPLANES
| D3DPMISCCAPS_MASKZ
| D3DPMISCCAPS_LINEPATTERNREP
|
1308 D3DPMISCCAPS_CONFORMANT
| D3DPMISCCAPS_CULLNONE
| D3DPMISCCAPS_CULLCW
|
1309 D3DPMISCCAPS_CULLCCW
);
1311 caps
->dpcLineCaps
.dwRasterCaps
&= (
1312 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ROP2
| D3DPRASTERCAPS_XOR
|
1313 D3DPRASTERCAPS_PAT
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_SUBPIXEL
|
1314 D3DPRASTERCAPS_SUBPIXELX
| D3DPRASTERCAPS_FOGVERTEX
| D3DPRASTERCAPS_FOGTABLE
|
1315 D3DPRASTERCAPS_STIPPLE
| D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT
| D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT
|
1316 D3DPRASTERCAPS_ANTIALIASEDGES
| D3DPRASTERCAPS_MIPMAPLODBIAS
| D3DPRASTERCAPS_ZBIAS
|
1317 D3DPRASTERCAPS_ZBUFFERLESSHSR
| D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
|
1318 D3DPRASTERCAPS_WBUFFER
| D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT
| D3DPRASTERCAPS_WFOG
|
1319 D3DPRASTERCAPS_ZFOG
);
1321 caps
->dpcLineCaps
.dwZCmpCaps
&= (
1322 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
1323 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
1324 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
1326 caps
->dpcLineCaps
.dwSrcBlendCaps
&= (
1327 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
1328 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
1329 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
1330 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
1331 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
1333 caps
->dpcLineCaps
.dwDestBlendCaps
&= (
1334 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
1335 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
1336 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
1337 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
1338 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
1340 caps
->dpcLineCaps
.dwAlphaCmpCaps
&= (
1341 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
1342 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
1343 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
1345 caps
->dpcLineCaps
.dwShadeCaps
&= (
1346 D3DPSHADECAPS_COLORFLATMONO
| D3DPSHADECAPS_COLORFLATRGB
| D3DPSHADECAPS_COLORGOURAUDMONO
|
1347 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_COLORPHONGMONO
| D3DPSHADECAPS_COLORPHONGRGB
|
1348 D3DPSHADECAPS_SPECULARFLATMONO
| D3DPSHADECAPS_SPECULARFLATRGB
| D3DPSHADECAPS_SPECULARGOURAUDMONO
|
1349 D3DPSHADECAPS_SPECULARGOURAUDRGB
| D3DPSHADECAPS_SPECULARPHONGMONO
| D3DPSHADECAPS_SPECULARPHONGRGB
|
1350 D3DPSHADECAPS_ALPHAFLATBLEND
| D3DPSHADECAPS_ALPHAFLATSTIPPLED
| D3DPSHADECAPS_ALPHAGOURAUDBLEND
|
1351 D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED
| D3DPSHADECAPS_ALPHAPHONGBLEND
| D3DPSHADECAPS_ALPHAPHONGSTIPPLED
|
1352 D3DPSHADECAPS_FOGFLAT
| D3DPSHADECAPS_FOGGOURAUD
| D3DPSHADECAPS_FOGPHONG
);
1354 caps
->dpcLineCaps
.dwTextureCaps
&= (
1355 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
1356 D3DPTEXTURECAPS_TRANSPARENCY
| D3DPTEXTURECAPS_BORDER
| D3DPTEXTURECAPS_SQUAREONLY
|
1357 D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
| D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
1358 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_COLORKEYBLEND
);
1360 caps
->dpcLineCaps
.dwTextureFilterCaps
&= (
1361 D3DPTFILTERCAPS_NEAREST
| D3DPTFILTERCAPS_LINEAR
| D3DPTFILTERCAPS_MIPNEAREST
|
1362 D3DPTFILTERCAPS_MIPLINEAR
| D3DPTFILTERCAPS_LINEARMIPNEAREST
| D3DPTFILTERCAPS_LINEARMIPLINEAR
|
1363 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
1364 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
1365 D3DPTFILTERCAPS_MAGFLINEAR
| D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
|
1366 D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
);
1368 caps
->dpcLineCaps
.dwTextureAddressCaps
&= (
1369 D3DPTADDRESSCAPS_WRAP
| D3DPTADDRESSCAPS_MIRROR
| D3DPTADDRESSCAPS_CLAMP
|
1370 D3DPTADDRESSCAPS_BORDER
| D3DPTADDRESSCAPS_INDEPENDENTUV
);
1372 if (!(caps
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
))
1374 /* DirectX7 always has the np2 flag set, no matter what the card
1375 * supports. Some old games (Rollcage) check the caps incorrectly.
1376 * If wined3d supports nonpow2 textures it also has np2 conditional
1378 caps
->dpcLineCaps
.dwTextureCaps
|= D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
;
1381 /* Fill the missing members, and do some fixup */
1382 caps
->dpcLineCaps
.dwSize
= sizeof(caps
->dpcLineCaps
);
1383 caps
->dpcLineCaps
.dwTextureBlendCaps
= D3DPTBLENDCAPS_ADD
1384 | D3DPTBLENDCAPS_MODULATEMASK
1385 | D3DPTBLENDCAPS_COPY
1386 | D3DPTBLENDCAPS_DECAL
1387 | D3DPTBLENDCAPS_DECALALPHA
1388 | D3DPTBLENDCAPS_DECALMASK
1389 | D3DPTBLENDCAPS_MODULATE
1390 | D3DPTBLENDCAPS_MODULATEALPHA
;
1391 caps
->dpcLineCaps
.dwStippleWidth
= 32;
1392 caps
->dpcLineCaps
.dwStippleHeight
= 32;
1393 /* Use the same for the TriCaps */
1394 caps
->dpcTriCaps
= caps
->dpcLineCaps
;
1396 caps
->dwDeviceRenderBitDepth
= DDBD_16
| DDBD_24
| DDBD_32
;
1397 caps
->dwDeviceZBufferBitDepth
= DDBD_16
| DDBD_24
;
1398 caps
->dwMinTextureWidth
= 1;
1399 caps
->dwMinTextureHeight
= 1;
1401 /* Convert DWORDs safely to WORDs */
1402 if (wined3d_caps
.MaxTextureBlendStages
> 0xffff)
1403 caps
->wMaxTextureBlendStages
= 0xffff;
1405 caps
->wMaxTextureBlendStages
= (WORD
)wined3d_caps
.MaxTextureBlendStages
;
1406 if (wined3d_caps
.MaxSimultaneousTextures
> 0xffff)
1407 caps
->wMaxSimultaneousTextures
= 0xffff;
1409 caps
->wMaxSimultaneousTextures
= (WORD
)wined3d_caps
.MaxSimultaneousTextures
;
1411 if (wined3d_caps
.MaxUserClipPlanes
> 0xffff)
1412 caps
->wMaxUserClipPlanes
= 0xffff;
1414 caps
->wMaxUserClipPlanes
= (WORD
)wined3d_caps
.MaxUserClipPlanes
;
1415 if (wined3d_caps
.MaxVertexBlendMatrices
> 0xffff)
1416 caps
->wMaxVertexBlendMatrices
= 0xffff;
1418 caps
->wMaxVertexBlendMatrices
= (WORD
)wined3d_caps
.MaxVertexBlendMatrices
;
1420 caps
->deviceGUID
= IID_IDirect3DTnLHalDevice
;
1422 caps
->dwReserved1
= 0;
1423 caps
->dwReserved2
= 0;
1424 caps
->dwReserved3
= 0;
1425 caps
->dwReserved4
= 0;
1430 /*****************************************************************************
1431 * IDirectDraw7::GetCaps
1433 * Returns the drives capabilities
1435 * Used for version 1, 2, 4 and 7
1438 * DriverCaps: Structure to write the Hardware accelerated caps to
1439 * HelCaps: Structure to write the emulation caps to
1442 * This implementation returns DD_OK only
1444 *****************************************************************************/
1445 static HRESULT WINAPI
ddraw7_GetCaps(IDirectDraw7
*iface
, DDCAPS
*DriverCaps
, DDCAPS
*HELCaps
)
1447 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1449 WINED3DCAPS winecaps
;
1451 DDSCAPS2 ddscaps
= {0, 0, 0, {0}};
1453 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, DriverCaps
, HELCaps
);
1455 /* One structure must be != NULL */
1456 if (!DriverCaps
&& !HELCaps
)
1458 WARN("Invalid parameters.\n");
1459 return DDERR_INVALIDPARAMS
;
1462 memset(&caps
, 0, sizeof(caps
));
1463 memset(&winecaps
, 0, sizeof(winecaps
));
1464 caps
.dwSize
= sizeof(caps
);
1466 wined3d_mutex_lock();
1467 hr
= wined3d_device_get_device_caps(ddraw
->wined3d_device
, &winecaps
);
1470 WARN("IWineD3DDevice::GetDeviceCaps failed\n");
1471 wined3d_mutex_unlock();
1475 hr
= IDirectDraw7_GetAvailableVidMem(iface
, &ddscaps
, &caps
.dwVidMemTotal
, &caps
.dwVidMemFree
);
1478 WARN("IDirectDraw7::GetAvailableVidMem failed\n");
1479 wined3d_mutex_unlock();
1483 hr
= IDirectDraw7_GetFourCCCodes(iface
, &caps
.dwNumFourCCCodes
, NULL
);
1484 wined3d_mutex_unlock();
1487 WARN("IDirectDraw7::GetFourCCCodes failed\n");
1491 caps
.dwCaps
= winecaps
.ddraw_caps
.caps
;
1492 caps
.dwCaps2
= winecaps
.ddraw_caps
.caps2
;
1493 caps
.dwCKeyCaps
= winecaps
.ddraw_caps
.color_key_caps
;
1494 caps
.dwFXCaps
= winecaps
.ddraw_caps
.fx_caps
;
1495 caps
.dwPalCaps
= DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
;
1496 caps
.ddsCaps
.dwCaps
= winecaps
.ddraw_caps
.dds_caps
;
1497 caps
.dwSVBCaps
= winecaps
.ddraw_caps
.svb_caps
;
1498 caps
.dwSVBCKeyCaps
= winecaps
.ddraw_caps
.svb_color_key_caps
;
1499 caps
.dwSVBFXCaps
= winecaps
.ddraw_caps
.svb_fx_caps
;
1500 caps
.dwVSBCaps
= winecaps
.ddraw_caps
.vsb_caps
;
1501 caps
.dwVSBCKeyCaps
= winecaps
.ddraw_caps
.vsb_color_key_caps
;
1502 caps
.dwVSBFXCaps
= winecaps
.ddraw_caps
.vsb_fx_caps
;
1503 caps
.dwSSBCaps
= winecaps
.ddraw_caps
.ssb_caps
;
1504 caps
.dwSSBCKeyCaps
= winecaps
.ddraw_caps
.ssb_color_key_caps
;
1505 caps
.dwSSBFXCaps
= winecaps
.ddraw_caps
.ssb_fx_caps
;
1507 caps
.dwCaps
|= DDCAPS_ALIGNSTRIDE
;
1508 caps
.dwAlignStrideAlign
= DDRAW_STRIDE_ALIGNMENT
;
1512 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &caps
);
1513 if (TRACE_ON(ddraw
))
1515 TRACE("Driver Caps :\n");
1516 DDRAW_dump_DDCAPS(DriverCaps
);
1522 DD_STRUCT_COPY_BYSIZE(HELCaps
, &caps
);
1523 if (TRACE_ON(ddraw
))
1525 TRACE("HEL Caps :\n");
1526 DDRAW_dump_DDCAPS(HELCaps
);
1533 static HRESULT WINAPI
ddraw4_GetCaps(IDirectDraw4
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1535 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1537 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1539 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1542 static HRESULT WINAPI
ddraw2_GetCaps(IDirectDraw2
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1544 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1546 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1548 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1551 static HRESULT WINAPI
ddraw1_GetCaps(IDirectDraw
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1553 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1555 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1557 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1560 /*****************************************************************************
1561 * IDirectDraw7::Compact
1563 * No idea what it does, MSDN says it's not implemented.
1566 * DD_OK, but this is unchecked
1568 *****************************************************************************/
1569 static HRESULT WINAPI
ddraw7_Compact(IDirectDraw7
*iface
)
1571 TRACE("iface %p.\n", iface
);
1576 static HRESULT WINAPI
ddraw4_Compact(IDirectDraw4
*iface
)
1578 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1580 TRACE("iface %p.\n", iface
);
1582 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1585 static HRESULT WINAPI
ddraw2_Compact(IDirectDraw2
*iface
)
1587 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1589 TRACE("iface %p.\n", iface
);
1591 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1594 static HRESULT WINAPI
ddraw1_Compact(IDirectDraw
*iface
)
1596 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1598 TRACE("iface %p.\n", iface
);
1600 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1603 /*****************************************************************************
1604 * IDirectDraw7::GetDisplayMode
1606 * Returns information about the current display mode
1608 * Exists in versions 1, 2, 4 and 7
1611 * DDSD: Address of a surface description structure to write the info to
1616 *****************************************************************************/
1617 static HRESULT WINAPI
ddraw7_GetDisplayMode(IDirectDraw7
*iface
, DDSURFACEDESC2
*DDSD
)
1619 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1620 struct wined3d_display_mode mode
;
1624 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
1626 wined3d_mutex_lock();
1627 /* This seems sane */
1630 wined3d_mutex_unlock();
1631 return DDERR_INVALIDPARAMS
;
1634 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1636 ERR("Failed to get display mode, hr %#x.\n", hr
);
1637 wined3d_mutex_unlock();
1641 Size
= DDSD
->dwSize
;
1642 memset(DDSD
, 0, Size
);
1644 DDSD
->dwSize
= Size
;
1645 DDSD
->dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
1646 DDSD
->dwWidth
= mode
.width
;
1647 DDSD
->dwHeight
= mode
.height
;
1648 DDSD
->u2
.dwRefreshRate
= 60;
1649 DDSD
->ddsCaps
.dwCaps
= 0;
1650 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
1651 ddrawformat_from_wined3dformat(&DDSD
->u4
.ddpfPixelFormat
, mode
.format_id
);
1652 DDSD
->u1
.lPitch
= mode
.width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
1656 TRACE("Returning surface desc :\n");
1657 DDRAW_dump_surface_desc(DDSD
);
1660 wined3d_mutex_unlock();
1665 static HRESULT WINAPI
ddraw4_GetDisplayMode(IDirectDraw4
*iface
, DDSURFACEDESC2
*surface_desc
)
1667 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1669 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1671 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, surface_desc
);
1674 static HRESULT WINAPI
ddraw2_GetDisplayMode(IDirectDraw2
*iface
, DDSURFACEDESC
*surface_desc
)
1676 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1678 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1680 /* FIXME: Test sizes, properly convert surface_desc */
1681 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1684 static HRESULT WINAPI
ddraw1_GetDisplayMode(IDirectDraw
*iface
, DDSURFACEDESC
*surface_desc
)
1686 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1688 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1690 /* FIXME: Test sizes, properly convert surface_desc */
1691 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1694 /*****************************************************************************
1695 * IDirectDraw7::GetFourCCCodes
1697 * Returns an array of supported FourCC codes.
1699 * Exists in versions 1, 2, 4 and 7
1702 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
1703 * of enumerated codes
1704 * Codes: Pointer to an array of DWORDs where the supported codes are written
1708 * Always returns DD_OK, as it's a stub for now
1710 *****************************************************************************/
1711 static HRESULT WINAPI
ddraw7_GetFourCCCodes(IDirectDraw7
*iface
, DWORD
*NumCodes
, DWORD
*Codes
)
1713 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1714 static const enum wined3d_format_id formats
[] =
1716 WINED3DFMT_YUY2
, WINED3DFMT_UYVY
, WINED3DFMT_YV12
,
1717 WINED3DFMT_DXT1
, WINED3DFMT_DXT2
, WINED3DFMT_DXT3
, WINED3DFMT_DXT4
, WINED3DFMT_DXT5
,
1718 WINED3DFMT_ATI2N
, WINED3DFMT_NVHU
, WINED3DFMT_NVHS
1720 struct wined3d_display_mode mode
;
1721 DWORD count
= 0, i
, outsize
;
1724 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, NumCodes
, Codes
);
1726 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1728 ERR("Failed to get display mode, hr %#x.\n", hr
);
1732 outsize
= NumCodes
&& Codes
? *NumCodes
: 0;
1734 for (i
= 0; i
< (sizeof(formats
) / sizeof(formats
[0])); ++i
)
1736 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, WINED3D_DEVICE_TYPE_HAL
,
1737 mode
.format_id
, 0, WINED3D_RTYPE_TEXTURE_2D
, formats
[i
])))
1739 if (count
< outsize
)
1740 Codes
[count
] = formats
[i
];
1745 TRACE("Returning %u FourCC codes\n", count
);
1752 static HRESULT WINAPI
ddraw4_GetFourCCCodes(IDirectDraw4
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1754 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1756 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1758 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1761 static HRESULT WINAPI
ddraw2_GetFourCCCodes(IDirectDraw2
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1763 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1765 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1767 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1770 static HRESULT WINAPI
ddraw1_GetFourCCCodes(IDirectDraw
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1772 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1774 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1776 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1779 static HRESULT WINAPI
ddraw7_GetMonitorFrequency(IDirectDraw7
*iface
, DWORD
*frequency
)
1781 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1782 struct wined3d_display_mode mode
;
1785 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1787 wined3d_mutex_lock();
1788 hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
);
1789 wined3d_mutex_unlock();
1792 WARN("Failed to get display mode, hr %#x.\n", hr
);
1796 *frequency
= mode
.refresh_rate
;
1801 static HRESULT WINAPI
ddraw4_GetMonitorFrequency(IDirectDraw4
*iface
, DWORD
*frequency
)
1803 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1805 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1807 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1810 static HRESULT WINAPI
ddraw2_GetMonitorFrequency(IDirectDraw2
*iface
, DWORD
*frequency
)
1812 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1814 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1816 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1819 static HRESULT WINAPI
ddraw1_GetMonitorFrequency(IDirectDraw
*iface
, DWORD
*frequency
)
1821 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1823 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1825 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1828 static HRESULT WINAPI
ddraw7_GetVerticalBlankStatus(IDirectDraw7
*iface
, BOOL
*status
)
1830 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1831 struct wined3d_raster_status raster_status
;
1834 TRACE("iface %p, status %p.\n", iface
, status
);
1837 return DDERR_INVALIDPARAMS
;
1839 wined3d_mutex_lock();
1840 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
1841 wined3d_mutex_unlock();
1844 WARN("Failed to get raster status, hr %#x.\n", hr
);
1848 *status
= raster_status
.in_vblank
;
1853 static HRESULT WINAPI
ddraw4_GetVerticalBlankStatus(IDirectDraw4
*iface
, BOOL
*status
)
1855 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1857 TRACE("iface %p, status %p.\n", iface
, status
);
1859 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1862 static HRESULT WINAPI
ddraw2_GetVerticalBlankStatus(IDirectDraw2
*iface
, BOOL
*status
)
1864 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1866 TRACE("iface %p, status %p.\n", iface
, status
);
1868 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1871 static HRESULT WINAPI
ddraw1_GetVerticalBlankStatus(IDirectDraw
*iface
, BOOL
*status
)
1873 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1875 TRACE("iface %p, status %p.\n", iface
, status
);
1877 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1880 /*****************************************************************************
1881 * IDirectDraw7::GetAvailableVidMem
1883 * Returns the total and free video memory
1886 * Caps: Specifies the memory type asked for
1887 * total: Pointer to a DWORD to be filled with the total memory
1888 * free: Pointer to a DWORD to be filled with the free memory
1892 * DDERR_INVALIDPARAMS if free and total are NULL
1894 *****************************************************************************/
1895 static HRESULT WINAPI
ddraw7_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*Caps
, DWORD
*total
,
1898 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1901 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, Caps
, total
, free
);
1903 if (TRACE_ON(ddraw
))
1905 TRACE("Asked for memory with description: ");
1906 DDRAW_dump_DDSCAPS2(Caps
);
1908 wined3d_mutex_lock();
1910 /* Todo: System memory vs local video memory vs non-local video memory
1911 * The MSDN also mentions differences between texture memory and other
1912 * resources, but that's not important
1915 if( (!total
) && (!free
) )
1917 wined3d_mutex_unlock();
1918 return DDERR_INVALIDPARAMS
;
1922 *free
= wined3d_device_get_available_texture_mem(ddraw
->wined3d_device
);
1925 struct wined3d_adapter_identifier desc
= {0};
1927 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0, &desc
);
1928 *total
= min(UINT_MAX
, desc
.video_memory
);
1931 wined3d_mutex_unlock();
1936 static HRESULT WINAPI
ddraw4_GetAvailableVidMem(IDirectDraw4
*iface
,
1937 DDSCAPS2
*caps
, DWORD
*total
, DWORD
*free
)
1939 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1941 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1943 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, caps
, total
, free
);
1946 static HRESULT WINAPI
ddraw2_GetAvailableVidMem(IDirectDraw2
*iface
,
1947 DDSCAPS
*caps
, DWORD
*total
, DWORD
*free
)
1949 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1952 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1954 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
1955 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, &caps2
, total
, free
);
1958 /*****************************************************************************
1959 * IDirectDraw7::Initialize
1961 * Initializes a DirectDraw interface.
1964 * GUID: Interface identifier. Well, don't know what this is really good
1968 * Returns DD_OK on the first call,
1969 * DDERR_ALREADYINITIALIZED on repeated calls
1971 *****************************************************************************/
1972 static HRESULT WINAPI
ddraw7_Initialize(IDirectDraw7
*iface
, GUID
*guid
)
1974 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1976 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1978 if (ddraw
->flags
& DDRAW_INITIALIZED
)
1979 return DDERR_ALREADYINITIALIZED
;
1981 /* FIXME: To properly take the GUID into account we should call
1982 * ddraw_init() here instead of in DDRAW_Create(). */
1984 FIXME("Ignoring guid %s.\n", debugstr_guid(guid
));
1986 ddraw
->flags
|= DDRAW_INITIALIZED
;
1990 static HRESULT WINAPI
ddraw4_Initialize(IDirectDraw4
*iface
, GUID
*guid
)
1992 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1994 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1996 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
1999 static HRESULT WINAPI
ddraw2_Initialize(IDirectDraw2
*iface
, GUID
*guid
)
2001 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2003 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2005 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2008 static HRESULT WINAPI
ddraw1_Initialize(IDirectDraw
*iface
, GUID
*guid
)
2010 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2012 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2014 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2017 static HRESULT WINAPI
d3d1_Initialize(IDirect3D
*iface
, REFIID riid
)
2019 TRACE("iface %p, riid %s.\n", iface
, debugstr_guid(riid
));
2021 return DDERR_ALREADYINITIALIZED
;
2024 /*****************************************************************************
2025 * IDirectDraw7::FlipToGDISurface
2027 * "Makes the surface that the GDI writes to the primary surface"
2028 * Looks like some windows specific thing we don't have to care about.
2029 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
2030 * show error boxes ;)
2031 * Well, just return DD_OK.
2034 * Always returns DD_OK
2036 *****************************************************************************/
2037 static HRESULT WINAPI
ddraw7_FlipToGDISurface(IDirectDraw7
*iface
)
2039 FIXME("iface %p stub!\n", iface
);
2044 static HRESULT WINAPI
ddraw4_FlipToGDISurface(IDirectDraw4
*iface
)
2046 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2048 TRACE("iface %p.\n", iface
);
2050 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2053 static HRESULT WINAPI
ddraw2_FlipToGDISurface(IDirectDraw2
*iface
)
2055 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2057 TRACE("iface %p.\n", iface
);
2059 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2062 static HRESULT WINAPI
ddraw1_FlipToGDISurface(IDirectDraw
*iface
)
2064 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2066 TRACE("iface %p.\n", iface
);
2068 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2071 /*****************************************************************************
2072 * IDirectDraw7::WaitForVerticalBlank
2074 * This method allows applications to get in sync with the vertical blank
2076 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
2077 * redraw the screen, most likely because of this stub
2080 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
2081 * or DDWAITVB_BLOCKEND
2082 * h: Not used, according to MSDN
2085 * Always returns DD_OK
2087 *****************************************************************************/
2088 static HRESULT WINAPI
ddraw7_WaitForVerticalBlank(IDirectDraw7
*iface
, DWORD Flags
, HANDLE event
)
2092 TRACE("iface %p, flags %#x, event %p.\n", iface
, Flags
, event
);
2094 /* This function is called often, so print the fixme only once */
2097 FIXME("iface %p, flags %#x, event %p stub!\n", iface
, Flags
, event
);
2101 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
2102 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
2103 return DDERR_UNSUPPORTED
; /* unchecked */
2108 static HRESULT WINAPI
ddraw4_WaitForVerticalBlank(IDirectDraw4
*iface
, DWORD flags
, HANDLE event
)
2110 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2112 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2114 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2117 static HRESULT WINAPI
ddraw2_WaitForVerticalBlank(IDirectDraw2
*iface
, DWORD flags
, HANDLE event
)
2119 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2121 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2123 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2126 static HRESULT WINAPI
ddraw1_WaitForVerticalBlank(IDirectDraw
*iface
, DWORD flags
, HANDLE event
)
2128 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2130 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2132 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2135 static HRESULT WINAPI
ddraw7_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
2137 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2138 struct wined3d_raster_status raster_status
;
2141 TRACE("iface %p, line %p.\n", iface
, Scanline
);
2143 wined3d_mutex_lock();
2144 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
2145 wined3d_mutex_unlock();
2148 WARN("Failed to get raster status, hr %#x.\n", hr
);
2152 *Scanline
= raster_status
.scan_line
;
2154 if (raster_status
.in_vblank
)
2155 return DDERR_VERTICALBLANKINPROGRESS
;
2160 static HRESULT WINAPI
ddraw4_GetScanLine(IDirectDraw4
*iface
, DWORD
*line
)
2162 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2164 TRACE("iface %p, line %p.\n", iface
, line
);
2166 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2169 static HRESULT WINAPI
ddraw2_GetScanLine(IDirectDraw2
*iface
, DWORD
*line
)
2171 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2173 TRACE("iface %p, line %p.\n", iface
, line
);
2175 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2178 static HRESULT WINAPI
ddraw1_GetScanLine(IDirectDraw
*iface
, DWORD
*line
)
2180 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2182 TRACE("iface %p, line %p.\n", iface
, line
);
2184 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2187 static HRESULT WINAPI
ddraw7_TestCooperativeLevel(IDirectDraw7
*iface
)
2189 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2191 TRACE("iface %p.\n", iface
);
2193 return ddraw
->device_state
== DDRAW_DEVICE_STATE_LOST
? DDERR_NOEXCLUSIVEMODE
: DD_OK
;
2196 static HRESULT WINAPI
ddraw4_TestCooperativeLevel(IDirectDraw4
*iface
)
2198 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2200 TRACE("iface %p.\n", iface
);
2202 return ddraw7_TestCooperativeLevel(&ddraw
->IDirectDraw7_iface
);
2205 /*****************************************************************************
2206 * IDirectDraw7::GetGDISurface
2208 * Returns the surface that GDI is treating as the primary surface.
2209 * For Wine this is the front buffer
2212 * GDISurface: Address to write the surface pointer to
2215 * DD_OK if the surface was found
2216 * DDERR_NOTFOUND if the GDI surface wasn't found
2218 *****************************************************************************/
2219 static HRESULT WINAPI
ddraw7_GetGDISurface(IDirectDraw7
*iface
, IDirectDrawSurface7
**GDISurface
)
2221 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2223 TRACE("iface %p, surface %p.\n", iface
, GDISurface
);
2225 wined3d_mutex_lock();
2227 if (!(*GDISurface
= &ddraw
->primary
->IDirectDrawSurface7_iface
))
2229 WARN("Primary not created yet.\n");
2230 wined3d_mutex_unlock();
2231 return DDERR_NOTFOUND
;
2233 IDirectDrawSurface7_AddRef(*GDISurface
);
2235 wined3d_mutex_unlock();
2240 static HRESULT WINAPI
ddraw4_GetGDISurface(IDirectDraw4
*iface
, IDirectDrawSurface4
**surface
)
2242 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2243 struct ddraw_surface
*surface_impl
;
2244 IDirectDrawSurface7
*surface7
;
2247 TRACE("iface %p, surface %p.\n", iface
, surface
);
2249 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2255 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2256 *surface
= &surface_impl
->IDirectDrawSurface4_iface
;
2257 IDirectDrawSurface4_AddRef(*surface
);
2258 IDirectDrawSurface7_Release(surface7
);
2263 static HRESULT WINAPI
ddraw2_GetGDISurface(IDirectDraw2
*iface
, IDirectDrawSurface
**surface
)
2265 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2266 struct ddraw_surface
*surface_impl
;
2267 IDirectDrawSurface7
*surface7
;
2270 TRACE("iface %p, surface %p.\n", iface
, surface
);
2272 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2278 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2279 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2280 IDirectDrawSurface_AddRef(*surface
);
2281 IDirectDrawSurface7_Release(surface7
);
2286 static HRESULT WINAPI
ddraw1_GetGDISurface(IDirectDraw
*iface
, IDirectDrawSurface
**surface
)
2288 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2289 struct ddraw_surface
*surface_impl
;
2290 IDirectDrawSurface7
*surface7
;
2293 TRACE("iface %p, surface %p.\n", iface
, surface
);
2295 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2301 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2302 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2303 IDirectDrawSurface_AddRef(*surface
);
2304 IDirectDrawSurface7_Release(surface7
);
2309 struct displaymodescallback_context
2311 LPDDENUMMODESCALLBACK func
;
2315 static HRESULT CALLBACK
EnumDisplayModesCallbackThunk(DDSURFACEDESC2
*surface_desc
, void *context
)
2317 struct displaymodescallback_context
*cbcontext
= context
;
2320 DDSD2_to_DDSD(surface_desc
, &desc
);
2321 return cbcontext
->func(&desc
, cbcontext
->context
);
2324 /*****************************************************************************
2325 * IDirectDraw7::EnumDisplayModes
2327 * Enumerates the supported Display modes. The modes can be filtered with
2328 * the DDSD parameter.
2331 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES. For old ddraw
2332 * versions (3 and older?) this is reserved and must be 0.
2333 * DDSD: Surface description to filter the modes
2334 * Context: Pointer passed back to the callback function
2335 * cb: Application-provided callback function
2339 * DDERR_INVALIDPARAMS if the callback wasn't set
2341 *****************************************************************************/
2342 static HRESULT WINAPI
ddraw7_EnumDisplayModes(IDirectDraw7
*iface
, DWORD Flags
,
2343 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMMODESCALLBACK2 cb
)
2345 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2346 struct wined3d_display_mode
*enum_modes
= NULL
;
2347 struct wined3d_display_mode mode
;
2348 unsigned int modenum
, fmt
;
2349 DDSURFACEDESC2 callback_sd
;
2350 unsigned enum_mode_count
= 0, enum_mode_array_size
= 16;
2351 DDPIXELFORMAT pixelformat
;
2353 static const enum wined3d_format_id checkFormatList
[] =
2355 WINED3DFMT_B8G8R8X8_UNORM
,
2356 WINED3DFMT_B5G6R5_UNORM
,
2360 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2361 iface
, Flags
, DDSD
, Context
, cb
);
2364 return DDERR_INVALIDPARAMS
;
2366 enum_modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(*enum_modes
) * enum_mode_array_size
);
2367 if (!enum_modes
) return DDERR_OUTOFMEMORY
;
2369 wined3d_mutex_lock();
2371 pixelformat
.dwSize
= sizeof(pixelformat
);
2372 for(fmt
= 0; fmt
< (sizeof(checkFormatList
) / sizeof(checkFormatList
[0])); fmt
++)
2375 while (wined3d_enum_adapter_modes(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, checkFormatList
[fmt
],
2376 WINED3D_SCANLINE_ORDERING_UNKNOWN
, modenum
++, &mode
) == WINED3D_OK
)
2381 ddrawformat_from_wined3dformat(&pixelformat
, mode
.format_id
);
2384 if (DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.width
!= DDSD
->dwWidth
)
2386 if (DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.height
!= DDSD
->dwHeight
)
2388 if (DDSD
->dwFlags
& DDSD_REFRESHRATE
&& mode
.refresh_rate
!= DDSD
->u2
.dwRefreshRate
)
2390 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
2391 && pixelformat
.u1
.dwRGBBitCount
!= DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
)
2395 /* DX docs state EnumDisplayMode should return only unique modes */
2396 for (i
= 0; i
< enum_mode_count
; i
++)
2398 if (enum_modes
[i
].width
== mode
.width
&& enum_modes
[i
].height
== mode
.height
2399 && enum_modes
[i
].format_id
== mode
.format_id
2400 && (enum_modes
[i
].refresh_rate
== mode
.refresh_rate
|| !(Flags
& DDEDM_REFRESHRATES
)))
2408 memset(&callback_sd
, 0, sizeof(callback_sd
));
2409 callback_sd
.dwSize
= sizeof(callback_sd
);
2410 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2412 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
|DDSD_REFRESHRATE
;
2413 if (Flags
& DDEDM_REFRESHRATES
)
2414 callback_sd
.u2
.dwRefreshRate
= mode
.refresh_rate
;
2416 callback_sd
.dwWidth
= mode
.width
;
2417 callback_sd
.dwHeight
= mode
.height
;
2419 callback_sd
.u4
.ddpfPixelFormat
=pixelformat
;
2421 /* Calc pitch and DWORD align like MSDN says */
2422 callback_sd
.u1
.lPitch
= (callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8) * mode
.width
;
2423 callback_sd
.u1
.lPitch
= (callback_sd
.u1
.lPitch
+ 3) & ~3;
2425 TRACE("Enumerating %dx%dx%d @%d\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
,
2426 callback_sd
.u2
.dwRefreshRate
);
2428 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
2430 TRACE("Application asked to terminate the enumeration\n");
2431 HeapFree(GetProcessHeap(), 0, enum_modes
);
2432 wined3d_mutex_unlock();
2436 if (enum_mode_count
== enum_mode_array_size
)
2438 struct wined3d_display_mode
*new_enum_modes
;
2440 enum_mode_array_size
*= 2;
2441 new_enum_modes
= HeapReAlloc(GetProcessHeap(), 0, enum_modes
,
2442 sizeof(*new_enum_modes
) * enum_mode_array_size
);
2443 if (!new_enum_modes
)
2445 HeapFree(GetProcessHeap(), 0, enum_modes
);
2446 wined3d_mutex_unlock();
2447 return DDERR_OUTOFMEMORY
;
2450 enum_modes
= new_enum_modes
;
2452 enum_modes
[enum_mode_count
++] = mode
;
2456 TRACE("End of enumeration\n");
2457 HeapFree(GetProcessHeap(), 0, enum_modes
);
2458 wined3d_mutex_unlock();
2463 static HRESULT WINAPI
ddraw4_EnumDisplayModes(IDirectDraw4
*iface
, DWORD flags
,
2464 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK2 callback
)
2466 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2468 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2469 iface
, flags
, surface_desc
, context
, callback
);
2471 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
, context
, callback
);
2474 static HRESULT WINAPI
ddraw2_EnumDisplayModes(IDirectDraw2
*iface
, DWORD flags
,
2475 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2477 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2478 struct displaymodescallback_context cbcontext
;
2479 DDSURFACEDESC2 surface_desc2
;
2481 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2482 iface
, flags
, surface_desc
, context
, callback
);
2484 cbcontext
.func
= callback
;
2485 cbcontext
.context
= context
;
2487 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2488 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2489 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2492 static HRESULT WINAPI
ddraw1_EnumDisplayModes(IDirectDraw
*iface
, DWORD flags
,
2493 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2495 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2496 struct displaymodescallback_context cbcontext
;
2497 DDSURFACEDESC2 surface_desc2
;
2499 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2500 iface
, flags
, surface_desc
, context
, callback
);
2502 cbcontext
.func
= callback
;
2503 cbcontext
.context
= context
;
2505 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2506 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2507 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2510 /*****************************************************************************
2511 * IDirectDraw7::EvaluateMode
2513 * Used with IDirectDraw7::StartModeTest to test video modes.
2514 * EvaluateMode is used to pass or fail a mode, and continue with the next
2518 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
2519 * Timeout: Returns the amount of seconds left before the mode would have
2520 * been failed automatically
2523 * This implementation always DD_OK, because it's a stub
2525 *****************************************************************************/
2526 static HRESULT WINAPI
ddraw7_EvaluateMode(IDirectDraw7
*iface
, DWORD Flags
, DWORD
*Timeout
)
2528 FIXME("iface %p, flags %#x, timeout %p stub!\n", iface
, Flags
, Timeout
);
2530 /* When implementing this, implement it in WineD3D */
2535 /*****************************************************************************
2536 * IDirectDraw7::GetDeviceIdentifier
2538 * Returns the device identifier, which gives information about the driver
2539 * Our device identifier is defined at the beginning of this file.
2542 * DDDI: Address for the returned structure
2543 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
2546 * On success it returns DD_OK
2547 * DDERR_INVALIDPARAMS if DDDI is NULL
2549 *****************************************************************************/
2550 static HRESULT WINAPI
ddraw7_GetDeviceIdentifier(IDirectDraw7
*iface
,
2551 DDDEVICEIDENTIFIER2
*DDDI
, DWORD Flags
)
2553 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2554 struct wined3d_adapter_identifier adapter_id
;
2557 TRACE("iface %p, device_identifier %p, flags %#x.\n", iface
, DDDI
, Flags
);
2560 return DDERR_INVALIDPARAMS
;
2562 if (Flags
& DDGDI_GETHOSTIDENTIFIER
)
2564 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
2565 * host adapter, if there's a secondary 3D adapter. This doesn't apply
2566 * to any modern hardware, nor is it interesting for Wine, so ignore it.
2567 * Size of DDDEVICEIDENTIFIER2 may be aligned to 8 bytes and thus 4
2568 * bytes too long. So only copy the relevant part of the structure
2571 memcpy(DDDI
, &deviceidentifier
, FIELD_OFFSET(DDDEVICEIDENTIFIER2
, dwWHQLLevel
) + sizeof(DWORD
));
2575 /* Drakan: Order of the Flame expects accurate D3D device information from ddraw */
2576 adapter_id
.driver
= DDDI
->szDriver
;
2577 adapter_id
.driver_size
= sizeof(DDDI
->szDriver
);
2578 adapter_id
.description
= DDDI
->szDescription
;
2579 adapter_id
.description_size
= sizeof(DDDI
->szDescription
);
2580 adapter_id
.device_name_size
= 0;
2581 wined3d_mutex_lock();
2582 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0x0, &adapter_id
);
2583 wined3d_mutex_unlock();
2584 if (FAILED(hr
)) return hr
;
2586 DDDI
->liDriverVersion
= adapter_id
.driver_version
;
2587 DDDI
->dwVendorId
= adapter_id
.vendor_id
;
2588 DDDI
->dwDeviceId
= adapter_id
.device_id
;
2589 DDDI
->dwSubSysId
= adapter_id
.subsystem_id
;
2590 DDDI
->dwRevision
= adapter_id
.revision
;
2591 DDDI
->guidDeviceIdentifier
= adapter_id
.device_identifier
;
2592 DDDI
->dwWHQLLevel
= adapter_id
.whql_level
;
2596 static HRESULT WINAPI
ddraw4_GetDeviceIdentifier(IDirectDraw4
*iface
,
2597 DDDEVICEIDENTIFIER
*identifier
, DWORD flags
)
2599 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2600 DDDEVICEIDENTIFIER2 identifier2
;
2603 TRACE("iface %p, identifier %p, flags %#x.\n", iface
, identifier
, flags
);
2605 hr
= ddraw7_GetDeviceIdentifier(&ddraw
->IDirectDraw7_iface
, &identifier2
, flags
);
2606 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&identifier2
, identifier
);
2611 /*****************************************************************************
2612 * IDirectDraw7::GetSurfaceFromDC
2614 * Returns the Surface for a GDI device context handle.
2615 * Is this related to IDirectDrawSurface::GetDC ???
2618 * hdc: hdc to return the surface for
2619 * Surface: Address to write the surface pointer to
2622 * Always returns DD_OK because it's a stub
2624 *****************************************************************************/
2625 static HRESULT WINAPI
ddraw7_GetSurfaceFromDC(IDirectDraw7
*iface
,
2626 HDC dc
, IDirectDrawSurface7
**surface
)
2628 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2629 struct ddraw_surface
*surface_impl
;
2631 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2634 return E_INVALIDARG
;
2639 wined3d_mutex_lock();
2640 LIST_FOR_EACH_ENTRY(surface_impl
, &ddraw
->surface_list
, struct ddraw_surface
, surface_list_entry
)
2642 if (surface_impl
->dc
!= dc
)
2645 TRACE("Found surface %p for dc %p.\n", surface_impl
, dc
);
2646 *surface
= &surface_impl
->IDirectDrawSurface7_iface
;
2647 IDirectDrawSurface7_AddRef(*surface
);
2648 wined3d_mutex_unlock();
2651 wined3d_mutex_unlock();
2654 TRACE("No surface found for dc %p.\n", dc
);
2656 return DDERR_NOTFOUND
;
2659 static HRESULT WINAPI
ddraw4_GetSurfaceFromDC(IDirectDraw4
*iface
, HDC dc
,
2660 IDirectDrawSurface4
**surface
)
2662 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2663 struct ddraw_surface
*surface_impl
;
2664 IDirectDrawSurface7
*surface7
;
2667 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2669 if (!surface
) return E_INVALIDARG
;
2671 hr
= ddraw7_GetSurfaceFromDC(&ddraw
->IDirectDraw7_iface
, dc
, &surface7
);
2677 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2678 /* Tests say this is true */
2679 *surface
= (IDirectDrawSurface4
*)&surface_impl
->IDirectDrawSurface_iface
;
2680 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2681 IDirectDrawSurface7_Release(surface7
);
2686 static HRESULT CALLBACK
restore_callback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
2688 IDirectDrawSurface_Restore(surface
);
2689 IDirectDrawSurface_Release(surface
);
2691 return DDENUMRET_OK
;
2694 static HRESULT WINAPI
ddraw7_RestoreAllSurfaces(IDirectDraw7
*iface
)
2696 TRACE("iface %p.\n", iface
);
2698 return IDirectDraw7_EnumSurfaces(iface
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
2699 NULL
, NULL
, restore_callback
);
2702 static HRESULT WINAPI
ddraw4_RestoreAllSurfaces(IDirectDraw4
*iface
)
2704 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2706 TRACE("iface %p.\n", iface
);
2708 return ddraw7_RestoreAllSurfaces(&ddraw
->IDirectDraw7_iface
);
2711 /*****************************************************************************
2712 * IDirectDraw7::StartModeTest
2714 * Tests the specified video modes to update the system registry with
2715 * refresh rate information. StartModeTest starts the mode test,
2716 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
2717 * isn't called within 15 seconds, the mode is failed automatically
2719 * As refresh rates are handled by the X server, I don't think this
2720 * Method is important
2723 * Modes: An array of mode specifications
2724 * NumModes: The number of modes in Modes
2725 * Flags: Some flags...
2728 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
2729 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
2732 *****************************************************************************/
2733 static HRESULT WINAPI
ddraw7_StartModeTest(IDirectDraw7
*iface
, SIZE
*Modes
, DWORD NumModes
, DWORD Flags
)
2735 FIXME("iface %p, modes %p, mode_count %u, flags %#x partial stub!\n",
2736 iface
, Modes
, NumModes
, Flags
);
2738 /* This looks sane */
2739 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
2741 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
2742 * As it is not, DDERR_TESTFINISHED is returned
2743 * (hopefully that's correct
2745 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
2746 * well, that value doesn't (yet) exist in the wine headers, so ignore it
2752 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
, DDSURFACEDESC2
*surface_desc
,
2753 IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
2755 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2756 struct ddraw_surface
*impl
;
2759 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2760 iface
, surface_desc
, surface
, outer_unknown
);
2762 wined3d_mutex_lock();
2764 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2766 WARN("Cooperative level not set.\n");
2767 wined3d_mutex_unlock();
2768 return DDERR_NOCOOPERATIVELEVELSET
;
2771 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2773 WARN("Application supplied invalid surface descriptor\n");
2774 wined3d_mutex_unlock();
2775 return DDERR_INVALIDPARAMS
;
2778 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2780 if (TRACE_ON(ddraw
))
2782 TRACE(" (%p) Requesting surface desc :\n", iface
);
2783 DDRAW_dump_surface_desc(surface_desc
);
2786 WARN("Application tried to create an explicit front or back buffer\n");
2787 wined3d_mutex_unlock();
2788 return DDERR_INVALIDCAPS
;
2791 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 7);
2792 wined3d_mutex_unlock();
2799 *surface
= &impl
->IDirectDrawSurface7_iface
;
2800 IDirectDraw7_AddRef(iface
);
2801 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2806 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
2807 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
2809 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2810 struct ddraw_surface
*impl
;
2813 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2814 iface
, surface_desc
, surface
, outer_unknown
);
2816 wined3d_mutex_lock();
2818 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2820 WARN("Cooperative level not set.\n");
2821 wined3d_mutex_unlock();
2822 return DDERR_NOCOOPERATIVELEVELSET
;
2825 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2827 WARN("Application supplied invalid surface descriptor\n");
2828 wined3d_mutex_unlock();
2829 return DDERR_INVALIDPARAMS
;
2832 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2834 if (TRACE_ON(ddraw
))
2836 TRACE(" (%p) Requesting surface desc :\n", iface
);
2837 DDRAW_dump_surface_desc(surface_desc
);
2840 WARN("Application tried to create an explicit front or back buffer\n");
2841 wined3d_mutex_unlock();
2842 return DDERR_INVALIDCAPS
;
2845 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 4);
2846 wined3d_mutex_unlock();
2853 *surface
= &impl
->IDirectDrawSurface4_iface
;
2854 IDirectDraw4_AddRef(iface
);
2855 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2860 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
2861 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2863 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2864 struct ddraw_surface
*impl
;
2866 DDSURFACEDESC2 surface_desc2
;
2868 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2869 iface
, surface_desc
, surface
, outer_unknown
);
2871 wined3d_mutex_lock();
2873 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2875 WARN("Cooperative level not set.\n");
2876 wined3d_mutex_unlock();
2877 return DDERR_NOCOOPERATIVELEVELSET
;
2880 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2882 WARN("Application supplied invalid surface descriptor\n");
2883 wined3d_mutex_unlock();
2884 return DDERR_INVALIDPARAMS
;
2887 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2888 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2890 if (TRACE_ON(ddraw
))
2892 TRACE(" (%p) Requesting surface desc :\n", iface
);
2893 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
2896 WARN("Application tried to create an explicit front or back buffer\n");
2897 wined3d_mutex_unlock();
2898 return DDERR_INVALIDCAPS
;
2901 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 2);
2902 wined3d_mutex_unlock();
2909 *surface
= &impl
->IDirectDrawSurface_iface
;
2910 impl
->ifaceToRelease
= NULL
;
2915 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
2916 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2918 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2919 struct ddraw_surface
*impl
;
2921 DDSURFACEDESC2 surface_desc2
;
2923 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2924 iface
, surface_desc
, surface
, outer_unknown
);
2926 wined3d_mutex_lock();
2928 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2930 WARN("Cooperative level not set.\n");
2931 wined3d_mutex_unlock();
2932 return DDERR_NOCOOPERATIVELEVELSET
;
2935 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2937 WARN("Application supplied invalid surface descriptor\n");
2938 wined3d_mutex_unlock();
2939 return DDERR_INVALIDPARAMS
;
2942 if ((surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
))
2943 == (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
)
2944 || (surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
))
2945 == ((DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
)))
2947 WARN("Application tried to create an explicit front or back buffer.\n");
2948 wined3d_mutex_unlock();
2949 return DDERR_INVALIDCAPS
;
2952 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2953 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 1);
2954 wined3d_mutex_unlock();
2961 *surface
= &impl
->IDirectDrawSurface_iface
;
2962 impl
->ifaceToRelease
= NULL
;
2968 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
2969 const DDPIXELFORMAT
*provided
)
2971 /* Some flags must be present in both or neither for a match. */
2972 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
2973 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
2974 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
2976 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
2979 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
2982 if (requested
->dwFlags
& DDPF_FOURCC
)
2983 if (requested
->dwFourCC
!= provided
->dwFourCC
)
2986 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
2987 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
2988 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
2991 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
2992 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
2993 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
2996 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
2997 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
3000 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
3001 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3003 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
3006 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
3007 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
3013 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3022 #define CMP(FLAG, FIELD) \
3023 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3024 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3026 static const struct compare_info compare
[] =
3028 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3029 CMP(BACKBUFFERCOUNT
, u5
.dwBackBufferCount
),
3031 CMP(CKDESTBLT
, ddckCKDestBlt
),
3032 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3033 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3034 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3035 CMP(HEIGHT
, dwHeight
),
3036 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3037 CMP(LPSURFACE
, lpSurface
),
3038 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3039 CMP(PITCH
, u1
/* lPitch */),
3040 /* PIXELFORMAT: manual */
3041 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3042 CMP(TEXTURESTAGE
, dwTextureStage
),
3043 CMP(WIDTH
, dwWidth
),
3044 /* ZBUFFERBITDEPTH: "obsolete" */
3051 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3054 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
3056 if (requested
->dwFlags
& compare
[i
].flag
3057 && memcmp((const char *)provided
+ compare
[i
].offset
,
3058 (const char *)requested
+ compare
[i
].offset
,
3059 compare
[i
].size
) != 0)
3063 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3065 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3066 &provided
->u4
.ddpfPixelFormat
))
3073 struct surfacescallback2_context
3075 LPDDENUMSURFACESCALLBACK2 func
;
3079 struct surfacescallback_context
3081 LPDDENUMSURFACESCALLBACK func
;
3085 static HRESULT CALLBACK
EnumSurfacesCallback2Thunk(IDirectDrawSurface7
*surface
,
3086 DDSURFACEDESC2
*surface_desc
, void *context
)
3088 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3089 struct surfacescallback2_context
*cbcontext
= context
;
3091 IDirectDrawSurface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
3092 IDirectDrawSurface7_Release(surface
);
3094 return cbcontext
->func(&surface_impl
->IDirectDrawSurface4_iface
,
3095 surface_desc
, cbcontext
->context
);
3098 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3099 DDSURFACEDESC2
*surface_desc
, void *context
)
3101 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3102 struct surfacescallback_context
*cbcontext
= context
;
3104 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
3105 IDirectDrawSurface7_Release(surface
);
3107 return cbcontext
->func(&surface_impl
->IDirectDrawSurface_iface
,
3108 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3111 /*****************************************************************************
3112 * IDirectDraw7::EnumSurfaces
3114 * Loops through all surfaces attached to this device and calls the
3115 * application callback. This can't be relayed to WineD3DDevice,
3116 * because some WineD3DSurfaces' parents are IParent objects
3119 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3120 * DDSD: Description to filter for
3121 * Context: Application-provided pointer, it's passed unmodified to the
3123 * Callback: Address to call for each surface
3126 * DDERR_INVALIDPARAMS if the callback is NULL
3129 *****************************************************************************/
3130 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD Flags
,
3131 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMSURFACESCALLBACK7 Callback
)
3133 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3134 struct ddraw_surface
*surf
;
3136 DDSURFACEDESC2 desc
;
3137 struct list
*entry
, *entry2
;
3139 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3140 iface
, Flags
, DDSD
, Context
, Callback
);
3142 all
= Flags
& DDENUMSURFACES_ALL
;
3143 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
3146 return DDERR_INVALIDPARAMS
;
3148 wined3d_mutex_lock();
3150 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
3151 LIST_FOR_EACH_SAFE(entry
, entry2
, &ddraw
->surface_list
)
3153 surf
= LIST_ENTRY(entry
, struct ddraw_surface
, surface_list_entry
);
3155 if (!surf
->iface_count
)
3157 WARN("Not enumerating surface %p because it doesn't have any references.\n", surf
);
3161 if (all
|| (nomatch
!= ddraw_match_surface_desc(DDSD
, &surf
->surface_desc
)))
3163 TRACE("Enumerating surface %p.\n", surf
);
3164 desc
= surf
->surface_desc
;
3165 IDirectDrawSurface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
3166 if (Callback(&surf
->IDirectDrawSurface7_iface
, &desc
, Context
) != DDENUMRET_OK
)
3168 wined3d_mutex_unlock();
3174 wined3d_mutex_unlock();
3179 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3180 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3182 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3183 struct surfacescallback2_context cbcontext
;
3185 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3186 iface
, flags
, surface_desc
, context
, callback
);
3188 cbcontext
.func
= callback
;
3189 cbcontext
.context
= context
;
3191 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
,
3192 &cbcontext
, EnumSurfacesCallback2Thunk
);
3195 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3196 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3198 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3199 struct surfacescallback_context cbcontext
;
3200 DDSURFACEDESC2 surface_desc2
;
3202 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3203 iface
, flags
, surface_desc
, context
, callback
);
3205 cbcontext
.func
= callback
;
3206 cbcontext
.context
= context
;
3208 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3209 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3210 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3213 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3214 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3216 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3217 struct surfacescallback_context cbcontext
;
3218 DDSURFACEDESC2 surface_desc2
;
3220 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3221 iface
, flags
, surface_desc
, context
, callback
);
3223 cbcontext
.func
= callback
;
3224 cbcontext
.context
= context
;
3226 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3227 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3228 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3231 /*****************************************************************************
3232 * DirectDrawCreateClipper (DDRAW.@)
3234 * Creates a new IDirectDrawClipper object.
3237 * Clipper: Address to write the interface pointer to
3238 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3242 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3243 * E_OUTOFMEMORY if allocating the object failed
3245 *****************************************************************************/
3246 HRESULT WINAPI
DirectDrawCreateClipper(DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3248 struct ddraw_clipper
*object
;
3251 TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
3252 flags
, clipper
, outer_unknown
);
3255 return CLASS_E_NOAGGREGATION
;
3257 wined3d_mutex_lock();
3259 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3262 wined3d_mutex_unlock();
3263 return E_OUTOFMEMORY
;
3266 hr
= ddraw_clipper_init(object
);
3269 WARN("Failed to initialize clipper, hr %#x.\n", hr
);
3270 HeapFree(GetProcessHeap(), 0, object
);
3271 wined3d_mutex_unlock();
3275 TRACE("Created clipper %p.\n", object
);
3276 *clipper
= &object
->IDirectDrawClipper_iface
;
3277 wined3d_mutex_unlock();
3282 /*****************************************************************************
3283 * IDirectDraw7::CreateClipper
3285 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3287 *****************************************************************************/
3288 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3289 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3291 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3292 iface
, Flags
, Clipper
, UnkOuter
);
3294 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3297 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
, DWORD flags
,
3298 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3300 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3302 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3303 iface
, flags
, clipper
, outer_unknown
);
3305 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3308 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
3309 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3311 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3313 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3314 iface
, flags
, clipper
, outer_unknown
);
3316 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3319 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
3320 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3322 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3324 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3325 iface
, flags
, clipper
, outer_unknown
);
3327 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3330 /*****************************************************************************
3331 * IDirectDraw7::CreatePalette
3333 * Creates a new IDirectDrawPalette object
3336 * Flags: The flags for the new clipper
3337 * ColorTable: Color table to assign to the new clipper
3338 * Palette: Address to write the interface pointer to
3339 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3343 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3344 * E_OUTOFMEMORY if allocating the object failed
3346 *****************************************************************************/
3347 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
3348 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
3350 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3351 struct ddraw_palette
*object
;
3354 TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
3355 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3358 return CLASS_E_NOAGGREGATION
;
3360 wined3d_mutex_lock();
3362 /* The refcount test shows that a cooplevel is required for this */
3363 if (!ddraw
->cooperative_level
)
3365 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3366 wined3d_mutex_unlock();
3367 return DDERR_NOCOOPERATIVELEVELSET
;
3370 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(*object
));
3373 ERR("Out of memory when allocating memory for a palette implementation\n");
3374 wined3d_mutex_unlock();
3375 return E_OUTOFMEMORY
;
3378 hr
= ddraw_palette_init(object
, ddraw
, Flags
, ColorTable
);
3381 WARN("Failed to initialize palette, hr %#x.\n", hr
);
3382 HeapFree(GetProcessHeap(), 0, object
);
3383 wined3d_mutex_unlock();
3387 TRACE("Created palette %p.\n", object
);
3388 *Palette
= &object
->IDirectDrawPalette_iface
;
3389 wined3d_mutex_unlock();
3394 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
, PALETTEENTRY
*entries
,
3395 IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3397 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3400 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3401 iface
, flags
, entries
, palette
, outer_unknown
);
3403 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3404 if (SUCCEEDED(hr
) && *palette
)
3406 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3407 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3408 IDirectDraw4_AddRef(iface
);
3409 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3414 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
3415 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3417 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3420 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3421 iface
, flags
, entries
, palette
, outer_unknown
);
3423 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3424 if (SUCCEEDED(hr
) && *palette
)
3426 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3427 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3428 impl
->ifaceToRelease
= NULL
;
3434 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
3435 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3437 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3440 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3441 iface
, flags
, entries
, palette
, outer_unknown
);
3443 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3444 if (SUCCEEDED(hr
) && *palette
)
3446 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3447 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3448 impl
->ifaceToRelease
= NULL
;
3454 /*****************************************************************************
3455 * IDirectDraw7::DuplicateSurface
3457 * Duplicates a surface. The surface memory points to the same memory as
3458 * the original surface, and it's released when the last surface referencing
3459 * it is released. I guess that's beyond Wine's surface management right now
3460 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3461 * test application to implement this)
3464 * Src: Address of the source surface
3465 * Dest: Address to write the new surface pointer to
3468 * See IDirectDraw7::CreateSurface
3470 *****************************************************************************/
3471 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
3472 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
3474 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(Src
);
3476 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
3478 /* For now, simply create a new, independent surface */
3479 return IDirectDraw7_CreateSurface(iface
, &src_surface
->surface_desc
, Dest
, NULL
);
3482 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
, IDirectDrawSurface4
*src
,
3483 IDirectDrawSurface4
**dst
)
3485 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
3486 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3487 struct ddraw_surface
*dst_impl
;
3488 IDirectDrawSurface7
*dst7
;
3491 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3493 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3494 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3500 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3501 *dst
= &dst_impl
->IDirectDrawSurface4_iface
;
3502 IDirectDrawSurface4_AddRef(*dst
);
3503 IDirectDrawSurface7_Release(dst7
);
3508 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
3509 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
3511 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3512 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3513 struct ddraw_surface
*dst_impl
;
3514 IDirectDrawSurface7
*dst7
;
3517 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3519 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3520 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3523 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3524 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3525 IDirectDrawSurface_AddRef(*dst
);
3526 IDirectDrawSurface7_Release(dst7
);
3531 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
, IDirectDrawSurface
*src
,
3532 IDirectDrawSurface
**dst
)
3534 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3535 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3536 struct ddraw_surface
*dst_impl
;
3537 IDirectDrawSurface7
*dst7
;
3540 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3542 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3543 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3546 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3547 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3548 IDirectDrawSurface_AddRef(*dst
);
3549 IDirectDrawSurface7_Release(dst7
);
3554 /*****************************************************************************
3555 * IDirect3D7::EnumDevices
3557 * The EnumDevices method for IDirect3D7. It enumerates all supported
3558 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
3561 * callback: Function to call for each enumerated device
3562 * context: Pointer to pass back to the app
3565 * D3D_OK, or the return value of the GetCaps call
3567 *****************************************************************************/
3568 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
3570 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
3571 D3DDEVICEDESC7 device_desc7
;
3575 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3578 return DDERR_INVALIDPARAMS
;
3580 wined3d_mutex_lock();
3582 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3584 wined3d_mutex_unlock();
3588 for (i
= 0; i
< sizeof(device_list7
)/sizeof(device_list7
[0]); i
++)
3592 device_desc7
.deviceGUID
= *device_list7
[i
].device_guid
;
3593 ret
= callback(device_list7
[i
].interface_name
, device_list7
[i
].device_name
, &device_desc7
, context
);
3594 if (ret
!= DDENUMRET_OK
)
3596 TRACE("Application cancelled the enumeration.\n");
3597 wined3d_mutex_unlock();
3602 TRACE("End of enumeration.\n");
3604 wined3d_mutex_unlock();
3609 /*****************************************************************************
3610 * IDirect3D3::EnumDevices
3612 * Enumerates all supported Direct3DDevice interfaces. This is the
3613 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
3615 * Versions 1, 2 and 3
3618 * callback: Application-provided routine to call for each enumerated device
3619 * Context: Pointer to pass to the callback
3622 * D3D_OK on success,
3623 * The result of IDirect3DImpl_GetCaps if it failed
3625 *****************************************************************************/
3626 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3628 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
3630 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3631 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
3632 D3DDEVICEDESC7 device_desc7
;
3635 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
3636 * name string. Let's put the string in a sufficiently sized array in
3637 * writable memory. */
3638 char device_name
[50];
3639 strcpy(device_name
,"Direct3D HEL");
3641 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3644 return DDERR_INVALIDPARAMS
;
3646 wined3d_mutex_lock();
3648 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3650 wined3d_mutex_unlock();
3653 ddraw_d3dcaps1_from_7(&device_desc1
, &device_desc7
);
3655 /* Do I have to enumerate the reference id? Note from old d3d7:
3656 * "It seems that enumerating the reference IID on Direct3D 1 games
3657 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
3659 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
3660 * EnumReference which enables / disables enumerating the reference
3661 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
3662 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
3663 * demo directory suggest this.
3665 * Some games(GTA 2) seem to use the second enumerated device, so I have
3666 * to enumerate at least 2 devices. So enumerate the reference device to
3669 * Other games (Rollcage) tell emulation and hal device apart by certain
3670 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
3671 * limitation flag), and it refuses all devices that have the perspective
3672 * flag set. This way it refuses the emulation device, and HAL devices
3673 * never have POW2 unset in d3d7 on windows. */
3674 if (ddraw
->d3dversion
!= 1)
3676 static CHAR reference_description
[] = "RGB Direct3D emulation";
3678 TRACE("Enumerating WineD3D D3DDevice interface.\n");
3679 hal_desc
= device_desc1
;
3680 hel_desc
= device_desc1
;
3681 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
3682 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3683 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3684 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3685 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3686 /* RGB, RAMP and MMX devices have a HAL dcmColorModel of 0 */
3687 hal_desc
.dcmColorModel
= 0;
3688 /* RGB, RAMP and MMX devices cannot report HAL hardware flags */
3689 hal_desc
.dwFlags
= 0;
3691 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
3692 device_name
, &hal_desc
, &hel_desc
, context
);
3693 if (hr
!= D3DENUMRET_OK
)
3695 TRACE("Application cancelled the enumeration.\n");
3696 wined3d_mutex_unlock();
3701 strcpy(device_name
,"Direct3D HAL");
3703 TRACE("Enumerating HAL Direct3D device.\n");
3704 hal_desc
= device_desc1
;
3705 hel_desc
= device_desc1
;
3707 /* The hal device does not have the pow2 flag set in hel, but in hal. */
3708 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3709 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3710 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3711 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3712 /* HAL devices have a HEL dcmColorModel of 0 */
3713 hel_desc
.dcmColorModel
= 0;
3715 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
3716 device_name
, &hal_desc
, &hel_desc
, context
);
3717 if (hr
!= D3DENUMRET_OK
)
3719 TRACE("Application cancelled the enumeration.\n");
3720 wined3d_mutex_unlock();
3724 TRACE("End of enumeration.\n");
3726 wined3d_mutex_unlock();
3731 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3733 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3735 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3737 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3740 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3742 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3744 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3746 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3749 /*****************************************************************************
3750 * IDirect3D3::CreateLight
3752 * Creates an IDirect3DLight interface. This interface is used in
3753 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
3754 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
3755 * uses the IDirect3DDevice7 interface with D3D7 lights.
3757 * Versions 1, 2 and 3
3760 * light: Address to store the new interface pointer
3761 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3766 * DDERR_OUTOFMEMORY if memory allocation failed
3767 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3769 *****************************************************************************/
3770 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
,
3771 IUnknown
*outer_unknown
)
3773 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3774 struct d3d_light
*object
;
3776 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3778 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3780 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3783 ERR("Failed to allocate light memory.\n");
3784 return DDERR_OUTOFMEMORY
;
3787 d3d_light_init(object
, ddraw
);
3789 TRACE("Created light %p.\n", object
);
3790 *light
= &object
->IDirect3DLight_iface
;
3795 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3797 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3799 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3801 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3804 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3806 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3808 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3810 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3813 /*****************************************************************************
3814 * IDirect3D3::CreateMaterial
3816 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
3817 * and older versions. The IDirect3DMaterial implementation wraps its
3818 * functionality to IDirect3DDevice7::SetMaterial and friends.
3820 * Versions 1, 2 and 3
3823 * material: Address to store the new interface's pointer to
3824 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3829 * DDERR_OUTOFMEMORY if memory allocation failed
3830 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3832 *****************************************************************************/
3833 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
,
3834 IUnknown
*outer_unknown
)
3836 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3837 struct d3d_material
*object
;
3839 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3841 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3843 object
= d3d_material_create(ddraw
);
3846 ERR("Failed to allocate material memory.\n");
3847 return DDERR_OUTOFMEMORY
;
3850 TRACE("Created material %p.\n", object
);
3851 *material
= &object
->IDirect3DMaterial3_iface
;
3856 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
,
3857 IUnknown
*outer_unknown
)
3859 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3860 struct d3d_material
*object
;
3862 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3864 object
= d3d_material_create(ddraw
);
3867 ERR("Failed to allocate material memory.\n");
3868 return DDERR_OUTOFMEMORY
;
3871 TRACE("Created material %p.\n", object
);
3872 *material
= &object
->IDirect3DMaterial2_iface
;
3877 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
,
3878 IUnknown
*outer_unknown
)
3880 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3881 struct d3d_material
*object
;
3883 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3885 object
= d3d_material_create(ddraw
);
3888 ERR("Failed to allocate material memory.\n");
3889 return DDERR_OUTOFMEMORY
;
3892 TRACE("Created material %p.\n", object
);
3893 *material
= &object
->IDirect3DMaterial_iface
;
3898 /*****************************************************************************
3899 * IDirect3D3::CreateViewport
3901 * Creates an IDirect3DViewport interface. This interface is used
3902 * by Direct3D and earlier versions for Viewport management. In Direct3D7
3903 * it has been replaced by a viewport structure and
3904 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
3905 * uses the IDirect3DDevice7 methods for its functionality
3908 * Viewport: Address to store the new interface pointer
3909 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3914 * DDERR_OUTOFMEMORY if memory allocation failed
3915 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3917 *****************************************************************************/
3918 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
,
3919 IUnknown
*outer_unknown
)
3921 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3922 struct d3d_viewport
*object
;
3924 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
3926 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3928 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3931 ERR("Failed to allocate viewport memory.\n");
3932 return DDERR_OUTOFMEMORY
;
3935 d3d_viewport_init(object
, ddraw
);
3937 TRACE("Created viewport %p.\n", object
);
3938 *viewport
= &object
->IDirect3DViewport3_iface
;
3943 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
3945 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3947 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
3949 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
3953 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
3955 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3957 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
3959 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
3963 /*****************************************************************************
3964 * IDirect3D3::FindDevice
3966 * This method finds a device with the requested properties and returns a
3967 * device description
3969 * Versions 1, 2 and 3
3971 * fds: Describes the requested device characteristics
3972 * fdr: Returns the device description
3976 * DDERR_INVALIDPARAMS if no device was found
3978 *****************************************************************************/
3979 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
3981 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3982 D3DDEVICEDESC7 desc7
;
3983 D3DDEVICEDESC desc1
;
3986 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
3988 if (!fds
|| !fdr
) return DDERR_INVALIDPARAMS
;
3990 if (fds
->dwSize
!= sizeof(D3DFINDDEVICESEARCH
)
3991 || fdr
->dwSize
!= sizeof(D3DFINDDEVICERESULT
))
3992 return DDERR_INVALIDPARAMS
;
3994 if ((fds
->dwFlags
& D3DFDS_COLORMODEL
)
3995 && fds
->dcmColorModel
!= D3DCOLOR_RGB
)
3997 WARN("Trying to request a non-RGB D3D color model. Not supported.\n");
3998 return DDERR_INVALIDPARAMS
; /* No real idea what to return here :-) */
4001 if (fds
->dwFlags
& D3DFDS_GUID
)
4003 TRACE("Trying to match guid %s.\n", debugstr_guid(&(fds
->guid
)));
4004 if (!IsEqualGUID(&IID_D3DDEVICE_WineD3D
, &fds
->guid
)
4005 && !IsEqualGUID(&IID_IDirect3DHALDevice
, &fds
->guid
)
4006 && !IsEqualGUID(&IID_IDirect3DRGBDevice
, &fds
->guid
))
4008 WARN("No match for this GUID.\n");
4009 return DDERR_NOTFOUND
;
4014 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &desc7
)))
4017 /* Now return our own GUID */
4018 ddraw_d3dcaps1_from_7(&desc1
, &desc7
);
4019 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4020 fdr
->ddHwDesc
= desc1
;
4021 fdr
->ddSwDesc
= desc1
;
4023 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4028 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4030 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4032 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4034 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4037 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4039 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4041 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4043 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4046 /*****************************************************************************
4047 * IDirect3D7::CreateDevice
4049 * Creates an IDirect3DDevice7 interface.
4051 * Versions 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4052 * DirectDraw surfaces and are created with
4053 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4054 * create the device object and QueryInterfaces for IDirect3DDevice
4057 * refiid: IID of the device to create
4058 * Surface: Initial rendertarget
4059 * Device: Address to return the interface pointer
4063 * DDERR_OUTOFMEMORY if memory allocation failed
4064 * DDERR_INVALIDPARAMS if a device exists already
4066 *****************************************************************************/
4067 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4068 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4070 struct ddraw_surface
*target
= unsafe_impl_from_IDirectDrawSurface7(surface
);
4071 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4072 struct d3d_device
*object
;
4075 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4077 wined3d_mutex_lock();
4078 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, target
, (IUnknown
*)surface
, 7, &object
, NULL
)))
4080 *device
= &object
->IDirect3DDevice7_iface
;
4084 WARN("Failed to create device, hr %#x.\n", hr
);
4087 wined3d_mutex_unlock();
4092 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4093 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4095 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface4(surface
);
4096 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4097 struct d3d_device
*device_impl
;
4100 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4101 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4104 return CLASS_E_NOAGGREGATION
;
4106 wined3d_mutex_lock();
4107 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 3, &device_impl
, NULL
)))
4109 *device
= &device_impl
->IDirect3DDevice3_iface
;
4113 WARN("Failed to create device, hr %#x.\n", hr
);
4116 wined3d_mutex_unlock();
4121 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4122 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4124 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface(surface
);
4125 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4126 struct d3d_device
*device_impl
;
4129 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4130 iface
, debugstr_guid(riid
), surface
, device
);
4132 wined3d_mutex_lock();
4133 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 2, &device_impl
, NULL
)))
4135 *device
= &device_impl
->IDirect3DDevice2_iface
;
4139 WARN("Failed to create device, hr %#x.\n", hr
);
4142 wined3d_mutex_unlock();
4147 /*****************************************************************************
4148 * IDirect3D7::CreateVertexBuffer
4150 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4156 * desc: Requested Vertex buffer properties
4157 * vertex_buffer: Address to return the interface pointer at
4158 * flags: Some flags, should be 0
4162 * DDERR_OUTOFMEMORY if memory allocation failed
4163 * The return value of IWineD3DDevice::CreateVertexBuffer if this call fails
4164 * DDERR_INVALIDPARAMS if desc or vertex_buffer is NULL
4166 *****************************************************************************/
4167 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4168 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4170 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4171 struct d3d_vertex_buffer
*object
;
4174 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
4175 iface
, desc
, vertex_buffer
, flags
);
4177 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4179 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4182 TRACE("Created vertex buffer %p.\n", object
);
4183 *vertex_buffer
= &object
->IDirect3DVertexBuffer7_iface
;
4186 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4191 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4192 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4194 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4195 struct d3d_vertex_buffer
*object
;
4198 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n",
4199 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4202 return CLASS_E_NOAGGREGATION
;
4203 if (!vertex_buffer
|| !desc
)
4204 return DDERR_INVALIDPARAMS
;
4206 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4209 TRACE("Created vertex buffer %p.\n", object
);
4210 *vertex_buffer
= &object
->IDirect3DVertexBuffer_iface
;
4213 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4218 /*****************************************************************************
4219 * IDirect3D7::EnumZBufferFormats
4221 * Enumerates all supported Z buffer pixel formats
4227 * callback: callback to call for each pixel format
4228 * context: Pointer to pass back to the callback
4232 * DDERR_INVALIDPARAMS if callback is NULL
4233 * For details, see IWineD3DDevice::EnumZBufferFormats
4235 *****************************************************************************/
4236 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4237 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4239 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4240 struct wined3d_display_mode mode
;
4241 enum wined3d_device_type type
;
4245 /* Order matters. Specifically, BattleZone II (full version) expects the
4246 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4247 static const enum wined3d_format_id formats
[] =
4249 WINED3DFMT_S1_UINT_D15_UNORM
,
4250 WINED3DFMT_D16_UNORM
,
4251 WINED3DFMT_X8D24_UNORM
,
4252 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4253 WINED3DFMT_D24_UNORM_S8_UINT
,
4254 WINED3DFMT_D32_UNORM
,
4257 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4258 iface
, debugstr_guid(device_iid
), callback
, context
);
4260 if (!callback
) return DDERR_INVALIDPARAMS
;
4262 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4263 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4264 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4266 TRACE("Asked for HAL device.\n");
4267 type
= WINED3D_DEVICE_TYPE_HAL
;
4269 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4270 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4272 TRACE("Asked for SW device.\n");
4273 type
= WINED3D_DEVICE_TYPE_SW
;
4275 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4277 TRACE("Asked for REF device.\n");
4278 type
= WINED3D_DEVICE_TYPE_REF
;
4280 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4282 TRACE("Asked for NULLREF device.\n");
4283 type
= WINED3D_DEVICE_TYPE_NULLREF
;
4287 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4288 type
= WINED3D_DEVICE_TYPE_HAL
;
4291 wined3d_mutex_lock();
4292 /* We need an adapter format from somewhere to please wined3d and WGL.
4293 * Use the current display mode. So far all cards offer the same depth
4294 * stencil format for all modes, but if some do not and applications do
4295 * not like that we'll have to find some workaround, like iterating over
4296 * all imaginable formats and collecting all the depth stencil formats we
4298 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
4300 ERR("Failed to get display mode, hr %#x.\n", hr
);
4301 wined3d_mutex_unlock();
4305 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
4307 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4308 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_TEXTURE_2D
, formats
[i
])))
4310 DDPIXELFORMAT pformat
;
4312 memset(&pformat
, 0, sizeof(pformat
));
4313 pformat
.dwSize
= sizeof(pformat
);
4314 ddrawformat_from_wined3dformat(&pformat
, formats
[i
]);
4316 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
4317 hr
= callback(&pformat
, context
);
4318 if (hr
!= DDENUMRET_OK
)
4320 TRACE("Format enumeration cancelled by application.\n");
4321 wined3d_mutex_unlock();
4327 /* Historically some windows drivers used dwZBufferBitDepth=24 for WINED3DFMT_X8D24_UNORM,
4328 * while others used dwZBufferBitDepth=32. In either case the pitch matches a 32 bits per
4329 * pixel format, so we use dwZBufferBitDepth=32. Some games expect 24. Windows Vista and
4330 * newer enumerate both versions, so we do the same(bug 22434) */
4331 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4332 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_TEXTURE_2D
, WINED3DFMT_X8D24_UNORM
)))
4334 DDPIXELFORMAT x8d24
=
4336 sizeof(x8d24
), DDPF_ZBUFFER
, 0,
4337 {24}, {0x00000000}, {0x00ffffff}, {0x00000000}
4339 TRACE("Enumerating WINED3DFMT_X8D24_UNORM, dwZBufferBitDepth=24 version\n");
4340 callback(&x8d24
, context
);
4343 TRACE("End of enumeration.\n");
4345 wined3d_mutex_unlock();
4350 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
4351 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4353 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4355 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4356 iface
, debugstr_guid(device_iid
), callback
, context
);
4358 return d3d7_EnumZBufferFormats(&ddraw
->IDirect3D7_iface
, device_iid
, callback
, context
);
4361 /*****************************************************************************
4362 * IDirect3D7::EvictManagedTextures
4364 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
4365 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
4370 * D3D_OK, because it's a stub
4372 *****************************************************************************/
4373 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
4375 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4377 TRACE("iface %p!\n", iface
);
4379 wined3d_mutex_lock();
4380 if (ddraw
->flags
& DDRAW_D3D_INITIALIZED
)
4381 wined3d_device_evict_managed_resources(ddraw
->wined3d_device
);
4382 wined3d_mutex_unlock();
4387 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
4389 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4391 TRACE("iface %p.\n", iface
);
4393 return d3d7_EvictManagedTextures(&ddraw
->IDirect3D7_iface
);
4396 /*****************************************************************************
4397 * IDirectDraw7 VTable
4398 *****************************************************************************/
4399 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
4402 ddraw7_QueryInterface
,
4407 ddraw7_CreateClipper
,
4408 ddraw7_CreatePalette
,
4409 ddraw7_CreateSurface
,
4410 ddraw7_DuplicateSurface
,
4411 ddraw7_EnumDisplayModes
,
4412 ddraw7_EnumSurfaces
,
4413 ddraw7_FlipToGDISurface
,
4415 ddraw7_GetDisplayMode
,
4416 ddraw7_GetFourCCCodes
,
4417 ddraw7_GetGDISurface
,
4418 ddraw7_GetMonitorFrequency
,
4420 ddraw7_GetVerticalBlankStatus
,
4422 ddraw7_RestoreDisplayMode
,
4423 ddraw7_SetCooperativeLevel
,
4424 ddraw7_SetDisplayMode
,
4425 ddraw7_WaitForVerticalBlank
,
4427 ddraw7_GetAvailableVidMem
,
4429 ddraw7_GetSurfaceFromDC
,
4431 ddraw7_RestoreAllSurfaces
,
4432 ddraw7_TestCooperativeLevel
,
4433 ddraw7_GetDeviceIdentifier
,
4435 ddraw7_StartModeTest
,
4439 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
4442 ddraw4_QueryInterface
,
4447 ddraw4_CreateClipper
,
4448 ddraw4_CreatePalette
,
4449 ddraw4_CreateSurface
,
4450 ddraw4_DuplicateSurface
,
4451 ddraw4_EnumDisplayModes
,
4452 ddraw4_EnumSurfaces
,
4453 ddraw4_FlipToGDISurface
,
4455 ddraw4_GetDisplayMode
,
4456 ddraw4_GetFourCCCodes
,
4457 ddraw4_GetGDISurface
,
4458 ddraw4_GetMonitorFrequency
,
4460 ddraw4_GetVerticalBlankStatus
,
4462 ddraw4_RestoreDisplayMode
,
4463 ddraw4_SetCooperativeLevel
,
4464 ddraw4_SetDisplayMode
,
4465 ddraw4_WaitForVerticalBlank
,
4467 ddraw4_GetAvailableVidMem
,
4469 ddraw4_GetSurfaceFromDC
,
4471 ddraw4_RestoreAllSurfaces
,
4472 ddraw4_TestCooperativeLevel
,
4473 ddraw4_GetDeviceIdentifier
,
4476 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
4479 ddraw2_QueryInterface
,
4484 ddraw2_CreateClipper
,
4485 ddraw2_CreatePalette
,
4486 ddraw2_CreateSurface
,
4487 ddraw2_DuplicateSurface
,
4488 ddraw2_EnumDisplayModes
,
4489 ddraw2_EnumSurfaces
,
4490 ddraw2_FlipToGDISurface
,
4492 ddraw2_GetDisplayMode
,
4493 ddraw2_GetFourCCCodes
,
4494 ddraw2_GetGDISurface
,
4495 ddraw2_GetMonitorFrequency
,
4497 ddraw2_GetVerticalBlankStatus
,
4499 ddraw2_RestoreDisplayMode
,
4500 ddraw2_SetCooperativeLevel
,
4501 ddraw2_SetDisplayMode
,
4502 ddraw2_WaitForVerticalBlank
,
4504 ddraw2_GetAvailableVidMem
,
4507 static const struct IDirectDrawVtbl ddraw1_vtbl
=
4510 ddraw1_QueryInterface
,
4515 ddraw1_CreateClipper
,
4516 ddraw1_CreatePalette
,
4517 ddraw1_CreateSurface
,
4518 ddraw1_DuplicateSurface
,
4519 ddraw1_EnumDisplayModes
,
4520 ddraw1_EnumSurfaces
,
4521 ddraw1_FlipToGDISurface
,
4523 ddraw1_GetDisplayMode
,
4524 ddraw1_GetFourCCCodes
,
4525 ddraw1_GetGDISurface
,
4526 ddraw1_GetMonitorFrequency
,
4528 ddraw1_GetVerticalBlankStatus
,
4530 ddraw1_RestoreDisplayMode
,
4531 ddraw1_SetCooperativeLevel
,
4532 ddraw1_SetDisplayMode
,
4533 ddraw1_WaitForVerticalBlank
,
4536 static const struct IDirect3D7Vtbl d3d7_vtbl
=
4538 /* IUnknown methods */
4539 d3d7_QueryInterface
,
4542 /* IDirect3D7 methods */
4545 d3d7_CreateVertexBuffer
,
4546 d3d7_EnumZBufferFormats
,
4547 d3d7_EvictManagedTextures
4550 static const struct IDirect3D3Vtbl d3d3_vtbl
=
4552 /* IUnknown methods */
4553 d3d3_QueryInterface
,
4556 /* IDirect3D3 methods */
4559 d3d3_CreateMaterial
,
4560 d3d3_CreateViewport
,
4563 d3d3_CreateVertexBuffer
,
4564 d3d3_EnumZBufferFormats
,
4565 d3d3_EvictManagedTextures
4568 static const struct IDirect3D2Vtbl d3d2_vtbl
=
4570 /* IUnknown methods */
4571 d3d2_QueryInterface
,
4574 /* IDirect3D2 methods */
4577 d3d2_CreateMaterial
,
4578 d3d2_CreateViewport
,
4583 static const struct IDirect3DVtbl d3d1_vtbl
=
4585 /* IUnknown methods */
4586 d3d1_QueryInterface
,
4589 /* IDirect3D methods */
4593 d3d1_CreateMaterial
,
4594 d3d1_CreateViewport
,
4598 /*****************************************************************************
4601 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
4602 * if none was found.
4604 * This function is in ddraw.c and the DDraw object space because D3D7
4605 * vertex buffers are created using the IDirect3D interface to the ddraw
4606 * object, so they can be valid across D3D devices(theoretically. The ddraw
4607 * object also owns the wined3d device
4611 * fvf: Fvf to find the decl for
4614 * NULL in case of an error, the vertex declaration for the FVF otherwise.
4616 *****************************************************************************/
4617 struct wined3d_vertex_declaration
*ddraw_find_decl(struct ddraw
*This
, DWORD fvf
)
4619 struct wined3d_vertex_declaration
*pDecl
= NULL
;
4621 int p
, low
, high
; /* deliberately signed */
4622 struct FvfToDecl
*convertedDecls
= This
->decls
;
4624 TRACE("Searching for declaration for fvf %08x... ", fvf
);
4627 high
= This
->numConvertedDecls
- 1;
4628 while(low
<= high
) {
4629 p
= (low
+ high
) >> 1;
4631 if(convertedDecls
[p
].fvf
== fvf
) {
4632 TRACE("found %p\n", convertedDecls
[p
].decl
);
4633 return convertedDecls
[p
].decl
;
4634 } else if(convertedDecls
[p
].fvf
< fvf
) {
4640 TRACE("not found. Creating and inserting at position %d.\n", low
);
4642 hr
= wined3d_vertex_declaration_create_from_fvf(This
->wined3d_device
,
4643 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
4644 if (hr
!= S_OK
) return NULL
;
4646 if(This
->declArraySize
== This
->numConvertedDecls
) {
4647 int grow
= max(This
->declArraySize
/ 2, 8);
4648 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
4649 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
4650 if (!convertedDecls
)
4652 wined3d_vertex_declaration_decref(pDecl
);
4655 This
->decls
= convertedDecls
;
4656 This
->declArraySize
+= grow
;
4659 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
4660 convertedDecls
[low
].decl
= pDecl
;
4661 convertedDecls
[low
].fvf
= fvf
;
4662 This
->numConvertedDecls
++;
4664 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
4668 static inline struct ddraw
*ddraw_from_device_parent(struct wined3d_device_parent
*device_parent
)
4670 return CONTAINING_RECORD(device_parent
, struct ddraw
, device_parent
);
4673 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
4674 struct wined3d_device
*device
)
4676 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
4679 /* This is run from device_process_message() in wined3d, we can't take the
4681 /* FIXME: We only get mode change notifications in exclusive mode, but we
4682 * should mark surfaces as lost on mode changes in DDSCL_NORMAL mode as well. */
4683 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
4685 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4686 MONITORINFO monitor_info
;
4690 TRACE("device_parent %p.\n", device_parent
);
4692 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) || !ddraw
->swapchain_window
)
4694 TRACE("Nothing to resize.\n");
4698 monitor
= MonitorFromWindow(ddraw
->swapchain_window
, MONITOR_DEFAULTTOPRIMARY
);
4699 monitor_info
.cbSize
= sizeof(monitor_info
);
4700 if (!GetMonitorInfoW(monitor
, &monitor_info
))
4702 ERR("Failed to get monitor info.\n");
4706 r
= &monitor_info
.rcMonitor
;
4707 TRACE("Resizing window %p to %s.\n", ddraw
->swapchain_window
, wine_dbgstr_rect(r
));
4709 if (!SetWindowPos(ddraw
->swapchain_window
, HWND_TOP
, r
->left
, r
->top
,
4710 r
->right
- r
->left
, r
->bottom
- r
->top
, SWP_SHOWWINDOW
| SWP_NOACTIVATE
))
4711 ERR("Failed to resize window.\n");
4713 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_OK
);
4716 static void CDECL
device_parent_activate(struct wined3d_device_parent
*device_parent
, BOOL activate
)
4718 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4720 TRACE("device_parent %p, activate %#x.\n", device_parent
, activate
);
4724 ddraw
->device_state
= DDRAW_DEVICE_STATE_LOST
;
4725 exclusive_window
= NULL
;
4729 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_LOST
);
4733 void ddraw_update_lost_surfaces(struct ddraw
*ddraw
)
4735 struct ddraw_surface
*surface
;
4737 if (ddraw
->device_state
!= DDRAW_DEVICE_STATE_NOT_RESTORED
)
4740 LIST_FOR_EACH_ENTRY(surface
, &ddraw
->surface_list
, struct ddraw_surface
, surface_list_entry
)
4742 surface
->is_lost
= TRUE
;
4744 ddraw
->device_state
= DDRAW_DEVICE_STATE_OK
;
4747 static HRESULT CDECL
device_parent_surface_created(struct wined3d_device_parent
*device_parent
,
4748 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
4749 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
4751 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4752 struct ddraw_surface
*ddraw_surface
;
4754 TRACE("device_parent %p, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
4755 device_parent
, wined3d_texture
, sub_resource_idx
, parent
, parent_ops
);
4757 /* We have a swapchain or wined3d internal texture. */
4758 if (!wined3d_texture_get_parent(wined3d_texture
) || wined3d_texture_get_parent(wined3d_texture
) == ddraw
)
4761 *parent_ops
= &ddraw_null_wined3d_parent_ops
;
4766 if (!(ddraw_surface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ddraw_surface
))))
4768 ERR("Failed to allocate surface memory.\n");
4769 return DDERR_OUTOFVIDEOMEMORY
;
4772 ddraw_surface_init(ddraw_surface
, ddraw
, wined3d_texture
, sub_resource_idx
, parent_ops
);
4773 *parent
= ddraw_surface
;
4775 ddraw_update_lost_surfaces(ddraw
);
4776 list_add_head(&ddraw
->surface_list
, &ddraw_surface
->surface_list_entry
);
4778 TRACE("Created ddraw surface %p.\n", ddraw_surface
);
4783 static HRESULT CDECL
device_parent_volume_created(struct wined3d_device_parent
*device_parent
,
4784 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
4785 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
4787 TRACE("device_parent %p, texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
4788 device_parent
, wined3d_texture
, sub_resource_idx
, parent
, parent_ops
);
4791 *parent_ops
= &ddraw_null_wined3d_parent_ops
;
4796 static void STDMETHODCALLTYPE
ddraw_frontbuffer_destroyed(void *parent
)
4798 struct ddraw
*ddraw
= parent
;
4799 ddraw
->wined3d_frontbuffer
= NULL
;
4802 static const struct wined3d_parent_ops ddraw_frontbuffer_parent_ops
=
4804 ddraw_frontbuffer_destroyed
,
4807 static HRESULT CDECL
device_parent_create_swapchain_texture(struct wined3d_device_parent
*device_parent
,
4808 void *container_parent
, const struct wined3d_resource_desc
*desc
, struct wined3d_texture
**texture
)
4810 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4813 TRACE("device_parent %p, container_parent %p, desc %p, texture %p.\n",
4814 device_parent
, container_parent
, desc
, texture
);
4816 if (ddraw
->wined3d_frontbuffer
)
4818 ERR("Frontbuffer already created.\n");
4822 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, desc
, 1, 1,
4823 WINED3D_TEXTURE_CREATE_MAPPABLE
, NULL
, ddraw
, &ddraw_frontbuffer_parent_ops
, texture
)))
4825 WARN("Failed to create texture, hr %#x.\n", hr
);
4829 ddraw
->wined3d_frontbuffer
= *texture
;
4834 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
4835 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
4837 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4840 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent
, desc
, swapchain
);
4842 if (ddraw
->wined3d_swapchain
)
4844 ERR("Swapchain already created.\n");
4848 if (FAILED(hr
= wined3d_swapchain_create(ddraw
->wined3d_device
, desc
, NULL
,
4849 &ddraw_null_wined3d_parent_ops
, swapchain
)))
4850 WARN("Failed to create swapchain, hr %#x.\n", hr
);
4855 static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops
=
4857 device_parent_wined3d_device_created
,
4858 device_parent_mode_changed
,
4859 device_parent_activate
,
4860 device_parent_surface_created
,
4861 device_parent_volume_created
,
4862 device_parent_create_swapchain_texture
,
4863 device_parent_create_swapchain
,
4866 HRESULT
ddraw_init(struct ddraw
*ddraw
, DWORD flags
, enum wined3d_device_type device_type
)
4871 ddraw
->IDirectDraw7_iface
.lpVtbl
= &ddraw7_vtbl
;
4872 ddraw
->IDirectDraw_iface
.lpVtbl
= &ddraw1_vtbl
;
4873 ddraw
->IDirectDraw2_iface
.lpVtbl
= &ddraw2_vtbl
;
4874 ddraw
->IDirectDraw4_iface
.lpVtbl
= &ddraw4_vtbl
;
4875 ddraw
->IDirect3D_iface
.lpVtbl
= &d3d1_vtbl
;
4876 ddraw
->IDirect3D2_iface
.lpVtbl
= &d3d2_vtbl
;
4877 ddraw
->IDirect3D3_iface
.lpVtbl
= &d3d3_vtbl
;
4878 ddraw
->IDirect3D7_iface
.lpVtbl
= &d3d7_vtbl
;
4879 ddraw
->device_parent
.ops
= &ddraw_wined3d_device_parent_ops
;
4880 ddraw
->numIfaces
= 1;
4883 flags
|= DDRAW_WINED3D_FLAGS
;
4884 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
4886 flags
|= WINED3D_NO3D
;
4887 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
4889 WARN("Failed to create a wined3d object.\n");
4894 if (FAILED(hr
= wined3d_get_device_caps(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
, &caps
)))
4896 ERR("Failed to get device caps, hr %#x.\n", hr
);
4897 wined3d_decref(ddraw
->wined3d
);
4901 if (!(caps
.ddraw_caps
.caps
& WINEDDCAPS_3D
))
4903 WARN("Created a wined3d object without 3D support.\n");
4904 ddraw
->flags
|= DDRAW_NO3D
;
4907 if (FAILED(hr
= wined3d_device_create(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
,
4908 NULL
, 0, DDRAW_STRIDE_ALIGNMENT
, &ddraw
->device_parent
, &ddraw
->wined3d_device
)))
4910 WARN("Failed to create a wined3d device, hr %#x.\n", hr
);
4911 wined3d_decref(ddraw
->wined3d
);
4915 list_init(&ddraw
->surface_list
);