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 if (ddraw
->flags
& DDRAW_SCL_RECURSIVE
)
783 WARN("Recursive call, returning DD_OK.\n");
787 ddraw
->flags
|= DDRAW_SCL_RECURSIVE
;
789 /* Tests suggest that we need one of them: */
790 if(!(cooplevel
& (DDSCL_SETFOCUSWINDOW
|
794 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
795 hr
= DDERR_INVALIDPARAMS
;
799 if ((cooplevel
& DDSCL_CREATEDEVICEWINDOW
) && !(cooplevel
& DDSCL_EXCLUSIVE
))
801 WARN("DDSCL_CREATEDEVICEWINDOW requires DDSCL_EXCLUSIVE.\n");
802 hr
= DDERR_INVALIDPARAMS
;
806 /* Handle those levels first which set various hwnds */
807 if ((cooplevel
& DDSCL_SETFOCUSWINDOW
) && !(cooplevel
& DDSCL_CREATEDEVICEWINDOW
))
809 /* This isn't compatible with a lot of flags */
810 if (cooplevel
& (DDSCL_MULTITHREADED
815 | DDSCL_SETDEVICEWINDOW
820 WARN("Called with incompatible flags, returning DDERR_INVALIDPARAMS.\n");
821 hr
= DDERR_INVALIDPARAMS
;
825 hr
= ddraw_set_focus_window(ddraw
, window
);
829 if (cooplevel
& DDSCL_EXCLUSIVE
)
831 if (!(cooplevel
& DDSCL_FULLSCREEN
) || !(window
|| (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)))
833 WARN("DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN and a window.\n");
834 hr
= DDERR_INVALIDPARAMS
;
838 if (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)
842 if (!ddraw
->focuswindow
&& !(cooplevel
& DDSCL_SETFOCUSWINDOW
))
844 WARN("No focus window set.\n");
845 hr
= DDERR_NOFOCUSWINDOW
;
849 device_window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "DirectDrawDeviceWnd",
850 WS_POPUP
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
851 NULL
, NULL
, NULL
, NULL
);
854 ERR("Failed to create window, last error %#x.\n", GetLastError());
859 ShowWindow(device_window
, SW_SHOW
);
860 TRACE("Created a device window %p.\n", device_window
);
862 /* Native apparently leaks the created device window if setting the
863 * focus window below fails. */
864 ddraw
->cooperative_level
|= DDSCL_CREATEDEVICEWINDOW
;
865 ddraw
->devicewindow
= device_window
;
867 if (cooplevel
& DDSCL_SETFOCUSWINDOW
)
875 if (FAILED(hr
= ddraw_set_focus_window(ddraw
, window
)))
879 window
= device_window
;
884 if (ddraw
->cooperative_level
& DDSCL_CREATEDEVICEWINDOW
)
885 DestroyWindow(ddraw
->devicewindow
);
886 ddraw
->devicewindow
= NULL
;
887 ddraw
->focuswindow
= NULL
;
890 if ((cooplevel
& DDSCL_FULLSCREEN
) != (ddraw
->cooperative_level
& DDSCL_FULLSCREEN
) || window
!= ddraw
->dest_window
)
892 if (ddraw
->cooperative_level
& DDSCL_FULLSCREEN
)
893 wined3d_device_restore_fullscreen_window(ddraw
->wined3d_device
, ddraw
->dest_window
);
895 if (cooplevel
& DDSCL_FULLSCREEN
)
897 struct wined3d_display_mode display_mode
;
899 wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &display_mode
, NULL
);
900 wined3d_device_setup_fullscreen_window(ddraw
->wined3d_device
, window
,
901 display_mode
.width
, display_mode
.height
);
905 if (cooplevel
& DDSCL_MULTITHREADED
&& !(ddraw
->cooperative_level
& DDSCL_MULTITHREADED
))
906 wined3d_device_set_multithreaded(ddraw
->wined3d_device
);
908 if (ddraw
->wined3d_swapchain
)
910 if (!(ddraw
->flags
& DDRAW_NO3D
))
912 restore_state
= TRUE
;
914 if (FAILED(hr
= wined3d_stateblock_create(ddraw
->wined3d_device
, WINED3D_SBT_ALL
, &stateblock
)))
916 ERR("Failed to create stateblock, hr %#x.\n", hr
);
920 wined3d_stateblock_capture(stateblock
);
921 rt
= wined3d_device_get_render_target(ddraw
->wined3d_device
, 0);
922 if (rt
== ddraw
->wined3d_frontbuffer
)
925 wined3d_surface_incref(rt
);
927 if ((ds
= wined3d_device_get_depth_stencil(ddraw
->wined3d_device
)))
928 wined3d_surface_incref(ds
);
931 ddraw_destroy_swapchain(ddraw
);
934 if (FAILED(hr
= ddraw_create_swapchain(ddraw
, window
, !(cooplevel
& DDSCL_FULLSCREEN
))))
935 ERR("Failed to create swapchain, hr %#x.\n", hr
);
941 wined3d_device_set_depth_stencil(ddraw
->wined3d_device
, ds
);
942 wined3d_surface_decref(ds
);
947 wined3d_device_set_render_target(ddraw
->wined3d_device
, 0, rt
, FALSE
);
948 wined3d_surface_decref(rt
);
951 wined3d_stateblock_apply(stateblock
);
952 wined3d_stateblock_decref(stateblock
);
955 if (!(cooplevel
& DDSCL_EXCLUSIVE
) && (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
956 && restore_mode_on_normal
)
958 hr
= ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
960 ERR("RestoreDisplayMode failed\n");
963 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
964 && (window
!= ddraw
->dest_window
|| !(cooplevel
& DDSCL_EXCLUSIVE
)))
965 wined3d_device_release_focus_window(ddraw
->wined3d_device
);
967 if ((cooplevel
& DDSCL_EXCLUSIVE
)
968 && (window
!= ddraw
->dest_window
|| !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)))
970 hr
= wined3d_device_acquire_focus_window(ddraw
->wined3d_device
, window
);
973 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
978 /* Unhandled flags */
979 if (cooplevel
& DDSCL_ALLOWREBOOT
)
980 WARN("Unhandled flag DDSCL_ALLOWREBOOT, harmless\n");
981 if (cooplevel
& DDSCL_ALLOWMODEX
)
982 WARN("Unhandled flag DDSCL_ALLOWMODEX, harmless\n");
983 if (cooplevel
& DDSCL_FPUSETUP
)
984 WARN("Unhandled flag DDSCL_FPUSETUP, harmless\n");
986 if (cooplevel
& DDSCL_EXCLUSIVE
)
987 exclusive_ddraw
= ddraw
;
988 else if (exclusive_ddraw
== ddraw
)
989 exclusive_ddraw
= NULL
;
991 /* Store the cooperative_level */
992 ddraw
->cooperative_level
= cooplevel
;
993 ddraw
->dest_window
= window
;
995 TRACE("SetCooperativeLevel retuning DD_OK\n");
998 ddraw
->flags
&= ~DDRAW_SCL_RECURSIVE
;
999 wined3d_mutex_unlock();
1004 static HRESULT WINAPI
ddraw7_SetCooperativeLevel(IDirectDraw7
*iface
, HWND window
, DWORD flags
)
1006 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1008 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1010 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1013 static HRESULT WINAPI
ddraw4_SetCooperativeLevel(IDirectDraw4
*iface
, HWND window
, DWORD flags
)
1015 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1017 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1019 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1022 static HRESULT WINAPI
ddraw2_SetCooperativeLevel(IDirectDraw2
*iface
, HWND window
, DWORD flags
)
1024 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1026 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1028 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1031 static HRESULT WINAPI
ddraw1_SetCooperativeLevel(IDirectDraw
*iface
, HWND window
, DWORD flags
)
1033 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1036 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1038 hr
= ddraw_set_cooperative_level(ddraw
, window
, flags
, FALSE
);
1040 ddraw
->flags
|= DDRAW_SCL_DDRAW1
;
1044 /*****************************************************************************
1045 * IDirectDraw7::SetDisplayMode
1047 * Sets the display screen resolution, color depth and refresh frequency
1048 * when in fullscreen mode (in theory).
1049 * Possible return values listed in the SDK suggest that this method fails
1050 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
1051 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
1052 * It seems to be valid to pass 0 for With and Height, this has to be tested
1053 * It could mean that the current video mode should be left as-is. (But why
1057 * Height, Width: Screen dimension
1058 * BPP: Color depth in Bits per pixel
1059 * Refreshrate: Screen refresh rate
1060 * Flags: Other stuff
1065 *****************************************************************************/
1066 static HRESULT WINAPI
ddraw7_SetDisplayMode(IDirectDraw7
*iface
, DWORD width
, DWORD height
,
1067 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1069 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1070 struct wined3d_display_mode mode
;
1071 enum wined3d_format_id format
;
1074 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1075 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1077 if (force_refresh_rate
!= 0)
1079 TRACE("ForceRefreshRate overriding passed-in refresh rate (%u Hz) to %u Hz\n",
1080 refresh_rate
, force_refresh_rate
);
1081 refresh_rate
= force_refresh_rate
;
1084 wined3d_mutex_lock();
1086 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
1088 wined3d_mutex_unlock();
1089 return DDERR_NOEXCLUSIVEMODE
;
1092 if (!width
|| !height
)
1094 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here. */
1095 wined3d_mutex_unlock();
1099 if (!restore_mode
&& FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
,
1100 WINED3DADAPTER_DEFAULT
, &original_mode
, NULL
)))
1101 ERR("Failed to get current display mode, hr %#x.\n", hr
);
1105 case 8: format
= WINED3DFMT_P8_UINT
; break;
1106 case 15: format
= WINED3DFMT_B5G5R5X1_UNORM
; break;
1107 case 16: format
= WINED3DFMT_B5G6R5_UNORM
; break;
1108 case 24: format
= WINED3DFMT_B8G8R8_UNORM
; break;
1109 case 32: format
= WINED3DFMT_B8G8R8X8_UNORM
; break;
1110 default: format
= WINED3DFMT_UNKNOWN
; break;
1114 mode
.height
= height
;
1115 mode
.refresh_rate
= refresh_rate
;
1116 mode
.format_id
= format
;
1117 mode
.scanline_ordering
= WINED3D_SCANLINE_ORDERING_UNKNOWN
;
1119 /* TODO: The possible return values from msdn suggest that the screen mode
1120 * can't be changed if a surface is locked or some drawing is in progress. */
1121 /* TODO: Lose the primary surface. */
1122 if (SUCCEEDED(hr
= wined3d_set_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
)))
1124 ddraw
->flags
|= DDRAW_RESTORE_MODE
;
1125 restore_mode
= TRUE
;
1128 wined3d_mutex_unlock();
1132 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1137 static HRESULT WINAPI
ddraw4_SetDisplayMode(IDirectDraw4
*iface
, DWORD width
, DWORD height
,
1138 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1140 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1142 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1143 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1145 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1148 static HRESULT WINAPI
ddraw2_SetDisplayMode(IDirectDraw2
*iface
,
1149 DWORD width
, DWORD height
, DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1151 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1153 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1154 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1156 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1159 static HRESULT WINAPI
ddraw1_SetDisplayMode(IDirectDraw
*iface
, DWORD width
, DWORD height
, DWORD bpp
)
1161 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1163 TRACE("iface %p, width %u, height %u, bpp %u.\n", iface
, width
, height
, bpp
);
1165 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, 0, 0);
1168 void ddraw_d3dcaps1_from_7(D3DDEVICEDESC
*caps1
, D3DDEVICEDESC7
*caps7
)
1170 memset(caps1
, 0, sizeof(*caps1
));
1171 caps1
->dwSize
= sizeof(*caps1
);
1172 caps1
->dwFlags
= D3DDD_COLORMODEL
1174 | D3DDD_TRANSFORMCAPS
1176 | D3DDD_LIGHTINGCAPS
1179 | D3DDD_DEVICERENDERBITDEPTH
1180 | D3DDD_DEVICEZBUFFERBITDEPTH
1181 | D3DDD_MAXBUFFERSIZE
1182 | D3DDD_MAXVERTEXCOUNT
;
1183 caps1
->dcmColorModel
= D3DCOLOR_RGB
;
1184 caps1
->dwDevCaps
= caps7
->dwDevCaps
;
1185 caps1
->dtcTransformCaps
.dwSize
= sizeof(caps1
->dtcTransformCaps
);
1186 caps1
->dtcTransformCaps
.dwCaps
= D3DTRANSFORMCAPS_CLIP
;
1187 caps1
->bClipping
= TRUE
;
1188 caps1
->dlcLightingCaps
.dwSize
= sizeof(caps1
->dlcLightingCaps
);
1189 caps1
->dlcLightingCaps
.dwCaps
= D3DLIGHTCAPS_DIRECTIONAL
1190 | D3DLIGHTCAPS_PARALLELPOINT
1191 | D3DLIGHTCAPS_POINT
1192 | D3DLIGHTCAPS_SPOT
;
1193 caps1
->dlcLightingCaps
.dwLightingModel
= D3DLIGHTINGMODEL_RGB
;
1194 caps1
->dlcLightingCaps
.dwNumLights
= caps7
->dwMaxActiveLights
;
1195 caps1
->dpcLineCaps
= caps7
->dpcLineCaps
;
1196 caps1
->dpcTriCaps
= caps7
->dpcTriCaps
;
1197 caps1
->dwDeviceRenderBitDepth
= caps7
->dwDeviceRenderBitDepth
;
1198 caps1
->dwDeviceZBufferBitDepth
= caps7
->dwDeviceZBufferBitDepth
;
1199 caps1
->dwMaxBufferSize
= 0;
1200 caps1
->dwMaxVertexCount
= 65536;
1201 caps1
->dwMinTextureWidth
= caps7
->dwMinTextureWidth
;
1202 caps1
->dwMinTextureHeight
= caps7
->dwMinTextureHeight
;
1203 caps1
->dwMaxTextureWidth
= caps7
->dwMaxTextureWidth
;
1204 caps1
->dwMaxTextureHeight
= caps7
->dwMaxTextureHeight
;
1205 caps1
->dwMinStippleWidth
= 1;
1206 caps1
->dwMinStippleHeight
= 1;
1207 caps1
->dwMaxStippleWidth
= 32;
1208 caps1
->dwMaxStippleHeight
= 32;
1209 caps1
->dwMaxTextureRepeat
= caps7
->dwMaxTextureRepeat
;
1210 caps1
->dwMaxTextureAspectRatio
= caps7
->dwMaxTextureAspectRatio
;
1211 caps1
->dwMaxAnisotropy
= caps7
->dwMaxAnisotropy
;
1212 caps1
->dvGuardBandLeft
= caps7
->dvGuardBandLeft
;
1213 caps1
->dvGuardBandTop
= caps7
->dvGuardBandTop
;
1214 caps1
->dvGuardBandRight
= caps7
->dvGuardBandRight
;
1215 caps1
->dvGuardBandBottom
= caps7
->dvGuardBandBottom
;
1216 caps1
->dvExtentsAdjust
= caps7
->dvExtentsAdjust
;
1217 caps1
->dwStencilCaps
= caps7
->dwStencilCaps
;
1218 caps1
->dwFVFCaps
= caps7
->dwFVFCaps
;
1219 caps1
->dwTextureOpCaps
= caps7
->dwTextureOpCaps
;
1220 caps1
->wMaxTextureBlendStages
= caps7
->wMaxTextureBlendStages
;
1221 caps1
->wMaxSimultaneousTextures
= caps7
->wMaxSimultaneousTextures
;
1224 HRESULT
ddraw_get_d3dcaps(const struct ddraw
*ddraw
, D3DDEVICEDESC7
*caps
)
1226 WINED3DCAPS wined3d_caps
;
1229 TRACE("ddraw %p, caps %p.\n", ddraw
, caps
);
1231 memset(&wined3d_caps
, 0, sizeof(wined3d_caps
));
1233 wined3d_mutex_lock();
1234 hr
= wined3d_get_device_caps(ddraw
->wined3d
, 0, WINED3D_DEVICE_TYPE_HAL
, &wined3d_caps
);
1235 wined3d_mutex_unlock();
1238 WARN("Failed to get device caps, hr %#x.\n", hr
);
1242 caps
->dwDevCaps
= wined3d_caps
.DevCaps
;
1243 caps
->dpcLineCaps
.dwMiscCaps
= wined3d_caps
.PrimitiveMiscCaps
;
1244 caps
->dpcLineCaps
.dwRasterCaps
= wined3d_caps
.RasterCaps
;
1245 caps
->dpcLineCaps
.dwZCmpCaps
= wined3d_caps
.ZCmpCaps
;
1246 caps
->dpcLineCaps
.dwSrcBlendCaps
= wined3d_caps
.SrcBlendCaps
;
1247 caps
->dpcLineCaps
.dwDestBlendCaps
= wined3d_caps
.DestBlendCaps
;
1248 caps
->dpcLineCaps
.dwAlphaCmpCaps
= wined3d_caps
.AlphaCmpCaps
;
1249 caps
->dpcLineCaps
.dwShadeCaps
= wined3d_caps
.ShadeCaps
;
1250 caps
->dpcLineCaps
.dwTextureCaps
= wined3d_caps
.TextureCaps
;
1251 caps
->dpcLineCaps
.dwTextureFilterCaps
= wined3d_caps
.TextureFilterCaps
;
1252 caps
->dpcLineCaps
.dwTextureAddressCaps
= wined3d_caps
.TextureAddressCaps
;
1254 caps
->dwMaxTextureWidth
= wined3d_caps
.MaxTextureWidth
;
1255 caps
->dwMaxTextureHeight
= wined3d_caps
.MaxTextureHeight
;
1257 caps
->dwMaxTextureRepeat
= wined3d_caps
.MaxTextureRepeat
;
1258 caps
->dwMaxTextureAspectRatio
= wined3d_caps
.MaxTextureAspectRatio
;
1259 caps
->dwMaxAnisotropy
= wined3d_caps
.MaxAnisotropy
;
1260 caps
->dvMaxVertexW
= wined3d_caps
.MaxVertexW
;
1262 caps
->dvGuardBandLeft
= wined3d_caps
.GuardBandLeft
;
1263 caps
->dvGuardBandTop
= wined3d_caps
.GuardBandTop
;
1264 caps
->dvGuardBandRight
= wined3d_caps
.GuardBandRight
;
1265 caps
->dvGuardBandBottom
= wined3d_caps
.GuardBandBottom
;
1267 caps
->dvExtentsAdjust
= wined3d_caps
.ExtentsAdjust
;
1268 caps
->dwStencilCaps
= wined3d_caps
.StencilCaps
;
1270 caps
->dwFVFCaps
= wined3d_caps
.FVFCaps
;
1271 caps
->dwTextureOpCaps
= wined3d_caps
.TextureOpCaps
;
1273 caps
->dwVertexProcessingCaps
= wined3d_caps
.VertexProcessingCaps
;
1274 caps
->dwMaxActiveLights
= wined3d_caps
.MaxActiveLights
;
1276 /* Remove all non-d3d7 caps */
1277 caps
->dwDevCaps
&= (
1278 D3DDEVCAPS_FLOATTLVERTEX
| D3DDEVCAPS_SORTINCREASINGZ
| D3DDEVCAPS_SORTDECREASINGZ
|
1279 D3DDEVCAPS_SORTEXACT
| D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
|
1280 D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
| D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
|
1281 D3DDEVCAPS_TEXTUREVIDEOMEMORY
| D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
|
1282 D3DDEVCAPS_TEXTURENONLOCALVIDMEM
| D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
1283 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
1284 D3DDEVCAPS_HWRASTERIZATION
);
1286 caps
->dwStencilCaps
&= (
1287 D3DSTENCILCAPS_KEEP
| D3DSTENCILCAPS_ZERO
| D3DSTENCILCAPS_REPLACE
|
1288 D3DSTENCILCAPS_INCRSAT
| D3DSTENCILCAPS_DECRSAT
| D3DSTENCILCAPS_INVERT
|
1289 D3DSTENCILCAPS_INCR
| D3DSTENCILCAPS_DECR
);
1293 caps
->dwTextureOpCaps
&= (
1294 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_SELECTARG2
|
1295 D3DTEXOPCAPS_MODULATE
| D3DTEXOPCAPS_MODULATE2X
| D3DTEXOPCAPS_MODULATE4X
|
1296 D3DTEXOPCAPS_ADD
| D3DTEXOPCAPS_ADDSIGNED
| D3DTEXOPCAPS_ADDSIGNED2X
|
1297 D3DTEXOPCAPS_SUBTRACT
| D3DTEXOPCAPS_ADDSMOOTH
| D3DTEXOPCAPS_BLENDTEXTUREALPHA
|
1298 D3DTEXOPCAPS_BLENDFACTORALPHA
| D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
| D3DTEXOPCAPS_BLENDCURRENTALPHA
|
1299 D3DTEXOPCAPS_PREMODULATE
| D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
|
1300 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
| D3DTEXOPCAPS_BUMPENVMAP
|
1301 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
| D3DTEXOPCAPS_DOTPRODUCT3
);
1303 caps
->dwVertexProcessingCaps
&= (
1304 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_VERTEXFOG
|
1305 D3DVTXPCAPS_DIRECTIONALLIGHTS
| D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
);
1307 caps
->dpcLineCaps
.dwMiscCaps
&= (
1308 D3DPMISCCAPS_MASKPLANES
| D3DPMISCCAPS_MASKZ
| D3DPMISCCAPS_LINEPATTERNREP
|
1309 D3DPMISCCAPS_CONFORMANT
| D3DPMISCCAPS_CULLNONE
| D3DPMISCCAPS_CULLCW
|
1310 D3DPMISCCAPS_CULLCCW
);
1312 caps
->dpcLineCaps
.dwRasterCaps
&= (
1313 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ROP2
| D3DPRASTERCAPS_XOR
|
1314 D3DPRASTERCAPS_PAT
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_SUBPIXEL
|
1315 D3DPRASTERCAPS_SUBPIXELX
| D3DPRASTERCAPS_FOGVERTEX
| D3DPRASTERCAPS_FOGTABLE
|
1316 D3DPRASTERCAPS_STIPPLE
| D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT
| D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT
|
1317 D3DPRASTERCAPS_ANTIALIASEDGES
| D3DPRASTERCAPS_MIPMAPLODBIAS
| D3DPRASTERCAPS_ZBIAS
|
1318 D3DPRASTERCAPS_ZBUFFERLESSHSR
| D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
|
1319 D3DPRASTERCAPS_WBUFFER
| D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT
| D3DPRASTERCAPS_WFOG
|
1320 D3DPRASTERCAPS_ZFOG
);
1322 caps
->dpcLineCaps
.dwZCmpCaps
&= (
1323 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
1324 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
1325 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
1327 caps
->dpcLineCaps
.dwSrcBlendCaps
&= (
1328 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
1329 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
1330 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
1331 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
1332 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
1334 caps
->dpcLineCaps
.dwDestBlendCaps
&= (
1335 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
1336 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
1337 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
1338 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
1339 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
1341 caps
->dpcLineCaps
.dwAlphaCmpCaps
&= (
1342 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
1343 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
1344 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
1346 caps
->dpcLineCaps
.dwShadeCaps
&= (
1347 D3DPSHADECAPS_COLORFLATMONO
| D3DPSHADECAPS_COLORFLATRGB
| D3DPSHADECAPS_COLORGOURAUDMONO
|
1348 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_COLORPHONGMONO
| D3DPSHADECAPS_COLORPHONGRGB
|
1349 D3DPSHADECAPS_SPECULARFLATMONO
| D3DPSHADECAPS_SPECULARFLATRGB
| D3DPSHADECAPS_SPECULARGOURAUDMONO
|
1350 D3DPSHADECAPS_SPECULARGOURAUDRGB
| D3DPSHADECAPS_SPECULARPHONGMONO
| D3DPSHADECAPS_SPECULARPHONGRGB
|
1351 D3DPSHADECAPS_ALPHAFLATBLEND
| D3DPSHADECAPS_ALPHAFLATSTIPPLED
| D3DPSHADECAPS_ALPHAGOURAUDBLEND
|
1352 D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED
| D3DPSHADECAPS_ALPHAPHONGBLEND
| D3DPSHADECAPS_ALPHAPHONGSTIPPLED
|
1353 D3DPSHADECAPS_FOGFLAT
| D3DPSHADECAPS_FOGGOURAUD
| D3DPSHADECAPS_FOGPHONG
);
1355 caps
->dpcLineCaps
.dwTextureCaps
&= (
1356 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
1357 D3DPTEXTURECAPS_TRANSPARENCY
| D3DPTEXTURECAPS_BORDER
| D3DPTEXTURECAPS_SQUAREONLY
|
1358 D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
| D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
1359 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_COLORKEYBLEND
);
1361 caps
->dpcLineCaps
.dwTextureFilterCaps
&= (
1362 D3DPTFILTERCAPS_NEAREST
| D3DPTFILTERCAPS_LINEAR
| D3DPTFILTERCAPS_MIPNEAREST
|
1363 D3DPTFILTERCAPS_MIPLINEAR
| D3DPTFILTERCAPS_LINEARMIPNEAREST
| D3DPTFILTERCAPS_LINEARMIPLINEAR
|
1364 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
1365 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
1366 D3DPTFILTERCAPS_MAGFLINEAR
| D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
|
1367 D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
);
1369 caps
->dpcLineCaps
.dwTextureAddressCaps
&= (
1370 D3DPTADDRESSCAPS_WRAP
| D3DPTADDRESSCAPS_MIRROR
| D3DPTADDRESSCAPS_CLAMP
|
1371 D3DPTADDRESSCAPS_BORDER
| D3DPTADDRESSCAPS_INDEPENDENTUV
);
1373 if (!(caps
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
))
1375 /* DirectX7 always has the np2 flag set, no matter what the card
1376 * supports. Some old games (Rollcage) check the caps incorrectly.
1377 * If wined3d supports nonpow2 textures it also has np2 conditional
1379 caps
->dpcLineCaps
.dwTextureCaps
|= D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
;
1382 /* Fill the missing members, and do some fixup */
1383 caps
->dpcLineCaps
.dwSize
= sizeof(caps
->dpcLineCaps
);
1384 caps
->dpcLineCaps
.dwTextureBlendCaps
= D3DPTBLENDCAPS_ADD
1385 | D3DPTBLENDCAPS_MODULATEMASK
1386 | D3DPTBLENDCAPS_COPY
1387 | D3DPTBLENDCAPS_DECAL
1388 | D3DPTBLENDCAPS_DECALALPHA
1389 | D3DPTBLENDCAPS_DECALMASK
1390 | D3DPTBLENDCAPS_MODULATE
1391 | D3DPTBLENDCAPS_MODULATEALPHA
;
1392 caps
->dpcLineCaps
.dwStippleWidth
= 32;
1393 caps
->dpcLineCaps
.dwStippleHeight
= 32;
1394 /* Use the same for the TriCaps */
1395 caps
->dpcTriCaps
= caps
->dpcLineCaps
;
1397 caps
->dwDeviceRenderBitDepth
= DDBD_16
| DDBD_24
| DDBD_32
;
1398 caps
->dwDeviceZBufferBitDepth
= DDBD_16
| DDBD_24
;
1399 caps
->dwMinTextureWidth
= 1;
1400 caps
->dwMinTextureHeight
= 1;
1402 /* Convert DWORDs safely to WORDs */
1403 if (wined3d_caps
.MaxTextureBlendStages
> 0xffff)
1404 caps
->wMaxTextureBlendStages
= 0xffff;
1406 caps
->wMaxTextureBlendStages
= (WORD
)wined3d_caps
.MaxTextureBlendStages
;
1407 if (wined3d_caps
.MaxSimultaneousTextures
> 0xffff)
1408 caps
->wMaxSimultaneousTextures
= 0xffff;
1410 caps
->wMaxSimultaneousTextures
= (WORD
)wined3d_caps
.MaxSimultaneousTextures
;
1412 if (wined3d_caps
.MaxUserClipPlanes
> 0xffff)
1413 caps
->wMaxUserClipPlanes
= 0xffff;
1415 caps
->wMaxUserClipPlanes
= (WORD
)wined3d_caps
.MaxUserClipPlanes
;
1416 if (wined3d_caps
.MaxVertexBlendMatrices
> 0xffff)
1417 caps
->wMaxVertexBlendMatrices
= 0xffff;
1419 caps
->wMaxVertexBlendMatrices
= (WORD
)wined3d_caps
.MaxVertexBlendMatrices
;
1421 caps
->deviceGUID
= IID_IDirect3DTnLHalDevice
;
1423 caps
->dwReserved1
= 0;
1424 caps
->dwReserved2
= 0;
1425 caps
->dwReserved3
= 0;
1426 caps
->dwReserved4
= 0;
1431 /*****************************************************************************
1432 * IDirectDraw7::GetCaps
1434 * Returns the drives capabilities
1436 * Used for version 1, 2, 4 and 7
1439 * DriverCaps: Structure to write the Hardware accelerated caps to
1440 * HelCaps: Structure to write the emulation caps to
1443 * This implementation returns DD_OK only
1445 *****************************************************************************/
1446 static HRESULT WINAPI
ddraw7_GetCaps(IDirectDraw7
*iface
, DDCAPS
*DriverCaps
, DDCAPS
*HELCaps
)
1448 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1450 WINED3DCAPS winecaps
;
1452 DDSCAPS2 ddscaps
= {0, 0, 0, 0};
1454 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, DriverCaps
, HELCaps
);
1456 /* One structure must be != NULL */
1457 if (!DriverCaps
&& !HELCaps
)
1459 WARN("Invalid parameters.\n");
1460 return DDERR_INVALIDPARAMS
;
1463 memset(&caps
, 0, sizeof(caps
));
1464 memset(&winecaps
, 0, sizeof(winecaps
));
1465 caps
.dwSize
= sizeof(caps
);
1467 wined3d_mutex_lock();
1468 hr
= wined3d_device_get_device_caps(ddraw
->wined3d_device
, &winecaps
);
1471 WARN("IWineD3DDevice::GetDeviceCaps failed\n");
1472 wined3d_mutex_unlock();
1476 hr
= IDirectDraw7_GetAvailableVidMem(iface
, &ddscaps
, &caps
.dwVidMemTotal
, &caps
.dwVidMemFree
);
1477 wined3d_mutex_unlock();
1479 WARN("IDirectDraw7::GetAvailableVidMem failed\n");
1483 caps
.dwCaps
= winecaps
.ddraw_caps
.caps
;
1484 caps
.dwCaps2
= winecaps
.ddraw_caps
.caps2
;
1485 caps
.dwCKeyCaps
= winecaps
.ddraw_caps
.color_key_caps
;
1486 caps
.dwFXCaps
= winecaps
.ddraw_caps
.fx_caps
;
1487 caps
.dwPalCaps
= winecaps
.ddraw_caps
.pal_caps
;
1488 caps
.ddsCaps
.dwCaps
= winecaps
.ddraw_caps
.dds_caps
;
1489 caps
.dwSVBCaps
= winecaps
.ddraw_caps
.svb_caps
;
1490 caps
.dwSVBCKeyCaps
= winecaps
.ddraw_caps
.svb_color_key_caps
;
1491 caps
.dwSVBFXCaps
= winecaps
.ddraw_caps
.svb_fx_caps
;
1492 caps
.dwVSBCaps
= winecaps
.ddraw_caps
.vsb_caps
;
1493 caps
.dwVSBCKeyCaps
= winecaps
.ddraw_caps
.vsb_color_key_caps
;
1494 caps
.dwVSBFXCaps
= winecaps
.ddraw_caps
.vsb_fx_caps
;
1495 caps
.dwSSBCaps
= winecaps
.ddraw_caps
.ssb_caps
;
1496 caps
.dwSSBCKeyCaps
= winecaps
.ddraw_caps
.ssb_color_key_caps
;
1497 caps
.dwSSBFXCaps
= winecaps
.ddraw_caps
.ssb_fx_caps
;
1499 caps
.dwCaps
|= DDCAPS_ALIGNSTRIDE
;
1500 caps
.dwAlignStrideAlign
= DDRAW_STRIDE_ALIGNMENT
;
1504 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &caps
);
1505 if (TRACE_ON(ddraw
))
1507 TRACE("Driver Caps :\n");
1508 DDRAW_dump_DDCAPS(DriverCaps
);
1514 DD_STRUCT_COPY_BYSIZE(HELCaps
, &caps
);
1515 if (TRACE_ON(ddraw
))
1517 TRACE("HEL Caps :\n");
1518 DDRAW_dump_DDCAPS(HELCaps
);
1525 static HRESULT WINAPI
ddraw4_GetCaps(IDirectDraw4
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1527 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1529 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1531 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1534 static HRESULT WINAPI
ddraw2_GetCaps(IDirectDraw2
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1536 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1538 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1540 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1543 static HRESULT WINAPI
ddraw1_GetCaps(IDirectDraw
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1545 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1547 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1549 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1552 /*****************************************************************************
1553 * IDirectDraw7::Compact
1555 * No idea what it does, MSDN says it's not implemented.
1558 * DD_OK, but this is unchecked
1560 *****************************************************************************/
1561 static HRESULT WINAPI
ddraw7_Compact(IDirectDraw7
*iface
)
1563 TRACE("iface %p.\n", iface
);
1568 static HRESULT WINAPI
ddraw4_Compact(IDirectDraw4
*iface
)
1570 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1572 TRACE("iface %p.\n", iface
);
1574 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1577 static HRESULT WINAPI
ddraw2_Compact(IDirectDraw2
*iface
)
1579 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1581 TRACE("iface %p.\n", iface
);
1583 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1586 static HRESULT WINAPI
ddraw1_Compact(IDirectDraw
*iface
)
1588 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1590 TRACE("iface %p.\n", iface
);
1592 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1595 /*****************************************************************************
1596 * IDirectDraw7::GetDisplayMode
1598 * Returns information about the current display mode
1600 * Exists in Version 1, 2, 4 and 7
1603 * DDSD: Address of a surface description structure to write the info to
1608 *****************************************************************************/
1609 static HRESULT WINAPI
ddraw7_GetDisplayMode(IDirectDraw7
*iface
, DDSURFACEDESC2
*DDSD
)
1611 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1612 struct wined3d_display_mode mode
;
1616 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
1618 wined3d_mutex_lock();
1619 /* This seems sane */
1622 wined3d_mutex_unlock();
1623 return DDERR_INVALIDPARAMS
;
1626 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1628 ERR("Failed to get display mode, hr %#x.\n", hr
);
1629 wined3d_mutex_unlock();
1633 Size
= DDSD
->dwSize
;
1634 memset(DDSD
, 0, Size
);
1636 DDSD
->dwSize
= Size
;
1637 DDSD
->dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
1638 DDSD
->dwWidth
= mode
.width
;
1639 DDSD
->dwHeight
= mode
.height
;
1640 DDSD
->u2
.dwRefreshRate
= 60;
1641 DDSD
->ddsCaps
.dwCaps
= 0;
1642 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
1643 ddrawformat_from_wined3dformat(&DDSD
->u4
.ddpfPixelFormat
, mode
.format_id
);
1644 DDSD
->u1
.lPitch
= mode
.width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
1648 TRACE("Returning surface desc :\n");
1649 DDRAW_dump_surface_desc(DDSD
);
1652 wined3d_mutex_unlock();
1657 static HRESULT WINAPI
ddraw4_GetDisplayMode(IDirectDraw4
*iface
, DDSURFACEDESC2
*surface_desc
)
1659 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1661 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1663 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, surface_desc
);
1666 static HRESULT WINAPI
ddraw2_GetDisplayMode(IDirectDraw2
*iface
, DDSURFACEDESC
*surface_desc
)
1668 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1670 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1672 /* FIXME: Test sizes, properly convert surface_desc */
1673 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1676 static HRESULT WINAPI
ddraw1_GetDisplayMode(IDirectDraw
*iface
, DDSURFACEDESC
*surface_desc
)
1678 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1680 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1682 /* FIXME: Test sizes, properly convert surface_desc */
1683 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1686 /*****************************************************************************
1687 * IDirectDraw7::GetFourCCCodes
1689 * Returns an array of supported FourCC codes.
1691 * Exists in Version 1, 2, 4 and 7
1694 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
1695 * of enumerated codes
1696 * Codes: Pointer to an array of DWORDs where the supported codes are written
1700 * Always returns DD_OK, as it's a stub for now
1702 *****************************************************************************/
1703 static HRESULT WINAPI
ddraw7_GetFourCCCodes(IDirectDraw7
*iface
, DWORD
*NumCodes
, DWORD
*Codes
)
1705 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1706 static const enum wined3d_format_id formats
[] =
1708 WINED3DFMT_YUY2
, WINED3DFMT_UYVY
, WINED3DFMT_YV12
,
1709 WINED3DFMT_DXT1
, WINED3DFMT_DXT2
, WINED3DFMT_DXT3
, WINED3DFMT_DXT4
, WINED3DFMT_DXT5
,
1710 WINED3DFMT_ATI2N
, WINED3DFMT_NVHU
, WINED3DFMT_NVHS
1712 struct wined3d_display_mode mode
;
1713 DWORD count
= 0, i
, outsize
;
1716 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, NumCodes
, Codes
);
1718 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1720 ERR("Failed to get display mode, hr %#x.\n", hr
);
1724 outsize
= NumCodes
&& Codes
? *NumCodes
: 0;
1726 for (i
= 0; i
< (sizeof(formats
) / sizeof(formats
[0])); ++i
)
1728 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, WINED3D_DEVICE_TYPE_HAL
,
1729 mode
.format_id
, 0, WINED3D_RTYPE_SURFACE
, formats
[i
])))
1731 if (count
< outsize
)
1732 Codes
[count
] = formats
[i
];
1737 TRACE("Returning %u FourCC codes\n", count
);
1744 static HRESULT WINAPI
ddraw4_GetFourCCCodes(IDirectDraw4
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1746 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1748 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1750 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1753 static HRESULT WINAPI
ddraw2_GetFourCCCodes(IDirectDraw2
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1755 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1757 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1759 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1762 static HRESULT WINAPI
ddraw1_GetFourCCCodes(IDirectDraw
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1764 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1766 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1768 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1771 static HRESULT WINAPI
ddraw7_GetMonitorFrequency(IDirectDraw7
*iface
, DWORD
*frequency
)
1773 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1774 struct wined3d_display_mode mode
;
1777 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1779 wined3d_mutex_lock();
1780 hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
);
1781 wined3d_mutex_unlock();
1784 WARN("Failed to get display mode, hr %#x.\n", hr
);
1788 *frequency
= mode
.refresh_rate
;
1793 static HRESULT WINAPI
ddraw4_GetMonitorFrequency(IDirectDraw4
*iface
, DWORD
*frequency
)
1795 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1797 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1799 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1802 static HRESULT WINAPI
ddraw2_GetMonitorFrequency(IDirectDraw2
*iface
, DWORD
*frequency
)
1804 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1806 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1808 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1811 static HRESULT WINAPI
ddraw1_GetMonitorFrequency(IDirectDraw
*iface
, DWORD
*frequency
)
1813 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1815 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1817 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1820 static HRESULT WINAPI
ddraw7_GetVerticalBlankStatus(IDirectDraw7
*iface
, BOOL
*status
)
1822 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1823 struct wined3d_raster_status raster_status
;
1826 TRACE("iface %p, status %p.\n", iface
, status
);
1829 return DDERR_INVALIDPARAMS
;
1831 wined3d_mutex_lock();
1832 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
1833 wined3d_mutex_unlock();
1836 WARN("Failed to get raster status, hr %#x.\n", hr
);
1840 *status
= raster_status
.in_vblank
;
1845 static HRESULT WINAPI
ddraw4_GetVerticalBlankStatus(IDirectDraw4
*iface
, BOOL
*status
)
1847 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1849 TRACE("iface %p, status %p.\n", iface
, status
);
1851 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1854 static HRESULT WINAPI
ddraw2_GetVerticalBlankStatus(IDirectDraw2
*iface
, BOOL
*status
)
1856 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1858 TRACE("iface %p, status %p.\n", iface
, status
);
1860 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1863 static HRESULT WINAPI
ddraw1_GetVerticalBlankStatus(IDirectDraw
*iface
, BOOL
*status
)
1865 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1867 TRACE("iface %p, status %p.\n", iface
, status
);
1869 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1872 /*****************************************************************************
1873 * IDirectDraw7::GetAvailableVidMem
1875 * Returns the total and free video memory
1878 * Caps: Specifies the memory type asked for
1879 * total: Pointer to a DWORD to be filled with the total memory
1880 * free: Pointer to a DWORD to be filled with the free memory
1884 * DDERR_INVALIDPARAMS of free and total are NULL
1886 *****************************************************************************/
1887 static HRESULT WINAPI
ddraw7_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*Caps
, DWORD
*total
,
1890 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1893 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, Caps
, total
, free
);
1895 if (TRACE_ON(ddraw
))
1897 TRACE("Asked for memory with description: ");
1898 DDRAW_dump_DDSCAPS2(Caps
);
1900 wined3d_mutex_lock();
1902 /* Todo: System memory vs local video memory vs non-local video memory
1903 * The MSDN also mentions differences between texture memory and other
1904 * resources, but that's not important
1907 if( (!total
) && (!free
) )
1909 wined3d_mutex_unlock();
1910 return DDERR_INVALIDPARAMS
;
1914 *free
= wined3d_device_get_available_texture_mem(ddraw
->wined3d_device
);
1917 struct wined3d_adapter_identifier desc
= {0};
1919 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0, &desc
);
1920 *total
= desc
.video_memory
;
1923 wined3d_mutex_unlock();
1928 static HRESULT WINAPI
ddraw4_GetAvailableVidMem(IDirectDraw4
*iface
,
1929 DDSCAPS2
*caps
, DWORD
*total
, DWORD
*free
)
1931 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1933 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1935 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, caps
, total
, free
);
1938 static HRESULT WINAPI
ddraw2_GetAvailableVidMem(IDirectDraw2
*iface
,
1939 DDSCAPS
*caps
, DWORD
*total
, DWORD
*free
)
1941 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1944 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1946 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
1947 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, &caps2
, total
, free
);
1950 /*****************************************************************************
1951 * IDirectDraw7::Initialize
1953 * Initializes a DirectDraw interface.
1956 * GUID: Interface identifier. Well, don't know what this is really good
1960 * Returns DD_OK on the first call,
1961 * DDERR_ALREADYINITIALIZED on repeated calls
1963 *****************************************************************************/
1964 static HRESULT WINAPI
ddraw7_Initialize(IDirectDraw7
*iface
, GUID
*guid
)
1966 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1968 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1970 if (ddraw
->flags
& DDRAW_INITIALIZED
)
1971 return DDERR_ALREADYINITIALIZED
;
1973 /* FIXME: To properly take the GUID into account we should call
1974 * ddraw_init() here instead of in DDRAW_Create(). */
1976 FIXME("Ignoring guid %s.\n", debugstr_guid(guid
));
1978 ddraw
->flags
|= DDRAW_INITIALIZED
;
1982 static HRESULT WINAPI
ddraw4_Initialize(IDirectDraw4
*iface
, GUID
*guid
)
1984 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1986 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1988 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
1991 static HRESULT WINAPI
ddraw2_Initialize(IDirectDraw2
*iface
, GUID
*guid
)
1993 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1995 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1997 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2000 static HRESULT WINAPI
ddraw1_Initialize(IDirectDraw
*iface
, GUID
*guid
)
2002 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2004 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2006 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2009 static HRESULT WINAPI
d3d1_Initialize(IDirect3D
*iface
, REFIID riid
)
2011 TRACE("iface %p, riid %s.\n", iface
, debugstr_guid(riid
));
2013 return DDERR_ALREADYINITIALIZED
;
2016 /*****************************************************************************
2017 * IDirectDraw7::FlipToGDISurface
2019 * "Makes the surface that the GDI writes to the primary surface"
2020 * Looks like some windows specific thing we don't have to care about.
2021 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
2022 * show error boxes ;)
2023 * Well, just return DD_OK.
2026 * Always returns DD_OK
2028 *****************************************************************************/
2029 static HRESULT WINAPI
ddraw7_FlipToGDISurface(IDirectDraw7
*iface
)
2031 FIXME("iface %p stub!\n", iface
);
2036 static HRESULT WINAPI
ddraw4_FlipToGDISurface(IDirectDraw4
*iface
)
2038 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2040 TRACE("iface %p.\n", iface
);
2042 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2045 static HRESULT WINAPI
ddraw2_FlipToGDISurface(IDirectDraw2
*iface
)
2047 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2049 TRACE("iface %p.\n", iface
);
2051 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2054 static HRESULT WINAPI
ddraw1_FlipToGDISurface(IDirectDraw
*iface
)
2056 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2058 TRACE("iface %p.\n", iface
);
2060 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2063 /*****************************************************************************
2064 * IDirectDraw7::WaitForVerticalBlank
2066 * This method allows applications to get in sync with the vertical blank
2068 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
2069 * redraw the screen, most likely because of this stub
2072 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
2073 * or DDWAITVB_BLOCKEND
2074 * h: Not used, according to MSDN
2077 * Always returns DD_OK
2079 *****************************************************************************/
2080 static HRESULT WINAPI
ddraw7_WaitForVerticalBlank(IDirectDraw7
*iface
, DWORD Flags
, HANDLE event
)
2084 TRACE("iface %p, flags %#x, event %p.\n", iface
, Flags
, event
);
2086 /* This function is called often, so print the fixme only once */
2089 FIXME("iface %p, flags %#x, event %p stub!\n", iface
, Flags
, event
);
2093 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
2094 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
2095 return DDERR_UNSUPPORTED
; /* unchecked */
2100 static HRESULT WINAPI
ddraw4_WaitForVerticalBlank(IDirectDraw4
*iface
, DWORD flags
, HANDLE event
)
2102 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2104 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2106 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2109 static HRESULT WINAPI
ddraw2_WaitForVerticalBlank(IDirectDraw2
*iface
, DWORD flags
, HANDLE event
)
2111 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2113 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2115 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2118 static HRESULT WINAPI
ddraw1_WaitForVerticalBlank(IDirectDraw
*iface
, DWORD flags
, HANDLE event
)
2120 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2122 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2124 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2127 static HRESULT WINAPI
ddraw7_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
2129 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2130 struct wined3d_raster_status raster_status
;
2133 TRACE("iface %p, line %p.\n", iface
, Scanline
);
2135 wined3d_mutex_lock();
2136 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
2137 wined3d_mutex_unlock();
2140 WARN("Failed to get raster status, hr %#x.\n", hr
);
2144 *Scanline
= raster_status
.scan_line
;
2146 if (raster_status
.in_vblank
)
2147 return DDERR_VERTICALBLANKINPROGRESS
;
2152 static HRESULT WINAPI
ddraw4_GetScanLine(IDirectDraw4
*iface
, DWORD
*line
)
2154 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2156 TRACE("iface %p, line %p.\n", iface
, line
);
2158 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2161 static HRESULT WINAPI
ddraw2_GetScanLine(IDirectDraw2
*iface
, DWORD
*line
)
2163 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2165 TRACE("iface %p, line %p.\n", iface
, line
);
2167 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2170 static HRESULT WINAPI
ddraw1_GetScanLine(IDirectDraw
*iface
, DWORD
*line
)
2172 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2174 TRACE("iface %p, line %p.\n", iface
, line
);
2176 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2179 /*****************************************************************************
2180 * IDirectDraw7::TestCooperativeLevel
2182 * Informs the application about the state of the video adapter, depending
2183 * on the cooperative level
2186 * DD_OK if the device is in a sane state
2187 * DDERR_NOEXCLUSIVEMODE or DDERR_EXCLUSIVEMODEALREADYSET
2188 * if the state is not correct(See below)
2190 *****************************************************************************/
2191 static HRESULT WINAPI
ddraw7_TestCooperativeLevel(IDirectDraw7
*iface
)
2193 TRACE("iface %p.\n", iface
);
2198 static HRESULT WINAPI
ddraw4_TestCooperativeLevel(IDirectDraw4
*iface
)
2200 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2202 TRACE("iface %p.\n", iface
);
2204 return ddraw7_TestCooperativeLevel(&ddraw
->IDirectDraw7_iface
);
2207 /*****************************************************************************
2208 * IDirectDraw7::GetGDISurface
2210 * Returns the surface that GDI is treating as the primary surface.
2211 * For Wine this is the front buffer
2214 * GDISurface: Address to write the surface pointer to
2217 * DD_OK if the surface was found
2218 * DDERR_NOTFOUND if the GDI surface wasn't found
2220 *****************************************************************************/
2221 static HRESULT WINAPI
ddraw7_GetGDISurface(IDirectDraw7
*iface
, IDirectDrawSurface7
**GDISurface
)
2223 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2225 TRACE("iface %p, surface %p.\n", iface
, GDISurface
);
2227 wined3d_mutex_lock();
2229 if (!(*GDISurface
= &ddraw
->primary
->IDirectDrawSurface7_iface
))
2231 WARN("Primary not created yet.\n");
2232 wined3d_mutex_unlock();
2233 return DDERR_NOTFOUND
;
2235 IDirectDrawSurface7_AddRef(*GDISurface
);
2237 wined3d_mutex_unlock();
2242 static HRESULT WINAPI
ddraw4_GetGDISurface(IDirectDraw4
*iface
, IDirectDrawSurface4
**surface
)
2244 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2245 struct ddraw_surface
*surface_impl
;
2246 IDirectDrawSurface7
*surface7
;
2249 TRACE("iface %p, surface %p.\n", iface
, surface
);
2251 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2257 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2258 *surface
= &surface_impl
->IDirectDrawSurface4_iface
;
2259 IDirectDrawSurface4_AddRef(*surface
);
2260 IDirectDrawSurface7_Release(surface7
);
2265 static HRESULT WINAPI
ddraw2_GetGDISurface(IDirectDraw2
*iface
, IDirectDrawSurface
**surface
)
2267 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2268 struct ddraw_surface
*surface_impl
;
2269 IDirectDrawSurface7
*surface7
;
2272 TRACE("iface %p, surface %p.\n", iface
, surface
);
2274 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2280 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2281 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2282 IDirectDrawSurface_AddRef(*surface
);
2283 IDirectDrawSurface7_Release(surface7
);
2288 static HRESULT WINAPI
ddraw1_GetGDISurface(IDirectDraw
*iface
, IDirectDrawSurface
**surface
)
2290 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2291 struct ddraw_surface
*surface_impl
;
2292 IDirectDrawSurface7
*surface7
;
2295 TRACE("iface %p, surface %p.\n", iface
, surface
);
2297 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2303 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2304 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2305 IDirectDrawSurface_AddRef(*surface
);
2306 IDirectDrawSurface7_Release(surface7
);
2311 struct displaymodescallback_context
2313 LPDDENUMMODESCALLBACK func
;
2317 static HRESULT CALLBACK
EnumDisplayModesCallbackThunk(DDSURFACEDESC2
*surface_desc
, void *context
)
2319 struct displaymodescallback_context
*cbcontext
= context
;
2322 DDSD2_to_DDSD(surface_desc
, &desc
);
2323 return cbcontext
->func(&desc
, cbcontext
->context
);
2326 /*****************************************************************************
2327 * IDirectDraw7::EnumDisplayModes
2329 * Enumerates the supported Display modes. The modes can be filtered with
2330 * the DDSD parameter.
2333 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES. For old ddraw
2334 * versions (3 and older?) this is reserved and must be 0.
2335 * DDSD: Surface description to filter the modes
2336 * Context: Pointer passed back to the callback function
2337 * cb: Application-provided callback function
2341 * DDERR_INVALIDPARAMS if the callback wasn't set
2343 *****************************************************************************/
2344 static HRESULT WINAPI
ddraw7_EnumDisplayModes(IDirectDraw7
*iface
, DWORD Flags
,
2345 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMMODESCALLBACK2 cb
)
2347 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2348 struct wined3d_display_mode
*enum_modes
= NULL
;
2349 struct wined3d_display_mode mode
;
2350 unsigned int modenum
, fmt
;
2351 DDSURFACEDESC2 callback_sd
;
2352 unsigned enum_mode_count
= 0, enum_mode_array_size
= 16;
2353 DDPIXELFORMAT pixelformat
;
2355 static const enum wined3d_format_id checkFormatList
[] =
2357 WINED3DFMT_B8G8R8X8_UNORM
,
2358 WINED3DFMT_B5G6R5_UNORM
,
2362 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2363 iface
, Flags
, DDSD
, Context
, cb
);
2366 return DDERR_INVALIDPARAMS
;
2368 enum_modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(*enum_modes
) * enum_mode_array_size
);
2369 if (!enum_modes
) return DDERR_OUTOFMEMORY
;
2371 wined3d_mutex_lock();
2373 pixelformat
.dwSize
= sizeof(pixelformat
);
2374 for(fmt
= 0; fmt
< (sizeof(checkFormatList
) / sizeof(checkFormatList
[0])); fmt
++)
2377 while (wined3d_enum_adapter_modes(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, checkFormatList
[fmt
],
2378 WINED3D_SCANLINE_ORDERING_UNKNOWN
, modenum
++, &mode
) == WINED3D_OK
)
2383 ddrawformat_from_wined3dformat(&pixelformat
, mode
.format_id
);
2386 if (DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.width
!= DDSD
->dwWidth
)
2388 if (DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.height
!= DDSD
->dwHeight
)
2390 if (DDSD
->dwFlags
& DDSD_REFRESHRATE
&& mode
.refresh_rate
!= DDSD
->u2
.dwRefreshRate
)
2392 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
2393 && pixelformat
.u1
.dwRGBBitCount
!= DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
)
2397 /* DX docs state EnumDisplayMode should return only unique modes */
2398 for (i
= 0; i
< enum_mode_count
; i
++)
2400 if (enum_modes
[i
].width
== mode
.width
&& enum_modes
[i
].height
== mode
.height
2401 && enum_modes
[i
].format_id
== mode
.format_id
2402 && (enum_modes
[i
].refresh_rate
== mode
.refresh_rate
|| !(Flags
& DDEDM_REFRESHRATES
)))
2410 memset(&callback_sd
, 0, sizeof(callback_sd
));
2411 callback_sd
.dwSize
= sizeof(callback_sd
);
2412 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2414 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
|DDSD_REFRESHRATE
;
2415 if (Flags
& DDEDM_REFRESHRATES
)
2416 callback_sd
.u2
.dwRefreshRate
= mode
.refresh_rate
;
2418 callback_sd
.dwWidth
= mode
.width
;
2419 callback_sd
.dwHeight
= mode
.height
;
2421 callback_sd
.u4
.ddpfPixelFormat
=pixelformat
;
2423 /* Calc pitch and DWORD align like MSDN says */
2424 callback_sd
.u1
.lPitch
= (callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8) * mode
.width
;
2425 callback_sd
.u1
.lPitch
= (callback_sd
.u1
.lPitch
+ 3) & ~3;
2427 TRACE("Enumerating %dx%dx%d @%d\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
,
2428 callback_sd
.u2
.dwRefreshRate
);
2430 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
2432 TRACE("Application asked to terminate the enumeration\n");
2433 HeapFree(GetProcessHeap(), 0, enum_modes
);
2434 wined3d_mutex_unlock();
2438 if (enum_mode_count
== enum_mode_array_size
)
2440 struct wined3d_display_mode
*new_enum_modes
;
2442 enum_mode_array_size
*= 2;
2443 new_enum_modes
= HeapReAlloc(GetProcessHeap(), 0, enum_modes
,
2444 sizeof(*new_enum_modes
) * enum_mode_array_size
);
2445 if (!new_enum_modes
)
2447 HeapFree(GetProcessHeap(), 0, enum_modes
);
2448 wined3d_mutex_unlock();
2449 return DDERR_OUTOFMEMORY
;
2452 enum_modes
= new_enum_modes
;
2454 enum_modes
[enum_mode_count
++] = mode
;
2458 TRACE("End of enumeration\n");
2459 HeapFree(GetProcessHeap(), 0, enum_modes
);
2460 wined3d_mutex_unlock();
2465 static HRESULT WINAPI
ddraw4_EnumDisplayModes(IDirectDraw4
*iface
, DWORD flags
,
2466 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK2 callback
)
2468 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2470 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2471 iface
, flags
, surface_desc
, context
, callback
);
2473 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
, context
, callback
);
2476 static HRESULT WINAPI
ddraw2_EnumDisplayModes(IDirectDraw2
*iface
, DWORD flags
,
2477 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2479 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2480 struct displaymodescallback_context cbcontext
;
2481 DDSURFACEDESC2 surface_desc2
;
2483 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2484 iface
, flags
, surface_desc
, context
, callback
);
2486 cbcontext
.func
= callback
;
2487 cbcontext
.context
= context
;
2489 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2490 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2491 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2494 static HRESULT WINAPI
ddraw1_EnumDisplayModes(IDirectDraw
*iface
, DWORD flags
,
2495 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2497 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2498 struct displaymodescallback_context cbcontext
;
2499 DDSURFACEDESC2 surface_desc2
;
2501 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2502 iface
, flags
, surface_desc
, context
, callback
);
2504 cbcontext
.func
= callback
;
2505 cbcontext
.context
= context
;
2507 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2508 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2509 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2512 /*****************************************************************************
2513 * IDirectDraw7::EvaluateMode
2515 * Used with IDirectDraw7::StartModeTest to test video modes.
2516 * EvaluateMode is used to pass or fail a mode, and continue with the next
2520 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
2521 * Timeout: Returns the amount of seconds left before the mode would have
2522 * been failed automatically
2525 * This implementation always DD_OK, because it's a stub
2527 *****************************************************************************/
2528 static HRESULT WINAPI
ddraw7_EvaluateMode(IDirectDraw7
*iface
, DWORD Flags
, DWORD
*Timeout
)
2530 FIXME("iface %p, flags %#x, timeout %p stub!\n", iface
, Flags
, Timeout
);
2532 /* When implementing this, implement it in WineD3D */
2537 /*****************************************************************************
2538 * IDirectDraw7::GetDeviceIdentifier
2540 * Returns the device identifier, which gives information about the driver
2541 * Our device identifier is defined at the beginning of this file.
2544 * DDDI: Address for the returned structure
2545 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
2548 * On success it returns DD_OK
2549 * DDERR_INVALIDPARAMS if DDDI is NULL
2551 *****************************************************************************/
2552 static HRESULT WINAPI
ddraw7_GetDeviceIdentifier(IDirectDraw7
*iface
,
2553 DDDEVICEIDENTIFIER2
*DDDI
, DWORD Flags
)
2555 TRACE("iface %p, device_identifier %p, flags %#x.\n", iface
, DDDI
, Flags
);
2558 return DDERR_INVALIDPARAMS
;
2560 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
2561 * host adapter, if there's a secondary 3D adapter. This doesn't apply
2562 * to any modern hardware, nor is it interesting for Wine, so ignore it.
2563 * Size of DDDEVICEIDENTIFIER2 may be aligned to 8 bytes and thus 4
2564 * bytes too long. So only copy the relevant part of the structure
2567 memcpy(DDDI
, &deviceidentifier
, FIELD_OFFSET(DDDEVICEIDENTIFIER2
, dwWHQLLevel
) + sizeof(DWORD
));
2571 static HRESULT WINAPI
ddraw4_GetDeviceIdentifier(IDirectDraw4
*iface
,
2572 DDDEVICEIDENTIFIER
*identifier
, DWORD flags
)
2574 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2575 DDDEVICEIDENTIFIER2 identifier2
;
2578 TRACE("iface %p, identifier %p, flags %#x.\n", iface
, identifier
, flags
);
2580 hr
= ddraw7_GetDeviceIdentifier(&ddraw
->IDirectDraw7_iface
, &identifier2
, flags
);
2581 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&identifier2
, identifier
);
2586 /*****************************************************************************
2587 * IDirectDraw7::GetSurfaceFromDC
2589 * Returns the Surface for a GDI device context handle.
2590 * Is this related to IDirectDrawSurface::GetDC ???
2593 * hdc: hdc to return the surface for
2594 * Surface: Address to write the surface pointer to
2597 * Always returns DD_OK because it's a stub
2599 *****************************************************************************/
2600 static HRESULT WINAPI
ddraw7_GetSurfaceFromDC(IDirectDraw7
*iface
, HDC hdc
,
2601 IDirectDrawSurface7
**Surface
)
2603 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2604 struct wined3d_surface
*wined3d_surface
;
2605 struct ddraw_surface
*surface_impl
;
2607 TRACE("iface %p, dc %p, surface %p.\n", iface
, hdc
, Surface
);
2609 if (!Surface
) return E_INVALIDARG
;
2611 if (!(wined3d_surface
= wined3d_device_get_surface_from_dc(ddraw
->wined3d_device
, hdc
)))
2613 TRACE("No surface found for dc %p.\n", hdc
);
2615 return DDERR_NOTFOUND
;
2618 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
2619 *Surface
= &surface_impl
->IDirectDrawSurface7_iface
;
2620 IDirectDrawSurface7_AddRef(*Surface
);
2621 TRACE("Returning surface %p.\n", Surface
);
2625 static HRESULT WINAPI
ddraw4_GetSurfaceFromDC(IDirectDraw4
*iface
, HDC dc
,
2626 IDirectDrawSurface4
**surface
)
2628 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2629 struct ddraw_surface
*surface_impl
;
2630 IDirectDrawSurface7
*surface7
;
2633 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2635 if (!surface
) return E_INVALIDARG
;
2637 hr
= ddraw7_GetSurfaceFromDC(&ddraw
->IDirectDraw7_iface
, dc
, &surface7
);
2643 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2644 /* Tests say this is true */
2645 *surface
= (IDirectDrawSurface4
*)&surface_impl
->IDirectDrawSurface_iface
;
2646 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2647 IDirectDrawSurface7_Release(surface7
);
2652 /*****************************************************************************
2653 * IDirectDraw7::RestoreAllSurfaces
2655 * Calls the restore method of all surfaces
2660 * Always returns DD_OK because it's a stub
2662 *****************************************************************************/
2663 static HRESULT WINAPI
ddraw7_RestoreAllSurfaces(IDirectDraw7
*iface
)
2665 FIXME("iface %p stub!\n", iface
);
2667 /* This isn't hard to implement: Enumerate all WineD3D surfaces,
2668 * get their parent and call their restore method. Do not implement
2669 * it in WineD3D, as restoring a surface means re-creating the
2675 static HRESULT WINAPI
ddraw4_RestoreAllSurfaces(IDirectDraw4
*iface
)
2677 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2679 TRACE("iface %p.\n", iface
);
2681 return ddraw7_RestoreAllSurfaces(&ddraw
->IDirectDraw7_iface
);
2684 /*****************************************************************************
2685 * IDirectDraw7::StartModeTest
2687 * Tests the specified video modes to update the system registry with
2688 * refresh rate information. StartModeTest starts the mode test,
2689 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
2690 * isn't called within 15 seconds, the mode is failed automatically
2692 * As refresh rates are handled by the X server, I don't think this
2693 * Method is important
2696 * Modes: An array of mode specifications
2697 * NumModes: The number of modes in Modes
2698 * Flags: Some flags...
2701 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
2702 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
2705 *****************************************************************************/
2706 static HRESULT WINAPI
ddraw7_StartModeTest(IDirectDraw7
*iface
, SIZE
*Modes
, DWORD NumModes
, DWORD Flags
)
2708 FIXME("iface %p, modes %p, mode_count %u, flags %#x partial stub!\n",
2709 iface
, Modes
, NumModes
, Flags
);
2711 /* This looks sane */
2712 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
2714 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
2715 * As it is not, DDERR_TESTFINISHED is returned
2716 * (hopefully that's correct
2718 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
2719 * well, that value doesn't (yet) exist in the wine headers, so ignore it
2725 /*****************************************************************************
2726 * ddraw_create_surface
2728 * A helper function for IDirectDraw7::CreateSurface. It creates a new surface
2729 * with the passed parameters.
2732 * DDSD: Description of the surface to create
2733 * Surf: Address to store the interface pointer at
2738 *****************************************************************************/
2739 static HRESULT
ddraw_create_surface(struct ddraw
*ddraw
, DDSURFACEDESC2
*desc
,
2740 DWORD flags
, struct ddraw_surface
**surface
, UINT version
)
2744 TRACE("ddraw %p, desc %p, flags %#x, surface %p.\n", ddraw
, desc
, flags
, surface
);
2746 if (TRACE_ON(ddraw
))
2748 TRACE("Requesting surface desc:\n");
2749 DDRAW_dump_surface_desc(desc
);
2752 if ((desc
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) && (ddraw
->flags
& DDRAW_NO3D
))
2754 WARN("The application requests a 3D capable surface, but the ddraw object was created without 3D support.\n");
2755 /* Do not fail surface creation, only fail 3D device creation. */
2758 /* Create the Surface object */
2759 *surface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(**surface
));
2762 ERR("Failed to allocate surface memory.\n");
2763 return DDERR_OUTOFVIDEOMEMORY
;
2766 if (FAILED(hr
= ddraw_surface_init(*surface
, ddraw
, desc
, flags
, version
)))
2768 WARN("Failed to initialize surface, hr %#x.\n", hr
);
2769 HeapFree(GetProcessHeap(), 0, *surface
);
2773 /* Increase the surface counter, and attach the surface */
2774 list_add_head(&ddraw
->surface_list
, &(*surface
)->surface_list_entry
);
2776 TRACE("Created surface %p.\n", *surface
);
2781 static HRESULT CDECL
ddraw_reset_enum_callback(struct wined3d_resource
*resource
)
2786 /*****************************************************************************
2787 * IDirectDraw7::CreateSurface
2789 * Creates a new IDirectDrawSurface object and returns its interface.
2791 * The surface connections with wined3d are a bit tricky. Basically it works
2794 * |------------------------| |-----------------|
2795 * | DDraw surface | | WineD3DSurface |
2797 * | WineD3DSurface |-------------->| |
2798 * | Child |<------------->| Parent |
2799 * |------------------------| |-----------------|
2801 * The DDraw surface is the parent of the wined3d surface, and it releases
2802 * the WineD3DSurface when the ddraw surface is destroyed.
2804 * However, for all surfaces which can be in a container in WineD3D,
2805 * we have to do this. These surfaces are usually complex surfaces,
2806 * so this concerns primary surfaces with a front and a back buffer,
2809 * |------------------------| |-----------------|
2810 * | DDraw surface | | Container |
2812 * | Child |<------------->| Parent |
2813 * | Texture |<------------->| |
2814 * | WineD3DSurface |<----| | Levels |<--|
2815 * | Complex connection | | | | |
2816 * |------------------------| | |-----------------| |
2820 * | |------------------| | |-----------------| |
2821 * | | IParent | |-------->| WineD3DSurface | |
2823 * | | Child |<------------->| Parent | |
2824 * | | | | Container |<--|
2825 * | |------------------| |-----------------| |
2827 * | |----------------------| |
2828 * | | DDraw surface 2 | |
2830 * |<->| Complex root Child | |
2832 * | | WineD3DSurface |<----| |
2833 * | |----------------------| | |
2835 * | |---------------------| | |-----------------| |
2836 * | | IParent | |----->| WineD3DSurface | |
2838 * | | Child |<---------->| Parent | |
2839 * | |---------------------| | Container |<--|
2840 * | |-----------------| |
2842 * | ---More surfaces can follow--- |
2844 * The reason is that the IWineD3DSwapchain(render target container)
2845 * and the IWineD3DTexure(Texture container) release the parents
2846 * of their surface's children, but by releasing the complex root
2847 * the surfaces which are complexly attached to it are destroyed
2848 * too. See IDirectDrawSurface::Release for a more detailed
2852 * DDSD: Description of the surface to create
2853 * Surf: Address to store the interface pointer at
2854 * UnkOuter: Basically for aggregation support, but ddraw doesn't support
2855 * aggregation, so it has to be NULL
2859 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
2860 * DDERR_* if an error occurs
2862 *****************************************************************************/
2863 static HRESULT
CreateSurface(struct ddraw
*ddraw
, DDSURFACEDESC2
*DDSD
,
2864 struct ddraw_surface
**surface
, IUnknown
*UnkOuter
, UINT version
)
2866 struct ddraw_surface
*object
= NULL
;
2867 struct wined3d_display_mode mode
;
2869 DDSURFACEDESC2 desc2
;
2870 const DWORD sysvidmem
= DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
2871 /* Some applications assume surfaces will always be mapped at the same
2872 * address. Some of those also assume that this address is valid even when
2873 * the surface isn't mapped, and that updates done this way will be
2874 * visible on the screen. The game Nox is such an application,
2875 * Commandos: Behind Enemy Lines is another. */
2876 const DWORD flags
= WINED3D_SURFACE_PIN_SYSMEM
;
2878 TRACE("ddraw %p, surface_desc %p, surface %p, outer_unknown %p.\n", ddraw
, DDSD
, surface
, UnkOuter
);
2880 /* Some checks before we start */
2881 if (TRACE_ON(ddraw
))
2883 TRACE(" (%p) Requesting surface desc :\n", ddraw
);
2884 DDRAW_dump_surface_desc(DDSD
);
2887 if (UnkOuter
!= NULL
)
2889 FIXME("(%p) : outer != NULL?\n", ddraw
);
2890 return CLASS_E_NOAGGREGATION
; /* unchecked */
2895 FIXME("(%p) You want to get back a surface? Don't give NULL ptrs!\n", ddraw
);
2896 return E_POINTER
; /* unchecked */
2899 if (!(DDSD
->dwFlags
& DDSD_CAPS
))
2901 /* DVIDEO.DLL does forget the DDSD_CAPS flag ... *sigh* */
2902 DDSD
->dwFlags
|= DDSD_CAPS
;
2905 if (DDSD
->ddsCaps
.dwCaps
& DDSCAPS_ALLOCONLOAD
)
2907 /* If the surface is of the 'alloconload' type, ignore the LPSURFACE field */
2908 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2911 if ((DDSD
->dwFlags
& DDSD_LPSURFACE
) && (DDSD
->lpSurface
== NULL
))
2913 /* Frank Herbert's Dune specifies a null pointer for the surface, ignore the LPSURFACE field */
2914 WARN("(%p) Null surface pointer specified, ignore it!\n", ddraw
);
2915 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2918 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
) &&
2919 !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
2921 TRACE("(%p): Attempt to create a flipable primary surface without DDSCL_EXCLUSIVE set\n",
2924 return DDERR_NOEXCLUSIVEMODE
;
2927 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_BACKBUFFER
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_BACKBUFFER
| DDSCAPS_PRIMARYSURFACE
))
2929 WARN("Application wanted to create back buffer primary surface\n");
2930 return DDERR_INVALIDCAPS
;
2933 if((DDSD
->ddsCaps
.dwCaps
& sysvidmem
) == sysvidmem
)
2935 /* This is a special switch in ddrawex.dll, but not allowed in ddraw.dll */
2936 WARN("Application tries to put the surface in both system and video memory\n");
2938 return DDERR_INVALIDCAPS
;
2941 /* Check cube maps but only if the size includes them */
2942 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2944 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
&&
2945 !(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
2947 WARN("Cube map faces requested without cube map flag\n");
2948 return DDERR_INVALIDCAPS
;
2950 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2951 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) == 0)
2953 WARN("Cube map without faces requested\n");
2954 return DDERR_INVALIDPARAMS
;
2957 /* Quick tests confirm those can be created, but we don't do that yet */
2958 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2959 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
2961 FIXME("Partial cube maps not supported yet\n");
2965 if (DDSD
->ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
))
2967 if (!(DDSD
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
))
2969 WARN("DDSCAPS2_TEXTUREMANAGE used without DDSCAPS_TEXTURE, returning DDERR_INVALIDCAPS.\n");
2970 return DDERR_INVALIDCAPS
;
2972 if (DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
2974 WARN("DDSCAPS2_TEXTUREMANAGE used width DDSCAPS_VIDEOMEMORY "
2975 "or DDSCAPS_SYSTEMMEMORY, returning DDERR_INVALIDCAPS.\n");
2976 return DDERR_INVALIDCAPS
;
2980 /* According to the msdn this flag is ignored by CreateSurface */
2981 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2982 DDSD
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2984 /* Modify some flags */
2985 copy_to_surfacedesc2(&desc2
, DDSD
);
2986 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
); /* Just to be sure */
2988 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
2990 ERR("Failed to get display mode, hr %#x.\n", hr
);
2994 /* No pixelformat given? Use the current screen format */
2995 if(!(desc2
.dwFlags
& DDSD_PIXELFORMAT
))
2997 desc2
.dwFlags
|= DDSD_PIXELFORMAT
;
2998 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
);
3000 ddrawformat_from_wined3dformat(&desc2
.u4
.ddpfPixelFormat
, mode
.format_id
);
3003 if (!(desc2
.ddsCaps
.dwCaps
& (DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
))
3004 && !(desc2
.ddsCaps
.dwCaps2
& (DDSCAPS2_TEXTUREMANAGE
| DDSCAPS2_D3DTEXTUREMANAGE
)))
3006 enum wined3d_format_id format
= wined3dformat_from_ddrawformat(&desc2
.u4
.ddpfPixelFormat
);
3007 enum wined3d_resource_type rtype
;
3010 if (desc2
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
3011 rtype
= WINED3D_RTYPE_TEXTURE
;
3012 else if (desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
3013 rtype
= WINED3D_RTYPE_CUBE_TEXTURE
;
3015 rtype
= WINED3D_RTYPE_SURFACE
;
3017 if (desc2
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
3018 usage
= WINED3DUSAGE_DEPTHSTENCIL
;
3019 else if (desc2
.ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
3020 usage
= WINED3DUSAGE_RENDERTARGET
;
3022 hr
= wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, WINED3D_DEVICE_TYPE_HAL
,
3023 mode
.format_id
, usage
, rtype
, format
);
3025 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_VIDEOMEMORY
;
3027 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
3030 /* No Width or no Height? Use the original screen size
3032 if(!(desc2
.dwFlags
& DDSD_WIDTH
) ||
3033 !(desc2
.dwFlags
& DDSD_HEIGHT
) )
3035 /* Invalid for non-render targets */
3036 if(!(desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
3038 WARN("Creating a non-Primary surface without Width or Height info, returning DDERR_INVALIDPARAMS\n");
3040 return DDERR_INVALIDPARAMS
;
3043 desc2
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
3044 desc2
.dwWidth
= mode
.width
;
3045 desc2
.dwHeight
= mode
.height
;
3048 if (!desc2
.dwWidth
|| !desc2
.dwHeight
)
3049 return DDERR_INVALIDPARAMS
;
3051 /* Mipmap count fixes */
3052 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
3054 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
3056 if(desc2
.dwFlags
& DDSD_MIPMAPCOUNT
)
3058 /* Mipmap count is given, should not be 0 */
3059 if( desc2
.u2
.dwMipMapCount
== 0 )
3060 return DDERR_INVALIDPARAMS
;
3064 /* Undocumented feature: Create sublevels until
3065 * either the width or the height is 1
3067 DWORD min
= desc2
.dwWidth
< desc2
.dwHeight
?
3068 desc2
.dwWidth
: desc2
.dwHeight
;
3069 desc2
.u2
.dwMipMapCount
= 0;
3072 desc2
.u2
.dwMipMapCount
+= 1;
3079 /* Not-complex mipmap -> Mipmapcount = 1 */
3080 desc2
.u2
.dwMipMapCount
= 1;
3083 /* There's a mipmap count in the created surface in any case */
3084 desc2
.dwFlags
|= DDSD_MIPMAPCOUNT
;
3086 /* If no mipmap is given, the texture has only one level */
3088 /* The first surface is a front buffer, the back buffer is created afterwards */
3089 if( (desc2
.dwFlags
& DDSD_CAPS
) && (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) )
3091 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
3094 /* The root surface in a cube map is positive x */
3095 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
3097 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
3098 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
3101 if ((desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) && (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
3103 struct wined3d_swapchain_desc swapchain_desc
;
3105 wined3d_swapchain_get_desc(ddraw
->wined3d_swapchain
, &swapchain_desc
);
3106 swapchain_desc
.backbuffer_width
= mode
.width
;
3107 swapchain_desc
.backbuffer_height
= mode
.height
;
3108 swapchain_desc
.backbuffer_format
= mode
.format_id
;
3110 hr
= wined3d_device_reset(ddraw
->wined3d_device
,
3111 &swapchain_desc
, NULL
, ddraw_reset_enum_callback
, TRUE
);
3114 ERR("Failed to reset device.\n");
3119 /* Create the first surface */
3120 if (FAILED(hr
= ddraw_create_surface(ddraw
, &desc2
, flags
, &object
, version
)))
3122 WARN("ddraw_create_surface failed, hr %#x.\n", hr
);
3125 object
->is_complex_root
= TRUE
;
3129 /* Create Additional surfaces if necessary
3130 * This applies to Primary surfaces which have a back buffer count
3131 * set, but not to mipmap textures. In case of Mipmap textures,
3132 * wineD3D takes care of the creation of additional surfaces
3134 if(DDSD
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
3136 struct ddraw_surface
*last
= object
;
3139 desc2
.ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
; /* It's not a front buffer */
3140 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
3141 desc2
.dwBackBufferCount
= 0;
3143 for (i
= 0; i
< DDSD
->dwBackBufferCount
; ++i
)
3145 struct ddraw_surface
*object2
= NULL
;
3147 if (FAILED(hr
= ddraw_create_surface(ddraw
, &desc2
, flags
, &object2
, version
)))
3150 IDirectDrawSurface7_Release(&object
->IDirectDrawSurface7_iface
);
3151 else if (version
== 4)
3152 IDirectDrawSurface4_Release(&object
->IDirectDrawSurface4_iface
);
3154 IDirectDrawSurface_Release(&object
->IDirectDrawSurface_iface
);
3159 /* Add the new surface to the complex attachment array. */
3160 last
->complex_array
[0] = object2
;
3163 /* Remove the (possible) back buffer cap from the new surface
3164 * description, because only one surface in the flipping chain is a
3165 * back buffer, one is a front buffer, the others are just primary
3167 desc2
.ddsCaps
.dwCaps
&= ~DDSCAPS_BACKBUFFER
;
3171 if (desc2
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
3173 hr
= ddraw_surface_create_texture(object
, flags
);
3177 IDirectDrawSurface7_Release(&object
->IDirectDrawSurface7_iface
);
3178 else if (version
== 4)
3179 IDirectDrawSurface4_Release(&object
->IDirectDrawSurface4_iface
);
3181 IDirectDrawSurface_Release(&object
->IDirectDrawSurface_iface
);
3187 if (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
3188 ddraw
->primary
= object
;
3193 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
, DDSURFACEDESC2
*surface_desc
,
3194 IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
3196 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3197 struct ddraw_surface
*impl
;
3200 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3201 iface
, surface_desc
, surface
, outer_unknown
);
3203 wined3d_mutex_lock();
3205 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
3207 WARN("Cooperative level not set.\n");
3208 wined3d_mutex_unlock();
3209 return DDERR_NOCOOPERATIVELEVELSET
;
3212 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
3214 WARN("Application supplied invalid surface descriptor\n");
3215 wined3d_mutex_unlock();
3216 return DDERR_INVALIDPARAMS
;
3219 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3221 if (TRACE_ON(ddraw
))
3223 TRACE(" (%p) Requesting surface desc :\n", iface
);
3224 DDRAW_dump_surface_desc(surface_desc
);
3227 WARN("Application tried to create an explicit front or back buffer\n");
3228 wined3d_mutex_unlock();
3229 return DDERR_INVALIDCAPS
;
3232 hr
= CreateSurface(ddraw
, surface_desc
, &impl
, outer_unknown
, 7);
3233 wined3d_mutex_unlock();
3240 *surface
= &impl
->IDirectDrawSurface7_iface
;
3241 IDirectDraw7_AddRef(iface
);
3242 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3247 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
3248 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
3250 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3251 struct ddraw_surface
*impl
;
3254 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3255 iface
, surface_desc
, surface
, outer_unknown
);
3257 wined3d_mutex_lock();
3259 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
3261 WARN("Cooperative level not set.\n");
3262 wined3d_mutex_unlock();
3263 return DDERR_NOCOOPERATIVELEVELSET
;
3266 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
3268 WARN("Application supplied invalid surface descriptor\n");
3269 wined3d_mutex_unlock();
3270 return DDERR_INVALIDPARAMS
;
3273 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3275 if (TRACE_ON(ddraw
))
3277 TRACE(" (%p) Requesting surface desc :\n", iface
);
3278 DDRAW_dump_surface_desc(surface_desc
);
3281 WARN("Application tried to create an explicit front or back buffer\n");
3282 wined3d_mutex_unlock();
3283 return DDERR_INVALIDCAPS
;
3286 hr
= CreateSurface(ddraw
, surface_desc
, &impl
, outer_unknown
, 4);
3287 wined3d_mutex_unlock();
3294 *surface
= &impl
->IDirectDrawSurface4_iface
;
3295 IDirectDraw4_AddRef(iface
);
3296 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3301 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
3302 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3304 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3305 struct ddraw_surface
*impl
;
3307 DDSURFACEDESC2 surface_desc2
;
3309 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3310 iface
, surface_desc
, surface
, outer_unknown
);
3312 wined3d_mutex_lock();
3314 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
3316 WARN("Cooperative level not set.\n");
3317 wined3d_mutex_unlock();
3318 return DDERR_NOCOOPERATIVELEVELSET
;
3321 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3323 WARN("Application supplied invalid surface descriptor\n");
3324 wined3d_mutex_unlock();
3325 return DDERR_INVALIDPARAMS
;
3328 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3329 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3331 if (TRACE_ON(ddraw
))
3333 TRACE(" (%p) Requesting surface desc :\n", iface
);
3334 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
3337 WARN("Application tried to create an explicit front or back buffer\n");
3338 wined3d_mutex_unlock();
3339 return DDERR_INVALIDCAPS
;
3342 hr
= CreateSurface(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 2);
3343 wined3d_mutex_unlock();
3350 *surface
= &impl
->IDirectDrawSurface_iface
;
3351 impl
->ifaceToRelease
= NULL
;
3356 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
3357 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3359 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3360 struct ddraw_surface
*impl
;
3362 DDSURFACEDESC2 surface_desc2
;
3364 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3365 iface
, surface_desc
, surface
, outer_unknown
);
3367 wined3d_mutex_lock();
3369 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
3371 WARN("Cooperative level not set.\n");
3372 wined3d_mutex_unlock();
3373 return DDERR_NOCOOPERATIVELEVELSET
;
3376 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3378 WARN("Application supplied invalid surface descriptor\n");
3379 wined3d_mutex_unlock();
3380 return DDERR_INVALIDPARAMS
;
3383 /* Remove front buffer flag, this causes failure in v7, and its added to normal
3384 * primaries anyway. */
3385 surface_desc
->ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
;
3386 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3387 hr
= CreateSurface(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 1);
3388 wined3d_mutex_unlock();
3395 *surface
= &impl
->IDirectDrawSurface_iface
;
3396 impl
->ifaceToRelease
= NULL
;
3401 #define DDENUMSURFACES_SEARCHTYPE (DDENUMSURFACES_CANBECREATED|DDENUMSURFACES_DOESEXIST)
3402 #define DDENUMSURFACES_MATCHTYPE (DDENUMSURFACES_ALL|DDENUMSURFACES_MATCH|DDENUMSURFACES_NOMATCH)
3405 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
3406 const DDPIXELFORMAT
*provided
)
3408 /* Some flags must be present in both or neither for a match. */
3409 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
3410 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
3411 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
3413 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3416 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
3419 if (requested
->dwFlags
& DDPF_FOURCC
)
3420 if (requested
->dwFourCC
!= provided
->dwFourCC
)
3423 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
3424 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3425 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
3428 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3429 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3430 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
3433 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
3434 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
3437 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
3438 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3440 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
3443 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
3444 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
3450 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3459 #define CMP(FLAG, FIELD) \
3460 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3461 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3463 static const struct compare_info compare
[] =
3465 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3466 CMP(BACKBUFFERCOUNT
, dwBackBufferCount
),
3468 CMP(CKDESTBLT
, ddckCKDestBlt
),
3469 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3470 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3471 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3472 CMP(HEIGHT
, dwHeight
),
3473 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3474 CMP(LPSURFACE
, lpSurface
),
3475 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3476 CMP(PITCH
, u1
/* lPitch */),
3477 /* PIXELFORMAT: manual */
3478 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3479 CMP(TEXTURESTAGE
, dwTextureStage
),
3480 CMP(WIDTH
, dwWidth
),
3481 /* ZBUFFERBITDEPTH: "obsolete" */
3488 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3491 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
3493 if (requested
->dwFlags
& compare
[i
].flag
3494 && memcmp((const char *)provided
+ compare
[i
].offset
,
3495 (const char *)requested
+ compare
[i
].offset
,
3496 compare
[i
].size
) != 0)
3500 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3502 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3503 &provided
->u4
.ddpfPixelFormat
))
3510 #undef DDENUMSURFACES_SEARCHTYPE
3511 #undef DDENUMSURFACES_MATCHTYPE
3513 struct surfacescallback2_context
3515 LPDDENUMSURFACESCALLBACK2 func
;
3519 struct surfacescallback_context
3521 LPDDENUMSURFACESCALLBACK func
;
3525 static HRESULT CALLBACK
EnumSurfacesCallback2Thunk(IDirectDrawSurface7
*surface
,
3526 DDSURFACEDESC2
*surface_desc
, void *context
)
3528 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3529 struct surfacescallback2_context
*cbcontext
= context
;
3531 IDirectDrawSurface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
3532 IDirectDrawSurface7_Release(surface
);
3534 return cbcontext
->func(&surface_impl
->IDirectDrawSurface4_iface
,
3535 surface_desc
, cbcontext
->context
);
3538 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3539 DDSURFACEDESC2
*surface_desc
, void *context
)
3541 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3542 struct surfacescallback_context
*cbcontext
= context
;
3544 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
3545 IDirectDrawSurface7_Release(surface
);
3547 return cbcontext
->func(&surface_impl
->IDirectDrawSurface_iface
,
3548 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3551 /*****************************************************************************
3552 * IDirectDraw7::EnumSurfaces
3554 * Loops through all surfaces attached to this device and calls the
3555 * application callback. This can't be relayed to WineD3DDevice,
3556 * because some WineD3DSurfaces' parents are IParent objects
3559 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3560 * DDSD: Description to filter for
3561 * Context: Application-provided pointer, it's passed unmodified to the
3563 * Callback: Address to call for each surface
3566 * DDERR_INVALIDPARAMS if the callback is NULL
3569 *****************************************************************************/
3570 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD Flags
,
3571 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMSURFACESCALLBACK7 Callback
)
3573 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3574 struct ddraw_surface
*surf
;
3576 DDSURFACEDESC2 desc
;
3577 struct list
*entry
, *entry2
;
3579 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3580 iface
, Flags
, DDSD
, Context
, Callback
);
3582 all
= Flags
& DDENUMSURFACES_ALL
;
3583 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
3586 return DDERR_INVALIDPARAMS
;
3588 wined3d_mutex_lock();
3590 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
3591 LIST_FOR_EACH_SAFE(entry
, entry2
, &ddraw
->surface_list
)
3593 surf
= LIST_ENTRY(entry
, struct ddraw_surface
, surface_list_entry
);
3595 if (!surf
->iface_count
)
3597 WARN("Not enumerating surface %p because it doesn't have any references.\n", surf
);
3601 if (all
|| (nomatch
!= ddraw_match_surface_desc(DDSD
, &surf
->surface_desc
)))
3603 TRACE("Enumerating surface %p.\n", surf
);
3604 desc
= surf
->surface_desc
;
3605 IDirectDrawSurface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
3606 if (Callback(&surf
->IDirectDrawSurface7_iface
, &desc
, Context
) != DDENUMRET_OK
)
3608 wined3d_mutex_unlock();
3614 wined3d_mutex_unlock();
3619 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3620 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3622 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3623 struct surfacescallback2_context cbcontext
;
3625 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3626 iface
, flags
, surface_desc
, context
, callback
);
3628 cbcontext
.func
= callback
;
3629 cbcontext
.context
= context
;
3631 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
,
3632 &cbcontext
, EnumSurfacesCallback2Thunk
);
3635 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3636 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3638 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3639 struct surfacescallback_context cbcontext
;
3640 DDSURFACEDESC2 surface_desc2
;
3642 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3643 iface
, flags
, surface_desc
, context
, callback
);
3645 cbcontext
.func
= callback
;
3646 cbcontext
.context
= context
;
3648 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3649 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3650 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3653 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3654 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3656 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3657 struct surfacescallback_context cbcontext
;
3658 DDSURFACEDESC2 surface_desc2
;
3660 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3661 iface
, flags
, surface_desc
, context
, callback
);
3663 cbcontext
.func
= callback
;
3664 cbcontext
.context
= context
;
3666 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3667 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3668 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3671 /*****************************************************************************
3672 * DirectDrawCreateClipper (DDRAW.@)
3674 * Creates a new IDirectDrawClipper object.
3677 * Clipper: Address to write the interface pointer to
3678 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3682 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3683 * E_OUTOFMEMORY if allocating the object failed
3685 *****************************************************************************/
3686 HRESULT WINAPI
DirectDrawCreateClipper(DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3688 struct ddraw_clipper
*object
;
3691 TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
3692 flags
, clipper
, outer_unknown
);
3695 return CLASS_E_NOAGGREGATION
;
3697 wined3d_mutex_lock();
3699 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3702 wined3d_mutex_unlock();
3703 return E_OUTOFMEMORY
;
3706 hr
= ddraw_clipper_init(object
);
3709 WARN("Failed to initialize clipper, hr %#x.\n", hr
);
3710 HeapFree(GetProcessHeap(), 0, object
);
3711 wined3d_mutex_unlock();
3715 TRACE("Created clipper %p.\n", object
);
3716 *clipper
= &object
->IDirectDrawClipper_iface
;
3717 wined3d_mutex_unlock();
3722 /*****************************************************************************
3723 * IDirectDraw7::CreateClipper
3725 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3727 *****************************************************************************/
3728 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3729 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3731 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3732 iface
, Flags
, Clipper
, UnkOuter
);
3734 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3737 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
, DWORD flags
,
3738 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3740 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3742 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3743 iface
, flags
, clipper
, outer_unknown
);
3745 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3748 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
3749 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3751 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3753 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3754 iface
, flags
, clipper
, outer_unknown
);
3756 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3759 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
3760 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3762 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3764 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3765 iface
, flags
, clipper
, outer_unknown
);
3767 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3770 /*****************************************************************************
3771 * IDirectDraw7::CreatePalette
3773 * Creates a new IDirectDrawPalette object
3776 * Flags: The flags for the new clipper
3777 * ColorTable: Color table to assign to the new clipper
3778 * Palette: Address to write the interface pointer to
3779 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3783 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3784 * E_OUTOFMEMORY if allocating the object failed
3786 *****************************************************************************/
3787 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
3788 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
3790 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3791 struct ddraw_palette
*object
;
3794 TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
3795 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3798 return CLASS_E_NOAGGREGATION
;
3800 wined3d_mutex_lock();
3802 /* The refcount test shows that a cooplevel is required for this */
3803 if (!ddraw
->cooperative_level
)
3805 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3806 wined3d_mutex_unlock();
3807 return DDERR_NOCOOPERATIVELEVELSET
;
3810 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(*object
));
3813 ERR("Out of memory when allocating memory for a palette implementation\n");
3814 wined3d_mutex_unlock();
3815 return E_OUTOFMEMORY
;
3818 hr
= ddraw_palette_init(object
, ddraw
, Flags
, ColorTable
);
3821 WARN("Failed to initialize palette, hr %#x.\n", hr
);
3822 HeapFree(GetProcessHeap(), 0, object
);
3823 wined3d_mutex_unlock();
3827 TRACE("Created palette %p.\n", object
);
3828 *Palette
= &object
->IDirectDrawPalette_iface
;
3829 wined3d_mutex_unlock();
3834 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
, PALETTEENTRY
*entries
,
3835 IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3837 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3840 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3841 iface
, flags
, entries
, palette
, outer_unknown
);
3843 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3844 if (SUCCEEDED(hr
) && *palette
)
3846 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3847 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3848 IDirectDraw4_AddRef(iface
);
3849 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3854 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
3855 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3857 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3860 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3861 iface
, flags
, entries
, palette
, outer_unknown
);
3863 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3864 if (SUCCEEDED(hr
) && *palette
)
3866 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3867 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3868 impl
->ifaceToRelease
= NULL
;
3874 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
3875 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3877 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3880 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3881 iface
, flags
, entries
, palette
, outer_unknown
);
3883 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3884 if (SUCCEEDED(hr
) && *palette
)
3886 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3887 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3888 impl
->ifaceToRelease
= NULL
;
3894 /*****************************************************************************
3895 * IDirectDraw7::DuplicateSurface
3897 * Duplicates a surface. The surface memory points to the same memory as
3898 * the original surface, and it's released when the last surface referencing
3899 * it is released. I guess that's beyond Wine's surface management right now
3900 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3901 * test application to implement this)
3904 * Src: Address of the source surface
3905 * Dest: Address to write the new surface pointer to
3908 * See IDirectDraw7::CreateSurface
3910 *****************************************************************************/
3911 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
3912 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
3914 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(Src
);
3916 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
3918 /* For now, simply create a new, independent surface */
3919 return IDirectDraw7_CreateSurface(iface
, &src_surface
->surface_desc
, Dest
, NULL
);
3922 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
, IDirectDrawSurface4
*src
,
3923 IDirectDrawSurface4
**dst
)
3925 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
3926 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3927 struct ddraw_surface
*dst_impl
;
3928 IDirectDrawSurface7
*dst7
;
3931 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3933 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3934 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3940 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3941 *dst
= &dst_impl
->IDirectDrawSurface4_iface
;
3942 IDirectDrawSurface4_AddRef(*dst
);
3943 IDirectDrawSurface7_Release(dst7
);
3948 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
3949 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
3951 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3952 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3953 struct ddraw_surface
*dst_impl
;
3954 IDirectDrawSurface7
*dst7
;
3957 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3959 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3960 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3963 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3964 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3965 IDirectDrawSurface_AddRef(*dst
);
3966 IDirectDrawSurface7_Release(dst7
);
3971 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
, IDirectDrawSurface
*src
,
3972 IDirectDrawSurface
**dst
)
3974 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3975 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3976 struct ddraw_surface
*dst_impl
;
3977 IDirectDrawSurface7
*dst7
;
3980 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3982 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3983 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3986 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3987 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3988 IDirectDrawSurface_AddRef(*dst
);
3989 IDirectDrawSurface7_Release(dst7
);
3994 /*****************************************************************************
3995 * IDirect3D7::EnumDevices
3997 * The EnumDevices method for IDirect3D7. It enumerates all supported
3998 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
4001 * callback: Function to call for each enumerated device
4002 * context: Pointer to pass back to the app
4005 * D3D_OK, or the return value of the GetCaps call
4007 *****************************************************************************/
4008 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
4010 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4011 D3DDEVICEDESC7 device_desc7
;
4015 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
4018 return DDERR_INVALIDPARAMS
;
4020 wined3d_mutex_lock();
4022 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
4024 wined3d_mutex_unlock();
4028 for (i
= 0; i
< sizeof(device_list7
)/sizeof(device_list7
[0]); i
++)
4032 device_desc7
.deviceGUID
= *device_list7
[i
].device_guid
;
4033 ret
= callback(device_list7
[i
].interface_name
, device_list7
[i
].device_name
, &device_desc7
, context
);
4034 if (ret
!= DDENUMRET_OK
)
4036 TRACE("Application cancelled the enumeration.\n");
4037 wined3d_mutex_unlock();
4042 TRACE("End of enumeration.\n");
4044 wined3d_mutex_unlock();
4049 /*****************************************************************************
4050 * IDirect3D3::EnumDevices
4052 * Enumerates all supported Direct3DDevice interfaces. This is the
4053 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
4055 * Version 1, 2 and 3
4058 * callback: Application-provided routine to call for each enumerated device
4059 * Context: Pointer to pass to the callback
4062 * D3D_OK on success,
4063 * The result of IDirect3DImpl_GetCaps if it failed
4065 *****************************************************************************/
4066 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
4068 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
4070 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4071 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
4072 D3DDEVICEDESC7 device_desc7
;
4075 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
4076 * name string. Let's put the string in a sufficiently sized array in
4077 * writable memory. */
4078 char device_name
[50];
4079 strcpy(device_name
,"Direct3D HEL");
4081 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
4084 return DDERR_INVALIDPARAMS
;
4086 wined3d_mutex_lock();
4088 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
4090 wined3d_mutex_unlock();
4093 ddraw_d3dcaps1_from_7(&device_desc1
, &device_desc7
);
4095 /* Do I have to enumerate the reference id? Note from old d3d7:
4096 * "It seems that enumerating the reference IID on Direct3D 1 games
4097 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
4099 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
4100 * EnumReference which enables / disables enumerating the reference
4101 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
4102 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
4103 * demo directory suggest this.
4105 * Some games(GTA 2) seem to use the second enumerated device, so I have
4106 * to enumerate at least 2 devices. So enumerate the reference device to
4109 * Other games (Rollcage) tell emulation and hal device apart by certain
4110 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
4111 * limitation flag), and it refuses all devices that have the perspective
4112 * flag set. This way it refuses the emulation device, and HAL devices
4113 * never have POW2 unset in d3d7 on windows. */
4114 if (ddraw
->d3dversion
!= 1)
4116 static CHAR reference_description
[] = "RGB Direct3D emulation";
4118 TRACE("Enumerating WineD3D D3DDevice interface.\n");
4119 hal_desc
= device_desc1
;
4120 hel_desc
= device_desc1
;
4121 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
4122 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4123 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4124 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4125 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4126 /* RGB, RAMP and MMX devices have a HAL dcmColorModel of 0 */
4127 hal_desc
.dcmColorModel
= 0;
4129 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
4130 device_name
, &hal_desc
, &hel_desc
, context
);
4131 if (hr
!= D3DENUMRET_OK
)
4133 TRACE("Application cancelled the enumeration.\n");
4134 wined3d_mutex_unlock();
4139 strcpy(device_name
,"Direct3D HAL");
4141 TRACE("Enumerating HAL Direct3D device.\n");
4142 hal_desc
= device_desc1
;
4143 hel_desc
= device_desc1
;
4145 /* The hal device does not have the pow2 flag set in hel, but in hal. */
4146 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4147 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4148 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4149 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4150 /* HAL devices have a HEL dcmColorModel of 0 */
4151 hel_desc
.dcmColorModel
= 0;
4153 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
4154 device_name
, &hal_desc
, &hel_desc
, context
);
4155 if (hr
!= D3DENUMRET_OK
)
4157 TRACE("Application cancelled the enumeration.\n");
4158 wined3d_mutex_unlock();
4162 TRACE("End of enumeration.\n");
4164 wined3d_mutex_unlock();
4169 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
4171 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4173 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
4175 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
4178 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
4180 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4182 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
4184 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
4187 /*****************************************************************************
4188 * IDirect3D3::CreateLight
4190 * Creates an IDirect3DLight interface. This interface is used in
4191 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
4192 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
4193 * uses the IDirect3DDevice7 interface with D3D7 lights.
4195 * Version 1, 2 and 3
4198 * light: Address to store the new interface pointer
4199 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4204 * DDERR_OUTOFMEMORY if memory allocation failed
4205 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4207 *****************************************************************************/
4208 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
,
4209 IUnknown
*outer_unknown
)
4211 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4212 struct d3d_light
*object
;
4214 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4216 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4218 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4221 ERR("Failed to allocate light memory.\n");
4222 return DDERR_OUTOFMEMORY
;
4225 d3d_light_init(object
, ddraw
);
4227 TRACE("Created light %p.\n", object
);
4228 *light
= &object
->IDirect3DLight_iface
;
4233 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
4235 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4237 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4239 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
4242 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
4244 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4246 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4248 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
4251 /*****************************************************************************
4252 * IDirect3D3::CreateMaterial
4254 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
4255 * and older versions. The IDirect3DMaterial implementation wraps its
4256 * functionality to IDirect3DDevice7::SetMaterial and friends.
4258 * Version 1, 2 and 3
4261 * material: Address to store the new interface's pointer to
4262 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4267 * DDERR_OUTOFMEMORY if memory allocation failed
4268 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4270 *****************************************************************************/
4271 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
,
4272 IUnknown
*outer_unknown
)
4274 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4275 struct d3d_material
*object
;
4277 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4279 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4281 object
= d3d_material_create(ddraw
);
4284 ERR("Failed to allocate material memory.\n");
4285 return DDERR_OUTOFMEMORY
;
4288 TRACE("Created material %p.\n", object
);
4289 *material
= &object
->IDirect3DMaterial3_iface
;
4294 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
,
4295 IUnknown
*outer_unknown
)
4297 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4298 struct d3d_material
*object
;
4300 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4302 object
= d3d_material_create(ddraw
);
4305 ERR("Failed to allocate material memory.\n");
4306 return DDERR_OUTOFMEMORY
;
4309 TRACE("Created material %p.\n", object
);
4310 *material
= &object
->IDirect3DMaterial2_iface
;
4315 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
,
4316 IUnknown
*outer_unknown
)
4318 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4319 struct d3d_material
*object
;
4321 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4323 object
= d3d_material_create(ddraw
);
4326 ERR("Failed to allocate material memory.\n");
4327 return DDERR_OUTOFMEMORY
;
4330 TRACE("Created material %p.\n", object
);
4331 *material
= &object
->IDirect3DMaterial_iface
;
4336 /*****************************************************************************
4337 * IDirect3D3::CreateViewport
4339 * Creates an IDirect3DViewport interface. This interface is used
4340 * by Direct3D and earlier versions for Viewport management. In Direct3D7
4341 * it has been replaced by a viewport structure and
4342 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
4343 * uses the IDirect3DDevice7 methods for its functionality
4346 * Viewport: Address to store the new interface pointer
4347 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4352 * DDERR_OUTOFMEMORY if memory allocation failed
4353 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4355 *****************************************************************************/
4356 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
,
4357 IUnknown
*outer_unknown
)
4359 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4360 struct d3d_viewport
*object
;
4362 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4364 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4366 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4369 ERR("Failed to allocate viewport memory.\n");
4370 return DDERR_OUTOFMEMORY
;
4373 d3d_viewport_init(object
, ddraw
);
4375 TRACE("Created viewport %p.\n", object
);
4376 *viewport
= &object
->IDirect3DViewport3_iface
;
4381 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
4383 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4385 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4387 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4391 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
4393 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4395 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4397 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4401 /*****************************************************************************
4402 * IDirect3D3::FindDevice
4404 * This method finds a device with the requested properties and returns a
4405 * device description
4409 * fds: Describes the requested device characteristics
4410 * fdr: Returns the device description
4414 * DDERR_INVALIDPARAMS if no device was found
4416 *****************************************************************************/
4417 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4419 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4420 D3DDEVICEDESC7 desc7
;
4421 D3DDEVICEDESC desc1
;
4424 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4426 if (!fds
|| !fdr
) return DDERR_INVALIDPARAMS
;
4428 if (fds
->dwSize
!= sizeof(D3DFINDDEVICESEARCH
)
4429 || fdr
->dwSize
!= sizeof(D3DFINDDEVICERESULT
))
4430 return DDERR_INVALIDPARAMS
;
4432 if ((fds
->dwFlags
& D3DFDS_COLORMODEL
)
4433 && fds
->dcmColorModel
!= D3DCOLOR_RGB
)
4435 WARN("Trying to request a non-RGB D3D color model. Not supported.\n");
4436 return DDERR_INVALIDPARAMS
; /* No real idea what to return here :-) */
4439 if (fds
->dwFlags
& D3DFDS_GUID
)
4441 TRACE("Trying to match guid %s.\n", debugstr_guid(&(fds
->guid
)));
4442 if (!IsEqualGUID(&IID_D3DDEVICE_WineD3D
, &fds
->guid
)
4443 && !IsEqualGUID(&IID_IDirect3DHALDevice
, &fds
->guid
)
4444 && !IsEqualGUID(&IID_IDirect3DRGBDevice
, &fds
->guid
))
4446 WARN("No match for this GUID.\n");
4447 return DDERR_NOTFOUND
;
4452 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &desc7
)))
4455 /* Now return our own GUID */
4456 ddraw_d3dcaps1_from_7(&desc1
, &desc7
);
4457 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4458 fdr
->ddHwDesc
= desc1
;
4459 fdr
->ddSwDesc
= desc1
;
4461 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4466 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4468 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4470 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4472 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4475 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4477 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4479 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4481 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4484 /*****************************************************************************
4485 * IDirect3D7::CreateDevice
4487 * Creates an IDirect3DDevice7 interface.
4489 * Version 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4490 * DirectDraw surfaces and are created with
4491 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4492 * create the device object and QueryInterfaces for IDirect3DDevice
4495 * refiid: IID of the device to create
4496 * Surface: Initial rendertarget
4497 * Device: Address to return the interface pointer
4501 * DDERR_OUTOFMEMORY if memory allocation failed
4502 * DDERR_INVALIDPARAMS if a device exists already
4504 *****************************************************************************/
4505 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4506 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4508 struct ddraw_surface
*target
= unsafe_impl_from_IDirectDrawSurface7(surface
);
4509 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4510 struct d3d_device
*object
;
4513 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4515 wined3d_mutex_lock();
4516 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, target
, (IUnknown
*)surface
, 7, &object
, NULL
)))
4518 *device
= &object
->IDirect3DDevice7_iface
;
4522 WARN("Failed to create device, hr %#x.\n", hr
);
4525 wined3d_mutex_unlock();
4530 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4531 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4533 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface4(surface
);
4534 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4535 struct d3d_device
*device_impl
;
4538 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4539 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4542 return CLASS_E_NOAGGREGATION
;
4544 wined3d_mutex_lock();
4545 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 3, &device_impl
, NULL
)))
4547 *device
= &device_impl
->IDirect3DDevice3_iface
;
4551 WARN("Failed to create device, hr %#x.\n", hr
);
4554 wined3d_mutex_unlock();
4559 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4560 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4562 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface(surface
);
4563 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4564 struct d3d_device
*device_impl
;
4567 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4568 iface
, debugstr_guid(riid
), surface
, device
);
4570 wined3d_mutex_lock();
4571 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 2, &device_impl
, NULL
)))
4573 *device
= &device_impl
->IDirect3DDevice2_iface
;
4577 WARN("Failed to create device, hr %#x.\n", hr
);
4580 wined3d_mutex_unlock();
4585 /*****************************************************************************
4586 * IDirect3D7::CreateVertexBuffer
4588 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4594 * desc: Requested Vertex buffer properties
4595 * vertex_buffer: Address to return the interface pointer at
4596 * flags: Some flags, should be 0
4600 * DDERR_OUTOFMEMORY if memory allocation failed
4601 * The return value of IWineD3DDevice::CreateVertexBuffer if this call fails
4602 * DDERR_INVALIDPARAMS if desc or vertex_buffer are NULL
4604 *****************************************************************************/
4605 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4606 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4608 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4609 struct d3d_vertex_buffer
*object
;
4612 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
4613 iface
, desc
, vertex_buffer
, flags
);
4615 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4617 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4620 TRACE("Created vertex buffer %p.\n", object
);
4621 *vertex_buffer
= &object
->IDirect3DVertexBuffer7_iface
;
4624 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4629 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4630 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4632 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4633 struct d3d_vertex_buffer
*object
;
4636 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n",
4637 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4640 return CLASS_E_NOAGGREGATION
;
4641 if (!vertex_buffer
|| !desc
)
4642 return DDERR_INVALIDPARAMS
;
4644 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4647 TRACE("Created vertex buffer %p.\n", object
);
4648 *vertex_buffer
= &object
->IDirect3DVertexBuffer_iface
;
4651 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4656 /*****************************************************************************
4657 * IDirect3D7::EnumZBufferFormats
4659 * Enumerates all supported Z buffer pixel formats
4665 * callback: callback to call for each pixel format
4666 * context: Pointer to pass back to the callback
4670 * DDERR_INVALIDPARAMS if callback is NULL
4671 * For details, see IWineD3DDevice::EnumZBufferFormats
4673 *****************************************************************************/
4674 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4675 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4677 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4678 struct wined3d_display_mode mode
;
4679 enum wined3d_device_type type
;
4683 /* Order matters. Specifically, BattleZone II (full version) expects the
4684 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4685 static const enum wined3d_format_id formats
[] =
4687 WINED3DFMT_S1_UINT_D15_UNORM
,
4688 WINED3DFMT_D16_UNORM
,
4689 WINED3DFMT_X8D24_UNORM
,
4690 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4691 WINED3DFMT_D24_UNORM_S8_UINT
,
4692 WINED3DFMT_D32_UNORM
,
4695 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4696 iface
, debugstr_guid(device_iid
), callback
, context
);
4698 if (!callback
) return DDERR_INVALIDPARAMS
;
4700 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4701 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4702 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4704 TRACE("Asked for HAL device.\n");
4705 type
= WINED3D_DEVICE_TYPE_HAL
;
4707 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4708 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4710 TRACE("Asked for SW device.\n");
4711 type
= WINED3D_DEVICE_TYPE_SW
;
4713 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4715 TRACE("Asked for REF device.\n");
4716 type
= WINED3D_DEVICE_TYPE_REF
;
4718 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4720 TRACE("Asked for NULLREF device.\n");
4721 type
= WINED3D_DEVICE_TYPE_NULLREF
;
4725 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4726 type
= WINED3D_DEVICE_TYPE_HAL
;
4729 wined3d_mutex_lock();
4730 /* We need an adapter format from somewhere to please wined3d and WGL.
4731 * Use the current display mode. So far all cards offer the same depth
4732 * stencil format for all modes, but if some do not and applications do
4733 * not like that we'll have to find some workaround, like iterating over
4734 * all imaginable formats and collecting all the depth stencil formats we
4736 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
4738 ERR("Failed to get display mode, hr %#x.\n", hr
);
4739 wined3d_mutex_unlock();
4743 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
4745 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4746 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_SURFACE
, formats
[i
])))
4748 DDPIXELFORMAT pformat
;
4750 memset(&pformat
, 0, sizeof(pformat
));
4751 pformat
.dwSize
= sizeof(pformat
);
4752 ddrawformat_from_wined3dformat(&pformat
, formats
[i
]);
4754 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
4755 hr
= callback(&pformat
, context
);
4756 if (hr
!= DDENUMRET_OK
)
4758 TRACE("Format enumeration cancelled by application.\n");
4759 wined3d_mutex_unlock();
4765 /* Historically some windows drivers used dwZBufferBitDepth=24 for WINED3DFMT_X8D24_UNORM,
4766 * while others used dwZBufferBitDepth=32. In either case the pitch matches a 32 bits per
4767 * pixel format, so we use dwZBufferBitDepth=32. Some games expect 24. Windows Vista and
4768 * newer enumerate both versions, so we do the same(bug 22434) */
4769 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4770 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_SURFACE
, WINED3DFMT_X8D24_UNORM
)))
4772 DDPIXELFORMAT x8d24
=
4774 sizeof(x8d24
), DDPF_ZBUFFER
, 0,
4775 {24}, {0x00000000}, {0x00ffffff}, {0x00000000}
4777 TRACE("Enumerating WINED3DFMT_X8D24_UNORM, dwZBufferBitDepth=24 version\n");
4778 callback(&x8d24
, context
);
4781 TRACE("End of enumeration.\n");
4783 wined3d_mutex_unlock();
4788 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
4789 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4791 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4793 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4794 iface
, debugstr_guid(device_iid
), callback
, context
);
4796 return d3d7_EnumZBufferFormats(&ddraw
->IDirect3D7_iface
, device_iid
, callback
, context
);
4799 /*****************************************************************************
4800 * IDirect3D7::EvictManagedTextures
4802 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
4803 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
4808 * D3D_OK, because it's a stub
4810 *****************************************************************************/
4811 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
4813 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4815 TRACE("iface %p!\n", iface
);
4817 wined3d_mutex_lock();
4818 if (ddraw
->flags
& DDRAW_D3D_INITIALIZED
)
4819 wined3d_device_evict_managed_resources(ddraw
->wined3d_device
);
4820 wined3d_mutex_unlock();
4825 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
4827 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4829 TRACE("iface %p.\n", iface
);
4831 return d3d7_EvictManagedTextures(&ddraw
->IDirect3D7_iface
);
4834 /*****************************************************************************
4835 * IDirectDraw7 VTable
4836 *****************************************************************************/
4837 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
4840 ddraw7_QueryInterface
,
4845 ddraw7_CreateClipper
,
4846 ddraw7_CreatePalette
,
4847 ddraw7_CreateSurface
,
4848 ddraw7_DuplicateSurface
,
4849 ddraw7_EnumDisplayModes
,
4850 ddraw7_EnumSurfaces
,
4851 ddraw7_FlipToGDISurface
,
4853 ddraw7_GetDisplayMode
,
4854 ddraw7_GetFourCCCodes
,
4855 ddraw7_GetGDISurface
,
4856 ddraw7_GetMonitorFrequency
,
4858 ddraw7_GetVerticalBlankStatus
,
4860 ddraw7_RestoreDisplayMode
,
4861 ddraw7_SetCooperativeLevel
,
4862 ddraw7_SetDisplayMode
,
4863 ddraw7_WaitForVerticalBlank
,
4865 ddraw7_GetAvailableVidMem
,
4867 ddraw7_GetSurfaceFromDC
,
4869 ddraw7_RestoreAllSurfaces
,
4870 ddraw7_TestCooperativeLevel
,
4871 ddraw7_GetDeviceIdentifier
,
4873 ddraw7_StartModeTest
,
4877 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
4880 ddraw4_QueryInterface
,
4885 ddraw4_CreateClipper
,
4886 ddraw4_CreatePalette
,
4887 ddraw4_CreateSurface
,
4888 ddraw4_DuplicateSurface
,
4889 ddraw4_EnumDisplayModes
,
4890 ddraw4_EnumSurfaces
,
4891 ddraw4_FlipToGDISurface
,
4893 ddraw4_GetDisplayMode
,
4894 ddraw4_GetFourCCCodes
,
4895 ddraw4_GetGDISurface
,
4896 ddraw4_GetMonitorFrequency
,
4898 ddraw4_GetVerticalBlankStatus
,
4900 ddraw4_RestoreDisplayMode
,
4901 ddraw4_SetCooperativeLevel
,
4902 ddraw4_SetDisplayMode
,
4903 ddraw4_WaitForVerticalBlank
,
4905 ddraw4_GetAvailableVidMem
,
4907 ddraw4_GetSurfaceFromDC
,
4909 ddraw4_RestoreAllSurfaces
,
4910 ddraw4_TestCooperativeLevel
,
4911 ddraw4_GetDeviceIdentifier
,
4914 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
4917 ddraw2_QueryInterface
,
4922 ddraw2_CreateClipper
,
4923 ddraw2_CreatePalette
,
4924 ddraw2_CreateSurface
,
4925 ddraw2_DuplicateSurface
,
4926 ddraw2_EnumDisplayModes
,
4927 ddraw2_EnumSurfaces
,
4928 ddraw2_FlipToGDISurface
,
4930 ddraw2_GetDisplayMode
,
4931 ddraw2_GetFourCCCodes
,
4932 ddraw2_GetGDISurface
,
4933 ddraw2_GetMonitorFrequency
,
4935 ddraw2_GetVerticalBlankStatus
,
4937 ddraw2_RestoreDisplayMode
,
4938 ddraw2_SetCooperativeLevel
,
4939 ddraw2_SetDisplayMode
,
4940 ddraw2_WaitForVerticalBlank
,
4942 ddraw2_GetAvailableVidMem
,
4945 static const struct IDirectDrawVtbl ddraw1_vtbl
=
4948 ddraw1_QueryInterface
,
4953 ddraw1_CreateClipper
,
4954 ddraw1_CreatePalette
,
4955 ddraw1_CreateSurface
,
4956 ddraw1_DuplicateSurface
,
4957 ddraw1_EnumDisplayModes
,
4958 ddraw1_EnumSurfaces
,
4959 ddraw1_FlipToGDISurface
,
4961 ddraw1_GetDisplayMode
,
4962 ddraw1_GetFourCCCodes
,
4963 ddraw1_GetGDISurface
,
4964 ddraw1_GetMonitorFrequency
,
4966 ddraw1_GetVerticalBlankStatus
,
4968 ddraw1_RestoreDisplayMode
,
4969 ddraw1_SetCooperativeLevel
,
4970 ddraw1_SetDisplayMode
,
4971 ddraw1_WaitForVerticalBlank
,
4974 static const struct IDirect3D7Vtbl d3d7_vtbl
=
4976 /* IUnknown methods */
4977 d3d7_QueryInterface
,
4980 /* IDirect3D7 methods */
4983 d3d7_CreateVertexBuffer
,
4984 d3d7_EnumZBufferFormats
,
4985 d3d7_EvictManagedTextures
4988 static const struct IDirect3D3Vtbl d3d3_vtbl
=
4990 /* IUnknown methods */
4991 d3d3_QueryInterface
,
4994 /* IDirect3D3 methods */
4997 d3d3_CreateMaterial
,
4998 d3d3_CreateViewport
,
5001 d3d3_CreateVertexBuffer
,
5002 d3d3_EnumZBufferFormats
,
5003 d3d3_EvictManagedTextures
5006 static const struct IDirect3D2Vtbl d3d2_vtbl
=
5008 /* IUnknown methods */
5009 d3d2_QueryInterface
,
5012 /* IDirect3D2 methods */
5015 d3d2_CreateMaterial
,
5016 d3d2_CreateViewport
,
5021 static const struct IDirect3DVtbl d3d1_vtbl
=
5023 /* IUnknown methods */
5024 d3d1_QueryInterface
,
5027 /* IDirect3D methods */
5031 d3d1_CreateMaterial
,
5032 d3d1_CreateViewport
,
5036 /*****************************************************************************
5039 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
5040 * if none was found.
5042 * This function is in ddraw.c and the DDraw object space because D3D7
5043 * vertex buffers are created using the IDirect3D interface to the ddraw
5044 * object, so they can be valid across D3D devices(theoretically. The ddraw
5045 * object also owns the wined3d device
5049 * fvf: Fvf to find the decl for
5052 * NULL in case of an error, the vertex declaration for the FVF otherwise.
5054 *****************************************************************************/
5055 struct wined3d_vertex_declaration
*ddraw_find_decl(struct ddraw
*This
, DWORD fvf
)
5057 struct wined3d_vertex_declaration
*pDecl
= NULL
;
5059 int p
, low
, high
; /* deliberately signed */
5060 struct FvfToDecl
*convertedDecls
= This
->decls
;
5062 TRACE("Searching for declaration for fvf %08x... ", fvf
);
5065 high
= This
->numConvertedDecls
- 1;
5066 while(low
<= high
) {
5067 p
= (low
+ high
) >> 1;
5069 if(convertedDecls
[p
].fvf
== fvf
) {
5070 TRACE("found %p\n", convertedDecls
[p
].decl
);
5071 return convertedDecls
[p
].decl
;
5072 } else if(convertedDecls
[p
].fvf
< fvf
) {
5078 TRACE("not found. Creating and inserting at position %d.\n", low
);
5080 hr
= wined3d_vertex_declaration_create_from_fvf(This
->wined3d_device
,
5081 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
5082 if (hr
!= S_OK
) return NULL
;
5084 if(This
->declArraySize
== This
->numConvertedDecls
) {
5085 int grow
= max(This
->declArraySize
/ 2, 8);
5086 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
5087 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
5088 if (!convertedDecls
)
5090 wined3d_vertex_declaration_decref(pDecl
);
5093 This
->decls
= convertedDecls
;
5094 This
->declArraySize
+= grow
;
5097 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
5098 convertedDecls
[low
].decl
= pDecl
;
5099 convertedDecls
[low
].fvf
= fvf
;
5100 This
->numConvertedDecls
++;
5102 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
5106 static inline struct ddraw
*ddraw_from_device_parent(struct wined3d_device_parent
*device_parent
)
5108 return CONTAINING_RECORD(device_parent
, struct ddraw
, device_parent
);
5111 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
5112 struct wined3d_device
*device
)
5114 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
5117 /* This is run from device_process_message() in wined3d, we can't take the
5119 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
5121 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
5122 MONITORINFO monitor_info
;
5126 TRACE("device_parent %p.\n", device_parent
);
5128 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) || !ddraw
->swapchain_window
)
5130 TRACE("Nothing to resize.\n");
5134 monitor
= MonitorFromWindow(ddraw
->swapchain_window
, MONITOR_DEFAULTTOPRIMARY
);
5135 monitor_info
.cbSize
= sizeof(monitor_info
);
5136 if (!GetMonitorInfoW(monitor
, &monitor_info
))
5138 ERR("Failed to get monitor info.\n");
5142 r
= &monitor_info
.rcMonitor
;
5143 TRACE("Resizing window %p to %s.\n", ddraw
->swapchain_window
, wine_dbgstr_rect(r
));
5145 if (!SetWindowPos(ddraw
->swapchain_window
, HWND_TOP
, r
->left
, r
->top
,
5146 r
->right
- r
->left
, r
->bottom
- r
->top
, SWP_SHOWWINDOW
| SWP_NOACTIVATE
))
5147 ERR("Failed to resize window.\n");
5150 static HRESULT CDECL
device_parent_create_texture_surface(struct wined3d_device_parent
*device_parent
,
5151 void *container_parent
, const struct wined3d_resource_desc
*wined3d_desc
, UINT sub_resource_idx
,
5152 DWORD flags
, struct wined3d_surface
**surface
)
5154 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
5155 struct ddraw_surface
*tex_root
= container_parent
;
5156 DDSURFACEDESC2 desc
= tex_root
->surface_desc
;
5157 struct ddraw_surface
*ddraw_surface
;
5160 TRACE("device_parent %p, container_parent %p, wined3d_desc %p, sub_resource_idx %u, flags %#x, surface %p.\n",
5161 device_parent
, container_parent
, wined3d_desc
, sub_resource_idx
, flags
, surface
);
5163 /* The ddraw root surface is created before the wined3d texture. */
5164 if (!sub_resource_idx
)
5166 ddraw_surface
= tex_root
;
5170 desc
.dwWidth
= wined3d_desc
->width
;
5171 desc
.dwHeight
= wined3d_desc
->height
;
5173 /* FIXME: Validate that format, usage, pool, etc. really make sense. */
5174 if (FAILED(hr
= ddraw_create_surface(ddraw
, &desc
, flags
, &ddraw_surface
, tex_root
->version
)))
5178 *surface
= ddraw_surface
->wined3d_surface
;
5179 wined3d_surface_incref(*surface
);
5184 static void STDMETHODCALLTYPE
ddraw_frontbuffer_destroyed(void *parent
)
5186 struct ddraw
*ddraw
= parent
;
5187 ddraw
->wined3d_frontbuffer
= NULL
;
5190 static const struct wined3d_parent_ops ddraw_frontbuffer_parent_ops
=
5192 ddraw_frontbuffer_destroyed
,
5195 static HRESULT CDECL
device_parent_create_swapchain_surface(struct wined3d_device_parent
*device_parent
,
5196 void *container_parent
, const struct wined3d_resource_desc
*desc
, struct wined3d_surface
**surface
)
5198 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
5201 TRACE("device_parent %p, container_parent %p, desc %p, surface %p.\n",
5202 device_parent
, container_parent
, desc
, surface
);
5204 if (ddraw
->wined3d_frontbuffer
)
5206 ERR("Frontbuffer already created.\n");
5210 if (SUCCEEDED(hr
= wined3d_surface_create(ddraw
->wined3d_device
, desc
->width
, desc
->height
, desc
->format
,
5211 desc
->usage
, desc
->pool
, desc
->multisample_type
, desc
->multisample_quality
, WINED3D_SURFACE_MAPPABLE
,
5212 ddraw
, &ddraw_frontbuffer_parent_ops
, surface
)))
5213 ddraw
->wined3d_frontbuffer
= *surface
;
5218 static HRESULT CDECL
device_parent_create_volume(struct wined3d_device_parent
*device_parent
,
5219 void *container_parent
, UINT width
, UINT height
, UINT depth
, UINT level
,
5220 enum wined3d_format_id format
, enum wined3d_pool pool
, DWORD usage
,
5221 struct wined3d_volume
**volume
)
5223 TRACE("device_parent %p, container_parent %p, width %u, height %u, depth %u, "
5224 "format %#x, pool %#x, usage %#x, volume %p.\n",
5225 device_parent
, container_parent
, width
, height
, depth
,
5226 format
, pool
, usage
, volume
);
5228 ERR("Not implemented!\n");
5233 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
5234 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
5236 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
5239 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent
, desc
, swapchain
);
5241 if (ddraw
->wined3d_swapchain
)
5243 ERR("Swapchain already created.\n");
5247 if (FAILED(hr
= wined3d_swapchain_create(ddraw
->wined3d_device
, desc
, NULL
,
5248 &ddraw_null_wined3d_parent_ops
, swapchain
)))
5249 WARN("Failed to create swapchain, hr %#x.\n", hr
);
5254 static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops
=
5256 device_parent_wined3d_device_created
,
5257 device_parent_mode_changed
,
5258 device_parent_create_swapchain_surface
,
5259 device_parent_create_texture_surface
,
5260 device_parent_create_volume
,
5261 device_parent_create_swapchain
,
5264 HRESULT
ddraw_init(struct ddraw
*ddraw
, enum wined3d_device_type device_type
)
5270 ddraw
->IDirectDraw7_iface
.lpVtbl
= &ddraw7_vtbl
;
5271 ddraw
->IDirectDraw_iface
.lpVtbl
= &ddraw1_vtbl
;
5272 ddraw
->IDirectDraw2_iface
.lpVtbl
= &ddraw2_vtbl
;
5273 ddraw
->IDirectDraw4_iface
.lpVtbl
= &ddraw4_vtbl
;
5274 ddraw
->IDirect3D_iface
.lpVtbl
= &d3d1_vtbl
;
5275 ddraw
->IDirect3D2_iface
.lpVtbl
= &d3d2_vtbl
;
5276 ddraw
->IDirect3D3_iface
.lpVtbl
= &d3d3_vtbl
;
5277 ddraw
->IDirect3D7_iface
.lpVtbl
= &d3d7_vtbl
;
5278 ddraw
->device_parent
.ops
= &ddraw_wined3d_device_parent_ops
;
5279 ddraw
->numIfaces
= 1;
5282 flags
= WINED3D_LEGACY_DEPTH_BIAS
| WINED3D_VIDMEM_ACCOUNTING
;
5283 if (!(ddraw
->wined3d
= wined3d_create(7, flags
)))
5285 if (!(ddraw
->wined3d
= wined3d_create(7, flags
| WINED3D_NO3D
)))
5287 WARN("Failed to create a wined3d object.\n");
5292 if (FAILED(hr
= wined3d_get_device_caps(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
, &caps
)))
5294 ERR("Failed to get device caps, hr %#x.\n", hr
);
5295 wined3d_decref(ddraw
->wined3d
);
5299 if (!(caps
.ddraw_caps
.caps
& WINEDDCAPS_3D
))
5301 WARN("Created a wined3d object without 3D support.\n");
5302 ddraw
->flags
|= DDRAW_NO3D
;
5305 if (FAILED(hr
= wined3d_device_create(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
,
5306 NULL
, 0, DDRAW_STRIDE_ALIGNMENT
, &ddraw
->device_parent
, &ddraw
->wined3d_device
)))
5308 WARN("Failed to create a wined3d device, hr %#x.\n", hr
);
5309 wined3d_decref(ddraw
->wined3d
);
5313 list_init(&ddraw
->surface_list
);