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
=
38 "vga.dll", /* default 2D driver */
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
);
1479 WARN("IDirectDraw7::GetAvailableVidMem failed\n");
1480 wined3d_mutex_unlock();
1484 hr
= IDirectDraw7_GetFourCCCodes(iface
, &caps
.dwNumFourCCCodes
, NULL
);
1485 wined3d_mutex_unlock();
1488 WARN("IDirectDraw7::GetFourCCCodes failed\n");
1492 caps
.dwCaps
= winecaps
.ddraw_caps
.caps
;
1493 caps
.dwCaps2
= winecaps
.ddraw_caps
.caps2
;
1494 caps
.dwCKeyCaps
= winecaps
.ddraw_caps
.color_key_caps
;
1495 caps
.dwFXCaps
= winecaps
.ddraw_caps
.fx_caps
;
1496 caps
.dwPalCaps
= DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
;
1497 caps
.ddsCaps
.dwCaps
= winecaps
.ddraw_caps
.dds_caps
;
1498 caps
.dwSVBCaps
= winecaps
.ddraw_caps
.svb_caps
;
1499 caps
.dwSVBCKeyCaps
= winecaps
.ddraw_caps
.svb_color_key_caps
;
1500 caps
.dwSVBFXCaps
= winecaps
.ddraw_caps
.svb_fx_caps
;
1501 caps
.dwVSBCaps
= winecaps
.ddraw_caps
.vsb_caps
;
1502 caps
.dwVSBCKeyCaps
= winecaps
.ddraw_caps
.vsb_color_key_caps
;
1503 caps
.dwVSBFXCaps
= winecaps
.ddraw_caps
.vsb_fx_caps
;
1504 caps
.dwSSBCaps
= winecaps
.ddraw_caps
.ssb_caps
;
1505 caps
.dwSSBCKeyCaps
= winecaps
.ddraw_caps
.ssb_color_key_caps
;
1506 caps
.dwSSBFXCaps
= winecaps
.ddraw_caps
.ssb_fx_caps
;
1508 caps
.dwCaps
|= DDCAPS_ALIGNSTRIDE
;
1509 caps
.dwAlignStrideAlign
= DDRAW_STRIDE_ALIGNMENT
;
1513 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &caps
);
1514 if (TRACE_ON(ddraw
))
1516 TRACE("Driver Caps :\n");
1517 DDRAW_dump_DDCAPS(DriverCaps
);
1523 DD_STRUCT_COPY_BYSIZE(HELCaps
, &caps
);
1524 if (TRACE_ON(ddraw
))
1526 TRACE("HEL Caps :\n");
1527 DDRAW_dump_DDCAPS(HELCaps
);
1534 static HRESULT WINAPI
ddraw4_GetCaps(IDirectDraw4
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1536 struct ddraw
*ddraw
= impl_from_IDirectDraw4(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
ddraw2_GetCaps(IDirectDraw2
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1545 struct ddraw
*ddraw
= impl_from_IDirectDraw2(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 static HRESULT WINAPI
ddraw1_GetCaps(IDirectDraw
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1554 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1556 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1558 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1561 /*****************************************************************************
1562 * IDirectDraw7::Compact
1564 * No idea what it does, MSDN says it's not implemented.
1567 * DD_OK, but this is unchecked
1569 *****************************************************************************/
1570 static HRESULT WINAPI
ddraw7_Compact(IDirectDraw7
*iface
)
1572 TRACE("iface %p.\n", iface
);
1577 static HRESULT WINAPI
ddraw4_Compact(IDirectDraw4
*iface
)
1579 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1581 TRACE("iface %p.\n", iface
);
1583 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1586 static HRESULT WINAPI
ddraw2_Compact(IDirectDraw2
*iface
)
1588 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1590 TRACE("iface %p.\n", iface
);
1592 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1595 static HRESULT WINAPI
ddraw1_Compact(IDirectDraw
*iface
)
1597 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1599 TRACE("iface %p.\n", iface
);
1601 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1604 /*****************************************************************************
1605 * IDirectDraw7::GetDisplayMode
1607 * Returns information about the current display mode
1609 * Exists in Version 1, 2, 4 and 7
1612 * DDSD: Address of a surface description structure to write the info to
1617 *****************************************************************************/
1618 static HRESULT WINAPI
ddraw7_GetDisplayMode(IDirectDraw7
*iface
, DDSURFACEDESC2
*DDSD
)
1620 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1621 struct wined3d_display_mode mode
;
1625 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
1627 wined3d_mutex_lock();
1628 /* This seems sane */
1631 wined3d_mutex_unlock();
1632 return DDERR_INVALIDPARAMS
;
1635 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1637 ERR("Failed to get display mode, hr %#x.\n", hr
);
1638 wined3d_mutex_unlock();
1642 Size
= DDSD
->dwSize
;
1643 memset(DDSD
, 0, Size
);
1645 DDSD
->dwSize
= Size
;
1646 DDSD
->dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
1647 DDSD
->dwWidth
= mode
.width
;
1648 DDSD
->dwHeight
= mode
.height
;
1649 DDSD
->u2
.dwRefreshRate
= 60;
1650 DDSD
->ddsCaps
.dwCaps
= 0;
1651 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
1652 ddrawformat_from_wined3dformat(&DDSD
->u4
.ddpfPixelFormat
, mode
.format_id
);
1653 DDSD
->u1
.lPitch
= mode
.width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
1657 TRACE("Returning surface desc :\n");
1658 DDRAW_dump_surface_desc(DDSD
);
1661 wined3d_mutex_unlock();
1666 static HRESULT WINAPI
ddraw4_GetDisplayMode(IDirectDraw4
*iface
, DDSURFACEDESC2
*surface_desc
)
1668 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1670 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1672 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, surface_desc
);
1675 static HRESULT WINAPI
ddraw2_GetDisplayMode(IDirectDraw2
*iface
, DDSURFACEDESC
*surface_desc
)
1677 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1679 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1681 /* FIXME: Test sizes, properly convert surface_desc */
1682 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1685 static HRESULT WINAPI
ddraw1_GetDisplayMode(IDirectDraw
*iface
, DDSURFACEDESC
*surface_desc
)
1687 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1689 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1691 /* FIXME: Test sizes, properly convert surface_desc */
1692 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1695 /*****************************************************************************
1696 * IDirectDraw7::GetFourCCCodes
1698 * Returns an array of supported FourCC codes.
1700 * Exists in Version 1, 2, 4 and 7
1703 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
1704 * of enumerated codes
1705 * Codes: Pointer to an array of DWORDs where the supported codes are written
1709 * Always returns DD_OK, as it's a stub for now
1711 *****************************************************************************/
1712 static HRESULT WINAPI
ddraw7_GetFourCCCodes(IDirectDraw7
*iface
, DWORD
*NumCodes
, DWORD
*Codes
)
1714 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1715 static const enum wined3d_format_id formats
[] =
1717 WINED3DFMT_YUY2
, WINED3DFMT_UYVY
, WINED3DFMT_YV12
,
1718 WINED3DFMT_DXT1
, WINED3DFMT_DXT2
, WINED3DFMT_DXT3
, WINED3DFMT_DXT4
, WINED3DFMT_DXT5
,
1719 WINED3DFMT_ATI2N
, WINED3DFMT_NVHU
, WINED3DFMT_NVHS
1721 struct wined3d_display_mode mode
;
1722 DWORD count
= 0, i
, outsize
;
1725 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, NumCodes
, Codes
);
1727 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1729 ERR("Failed to get display mode, hr %#x.\n", hr
);
1733 outsize
= NumCodes
&& Codes
? *NumCodes
: 0;
1735 for (i
= 0; i
< (sizeof(formats
) / sizeof(formats
[0])); ++i
)
1737 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, WINED3D_DEVICE_TYPE_HAL
,
1738 mode
.format_id
, 0, WINED3D_RTYPE_SURFACE
, formats
[i
])))
1740 if (count
< outsize
)
1741 Codes
[count
] = formats
[i
];
1746 TRACE("Returning %u FourCC codes\n", count
);
1753 static HRESULT WINAPI
ddraw4_GetFourCCCodes(IDirectDraw4
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1755 struct ddraw
*ddraw
= impl_from_IDirectDraw4(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
ddraw2_GetFourCCCodes(IDirectDraw2
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1764 struct ddraw
*ddraw
= impl_from_IDirectDraw2(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
ddraw1_GetFourCCCodes(IDirectDraw
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1773 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1775 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1777 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1780 static HRESULT WINAPI
ddraw7_GetMonitorFrequency(IDirectDraw7
*iface
, DWORD
*frequency
)
1782 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1783 struct wined3d_display_mode mode
;
1786 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1788 wined3d_mutex_lock();
1789 hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
);
1790 wined3d_mutex_unlock();
1793 WARN("Failed to get display mode, hr %#x.\n", hr
);
1797 *frequency
= mode
.refresh_rate
;
1802 static HRESULT WINAPI
ddraw4_GetMonitorFrequency(IDirectDraw4
*iface
, DWORD
*frequency
)
1804 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1806 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1808 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1811 static HRESULT WINAPI
ddraw2_GetMonitorFrequency(IDirectDraw2
*iface
, DWORD
*frequency
)
1813 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1815 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1817 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1820 static HRESULT WINAPI
ddraw1_GetMonitorFrequency(IDirectDraw
*iface
, DWORD
*frequency
)
1822 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1824 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1826 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1829 static HRESULT WINAPI
ddraw7_GetVerticalBlankStatus(IDirectDraw7
*iface
, BOOL
*status
)
1831 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1832 struct wined3d_raster_status raster_status
;
1835 TRACE("iface %p, status %p.\n", iface
, status
);
1838 return DDERR_INVALIDPARAMS
;
1840 wined3d_mutex_lock();
1841 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
1842 wined3d_mutex_unlock();
1845 WARN("Failed to get raster status, hr %#x.\n", hr
);
1849 *status
= raster_status
.in_vblank
;
1854 static HRESULT WINAPI
ddraw4_GetVerticalBlankStatus(IDirectDraw4
*iface
, BOOL
*status
)
1856 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1858 TRACE("iface %p, status %p.\n", iface
, status
);
1860 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1863 static HRESULT WINAPI
ddraw2_GetVerticalBlankStatus(IDirectDraw2
*iface
, BOOL
*status
)
1865 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1867 TRACE("iface %p, status %p.\n", iface
, status
);
1869 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1872 static HRESULT WINAPI
ddraw1_GetVerticalBlankStatus(IDirectDraw
*iface
, BOOL
*status
)
1874 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1876 TRACE("iface %p, status %p.\n", iface
, status
);
1878 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1881 /*****************************************************************************
1882 * IDirectDraw7::GetAvailableVidMem
1884 * Returns the total and free video memory
1887 * Caps: Specifies the memory type asked for
1888 * total: Pointer to a DWORD to be filled with the total memory
1889 * free: Pointer to a DWORD to be filled with the free memory
1893 * DDERR_INVALIDPARAMS if free and total are NULL
1895 *****************************************************************************/
1896 static HRESULT WINAPI
ddraw7_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*Caps
, DWORD
*total
,
1899 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1902 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, Caps
, total
, free
);
1904 if (TRACE_ON(ddraw
))
1906 TRACE("Asked for memory with description: ");
1907 DDRAW_dump_DDSCAPS2(Caps
);
1909 wined3d_mutex_lock();
1911 /* Todo: System memory vs local video memory vs non-local video memory
1912 * The MSDN also mentions differences between texture memory and other
1913 * resources, but that's not important
1916 if( (!total
) && (!free
) )
1918 wined3d_mutex_unlock();
1919 return DDERR_INVALIDPARAMS
;
1923 *free
= wined3d_device_get_available_texture_mem(ddraw
->wined3d_device
);
1926 struct wined3d_adapter_identifier desc
= {0};
1928 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0, &desc
);
1929 *total
= desc
.video_memory
;
1932 wined3d_mutex_unlock();
1937 static HRESULT WINAPI
ddraw4_GetAvailableVidMem(IDirectDraw4
*iface
,
1938 DDSCAPS2
*caps
, DWORD
*total
, DWORD
*free
)
1940 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1942 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1944 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, caps
, total
, free
);
1947 static HRESULT WINAPI
ddraw2_GetAvailableVidMem(IDirectDraw2
*iface
,
1948 DDSCAPS
*caps
, DWORD
*total
, DWORD
*free
)
1950 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1953 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1955 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
1956 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, &caps2
, total
, free
);
1959 /*****************************************************************************
1960 * IDirectDraw7::Initialize
1962 * Initializes a DirectDraw interface.
1965 * GUID: Interface identifier. Well, don't know what this is really good
1969 * Returns DD_OK on the first call,
1970 * DDERR_ALREADYINITIALIZED on repeated calls
1972 *****************************************************************************/
1973 static HRESULT WINAPI
ddraw7_Initialize(IDirectDraw7
*iface
, GUID
*guid
)
1975 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1977 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1979 if (ddraw
->flags
& DDRAW_INITIALIZED
)
1980 return DDERR_ALREADYINITIALIZED
;
1982 /* FIXME: To properly take the GUID into account we should call
1983 * ddraw_init() here instead of in DDRAW_Create(). */
1985 FIXME("Ignoring guid %s.\n", debugstr_guid(guid
));
1987 ddraw
->flags
|= DDRAW_INITIALIZED
;
1991 static HRESULT WINAPI
ddraw4_Initialize(IDirectDraw4
*iface
, GUID
*guid
)
1993 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1995 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1997 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2000 static HRESULT WINAPI
ddraw2_Initialize(IDirectDraw2
*iface
, GUID
*guid
)
2002 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2004 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2006 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2009 static HRESULT WINAPI
ddraw1_Initialize(IDirectDraw
*iface
, GUID
*guid
)
2011 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2013 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2015 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2018 static HRESULT WINAPI
d3d1_Initialize(IDirect3D
*iface
, REFIID riid
)
2020 TRACE("iface %p, riid %s.\n", iface
, debugstr_guid(riid
));
2022 return DDERR_ALREADYINITIALIZED
;
2025 /*****************************************************************************
2026 * IDirectDraw7::FlipToGDISurface
2028 * "Makes the surface that the GDI writes to the primary surface"
2029 * Looks like some windows specific thing we don't have to care about.
2030 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
2031 * show error boxes ;)
2032 * Well, just return DD_OK.
2035 * Always returns DD_OK
2037 *****************************************************************************/
2038 static HRESULT WINAPI
ddraw7_FlipToGDISurface(IDirectDraw7
*iface
)
2040 FIXME("iface %p stub!\n", iface
);
2045 static HRESULT WINAPI
ddraw4_FlipToGDISurface(IDirectDraw4
*iface
)
2047 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2049 TRACE("iface %p.\n", iface
);
2051 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2054 static HRESULT WINAPI
ddraw2_FlipToGDISurface(IDirectDraw2
*iface
)
2056 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2058 TRACE("iface %p.\n", iface
);
2060 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2063 static HRESULT WINAPI
ddraw1_FlipToGDISurface(IDirectDraw
*iface
)
2065 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2067 TRACE("iface %p.\n", iface
);
2069 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2072 /*****************************************************************************
2073 * IDirectDraw7::WaitForVerticalBlank
2075 * This method allows applications to get in sync with the vertical blank
2077 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
2078 * redraw the screen, most likely because of this stub
2081 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
2082 * or DDWAITVB_BLOCKEND
2083 * h: Not used, according to MSDN
2086 * Always returns DD_OK
2088 *****************************************************************************/
2089 static HRESULT WINAPI
ddraw7_WaitForVerticalBlank(IDirectDraw7
*iface
, DWORD Flags
, HANDLE event
)
2093 TRACE("iface %p, flags %#x, event %p.\n", iface
, Flags
, event
);
2095 /* This function is called often, so print the fixme only once */
2098 FIXME("iface %p, flags %#x, event %p stub!\n", iface
, Flags
, event
);
2102 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
2103 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
2104 return DDERR_UNSUPPORTED
; /* unchecked */
2109 static HRESULT WINAPI
ddraw4_WaitForVerticalBlank(IDirectDraw4
*iface
, DWORD flags
, HANDLE event
)
2111 struct ddraw
*ddraw
= impl_from_IDirectDraw4(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
ddraw2_WaitForVerticalBlank(IDirectDraw2
*iface
, DWORD flags
, HANDLE event
)
2120 struct ddraw
*ddraw
= impl_from_IDirectDraw2(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
ddraw1_WaitForVerticalBlank(IDirectDraw
*iface
, DWORD flags
, HANDLE event
)
2129 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2131 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2133 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2136 static HRESULT WINAPI
ddraw7_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
2138 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2139 struct wined3d_raster_status raster_status
;
2142 TRACE("iface %p, line %p.\n", iface
, Scanline
);
2144 wined3d_mutex_lock();
2145 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
2146 wined3d_mutex_unlock();
2149 WARN("Failed to get raster status, hr %#x.\n", hr
);
2153 *Scanline
= raster_status
.scan_line
;
2155 if (raster_status
.in_vblank
)
2156 return DDERR_VERTICALBLANKINPROGRESS
;
2161 static HRESULT WINAPI
ddraw4_GetScanLine(IDirectDraw4
*iface
, DWORD
*line
)
2163 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2165 TRACE("iface %p, line %p.\n", iface
, line
);
2167 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2170 static HRESULT WINAPI
ddraw2_GetScanLine(IDirectDraw2
*iface
, DWORD
*line
)
2172 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2174 TRACE("iface %p, line %p.\n", iface
, line
);
2176 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2179 static HRESULT WINAPI
ddraw1_GetScanLine(IDirectDraw
*iface
, DWORD
*line
)
2181 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2183 TRACE("iface %p, line %p.\n", iface
, line
);
2185 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2188 /*****************************************************************************
2189 * IDirectDraw7::TestCooperativeLevel
2191 * Informs the application about the state of the video adapter, depending
2192 * on the cooperative level
2195 * DD_OK if the device is in a sane state
2196 * DDERR_NOEXCLUSIVEMODE or DDERR_EXCLUSIVEMODEALREADYSET
2197 * if the state is not correct(See below)
2199 *****************************************************************************/
2200 static HRESULT WINAPI
ddraw7_TestCooperativeLevel(IDirectDraw7
*iface
)
2202 TRACE("iface %p.\n", iface
);
2207 static HRESULT WINAPI
ddraw4_TestCooperativeLevel(IDirectDraw4
*iface
)
2209 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2211 TRACE("iface %p.\n", iface
);
2213 return ddraw7_TestCooperativeLevel(&ddraw
->IDirectDraw7_iface
);
2216 /*****************************************************************************
2217 * IDirectDraw7::GetGDISurface
2219 * Returns the surface that GDI is treating as the primary surface.
2220 * For Wine this is the front buffer
2223 * GDISurface: Address to write the surface pointer to
2226 * DD_OK if the surface was found
2227 * DDERR_NOTFOUND if the GDI surface wasn't found
2229 *****************************************************************************/
2230 static HRESULT WINAPI
ddraw7_GetGDISurface(IDirectDraw7
*iface
, IDirectDrawSurface7
**GDISurface
)
2232 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2234 TRACE("iface %p, surface %p.\n", iface
, GDISurface
);
2236 wined3d_mutex_lock();
2238 if (!(*GDISurface
= &ddraw
->primary
->IDirectDrawSurface7_iface
))
2240 WARN("Primary not created yet.\n");
2241 wined3d_mutex_unlock();
2242 return DDERR_NOTFOUND
;
2244 IDirectDrawSurface7_AddRef(*GDISurface
);
2246 wined3d_mutex_unlock();
2251 static HRESULT WINAPI
ddraw4_GetGDISurface(IDirectDraw4
*iface
, IDirectDrawSurface4
**surface
)
2253 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2254 struct ddraw_surface
*surface_impl
;
2255 IDirectDrawSurface7
*surface7
;
2258 TRACE("iface %p, surface %p.\n", iface
, surface
);
2260 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2266 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2267 *surface
= &surface_impl
->IDirectDrawSurface4_iface
;
2268 IDirectDrawSurface4_AddRef(*surface
);
2269 IDirectDrawSurface7_Release(surface7
);
2274 static HRESULT WINAPI
ddraw2_GetGDISurface(IDirectDraw2
*iface
, IDirectDrawSurface
**surface
)
2276 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2277 struct ddraw_surface
*surface_impl
;
2278 IDirectDrawSurface7
*surface7
;
2281 TRACE("iface %p, surface %p.\n", iface
, surface
);
2283 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2289 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2290 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2291 IDirectDrawSurface_AddRef(*surface
);
2292 IDirectDrawSurface7_Release(surface7
);
2297 static HRESULT WINAPI
ddraw1_GetGDISurface(IDirectDraw
*iface
, IDirectDrawSurface
**surface
)
2299 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2300 struct ddraw_surface
*surface_impl
;
2301 IDirectDrawSurface7
*surface7
;
2304 TRACE("iface %p, surface %p.\n", iface
, surface
);
2306 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2312 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2313 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2314 IDirectDrawSurface_AddRef(*surface
);
2315 IDirectDrawSurface7_Release(surface7
);
2320 struct displaymodescallback_context
2322 LPDDENUMMODESCALLBACK func
;
2326 static HRESULT CALLBACK
EnumDisplayModesCallbackThunk(DDSURFACEDESC2
*surface_desc
, void *context
)
2328 struct displaymodescallback_context
*cbcontext
= context
;
2331 DDSD2_to_DDSD(surface_desc
, &desc
);
2332 return cbcontext
->func(&desc
, cbcontext
->context
);
2335 /*****************************************************************************
2336 * IDirectDraw7::EnumDisplayModes
2338 * Enumerates the supported Display modes. The modes can be filtered with
2339 * the DDSD parameter.
2342 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES. For old ddraw
2343 * versions (3 and older?) this is reserved and must be 0.
2344 * DDSD: Surface description to filter the modes
2345 * Context: Pointer passed back to the callback function
2346 * cb: Application-provided callback function
2350 * DDERR_INVALIDPARAMS if the callback wasn't set
2352 *****************************************************************************/
2353 static HRESULT WINAPI
ddraw7_EnumDisplayModes(IDirectDraw7
*iface
, DWORD Flags
,
2354 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMMODESCALLBACK2 cb
)
2356 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2357 struct wined3d_display_mode
*enum_modes
= NULL
;
2358 struct wined3d_display_mode mode
;
2359 unsigned int modenum
, fmt
;
2360 DDSURFACEDESC2 callback_sd
;
2361 unsigned enum_mode_count
= 0, enum_mode_array_size
= 16;
2362 DDPIXELFORMAT pixelformat
;
2364 static const enum wined3d_format_id checkFormatList
[] =
2366 WINED3DFMT_B8G8R8X8_UNORM
,
2367 WINED3DFMT_B5G6R5_UNORM
,
2371 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2372 iface
, Flags
, DDSD
, Context
, cb
);
2375 return DDERR_INVALIDPARAMS
;
2377 enum_modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(*enum_modes
) * enum_mode_array_size
);
2378 if (!enum_modes
) return DDERR_OUTOFMEMORY
;
2380 wined3d_mutex_lock();
2382 pixelformat
.dwSize
= sizeof(pixelformat
);
2383 for(fmt
= 0; fmt
< (sizeof(checkFormatList
) / sizeof(checkFormatList
[0])); fmt
++)
2386 while (wined3d_enum_adapter_modes(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, checkFormatList
[fmt
],
2387 WINED3D_SCANLINE_ORDERING_UNKNOWN
, modenum
++, &mode
) == WINED3D_OK
)
2392 ddrawformat_from_wined3dformat(&pixelformat
, mode
.format_id
);
2395 if (DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.width
!= DDSD
->dwWidth
)
2397 if (DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.height
!= DDSD
->dwHeight
)
2399 if (DDSD
->dwFlags
& DDSD_REFRESHRATE
&& mode
.refresh_rate
!= DDSD
->u2
.dwRefreshRate
)
2401 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
2402 && pixelformat
.u1
.dwRGBBitCount
!= DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
)
2406 /* DX docs state EnumDisplayMode should return only unique modes */
2407 for (i
= 0; i
< enum_mode_count
; i
++)
2409 if (enum_modes
[i
].width
== mode
.width
&& enum_modes
[i
].height
== mode
.height
2410 && enum_modes
[i
].format_id
== mode
.format_id
2411 && (enum_modes
[i
].refresh_rate
== mode
.refresh_rate
|| !(Flags
& DDEDM_REFRESHRATES
)))
2419 memset(&callback_sd
, 0, sizeof(callback_sd
));
2420 callback_sd
.dwSize
= sizeof(callback_sd
);
2421 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2423 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
|DDSD_REFRESHRATE
;
2424 if (Flags
& DDEDM_REFRESHRATES
)
2425 callback_sd
.u2
.dwRefreshRate
= mode
.refresh_rate
;
2427 callback_sd
.dwWidth
= mode
.width
;
2428 callback_sd
.dwHeight
= mode
.height
;
2430 callback_sd
.u4
.ddpfPixelFormat
=pixelformat
;
2432 /* Calc pitch and DWORD align like MSDN says */
2433 callback_sd
.u1
.lPitch
= (callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8) * mode
.width
;
2434 callback_sd
.u1
.lPitch
= (callback_sd
.u1
.lPitch
+ 3) & ~3;
2436 TRACE("Enumerating %dx%dx%d @%d\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
,
2437 callback_sd
.u2
.dwRefreshRate
);
2439 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
2441 TRACE("Application asked to terminate the enumeration\n");
2442 HeapFree(GetProcessHeap(), 0, enum_modes
);
2443 wined3d_mutex_unlock();
2447 if (enum_mode_count
== enum_mode_array_size
)
2449 struct wined3d_display_mode
*new_enum_modes
;
2451 enum_mode_array_size
*= 2;
2452 new_enum_modes
= HeapReAlloc(GetProcessHeap(), 0, enum_modes
,
2453 sizeof(*new_enum_modes
) * enum_mode_array_size
);
2454 if (!new_enum_modes
)
2456 HeapFree(GetProcessHeap(), 0, enum_modes
);
2457 wined3d_mutex_unlock();
2458 return DDERR_OUTOFMEMORY
;
2461 enum_modes
= new_enum_modes
;
2463 enum_modes
[enum_mode_count
++] = mode
;
2467 TRACE("End of enumeration\n");
2468 HeapFree(GetProcessHeap(), 0, enum_modes
);
2469 wined3d_mutex_unlock();
2474 static HRESULT WINAPI
ddraw4_EnumDisplayModes(IDirectDraw4
*iface
, DWORD flags
,
2475 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK2 callback
)
2477 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2479 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2480 iface
, flags
, surface_desc
, context
, callback
);
2482 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
, context
, callback
);
2485 static HRESULT WINAPI
ddraw2_EnumDisplayModes(IDirectDraw2
*iface
, DWORD flags
,
2486 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2488 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2489 struct displaymodescallback_context cbcontext
;
2490 DDSURFACEDESC2 surface_desc2
;
2492 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2493 iface
, flags
, surface_desc
, context
, callback
);
2495 cbcontext
.func
= callback
;
2496 cbcontext
.context
= context
;
2498 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2499 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2500 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2503 static HRESULT WINAPI
ddraw1_EnumDisplayModes(IDirectDraw
*iface
, DWORD flags
,
2504 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2506 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2507 struct displaymodescallback_context cbcontext
;
2508 DDSURFACEDESC2 surface_desc2
;
2510 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2511 iface
, flags
, surface_desc
, context
, callback
);
2513 cbcontext
.func
= callback
;
2514 cbcontext
.context
= context
;
2516 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2517 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2518 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2521 /*****************************************************************************
2522 * IDirectDraw7::EvaluateMode
2524 * Used with IDirectDraw7::StartModeTest to test video modes.
2525 * EvaluateMode is used to pass or fail a mode, and continue with the next
2529 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
2530 * Timeout: Returns the amount of seconds left before the mode would have
2531 * been failed automatically
2534 * This implementation always DD_OK, because it's a stub
2536 *****************************************************************************/
2537 static HRESULT WINAPI
ddraw7_EvaluateMode(IDirectDraw7
*iface
, DWORD Flags
, DWORD
*Timeout
)
2539 FIXME("iface %p, flags %#x, timeout %p stub!\n", iface
, Flags
, Timeout
);
2541 /* When implementing this, implement it in WineD3D */
2546 /*****************************************************************************
2547 * IDirectDraw7::GetDeviceIdentifier
2549 * Returns the device identifier, which gives information about the driver
2550 * Our device identifier is defined at the beginning of this file.
2553 * DDDI: Address for the returned structure
2554 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
2557 * On success it returns DD_OK
2558 * DDERR_INVALIDPARAMS if DDDI is NULL
2560 *****************************************************************************/
2561 static HRESULT WINAPI
ddraw7_GetDeviceIdentifier(IDirectDraw7
*iface
,
2562 DDDEVICEIDENTIFIER2
*DDDI
, DWORD Flags
)
2564 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2565 struct wined3d_adapter_identifier adapter_id
;
2568 TRACE("iface %p, device_identifier %p, flags %#x.\n", iface
, DDDI
, Flags
);
2571 return DDERR_INVALIDPARAMS
;
2573 if (Flags
& DDGDI_GETHOSTIDENTIFIER
)
2575 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
2576 * host adapter, if there's a secondary 3D adapter. This doesn't apply
2577 * to any modern hardware, nor is it interesting for Wine, so ignore it.
2578 * Size of DDDEVICEIDENTIFIER2 may be aligned to 8 bytes and thus 4
2579 * bytes too long. So only copy the relevant part of the structure
2582 memcpy(DDDI
, &deviceidentifier
, FIELD_OFFSET(DDDEVICEIDENTIFIER2
, dwWHQLLevel
) + sizeof(DWORD
));
2586 /* Drakan: Order of the Flame expects accurate D3D device information from ddraw */
2587 adapter_id
.driver
= DDDI
->szDriver
;
2588 adapter_id
.driver_size
= sizeof(DDDI
->szDriver
);
2589 adapter_id
.description
= DDDI
->szDescription
;
2590 adapter_id
.description_size
= sizeof(DDDI
->szDescription
);
2591 adapter_id
.device_name_size
= 0;
2592 wined3d_mutex_lock();
2593 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0x0, &adapter_id
);
2594 wined3d_mutex_unlock();
2595 if (FAILED(hr
)) return hr
;
2597 DDDI
->liDriverVersion
= adapter_id
.driver_version
;
2598 DDDI
->dwVendorId
= adapter_id
.vendor_id
;
2599 DDDI
->dwDeviceId
= adapter_id
.device_id
;
2600 DDDI
->dwSubSysId
= adapter_id
.subsystem_id
;
2601 DDDI
->dwRevision
= adapter_id
.revision
;
2602 DDDI
->guidDeviceIdentifier
= adapter_id
.device_identifier
;
2603 DDDI
->dwWHQLLevel
= adapter_id
.whql_level
;
2607 static HRESULT WINAPI
ddraw4_GetDeviceIdentifier(IDirectDraw4
*iface
,
2608 DDDEVICEIDENTIFIER
*identifier
, DWORD flags
)
2610 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2611 DDDEVICEIDENTIFIER2 identifier2
;
2614 TRACE("iface %p, identifier %p, flags %#x.\n", iface
, identifier
, flags
);
2616 hr
= ddraw7_GetDeviceIdentifier(&ddraw
->IDirectDraw7_iface
, &identifier2
, flags
);
2617 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&identifier2
, identifier
);
2622 /*****************************************************************************
2623 * IDirectDraw7::GetSurfaceFromDC
2625 * Returns the Surface for a GDI device context handle.
2626 * Is this related to IDirectDrawSurface::GetDC ???
2629 * hdc: hdc to return the surface for
2630 * Surface: Address to write the surface pointer to
2633 * Always returns DD_OK because it's a stub
2635 *****************************************************************************/
2636 static HRESULT WINAPI
ddraw7_GetSurfaceFromDC(IDirectDraw7
*iface
, HDC hdc
,
2637 IDirectDrawSurface7
**Surface
)
2639 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2640 struct wined3d_surface
*wined3d_surface
;
2641 struct ddraw_surface
*surface_impl
;
2643 TRACE("iface %p, dc %p, surface %p.\n", iface
, hdc
, Surface
);
2645 if (!Surface
) return E_INVALIDARG
;
2647 if (!(wined3d_surface
= wined3d_device_get_surface_from_dc(ddraw
->wined3d_device
, hdc
)))
2649 TRACE("No surface found for dc %p.\n", hdc
);
2651 return DDERR_NOTFOUND
;
2654 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
2655 *Surface
= &surface_impl
->IDirectDrawSurface7_iface
;
2656 IDirectDrawSurface7_AddRef(*Surface
);
2657 TRACE("Returning surface %p.\n", Surface
);
2661 static HRESULT WINAPI
ddraw4_GetSurfaceFromDC(IDirectDraw4
*iface
, HDC dc
,
2662 IDirectDrawSurface4
**surface
)
2664 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2665 struct ddraw_surface
*surface_impl
;
2666 IDirectDrawSurface7
*surface7
;
2669 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2671 if (!surface
) return E_INVALIDARG
;
2673 hr
= ddraw7_GetSurfaceFromDC(&ddraw
->IDirectDraw7_iface
, dc
, &surface7
);
2679 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2680 /* Tests say this is true */
2681 *surface
= (IDirectDrawSurface4
*)&surface_impl
->IDirectDrawSurface_iface
;
2682 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2683 IDirectDrawSurface7_Release(surface7
);
2688 /*****************************************************************************
2689 * IDirectDraw7::RestoreAllSurfaces
2691 * Calls the restore method of all surfaces
2696 * Always returns DD_OK because it's a stub
2698 *****************************************************************************/
2699 static HRESULT WINAPI
ddraw7_RestoreAllSurfaces(IDirectDraw7
*iface
)
2701 FIXME("iface %p stub!\n", iface
);
2703 /* This isn't hard to implement: Enumerate all WineD3D surfaces,
2704 * get their parent and call their restore method. Do not implement
2705 * it in WineD3D, as restoring a surface means re-creating the
2711 static HRESULT WINAPI
ddraw4_RestoreAllSurfaces(IDirectDraw4
*iface
)
2713 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2715 TRACE("iface %p.\n", iface
);
2717 return ddraw7_RestoreAllSurfaces(&ddraw
->IDirectDraw7_iface
);
2720 /*****************************************************************************
2721 * IDirectDraw7::StartModeTest
2723 * Tests the specified video modes to update the system registry with
2724 * refresh rate information. StartModeTest starts the mode test,
2725 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
2726 * isn't called within 15 seconds, the mode is failed automatically
2728 * As refresh rates are handled by the X server, I don't think this
2729 * Method is important
2732 * Modes: An array of mode specifications
2733 * NumModes: The number of modes in Modes
2734 * Flags: Some flags...
2737 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
2738 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
2741 *****************************************************************************/
2742 static HRESULT WINAPI
ddraw7_StartModeTest(IDirectDraw7
*iface
, SIZE
*Modes
, DWORD NumModes
, DWORD Flags
)
2744 FIXME("iface %p, modes %p, mode_count %u, flags %#x partial stub!\n",
2745 iface
, Modes
, NumModes
, Flags
);
2747 /* This looks sane */
2748 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
2750 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
2751 * As it is not, DDERR_TESTFINISHED is returned
2752 * (hopefully that's correct
2754 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
2755 * well, that value doesn't (yet) exist in the wine headers, so ignore it
2761 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
, DDSURFACEDESC2
*surface_desc
,
2762 IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
2764 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2765 struct ddraw_surface
*impl
;
2768 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2769 iface
, surface_desc
, surface
, outer_unknown
);
2771 wined3d_mutex_lock();
2773 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2775 WARN("Cooperative level not set.\n");
2776 wined3d_mutex_unlock();
2777 return DDERR_NOCOOPERATIVELEVELSET
;
2780 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2782 WARN("Application supplied invalid surface descriptor\n");
2783 wined3d_mutex_unlock();
2784 return DDERR_INVALIDPARAMS
;
2787 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2789 if (TRACE_ON(ddraw
))
2791 TRACE(" (%p) Requesting surface desc :\n", iface
);
2792 DDRAW_dump_surface_desc(surface_desc
);
2795 WARN("Application tried to create an explicit front or back buffer\n");
2796 wined3d_mutex_unlock();
2797 return DDERR_INVALIDCAPS
;
2800 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 7);
2801 wined3d_mutex_unlock();
2808 *surface
= &impl
->IDirectDrawSurface7_iface
;
2809 IDirectDraw7_AddRef(iface
);
2810 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2815 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
2816 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
2818 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2819 struct ddraw_surface
*impl
;
2822 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2823 iface
, surface_desc
, surface
, outer_unknown
);
2825 wined3d_mutex_lock();
2827 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2829 WARN("Cooperative level not set.\n");
2830 wined3d_mutex_unlock();
2831 return DDERR_NOCOOPERATIVELEVELSET
;
2834 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2836 WARN("Application supplied invalid surface descriptor\n");
2837 wined3d_mutex_unlock();
2838 return DDERR_INVALIDPARAMS
;
2841 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2843 if (TRACE_ON(ddraw
))
2845 TRACE(" (%p) Requesting surface desc :\n", iface
);
2846 DDRAW_dump_surface_desc(surface_desc
);
2849 WARN("Application tried to create an explicit front or back buffer\n");
2850 wined3d_mutex_unlock();
2851 return DDERR_INVALIDCAPS
;
2854 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 4);
2855 wined3d_mutex_unlock();
2862 *surface
= &impl
->IDirectDrawSurface4_iface
;
2863 IDirectDraw4_AddRef(iface
);
2864 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2869 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
2870 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2872 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2873 struct ddraw_surface
*impl
;
2875 DDSURFACEDESC2 surface_desc2
;
2877 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2878 iface
, surface_desc
, surface
, outer_unknown
);
2880 wined3d_mutex_lock();
2882 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2884 WARN("Cooperative level not set.\n");
2885 wined3d_mutex_unlock();
2886 return DDERR_NOCOOPERATIVELEVELSET
;
2889 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2891 WARN("Application supplied invalid surface descriptor\n");
2892 wined3d_mutex_unlock();
2893 return DDERR_INVALIDPARAMS
;
2896 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2897 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2899 if (TRACE_ON(ddraw
))
2901 TRACE(" (%p) Requesting surface desc :\n", iface
);
2902 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
2905 WARN("Application tried to create an explicit front or back buffer\n");
2906 wined3d_mutex_unlock();
2907 return DDERR_INVALIDCAPS
;
2910 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 2);
2911 wined3d_mutex_unlock();
2918 *surface
= &impl
->IDirectDrawSurface_iface
;
2919 impl
->ifaceToRelease
= NULL
;
2924 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
2925 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2927 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2928 struct ddraw_surface
*impl
;
2930 DDSURFACEDESC2 surface_desc2
;
2932 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2933 iface
, surface_desc
, surface
, outer_unknown
);
2935 wined3d_mutex_lock();
2937 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2939 WARN("Cooperative level not set.\n");
2940 wined3d_mutex_unlock();
2941 return DDERR_NOCOOPERATIVELEVELSET
;
2944 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2946 WARN("Application supplied invalid surface descriptor\n");
2947 wined3d_mutex_unlock();
2948 return DDERR_INVALIDPARAMS
;
2951 if ((surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
))
2952 == (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
)
2953 || (surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
))
2954 == ((DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
)))
2956 WARN("Application tried to create an explicit front or back buffer.\n");
2957 wined3d_mutex_unlock();
2958 return DDERR_INVALIDCAPS
;
2961 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2962 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 1);
2963 wined3d_mutex_unlock();
2970 *surface
= &impl
->IDirectDrawSurface_iface
;
2971 impl
->ifaceToRelease
= NULL
;
2976 #define DDENUMSURFACES_SEARCHTYPE (DDENUMSURFACES_CANBECREATED|DDENUMSURFACES_DOESEXIST)
2977 #define DDENUMSURFACES_MATCHTYPE (DDENUMSURFACES_ALL|DDENUMSURFACES_MATCH|DDENUMSURFACES_NOMATCH)
2980 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
2981 const DDPIXELFORMAT
*provided
)
2983 /* Some flags must be present in both or neither for a match. */
2984 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
2985 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
2986 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
2988 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
2991 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
2994 if (requested
->dwFlags
& DDPF_FOURCC
)
2995 if (requested
->dwFourCC
!= provided
->dwFourCC
)
2998 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
2999 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3000 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
3003 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3004 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3005 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
3008 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
3009 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
3012 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
3013 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3015 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
3018 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
3019 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
3025 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3034 #define CMP(FLAG, FIELD) \
3035 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3036 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3038 static const struct compare_info compare
[] =
3040 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3041 CMP(BACKBUFFERCOUNT
, dwBackBufferCount
),
3043 CMP(CKDESTBLT
, ddckCKDestBlt
),
3044 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3045 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3046 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3047 CMP(HEIGHT
, dwHeight
),
3048 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3049 CMP(LPSURFACE
, lpSurface
),
3050 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3051 CMP(PITCH
, u1
/* lPitch */),
3052 /* PIXELFORMAT: manual */
3053 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3054 CMP(TEXTURESTAGE
, dwTextureStage
),
3055 CMP(WIDTH
, dwWidth
),
3056 /* ZBUFFERBITDEPTH: "obsolete" */
3063 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3066 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
3068 if (requested
->dwFlags
& compare
[i
].flag
3069 && memcmp((const char *)provided
+ compare
[i
].offset
,
3070 (const char *)requested
+ compare
[i
].offset
,
3071 compare
[i
].size
) != 0)
3075 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3077 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3078 &provided
->u4
.ddpfPixelFormat
))
3085 #undef DDENUMSURFACES_SEARCHTYPE
3086 #undef DDENUMSURFACES_MATCHTYPE
3088 struct surfacescallback2_context
3090 LPDDENUMSURFACESCALLBACK2 func
;
3094 struct surfacescallback_context
3096 LPDDENUMSURFACESCALLBACK func
;
3100 static HRESULT CALLBACK
EnumSurfacesCallback2Thunk(IDirectDrawSurface7
*surface
,
3101 DDSURFACEDESC2
*surface_desc
, void *context
)
3103 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3104 struct surfacescallback2_context
*cbcontext
= context
;
3106 IDirectDrawSurface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
3107 IDirectDrawSurface7_Release(surface
);
3109 return cbcontext
->func(&surface_impl
->IDirectDrawSurface4_iface
,
3110 surface_desc
, cbcontext
->context
);
3113 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3114 DDSURFACEDESC2
*surface_desc
, void *context
)
3116 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3117 struct surfacescallback_context
*cbcontext
= context
;
3119 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
3120 IDirectDrawSurface7_Release(surface
);
3122 return cbcontext
->func(&surface_impl
->IDirectDrawSurface_iface
,
3123 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3126 /*****************************************************************************
3127 * IDirectDraw7::EnumSurfaces
3129 * Loops through all surfaces attached to this device and calls the
3130 * application callback. This can't be relayed to WineD3DDevice,
3131 * because some WineD3DSurfaces' parents are IParent objects
3134 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3135 * DDSD: Description to filter for
3136 * Context: Application-provided pointer, it's passed unmodified to the
3138 * Callback: Address to call for each surface
3141 * DDERR_INVALIDPARAMS if the callback is NULL
3144 *****************************************************************************/
3145 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD Flags
,
3146 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMSURFACESCALLBACK7 Callback
)
3148 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3149 struct ddraw_surface
*surf
;
3151 DDSURFACEDESC2 desc
;
3152 struct list
*entry
, *entry2
;
3154 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3155 iface
, Flags
, DDSD
, Context
, Callback
);
3157 all
= Flags
& DDENUMSURFACES_ALL
;
3158 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
3161 return DDERR_INVALIDPARAMS
;
3163 wined3d_mutex_lock();
3165 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
3166 LIST_FOR_EACH_SAFE(entry
, entry2
, &ddraw
->surface_list
)
3168 surf
= LIST_ENTRY(entry
, struct ddraw_surface
, surface_list_entry
);
3170 if (!surf
->iface_count
)
3172 WARN("Not enumerating surface %p because it doesn't have any references.\n", surf
);
3176 if (all
|| (nomatch
!= ddraw_match_surface_desc(DDSD
, &surf
->surface_desc
)))
3178 TRACE("Enumerating surface %p.\n", surf
);
3179 desc
= surf
->surface_desc
;
3180 IDirectDrawSurface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
3181 if (Callback(&surf
->IDirectDrawSurface7_iface
, &desc
, Context
) != DDENUMRET_OK
)
3183 wined3d_mutex_unlock();
3189 wined3d_mutex_unlock();
3194 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3195 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3197 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3198 struct surfacescallback2_context cbcontext
;
3200 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3201 iface
, flags
, surface_desc
, context
, callback
);
3203 cbcontext
.func
= callback
;
3204 cbcontext
.context
= context
;
3206 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
,
3207 &cbcontext
, EnumSurfacesCallback2Thunk
);
3210 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3211 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3213 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3214 struct surfacescallback_context cbcontext
;
3215 DDSURFACEDESC2 surface_desc2
;
3217 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3218 iface
, flags
, surface_desc
, context
, callback
);
3220 cbcontext
.func
= callback
;
3221 cbcontext
.context
= context
;
3223 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3224 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3225 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3228 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3229 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3231 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3232 struct surfacescallback_context cbcontext
;
3233 DDSURFACEDESC2 surface_desc2
;
3235 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3236 iface
, flags
, surface_desc
, context
, callback
);
3238 cbcontext
.func
= callback
;
3239 cbcontext
.context
= context
;
3241 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3242 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3243 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3246 /*****************************************************************************
3247 * DirectDrawCreateClipper (DDRAW.@)
3249 * Creates a new IDirectDrawClipper object.
3252 * Clipper: Address to write the interface pointer to
3253 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3257 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3258 * E_OUTOFMEMORY if allocating the object failed
3260 *****************************************************************************/
3261 HRESULT WINAPI
DirectDrawCreateClipper(DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3263 struct ddraw_clipper
*object
;
3266 TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
3267 flags
, clipper
, outer_unknown
);
3270 return CLASS_E_NOAGGREGATION
;
3272 wined3d_mutex_lock();
3274 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3277 wined3d_mutex_unlock();
3278 return E_OUTOFMEMORY
;
3281 hr
= ddraw_clipper_init(object
);
3284 WARN("Failed to initialize clipper, hr %#x.\n", hr
);
3285 HeapFree(GetProcessHeap(), 0, object
);
3286 wined3d_mutex_unlock();
3290 TRACE("Created clipper %p.\n", object
);
3291 *clipper
= &object
->IDirectDrawClipper_iface
;
3292 wined3d_mutex_unlock();
3297 /*****************************************************************************
3298 * IDirectDraw7::CreateClipper
3300 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3302 *****************************************************************************/
3303 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3304 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3306 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3307 iface
, Flags
, Clipper
, UnkOuter
);
3309 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3312 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
, DWORD flags
,
3313 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3315 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3317 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3318 iface
, flags
, clipper
, outer_unknown
);
3320 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3323 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
3324 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3326 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3328 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3329 iface
, flags
, clipper
, outer_unknown
);
3331 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3334 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
3335 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3337 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3339 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3340 iface
, flags
, clipper
, outer_unknown
);
3342 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3345 /*****************************************************************************
3346 * IDirectDraw7::CreatePalette
3348 * Creates a new IDirectDrawPalette object
3351 * Flags: The flags for the new clipper
3352 * ColorTable: Color table to assign to the new clipper
3353 * Palette: Address to write the interface pointer to
3354 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3358 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3359 * E_OUTOFMEMORY if allocating the object failed
3361 *****************************************************************************/
3362 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
3363 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
3365 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3366 struct ddraw_palette
*object
;
3369 TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
3370 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3373 return CLASS_E_NOAGGREGATION
;
3375 wined3d_mutex_lock();
3377 /* The refcount test shows that a cooplevel is required for this */
3378 if (!ddraw
->cooperative_level
)
3380 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3381 wined3d_mutex_unlock();
3382 return DDERR_NOCOOPERATIVELEVELSET
;
3385 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(*object
));
3388 ERR("Out of memory when allocating memory for a palette implementation\n");
3389 wined3d_mutex_unlock();
3390 return E_OUTOFMEMORY
;
3393 hr
= ddraw_palette_init(object
, ddraw
, Flags
, ColorTable
);
3396 WARN("Failed to initialize palette, hr %#x.\n", hr
);
3397 HeapFree(GetProcessHeap(), 0, object
);
3398 wined3d_mutex_unlock();
3402 TRACE("Created palette %p.\n", object
);
3403 *Palette
= &object
->IDirectDrawPalette_iface
;
3404 wined3d_mutex_unlock();
3409 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
, PALETTEENTRY
*entries
,
3410 IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3412 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3415 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3416 iface
, flags
, entries
, palette
, outer_unknown
);
3418 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3419 if (SUCCEEDED(hr
) && *palette
)
3421 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3422 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3423 IDirectDraw4_AddRef(iface
);
3424 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3429 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
3430 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3432 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3435 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3436 iface
, flags
, entries
, palette
, outer_unknown
);
3438 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3439 if (SUCCEEDED(hr
) && *palette
)
3441 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3442 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3443 impl
->ifaceToRelease
= NULL
;
3449 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
3450 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3452 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3455 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3456 iface
, flags
, entries
, palette
, outer_unknown
);
3458 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3459 if (SUCCEEDED(hr
) && *palette
)
3461 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3462 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3463 impl
->ifaceToRelease
= NULL
;
3469 /*****************************************************************************
3470 * IDirectDraw7::DuplicateSurface
3472 * Duplicates a surface. The surface memory points to the same memory as
3473 * the original surface, and it's released when the last surface referencing
3474 * it is released. I guess that's beyond Wine's surface management right now
3475 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3476 * test application to implement this)
3479 * Src: Address of the source surface
3480 * Dest: Address to write the new surface pointer to
3483 * See IDirectDraw7::CreateSurface
3485 *****************************************************************************/
3486 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
3487 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
3489 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(Src
);
3491 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
3493 /* For now, simply create a new, independent surface */
3494 return IDirectDraw7_CreateSurface(iface
, &src_surface
->surface_desc
, Dest
, NULL
);
3497 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
, IDirectDrawSurface4
*src
,
3498 IDirectDrawSurface4
**dst
)
3500 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
3501 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3502 struct ddraw_surface
*dst_impl
;
3503 IDirectDrawSurface7
*dst7
;
3506 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3508 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3509 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3515 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3516 *dst
= &dst_impl
->IDirectDrawSurface4_iface
;
3517 IDirectDrawSurface4_AddRef(*dst
);
3518 IDirectDrawSurface7_Release(dst7
);
3523 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
3524 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
3526 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3527 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3528 struct ddraw_surface
*dst_impl
;
3529 IDirectDrawSurface7
*dst7
;
3532 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3534 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3535 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3538 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3539 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3540 IDirectDrawSurface_AddRef(*dst
);
3541 IDirectDrawSurface7_Release(dst7
);
3546 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
, IDirectDrawSurface
*src
,
3547 IDirectDrawSurface
**dst
)
3549 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3550 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3551 struct ddraw_surface
*dst_impl
;
3552 IDirectDrawSurface7
*dst7
;
3555 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3557 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3558 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3561 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3562 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3563 IDirectDrawSurface_AddRef(*dst
);
3564 IDirectDrawSurface7_Release(dst7
);
3569 /*****************************************************************************
3570 * IDirect3D7::EnumDevices
3572 * The EnumDevices method for IDirect3D7. It enumerates all supported
3573 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
3576 * callback: Function to call for each enumerated device
3577 * context: Pointer to pass back to the app
3580 * D3D_OK, or the return value of the GetCaps call
3582 *****************************************************************************/
3583 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
3585 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
3586 D3DDEVICEDESC7 device_desc7
;
3590 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3593 return DDERR_INVALIDPARAMS
;
3595 wined3d_mutex_lock();
3597 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3599 wined3d_mutex_unlock();
3603 for (i
= 0; i
< sizeof(device_list7
)/sizeof(device_list7
[0]); i
++)
3607 device_desc7
.deviceGUID
= *device_list7
[i
].device_guid
;
3608 ret
= callback(device_list7
[i
].interface_name
, device_list7
[i
].device_name
, &device_desc7
, context
);
3609 if (ret
!= DDENUMRET_OK
)
3611 TRACE("Application cancelled the enumeration.\n");
3612 wined3d_mutex_unlock();
3617 TRACE("End of enumeration.\n");
3619 wined3d_mutex_unlock();
3624 /*****************************************************************************
3625 * IDirect3D3::EnumDevices
3627 * Enumerates all supported Direct3DDevice interfaces. This is the
3628 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
3630 * Version 1, 2 and 3
3633 * callback: Application-provided routine to call for each enumerated device
3634 * Context: Pointer to pass to the callback
3637 * D3D_OK on success,
3638 * The result of IDirect3DImpl_GetCaps if it failed
3640 *****************************************************************************/
3641 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3643 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
3645 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3646 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
3647 D3DDEVICEDESC7 device_desc7
;
3650 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
3651 * name string. Let's put the string in a sufficiently sized array in
3652 * writable memory. */
3653 char device_name
[50];
3654 strcpy(device_name
,"Direct3D HEL");
3656 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3659 return DDERR_INVALIDPARAMS
;
3661 wined3d_mutex_lock();
3663 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3665 wined3d_mutex_unlock();
3668 ddraw_d3dcaps1_from_7(&device_desc1
, &device_desc7
);
3670 /* Do I have to enumerate the reference id? Note from old d3d7:
3671 * "It seems that enumerating the reference IID on Direct3D 1 games
3672 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
3674 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
3675 * EnumReference which enables / disables enumerating the reference
3676 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
3677 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
3678 * demo directory suggest this.
3680 * Some games(GTA 2) seem to use the second enumerated device, so I have
3681 * to enumerate at least 2 devices. So enumerate the reference device to
3684 * Other games (Rollcage) tell emulation and hal device apart by certain
3685 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
3686 * limitation flag), and it refuses all devices that have the perspective
3687 * flag set. This way it refuses the emulation device, and HAL devices
3688 * never have POW2 unset in d3d7 on windows. */
3689 if (ddraw
->d3dversion
!= 1)
3691 static CHAR reference_description
[] = "RGB Direct3D emulation";
3693 TRACE("Enumerating WineD3D D3DDevice interface.\n");
3694 hal_desc
= device_desc1
;
3695 hel_desc
= device_desc1
;
3696 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
3697 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3698 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3699 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3700 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3701 /* RGB, RAMP and MMX devices have a HAL dcmColorModel of 0 */
3702 hal_desc
.dcmColorModel
= 0;
3704 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
3705 device_name
, &hal_desc
, &hel_desc
, context
);
3706 if (hr
!= D3DENUMRET_OK
)
3708 TRACE("Application cancelled the enumeration.\n");
3709 wined3d_mutex_unlock();
3714 strcpy(device_name
,"Direct3D HAL");
3716 TRACE("Enumerating HAL Direct3D device.\n");
3717 hal_desc
= device_desc1
;
3718 hel_desc
= device_desc1
;
3720 /* The hal device does not have the pow2 flag set in hel, but in hal. */
3721 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3722 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3723 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3724 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3725 /* HAL devices have a HEL dcmColorModel of 0 */
3726 hel_desc
.dcmColorModel
= 0;
3728 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
3729 device_name
, &hal_desc
, &hel_desc
, context
);
3730 if (hr
!= D3DENUMRET_OK
)
3732 TRACE("Application cancelled the enumeration.\n");
3733 wined3d_mutex_unlock();
3737 TRACE("End of enumeration.\n");
3739 wined3d_mutex_unlock();
3744 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3746 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3748 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3750 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3753 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3755 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3757 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3759 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3762 /*****************************************************************************
3763 * IDirect3D3::CreateLight
3765 * Creates an IDirect3DLight interface. This interface is used in
3766 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
3767 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
3768 * uses the IDirect3DDevice7 interface with D3D7 lights.
3770 * Version 1, 2 and 3
3773 * light: Address to store the new interface pointer
3774 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3779 * DDERR_OUTOFMEMORY if memory allocation failed
3780 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3782 *****************************************************************************/
3783 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
,
3784 IUnknown
*outer_unknown
)
3786 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3787 struct d3d_light
*object
;
3789 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3791 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3793 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3796 ERR("Failed to allocate light memory.\n");
3797 return DDERR_OUTOFMEMORY
;
3800 d3d_light_init(object
, ddraw
);
3802 TRACE("Created light %p.\n", object
);
3803 *light
= &object
->IDirect3DLight_iface
;
3808 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3810 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3812 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3814 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3817 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3819 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3821 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3823 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3826 /*****************************************************************************
3827 * IDirect3D3::CreateMaterial
3829 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
3830 * and older versions. The IDirect3DMaterial implementation wraps its
3831 * functionality to IDirect3DDevice7::SetMaterial and friends.
3833 * Version 1, 2 and 3
3836 * material: Address to store the new interface's pointer to
3837 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3842 * DDERR_OUTOFMEMORY if memory allocation failed
3843 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3845 *****************************************************************************/
3846 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
,
3847 IUnknown
*outer_unknown
)
3849 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3850 struct d3d_material
*object
;
3852 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3854 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3856 object
= d3d_material_create(ddraw
);
3859 ERR("Failed to allocate material memory.\n");
3860 return DDERR_OUTOFMEMORY
;
3863 TRACE("Created material %p.\n", object
);
3864 *material
= &object
->IDirect3DMaterial3_iface
;
3869 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
,
3870 IUnknown
*outer_unknown
)
3872 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3873 struct d3d_material
*object
;
3875 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3877 object
= d3d_material_create(ddraw
);
3880 ERR("Failed to allocate material memory.\n");
3881 return DDERR_OUTOFMEMORY
;
3884 TRACE("Created material %p.\n", object
);
3885 *material
= &object
->IDirect3DMaterial2_iface
;
3890 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
,
3891 IUnknown
*outer_unknown
)
3893 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3894 struct d3d_material
*object
;
3896 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3898 object
= d3d_material_create(ddraw
);
3901 ERR("Failed to allocate material memory.\n");
3902 return DDERR_OUTOFMEMORY
;
3905 TRACE("Created material %p.\n", object
);
3906 *material
= &object
->IDirect3DMaterial_iface
;
3911 /*****************************************************************************
3912 * IDirect3D3::CreateViewport
3914 * Creates an IDirect3DViewport interface. This interface is used
3915 * by Direct3D and earlier versions for Viewport management. In Direct3D7
3916 * it has been replaced by a viewport structure and
3917 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
3918 * uses the IDirect3DDevice7 methods for its functionality
3921 * Viewport: Address to store the new interface pointer
3922 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3927 * DDERR_OUTOFMEMORY if memory allocation failed
3928 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3930 *****************************************************************************/
3931 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
,
3932 IUnknown
*outer_unknown
)
3934 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3935 struct d3d_viewport
*object
;
3937 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
3939 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3941 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3944 ERR("Failed to allocate viewport memory.\n");
3945 return DDERR_OUTOFMEMORY
;
3948 d3d_viewport_init(object
, ddraw
);
3950 TRACE("Created viewport %p.\n", object
);
3951 *viewport
= &object
->IDirect3DViewport3_iface
;
3956 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
3958 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3960 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
3962 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
3966 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
3968 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3970 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
3972 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
3976 /*****************************************************************************
3977 * IDirect3D3::FindDevice
3979 * This method finds a device with the requested properties and returns a
3980 * device description
3984 * fds: Describes the requested device characteristics
3985 * fdr: Returns the device description
3989 * DDERR_INVALIDPARAMS if no device was found
3991 *****************************************************************************/
3992 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
3994 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3995 D3DDEVICEDESC7 desc7
;
3996 D3DDEVICEDESC desc1
;
3999 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4001 if (!fds
|| !fdr
) return DDERR_INVALIDPARAMS
;
4003 if (fds
->dwSize
!= sizeof(D3DFINDDEVICESEARCH
)
4004 || fdr
->dwSize
!= sizeof(D3DFINDDEVICERESULT
))
4005 return DDERR_INVALIDPARAMS
;
4007 if ((fds
->dwFlags
& D3DFDS_COLORMODEL
)
4008 && fds
->dcmColorModel
!= D3DCOLOR_RGB
)
4010 WARN("Trying to request a non-RGB D3D color model. Not supported.\n");
4011 return DDERR_INVALIDPARAMS
; /* No real idea what to return here :-) */
4014 if (fds
->dwFlags
& D3DFDS_GUID
)
4016 TRACE("Trying to match guid %s.\n", debugstr_guid(&(fds
->guid
)));
4017 if (!IsEqualGUID(&IID_D3DDEVICE_WineD3D
, &fds
->guid
)
4018 && !IsEqualGUID(&IID_IDirect3DHALDevice
, &fds
->guid
)
4019 && !IsEqualGUID(&IID_IDirect3DRGBDevice
, &fds
->guid
))
4021 WARN("No match for this GUID.\n");
4022 return DDERR_NOTFOUND
;
4027 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &desc7
)))
4030 /* Now return our own GUID */
4031 ddraw_d3dcaps1_from_7(&desc1
, &desc7
);
4032 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4033 fdr
->ddHwDesc
= desc1
;
4034 fdr
->ddSwDesc
= desc1
;
4036 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4041 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4043 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4045 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4047 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4050 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4052 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4054 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4056 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4059 /*****************************************************************************
4060 * IDirect3D7::CreateDevice
4062 * Creates an IDirect3DDevice7 interface.
4064 * Version 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4065 * DirectDraw surfaces and are created with
4066 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4067 * create the device object and QueryInterfaces for IDirect3DDevice
4070 * refiid: IID of the device to create
4071 * Surface: Initial rendertarget
4072 * Device: Address to return the interface pointer
4076 * DDERR_OUTOFMEMORY if memory allocation failed
4077 * DDERR_INVALIDPARAMS if a device exists already
4079 *****************************************************************************/
4080 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4081 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4083 struct ddraw_surface
*target
= unsafe_impl_from_IDirectDrawSurface7(surface
);
4084 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4085 struct d3d_device
*object
;
4088 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4090 wined3d_mutex_lock();
4091 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, target
, (IUnknown
*)surface
, 7, &object
, NULL
)))
4093 *device
= &object
->IDirect3DDevice7_iface
;
4097 WARN("Failed to create device, hr %#x.\n", hr
);
4100 wined3d_mutex_unlock();
4105 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4106 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4108 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface4(surface
);
4109 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4110 struct d3d_device
*device_impl
;
4113 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4114 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4117 return CLASS_E_NOAGGREGATION
;
4119 wined3d_mutex_lock();
4120 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 3, &device_impl
, NULL
)))
4122 *device
= &device_impl
->IDirect3DDevice3_iface
;
4126 WARN("Failed to create device, hr %#x.\n", hr
);
4129 wined3d_mutex_unlock();
4134 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4135 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4137 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface(surface
);
4138 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4139 struct d3d_device
*device_impl
;
4142 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4143 iface
, debugstr_guid(riid
), surface
, device
);
4145 wined3d_mutex_lock();
4146 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 2, &device_impl
, NULL
)))
4148 *device
= &device_impl
->IDirect3DDevice2_iface
;
4152 WARN("Failed to create device, hr %#x.\n", hr
);
4155 wined3d_mutex_unlock();
4160 /*****************************************************************************
4161 * IDirect3D7::CreateVertexBuffer
4163 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4169 * desc: Requested Vertex buffer properties
4170 * vertex_buffer: Address to return the interface pointer at
4171 * flags: Some flags, should be 0
4175 * DDERR_OUTOFMEMORY if memory allocation failed
4176 * The return value of IWineD3DDevice::CreateVertexBuffer if this call fails
4177 * DDERR_INVALIDPARAMS if desc or vertex_buffer is NULL
4179 *****************************************************************************/
4180 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4181 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4183 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4184 struct d3d_vertex_buffer
*object
;
4187 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
4188 iface
, desc
, vertex_buffer
, flags
);
4190 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4192 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4195 TRACE("Created vertex buffer %p.\n", object
);
4196 *vertex_buffer
= &object
->IDirect3DVertexBuffer7_iface
;
4199 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4204 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4205 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4207 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4208 struct d3d_vertex_buffer
*object
;
4211 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n",
4212 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4215 return CLASS_E_NOAGGREGATION
;
4216 if (!vertex_buffer
|| !desc
)
4217 return DDERR_INVALIDPARAMS
;
4219 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4222 TRACE("Created vertex buffer %p.\n", object
);
4223 *vertex_buffer
= &object
->IDirect3DVertexBuffer_iface
;
4226 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4231 /*****************************************************************************
4232 * IDirect3D7::EnumZBufferFormats
4234 * Enumerates all supported Z buffer pixel formats
4240 * callback: callback to call for each pixel format
4241 * context: Pointer to pass back to the callback
4245 * DDERR_INVALIDPARAMS if callback is NULL
4246 * For details, see IWineD3DDevice::EnumZBufferFormats
4248 *****************************************************************************/
4249 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4250 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4252 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4253 struct wined3d_display_mode mode
;
4254 enum wined3d_device_type type
;
4258 /* Order matters. Specifically, BattleZone II (full version) expects the
4259 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4260 static const enum wined3d_format_id formats
[] =
4262 WINED3DFMT_S1_UINT_D15_UNORM
,
4263 WINED3DFMT_D16_UNORM
,
4264 WINED3DFMT_X8D24_UNORM
,
4265 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4266 WINED3DFMT_D24_UNORM_S8_UINT
,
4267 WINED3DFMT_D32_UNORM
,
4270 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4271 iface
, debugstr_guid(device_iid
), callback
, context
);
4273 if (!callback
) return DDERR_INVALIDPARAMS
;
4275 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4276 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4277 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4279 TRACE("Asked for HAL device.\n");
4280 type
= WINED3D_DEVICE_TYPE_HAL
;
4282 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4283 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4285 TRACE("Asked for SW device.\n");
4286 type
= WINED3D_DEVICE_TYPE_SW
;
4288 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4290 TRACE("Asked for REF device.\n");
4291 type
= WINED3D_DEVICE_TYPE_REF
;
4293 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4295 TRACE("Asked for NULLREF device.\n");
4296 type
= WINED3D_DEVICE_TYPE_NULLREF
;
4300 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4301 type
= WINED3D_DEVICE_TYPE_HAL
;
4304 wined3d_mutex_lock();
4305 /* We need an adapter format from somewhere to please wined3d and WGL.
4306 * Use the current display mode. So far all cards offer the same depth
4307 * stencil format for all modes, but if some do not and applications do
4308 * not like that we'll have to find some workaround, like iterating over
4309 * all imaginable formats and collecting all the depth stencil formats we
4311 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
4313 ERR("Failed to get display mode, hr %#x.\n", hr
);
4314 wined3d_mutex_unlock();
4318 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
4320 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4321 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_SURFACE
, formats
[i
])))
4323 DDPIXELFORMAT pformat
;
4325 memset(&pformat
, 0, sizeof(pformat
));
4326 pformat
.dwSize
= sizeof(pformat
);
4327 ddrawformat_from_wined3dformat(&pformat
, formats
[i
]);
4329 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
4330 hr
= callback(&pformat
, context
);
4331 if (hr
!= DDENUMRET_OK
)
4333 TRACE("Format enumeration cancelled by application.\n");
4334 wined3d_mutex_unlock();
4340 /* Historically some windows drivers used dwZBufferBitDepth=24 for WINED3DFMT_X8D24_UNORM,
4341 * while others used dwZBufferBitDepth=32. In either case the pitch matches a 32 bits per
4342 * pixel format, so we use dwZBufferBitDepth=32. Some games expect 24. Windows Vista and
4343 * newer enumerate both versions, so we do the same(bug 22434) */
4344 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4345 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_SURFACE
, WINED3DFMT_X8D24_UNORM
)))
4347 DDPIXELFORMAT x8d24
=
4349 sizeof(x8d24
), DDPF_ZBUFFER
, 0,
4350 {24}, {0x00000000}, {0x00ffffff}, {0x00000000}
4352 TRACE("Enumerating WINED3DFMT_X8D24_UNORM, dwZBufferBitDepth=24 version\n");
4353 callback(&x8d24
, context
);
4356 TRACE("End of enumeration.\n");
4358 wined3d_mutex_unlock();
4363 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
4364 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4366 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4368 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4369 iface
, debugstr_guid(device_iid
), callback
, context
);
4371 return d3d7_EnumZBufferFormats(&ddraw
->IDirect3D7_iface
, device_iid
, callback
, context
);
4374 /*****************************************************************************
4375 * IDirect3D7::EvictManagedTextures
4377 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
4378 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
4383 * D3D_OK, because it's a stub
4385 *****************************************************************************/
4386 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
4388 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4390 TRACE("iface %p!\n", iface
);
4392 wined3d_mutex_lock();
4393 if (ddraw
->flags
& DDRAW_D3D_INITIALIZED
)
4394 wined3d_device_evict_managed_resources(ddraw
->wined3d_device
);
4395 wined3d_mutex_unlock();
4400 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
4402 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4404 TRACE("iface %p.\n", iface
);
4406 return d3d7_EvictManagedTextures(&ddraw
->IDirect3D7_iface
);
4409 /*****************************************************************************
4410 * IDirectDraw7 VTable
4411 *****************************************************************************/
4412 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
4415 ddraw7_QueryInterface
,
4420 ddraw7_CreateClipper
,
4421 ddraw7_CreatePalette
,
4422 ddraw7_CreateSurface
,
4423 ddraw7_DuplicateSurface
,
4424 ddraw7_EnumDisplayModes
,
4425 ddraw7_EnumSurfaces
,
4426 ddraw7_FlipToGDISurface
,
4428 ddraw7_GetDisplayMode
,
4429 ddraw7_GetFourCCCodes
,
4430 ddraw7_GetGDISurface
,
4431 ddraw7_GetMonitorFrequency
,
4433 ddraw7_GetVerticalBlankStatus
,
4435 ddraw7_RestoreDisplayMode
,
4436 ddraw7_SetCooperativeLevel
,
4437 ddraw7_SetDisplayMode
,
4438 ddraw7_WaitForVerticalBlank
,
4440 ddraw7_GetAvailableVidMem
,
4442 ddraw7_GetSurfaceFromDC
,
4444 ddraw7_RestoreAllSurfaces
,
4445 ddraw7_TestCooperativeLevel
,
4446 ddraw7_GetDeviceIdentifier
,
4448 ddraw7_StartModeTest
,
4452 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
4455 ddraw4_QueryInterface
,
4460 ddraw4_CreateClipper
,
4461 ddraw4_CreatePalette
,
4462 ddraw4_CreateSurface
,
4463 ddraw4_DuplicateSurface
,
4464 ddraw4_EnumDisplayModes
,
4465 ddraw4_EnumSurfaces
,
4466 ddraw4_FlipToGDISurface
,
4468 ddraw4_GetDisplayMode
,
4469 ddraw4_GetFourCCCodes
,
4470 ddraw4_GetGDISurface
,
4471 ddraw4_GetMonitorFrequency
,
4473 ddraw4_GetVerticalBlankStatus
,
4475 ddraw4_RestoreDisplayMode
,
4476 ddraw4_SetCooperativeLevel
,
4477 ddraw4_SetDisplayMode
,
4478 ddraw4_WaitForVerticalBlank
,
4480 ddraw4_GetAvailableVidMem
,
4482 ddraw4_GetSurfaceFromDC
,
4484 ddraw4_RestoreAllSurfaces
,
4485 ddraw4_TestCooperativeLevel
,
4486 ddraw4_GetDeviceIdentifier
,
4489 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
4492 ddraw2_QueryInterface
,
4497 ddraw2_CreateClipper
,
4498 ddraw2_CreatePalette
,
4499 ddraw2_CreateSurface
,
4500 ddraw2_DuplicateSurface
,
4501 ddraw2_EnumDisplayModes
,
4502 ddraw2_EnumSurfaces
,
4503 ddraw2_FlipToGDISurface
,
4505 ddraw2_GetDisplayMode
,
4506 ddraw2_GetFourCCCodes
,
4507 ddraw2_GetGDISurface
,
4508 ddraw2_GetMonitorFrequency
,
4510 ddraw2_GetVerticalBlankStatus
,
4512 ddraw2_RestoreDisplayMode
,
4513 ddraw2_SetCooperativeLevel
,
4514 ddraw2_SetDisplayMode
,
4515 ddraw2_WaitForVerticalBlank
,
4517 ddraw2_GetAvailableVidMem
,
4520 static const struct IDirectDrawVtbl ddraw1_vtbl
=
4523 ddraw1_QueryInterface
,
4528 ddraw1_CreateClipper
,
4529 ddraw1_CreatePalette
,
4530 ddraw1_CreateSurface
,
4531 ddraw1_DuplicateSurface
,
4532 ddraw1_EnumDisplayModes
,
4533 ddraw1_EnumSurfaces
,
4534 ddraw1_FlipToGDISurface
,
4536 ddraw1_GetDisplayMode
,
4537 ddraw1_GetFourCCCodes
,
4538 ddraw1_GetGDISurface
,
4539 ddraw1_GetMonitorFrequency
,
4541 ddraw1_GetVerticalBlankStatus
,
4543 ddraw1_RestoreDisplayMode
,
4544 ddraw1_SetCooperativeLevel
,
4545 ddraw1_SetDisplayMode
,
4546 ddraw1_WaitForVerticalBlank
,
4549 static const struct IDirect3D7Vtbl d3d7_vtbl
=
4551 /* IUnknown methods */
4552 d3d7_QueryInterface
,
4555 /* IDirect3D7 methods */
4558 d3d7_CreateVertexBuffer
,
4559 d3d7_EnumZBufferFormats
,
4560 d3d7_EvictManagedTextures
4563 static const struct IDirect3D3Vtbl d3d3_vtbl
=
4565 /* IUnknown methods */
4566 d3d3_QueryInterface
,
4569 /* IDirect3D3 methods */
4572 d3d3_CreateMaterial
,
4573 d3d3_CreateViewport
,
4576 d3d3_CreateVertexBuffer
,
4577 d3d3_EnumZBufferFormats
,
4578 d3d3_EvictManagedTextures
4581 static const struct IDirect3D2Vtbl d3d2_vtbl
=
4583 /* IUnknown methods */
4584 d3d2_QueryInterface
,
4587 /* IDirect3D2 methods */
4590 d3d2_CreateMaterial
,
4591 d3d2_CreateViewport
,
4596 static const struct IDirect3DVtbl d3d1_vtbl
=
4598 /* IUnknown methods */
4599 d3d1_QueryInterface
,
4602 /* IDirect3D methods */
4606 d3d1_CreateMaterial
,
4607 d3d1_CreateViewport
,
4611 /*****************************************************************************
4614 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
4615 * if none was found.
4617 * This function is in ddraw.c and the DDraw object space because D3D7
4618 * vertex buffers are created using the IDirect3D interface to the ddraw
4619 * object, so they can be valid across D3D devices(theoretically. The ddraw
4620 * object also owns the wined3d device
4624 * fvf: Fvf to find the decl for
4627 * NULL in case of an error, the vertex declaration for the FVF otherwise.
4629 *****************************************************************************/
4630 struct wined3d_vertex_declaration
*ddraw_find_decl(struct ddraw
*This
, DWORD fvf
)
4632 struct wined3d_vertex_declaration
*pDecl
= NULL
;
4634 int p
, low
, high
; /* deliberately signed */
4635 struct FvfToDecl
*convertedDecls
= This
->decls
;
4637 TRACE("Searching for declaration for fvf %08x... ", fvf
);
4640 high
= This
->numConvertedDecls
- 1;
4641 while(low
<= high
) {
4642 p
= (low
+ high
) >> 1;
4644 if(convertedDecls
[p
].fvf
== fvf
) {
4645 TRACE("found %p\n", convertedDecls
[p
].decl
);
4646 return convertedDecls
[p
].decl
;
4647 } else if(convertedDecls
[p
].fvf
< fvf
) {
4653 TRACE("not found. Creating and inserting at position %d.\n", low
);
4655 hr
= wined3d_vertex_declaration_create_from_fvf(This
->wined3d_device
,
4656 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
4657 if (hr
!= S_OK
) return NULL
;
4659 if(This
->declArraySize
== This
->numConvertedDecls
) {
4660 int grow
= max(This
->declArraySize
/ 2, 8);
4661 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
4662 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
4663 if (!convertedDecls
)
4665 wined3d_vertex_declaration_decref(pDecl
);
4668 This
->decls
= convertedDecls
;
4669 This
->declArraySize
+= grow
;
4672 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
4673 convertedDecls
[low
].decl
= pDecl
;
4674 convertedDecls
[low
].fvf
= fvf
;
4675 This
->numConvertedDecls
++;
4677 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
4681 static inline struct ddraw
*ddraw_from_device_parent(struct wined3d_device_parent
*device_parent
)
4683 return CONTAINING_RECORD(device_parent
, struct ddraw
, device_parent
);
4686 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
4687 struct wined3d_device
*device
)
4689 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
4692 /* This is run from device_process_message() in wined3d, we can't take the
4694 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
4696 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4697 MONITORINFO monitor_info
;
4701 TRACE("device_parent %p.\n", device_parent
);
4703 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) || !ddraw
->swapchain_window
)
4705 TRACE("Nothing to resize.\n");
4709 monitor
= MonitorFromWindow(ddraw
->swapchain_window
, MONITOR_DEFAULTTOPRIMARY
);
4710 monitor_info
.cbSize
= sizeof(monitor_info
);
4711 if (!GetMonitorInfoW(monitor
, &monitor_info
))
4713 ERR("Failed to get monitor info.\n");
4717 r
= &monitor_info
.rcMonitor
;
4718 TRACE("Resizing window %p to %s.\n", ddraw
->swapchain_window
, wine_dbgstr_rect(r
));
4720 if (!SetWindowPos(ddraw
->swapchain_window
, HWND_TOP
, r
->left
, r
->top
,
4721 r
->right
- r
->left
, r
->bottom
- r
->top
, SWP_SHOWWINDOW
| SWP_NOACTIVATE
))
4722 ERR("Failed to resize window.\n");
4725 static void CDECL
device_parent_activate(struct wined3d_device_parent
*device_parent
, BOOL activate
)
4727 TRACE("device_parent %p, activate %#x.\n", device_parent
, activate
);
4730 static HRESULT CDECL
device_parent_surface_created(struct wined3d_device_parent
*device_parent
,
4731 void *container_parent
, struct wined3d_surface
*surface
,
4732 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
4734 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4735 struct ddraw_surface
*ddraw_surface
;
4738 TRACE("device_parent %p, container_parent %p, surface %p, parent %p, parent_ops %p.\n",
4739 device_parent
, container_parent
, surface
, parent
, parent_ops
);
4741 /* We have a swapchain or wined3d internal texture. */
4742 if (!container_parent
|| container_parent
== ddraw
)
4745 *parent_ops
= &ddraw_null_wined3d_parent_ops
;
4750 if (!(ddraw_surface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ddraw_surface
))))
4752 ERR("Failed to allocate surface memory.\n");
4753 return DDERR_OUTOFVIDEOMEMORY
;
4756 if (FAILED(hr
= ddraw_surface_init(ddraw_surface
, ddraw
, container_parent
, surface
, parent_ops
)))
4758 WARN("Failed to initialize surface, hr %#x.\n", hr
);
4759 HeapFree(GetProcessHeap(), 0, ddraw_surface
);
4763 *parent
= ddraw_surface
;
4764 list_add_head(&ddraw
->surface_list
, &ddraw_surface
->surface_list_entry
);
4766 TRACE("Created ddraw surface %p.\n", ddraw_surface
);
4771 static HRESULT CDECL
device_parent_volume_created(struct wined3d_device_parent
*device_parent
,
4772 void *container_parent
, struct wined3d_volume
*volume
,
4773 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
4775 TRACE("device_parent %p, container_parent %p, volume %p, parent %p, parent_ops %p.\n",
4776 device_parent
, container_parent
, volume
, parent
, parent_ops
);
4779 *parent_ops
= &ddraw_null_wined3d_parent_ops
;
4784 static void STDMETHODCALLTYPE
ddraw_frontbuffer_destroyed(void *parent
)
4786 struct ddraw
*ddraw
= parent
;
4787 ddraw
->wined3d_frontbuffer
= NULL
;
4790 static const struct wined3d_parent_ops ddraw_frontbuffer_parent_ops
=
4792 ddraw_frontbuffer_destroyed
,
4795 static HRESULT CDECL
device_parent_create_swapchain_surface(struct wined3d_device_parent
*device_parent
,
4796 void *container_parent
, const struct wined3d_resource_desc
*desc
, struct wined3d_surface
**surface
)
4798 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4799 struct wined3d_resource_desc texture_desc
;
4800 struct wined3d_texture
*texture
;
4803 TRACE("device_parent %p, container_parent %p, desc %p, surface %p.\n",
4804 device_parent
, container_parent
, desc
, surface
);
4806 if (ddraw
->wined3d_frontbuffer
)
4808 ERR("Frontbuffer already created.\n");
4812 texture_desc
= *desc
;
4813 texture_desc
.resource_type
= WINED3D_RTYPE_TEXTURE
;
4814 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, &texture_desc
, 1,
4815 WINED3D_SURFACE_MAPPABLE
, ddraw
, &ddraw_frontbuffer_parent_ops
, &texture
)))
4817 WARN("Failed to create texture, hr %#x.\n", hr
);
4821 *surface
= wined3d_surface_from_resource(wined3d_texture_get_sub_resource(texture
, 0));
4822 ddraw
->wined3d_frontbuffer
= *surface
;
4823 wined3d_surface_incref(*surface
);
4824 wined3d_texture_decref(texture
);
4829 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
4830 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
4832 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4835 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent
, desc
, swapchain
);
4837 if (ddraw
->wined3d_swapchain
)
4839 ERR("Swapchain already created.\n");
4843 if (FAILED(hr
= wined3d_swapchain_create(ddraw
->wined3d_device
, desc
, NULL
,
4844 &ddraw_null_wined3d_parent_ops
, swapchain
)))
4845 WARN("Failed to create swapchain, hr %#x.\n", hr
);
4850 static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops
=
4852 device_parent_wined3d_device_created
,
4853 device_parent_mode_changed
,
4854 device_parent_activate
,
4855 device_parent_surface_created
,
4856 device_parent_volume_created
,
4857 device_parent_create_swapchain_surface
,
4858 device_parent_create_swapchain
,
4861 HRESULT
ddraw_init(struct ddraw
*ddraw
, enum wined3d_device_type device_type
)
4867 ddraw
->IDirectDraw7_iface
.lpVtbl
= &ddraw7_vtbl
;
4868 ddraw
->IDirectDraw_iface
.lpVtbl
= &ddraw1_vtbl
;
4869 ddraw
->IDirectDraw2_iface
.lpVtbl
= &ddraw2_vtbl
;
4870 ddraw
->IDirectDraw4_iface
.lpVtbl
= &ddraw4_vtbl
;
4871 ddraw
->IDirect3D_iface
.lpVtbl
= &d3d1_vtbl
;
4872 ddraw
->IDirect3D2_iface
.lpVtbl
= &d3d2_vtbl
;
4873 ddraw
->IDirect3D3_iface
.lpVtbl
= &d3d3_vtbl
;
4874 ddraw
->IDirect3D7_iface
.lpVtbl
= &d3d7_vtbl
;
4875 ddraw
->device_parent
.ops
= &ddraw_wined3d_device_parent_ops
;
4876 ddraw
->numIfaces
= 1;
4879 flags
= WINED3D_LEGACY_DEPTH_BIAS
| WINED3D_VIDMEM_ACCOUNTING
;
4880 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
4882 if (!(ddraw
->wined3d
= wined3d_create(flags
| WINED3D_NO3D
)))
4884 WARN("Failed to create a wined3d object.\n");
4889 if (FAILED(hr
= wined3d_get_device_caps(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
, &caps
)))
4891 ERR("Failed to get device caps, hr %#x.\n", hr
);
4892 wined3d_decref(ddraw
->wined3d
);
4896 if (!(caps
.ddraw_caps
.caps
& WINEDDCAPS_3D
))
4898 WARN("Created a wined3d object without 3D support.\n");
4899 ddraw
->flags
|= DDRAW_NO3D
;
4902 if (FAILED(hr
= wined3d_device_create(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
,
4903 NULL
, 0, DDRAW_STRIDE_ALIGNMENT
, &ddraw
->device_parent
, &ddraw
->wined3d_device
)))
4905 WARN("Failed to create a wined3d device, hr %#x.\n", hr
);
4906 wined3d_decref(ddraw
->wined3d
);
4910 list_init(&ddraw
->surface_list
);