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 struct wined3d_display_mode original_mode
;
32 static const struct ddraw
*exclusive_ddraw
;
33 static BOOL restore_mode
;
35 /* Device identifier. Don't relay it to WineD3D */
36 static const DDDEVICEIDENTIFIER2 deviceidentifier
=
40 { { 0x00010001, 0x00010001 } },
42 /* a8373c10-7ac4-4deb-849a-009844d08b2d */
43 {0xa8373c10,0x7ac4,0x4deb, {0x84,0x9a,0x00,0x98,0x44,0xd0,0x8b,0x2d}},
47 static struct enum_device_entry
49 char interface_name
[100];
50 char device_name
[100];
51 const GUID
*device_guid
;
56 "WINE Direct3D7 Hardware Transform and Lighting acceleration using WineD3D",
58 &IID_IDirect3DTnLHalDevice
,
63 "WINE Direct3D7 Hardware acceleration using WineD3D",
65 &IID_IDirect3DHALDevice
,
70 "WINE Direct3D7 RGB Software Emulation using WineD3D",
72 &IID_IDirect3DRGBDevice
,
76 static void STDMETHODCALLTYPE
ddraw_null_wined3d_object_destroyed(void *parent
) {}
78 const struct wined3d_parent_ops ddraw_null_wined3d_parent_ops
=
80 ddraw_null_wined3d_object_destroyed
,
83 static inline struct ddraw
*impl_from_IDirectDraw(IDirectDraw
*iface
)
85 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw_iface
);
88 static inline struct ddraw
*impl_from_IDirectDraw2(IDirectDraw2
*iface
)
90 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw2_iface
);
93 static inline struct ddraw
*impl_from_IDirectDraw4(IDirectDraw4
*iface
)
95 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw4_iface
);
98 static inline struct ddraw
*impl_from_IDirectDraw7(IDirectDraw7
*iface
)
100 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw7_iface
);
103 static inline struct ddraw
*impl_from_IDirect3D(IDirect3D
*iface
)
105 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D_iface
);
108 static inline struct ddraw
*impl_from_IDirect3D2(IDirect3D2
*iface
)
110 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D2_iface
);
113 static inline struct ddraw
*impl_from_IDirect3D3(IDirect3D3
*iface
)
115 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D3_iface
);
118 static inline struct ddraw
*impl_from_IDirect3D7(IDirect3D7
*iface
)
120 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D7_iface
);
123 static HRESULT WINAPI
ddraw7_QueryInterface(IDirectDraw7
*iface
, REFIID riid
, void **out
)
125 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
127 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
132 return DDERR_INVALIDPARAMS
;
135 /* The refcount unit test revealed that an IDirect3D7 interface can only
136 * be queried from a DirectDraw object that was created as an IDirectDraw7
137 * interface. The older interfaces can query any IDirect3D version except
138 * 7, because they are all initially created as IDirectDraw. This isn't
139 * really crucial behavior, and messy to implement with the common
140 * creation function, so it has been left out here. */
141 if (IsEqualGUID(&IID_IDirectDraw7
, riid
)
142 || IsEqualGUID(&IID_IUnknown
, riid
))
144 *out
= &ddraw
->IDirectDraw7_iface
;
145 TRACE("Returning IDirectDraw7 interface %p.\n", *out
);
147 else if (IsEqualGUID(&IID_IDirectDraw4
, riid
))
149 *out
= &ddraw
->IDirectDraw4_iface
;
150 TRACE("Returning IDirectDraw4 interface %p.\n", *out
);
152 else if (IsEqualGUID(&IID_IDirectDraw2
, riid
))
154 *out
= &ddraw
->IDirectDraw2_iface
;
155 TRACE("Returning IDirectDraw2 interface %p.\n", *out
);
157 else if (IsEqualGUID(&IID_IDirectDraw
, riid
))
159 *out
= &ddraw
->IDirectDraw_iface
;
160 TRACE("Returning IDirectDraw interface %p.\n", *out
);
162 else if (IsEqualGUID(&IID_IDirect3D7
, riid
))
164 ddraw
->d3dversion
= 7;
165 *out
= &ddraw
->IDirect3D7_iface
;
166 TRACE("Returning Direct3D7 interface %p.\n", *out
);
168 else if (IsEqualGUID(&IID_IDirect3D3
, riid
))
170 ddraw
->d3dversion
= 3;
171 *out
= &ddraw
->IDirect3D3_iface
;
172 TRACE("Returning Direct3D3 interface %p.\n", *out
);
174 else if (IsEqualGUID(&IID_IDirect3D2
, riid
))
176 ddraw
->d3dversion
= 2;
177 *out
= &ddraw
->IDirect3D2_iface
;
178 TRACE("Returning Direct3D2 interface %p.\n", *out
);
180 else if (IsEqualGUID(&IID_IDirect3D
, riid
))
182 ddraw
->d3dversion
= 1;
183 *out
= &ddraw
->IDirect3D_iface
;
184 TRACE("Returning Direct3D interface %p.\n", *out
);
186 /* Unknown interface */
189 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
191 return E_NOINTERFACE
;
194 IUnknown_AddRef((IUnknown
*)*out
);
198 static HRESULT WINAPI
ddraw4_QueryInterface(IDirectDraw4
*iface
, REFIID riid
, void **object
)
200 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
202 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
204 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
207 static HRESULT WINAPI
ddraw2_QueryInterface(IDirectDraw2
*iface
, REFIID riid
, void **object
)
209 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
211 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
213 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
216 static HRESULT WINAPI
ddraw1_QueryInterface(IDirectDraw
*iface
, REFIID riid
, void **object
)
218 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
220 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
222 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
225 static HRESULT WINAPI
d3d7_QueryInterface(IDirect3D7
*iface
, REFIID riid
, void **object
)
227 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
229 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
231 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
234 static HRESULT WINAPI
d3d3_QueryInterface(IDirect3D3
*iface
, REFIID riid
, void **object
)
236 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
238 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
240 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
243 static HRESULT WINAPI
d3d2_QueryInterface(IDirect3D2
*iface
, REFIID riid
, void **object
)
245 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
247 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
249 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
252 static HRESULT WINAPI
d3d1_QueryInterface(IDirect3D
*iface
, REFIID riid
, void **object
)
254 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
256 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
258 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
261 /*****************************************************************************
262 * IDirectDraw7::AddRef
264 * Increases the interfaces refcount, basically
266 * DDraw refcounting is a bit tricky. The different DirectDraw interface
267 * versions have individual refcounts, but the IDirect3D interfaces do not.
268 * All interfaces are from one object, that means calling QueryInterface on an
269 * IDirectDraw7 interface for an IDirectDraw4 interface does not create a new
272 * That means all AddRef and Release implementations of IDirectDrawX work
273 * with their own counter, and IDirect3DX::AddRef thunk to IDirectDraw (1),
274 * except of IDirect3D7 which thunks to IDirectDraw7
276 * Returns: The new refcount
278 *****************************************************************************/
279 static ULONG WINAPI
ddraw7_AddRef(IDirectDraw7
*iface
)
281 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
282 ULONG ref
= InterlockedIncrement(&This
->ref7
);
284 TRACE("%p increasing refcount to %u.\n", This
, ref
);
286 if(ref
== 1) InterlockedIncrement(&This
->numIfaces
);
291 static ULONG WINAPI
ddraw4_AddRef(IDirectDraw4
*iface
)
293 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
294 ULONG ref
= InterlockedIncrement(&This
->ref4
);
296 TRACE("%p increasing refcount to %u.\n", This
, ref
);
298 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
303 static ULONG WINAPI
ddraw2_AddRef(IDirectDraw2
*iface
)
305 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
306 ULONG ref
= InterlockedIncrement(&This
->ref2
);
308 TRACE("%p increasing refcount to %u.\n", This
, ref
);
310 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
315 static ULONG WINAPI
ddraw1_AddRef(IDirectDraw
*iface
)
317 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
318 ULONG ref
= InterlockedIncrement(&This
->ref1
);
320 TRACE("%p increasing refcount to %u.\n", This
, ref
);
322 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
327 static ULONG WINAPI
d3d7_AddRef(IDirect3D7
*iface
)
329 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
331 TRACE("iface %p.\n", iface
);
333 return ddraw7_AddRef(&This
->IDirectDraw7_iface
);
336 static ULONG WINAPI
d3d3_AddRef(IDirect3D3
*iface
)
338 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
340 TRACE("iface %p.\n", iface
);
342 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
345 static ULONG WINAPI
d3d2_AddRef(IDirect3D2
*iface
)
347 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
349 TRACE("iface %p.\n", iface
);
351 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
354 static ULONG WINAPI
d3d1_AddRef(IDirect3D
*iface
)
356 struct ddraw
*This
= impl_from_IDirect3D(iface
);
358 TRACE("iface %p.\n", iface
);
360 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
363 void ddraw_destroy_swapchain(struct ddraw
*ddraw
)
365 TRACE("Destroying the swapchain.\n");
367 wined3d_swapchain_decref(ddraw
->wined3d_swapchain
);
368 ddraw
->wined3d_swapchain
= NULL
;
370 if (!(ddraw
->flags
& DDRAW_NO3D
))
374 for (i
= 0; i
< ddraw
->numConvertedDecls
; ++i
)
376 wined3d_vertex_declaration_decref(ddraw
->decls
[i
].decl
);
378 HeapFree(GetProcessHeap(), 0, ddraw
->decls
);
379 ddraw
->numConvertedDecls
= 0;
381 if (FAILED(wined3d_device_uninit_3d(ddraw
->wined3d_device
)))
383 ERR("Failed to uninit 3D.\n");
387 /* Free the d3d window if one was created. */
388 if (ddraw
->d3d_window
&& ddraw
->d3d_window
!= ddraw
->dest_window
)
390 TRACE("Destroying the hidden render window %p.\n", ddraw
->d3d_window
);
391 DestroyWindow(ddraw
->d3d_window
);
392 ddraw
->d3d_window
= 0;
396 ddraw
->flags
&= ~DDRAW_D3D_INITIALIZED
;
400 wined3d_device_uninit_gdi(ddraw
->wined3d_device
);
403 ddraw_set_swapchain_window(ddraw
, NULL
);
405 TRACE("Swapchain destroyed.\n");
408 /*****************************************************************************
411 * Destroys a ddraw object if all refcounts are 0. This is to share code
412 * between the IDirectDrawX::Release functions
415 * This: DirectDraw object to destroy
417 *****************************************************************************/
418 static void ddraw_destroy(struct ddraw
*This
)
420 IDirectDraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, NULL
, DDSCL_NORMAL
);
421 IDirectDraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
423 /* Destroy the device window if we created one */
424 if(This
->devicewindow
!= 0)
426 TRACE(" (%p) Destroying the device window %p\n", This
, This
->devicewindow
);
427 DestroyWindow(This
->devicewindow
);
428 This
->devicewindow
= 0;
431 wined3d_mutex_lock();
432 list_remove(&This
->ddraw_list_entry
);
433 wined3d_mutex_unlock();
435 if (This
->wined3d_swapchain
)
436 ddraw_destroy_swapchain(This
);
437 wined3d_device_decref(This
->wined3d_device
);
438 wined3d_decref(This
->wined3d
);
440 /* Now free the object */
441 HeapFree(GetProcessHeap(), 0, This
);
444 /*****************************************************************************
445 * IDirectDraw7::Release
447 * Decreases the refcount. If the refcount falls to 0, the object is destroyed
449 * Returns: The new refcount
450 *****************************************************************************/
451 static ULONG WINAPI
ddraw7_Release(IDirectDraw7
*iface
)
453 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
454 ULONG ref
= InterlockedDecrement(&This
->ref7
);
456 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
458 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
464 static ULONG WINAPI
ddraw4_Release(IDirectDraw4
*iface
)
466 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
467 ULONG ref
= InterlockedDecrement(&This
->ref4
);
469 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
471 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
477 static ULONG WINAPI
ddraw2_Release(IDirectDraw2
*iface
)
479 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
480 ULONG ref
= InterlockedDecrement(&This
->ref2
);
482 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
484 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
490 static ULONG WINAPI
ddraw1_Release(IDirectDraw
*iface
)
492 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
493 ULONG ref
= InterlockedDecrement(&This
->ref1
);
495 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
497 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
503 static ULONG WINAPI
d3d7_Release(IDirect3D7
*iface
)
505 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
507 TRACE("iface %p.\n", iface
);
509 return ddraw7_Release(&This
->IDirectDraw7_iface
);
512 static ULONG WINAPI
d3d3_Release(IDirect3D3
*iface
)
514 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
516 TRACE("iface %p.\n", iface
);
518 return ddraw1_Release(&This
->IDirectDraw_iface
);
521 static ULONG WINAPI
d3d2_Release(IDirect3D2
*iface
)
523 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
525 TRACE("iface %p.\n", iface
);
527 return ddraw1_Release(&This
->IDirectDraw_iface
);
530 static ULONG WINAPI
d3d1_Release(IDirect3D
*iface
)
532 struct ddraw
*This
= impl_from_IDirect3D(iface
);
534 TRACE("iface %p.\n", iface
);
536 return ddraw1_Release(&This
->IDirectDraw_iface
);
539 /*****************************************************************************
540 * IDirectDraw methods
541 *****************************************************************************/
543 static HRESULT
ddraw_set_focus_window(struct ddraw
*ddraw
, HWND window
)
545 /* FIXME: This looks wrong, exclusive mode should imply a destination
547 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) && ddraw
->dest_window
)
549 TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET.\n");
550 return DDERR_HWNDALREADYSET
;
553 ddraw
->focuswindow
= window
;
558 static HRESULT
ddraw_attach_d3d_device(struct ddraw
*ddraw
,
559 struct wined3d_swapchain_desc
*swapchain_desc
)
561 HWND window
= swapchain_desc
->device_window
;
564 TRACE("ddraw %p.\n", ddraw
);
566 if (!window
|| window
== GetDesktopWindow())
568 window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "Hidden D3D Window",
569 WS_DISABLED
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
570 NULL
, NULL
, NULL
, NULL
);
573 ERR("Failed to create window, last error %#x.\n", GetLastError());
577 ShowWindow(window
, SW_HIDE
); /* Just to be sure */
578 WARN("No window for the Direct3DDevice, created hidden window %p.\n", window
);
580 swapchain_desc
->device_window
= window
;
584 TRACE("Using existing window %p for Direct3D rendering.\n", window
);
586 ddraw
->d3d_window
= window
;
588 /* Set this NOW, otherwise creating the depth stencil surface will cause a
589 * recursive loop until ram or emulated video memory is full. */
590 ddraw
->flags
|= DDRAW_D3D_INITIALIZED
;
591 hr
= wined3d_device_init_3d(ddraw
->wined3d_device
, swapchain_desc
);
594 ddraw
->flags
&= ~DDRAW_D3D_INITIALIZED
;
598 ddraw
->declArraySize
= 2;
599 ddraw
->decls
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ddraw
->decls
) * ddraw
->declArraySize
);
602 ERR("Error allocating an array for the converted vertex decls.\n");
603 ddraw
->declArraySize
= 0;
604 hr
= wined3d_device_uninit_3d(ddraw
->wined3d_device
);
605 return E_OUTOFMEMORY
;
608 TRACE("Successfully initialized 3D.\n");
613 static HRESULT
ddraw_create_swapchain(struct ddraw
*ddraw
, HWND window
, BOOL windowed
)
615 struct wined3d_swapchain_desc swapchain_desc
;
616 struct wined3d_display_mode mode
;
617 HRESULT hr
= WINED3D_OK
;
619 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
621 ERR("Failed to get display mode.\n");
625 memset(&swapchain_desc
, 0, sizeof(swapchain_desc
));
626 swapchain_desc
.backbuffer_width
= mode
.width
;
627 swapchain_desc
.backbuffer_height
= mode
.height
;
628 swapchain_desc
.backbuffer_format
= mode
.format_id
;
629 swapchain_desc
.swap_effect
= WINED3D_SWAP_EFFECT_COPY
;
630 swapchain_desc
.device_window
= window
;
631 swapchain_desc
.windowed
= windowed
;
633 if (!(ddraw
->flags
& DDRAW_NO3D
))
634 hr
= ddraw_attach_d3d_device(ddraw
, &swapchain_desc
);
636 hr
= wined3d_device_init_gdi(ddraw
->wined3d_device
, &swapchain_desc
);
640 ERR("Failed to create swapchain, hr %#x.\n", hr
);
644 if (!(ddraw
->wined3d_swapchain
= wined3d_device_get_swapchain(ddraw
->wined3d_device
, 0)))
646 ERR("Failed to get swapchain.\n");
647 return DDERR_INVALIDPARAMS
;
650 wined3d_swapchain_incref(ddraw
->wined3d_swapchain
);
651 ddraw_set_swapchain_window(ddraw
, window
);
656 /*****************************************************************************
657 * IDirectDraw7::RestoreDisplayMode
659 * Restores the display mode to what it was at creation time. Basically.
663 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
665 *****************************************************************************/
666 static HRESULT WINAPI
ddraw7_RestoreDisplayMode(IDirectDraw7
*iface
)
668 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
671 TRACE("iface %p.\n", iface
);
673 wined3d_mutex_lock();
675 if (!(ddraw
->flags
& DDRAW_RESTORE_MODE
))
677 wined3d_mutex_unlock();
681 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
683 wined3d_mutex_unlock();
684 return DDERR_NOEXCLUSIVEMODE
;
687 if (SUCCEEDED(hr
= wined3d_set_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &original_mode
)))
689 ddraw
->flags
&= ~DDRAW_RESTORE_MODE
;
690 restore_mode
= FALSE
;
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_surface
*rt
= NULL
, *ds
= 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 /* Tests suggest that we need one of them: */
782 if(!(cooplevel
& (DDSCL_SETFOCUSWINDOW
|
786 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
787 wined3d_mutex_unlock();
788 return DDERR_INVALIDPARAMS
;
791 if ((cooplevel
& DDSCL_CREATEDEVICEWINDOW
) && !(cooplevel
& DDSCL_EXCLUSIVE
))
793 WARN("DDSCL_CREATEDEVICEWINDOW requires DDSCL_EXCLUSIVE.\n");
794 wined3d_mutex_unlock();
795 return DDERR_INVALIDPARAMS
;
798 /* Handle those levels first which set various hwnds */
799 if ((cooplevel
& DDSCL_SETFOCUSWINDOW
) && !(cooplevel
& DDSCL_CREATEDEVICEWINDOW
))
801 /* This isn't compatible with a lot of flags */
802 if (cooplevel
& (DDSCL_MULTITHREADED
807 | DDSCL_SETDEVICEWINDOW
812 WARN("Called with incompatible flags, returning DDERR_INVALIDPARAMS.\n");
813 wined3d_mutex_unlock();
814 return DDERR_INVALIDPARAMS
;
817 hr
= ddraw_set_focus_window(ddraw
, window
);
818 wined3d_mutex_unlock();
822 if (cooplevel
& DDSCL_EXCLUSIVE
)
824 if (!(cooplevel
& DDSCL_FULLSCREEN
) || !(window
|| (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)))
826 WARN("DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN and a window.\n");
827 wined3d_mutex_unlock();
828 return DDERR_INVALIDPARAMS
;
831 if (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)
835 if (!ddraw
->focuswindow
&& !(cooplevel
& DDSCL_SETFOCUSWINDOW
))
837 WARN("No focus window set.\n");
838 wined3d_mutex_unlock();
839 return DDERR_NOFOCUSWINDOW
;
842 device_window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "DirectDrawDeviceWnd",
843 WS_POPUP
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
844 NULL
, NULL
, NULL
, NULL
);
847 ERR("Failed to create window, last error %#x.\n", GetLastError());
848 wined3d_mutex_unlock();
852 ShowWindow(device_window
, SW_SHOW
);
853 TRACE("Created a device window %p.\n", device_window
);
855 /* Native apparently leaks the created device window if setting the
856 * focus window below fails. */
857 ddraw
->cooperative_level
|= DDSCL_CREATEDEVICEWINDOW
;
858 ddraw
->devicewindow
= device_window
;
860 if (cooplevel
& DDSCL_SETFOCUSWINDOW
)
864 wined3d_mutex_unlock();
868 if (FAILED(hr
= ddraw_set_focus_window(ddraw
, window
)))
870 wined3d_mutex_unlock();
875 window
= device_window
;
880 if (ddraw
->cooperative_level
& DDSCL_CREATEDEVICEWINDOW
)
881 DestroyWindow(ddraw
->devicewindow
);
882 ddraw
->devicewindow
= NULL
;
883 ddraw
->focuswindow
= NULL
;
886 if ((cooplevel
& DDSCL_FULLSCREEN
) != (ddraw
->cooperative_level
& DDSCL_FULLSCREEN
) || window
!= ddraw
->dest_window
)
888 if (ddraw
->cooperative_level
& DDSCL_FULLSCREEN
)
889 wined3d_device_restore_fullscreen_window(ddraw
->wined3d_device
, ddraw
->dest_window
);
891 if (cooplevel
& DDSCL_FULLSCREEN
)
893 struct wined3d_display_mode display_mode
;
895 wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &display_mode
, NULL
);
896 wined3d_device_setup_fullscreen_window(ddraw
->wined3d_device
, window
,
897 display_mode
.width
, display_mode
.height
);
901 if (cooplevel
& DDSCL_MULTITHREADED
&& !(ddraw
->cooperative_level
& DDSCL_MULTITHREADED
))
902 wined3d_device_set_multithreaded(ddraw
->wined3d_device
);
904 if (ddraw
->wined3d_swapchain
)
906 if (!(ddraw
->flags
& DDRAW_NO3D
))
908 restore_state
= TRUE
;
910 if (FAILED(hr
= wined3d_stateblock_create(ddraw
->wined3d_device
, WINED3D_SBT_ALL
, &stateblock
)))
912 ERR("Failed to create stateblock, hr %#x.\n", hr
);
913 wined3d_mutex_unlock();
917 wined3d_stateblock_capture(stateblock
);
918 rt
= wined3d_device_get_render_target(ddraw
->wined3d_device
, 0);
919 if (rt
== ddraw
->wined3d_frontbuffer
)
922 wined3d_surface_incref(rt
);
924 if ((ds
= wined3d_device_get_depth_stencil(ddraw
->wined3d_device
)))
925 wined3d_surface_incref(ds
);
928 ddraw_destroy_swapchain(ddraw
);
931 if (FAILED(hr
= ddraw_create_swapchain(ddraw
, window
, !(cooplevel
& DDSCL_FULLSCREEN
))))
932 ERR("Failed to create swapchain, hr %#x.\n", hr
);
938 wined3d_device_set_depth_stencil(ddraw
->wined3d_device
, ds
);
939 wined3d_surface_decref(ds
);
944 wined3d_device_set_render_target(ddraw
->wined3d_device
, 0, rt
, FALSE
);
945 wined3d_surface_decref(rt
);
948 wined3d_stateblock_apply(stateblock
);
949 wined3d_stateblock_decref(stateblock
);
952 if (!(cooplevel
& DDSCL_EXCLUSIVE
) && (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
953 && restore_mode_on_normal
)
955 hr
= ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
957 ERR("RestoreDisplayMode failed\n");
960 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
961 && (window
!= ddraw
->dest_window
|| !(cooplevel
& DDSCL_EXCLUSIVE
)))
962 wined3d_device_release_focus_window(ddraw
->wined3d_device
);
964 if ((cooplevel
& DDSCL_EXCLUSIVE
)
965 && (window
!= ddraw
->dest_window
|| !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)))
967 hr
= wined3d_device_acquire_focus_window(ddraw
->wined3d_device
, window
);
970 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
971 wined3d_mutex_unlock();
976 /* Unhandled flags */
977 if (cooplevel
& DDSCL_ALLOWREBOOT
)
978 WARN("Unhandled flag DDSCL_ALLOWREBOOT, harmless\n");
979 if (cooplevel
& DDSCL_ALLOWMODEX
)
980 WARN("Unhandled flag DDSCL_ALLOWMODEX, harmless\n");
981 if (cooplevel
& DDSCL_FPUSETUP
)
982 WARN("Unhandled flag DDSCL_FPUSETUP, harmless\n");
984 if (cooplevel
& DDSCL_EXCLUSIVE
)
985 exclusive_ddraw
= ddraw
;
986 else if (exclusive_ddraw
== ddraw
)
987 exclusive_ddraw
= NULL
;
989 /* Store the cooperative_level */
990 ddraw
->cooperative_level
= cooplevel
;
991 ddraw
->dest_window
= window
;
993 TRACE("SetCooperativeLevel retuning DD_OK\n");
994 wined3d_mutex_unlock();
999 static HRESULT WINAPI
ddraw7_SetCooperativeLevel(IDirectDraw7
*iface
, HWND window
, DWORD flags
)
1001 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1003 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1005 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1008 static HRESULT WINAPI
ddraw4_SetCooperativeLevel(IDirectDraw4
*iface
, HWND window
, DWORD flags
)
1010 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1012 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1014 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1017 static HRESULT WINAPI
ddraw2_SetCooperativeLevel(IDirectDraw2
*iface
, HWND window
, DWORD flags
)
1019 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1021 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1023 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1026 static HRESULT WINAPI
ddraw1_SetCooperativeLevel(IDirectDraw
*iface
, HWND window
, DWORD flags
)
1028 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1031 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1033 hr
= ddraw_set_cooperative_level(ddraw
, window
, flags
, FALSE
);
1035 ddraw
->flags
|= DDRAW_SCL_DDRAW1
;
1039 /*****************************************************************************
1040 * IDirectDraw7::SetDisplayMode
1042 * Sets the display screen resolution, color depth and refresh frequency
1043 * when in fullscreen mode (in theory).
1044 * Possible return values listed in the SDK suggest that this method fails
1045 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
1046 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
1047 * It seems to be valid to pass 0 for With and Height, this has to be tested
1048 * It could mean that the current video mode should be left as-is. (But why
1052 * Height, Width: Screen dimension
1053 * BPP: Color depth in Bits per pixel
1054 * Refreshrate: Screen refresh rate
1055 * Flags: Other stuff
1060 *****************************************************************************/
1061 static HRESULT WINAPI
ddraw7_SetDisplayMode(IDirectDraw7
*iface
, DWORD width
, DWORD height
,
1062 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1064 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1065 struct wined3d_display_mode mode
;
1066 enum wined3d_format_id format
;
1069 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1070 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1072 if (force_refresh_rate
!= 0)
1074 TRACE("ForceRefreshRate overriding passed-in refresh rate (%u Hz) to %u Hz\n",
1075 refresh_rate
, force_refresh_rate
);
1076 refresh_rate
= force_refresh_rate
;
1079 wined3d_mutex_lock();
1081 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
1083 wined3d_mutex_unlock();
1084 return DDERR_NOEXCLUSIVEMODE
;
1087 if (!width
|| !height
)
1089 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here. */
1090 wined3d_mutex_unlock();
1094 if (!restore_mode
&& FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
,
1095 WINED3DADAPTER_DEFAULT
, &original_mode
, NULL
)))
1096 ERR("Failed to get current display mode, hr %#x.\n", hr
);
1100 case 8: format
= WINED3DFMT_P8_UINT
; break;
1101 case 15: format
= WINED3DFMT_B5G5R5X1_UNORM
; break;
1102 case 16: format
= WINED3DFMT_B5G6R5_UNORM
; break;
1103 case 24: format
= WINED3DFMT_B8G8R8_UNORM
; break;
1104 case 32: format
= WINED3DFMT_B8G8R8X8_UNORM
; break;
1105 default: format
= WINED3DFMT_UNKNOWN
; break;
1109 mode
.height
= height
;
1110 mode
.refresh_rate
= refresh_rate
;
1111 mode
.format_id
= format
;
1112 mode
.scanline_ordering
= WINED3D_SCANLINE_ORDERING_UNKNOWN
;
1114 /* TODO: The possible return values from msdn suggest that the screen mode
1115 * can't be changed if a surface is locked or some drawing is in progress. */
1116 /* TODO: Lose the primary surface. */
1117 if (SUCCEEDED(hr
= wined3d_set_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
)))
1119 ddraw
->flags
|= DDRAW_RESTORE_MODE
;
1120 restore_mode
= TRUE
;
1123 wined3d_mutex_unlock();
1127 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1132 static HRESULT WINAPI
ddraw4_SetDisplayMode(IDirectDraw4
*iface
, DWORD width
, DWORD height
,
1133 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1135 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1137 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1138 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1140 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1143 static HRESULT WINAPI
ddraw2_SetDisplayMode(IDirectDraw2
*iface
,
1144 DWORD width
, DWORD height
, DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1146 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1148 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1149 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1151 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1154 static HRESULT WINAPI
ddraw1_SetDisplayMode(IDirectDraw
*iface
, DWORD width
, DWORD height
, DWORD bpp
)
1156 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1158 TRACE("iface %p, width %u, height %u, bpp %u.\n", iface
, width
, height
, bpp
);
1160 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, 0, 0);
1163 /*****************************************************************************
1164 * IDirectDraw7::GetCaps
1166 * Returns the drives capabilities
1168 * Used for version 1, 2, 4 and 7
1171 * DriverCaps: Structure to write the Hardware accelerated caps to
1172 * HelCaps: Structure to write the emulation caps to
1175 * This implementation returns DD_OK only
1177 *****************************************************************************/
1178 static HRESULT WINAPI
ddraw7_GetCaps(IDirectDraw7
*iface
, DDCAPS
*DriverCaps
, DDCAPS
*HELCaps
)
1180 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1182 WINED3DCAPS winecaps
;
1184 DDSCAPS2 ddscaps
= {0, 0, 0, 0};
1186 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, DriverCaps
, HELCaps
);
1188 /* One structure must be != NULL */
1189 if (!DriverCaps
&& !HELCaps
)
1191 WARN("Invalid parameters.\n");
1192 return DDERR_INVALIDPARAMS
;
1195 memset(&caps
, 0, sizeof(caps
));
1196 memset(&winecaps
, 0, sizeof(winecaps
));
1197 caps
.dwSize
= sizeof(caps
);
1199 wined3d_mutex_lock();
1200 hr
= wined3d_device_get_device_caps(ddraw
->wined3d_device
, &winecaps
);
1203 WARN("IWineD3DDevice::GetDeviceCaps failed\n");
1204 wined3d_mutex_unlock();
1208 hr
= IDirectDraw7_GetAvailableVidMem(iface
, &ddscaps
, &caps
.dwVidMemTotal
, &caps
.dwVidMemFree
);
1209 wined3d_mutex_unlock();
1211 WARN("IDirectDraw7::GetAvailableVidMem failed\n");
1215 caps
.dwCaps
= winecaps
.ddraw_caps
.caps
;
1216 caps
.dwCaps2
= winecaps
.ddraw_caps
.caps2
;
1217 caps
.dwCKeyCaps
= winecaps
.ddraw_caps
.color_key_caps
;
1218 caps
.dwFXCaps
= winecaps
.ddraw_caps
.fx_caps
;
1219 caps
.dwPalCaps
= winecaps
.ddraw_caps
.pal_caps
;
1220 caps
.ddsCaps
.dwCaps
= winecaps
.ddraw_caps
.dds_caps
;
1221 caps
.dwSVBCaps
= winecaps
.ddraw_caps
.svb_caps
;
1222 caps
.dwSVBCKeyCaps
= winecaps
.ddraw_caps
.svb_color_key_caps
;
1223 caps
.dwSVBFXCaps
= winecaps
.ddraw_caps
.svb_fx_caps
;
1224 caps
.dwVSBCaps
= winecaps
.ddraw_caps
.vsb_caps
;
1225 caps
.dwVSBCKeyCaps
= winecaps
.ddraw_caps
.vsb_color_key_caps
;
1226 caps
.dwVSBFXCaps
= winecaps
.ddraw_caps
.vsb_fx_caps
;
1227 caps
.dwSSBCaps
= winecaps
.ddraw_caps
.ssb_caps
;
1228 caps
.dwSSBCKeyCaps
= winecaps
.ddraw_caps
.ssb_color_key_caps
;
1229 caps
.dwSSBFXCaps
= winecaps
.ddraw_caps
.ssb_fx_caps
;
1231 if (winecaps
.ddraw_caps
.stride_align
)
1233 caps
.dwCaps
|= DDCAPS_ALIGNSTRIDE
;
1234 caps
.dwAlignStrideAlign
= winecaps
.ddraw_caps
.stride_align
;
1239 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &caps
);
1240 if (TRACE_ON(ddraw
))
1242 TRACE("Driver Caps :\n");
1243 DDRAW_dump_DDCAPS(DriverCaps
);
1249 DD_STRUCT_COPY_BYSIZE(HELCaps
, &caps
);
1250 if (TRACE_ON(ddraw
))
1252 TRACE("HEL Caps :\n");
1253 DDRAW_dump_DDCAPS(HELCaps
);
1260 static HRESULT WINAPI
ddraw4_GetCaps(IDirectDraw4
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1262 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1264 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1266 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1269 static HRESULT WINAPI
ddraw2_GetCaps(IDirectDraw2
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1271 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1273 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1275 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1278 static HRESULT WINAPI
ddraw1_GetCaps(IDirectDraw
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1280 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1282 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1284 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1287 /*****************************************************************************
1288 * IDirectDraw7::Compact
1290 * No idea what it does, MSDN says it's not implemented.
1293 * DD_OK, but this is unchecked
1295 *****************************************************************************/
1296 static HRESULT WINAPI
ddraw7_Compact(IDirectDraw7
*iface
)
1298 TRACE("iface %p.\n", iface
);
1303 static HRESULT WINAPI
ddraw4_Compact(IDirectDraw4
*iface
)
1305 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1307 TRACE("iface %p.\n", iface
);
1309 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1312 static HRESULT WINAPI
ddraw2_Compact(IDirectDraw2
*iface
)
1314 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1316 TRACE("iface %p.\n", iface
);
1318 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1321 static HRESULT WINAPI
ddraw1_Compact(IDirectDraw
*iface
)
1323 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1325 TRACE("iface %p.\n", iface
);
1327 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1330 /*****************************************************************************
1331 * IDirectDraw7::GetDisplayMode
1333 * Returns information about the current display mode
1335 * Exists in Version 1, 2, 4 and 7
1338 * DDSD: Address of a surface description structure to write the info to
1343 *****************************************************************************/
1344 static HRESULT WINAPI
ddraw7_GetDisplayMode(IDirectDraw7
*iface
, DDSURFACEDESC2
*DDSD
)
1346 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1347 struct wined3d_display_mode mode
;
1351 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
1353 wined3d_mutex_lock();
1354 /* This seems sane */
1357 wined3d_mutex_unlock();
1358 return DDERR_INVALIDPARAMS
;
1361 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1363 ERR("Failed to get display mode, hr %#x.\n", hr
);
1364 wined3d_mutex_unlock();
1368 Size
= DDSD
->dwSize
;
1369 memset(DDSD
, 0, Size
);
1371 DDSD
->dwSize
= Size
;
1372 DDSD
->dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
1373 DDSD
->dwWidth
= mode
.width
;
1374 DDSD
->dwHeight
= mode
.height
;
1375 DDSD
->u2
.dwRefreshRate
= 60;
1376 DDSD
->ddsCaps
.dwCaps
= 0;
1377 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
1378 ddrawformat_from_wined3dformat(&DDSD
->u4
.ddpfPixelFormat
, mode
.format_id
);
1379 DDSD
->u1
.lPitch
= mode
.width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
1383 TRACE("Returning surface desc :\n");
1384 DDRAW_dump_surface_desc(DDSD
);
1387 wined3d_mutex_unlock();
1392 static HRESULT WINAPI
ddraw4_GetDisplayMode(IDirectDraw4
*iface
, DDSURFACEDESC2
*surface_desc
)
1394 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1396 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1398 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, surface_desc
);
1401 static HRESULT WINAPI
ddraw2_GetDisplayMode(IDirectDraw2
*iface
, DDSURFACEDESC
*surface_desc
)
1403 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1405 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1407 /* FIXME: Test sizes, properly convert surface_desc */
1408 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1411 static HRESULT WINAPI
ddraw1_GetDisplayMode(IDirectDraw
*iface
, DDSURFACEDESC
*surface_desc
)
1413 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1415 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1417 /* FIXME: Test sizes, properly convert surface_desc */
1418 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1421 /*****************************************************************************
1422 * IDirectDraw7::GetFourCCCodes
1424 * Returns an array of supported FourCC codes.
1426 * Exists in Version 1, 2, 4 and 7
1429 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
1430 * of enumerated codes
1431 * Codes: Pointer to an array of DWORDs where the supported codes are written
1435 * Always returns DD_OK, as it's a stub for now
1437 *****************************************************************************/
1438 static HRESULT WINAPI
ddraw7_GetFourCCCodes(IDirectDraw7
*iface
, DWORD
*NumCodes
, DWORD
*Codes
)
1440 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1441 static const enum wined3d_format_id formats
[] =
1443 WINED3DFMT_YUY2
, WINED3DFMT_UYVY
, WINED3DFMT_YV12
,
1444 WINED3DFMT_DXT1
, WINED3DFMT_DXT2
, WINED3DFMT_DXT3
, WINED3DFMT_DXT4
, WINED3DFMT_DXT5
,
1445 WINED3DFMT_ATI2N
, WINED3DFMT_NVHU
, WINED3DFMT_NVHS
1447 struct wined3d_display_mode mode
;
1448 DWORD count
= 0, i
, outsize
;
1451 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, NumCodes
, Codes
);
1453 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1455 ERR("Failed to get display mode, hr %#x.\n", hr
);
1459 outsize
= NumCodes
&& Codes
? *NumCodes
: 0;
1461 for (i
= 0; i
< (sizeof(formats
) / sizeof(formats
[0])); ++i
)
1463 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, WINED3D_DEVICE_TYPE_HAL
,
1464 mode
.format_id
, 0, WINED3D_RTYPE_SURFACE
, formats
[i
])))
1466 if (count
< outsize
)
1467 Codes
[count
] = formats
[i
];
1472 TRACE("Returning %u FourCC codes\n", count
);
1479 static HRESULT WINAPI
ddraw4_GetFourCCCodes(IDirectDraw4
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1481 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1483 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1485 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1488 static HRESULT WINAPI
ddraw2_GetFourCCCodes(IDirectDraw2
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1490 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1492 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1494 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1497 static HRESULT WINAPI
ddraw1_GetFourCCCodes(IDirectDraw
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1499 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1501 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1503 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1506 static HRESULT WINAPI
ddraw7_GetMonitorFrequency(IDirectDraw7
*iface
, DWORD
*frequency
)
1508 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1509 struct wined3d_display_mode mode
;
1512 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1514 wined3d_mutex_lock();
1515 hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
);
1516 wined3d_mutex_unlock();
1519 WARN("Failed to get display mode, hr %#x.\n", hr
);
1523 *frequency
= mode
.refresh_rate
;
1528 static HRESULT WINAPI
ddraw4_GetMonitorFrequency(IDirectDraw4
*iface
, DWORD
*frequency
)
1530 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1532 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1534 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1537 static HRESULT WINAPI
ddraw2_GetMonitorFrequency(IDirectDraw2
*iface
, DWORD
*frequency
)
1539 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1541 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1543 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1546 static HRESULT WINAPI
ddraw1_GetMonitorFrequency(IDirectDraw
*iface
, DWORD
*frequency
)
1548 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1550 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1552 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1555 static HRESULT WINAPI
ddraw7_GetVerticalBlankStatus(IDirectDraw7
*iface
, BOOL
*status
)
1557 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1558 struct wined3d_raster_status raster_status
;
1561 TRACE("iface %p, status %p.\n", iface
, status
);
1564 return DDERR_INVALIDPARAMS
;
1566 wined3d_mutex_lock();
1567 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
1568 wined3d_mutex_unlock();
1571 WARN("Failed to get raster status, hr %#x.\n", hr
);
1575 *status
= raster_status
.in_vblank
;
1580 static HRESULT WINAPI
ddraw4_GetVerticalBlankStatus(IDirectDraw4
*iface
, BOOL
*status
)
1582 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1584 TRACE("iface %p, status %p.\n", iface
, status
);
1586 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1589 static HRESULT WINAPI
ddraw2_GetVerticalBlankStatus(IDirectDraw2
*iface
, BOOL
*status
)
1591 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1593 TRACE("iface %p, status %p.\n", iface
, status
);
1595 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1598 static HRESULT WINAPI
ddraw1_GetVerticalBlankStatus(IDirectDraw
*iface
, BOOL
*status
)
1600 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1602 TRACE("iface %p, status %p.\n", iface
, status
);
1604 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1607 /*****************************************************************************
1608 * IDirectDraw7::GetAvailableVidMem
1610 * Returns the total and free video memory
1613 * Caps: Specifies the memory type asked for
1614 * total: Pointer to a DWORD to be filled with the total memory
1615 * free: Pointer to a DWORD to be filled with the free memory
1619 * DDERR_INVALIDPARAMS of free and total are NULL
1621 *****************************************************************************/
1622 static HRESULT WINAPI
ddraw7_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*Caps
, DWORD
*total
,
1625 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1628 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, Caps
, total
, free
);
1630 if (TRACE_ON(ddraw
))
1632 TRACE("Asked for memory with description: ");
1633 DDRAW_dump_DDSCAPS2(Caps
);
1635 wined3d_mutex_lock();
1637 /* Todo: System memory vs local video memory vs non-local video memory
1638 * The MSDN also mentions differences between texture memory and other
1639 * resources, but that's not important
1642 if( (!total
) && (!free
) )
1644 wined3d_mutex_unlock();
1645 return DDERR_INVALIDPARAMS
;
1649 *free
= wined3d_device_get_available_texture_mem(ddraw
->wined3d_device
);
1652 struct wined3d_adapter_identifier desc
= {0};
1654 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0, &desc
);
1655 *total
= desc
.video_memory
;
1658 wined3d_mutex_unlock();
1663 static HRESULT WINAPI
ddraw4_GetAvailableVidMem(IDirectDraw4
*iface
,
1664 DDSCAPS2
*caps
, DWORD
*total
, DWORD
*free
)
1666 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1668 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1670 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, caps
, total
, free
);
1673 static HRESULT WINAPI
ddraw2_GetAvailableVidMem(IDirectDraw2
*iface
,
1674 DDSCAPS
*caps
, DWORD
*total
, DWORD
*free
)
1676 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1679 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1681 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
1682 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, &caps2
, total
, free
);
1685 /*****************************************************************************
1686 * IDirectDraw7::Initialize
1688 * Initializes a DirectDraw interface.
1691 * GUID: Interface identifier. Well, don't know what this is really good
1695 * Returns DD_OK on the first call,
1696 * DDERR_ALREADYINITIALIZED on repeated calls
1698 *****************************************************************************/
1699 static HRESULT WINAPI
ddraw7_Initialize(IDirectDraw7
*iface
, GUID
*guid
)
1701 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1703 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1705 if (ddraw
->flags
& DDRAW_INITIALIZED
)
1706 return DDERR_ALREADYINITIALIZED
;
1708 /* FIXME: To properly take the GUID into account we should call
1709 * ddraw_init() here instead of in DDRAW_Create(). */
1711 FIXME("Ignoring guid %s.\n", debugstr_guid(guid
));
1713 ddraw
->flags
|= DDRAW_INITIALIZED
;
1717 static HRESULT WINAPI
ddraw4_Initialize(IDirectDraw4
*iface
, GUID
*guid
)
1719 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1721 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1723 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
1726 static HRESULT WINAPI
ddraw2_Initialize(IDirectDraw2
*iface
, GUID
*guid
)
1728 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1730 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1732 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
1735 static HRESULT WINAPI
ddraw1_Initialize(IDirectDraw
*iface
, GUID
*guid
)
1737 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1739 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1741 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
1744 static HRESULT WINAPI
d3d1_Initialize(IDirect3D
*iface
, REFIID riid
)
1746 TRACE("iface %p, riid %s.\n", iface
, debugstr_guid(riid
));
1748 return DDERR_ALREADYINITIALIZED
;
1751 /*****************************************************************************
1752 * IDirectDraw7::FlipToGDISurface
1754 * "Makes the surface that the GDI writes to the primary surface"
1755 * Looks like some windows specific thing we don't have to care about.
1756 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
1757 * show error boxes ;)
1758 * Well, just return DD_OK.
1761 * Always returns DD_OK
1763 *****************************************************************************/
1764 static HRESULT WINAPI
ddraw7_FlipToGDISurface(IDirectDraw7
*iface
)
1766 FIXME("iface %p stub!\n", iface
);
1771 static HRESULT WINAPI
ddraw4_FlipToGDISurface(IDirectDraw4
*iface
)
1773 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1775 TRACE("iface %p.\n", iface
);
1777 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
1780 static HRESULT WINAPI
ddraw2_FlipToGDISurface(IDirectDraw2
*iface
)
1782 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1784 TRACE("iface %p.\n", iface
);
1786 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
1789 static HRESULT WINAPI
ddraw1_FlipToGDISurface(IDirectDraw
*iface
)
1791 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1793 TRACE("iface %p.\n", iface
);
1795 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
1798 /*****************************************************************************
1799 * IDirectDraw7::WaitForVerticalBlank
1801 * This method allows applications to get in sync with the vertical blank
1803 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
1804 * redraw the screen, most likely because of this stub
1807 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
1808 * or DDWAITVB_BLOCKEND
1809 * h: Not used, according to MSDN
1812 * Always returns DD_OK
1814 *****************************************************************************/
1815 static HRESULT WINAPI
ddraw7_WaitForVerticalBlank(IDirectDraw7
*iface
, DWORD Flags
, HANDLE event
)
1819 TRACE("iface %p, flags %#x, event %p.\n", iface
, Flags
, event
);
1821 /* This function is called often, so print the fixme only once */
1824 FIXME("iface %p, flags %#x, event %p stub!\n", iface
, Flags
, event
);
1828 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
1829 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
1830 return DDERR_UNSUPPORTED
; /* unchecked */
1835 static HRESULT WINAPI
ddraw4_WaitForVerticalBlank(IDirectDraw4
*iface
, DWORD flags
, HANDLE event
)
1837 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1839 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1841 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
1844 static HRESULT WINAPI
ddraw2_WaitForVerticalBlank(IDirectDraw2
*iface
, DWORD flags
, HANDLE event
)
1846 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1848 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1850 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
1853 static HRESULT WINAPI
ddraw1_WaitForVerticalBlank(IDirectDraw
*iface
, DWORD flags
, HANDLE event
)
1855 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1857 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1859 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
1862 static HRESULT WINAPI
ddraw7_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
1864 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1865 struct wined3d_raster_status raster_status
;
1868 TRACE("iface %p, line %p.\n", iface
, Scanline
);
1870 wined3d_mutex_lock();
1871 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
1872 wined3d_mutex_unlock();
1875 WARN("Failed to get raster status, hr %#x.\n", hr
);
1879 *Scanline
= raster_status
.scan_line
;
1881 if (raster_status
.in_vblank
)
1882 return DDERR_VERTICALBLANKINPROGRESS
;
1887 static HRESULT WINAPI
ddraw4_GetScanLine(IDirectDraw4
*iface
, DWORD
*line
)
1889 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1891 TRACE("iface %p, line %p.\n", iface
, line
);
1893 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
1896 static HRESULT WINAPI
ddraw2_GetScanLine(IDirectDraw2
*iface
, DWORD
*line
)
1898 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1900 TRACE("iface %p, line %p.\n", iface
, line
);
1902 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
1905 static HRESULT WINAPI
ddraw1_GetScanLine(IDirectDraw
*iface
, DWORD
*line
)
1907 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1909 TRACE("iface %p, line %p.\n", iface
, line
);
1911 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
1914 /*****************************************************************************
1915 * IDirectDraw7::TestCooperativeLevel
1917 * Informs the application about the state of the video adapter, depending
1918 * on the cooperative level
1921 * DD_OK if the device is in a sane state
1922 * DDERR_NOEXCLUSIVEMODE or DDERR_EXCLUSIVEMODEALREADYSET
1923 * if the state is not correct(See below)
1925 *****************************************************************************/
1926 static HRESULT WINAPI
ddraw7_TestCooperativeLevel(IDirectDraw7
*iface
)
1928 TRACE("iface %p.\n", iface
);
1933 static HRESULT WINAPI
ddraw4_TestCooperativeLevel(IDirectDraw4
*iface
)
1935 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1937 TRACE("iface %p.\n", iface
);
1939 return ddraw7_TestCooperativeLevel(&ddraw
->IDirectDraw7_iface
);
1942 /*****************************************************************************
1943 * IDirectDraw7::GetGDISurface
1945 * Returns the surface that GDI is treating as the primary surface.
1946 * For Wine this is the front buffer
1949 * GDISurface: Address to write the surface pointer to
1952 * DD_OK if the surface was found
1953 * DDERR_NOTFOUND if the GDI surface wasn't found
1955 *****************************************************************************/
1956 static HRESULT WINAPI
ddraw7_GetGDISurface(IDirectDraw7
*iface
, IDirectDrawSurface7
**GDISurface
)
1958 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1960 TRACE("iface %p, surface %p.\n", iface
, GDISurface
);
1962 wined3d_mutex_lock();
1964 if (!(*GDISurface
= &ddraw
->primary
->IDirectDrawSurface7_iface
))
1966 WARN("Primary not created yet.\n");
1967 wined3d_mutex_unlock();
1968 return DDERR_NOTFOUND
;
1970 IDirectDrawSurface7_AddRef(*GDISurface
);
1972 wined3d_mutex_unlock();
1977 static HRESULT WINAPI
ddraw4_GetGDISurface(IDirectDraw4
*iface
, IDirectDrawSurface4
**surface
)
1979 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1980 struct ddraw_surface
*surface_impl
;
1981 IDirectDrawSurface7
*surface7
;
1984 TRACE("iface %p, surface %p.\n", iface
, surface
);
1986 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
1992 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
1993 *surface
= &surface_impl
->IDirectDrawSurface4_iface
;
1994 IDirectDrawSurface4_AddRef(*surface
);
1995 IDirectDrawSurface7_Release(surface7
);
2000 static HRESULT WINAPI
ddraw2_GetGDISurface(IDirectDraw2
*iface
, IDirectDrawSurface
**surface
)
2002 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2003 struct ddraw_surface
*surface_impl
;
2004 IDirectDrawSurface7
*surface7
;
2007 TRACE("iface %p, surface %p.\n", iface
, surface
);
2009 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2015 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2016 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2017 IDirectDrawSurface_AddRef(*surface
);
2018 IDirectDrawSurface7_Release(surface7
);
2023 static HRESULT WINAPI
ddraw1_GetGDISurface(IDirectDraw
*iface
, IDirectDrawSurface
**surface
)
2025 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2026 struct ddraw_surface
*surface_impl
;
2027 IDirectDrawSurface7
*surface7
;
2030 TRACE("iface %p, surface %p.\n", iface
, surface
);
2032 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2038 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2039 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2040 IDirectDrawSurface_AddRef(*surface
);
2041 IDirectDrawSurface7_Release(surface7
);
2046 struct displaymodescallback_context
2048 LPDDENUMMODESCALLBACK func
;
2052 static HRESULT CALLBACK
EnumDisplayModesCallbackThunk(DDSURFACEDESC2
*surface_desc
, void *context
)
2054 struct displaymodescallback_context
*cbcontext
= context
;
2057 DDSD2_to_DDSD(surface_desc
, &desc
);
2058 return cbcontext
->func(&desc
, cbcontext
->context
);
2061 /*****************************************************************************
2062 * IDirectDraw7::EnumDisplayModes
2064 * Enumerates the supported Display modes. The modes can be filtered with
2065 * the DDSD parameter.
2068 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES. For old ddraw
2069 * versions (3 and older?) this is reserved and must be 0.
2070 * DDSD: Surface description to filter the modes
2071 * Context: Pointer passed back to the callback function
2072 * cb: Application-provided callback function
2076 * DDERR_INVALIDPARAMS if the callback wasn't set
2078 *****************************************************************************/
2079 static HRESULT WINAPI
ddraw7_EnumDisplayModes(IDirectDraw7
*iface
, DWORD Flags
,
2080 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMMODESCALLBACK2 cb
)
2082 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2083 struct wined3d_display_mode
*enum_modes
= NULL
;
2084 struct wined3d_display_mode mode
;
2085 unsigned int modenum
, fmt
;
2086 DDSURFACEDESC2 callback_sd
;
2087 unsigned enum_mode_count
= 0, enum_mode_array_size
= 16;
2088 DDPIXELFORMAT pixelformat
;
2090 static const enum wined3d_format_id checkFormatList
[] =
2092 WINED3DFMT_B8G8R8X8_UNORM
,
2093 WINED3DFMT_B5G6R5_UNORM
,
2097 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2098 iface
, Flags
, DDSD
, Context
, cb
);
2101 return DDERR_INVALIDPARAMS
;
2103 enum_modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(*enum_modes
) * enum_mode_array_size
);
2104 if (!enum_modes
) return DDERR_OUTOFMEMORY
;
2106 wined3d_mutex_lock();
2108 pixelformat
.dwSize
= sizeof(pixelformat
);
2109 for(fmt
= 0; fmt
< (sizeof(checkFormatList
) / sizeof(checkFormatList
[0])); fmt
++)
2112 while (wined3d_enum_adapter_modes(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, checkFormatList
[fmt
],
2113 WINED3D_SCANLINE_ORDERING_UNKNOWN
, modenum
++, &mode
) == WINED3D_OK
)
2118 ddrawformat_from_wined3dformat(&pixelformat
, mode
.format_id
);
2121 if (DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.width
!= DDSD
->dwWidth
)
2123 if (DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.height
!= DDSD
->dwHeight
)
2125 if (DDSD
->dwFlags
& DDSD_REFRESHRATE
&& mode
.refresh_rate
!= DDSD
->u2
.dwRefreshRate
)
2127 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
2128 && pixelformat
.u1
.dwRGBBitCount
!= DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
)
2132 /* DX docs state EnumDisplayMode should return only unique modes */
2133 for (i
= 0; i
< enum_mode_count
; i
++)
2135 if (enum_modes
[i
].width
== mode
.width
&& enum_modes
[i
].height
== mode
.height
2136 && enum_modes
[i
].format_id
== mode
.format_id
2137 && (enum_modes
[i
].refresh_rate
== mode
.refresh_rate
|| !(Flags
& DDEDM_REFRESHRATES
)))
2145 memset(&callback_sd
, 0, sizeof(callback_sd
));
2146 callback_sd
.dwSize
= sizeof(callback_sd
);
2147 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2149 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
|DDSD_REFRESHRATE
;
2150 if (Flags
& DDEDM_REFRESHRATES
)
2151 callback_sd
.u2
.dwRefreshRate
= mode
.refresh_rate
;
2153 callback_sd
.dwWidth
= mode
.width
;
2154 callback_sd
.dwHeight
= mode
.height
;
2156 callback_sd
.u4
.ddpfPixelFormat
=pixelformat
;
2158 /* Calc pitch and DWORD align like MSDN says */
2159 callback_sd
.u1
.lPitch
= (callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8) * mode
.width
;
2160 callback_sd
.u1
.lPitch
= (callback_sd
.u1
.lPitch
+ 3) & ~3;
2162 TRACE("Enumerating %dx%dx%d @%d\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
,
2163 callback_sd
.u2
.dwRefreshRate
);
2165 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
2167 TRACE("Application asked to terminate the enumeration\n");
2168 HeapFree(GetProcessHeap(), 0, enum_modes
);
2169 wined3d_mutex_unlock();
2173 if (enum_mode_count
== enum_mode_array_size
)
2175 struct wined3d_display_mode
*new_enum_modes
;
2177 enum_mode_array_size
*= 2;
2178 new_enum_modes
= HeapReAlloc(GetProcessHeap(), 0, enum_modes
,
2179 sizeof(*new_enum_modes
) * enum_mode_array_size
);
2180 if (!new_enum_modes
)
2182 HeapFree(GetProcessHeap(), 0, enum_modes
);
2183 wined3d_mutex_unlock();
2184 return DDERR_OUTOFMEMORY
;
2187 enum_modes
= new_enum_modes
;
2189 enum_modes
[enum_mode_count
++] = mode
;
2193 TRACE("End of enumeration\n");
2194 HeapFree(GetProcessHeap(), 0, enum_modes
);
2195 wined3d_mutex_unlock();
2200 static HRESULT WINAPI
ddraw4_EnumDisplayModes(IDirectDraw4
*iface
, DWORD flags
,
2201 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK2 callback
)
2203 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2205 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2206 iface
, flags
, surface_desc
, context
, callback
);
2208 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
, context
, callback
);
2211 static HRESULT WINAPI
ddraw2_EnumDisplayModes(IDirectDraw2
*iface
, DWORD flags
,
2212 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2214 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2215 struct displaymodescallback_context cbcontext
;
2216 DDSURFACEDESC2 surface_desc2
;
2218 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2219 iface
, flags
, surface_desc
, context
, callback
);
2221 cbcontext
.func
= callback
;
2222 cbcontext
.context
= context
;
2224 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2225 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2226 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2229 static HRESULT WINAPI
ddraw1_EnumDisplayModes(IDirectDraw
*iface
, DWORD flags
,
2230 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2232 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2233 struct displaymodescallback_context cbcontext
;
2234 DDSURFACEDESC2 surface_desc2
;
2236 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2237 iface
, flags
, surface_desc
, context
, callback
);
2239 cbcontext
.func
= callback
;
2240 cbcontext
.context
= context
;
2242 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2243 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2244 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2247 /*****************************************************************************
2248 * IDirectDraw7::EvaluateMode
2250 * Used with IDirectDraw7::StartModeTest to test video modes.
2251 * EvaluateMode is used to pass or fail a mode, and continue with the next
2255 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
2256 * Timeout: Returns the amount of seconds left before the mode would have
2257 * been failed automatically
2260 * This implementation always DD_OK, because it's a stub
2262 *****************************************************************************/
2263 static HRESULT WINAPI
ddraw7_EvaluateMode(IDirectDraw7
*iface
, DWORD Flags
, DWORD
*Timeout
)
2265 FIXME("iface %p, flags %#x, timeout %p stub!\n", iface
, Flags
, Timeout
);
2267 /* When implementing this, implement it in WineD3D */
2272 /*****************************************************************************
2273 * IDirectDraw7::GetDeviceIdentifier
2275 * Returns the device identifier, which gives information about the driver
2276 * Our device identifier is defined at the beginning of this file.
2279 * DDDI: Address for the returned structure
2280 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
2283 * On success it returns DD_OK
2284 * DDERR_INVALIDPARAMS if DDDI is NULL
2286 *****************************************************************************/
2287 static HRESULT WINAPI
ddraw7_GetDeviceIdentifier(IDirectDraw7
*iface
,
2288 DDDEVICEIDENTIFIER2
*DDDI
, DWORD Flags
)
2290 TRACE("iface %p, device_identifier %p, flags %#x.\n", iface
, DDDI
, Flags
);
2293 return DDERR_INVALIDPARAMS
;
2295 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
2296 * host adapter, if there's a secondary 3D adapter. This doesn't apply
2297 * to any modern hardware, nor is it interesting for Wine, so ignore it.
2298 * Size of DDDEVICEIDENTIFIER2 may be aligned to 8 bytes and thus 4
2299 * bytes too long. So only copy the relevant part of the structure
2302 memcpy(DDDI
, &deviceidentifier
, FIELD_OFFSET(DDDEVICEIDENTIFIER2
, dwWHQLLevel
) + sizeof(DWORD
));
2306 static HRESULT WINAPI
ddraw4_GetDeviceIdentifier(IDirectDraw4
*iface
,
2307 DDDEVICEIDENTIFIER
*identifier
, DWORD flags
)
2309 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2310 DDDEVICEIDENTIFIER2 identifier2
;
2313 TRACE("iface %p, identifier %p, flags %#x.\n", iface
, identifier
, flags
);
2315 hr
= ddraw7_GetDeviceIdentifier(&ddraw
->IDirectDraw7_iface
, &identifier2
, flags
);
2316 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&identifier2
, identifier
);
2321 /*****************************************************************************
2322 * IDirectDraw7::GetSurfaceFromDC
2324 * Returns the Surface for a GDI device context handle.
2325 * Is this related to IDirectDrawSurface::GetDC ???
2328 * hdc: hdc to return the surface for
2329 * Surface: Address to write the surface pointer to
2332 * Always returns DD_OK because it's a stub
2334 *****************************************************************************/
2335 static HRESULT WINAPI
ddraw7_GetSurfaceFromDC(IDirectDraw7
*iface
, HDC hdc
,
2336 IDirectDrawSurface7
**Surface
)
2338 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2339 struct wined3d_surface
*wined3d_surface
;
2340 struct ddraw_surface
*surface_impl
;
2342 TRACE("iface %p, dc %p, surface %p.\n", iface
, hdc
, Surface
);
2344 if (!Surface
) return E_INVALIDARG
;
2346 if (!(wined3d_surface
= wined3d_device_get_surface_from_dc(ddraw
->wined3d_device
, hdc
)))
2348 TRACE("No surface found for dc %p.\n", hdc
);
2350 return DDERR_NOTFOUND
;
2353 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
2354 *Surface
= &surface_impl
->IDirectDrawSurface7_iface
;
2355 IDirectDrawSurface7_AddRef(*Surface
);
2356 TRACE("Returning surface %p.\n", Surface
);
2360 static HRESULT WINAPI
ddraw4_GetSurfaceFromDC(IDirectDraw4
*iface
, HDC dc
,
2361 IDirectDrawSurface4
**surface
)
2363 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2364 struct ddraw_surface
*surface_impl
;
2365 IDirectDrawSurface7
*surface7
;
2368 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2370 if (!surface
) return E_INVALIDARG
;
2372 hr
= ddraw7_GetSurfaceFromDC(&ddraw
->IDirectDraw7_iface
, dc
, &surface7
);
2378 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2379 /* Tests say this is true */
2380 *surface
= (IDirectDrawSurface4
*)&surface_impl
->IDirectDrawSurface_iface
;
2381 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2382 IDirectDrawSurface7_Release(surface7
);
2387 /*****************************************************************************
2388 * IDirectDraw7::RestoreAllSurfaces
2390 * Calls the restore method of all surfaces
2395 * Always returns DD_OK because it's a stub
2397 *****************************************************************************/
2398 static HRESULT WINAPI
ddraw7_RestoreAllSurfaces(IDirectDraw7
*iface
)
2400 FIXME("iface %p stub!\n", iface
);
2402 /* This isn't hard to implement: Enumerate all WineD3D surfaces,
2403 * get their parent and call their restore method. Do not implement
2404 * it in WineD3D, as restoring a surface means re-creating the
2410 static HRESULT WINAPI
ddraw4_RestoreAllSurfaces(IDirectDraw4
*iface
)
2412 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2414 TRACE("iface %p.\n", iface
);
2416 return ddraw7_RestoreAllSurfaces(&ddraw
->IDirectDraw7_iface
);
2419 /*****************************************************************************
2420 * IDirectDraw7::StartModeTest
2422 * Tests the specified video modes to update the system registry with
2423 * refresh rate information. StartModeTest starts the mode test,
2424 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
2425 * isn't called within 15 seconds, the mode is failed automatically
2427 * As refresh rates are handled by the X server, I don't think this
2428 * Method is important
2431 * Modes: An array of mode specifications
2432 * NumModes: The number of modes in Modes
2433 * Flags: Some flags...
2436 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
2437 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
2440 *****************************************************************************/
2441 static HRESULT WINAPI
ddraw7_StartModeTest(IDirectDraw7
*iface
, SIZE
*Modes
, DWORD NumModes
, DWORD Flags
)
2443 FIXME("iface %p, modes %p, mode_count %u, flags %#x partial stub!\n",
2444 iface
, Modes
, NumModes
, Flags
);
2446 /* This looks sane */
2447 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
2449 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
2450 * As it is not, DDERR_TESTFINISHED is returned
2451 * (hopefully that's correct
2453 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
2454 * well, that value doesn't (yet) exist in the wine headers, so ignore it
2460 /*****************************************************************************
2461 * ddraw_create_surface
2463 * A helper function for IDirectDraw7::CreateSurface. It creates a new surface
2464 * with the passed parameters.
2467 * DDSD: Description of the surface to create
2468 * Surf: Address to store the interface pointer at
2473 *****************************************************************************/
2474 static HRESULT
ddraw_create_surface(struct ddraw
*ddraw
, DDSURFACEDESC2
*desc
,
2475 DWORD flags
, struct ddraw_surface
**surface
, UINT version
)
2479 TRACE("ddraw %p, desc %p, flags %#x, surface %p.\n", ddraw
, desc
, flags
, surface
);
2481 if (TRACE_ON(ddraw
))
2483 TRACE("Requesting surface desc:\n");
2484 DDRAW_dump_surface_desc(desc
);
2487 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) && (ddraw
->flags
& DDRAW_NO3D
))
2489 WARN("The application requests a 3D capable surface, but the ddraw object was created without 3D support.\n");
2490 /* Do not fail surface creation, only fail 3D device creation. */
2493 /* Create the Surface object */
2494 *surface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(**surface
));
2497 ERR("Failed to allocate surface memory.\n");
2498 return DDERR_OUTOFVIDEOMEMORY
;
2501 if (FAILED(hr
= ddraw_surface_init(*surface
, ddraw
, desc
, flags
, version
)))
2503 WARN("Failed to initialize surface, hr %#x.\n", hr
);
2504 HeapFree(GetProcessHeap(), 0, *surface
);
2508 /* Increase the surface counter, and attach the surface */
2509 list_add_head(&ddraw
->surface_list
, &(*surface
)->surface_list_entry
);
2511 TRACE("Created surface %p.\n", *surface
);
2516 static HRESULT CDECL
ddraw_reset_enum_callback(struct wined3d_resource
*resource
)
2521 /*****************************************************************************
2522 * IDirectDraw7::CreateSurface
2524 * Creates a new IDirectDrawSurface object and returns its interface.
2526 * The surface connections with wined3d are a bit tricky. Basically it works
2529 * |------------------------| |-----------------|
2530 * | DDraw surface | | WineD3DSurface |
2532 * | WineD3DSurface |-------------->| |
2533 * | Child |<------------->| Parent |
2534 * |------------------------| |-----------------|
2536 * The DDraw surface is the parent of the wined3d surface, and it releases
2537 * the WineD3DSurface when the ddraw surface is destroyed.
2539 * However, for all surfaces which can be in a container in WineD3D,
2540 * we have to do this. These surfaces are usually complex surfaces,
2541 * so this concerns primary surfaces with a front and a back buffer,
2544 * |------------------------| |-----------------|
2545 * | DDraw surface | | Container |
2547 * | Child |<------------->| Parent |
2548 * | Texture |<------------->| |
2549 * | WineD3DSurface |<----| | Levels |<--|
2550 * | Complex connection | | | | |
2551 * |------------------------| | |-----------------| |
2555 * | |------------------| | |-----------------| |
2556 * | | IParent | |-------->| WineD3DSurface | |
2558 * | | Child |<------------->| Parent | |
2559 * | | | | Container |<--|
2560 * | |------------------| |-----------------| |
2562 * | |----------------------| |
2563 * | | DDraw surface 2 | |
2565 * |<->| Complex root Child | |
2567 * | | WineD3DSurface |<----| |
2568 * | |----------------------| | |
2570 * | |---------------------| | |-----------------| |
2571 * | | IParent | |----->| WineD3DSurface | |
2573 * | | Child |<---------->| Parent | |
2574 * | |---------------------| | Container |<--|
2575 * | |-----------------| |
2577 * | ---More surfaces can follow--- |
2579 * The reason is that the IWineD3DSwapchain(render target container)
2580 * and the IWineD3DTexure(Texture container) release the parents
2581 * of their surface's children, but by releasing the complex root
2582 * the surfaces which are complexly attached to it are destroyed
2583 * too. See IDirectDrawSurface::Release for a more detailed
2587 * DDSD: Description of the surface to create
2588 * Surf: Address to store the interface pointer at
2589 * UnkOuter: Basically for aggregation support, but ddraw doesn't support
2590 * aggregation, so it has to be NULL
2594 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
2595 * DDERR_* if an error occurs
2597 *****************************************************************************/
2598 static HRESULT
CreateSurface(struct ddraw
*ddraw
, DDSURFACEDESC2
*DDSD
,
2599 struct ddraw_surface
**surface
, IUnknown
*UnkOuter
, UINT version
)
2601 struct ddraw_surface
*object
= NULL
;
2602 struct wined3d_display_mode mode
;
2604 DDSURFACEDESC2 desc2
;
2605 const DWORD sysvidmem
= DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
2606 /* Some applications assume surfaces will always be mapped at the same
2607 * address. Some of those also assume that this address is valid even when
2608 * the surface isn't mapped, and that updates done this way will be
2609 * visible on the screen. The game Nox is such an application,
2610 * Commandos: Behind Enemy Lines is another. */
2611 const DWORD flags
= WINED3D_SURFACE_MAPPABLE
| WINED3D_SURFACE_PIN_SYSMEM
;
2613 TRACE("ddraw %p, surface_desc %p, surface %p, outer_unknown %p.\n", ddraw
, DDSD
, surface
, UnkOuter
);
2615 /* Some checks before we start */
2616 if (TRACE_ON(ddraw
))
2618 TRACE(" (%p) Requesting surface desc :\n", ddraw
);
2619 DDRAW_dump_surface_desc(DDSD
);
2622 if (UnkOuter
!= NULL
)
2624 FIXME("(%p) : outer != NULL?\n", ddraw
);
2625 return CLASS_E_NOAGGREGATION
; /* unchecked */
2630 FIXME("(%p) You want to get back a surface? Don't give NULL ptrs!\n", ddraw
);
2631 return E_POINTER
; /* unchecked */
2634 if (!(DDSD
->dwFlags
& DDSD_CAPS
))
2636 /* DVIDEO.DLL does forget the DDSD_CAPS flag ... *sigh* */
2637 DDSD
->dwFlags
|= DDSD_CAPS
;
2640 if (DDSD
->ddsCaps
.dwCaps
& DDSCAPS_ALLOCONLOAD
)
2642 /* If the surface is of the 'alloconload' type, ignore the LPSURFACE field */
2643 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2646 if ((DDSD
->dwFlags
& DDSD_LPSURFACE
) && (DDSD
->lpSurface
== NULL
))
2648 /* Frank Herbert's Dune specifies a null pointer for the surface, ignore the LPSURFACE field */
2649 WARN("(%p) Null surface pointer specified, ignore it!\n", ddraw
);
2650 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2653 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
) &&
2654 !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
2656 TRACE("(%p): Attempt to create a flipable primary surface without DDSCL_EXCLUSIVE set\n",
2659 return DDERR_NOEXCLUSIVEMODE
;
2662 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_BACKBUFFER
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_BACKBUFFER
| DDSCAPS_PRIMARYSURFACE
))
2664 WARN("Application wanted to create back buffer primary surface\n");
2665 return DDERR_INVALIDCAPS
;
2668 if((DDSD
->ddsCaps
.dwCaps
& sysvidmem
) == sysvidmem
)
2670 /* This is a special switch in ddrawex.dll, but not allowed in ddraw.dll */
2671 WARN("Application tries to put the surface in both system and video memory\n");
2673 return DDERR_INVALIDCAPS
;
2676 /* Check cube maps but only if the size includes them */
2677 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2679 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
&&
2680 !(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
2682 WARN("Cube map faces requested without cube map flag\n");
2683 return DDERR_INVALIDCAPS
;
2685 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2686 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) == 0)
2688 WARN("Cube map without faces requested\n");
2689 return DDERR_INVALIDPARAMS
;
2692 /* Quick tests confirm those can be created, but we don't do that yet */
2693 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2694 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
2696 FIXME("Partial cube maps not supported yet\n");
2700 /* According to the msdn this flag is ignored by CreateSurface */
2701 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2702 DDSD
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2704 /* Modify some flags */
2705 copy_to_surfacedesc2(&desc2
, DDSD
);
2706 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
); /* Just to be sure */
2708 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
2710 ERR("Failed to get display mode, hr %#x.\n", hr
);
2714 /* No pixelformat given? Use the current screen format */
2715 if(!(desc2
.dwFlags
& DDSD_PIXELFORMAT
))
2717 desc2
.dwFlags
|= DDSD_PIXELFORMAT
;
2718 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
);
2720 ddrawformat_from_wined3dformat(&desc2
.u4
.ddpfPixelFormat
, mode
.format_id
);
2723 /* No Width or no Height? Use the original screen size
2725 if(!(desc2
.dwFlags
& DDSD_WIDTH
) ||
2726 !(desc2
.dwFlags
& DDSD_HEIGHT
) )
2728 /* Invalid for non-render targets */
2729 if(!(desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
2731 WARN("Creating a non-Primary surface without Width or Height info, returning DDERR_INVALIDPARAMS\n");
2733 return DDERR_INVALIDPARAMS
;
2736 desc2
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
2737 desc2
.dwWidth
= mode
.width
;
2738 desc2
.dwHeight
= mode
.height
;
2741 if (!desc2
.dwWidth
|| !desc2
.dwHeight
)
2742 return DDERR_INVALIDPARAMS
;
2744 /* Mipmap count fixes */
2745 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
2747 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
2749 if(desc2
.dwFlags
& DDSD_MIPMAPCOUNT
)
2751 /* Mipmap count is given, should not be 0 */
2752 if( desc2
.u2
.dwMipMapCount
== 0 )
2753 return DDERR_INVALIDPARAMS
;
2757 /* Undocumented feature: Create sublevels until
2758 * either the width or the height is 1
2760 DWORD min
= desc2
.dwWidth
< desc2
.dwHeight
?
2761 desc2
.dwWidth
: desc2
.dwHeight
;
2762 desc2
.u2
.dwMipMapCount
= 0;
2765 desc2
.u2
.dwMipMapCount
+= 1;
2772 /* Not-complex mipmap -> Mipmapcount = 1 */
2773 desc2
.u2
.dwMipMapCount
= 1;
2776 /* There's a mipmap count in the created surface in any case */
2777 desc2
.dwFlags
|= DDSD_MIPMAPCOUNT
;
2779 /* If no mipmap is given, the texture has only one level */
2781 /* The first surface is a front buffer, the back buffer is created afterwards */
2782 if( (desc2
.dwFlags
& DDSD_CAPS
) && (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) )
2784 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
2787 /* The root surface in a cube map is positive x */
2788 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
2790 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
2791 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
2794 if ((desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) && (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
2796 struct wined3d_swapchain_desc swapchain_desc
;
2798 wined3d_swapchain_get_desc(ddraw
->wined3d_swapchain
, &swapchain_desc
);
2799 swapchain_desc
.backbuffer_width
= mode
.width
;
2800 swapchain_desc
.backbuffer_height
= mode
.height
;
2801 swapchain_desc
.backbuffer_format
= mode
.format_id
;
2803 hr
= wined3d_device_reset(ddraw
->wined3d_device
,
2804 &swapchain_desc
, NULL
, ddraw_reset_enum_callback
, TRUE
);
2807 ERR("Failed to reset device.\n");
2812 /* Create the first surface */
2813 if (FAILED(hr
= ddraw_create_surface(ddraw
, &desc2
, flags
, &object
, version
)))
2815 WARN("ddraw_create_surface failed, hr %#x.\n", hr
);
2818 object
->is_complex_root
= TRUE
;
2822 /* Create Additional surfaces if necessary
2823 * This applies to Primary surfaces which have a back buffer count
2824 * set, but not to mipmap textures. In case of Mipmap textures,
2825 * wineD3D takes care of the creation of additional surfaces
2827 if(DDSD
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
2829 struct ddraw_surface
*last
= object
;
2832 desc2
.ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
; /* It's not a front buffer */
2833 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
2834 desc2
.dwBackBufferCount
= 0;
2836 for (i
= 0; i
< DDSD
->dwBackBufferCount
; ++i
)
2838 struct ddraw_surface
*object2
= NULL
;
2840 if (FAILED(hr
= ddraw_create_surface(ddraw
, &desc2
, flags
, &object2
, version
)))
2843 IDirectDrawSurface7_Release(&object
->IDirectDrawSurface7_iface
);
2844 else if (version
== 4)
2845 IDirectDrawSurface4_Release(&object
->IDirectDrawSurface4_iface
);
2847 IDirectDrawSurface_Release(&object
->IDirectDrawSurface_iface
);
2852 /* Add the new surface to the complex attachment array. */
2853 last
->complex_array
[0] = object2
;
2856 /* Remove the (possible) back buffer cap from the new surface
2857 * description, because only one surface in the flipping chain is a
2858 * back buffer, one is a front buffer, the others are just primary
2860 desc2
.ddsCaps
.dwCaps
&= ~DDSCAPS_BACKBUFFER
;
2864 if (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2865 ddraw
->primary
= object
;
2867 /* Create a WineD3DTexture if a texture was requested */
2868 if (desc2
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
2869 ddraw_surface_create_texture(object
, flags
);
2874 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
, DDSURFACEDESC2
*surface_desc
,
2875 IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
2877 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2878 struct ddraw_surface
*impl
;
2881 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2882 iface
, surface_desc
, surface
, outer_unknown
);
2884 wined3d_mutex_lock();
2886 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2888 WARN("Cooperative level not set.\n");
2889 wined3d_mutex_unlock();
2890 return DDERR_NOCOOPERATIVELEVELSET
;
2893 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2895 WARN("Application supplied invalid surface descriptor\n");
2896 wined3d_mutex_unlock();
2897 return DDERR_INVALIDPARAMS
;
2900 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2902 if (TRACE_ON(ddraw
))
2904 TRACE(" (%p) Requesting surface desc :\n", iface
);
2905 DDRAW_dump_surface_desc(surface_desc
);
2908 WARN("Application tried to create an explicit front or back buffer\n");
2909 wined3d_mutex_unlock();
2910 return DDERR_INVALIDCAPS
;
2913 hr
= CreateSurface(ddraw
, surface_desc
, &impl
, outer_unknown
, 7);
2914 wined3d_mutex_unlock();
2921 *surface
= &impl
->IDirectDrawSurface7_iface
;
2922 IDirectDraw7_AddRef(iface
);
2923 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2928 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
2929 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
2931 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2932 struct ddraw_surface
*impl
;
2935 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2936 iface
, surface_desc
, surface
, outer_unknown
);
2938 wined3d_mutex_lock();
2940 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2942 WARN("Cooperative level not set.\n");
2943 wined3d_mutex_unlock();
2944 return DDERR_NOCOOPERATIVELEVELSET
;
2947 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2949 WARN("Application supplied invalid surface descriptor\n");
2950 wined3d_mutex_unlock();
2951 return DDERR_INVALIDPARAMS
;
2954 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2956 if (TRACE_ON(ddraw
))
2958 TRACE(" (%p) Requesting surface desc :\n", iface
);
2959 DDRAW_dump_surface_desc(surface_desc
);
2962 WARN("Application tried to create an explicit front or back buffer\n");
2963 wined3d_mutex_unlock();
2964 return DDERR_INVALIDCAPS
;
2967 hr
= CreateSurface(ddraw
, surface_desc
, &impl
, outer_unknown
, 4);
2968 wined3d_mutex_unlock();
2975 *surface
= &impl
->IDirectDrawSurface4_iface
;
2976 IDirectDraw4_AddRef(iface
);
2977 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2982 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
2983 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2985 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2986 struct ddraw_surface
*impl
;
2988 DDSURFACEDESC2 surface_desc2
;
2990 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2991 iface
, surface_desc
, surface
, outer_unknown
);
2993 wined3d_mutex_lock();
2995 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2997 WARN("Cooperative level not set.\n");
2998 wined3d_mutex_unlock();
2999 return DDERR_NOCOOPERATIVELEVELSET
;
3002 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3004 WARN("Application supplied invalid surface descriptor\n");
3005 wined3d_mutex_unlock();
3006 return DDERR_INVALIDPARAMS
;
3009 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3010 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3012 if (TRACE_ON(ddraw
))
3014 TRACE(" (%p) Requesting surface desc :\n", iface
);
3015 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
3018 WARN("Application tried to create an explicit front or back buffer\n");
3019 wined3d_mutex_unlock();
3020 return DDERR_INVALIDCAPS
;
3023 hr
= CreateSurface(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 2);
3024 wined3d_mutex_unlock();
3031 *surface
= &impl
->IDirectDrawSurface_iface
;
3032 impl
->ifaceToRelease
= NULL
;
3037 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
3038 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3040 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3041 struct ddraw_surface
*impl
;
3043 DDSURFACEDESC2 surface_desc2
;
3045 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3046 iface
, surface_desc
, surface
, outer_unknown
);
3048 wined3d_mutex_lock();
3050 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
3052 WARN("Cooperative level not set.\n");
3053 wined3d_mutex_unlock();
3054 return DDERR_NOCOOPERATIVELEVELSET
;
3057 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3059 WARN("Application supplied invalid surface descriptor\n");
3060 wined3d_mutex_unlock();
3061 return DDERR_INVALIDPARAMS
;
3064 /* Remove front buffer flag, this causes failure in v7, and its added to normal
3065 * primaries anyway. */
3066 surface_desc
->ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
;
3067 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3068 hr
= CreateSurface(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 1);
3069 wined3d_mutex_unlock();
3076 *surface
= &impl
->IDirectDrawSurface_iface
;
3077 impl
->ifaceToRelease
= NULL
;
3082 #define DDENUMSURFACES_SEARCHTYPE (DDENUMSURFACES_CANBECREATED|DDENUMSURFACES_DOESEXIST)
3083 #define DDENUMSURFACES_MATCHTYPE (DDENUMSURFACES_ALL|DDENUMSURFACES_MATCH|DDENUMSURFACES_NOMATCH)
3086 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
3087 const DDPIXELFORMAT
*provided
)
3089 /* Some flags must be present in both or neither for a match. */
3090 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
3091 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
3092 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
3094 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3097 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
3100 if (requested
->dwFlags
& DDPF_FOURCC
)
3101 if (requested
->dwFourCC
!= provided
->dwFourCC
)
3104 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
3105 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3106 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
3109 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3110 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3111 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
3114 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
3115 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
3118 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
3119 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3121 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
3124 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
3125 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
3131 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3140 #define CMP(FLAG, FIELD) \
3141 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3142 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3144 static const struct compare_info compare
[] =
3146 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3147 CMP(BACKBUFFERCOUNT
, dwBackBufferCount
),
3149 CMP(CKDESTBLT
, ddckCKDestBlt
),
3150 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3151 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3152 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3153 CMP(HEIGHT
, dwHeight
),
3154 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3155 CMP(LPSURFACE
, lpSurface
),
3156 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3157 CMP(PITCH
, u1
/* lPitch */),
3158 /* PIXELFORMAT: manual */
3159 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3160 CMP(TEXTURESTAGE
, dwTextureStage
),
3161 CMP(WIDTH
, dwWidth
),
3162 /* ZBUFFERBITDEPTH: "obsolete" */
3169 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3172 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
3174 if (requested
->dwFlags
& compare
[i
].flag
3175 && memcmp((const char *)provided
+ compare
[i
].offset
,
3176 (const char *)requested
+ compare
[i
].offset
,
3177 compare
[i
].size
) != 0)
3181 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3183 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3184 &provided
->u4
.ddpfPixelFormat
))
3191 #undef DDENUMSURFACES_SEARCHTYPE
3192 #undef DDENUMSURFACES_MATCHTYPE
3194 struct surfacescallback2_context
3196 LPDDENUMSURFACESCALLBACK2 func
;
3200 struct surfacescallback_context
3202 LPDDENUMSURFACESCALLBACK func
;
3206 static HRESULT CALLBACK
EnumSurfacesCallback2Thunk(IDirectDrawSurface7
*surface
,
3207 DDSURFACEDESC2
*surface_desc
, void *context
)
3209 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3210 struct surfacescallback2_context
*cbcontext
= context
;
3212 IDirectDrawSurface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
3213 IDirectDrawSurface7_Release(surface
);
3215 return cbcontext
->func(&surface_impl
->IDirectDrawSurface4_iface
,
3216 surface_desc
, cbcontext
->context
);
3219 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3220 DDSURFACEDESC2
*surface_desc
, void *context
)
3222 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3223 struct surfacescallback_context
*cbcontext
= context
;
3225 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
3226 IDirectDrawSurface7_Release(surface
);
3228 return cbcontext
->func(&surface_impl
->IDirectDrawSurface_iface
,
3229 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3232 /*****************************************************************************
3233 * IDirectDraw7::EnumSurfaces
3235 * Loops through all surfaces attached to this device and calls the
3236 * application callback. This can't be relayed to WineD3DDevice,
3237 * because some WineD3DSurfaces' parents are IParent objects
3240 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3241 * DDSD: Description to filter for
3242 * Context: Application-provided pointer, it's passed unmodified to the
3244 * Callback: Address to call for each surface
3247 * DDERR_INVALIDPARAMS if the callback is NULL
3250 *****************************************************************************/
3251 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD Flags
,
3252 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMSURFACESCALLBACK7 Callback
)
3254 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3255 struct ddraw_surface
*surf
;
3257 DDSURFACEDESC2 desc
;
3258 struct list
*entry
, *entry2
;
3260 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3261 iface
, Flags
, DDSD
, Context
, Callback
);
3263 all
= Flags
& DDENUMSURFACES_ALL
;
3264 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
3267 return DDERR_INVALIDPARAMS
;
3269 wined3d_mutex_lock();
3271 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
3272 LIST_FOR_EACH_SAFE(entry
, entry2
, &ddraw
->surface_list
)
3274 surf
= LIST_ENTRY(entry
, struct ddraw_surface
, surface_list_entry
);
3276 if (!surf
->iface_count
)
3278 WARN("Not enumerating surface %p because it doesn't have any references.\n", surf
);
3282 if (all
|| (nomatch
!= ddraw_match_surface_desc(DDSD
, &surf
->surface_desc
)))
3284 TRACE("Enumerating surface %p.\n", surf
);
3285 desc
= surf
->surface_desc
;
3286 IDirectDrawSurface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
3287 if (Callback(&surf
->IDirectDrawSurface7_iface
, &desc
, Context
) != DDENUMRET_OK
)
3289 wined3d_mutex_unlock();
3295 wined3d_mutex_unlock();
3300 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3301 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3303 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3304 struct surfacescallback2_context cbcontext
;
3306 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3307 iface
, flags
, surface_desc
, context
, callback
);
3309 cbcontext
.func
= callback
;
3310 cbcontext
.context
= context
;
3312 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
,
3313 &cbcontext
, EnumSurfacesCallback2Thunk
);
3316 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3317 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3319 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3320 struct surfacescallback_context cbcontext
;
3321 DDSURFACEDESC2 surface_desc2
;
3323 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3324 iface
, flags
, surface_desc
, context
, callback
);
3326 cbcontext
.func
= callback
;
3327 cbcontext
.context
= context
;
3329 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3330 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3331 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3334 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3335 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3337 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3338 struct surfacescallback_context cbcontext
;
3339 DDSURFACEDESC2 surface_desc2
;
3341 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3342 iface
, flags
, surface_desc
, context
, callback
);
3344 cbcontext
.func
= callback
;
3345 cbcontext
.context
= context
;
3347 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3348 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3349 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3352 /*****************************************************************************
3353 * DirectDrawCreateClipper (DDRAW.@)
3355 * Creates a new IDirectDrawClipper object.
3358 * Clipper: Address to write the interface pointer to
3359 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3363 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3364 * E_OUTOFMEMORY if allocating the object failed
3366 *****************************************************************************/
3367 HRESULT WINAPI
DirectDrawCreateClipper(DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3369 struct ddraw_clipper
*object
;
3372 TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
3373 flags
, clipper
, outer_unknown
);
3376 return CLASS_E_NOAGGREGATION
;
3378 wined3d_mutex_lock();
3380 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3383 wined3d_mutex_unlock();
3384 return E_OUTOFMEMORY
;
3387 hr
= ddraw_clipper_init(object
);
3390 WARN("Failed to initialize clipper, hr %#x.\n", hr
);
3391 HeapFree(GetProcessHeap(), 0, object
);
3392 wined3d_mutex_unlock();
3396 TRACE("Created clipper %p.\n", object
);
3397 *clipper
= &object
->IDirectDrawClipper_iface
;
3398 wined3d_mutex_unlock();
3403 /*****************************************************************************
3404 * IDirectDraw7::CreateClipper
3406 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3408 *****************************************************************************/
3409 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3410 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3412 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3413 iface
, Flags
, Clipper
, UnkOuter
);
3415 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3418 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
, DWORD flags
,
3419 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3421 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3423 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3424 iface
, flags
, clipper
, outer_unknown
);
3426 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3429 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
3430 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3432 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3434 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3435 iface
, flags
, clipper
, outer_unknown
);
3437 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3440 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
3441 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3443 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3445 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3446 iface
, flags
, clipper
, outer_unknown
);
3448 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3451 /*****************************************************************************
3452 * IDirectDraw7::CreatePalette
3454 * Creates a new IDirectDrawPalette object
3457 * Flags: The flags for the new clipper
3458 * ColorTable: Color table to assign to the new clipper
3459 * Palette: Address to write the interface pointer to
3460 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3464 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3465 * E_OUTOFMEMORY if allocating the object failed
3467 *****************************************************************************/
3468 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
3469 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
3471 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3472 struct ddraw_palette
*object
;
3475 TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
3476 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3479 return CLASS_E_NOAGGREGATION
;
3481 wined3d_mutex_lock();
3483 /* The refcount test shows that a cooplevel is required for this */
3484 if (!ddraw
->cooperative_level
)
3486 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3487 wined3d_mutex_unlock();
3488 return DDERR_NOCOOPERATIVELEVELSET
;
3491 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(*object
));
3494 ERR("Out of memory when allocating memory for a palette implementation\n");
3495 wined3d_mutex_unlock();
3496 return E_OUTOFMEMORY
;
3499 hr
= ddraw_palette_init(object
, ddraw
, Flags
, ColorTable
);
3502 WARN("Failed to initialize palette, hr %#x.\n", hr
);
3503 HeapFree(GetProcessHeap(), 0, object
);
3504 wined3d_mutex_unlock();
3508 TRACE("Created palette %p.\n", object
);
3509 *Palette
= &object
->IDirectDrawPalette_iface
;
3510 wined3d_mutex_unlock();
3515 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
, PALETTEENTRY
*entries
,
3516 IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3518 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3521 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3522 iface
, flags
, entries
, palette
, outer_unknown
);
3524 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3525 if (SUCCEEDED(hr
) && *palette
)
3527 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3528 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3529 IDirectDraw4_AddRef(iface
);
3530 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3535 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
3536 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3538 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3541 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3542 iface
, flags
, entries
, palette
, outer_unknown
);
3544 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3545 if (SUCCEEDED(hr
) && *palette
)
3547 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3548 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3549 impl
->ifaceToRelease
= NULL
;
3555 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
3556 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3558 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3561 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3562 iface
, flags
, entries
, palette
, outer_unknown
);
3564 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3565 if (SUCCEEDED(hr
) && *palette
)
3567 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3568 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3569 impl
->ifaceToRelease
= NULL
;
3575 /*****************************************************************************
3576 * IDirectDraw7::DuplicateSurface
3578 * Duplicates a surface. The surface memory points to the same memory as
3579 * the original surface, and it's released when the last surface referencing
3580 * it is released. I guess that's beyond Wine's surface management right now
3581 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3582 * test application to implement this)
3585 * Src: Address of the source surface
3586 * Dest: Address to write the new surface pointer to
3589 * See IDirectDraw7::CreateSurface
3591 *****************************************************************************/
3592 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
3593 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
3595 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(Src
);
3597 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
3599 /* For now, simply create a new, independent surface */
3600 return IDirectDraw7_CreateSurface(iface
, &src_surface
->surface_desc
, Dest
, NULL
);
3603 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
, IDirectDrawSurface4
*src
,
3604 IDirectDrawSurface4
**dst
)
3606 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
3607 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3608 struct ddraw_surface
*dst_impl
;
3609 IDirectDrawSurface7
*dst7
;
3612 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3614 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3615 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3621 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3622 *dst
= &dst_impl
->IDirectDrawSurface4_iface
;
3623 IDirectDrawSurface4_AddRef(*dst
);
3624 IDirectDrawSurface7_Release(dst7
);
3629 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
3630 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
3632 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3633 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3634 struct ddraw_surface
*dst_impl
;
3635 IDirectDrawSurface7
*dst7
;
3638 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3640 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3641 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3644 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3645 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3646 IDirectDrawSurface_AddRef(*dst
);
3647 IDirectDrawSurface7_Release(dst7
);
3652 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
, IDirectDrawSurface
*src
,
3653 IDirectDrawSurface
**dst
)
3655 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3656 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3657 struct ddraw_surface
*dst_impl
;
3658 IDirectDrawSurface7
*dst7
;
3661 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3663 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3664 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3667 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3668 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3669 IDirectDrawSurface_AddRef(*dst
);
3670 IDirectDrawSurface7_Release(dst7
);
3675 /*****************************************************************************
3676 * IDirect3D7::EnumDevices
3678 * The EnumDevices method for IDirect3D7. It enumerates all supported
3679 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
3682 * callback: Function to call for each enumerated device
3683 * context: Pointer to pass back to the app
3686 * D3D_OK, or the return value of the GetCaps call
3688 *****************************************************************************/
3689 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
3691 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
3692 D3DDEVICEDESC7 device_desc7
;
3693 D3DDEVICEDESC device_desc1
;
3697 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3700 return DDERR_INVALIDPARAMS
;
3702 wined3d_mutex_lock();
3704 hr
= IDirect3DImpl_GetCaps(ddraw
->wined3d
, &device_desc1
, &device_desc7
);
3707 wined3d_mutex_unlock();
3711 for (i
= 0; i
< sizeof(device_list7
)/sizeof(device_list7
[0]); i
++)
3715 device_desc7
.deviceGUID
= *device_list7
[i
].device_guid
;
3716 ret
= callback(device_list7
[i
].interface_name
, device_list7
[i
].device_name
, &device_desc7
, context
);
3717 if (ret
!= DDENUMRET_OK
)
3719 TRACE("Application cancelled the enumeration.\n");
3720 wined3d_mutex_unlock();
3725 TRACE("End of enumeration.\n");
3727 wined3d_mutex_unlock();
3732 /*****************************************************************************
3733 * IDirect3D3::EnumDevices
3735 * Enumerates all supported Direct3DDevice interfaces. This is the
3736 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
3738 * Version 1, 2 and 3
3741 * callback: Application-provided routine to call for each enumerated device
3742 * Context: Pointer to pass to the callback
3745 * D3D_OK on success,
3746 * The result of IDirect3DImpl_GetCaps if it failed
3748 *****************************************************************************/
3749 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3751 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
3753 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3754 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
3755 D3DDEVICEDESC7 device_desc7
;
3758 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
3759 * name string. Let's put the string in a sufficiently sized array in
3760 * writable memory. */
3761 char device_name
[50];
3762 strcpy(device_name
,"Direct3D HEL");
3764 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3767 return DDERR_INVALIDPARAMS
;
3769 wined3d_mutex_lock();
3771 hr
= IDirect3DImpl_GetCaps(ddraw
->wined3d
, &device_desc1
, &device_desc7
);
3774 wined3d_mutex_unlock();
3778 /* Do I have to enumerate the reference id? Note from old d3d7:
3779 * "It seems that enumerating the reference IID on Direct3D 1 games
3780 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
3782 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
3783 * EnumReference which enables / disables enumerating the reference
3784 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
3785 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
3786 * demo directory suggest this.
3788 * Some games(GTA 2) seem to use the second enumerated device, so I have
3789 * to enumerate at least 2 devices. So enumerate the reference device to
3792 * Other games (Rollcage) tell emulation and hal device apart by certain
3793 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
3794 * limitation flag), and it refuses all devices that have the perspective
3795 * flag set. This way it refuses the emulation device, and HAL devices
3796 * never have POW2 unset in d3d7 on windows. */
3797 if (ddraw
->d3dversion
!= 1)
3799 static CHAR reference_description
[] = "RGB Direct3D emulation";
3801 TRACE("Enumerating WineD3D D3DDevice interface.\n");
3802 hal_desc
= device_desc1
;
3803 hel_desc
= device_desc1
;
3804 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
3805 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3806 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3807 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3808 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3809 /* RGB, RAMP and MMX devices have a HAL dcmColorModel of 0 */
3810 hal_desc
.dcmColorModel
= 0;
3812 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
3813 device_name
, &hal_desc
, &hel_desc
, context
);
3814 if (hr
!= D3DENUMRET_OK
)
3816 TRACE("Application cancelled the enumeration.\n");
3817 wined3d_mutex_unlock();
3822 strcpy(device_name
,"Direct3D HAL");
3824 TRACE("Enumerating HAL Direct3D device.\n");
3825 hal_desc
= device_desc1
;
3826 hel_desc
= device_desc1
;
3828 /* The hal device does not have the pow2 flag set in hel, but in hal. */
3829 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3830 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3831 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3832 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3833 /* HAL devices have a HEL dcmColorModel of 0 */
3834 hel_desc
.dcmColorModel
= 0;
3836 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
3837 device_name
, &hal_desc
, &hel_desc
, context
);
3838 if (hr
!= D3DENUMRET_OK
)
3840 TRACE("Application cancelled the enumeration.\n");
3841 wined3d_mutex_unlock();
3845 TRACE("End of enumeration.\n");
3847 wined3d_mutex_unlock();
3852 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3854 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3856 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3858 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3861 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3863 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3865 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3867 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3870 /*****************************************************************************
3871 * IDirect3D3::CreateLight
3873 * Creates an IDirect3DLight interface. This interface is used in
3874 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
3875 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
3876 * uses the IDirect3DDevice7 interface with D3D7 lights.
3878 * Version 1, 2 and 3
3881 * light: Address to store the new interface pointer
3882 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3887 * DDERR_OUTOFMEMORY if memory allocation failed
3888 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3890 *****************************************************************************/
3891 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
,
3892 IUnknown
*outer_unknown
)
3894 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3895 struct d3d_light
*object
;
3897 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3899 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3901 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3904 ERR("Failed to allocate light memory.\n");
3905 return DDERR_OUTOFMEMORY
;
3908 d3d_light_init(object
, ddraw
);
3910 TRACE("Created light %p.\n", object
);
3911 *light
= &object
->IDirect3DLight_iface
;
3916 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3918 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3920 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3922 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3925 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3927 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3929 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3931 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3934 /*****************************************************************************
3935 * IDirect3D3::CreateMaterial
3937 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
3938 * and older versions. The IDirect3DMaterial implementation wraps its
3939 * functionality to IDirect3DDevice7::SetMaterial and friends.
3941 * Version 1, 2 and 3
3944 * material: Address to store the new interface's pointer to
3945 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3950 * DDERR_OUTOFMEMORY if memory allocation failed
3951 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3953 *****************************************************************************/
3954 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
,
3955 IUnknown
*outer_unknown
)
3957 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3958 struct d3d_material
*object
;
3960 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3962 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3964 object
= d3d_material_create(ddraw
);
3967 ERR("Failed to allocate material memory.\n");
3968 return DDERR_OUTOFMEMORY
;
3971 TRACE("Created material %p.\n", object
);
3972 *material
= &object
->IDirect3DMaterial3_iface
;
3977 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
,
3978 IUnknown
*outer_unknown
)
3980 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3981 struct d3d_material
*object
;
3983 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3985 object
= d3d_material_create(ddraw
);
3988 ERR("Failed to allocate material memory.\n");
3989 return DDERR_OUTOFMEMORY
;
3992 TRACE("Created material %p.\n", object
);
3993 *material
= &object
->IDirect3DMaterial2_iface
;
3998 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
,
3999 IUnknown
*outer_unknown
)
4001 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4002 struct d3d_material
*object
;
4004 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4006 object
= d3d_material_create(ddraw
);
4009 ERR("Failed to allocate material memory.\n");
4010 return DDERR_OUTOFMEMORY
;
4013 TRACE("Created material %p.\n", object
);
4014 *material
= &object
->IDirect3DMaterial_iface
;
4019 /*****************************************************************************
4020 * IDirect3D3::CreateViewport
4022 * Creates an IDirect3DViewport interface. This interface is used
4023 * by Direct3D and earlier versions for Viewport management. In Direct3D7
4024 * it has been replaced by a viewport structure and
4025 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
4026 * uses the IDirect3DDevice7 methods for its functionality
4029 * Viewport: Address to store the new interface pointer
4030 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4035 * DDERR_OUTOFMEMORY if memory allocation failed
4036 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4038 *****************************************************************************/
4039 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
,
4040 IUnknown
*outer_unknown
)
4042 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4043 struct d3d_viewport
*object
;
4045 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4047 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4049 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4052 ERR("Failed to allocate viewport memory.\n");
4053 return DDERR_OUTOFMEMORY
;
4056 d3d_viewport_init(object
, ddraw
);
4058 TRACE("Created viewport %p.\n", object
);
4059 *viewport
= &object
->IDirect3DViewport3_iface
;
4064 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
4066 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4068 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4070 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4074 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
4076 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4078 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4080 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4084 /*****************************************************************************
4085 * IDirect3D3::FindDevice
4087 * This method finds a device with the requested properties and returns a
4088 * device description
4092 * fds: Describes the requested device characteristics
4093 * fdr: Returns the device description
4097 * DDERR_INVALIDPARAMS if no device was found
4099 *****************************************************************************/
4100 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4102 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4103 D3DDEVICEDESC7 desc7
;
4104 D3DDEVICEDESC desc1
;
4107 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4109 if (!fds
|| !fdr
) return DDERR_INVALIDPARAMS
;
4111 if (fds
->dwSize
!= sizeof(D3DFINDDEVICESEARCH
)
4112 || fdr
->dwSize
!= sizeof(D3DFINDDEVICERESULT
))
4113 return DDERR_INVALIDPARAMS
;
4115 if ((fds
->dwFlags
& D3DFDS_COLORMODEL
)
4116 && fds
->dcmColorModel
!= D3DCOLOR_RGB
)
4118 WARN("Trying to request a non-RGB D3D color model. Not supported.\n");
4119 return DDERR_INVALIDPARAMS
; /* No real idea what to return here :-) */
4122 if (fds
->dwFlags
& D3DFDS_GUID
)
4124 TRACE("Trying to match guid %s.\n", debugstr_guid(&(fds
->guid
)));
4125 if (!IsEqualGUID(&IID_D3DDEVICE_WineD3D
, &fds
->guid
)
4126 && !IsEqualGUID(&IID_IDirect3DHALDevice
, &fds
->guid
)
4127 && !IsEqualGUID(&IID_IDirect3DRGBDevice
, &fds
->guid
))
4129 WARN("No match for this GUID.\n");
4130 return DDERR_NOTFOUND
;
4135 hr
= IDirect3DImpl_GetCaps(ddraw
->wined3d
, &desc1
, &desc7
);
4136 if (hr
!= D3D_OK
) return hr
;
4138 /* Now return our own GUID */
4139 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4140 fdr
->ddHwDesc
= desc1
;
4141 fdr
->ddSwDesc
= desc1
;
4143 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4148 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4150 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4152 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4154 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4157 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4159 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4161 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4163 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4166 /*****************************************************************************
4167 * IDirect3D7::CreateDevice
4169 * Creates an IDirect3DDevice7 interface.
4171 * Version 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4172 * DirectDraw surfaces and are created with
4173 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4174 * create the device object and QueryInterfaces for IDirect3DDevice
4177 * refiid: IID of the device to create
4178 * Surface: Initial rendertarget
4179 * Device: Address to return the interface pointer
4183 * DDERR_OUTOFMEMORY if memory allocation failed
4184 * DDERR_INVALIDPARAMS if a device exists already
4186 *****************************************************************************/
4187 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4188 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4190 struct ddraw_surface
*target
= unsafe_impl_from_IDirectDrawSurface7(surface
);
4191 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4192 struct d3d_device
*object
;
4195 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4197 wined3d_mutex_lock();
4198 hr
= d3d_device_create(ddraw
, target
, 7, &object
, NULL
);
4200 *device
= &object
->IDirect3DDevice7_iface
;
4203 WARN("Failed to create device, hr %#x.\n", hr
);
4206 wined3d_mutex_unlock();
4211 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4212 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4214 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface4(surface
);
4215 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4216 struct d3d_device
*device_impl
;
4219 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4220 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4223 return CLASS_E_NOAGGREGATION
;
4225 wined3d_mutex_lock();
4226 hr
= d3d_device_create(ddraw
, surface_impl
, 3, &device_impl
, NULL
);
4228 *device
= &device_impl
->IDirect3DDevice3_iface
;
4231 WARN("Failed to create device, hr %#x.\n", hr
);
4234 wined3d_mutex_unlock();
4239 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4240 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4242 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface(surface
);
4243 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4244 struct d3d_device
*device_impl
;
4247 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4248 iface
, debugstr_guid(riid
), surface
, device
);
4250 wined3d_mutex_lock();
4251 hr
= d3d_device_create(ddraw
, surface_impl
, 2, &device_impl
, NULL
);
4253 *device
= &device_impl
->IDirect3DDevice2_iface
;
4256 WARN("Failed to create device, hr %#x.\n", hr
);
4259 wined3d_mutex_unlock();
4264 /*****************************************************************************
4265 * IDirect3D7::CreateVertexBuffer
4267 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4273 * desc: Requested Vertex buffer properties
4274 * vertex_buffer: Address to return the interface pointer at
4275 * flags: Some flags, should be 0
4279 * DDERR_OUTOFMEMORY if memory allocation failed
4280 * The return value of IWineD3DDevice::CreateVertexBuffer if this call fails
4281 * DDERR_INVALIDPARAMS if desc or vertex_buffer are NULL
4283 *****************************************************************************/
4284 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4285 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4287 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4288 struct d3d_vertex_buffer
*object
;
4291 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
4292 iface
, desc
, vertex_buffer
, flags
);
4294 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4296 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4299 TRACE("Created vertex buffer %p.\n", object
);
4300 *vertex_buffer
= &object
->IDirect3DVertexBuffer7_iface
;
4303 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4308 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4309 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4311 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4312 struct d3d_vertex_buffer
*object
;
4315 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n",
4316 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4319 return CLASS_E_NOAGGREGATION
;
4320 if (!vertex_buffer
|| !desc
)
4321 return DDERR_INVALIDPARAMS
;
4323 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4326 TRACE("Created vertex buffer %p.\n", object
);
4327 *vertex_buffer
= &object
->IDirect3DVertexBuffer_iface
;
4330 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4335 /*****************************************************************************
4336 * IDirect3D7::EnumZBufferFormats
4338 * Enumerates all supported Z buffer pixel formats
4344 * callback: callback to call for each pixel format
4345 * context: Pointer to pass back to the callback
4349 * DDERR_INVALIDPARAMS if callback is NULL
4350 * For details, see IWineD3DDevice::EnumZBufferFormats
4352 *****************************************************************************/
4353 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4354 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4356 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4357 struct wined3d_display_mode mode
;
4358 enum wined3d_device_type type
;
4362 /* Order matters. Specifically, BattleZone II (full version) expects the
4363 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4364 static const enum wined3d_format_id formats
[] =
4366 WINED3DFMT_S1_UINT_D15_UNORM
,
4367 WINED3DFMT_D16_UNORM
,
4368 WINED3DFMT_X8D24_UNORM
,
4369 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4370 WINED3DFMT_D24_UNORM_S8_UINT
,
4371 WINED3DFMT_D32_UNORM
,
4374 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4375 iface
, debugstr_guid(device_iid
), callback
, context
);
4377 if (!callback
) return DDERR_INVALIDPARAMS
;
4379 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4380 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4381 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4383 TRACE("Asked for HAL device.\n");
4384 type
= WINED3D_DEVICE_TYPE_HAL
;
4386 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4387 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4389 TRACE("Asked for SW device.\n");
4390 type
= WINED3D_DEVICE_TYPE_SW
;
4392 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4394 TRACE("Asked for REF device.\n");
4395 type
= WINED3D_DEVICE_TYPE_REF
;
4397 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4399 TRACE("Asked for NULLREF device.\n");
4400 type
= WINED3D_DEVICE_TYPE_NULLREF
;
4404 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4405 type
= WINED3D_DEVICE_TYPE_HAL
;
4408 wined3d_mutex_lock();
4409 /* We need an adapter format from somewhere to please wined3d and WGL.
4410 * Use the current display mode. So far all cards offer the same depth
4411 * stencil format for all modes, but if some do not and applications do
4412 * not like that we'll have to find some workaround, like iterating over
4413 * all imaginable formats and collecting all the depth stencil formats we
4415 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
4417 ERR("Failed to get display mode, hr %#x.\n", hr
);
4418 wined3d_mutex_unlock();
4422 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
4424 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4425 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_SURFACE
, formats
[i
])))
4427 DDPIXELFORMAT pformat
;
4429 memset(&pformat
, 0, sizeof(pformat
));
4430 pformat
.dwSize
= sizeof(pformat
);
4431 ddrawformat_from_wined3dformat(&pformat
, formats
[i
]);
4433 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
4434 hr
= callback(&pformat
, context
);
4435 if (hr
!= DDENUMRET_OK
)
4437 TRACE("Format enumeration cancelled by application.\n");
4438 wined3d_mutex_unlock();
4444 /* Historically some windows drivers used dwZBufferBitDepth=24 for WINED3DFMT_X8D24_UNORM,
4445 * while others used dwZBufferBitDepth=32. In either case the pitch matches a 32 bits per
4446 * pixel format, so we use dwZBufferBitDepth=32. Some games expect 24. Windows Vista and
4447 * newer enumerate both versions, so we do the same(bug 22434) */
4448 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4449 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_SURFACE
, WINED3DFMT_X8D24_UNORM
)))
4451 DDPIXELFORMAT x8d24
=
4453 sizeof(x8d24
), DDPF_ZBUFFER
, 0,
4454 {24}, {0x00000000}, {0x00ffffff}, {0x00000000}
4456 TRACE("Enumerating WINED3DFMT_X8D24_UNORM, dwZBufferBitDepth=24 version\n");
4457 callback(&x8d24
, context
);
4460 TRACE("End of enumeration.\n");
4462 wined3d_mutex_unlock();
4467 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
4468 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4470 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4472 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4473 iface
, debugstr_guid(device_iid
), callback
, context
);
4475 return d3d7_EnumZBufferFormats(&ddraw
->IDirect3D7_iface
, device_iid
, callback
, context
);
4478 /*****************************************************************************
4479 * IDirect3D7::EvictManagedTextures
4481 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
4482 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
4487 * D3D_OK, because it's a stub
4489 *****************************************************************************/
4490 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
4492 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4494 TRACE("iface %p!\n", iface
);
4496 wined3d_mutex_lock();
4497 if (ddraw
->flags
& DDRAW_D3D_INITIALIZED
)
4498 wined3d_device_evict_managed_resources(ddraw
->wined3d_device
);
4499 wined3d_mutex_unlock();
4504 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
4506 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4508 TRACE("iface %p.\n", iface
);
4510 return d3d7_EvictManagedTextures(&ddraw
->IDirect3D7_iface
);
4513 /*****************************************************************************
4514 * IDirect3DImpl_GetCaps
4516 * This function retrieves the device caps from wined3d
4517 * and converts it into a D3D7 and D3D - D3D3 structure
4518 * This is a helper function called from various places in ddraw
4521 * wined3d: The interface to get the caps from
4522 * desc1: Old D3D <3 structure to fill (needed)
4523 * desc7: D3D7 device desc structure to fill (needed)
4526 * D3D_OK on success, or the return value of IWineD3D::GetCaps
4528 *****************************************************************************/
4529 HRESULT
IDirect3DImpl_GetCaps(const struct wined3d
*wined3d
, D3DDEVICEDESC
*desc1
, D3DDEVICEDESC7
*desc7
)
4531 WINED3DCAPS wined3d_caps
;
4534 TRACE("wined3d %p, desc1 %p, desc7 %p.\n", wined3d
, desc1
, desc7
);
4536 memset(&wined3d_caps
, 0, sizeof(wined3d_caps
));
4538 wined3d_mutex_lock();
4539 hr
= wined3d_get_device_caps(wined3d
, 0, WINED3D_DEVICE_TYPE_HAL
, &wined3d_caps
);
4540 wined3d_mutex_unlock();
4543 WARN("Failed to get device caps, hr %#x.\n", hr
);
4547 /* Copy the results into the d3d7 and d3d3 structures */
4548 desc7
->dwDevCaps
= wined3d_caps
.DevCaps
;
4549 desc7
->dpcLineCaps
.dwMiscCaps
= wined3d_caps
.PrimitiveMiscCaps
;
4550 desc7
->dpcLineCaps
.dwRasterCaps
= wined3d_caps
.RasterCaps
;
4551 desc7
->dpcLineCaps
.dwZCmpCaps
= wined3d_caps
.ZCmpCaps
;
4552 desc7
->dpcLineCaps
.dwSrcBlendCaps
= wined3d_caps
.SrcBlendCaps
;
4553 desc7
->dpcLineCaps
.dwDestBlendCaps
= wined3d_caps
.DestBlendCaps
;
4554 desc7
->dpcLineCaps
.dwAlphaCmpCaps
= wined3d_caps
.AlphaCmpCaps
;
4555 desc7
->dpcLineCaps
.dwShadeCaps
= wined3d_caps
.ShadeCaps
;
4556 desc7
->dpcLineCaps
.dwTextureCaps
= wined3d_caps
.TextureCaps
;
4557 desc7
->dpcLineCaps
.dwTextureFilterCaps
= wined3d_caps
.TextureFilterCaps
;
4558 desc7
->dpcLineCaps
.dwTextureAddressCaps
= wined3d_caps
.TextureAddressCaps
;
4560 desc7
->dwMaxTextureWidth
= wined3d_caps
.MaxTextureWidth
;
4561 desc7
->dwMaxTextureHeight
= wined3d_caps
.MaxTextureHeight
;
4563 desc7
->dwMaxTextureRepeat
= wined3d_caps
.MaxTextureRepeat
;
4564 desc7
->dwMaxTextureAspectRatio
= wined3d_caps
.MaxTextureAspectRatio
;
4565 desc7
->dwMaxAnisotropy
= wined3d_caps
.MaxAnisotropy
;
4566 desc7
->dvMaxVertexW
= wined3d_caps
.MaxVertexW
;
4568 desc7
->dvGuardBandLeft
= wined3d_caps
.GuardBandLeft
;
4569 desc7
->dvGuardBandTop
= wined3d_caps
.GuardBandTop
;
4570 desc7
->dvGuardBandRight
= wined3d_caps
.GuardBandRight
;
4571 desc7
->dvGuardBandBottom
= wined3d_caps
.GuardBandBottom
;
4573 desc7
->dvExtentsAdjust
= wined3d_caps
.ExtentsAdjust
;
4574 desc7
->dwStencilCaps
= wined3d_caps
.StencilCaps
;
4576 desc7
->dwFVFCaps
= wined3d_caps
.FVFCaps
;
4577 desc7
->dwTextureOpCaps
= wined3d_caps
.TextureOpCaps
;
4579 desc7
->dwVertexProcessingCaps
= wined3d_caps
.VertexProcessingCaps
;
4580 desc7
->dwMaxActiveLights
= wined3d_caps
.MaxActiveLights
;
4582 /* Remove all non-d3d7 caps */
4583 desc7
->dwDevCaps
&= (
4584 D3DDEVCAPS_FLOATTLVERTEX
| D3DDEVCAPS_SORTINCREASINGZ
| D3DDEVCAPS_SORTDECREASINGZ
|
4585 D3DDEVCAPS_SORTEXACT
| D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
|
4586 D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
| D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
|
4587 D3DDEVCAPS_TEXTUREVIDEOMEMORY
| D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
|
4588 D3DDEVCAPS_TEXTURENONLOCALVIDMEM
| D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
4589 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
4590 D3DDEVCAPS_HWRASTERIZATION
);
4592 desc7
->dwStencilCaps
&= (
4593 D3DSTENCILCAPS_KEEP
| D3DSTENCILCAPS_ZERO
| D3DSTENCILCAPS_REPLACE
|
4594 D3DSTENCILCAPS_INCRSAT
| D3DSTENCILCAPS_DECRSAT
| D3DSTENCILCAPS_INVERT
|
4595 D3DSTENCILCAPS_INCR
| D3DSTENCILCAPS_DECR
);
4599 desc7
->dwTextureOpCaps
&= (
4600 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_SELECTARG2
|
4601 D3DTEXOPCAPS_MODULATE
| D3DTEXOPCAPS_MODULATE2X
| D3DTEXOPCAPS_MODULATE4X
|
4602 D3DTEXOPCAPS_ADD
| D3DTEXOPCAPS_ADDSIGNED
| D3DTEXOPCAPS_ADDSIGNED2X
|
4603 D3DTEXOPCAPS_SUBTRACT
| D3DTEXOPCAPS_ADDSMOOTH
| D3DTEXOPCAPS_BLENDTEXTUREALPHA
|
4604 D3DTEXOPCAPS_BLENDFACTORALPHA
| D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
| D3DTEXOPCAPS_BLENDCURRENTALPHA
|
4605 D3DTEXOPCAPS_PREMODULATE
| D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
|
4606 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
| D3DTEXOPCAPS_BUMPENVMAP
|
4607 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
| D3DTEXOPCAPS_DOTPRODUCT3
);
4609 desc7
->dwVertexProcessingCaps
&= (
4610 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_VERTEXFOG
|
4611 D3DVTXPCAPS_DIRECTIONALLIGHTS
| D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
);
4613 desc7
->dpcLineCaps
.dwMiscCaps
&= (
4614 D3DPMISCCAPS_MASKPLANES
| D3DPMISCCAPS_MASKZ
| D3DPMISCCAPS_LINEPATTERNREP
|
4615 D3DPMISCCAPS_CONFORMANT
| D3DPMISCCAPS_CULLNONE
| D3DPMISCCAPS_CULLCW
|
4616 D3DPMISCCAPS_CULLCCW
);
4618 desc7
->dpcLineCaps
.dwRasterCaps
&= (
4619 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ROP2
| D3DPRASTERCAPS_XOR
|
4620 D3DPRASTERCAPS_PAT
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_SUBPIXEL
|
4621 D3DPRASTERCAPS_SUBPIXELX
| D3DPRASTERCAPS_FOGVERTEX
| D3DPRASTERCAPS_FOGTABLE
|
4622 D3DPRASTERCAPS_STIPPLE
| D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT
| D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT
|
4623 D3DPRASTERCAPS_ANTIALIASEDGES
| D3DPRASTERCAPS_MIPMAPLODBIAS
| D3DPRASTERCAPS_ZBIAS
|
4624 D3DPRASTERCAPS_ZBUFFERLESSHSR
| D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
|
4625 D3DPRASTERCAPS_WBUFFER
| D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT
| D3DPRASTERCAPS_WFOG
|
4626 D3DPRASTERCAPS_ZFOG
);
4628 desc7
->dpcLineCaps
.dwZCmpCaps
&= (
4629 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
4630 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
4631 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
4633 desc7
->dpcLineCaps
.dwSrcBlendCaps
&= (
4634 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
4635 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
4636 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
4637 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
4638 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
4640 desc7
->dpcLineCaps
.dwDestBlendCaps
&= (
4641 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
4642 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
4643 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
4644 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
4645 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
4647 desc7
->dpcLineCaps
.dwAlphaCmpCaps
&= (
4648 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
4649 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
4650 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
4652 desc7
->dpcLineCaps
.dwShadeCaps
&= (
4653 D3DPSHADECAPS_COLORFLATMONO
| D3DPSHADECAPS_COLORFLATRGB
| D3DPSHADECAPS_COLORGOURAUDMONO
|
4654 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_COLORPHONGMONO
| D3DPSHADECAPS_COLORPHONGRGB
|
4655 D3DPSHADECAPS_SPECULARFLATMONO
| D3DPSHADECAPS_SPECULARFLATRGB
| D3DPSHADECAPS_SPECULARGOURAUDMONO
|
4656 D3DPSHADECAPS_SPECULARGOURAUDRGB
| D3DPSHADECAPS_SPECULARPHONGMONO
| D3DPSHADECAPS_SPECULARPHONGRGB
|
4657 D3DPSHADECAPS_ALPHAFLATBLEND
| D3DPSHADECAPS_ALPHAFLATSTIPPLED
| D3DPSHADECAPS_ALPHAGOURAUDBLEND
|
4658 D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED
| D3DPSHADECAPS_ALPHAPHONGBLEND
| D3DPSHADECAPS_ALPHAPHONGSTIPPLED
|
4659 D3DPSHADECAPS_FOGFLAT
| D3DPSHADECAPS_FOGGOURAUD
| D3DPSHADECAPS_FOGPHONG
);
4661 desc7
->dpcLineCaps
.dwTextureCaps
&= (
4662 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
4663 D3DPTEXTURECAPS_TRANSPARENCY
| D3DPTEXTURECAPS_BORDER
| D3DPTEXTURECAPS_SQUAREONLY
|
4664 D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
| D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
4665 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_COLORKEYBLEND
);
4667 desc7
->dpcLineCaps
.dwTextureFilterCaps
&= (
4668 D3DPTFILTERCAPS_NEAREST
| D3DPTFILTERCAPS_LINEAR
| D3DPTFILTERCAPS_MIPNEAREST
|
4669 D3DPTFILTERCAPS_MIPLINEAR
| D3DPTFILTERCAPS_LINEARMIPNEAREST
| D3DPTFILTERCAPS_LINEARMIPLINEAR
|
4670 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
4671 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
4672 D3DPTFILTERCAPS_MAGFLINEAR
| D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
|
4673 D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
);
4675 desc7
->dpcLineCaps
.dwTextureAddressCaps
&= (
4676 D3DPTADDRESSCAPS_WRAP
| D3DPTADDRESSCAPS_MIRROR
| D3DPTADDRESSCAPS_CLAMP
|
4677 D3DPTADDRESSCAPS_BORDER
| D3DPTADDRESSCAPS_INDEPENDENTUV
);
4679 if (!(desc7
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
))
4681 /* DirectX7 always has the np2 flag set, no matter what the card
4682 * supports. Some old games (Rollcage) check the caps incorrectly.
4683 * If wined3d supports nonpow2 textures it also has np2 conditional
4685 desc7
->dpcLineCaps
.dwTextureCaps
|= D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
;
4688 /* Fill the missing members, and do some fixup */
4689 desc7
->dpcLineCaps
.dwSize
= sizeof(desc7
->dpcLineCaps
);
4690 desc7
->dpcLineCaps
.dwTextureBlendCaps
= D3DPTBLENDCAPS_ADD
| D3DPTBLENDCAPS_MODULATEMASK
|
4691 D3DPTBLENDCAPS_COPY
| D3DPTBLENDCAPS_DECAL
|
4692 D3DPTBLENDCAPS_DECALALPHA
| D3DPTBLENDCAPS_DECALMASK
|
4693 D3DPTBLENDCAPS_MODULATE
| D3DPTBLENDCAPS_MODULATEALPHA
;
4694 desc7
->dpcLineCaps
.dwStippleWidth
= 32;
4695 desc7
->dpcLineCaps
.dwStippleHeight
= 32;
4696 /* Use the same for the TriCaps */
4697 desc7
->dpcTriCaps
= desc7
->dpcLineCaps
;
4699 desc7
->dwDeviceRenderBitDepth
= DDBD_16
| DDBD_24
| DDBD_32
;
4700 desc7
->dwDeviceZBufferBitDepth
= DDBD_16
| DDBD_24
;
4701 desc7
->dwMinTextureWidth
= 1;
4702 desc7
->dwMinTextureHeight
= 1;
4704 /* Convert DWORDs safely to WORDs */
4705 if (wined3d_caps
.MaxTextureBlendStages
> 0xffff) desc7
->wMaxTextureBlendStages
= 0xffff;
4706 else desc7
->wMaxTextureBlendStages
= (WORD
)wined3d_caps
.MaxTextureBlendStages
;
4707 if (wined3d_caps
.MaxSimultaneousTextures
> 0xffff) desc7
->wMaxSimultaneousTextures
= 0xffff;
4708 else desc7
->wMaxSimultaneousTextures
= (WORD
)wined3d_caps
.MaxSimultaneousTextures
;
4710 if (wined3d_caps
.MaxUserClipPlanes
> 0xffff) desc7
->wMaxUserClipPlanes
= 0xffff;
4711 else desc7
->wMaxUserClipPlanes
= (WORD
)wined3d_caps
.MaxUserClipPlanes
;
4712 if (wined3d_caps
.MaxVertexBlendMatrices
> 0xffff) desc7
->wMaxVertexBlendMatrices
= 0xffff;
4713 else desc7
->wMaxVertexBlendMatrices
= (WORD
)wined3d_caps
.MaxVertexBlendMatrices
;
4715 desc7
->deviceGUID
= IID_IDirect3DTnLHalDevice
;
4717 desc7
->dwReserved1
= 0;
4718 desc7
->dwReserved2
= 0;
4719 desc7
->dwReserved3
= 0;
4720 desc7
->dwReserved4
= 0;
4722 /* Fill the old structure */
4723 memset(desc1
, 0, sizeof(*desc1
));
4724 desc1
->dwSize
= sizeof(D3DDEVICEDESC
);
4725 desc1
->dwFlags
= D3DDD_COLORMODEL
4727 | D3DDD_TRANSFORMCAPS
4729 | D3DDD_LIGHTINGCAPS
4732 | D3DDD_DEVICERENDERBITDEPTH
4733 | D3DDD_DEVICEZBUFFERBITDEPTH
4734 | D3DDD_MAXBUFFERSIZE
4735 | D3DDD_MAXVERTEXCOUNT
;
4737 desc1
->dcmColorModel
= D3DCOLOR_RGB
;
4738 desc1
->dwDevCaps
= desc7
->dwDevCaps
;
4739 desc1
->dtcTransformCaps
.dwSize
= sizeof(D3DTRANSFORMCAPS
);
4740 desc1
->dtcTransformCaps
.dwCaps
= D3DTRANSFORMCAPS_CLIP
;
4741 desc1
->bClipping
= TRUE
;
4742 desc1
->dlcLightingCaps
.dwSize
= sizeof(D3DLIGHTINGCAPS
);
4743 desc1
->dlcLightingCaps
.dwCaps
= D3DLIGHTCAPS_DIRECTIONAL
4744 | D3DLIGHTCAPS_PARALLELPOINT
4745 | D3DLIGHTCAPS_POINT
4746 | D3DLIGHTCAPS_SPOT
;
4748 desc1
->dlcLightingCaps
.dwLightingModel
= D3DLIGHTINGMODEL_RGB
;
4749 desc1
->dlcLightingCaps
.dwNumLights
= desc7
->dwMaxActiveLights
;
4751 desc1
->dpcLineCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
4752 desc1
->dpcLineCaps
.dwMiscCaps
= desc7
->dpcLineCaps
.dwMiscCaps
;
4753 desc1
->dpcLineCaps
.dwRasterCaps
= desc7
->dpcLineCaps
.dwRasterCaps
;
4754 desc1
->dpcLineCaps
.dwZCmpCaps
= desc7
->dpcLineCaps
.dwZCmpCaps
;
4755 desc1
->dpcLineCaps
.dwSrcBlendCaps
= desc7
->dpcLineCaps
.dwSrcBlendCaps
;
4756 desc1
->dpcLineCaps
.dwDestBlendCaps
= desc7
->dpcLineCaps
.dwDestBlendCaps
;
4757 desc1
->dpcLineCaps
.dwShadeCaps
= desc7
->dpcLineCaps
.dwShadeCaps
;
4758 desc1
->dpcLineCaps
.dwTextureCaps
= desc7
->dpcLineCaps
.dwTextureCaps
;
4759 desc1
->dpcLineCaps
.dwTextureFilterCaps
= desc7
->dpcLineCaps
.dwTextureFilterCaps
;
4760 desc1
->dpcLineCaps
.dwTextureBlendCaps
= desc7
->dpcLineCaps
.dwTextureBlendCaps
;
4761 desc1
->dpcLineCaps
.dwTextureAddressCaps
= desc7
->dpcLineCaps
.dwTextureAddressCaps
;
4762 desc1
->dpcLineCaps
.dwStippleWidth
= desc7
->dpcLineCaps
.dwStippleWidth
;
4763 desc1
->dpcLineCaps
.dwAlphaCmpCaps
= desc7
->dpcLineCaps
.dwAlphaCmpCaps
;
4765 desc1
->dpcTriCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
4766 desc1
->dpcTriCaps
.dwMiscCaps
= desc7
->dpcTriCaps
.dwMiscCaps
;
4767 desc1
->dpcTriCaps
.dwRasterCaps
= desc7
->dpcTriCaps
.dwRasterCaps
;
4768 desc1
->dpcTriCaps
.dwZCmpCaps
= desc7
->dpcTriCaps
.dwZCmpCaps
;
4769 desc1
->dpcTriCaps
.dwSrcBlendCaps
= desc7
->dpcTriCaps
.dwSrcBlendCaps
;
4770 desc1
->dpcTriCaps
.dwDestBlendCaps
= desc7
->dpcTriCaps
.dwDestBlendCaps
;
4771 desc1
->dpcTriCaps
.dwShadeCaps
= desc7
->dpcTriCaps
.dwShadeCaps
;
4772 desc1
->dpcTriCaps
.dwTextureCaps
= desc7
->dpcTriCaps
.dwTextureCaps
;
4773 desc1
->dpcTriCaps
.dwTextureFilterCaps
= desc7
->dpcTriCaps
.dwTextureFilterCaps
;
4774 desc1
->dpcTriCaps
.dwTextureBlendCaps
= desc7
->dpcTriCaps
.dwTextureBlendCaps
;
4775 desc1
->dpcTriCaps
.dwTextureAddressCaps
= desc7
->dpcTriCaps
.dwTextureAddressCaps
;
4776 desc1
->dpcTriCaps
.dwStippleWidth
= desc7
->dpcTriCaps
.dwStippleWidth
;
4777 desc1
->dpcTriCaps
.dwAlphaCmpCaps
= desc7
->dpcTriCaps
.dwAlphaCmpCaps
;
4779 desc1
->dwDeviceRenderBitDepth
= desc7
->dwDeviceRenderBitDepth
;
4780 desc1
->dwDeviceZBufferBitDepth
= desc7
->dwDeviceZBufferBitDepth
;
4781 desc1
->dwMaxBufferSize
= 0;
4782 desc1
->dwMaxVertexCount
= 65536;
4783 desc1
->dwMinTextureWidth
= desc7
->dwMinTextureWidth
;
4784 desc1
->dwMinTextureHeight
= desc7
->dwMinTextureHeight
;
4785 desc1
->dwMaxTextureWidth
= desc7
->dwMaxTextureWidth
;
4786 desc1
->dwMaxTextureHeight
= desc7
->dwMaxTextureHeight
;
4787 desc1
->dwMinStippleWidth
= 1;
4788 desc1
->dwMinStippleHeight
= 1;
4789 desc1
->dwMaxStippleWidth
= 32;
4790 desc1
->dwMaxStippleHeight
= 32;
4791 desc1
->dwMaxTextureRepeat
= desc7
->dwMaxTextureRepeat
;
4792 desc1
->dwMaxTextureAspectRatio
= desc7
->dwMaxTextureAspectRatio
;
4793 desc1
->dwMaxAnisotropy
= desc7
->dwMaxAnisotropy
;
4794 desc1
->dvGuardBandLeft
= desc7
->dvGuardBandLeft
;
4795 desc1
->dvGuardBandRight
= desc7
->dvGuardBandRight
;
4796 desc1
->dvGuardBandTop
= desc7
->dvGuardBandTop
;
4797 desc1
->dvGuardBandBottom
= desc7
->dvGuardBandBottom
;
4798 desc1
->dvExtentsAdjust
= desc7
->dvExtentsAdjust
;
4799 desc1
->dwStencilCaps
= desc7
->dwStencilCaps
;
4800 desc1
->dwFVFCaps
= desc7
->dwFVFCaps
;
4801 desc1
->dwTextureOpCaps
= desc7
->dwTextureOpCaps
;
4802 desc1
->wMaxTextureBlendStages
= desc7
->wMaxTextureBlendStages
;
4803 desc1
->wMaxSimultaneousTextures
= desc7
->wMaxSimultaneousTextures
;
4808 /*****************************************************************************
4809 * IDirectDraw7 VTable
4810 *****************************************************************************/
4811 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
4814 ddraw7_QueryInterface
,
4819 ddraw7_CreateClipper
,
4820 ddraw7_CreatePalette
,
4821 ddraw7_CreateSurface
,
4822 ddraw7_DuplicateSurface
,
4823 ddraw7_EnumDisplayModes
,
4824 ddraw7_EnumSurfaces
,
4825 ddraw7_FlipToGDISurface
,
4827 ddraw7_GetDisplayMode
,
4828 ddraw7_GetFourCCCodes
,
4829 ddraw7_GetGDISurface
,
4830 ddraw7_GetMonitorFrequency
,
4832 ddraw7_GetVerticalBlankStatus
,
4834 ddraw7_RestoreDisplayMode
,
4835 ddraw7_SetCooperativeLevel
,
4836 ddraw7_SetDisplayMode
,
4837 ddraw7_WaitForVerticalBlank
,
4839 ddraw7_GetAvailableVidMem
,
4841 ddraw7_GetSurfaceFromDC
,
4843 ddraw7_RestoreAllSurfaces
,
4844 ddraw7_TestCooperativeLevel
,
4845 ddraw7_GetDeviceIdentifier
,
4847 ddraw7_StartModeTest
,
4851 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
4854 ddraw4_QueryInterface
,
4859 ddraw4_CreateClipper
,
4860 ddraw4_CreatePalette
,
4861 ddraw4_CreateSurface
,
4862 ddraw4_DuplicateSurface
,
4863 ddraw4_EnumDisplayModes
,
4864 ddraw4_EnumSurfaces
,
4865 ddraw4_FlipToGDISurface
,
4867 ddraw4_GetDisplayMode
,
4868 ddraw4_GetFourCCCodes
,
4869 ddraw4_GetGDISurface
,
4870 ddraw4_GetMonitorFrequency
,
4872 ddraw4_GetVerticalBlankStatus
,
4874 ddraw4_RestoreDisplayMode
,
4875 ddraw4_SetCooperativeLevel
,
4876 ddraw4_SetDisplayMode
,
4877 ddraw4_WaitForVerticalBlank
,
4879 ddraw4_GetAvailableVidMem
,
4881 ddraw4_GetSurfaceFromDC
,
4883 ddraw4_RestoreAllSurfaces
,
4884 ddraw4_TestCooperativeLevel
,
4885 ddraw4_GetDeviceIdentifier
,
4888 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
4891 ddraw2_QueryInterface
,
4896 ddraw2_CreateClipper
,
4897 ddraw2_CreatePalette
,
4898 ddraw2_CreateSurface
,
4899 ddraw2_DuplicateSurface
,
4900 ddraw2_EnumDisplayModes
,
4901 ddraw2_EnumSurfaces
,
4902 ddraw2_FlipToGDISurface
,
4904 ddraw2_GetDisplayMode
,
4905 ddraw2_GetFourCCCodes
,
4906 ddraw2_GetGDISurface
,
4907 ddraw2_GetMonitorFrequency
,
4909 ddraw2_GetVerticalBlankStatus
,
4911 ddraw2_RestoreDisplayMode
,
4912 ddraw2_SetCooperativeLevel
,
4913 ddraw2_SetDisplayMode
,
4914 ddraw2_WaitForVerticalBlank
,
4916 ddraw2_GetAvailableVidMem
,
4919 static const struct IDirectDrawVtbl ddraw1_vtbl
=
4922 ddraw1_QueryInterface
,
4927 ddraw1_CreateClipper
,
4928 ddraw1_CreatePalette
,
4929 ddraw1_CreateSurface
,
4930 ddraw1_DuplicateSurface
,
4931 ddraw1_EnumDisplayModes
,
4932 ddraw1_EnumSurfaces
,
4933 ddraw1_FlipToGDISurface
,
4935 ddraw1_GetDisplayMode
,
4936 ddraw1_GetFourCCCodes
,
4937 ddraw1_GetGDISurface
,
4938 ddraw1_GetMonitorFrequency
,
4940 ddraw1_GetVerticalBlankStatus
,
4942 ddraw1_RestoreDisplayMode
,
4943 ddraw1_SetCooperativeLevel
,
4944 ddraw1_SetDisplayMode
,
4945 ddraw1_WaitForVerticalBlank
,
4948 static const struct IDirect3D7Vtbl d3d7_vtbl
=
4950 /* IUnknown methods */
4951 d3d7_QueryInterface
,
4954 /* IDirect3D7 methods */
4957 d3d7_CreateVertexBuffer
,
4958 d3d7_EnumZBufferFormats
,
4959 d3d7_EvictManagedTextures
4962 static const struct IDirect3D3Vtbl d3d3_vtbl
=
4964 /* IUnknown methods */
4965 d3d3_QueryInterface
,
4968 /* IDirect3D3 methods */
4971 d3d3_CreateMaterial
,
4972 d3d3_CreateViewport
,
4975 d3d3_CreateVertexBuffer
,
4976 d3d3_EnumZBufferFormats
,
4977 d3d3_EvictManagedTextures
4980 static const struct IDirect3D2Vtbl d3d2_vtbl
=
4982 /* IUnknown methods */
4983 d3d2_QueryInterface
,
4986 /* IDirect3D2 methods */
4989 d3d2_CreateMaterial
,
4990 d3d2_CreateViewport
,
4995 static const struct IDirect3DVtbl d3d1_vtbl
=
4997 /* IUnknown methods */
4998 d3d1_QueryInterface
,
5001 /* IDirect3D methods */
5005 d3d1_CreateMaterial
,
5006 d3d1_CreateViewport
,
5010 /*****************************************************************************
5013 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
5014 * if none was found.
5016 * This function is in ddraw.c and the DDraw object space because D3D7
5017 * vertex buffers are created using the IDirect3D interface to the ddraw
5018 * object, so they can be valid across D3D devices(theoretically. The ddraw
5019 * object also owns the wined3d device
5023 * fvf: Fvf to find the decl for
5026 * NULL in case of an error, the vertex declaration for the FVF otherwise.
5028 *****************************************************************************/
5029 struct wined3d_vertex_declaration
*ddraw_find_decl(struct ddraw
*This
, DWORD fvf
)
5031 struct wined3d_vertex_declaration
*pDecl
= NULL
;
5033 int p
, low
, high
; /* deliberately signed */
5034 struct FvfToDecl
*convertedDecls
= This
->decls
;
5036 TRACE("Searching for declaration for fvf %08x... ", fvf
);
5039 high
= This
->numConvertedDecls
- 1;
5040 while(low
<= high
) {
5041 p
= (low
+ high
) >> 1;
5043 if(convertedDecls
[p
].fvf
== fvf
) {
5044 TRACE("found %p\n", convertedDecls
[p
].decl
);
5045 return convertedDecls
[p
].decl
;
5046 } else if(convertedDecls
[p
].fvf
< fvf
) {
5052 TRACE("not found. Creating and inserting at position %d.\n", low
);
5054 hr
= wined3d_vertex_declaration_create_from_fvf(This
->wined3d_device
,
5055 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
5056 if (hr
!= S_OK
) return NULL
;
5058 if(This
->declArraySize
== This
->numConvertedDecls
) {
5059 int grow
= max(This
->declArraySize
/ 2, 8);
5060 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
5061 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
5062 if (!convertedDecls
)
5064 wined3d_vertex_declaration_decref(pDecl
);
5067 This
->decls
= convertedDecls
;
5068 This
->declArraySize
+= grow
;
5071 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
5072 convertedDecls
[low
].decl
= pDecl
;
5073 convertedDecls
[low
].fvf
= fvf
;
5074 This
->numConvertedDecls
++;
5076 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
5080 static inline struct ddraw
*ddraw_from_device_parent(struct wined3d_device_parent
*device_parent
)
5082 return CONTAINING_RECORD(device_parent
, struct ddraw
, device_parent
);
5085 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
5086 struct wined3d_device
*device
)
5088 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
5091 /* This is run from device_process_message() in wined3d, we can't take the
5093 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
5095 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
5096 MONITORINFO monitor_info
;
5100 TRACE("device_parent %p.\n", device_parent
);
5102 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) || !ddraw
->swapchain_window
)
5104 TRACE("Nothing to resize.\n");
5108 monitor
= MonitorFromWindow(ddraw
->swapchain_window
, MONITOR_DEFAULTTOPRIMARY
);
5109 monitor_info
.cbSize
= sizeof(monitor_info
);
5110 if (!GetMonitorInfoW(monitor
, &monitor_info
))
5112 ERR("Failed to get monitor info.\n");
5116 r
= &monitor_info
.rcMonitor
;
5117 TRACE("Resizing window %p to %s.\n", ddraw
->swapchain_window
, wine_dbgstr_rect(r
));
5119 if (!SetWindowPos(ddraw
->swapchain_window
, HWND_TOP
, r
->left
, r
->top
,
5120 r
->right
- r
->left
, r
->bottom
- r
->top
, SWP_SHOWWINDOW
| SWP_NOACTIVATE
))
5121 ERR("Failed to resize window.\n");
5124 static HRESULT CDECL
device_parent_create_texture_surface(struct wined3d_device_parent
*device_parent
,
5125 void *container_parent
, const struct wined3d_resource_desc
*wined3d_desc
, UINT sub_resource_idx
,
5126 DWORD flags
, struct wined3d_surface
**surface
)
5128 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
5129 struct ddraw_surface
*tex_root
= container_parent
;
5130 DDSURFACEDESC2 desc
= tex_root
->surface_desc
;
5131 struct ddraw_surface
*ddraw_surface
;
5134 TRACE("device_parent %p, container_parent %p, wined3d_desc %p, sub_resource_idx %u, flags %#x, surface %p.\n",
5135 device_parent
, container_parent
, wined3d_desc
, sub_resource_idx
, flags
, surface
);
5137 /* The ddraw root surface is created before the wined3d texture. */
5138 if (!sub_resource_idx
)
5140 ddraw_surface
= tex_root
;
5144 desc
.dwWidth
= wined3d_desc
->width
;
5145 desc
.dwHeight
= wined3d_desc
->height
;
5147 /* FIXME: Validate that format, usage, pool, etc. really make sense. */
5148 if (FAILED(hr
= ddraw_create_surface(ddraw
, &desc
, flags
, &ddraw_surface
, tex_root
->version
)))
5152 *surface
= ddraw_surface
->wined3d_surface
;
5153 wined3d_surface_incref(*surface
);
5158 static void STDMETHODCALLTYPE
ddraw_frontbuffer_destroyed(void *parent
)
5160 struct ddraw
*ddraw
= parent
;
5161 ddraw
->wined3d_frontbuffer
= NULL
;
5164 static const struct wined3d_parent_ops ddraw_frontbuffer_parent_ops
=
5166 ddraw_frontbuffer_destroyed
,
5169 static HRESULT CDECL
device_parent_create_swapchain_surface(struct wined3d_device_parent
*device_parent
,
5170 void *container_parent
, const struct wined3d_resource_desc
*desc
, struct wined3d_surface
**surface
)
5172 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
5175 TRACE("device_parent %p, container_parent %p, desc %p, surface %p.\n",
5176 device_parent
, container_parent
, desc
, surface
);
5178 if (ddraw
->wined3d_frontbuffer
)
5180 ERR("Frontbuffer already created.\n");
5184 if (SUCCEEDED(hr
= wined3d_surface_create(ddraw
->wined3d_device
, desc
->width
, desc
->height
, desc
->format
,
5185 desc
->usage
, desc
->pool
, desc
->multisample_type
, desc
->multisample_quality
, WINED3D_SURFACE_MAPPABLE
,
5186 ddraw
, &ddraw_frontbuffer_parent_ops
, surface
)))
5187 ddraw
->wined3d_frontbuffer
= *surface
;
5192 static HRESULT CDECL
device_parent_create_volume(struct wined3d_device_parent
*device_parent
,
5193 void *container_parent
, UINT width
, UINT height
, UINT depth
, enum wined3d_format_id format
,
5194 enum wined3d_pool pool
, DWORD usage
, struct wined3d_volume
**volume
)
5196 TRACE("device_parent %p, container_parent %p, width %u, height %u, depth %u, "
5197 "format %#x, pool %#x, usage %#x, volume %p.\n",
5198 device_parent
, container_parent
, width
, height
, depth
,
5199 format
, pool
, usage
, volume
);
5201 ERR("Not implemented!\n");
5206 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
5207 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
5209 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
5212 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent
, desc
, swapchain
);
5214 if (ddraw
->wined3d_swapchain
)
5216 ERR("Swapchain already created.\n");
5220 if (FAILED(hr
= wined3d_swapchain_create(ddraw
->wined3d_device
, desc
, NULL
,
5221 &ddraw_null_wined3d_parent_ops
, swapchain
)))
5222 WARN("Failed to create swapchain, hr %#x.\n", hr
);
5227 static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops
=
5229 device_parent_wined3d_device_created
,
5230 device_parent_mode_changed
,
5231 device_parent_create_swapchain_surface
,
5232 device_parent_create_texture_surface
,
5233 device_parent_create_volume
,
5234 device_parent_create_swapchain
,
5237 HRESULT
ddraw_init(struct ddraw
*ddraw
, enum wined3d_device_type device_type
)
5243 ddraw
->IDirectDraw7_iface
.lpVtbl
= &ddraw7_vtbl
;
5244 ddraw
->IDirectDraw_iface
.lpVtbl
= &ddraw1_vtbl
;
5245 ddraw
->IDirectDraw2_iface
.lpVtbl
= &ddraw2_vtbl
;
5246 ddraw
->IDirectDraw4_iface
.lpVtbl
= &ddraw4_vtbl
;
5247 ddraw
->IDirect3D_iface
.lpVtbl
= &d3d1_vtbl
;
5248 ddraw
->IDirect3D2_iface
.lpVtbl
= &d3d2_vtbl
;
5249 ddraw
->IDirect3D3_iface
.lpVtbl
= &d3d3_vtbl
;
5250 ddraw
->IDirect3D7_iface
.lpVtbl
= &d3d7_vtbl
;
5251 ddraw
->device_parent
.ops
= &ddraw_wined3d_device_parent_ops
;
5252 ddraw
->numIfaces
= 1;
5255 flags
= WINED3D_LEGACY_DEPTH_BIAS
| WINED3D_VIDMEM_ACCOUNTING
;
5256 if (!(ddraw
->wined3d
= wined3d_create(7, flags
)))
5258 if (!(ddraw
->wined3d
= wined3d_create(7, flags
| WINED3D_NO3D
)))
5260 WARN("Failed to create a wined3d object.\n");
5265 if (FAILED(hr
= wined3d_get_device_caps(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
, &caps
)))
5267 ERR("Failed to get device caps, hr %#x.\n", hr
);
5268 wined3d_decref(ddraw
->wined3d
);
5272 if (!(caps
.ddraw_caps
.caps
& WINEDDCAPS_3D
))
5274 WARN("Created a wined3d object without 3D support.\n");
5275 ddraw
->flags
|= DDRAW_NO3D
;
5278 hr
= wined3d_device_create(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
,
5279 NULL
, 0, 8, &ddraw
->device_parent
, &ddraw
->wined3d_device
);
5282 WARN("Failed to create a wined3d device, hr %#x.\n", hr
);
5283 wined3d_decref(ddraw
->wined3d
);
5287 list_init(&ddraw
->surface_list
);