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 #include "wine/exception.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
33 static const struct ddraw
*exclusive_ddraw
;
34 static HWND exclusive_window
;
36 /* Device identifier. Don't relay it to WineD3D */
37 static const DDDEVICEIDENTIFIER2 deviceidentifier
=
39 "vga.dll", /* default 2D driver */
41 { { 0x00010001, 0x00010001 } },
43 /* a8373c10-7ac4-4deb-849a-009844d08b2d */
44 {0xa8373c10,0x7ac4,0x4deb, {0x84,0x9a,0x00,0x98,0x44,0xd0,0x8b,0x2d}},
48 static struct enum_device_entry
50 char interface_name
[100];
51 char device_name
[100];
52 const GUID
*device_guid
;
57 "WINE Direct3D7 Hardware Transform and Lighting acceleration using WineD3D",
59 &IID_IDirect3DTnLHalDevice
,
64 "WINE Direct3D7 Hardware acceleration using WineD3D",
66 &IID_IDirect3DHALDevice
,
71 "WINE Direct3D7 RGB Software Emulation using WineD3D",
73 &IID_IDirect3DRGBDevice
,
77 static void STDMETHODCALLTYPE
ddraw_null_wined3d_object_destroyed(void *parent
) {}
79 const struct wined3d_parent_ops ddraw_null_wined3d_parent_ops
=
81 ddraw_null_wined3d_object_destroyed
,
84 static inline struct ddraw
*impl_from_IDirectDraw(IDirectDraw
*iface
)
86 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw_iface
);
89 static inline struct ddraw
*impl_from_IDirectDraw2(IDirectDraw2
*iface
)
91 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw2_iface
);
94 static inline struct ddraw
*impl_from_IDirectDraw4(IDirectDraw4
*iface
)
96 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw4_iface
);
99 static inline struct ddraw
*impl_from_IDirectDraw7(IDirectDraw7
*iface
)
101 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw7_iface
);
104 static inline struct ddraw
*impl_from_IDirect3D(IDirect3D
*iface
)
106 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D_iface
);
109 static inline struct ddraw
*impl_from_IDirect3D2(IDirect3D2
*iface
)
111 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D2_iface
);
114 static inline struct ddraw
*impl_from_IDirect3D3(IDirect3D3
*iface
)
116 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D3_iface
);
119 static inline struct ddraw
*impl_from_IDirect3D7(IDirect3D7
*iface
)
121 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D7_iface
);
124 static HRESULT WINAPI
ddraw7_QueryInterface(IDirectDraw7
*iface
, REFIID riid
, void **out
)
126 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
128 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
133 return DDERR_INVALIDPARAMS
;
136 /* The refcount unit test revealed that an IDirect3D7 interface can only
137 * be queried from a DirectDraw object that was created as an IDirectDraw7
138 * interface. The older interfaces can query any IDirect3D version except
139 * 7, because they are all initially created as IDirectDraw. This isn't
140 * really crucial behavior, and messy to implement with the common
141 * creation function, so it has been left out here. */
142 if (IsEqualGUID(&IID_IDirectDraw7
, riid
)
143 || IsEqualGUID(&IID_IUnknown
, riid
))
145 *out
= &ddraw
->IDirectDraw7_iface
;
146 TRACE("Returning IDirectDraw7 interface %p.\n", *out
);
148 else if (IsEqualGUID(&IID_IDirectDraw4
, riid
))
150 *out
= &ddraw
->IDirectDraw4_iface
;
151 TRACE("Returning IDirectDraw4 interface %p.\n", *out
);
153 else if (IsEqualGUID(&IID_IDirectDraw2
, riid
))
155 *out
= &ddraw
->IDirectDraw2_iface
;
156 TRACE("Returning IDirectDraw2 interface %p.\n", *out
);
158 else if (IsEqualGUID(&IID_IDirectDraw
, riid
))
160 *out
= &ddraw
->IDirectDraw_iface
;
161 TRACE("Returning IDirectDraw interface %p.\n", *out
);
163 else if (IsEqualGUID(&IID_IDirect3D7
, riid
))
165 ddraw
->d3dversion
= 7;
166 *out
= &ddraw
->IDirect3D7_iface
;
167 TRACE("Returning Direct3D7 interface %p.\n", *out
);
169 else if (IsEqualGUID(&IID_IDirect3D3
, riid
))
171 ddraw
->d3dversion
= 3;
172 *out
= &ddraw
->IDirect3D3_iface
;
173 TRACE("Returning Direct3D3 interface %p.\n", *out
);
175 else if (IsEqualGUID(&IID_IDirect3D2
, riid
))
177 ddraw
->d3dversion
= 2;
178 *out
= &ddraw
->IDirect3D2_iface
;
179 TRACE("Returning Direct3D2 interface %p.\n", *out
);
181 else if (IsEqualGUID(&IID_IDirect3D
, riid
))
183 ddraw
->d3dversion
= 1;
184 *out
= &ddraw
->IDirect3D_iface
;
185 TRACE("Returning Direct3D interface %p.\n", *out
);
187 /* Unknown interface */
190 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
192 return E_NOINTERFACE
;
195 IUnknown_AddRef((IUnknown
*)*out
);
199 static HRESULT WINAPI
ddraw4_QueryInterface(IDirectDraw4
*iface
, REFIID riid
, void **object
)
201 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
203 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
205 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
208 static HRESULT WINAPI
ddraw2_QueryInterface(IDirectDraw2
*iface
, REFIID riid
, void **object
)
210 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
212 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
214 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
217 static HRESULT WINAPI
ddraw1_QueryInterface(IDirectDraw
*iface
, REFIID riid
, void **object
)
219 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
221 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
223 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
226 static HRESULT WINAPI
d3d7_QueryInterface(IDirect3D7
*iface
, REFIID riid
, void **object
)
228 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
230 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
232 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
235 static HRESULT WINAPI
d3d3_QueryInterface(IDirect3D3
*iface
, REFIID riid
, void **object
)
237 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
239 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
241 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
244 static HRESULT WINAPI
d3d2_QueryInterface(IDirect3D2
*iface
, REFIID riid
, void **object
)
246 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
248 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
250 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
253 static HRESULT WINAPI
d3d1_QueryInterface(IDirect3D
*iface
, REFIID riid
, void **object
)
255 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
257 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
259 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
262 /*****************************************************************************
263 * IDirectDraw7::AddRef
265 * Increases the interfaces refcount, basically
267 * DDraw refcounting is a bit tricky. The different DirectDraw interface
268 * versions have individual refcounts, but the IDirect3D interfaces do not.
269 * All interfaces are from one object, that means calling QueryInterface on an
270 * IDirectDraw7 interface for an IDirectDraw4 interface does not create a new
273 * That means all AddRef and Release implementations of IDirectDrawX work
274 * with their own counter, and IDirect3DX::AddRef thunk to IDirectDraw (1),
275 * except of IDirect3D7 which thunks to IDirectDraw7
277 * Returns: The new refcount
279 *****************************************************************************/
280 static ULONG WINAPI
ddraw7_AddRef(IDirectDraw7
*iface
)
282 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
283 ULONG ref
= InterlockedIncrement(&This
->ref7
);
285 TRACE("%p increasing refcount to %u.\n", This
, ref
);
287 if(ref
== 1) InterlockedIncrement(&This
->numIfaces
);
292 static ULONG WINAPI
ddraw4_AddRef(IDirectDraw4
*iface
)
294 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
295 ULONG ref
= InterlockedIncrement(&This
->ref4
);
297 TRACE("%p increasing refcount to %u.\n", This
, ref
);
299 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
304 static ULONG WINAPI
ddraw2_AddRef(IDirectDraw2
*iface
)
306 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
307 ULONG ref
= InterlockedIncrement(&This
->ref2
);
309 TRACE("%p increasing refcount to %u.\n", This
, ref
);
311 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
316 static ULONG WINAPI
ddraw1_AddRef(IDirectDraw
*iface
)
318 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
319 ULONG ref
= InterlockedIncrement(&This
->ref1
);
321 TRACE("%p increasing refcount to %u.\n", This
, ref
);
323 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
328 static ULONG WINAPI
d3d7_AddRef(IDirect3D7
*iface
)
330 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
332 TRACE("iface %p.\n", iface
);
334 return ddraw7_AddRef(&This
->IDirectDraw7_iface
);
337 static ULONG WINAPI
d3d3_AddRef(IDirect3D3
*iface
)
339 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
341 TRACE("iface %p.\n", iface
);
343 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
346 static ULONG WINAPI
d3d2_AddRef(IDirect3D2
*iface
)
348 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
350 TRACE("iface %p.\n", iface
);
352 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
355 static ULONG WINAPI
d3d1_AddRef(IDirect3D
*iface
)
357 struct ddraw
*This
= impl_from_IDirect3D(iface
);
359 TRACE("iface %p.\n", iface
);
361 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
364 static void ddraw_destroy_swapchain(struct ddraw
*ddraw
)
366 TRACE("Destroying the swapchain.\n");
368 wined3d_swapchain_decref(ddraw
->wined3d_swapchain
);
369 ddraw
->wined3d_swapchain
= NULL
;
371 if (!(ddraw
->flags
& DDRAW_NO3D
))
375 for (i
= 0; i
< ddraw
->numConvertedDecls
; ++i
)
377 wined3d_vertex_declaration_decref(ddraw
->decls
[i
].decl
);
379 HeapFree(GetProcessHeap(), 0, ddraw
->decls
);
380 ddraw
->numConvertedDecls
= 0;
382 if (FAILED(wined3d_device_uninit_3d(ddraw
->wined3d_device
)))
384 ERR("Failed to uninit 3D.\n");
388 /* Free the d3d window if one was created. */
389 if (ddraw
->d3d_window
&& ddraw
->d3d_window
!= ddraw
->dest_window
)
391 TRACE("Destroying the hidden render window %p.\n", ddraw
->d3d_window
);
392 DestroyWindow(ddraw
->d3d_window
);
393 ddraw
->d3d_window
= 0;
397 ddraw
->flags
&= ~DDRAW_D3D_INITIALIZED
;
401 wined3d_device_uninit_gdi(ddraw
->wined3d_device
);
404 ddraw_set_swapchain_window(ddraw
, NULL
);
406 TRACE("Swapchain destroyed.\n");
409 /*****************************************************************************
412 * Destroys a ddraw object if all refcounts are 0. This is to share code
413 * between the IDirectDrawX::Release functions
416 * This: DirectDraw object to destroy
418 *****************************************************************************/
419 static void ddraw_destroy(struct ddraw
*This
)
421 IDirectDraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, NULL
, DDSCL_NORMAL
);
422 IDirectDraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
424 /* Destroy the device window if we created one */
425 if(This
->devicewindow
!= 0)
427 TRACE(" (%p) Destroying the device window %p\n", This
, This
->devicewindow
);
428 DestroyWindow(This
->devicewindow
);
429 This
->devicewindow
= 0;
432 wined3d_mutex_lock();
433 list_remove(&This
->ddraw_list_entry
);
434 wined3d_mutex_unlock();
436 if (This
->wined3d_swapchain
)
437 ddraw_destroy_swapchain(This
);
438 wined3d_device_decref(This
->wined3d_device
);
439 wined3d_decref(This
->wined3d
);
442 This
->d3ddevice
->ddraw
= NULL
;
444 /* Now free the object */
445 HeapFree(GetProcessHeap(), 0, This
);
448 /*****************************************************************************
449 * IDirectDraw7::Release
451 * Decreases the refcount. If the refcount falls to 0, the object is destroyed
453 * Returns: The new refcount
454 *****************************************************************************/
455 static ULONG WINAPI
ddraw7_Release(IDirectDraw7
*iface
)
457 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
458 ULONG ref
= InterlockedDecrement(&This
->ref7
);
460 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
462 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
468 static ULONG WINAPI
ddraw4_Release(IDirectDraw4
*iface
)
470 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
471 ULONG ref
= InterlockedDecrement(&This
->ref4
);
473 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
475 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
481 static ULONG WINAPI
ddraw2_Release(IDirectDraw2
*iface
)
483 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
484 ULONG ref
= InterlockedDecrement(&This
->ref2
);
486 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
488 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
494 static ULONG WINAPI
ddraw1_Release(IDirectDraw
*iface
)
496 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
497 ULONG ref
= InterlockedDecrement(&This
->ref1
);
499 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
501 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
507 static ULONG WINAPI
d3d7_Release(IDirect3D7
*iface
)
509 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
511 TRACE("iface %p.\n", iface
);
513 return ddraw7_Release(&This
->IDirectDraw7_iface
);
516 static ULONG WINAPI
d3d3_Release(IDirect3D3
*iface
)
518 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
520 TRACE("iface %p.\n", iface
);
522 return ddraw1_Release(&This
->IDirectDraw_iface
);
525 static ULONG WINAPI
d3d2_Release(IDirect3D2
*iface
)
527 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
529 TRACE("iface %p.\n", iface
);
531 return ddraw1_Release(&This
->IDirectDraw_iface
);
534 static ULONG WINAPI
d3d1_Release(IDirect3D
*iface
)
536 struct ddraw
*This
= impl_from_IDirect3D(iface
);
538 TRACE("iface %p.\n", iface
);
540 return ddraw1_Release(&This
->IDirectDraw_iface
);
543 /*****************************************************************************
544 * IDirectDraw methods
545 *****************************************************************************/
547 static HRESULT
ddraw_set_focus_window(struct ddraw
*ddraw
, HWND window
)
549 /* FIXME: This looks wrong, exclusive mode should imply a destination
551 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) && ddraw
->dest_window
)
553 TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET.\n");
554 return DDERR_HWNDALREADYSET
;
557 ddraw
->focuswindow
= window
;
562 static HRESULT
ddraw_attach_d3d_device(struct ddraw
*ddraw
,
563 struct wined3d_swapchain_desc
*swapchain_desc
)
565 HWND window
= swapchain_desc
->device_window
;
568 TRACE("ddraw %p.\n", ddraw
);
570 if (!window
|| window
== GetDesktopWindow())
572 window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "Hidden D3D Window",
573 WS_DISABLED
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
574 NULL
, NULL
, NULL
, NULL
);
577 ERR("Failed to create window, last error %#x.\n", GetLastError());
581 ShowWindow(window
, SW_HIDE
); /* Just to be sure */
582 WARN("No window for the Direct3DDevice, created hidden window %p.\n", window
);
584 swapchain_desc
->device_window
= window
;
588 TRACE("Using existing window %p for Direct3D rendering.\n", window
);
590 ddraw
->d3d_window
= window
;
592 /* Set this NOW, otherwise creating the depth stencil surface will cause a
593 * recursive loop until ram or emulated video memory is full. */
594 ddraw
->flags
|= DDRAW_D3D_INITIALIZED
;
595 hr
= wined3d_device_init_3d(ddraw
->wined3d_device
, swapchain_desc
);
598 ddraw
->flags
&= ~DDRAW_D3D_INITIALIZED
;
602 ddraw
->declArraySize
= 2;
603 ddraw
->decls
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ddraw
->decls
) * ddraw
->declArraySize
);
606 ERR("Error allocating an array for the converted vertex decls.\n");
607 ddraw
->declArraySize
= 0;
608 hr
= wined3d_device_uninit_3d(ddraw
->wined3d_device
);
609 return E_OUTOFMEMORY
;
612 TRACE("Successfully initialized 3D.\n");
617 static HRESULT
ddraw_create_swapchain(struct ddraw
*ddraw
, HWND window
, BOOL windowed
)
619 struct wined3d_swapchain_desc swapchain_desc
;
620 struct wined3d_display_mode mode
;
621 HRESULT hr
= WINED3D_OK
;
623 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
625 ERR("Failed to get display mode.\n");
629 memset(&swapchain_desc
, 0, sizeof(swapchain_desc
));
630 swapchain_desc
.backbuffer_width
= mode
.width
;
631 swapchain_desc
.backbuffer_height
= mode
.height
;
632 swapchain_desc
.backbuffer_format
= mode
.format_id
;
633 swapchain_desc
.swap_effect
= WINED3D_SWAP_EFFECT_COPY
;
634 swapchain_desc
.device_window
= window
;
635 swapchain_desc
.windowed
= windowed
;
636 swapchain_desc
.flags
= WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH
;
638 if (!(ddraw
->flags
& DDRAW_NO3D
))
639 hr
= ddraw_attach_d3d_device(ddraw
, &swapchain_desc
);
641 hr
= wined3d_device_init_gdi(ddraw
->wined3d_device
, &swapchain_desc
);
645 ERR("Failed to create swapchain, hr %#x.\n", hr
);
649 if (!(ddraw
->wined3d_swapchain
= wined3d_device_get_swapchain(ddraw
->wined3d_device
, 0)))
651 ERR("Failed to get swapchain.\n");
652 return DDERR_INVALIDPARAMS
;
655 wined3d_swapchain_incref(ddraw
->wined3d_swapchain
);
656 ddraw_set_swapchain_window(ddraw
, window
);
658 if (ddraw
->primary
&& ddraw
->primary
->palette
)
659 wined3d_swapchain_set_palette(ddraw
->wined3d_swapchain
, ddraw
->primary
->palette
->wined3d_palette
);
664 /*****************************************************************************
665 * IDirectDraw7::RestoreDisplayMode
667 * Restores the display mode to what it was at creation time. Basically.
671 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
673 *****************************************************************************/
674 static HRESULT WINAPI
ddraw7_RestoreDisplayMode(IDirectDraw7
*iface
)
676 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
679 TRACE("iface %p.\n", iface
);
681 wined3d_mutex_lock();
683 if (!(ddraw
->flags
& DDRAW_RESTORE_MODE
))
685 wined3d_mutex_unlock();
689 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
691 wined3d_mutex_unlock();
692 return DDERR_NOEXCLUSIVEMODE
;
695 if (SUCCEEDED(hr
= wined3d_set_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, NULL
)))
696 ddraw
->flags
&= ~DDRAW_RESTORE_MODE
;
698 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_OK
);
700 wined3d_mutex_unlock();
705 static HRESULT WINAPI
ddraw4_RestoreDisplayMode(IDirectDraw4
*iface
)
707 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
709 TRACE("iface %p.\n", iface
);
711 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
714 static HRESULT WINAPI
ddraw2_RestoreDisplayMode(IDirectDraw2
*iface
)
716 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
718 TRACE("iface %p.\n", iface
);
720 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
723 static HRESULT WINAPI
ddraw1_RestoreDisplayMode(IDirectDraw
*iface
)
725 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
727 TRACE("iface %p.\n", iface
);
729 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
732 /*****************************************************************************
733 * IDirectDraw7::SetCooperativeLevel
735 * Sets the cooperative level for the DirectDraw object, and the window
736 * assigned to it. The cooperative level determines the general behavior
737 * of the DirectDraw application
739 * Warning: This is quite tricky, as it's not really documented which
740 * cooperative levels can be combined with each other. If a game fails
741 * after this function, try to check the cooperative levels passed on
742 * Windows, and if it returns something different.
744 * If you think that this function caused the failure because it writes a
745 * fixme, be sure to run again with a +ddraw trace.
747 * What is known about cooperative levels (See the ddraw modes test):
748 * DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN.
749 * DDSCL_NORMAL is not compatible with DDSCL_EXCLUSIVE.
750 * Unlike what msdn claims, DDSCL_NORMAL | DDSCL_FULLSCREEN is allowed.
751 * DDSCL_SETFOCUSWINDOW can be passed only in DDSCL_NORMAL mode, but after that
752 * DDSCL_EXCLUSIVE can be activated.
753 * DDSCL_SETFOCUSWINDOW may only be used with DDSCL_NOWINDOWCHANGES or
754 * DDSCL_CREATEDEVICEWINDOW.
756 * Handled flags: DDSCL_NORMAL, DDSCL_FULLSCREEN, DDSCL_EXCLUSIVE,
757 * DDSCL_CREATEDEVICEWINDOW, DDSCL_SETDEVICEWINDOW
758 * DDSCL_SETFOCUSWINDOW (partially),
759 * DDSCL_MULTITHREADED (work in progress)
760 * DDSCL_FPUPRESERVE (see device.c)
762 * Unsure about this: DDSCL_FPUSETUP
764 * These don't seem very important for wine:
765 * DDSCL_ALLOWREBOOT, DDSCL_NOWINDOWCHANGES, DDSCL_ALLOWMODEX
768 * DD_OK if the cooperative level was set successfully
769 * DDERR_INVALIDPARAMS if the passed cooperative level combination is invalid
770 * DDERR_HWNDALREADYSET if DDSCL_SETFOCUSWINDOW is passed in exclusive mode
771 * (Probably others too, have to investigate)
773 *****************************************************************************/
774 static HRESULT
ddraw_set_cooperative_level(struct ddraw
*ddraw
, HWND window
,
775 DWORD cooplevel
, BOOL restore_mode_on_normal
)
777 struct wined3d_rendertarget_view
*rtv
= NULL
, *dsv
= NULL
;
778 struct wined3d_stateblock
*stateblock
;
779 BOOL restore_state
= FALSE
;
782 TRACE("ddraw %p, window %p, flags %#x, restore_mode_on_normal %x.\n", ddraw
, window
, cooplevel
,
783 restore_mode_on_normal
);
784 DDRAW_dump_cooperativelevel(cooplevel
);
786 wined3d_mutex_lock();
788 if (ddraw
->flags
& DDRAW_SCL_RECURSIVE
)
790 WARN("Recursive call, returning DD_OK.\n");
794 ddraw
->flags
|= DDRAW_SCL_RECURSIVE
;
796 /* Tests suggest that we need one of them: */
797 if(!(cooplevel
& (DDSCL_SETFOCUSWINDOW
|
801 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
802 hr
= DDERR_INVALIDPARAMS
;
806 if ((cooplevel
& DDSCL_CREATEDEVICEWINDOW
) && !(cooplevel
& DDSCL_EXCLUSIVE
))
808 WARN("DDSCL_CREATEDEVICEWINDOW requires DDSCL_EXCLUSIVE.\n");
809 hr
= DDERR_INVALIDPARAMS
;
813 /* Handle those levels first which set various hwnds */
814 if ((cooplevel
& DDSCL_SETFOCUSWINDOW
) && !(cooplevel
& DDSCL_CREATEDEVICEWINDOW
))
816 /* This isn't compatible with a lot of flags */
817 if (cooplevel
& (DDSCL_MULTITHREADED
822 | DDSCL_SETDEVICEWINDOW
827 WARN("Called with incompatible flags, returning DDERR_INVALIDPARAMS.\n");
828 hr
= DDERR_INVALIDPARAMS
;
832 hr
= ddraw_set_focus_window(ddraw
, window
);
836 if (cooplevel
& DDSCL_EXCLUSIVE
)
838 if (!(cooplevel
& DDSCL_FULLSCREEN
) || !(window
|| (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)))
840 WARN("DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN and a window.\n");
841 hr
= DDERR_INVALIDPARAMS
;
845 if (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)
849 if (!ddraw
->focuswindow
&& !(cooplevel
& DDSCL_SETFOCUSWINDOW
))
851 WARN("No focus window set.\n");
852 hr
= DDERR_NOFOCUSWINDOW
;
856 device_window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "DirectDrawDeviceWnd",
857 WS_POPUP
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
858 NULL
, NULL
, NULL
, NULL
);
861 ERR("Failed to create window, last error %#x.\n", GetLastError());
866 ShowWindow(device_window
, SW_SHOW
);
867 TRACE("Created a device window %p.\n", device_window
);
869 /* Native apparently leaks the created device window if setting the
870 * focus window below fails. */
871 ddraw
->cooperative_level
|= DDSCL_CREATEDEVICEWINDOW
;
872 ddraw
->devicewindow
= device_window
;
874 if (cooplevel
& DDSCL_SETFOCUSWINDOW
)
882 if (FAILED(hr
= ddraw_set_focus_window(ddraw
, window
)))
886 window
= device_window
;
891 if (ddraw
->cooperative_level
& DDSCL_CREATEDEVICEWINDOW
)
892 DestroyWindow(ddraw
->devicewindow
);
893 ddraw
->devicewindow
= NULL
;
894 ddraw
->focuswindow
= NULL
;
897 if ((cooplevel
& DDSCL_FULLSCREEN
) != (ddraw
->cooperative_level
& DDSCL_FULLSCREEN
) || window
!= ddraw
->dest_window
)
899 if (ddraw
->cooperative_level
& DDSCL_FULLSCREEN
)
900 wined3d_device_restore_fullscreen_window(ddraw
->wined3d_device
, ddraw
->dest_window
, NULL
);
902 if (cooplevel
& DDSCL_FULLSCREEN
)
904 struct wined3d_display_mode display_mode
;
906 wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &display_mode
, NULL
);
907 wined3d_device_setup_fullscreen_window(ddraw
->wined3d_device
, window
,
908 display_mode
.width
, display_mode
.height
);
912 if ((cooplevel
& DDSCL_EXCLUSIVE
) && exclusive_window
!= window
)
914 ddraw
->device_state
= DDRAW_DEVICE_STATE_NOT_RESTORED
;
915 exclusive_window
= window
;
918 if (cooplevel
& DDSCL_MULTITHREADED
&& !(ddraw
->cooperative_level
& DDSCL_MULTITHREADED
))
919 wined3d_device_set_multithreaded(ddraw
->wined3d_device
);
921 if (ddraw
->wined3d_swapchain
)
923 if (!(ddraw
->flags
& DDRAW_NO3D
))
925 restore_state
= TRUE
;
927 if (FAILED(hr
= wined3d_stateblock_create(ddraw
->wined3d_device
, WINED3D_SBT_ALL
, &stateblock
)))
929 ERR("Failed to create stateblock, hr %#x.\n", hr
);
933 wined3d_stateblock_capture(stateblock
);
934 rtv
= wined3d_device_get_rendertarget_view(ddraw
->wined3d_device
, 0);
935 /* Rendering to ddraw->wined3d_frontbuffer. */
936 if (rtv
&& !wined3d_rendertarget_view_get_sub_resource_parent(rtv
))
939 wined3d_rendertarget_view_incref(rtv
);
941 if ((dsv
= wined3d_device_get_depth_stencil_view(ddraw
->wined3d_device
)))
942 wined3d_rendertarget_view_incref(dsv
);
945 ddraw_destroy_swapchain(ddraw
);
948 if (FAILED(hr
= ddraw_create_swapchain(ddraw
, window
, !(cooplevel
& DDSCL_FULLSCREEN
))))
949 ERR("Failed to create swapchain, hr %#x.\n", hr
);
955 wined3d_device_set_depth_stencil_view(ddraw
->wined3d_device
, dsv
);
956 wined3d_rendertarget_view_decref(dsv
);
961 wined3d_device_set_rendertarget_view(ddraw
->wined3d_device
, 0, rtv
, FALSE
);
962 wined3d_rendertarget_view_decref(rtv
);
965 wined3d_stateblock_apply(stateblock
);
966 wined3d_stateblock_decref(stateblock
);
969 if (!(cooplevel
& DDSCL_EXCLUSIVE
) && (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
970 && restore_mode_on_normal
)
972 hr
= ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
974 ERR("RestoreDisplayMode failed\n");
977 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
978 && (window
!= ddraw
->dest_window
|| !(cooplevel
& DDSCL_EXCLUSIVE
)))
979 wined3d_device_release_focus_window(ddraw
->wined3d_device
);
981 if ((cooplevel
& DDSCL_EXCLUSIVE
)
982 && (window
!= ddraw
->dest_window
|| !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)))
984 hr
= wined3d_device_acquire_focus_window(ddraw
->wined3d_device
, window
);
987 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
992 /* Unhandled flags */
993 if (cooplevel
& DDSCL_ALLOWREBOOT
)
994 WARN("Unhandled flag DDSCL_ALLOWREBOOT, harmless\n");
995 if (cooplevel
& DDSCL_ALLOWMODEX
)
996 WARN("Unhandled flag DDSCL_ALLOWMODEX, harmless\n");
997 if (cooplevel
& DDSCL_FPUSETUP
)
998 WARN("Unhandled flag DDSCL_FPUSETUP, harmless\n");
1000 if (cooplevel
& DDSCL_EXCLUSIVE
)
1001 exclusive_ddraw
= ddraw
;
1002 else if (exclusive_ddraw
== ddraw
)
1003 exclusive_ddraw
= NULL
;
1005 /* Store the cooperative_level */
1006 ddraw
->cooperative_level
= cooplevel
;
1007 ddraw
->dest_window
= window
;
1009 TRACE("SetCooperativeLevel returning DD_OK\n");
1012 ddraw
->flags
&= ~DDRAW_SCL_RECURSIVE
;
1013 wined3d_mutex_unlock();
1018 static HRESULT WINAPI
ddraw7_SetCooperativeLevel(IDirectDraw7
*iface
, HWND window
, DWORD flags
)
1020 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1022 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1024 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1027 static HRESULT WINAPI
ddraw4_SetCooperativeLevel(IDirectDraw4
*iface
, HWND window
, DWORD flags
)
1029 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1031 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1033 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1036 static HRESULT WINAPI
ddraw2_SetCooperativeLevel(IDirectDraw2
*iface
, HWND window
, DWORD flags
)
1038 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1040 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1042 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1045 static HRESULT WINAPI
ddraw1_SetCooperativeLevel(IDirectDraw
*iface
, HWND window
, DWORD flags
)
1047 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1050 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1052 hr
= ddraw_set_cooperative_level(ddraw
, window
, flags
, FALSE
);
1054 ddraw
->flags
|= DDRAW_SCL_DDRAW1
;
1058 /*****************************************************************************
1059 * IDirectDraw7::SetDisplayMode
1061 * Sets the display screen resolution, color depth and refresh frequency
1062 * when in fullscreen mode (in theory).
1063 * Possible return values listed in the SDK suggest that this method fails
1064 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
1065 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
1066 * It seems to be valid to pass 0 for With and Height, this has to be tested
1067 * It could mean that the current video mode should be left as-is. (But why
1071 * Height, Width: Screen dimension
1072 * BPP: Color depth in Bits per pixel
1073 * Refreshrate: Screen refresh rate
1074 * Flags: Other stuff
1079 *****************************************************************************/
1080 static HRESULT WINAPI
ddraw7_SetDisplayMode(IDirectDraw7
*iface
, DWORD width
, DWORD height
,
1081 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1083 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1084 struct wined3d_display_mode mode
;
1085 enum wined3d_format_id format
;
1088 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1089 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1091 if (force_refresh_rate
!= 0)
1093 TRACE("ForceRefreshRate overriding passed-in refresh rate (%u Hz) to %u Hz\n",
1094 refresh_rate
, force_refresh_rate
);
1095 refresh_rate
= force_refresh_rate
;
1098 wined3d_mutex_lock();
1100 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
1102 wined3d_mutex_unlock();
1103 return DDERR_NOEXCLUSIVEMODE
;
1106 if (!width
|| !height
)
1108 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here. */
1109 wined3d_mutex_unlock();
1115 case 8: format
= WINED3DFMT_P8_UINT
; break;
1116 case 15: format
= WINED3DFMT_B5G5R5X1_UNORM
; break;
1117 case 16: format
= WINED3DFMT_B5G6R5_UNORM
; break;
1118 case 24: format
= WINED3DFMT_B8G8R8_UNORM
; break;
1119 case 32: format
= WINED3DFMT_B8G8R8X8_UNORM
; break;
1120 default: format
= WINED3DFMT_UNKNOWN
; break;
1124 mode
.height
= height
;
1125 mode
.refresh_rate
= refresh_rate
;
1126 mode
.format_id
= format
;
1127 mode
.scanline_ordering
= WINED3D_SCANLINE_ORDERING_UNKNOWN
;
1129 /* TODO: The possible return values from msdn suggest that the screen mode
1130 * can't be changed if a surface is locked or some drawing is in progress. */
1131 if (SUCCEEDED(hr
= wined3d_set_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
)))
1135 DDSURFACEDESC2
*surface_desc
= &ddraw
->primary
->surface_desc
;
1137 if (FAILED(hr
= wined3d_swapchain_resize_buffers(ddraw
->wined3d_swapchain
, 0,
1138 surface_desc
->dwWidth
, surface_desc
->dwHeight
, mode
.format_id
, WINED3D_MULTISAMPLE_NONE
, 0)))
1139 ERR("Failed to resize buffers, hr %#x.\n", hr
);
1141 ddrawformat_from_wined3dformat(&ddraw
->primary
->surface_desc
.u4
.ddpfPixelFormat
, mode
.format_id
);
1143 ddraw
->flags
|= DDRAW_RESTORE_MODE
;
1146 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_OK
);
1148 wined3d_mutex_unlock();
1152 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1157 static HRESULT WINAPI
ddraw4_SetDisplayMode(IDirectDraw4
*iface
, DWORD width
, DWORD height
,
1158 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1160 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1162 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1163 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1165 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1168 static HRESULT WINAPI
ddraw2_SetDisplayMode(IDirectDraw2
*iface
,
1169 DWORD width
, DWORD height
, DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1171 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1173 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1174 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1176 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1179 static HRESULT WINAPI
ddraw1_SetDisplayMode(IDirectDraw
*iface
, DWORD width
, DWORD height
, DWORD bpp
)
1181 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1183 TRACE("iface %p, width %u, height %u, bpp %u.\n", iface
, width
, height
, bpp
);
1185 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, 0, 0);
1188 void ddraw_d3dcaps1_from_7(D3DDEVICEDESC
*caps1
, D3DDEVICEDESC7
*caps7
)
1190 memset(caps1
, 0, sizeof(*caps1
));
1191 caps1
->dwSize
= sizeof(*caps1
);
1192 caps1
->dwFlags
= D3DDD_COLORMODEL
1194 | D3DDD_TRANSFORMCAPS
1196 | D3DDD_LIGHTINGCAPS
1199 | D3DDD_DEVICERENDERBITDEPTH
1200 | D3DDD_DEVICEZBUFFERBITDEPTH
1201 | D3DDD_MAXBUFFERSIZE
1202 | D3DDD_MAXVERTEXCOUNT
;
1203 caps1
->dcmColorModel
= D3DCOLOR_RGB
;
1204 caps1
->dwDevCaps
= caps7
->dwDevCaps
;
1205 caps1
->dtcTransformCaps
.dwSize
= sizeof(caps1
->dtcTransformCaps
);
1206 caps1
->dtcTransformCaps
.dwCaps
= D3DTRANSFORMCAPS_CLIP
;
1207 caps1
->bClipping
= TRUE
;
1208 caps1
->dlcLightingCaps
.dwSize
= sizeof(caps1
->dlcLightingCaps
);
1209 caps1
->dlcLightingCaps
.dwCaps
= D3DLIGHTCAPS_DIRECTIONAL
1210 | D3DLIGHTCAPS_PARALLELPOINT
1211 | D3DLIGHTCAPS_POINT
1212 | D3DLIGHTCAPS_SPOT
;
1213 caps1
->dlcLightingCaps
.dwLightingModel
= D3DLIGHTINGMODEL_RGB
;
1214 caps1
->dlcLightingCaps
.dwNumLights
= caps7
->dwMaxActiveLights
;
1215 caps1
->dpcLineCaps
= caps7
->dpcLineCaps
;
1216 caps1
->dpcTriCaps
= caps7
->dpcTriCaps
;
1217 caps1
->dwDeviceRenderBitDepth
= caps7
->dwDeviceRenderBitDepth
;
1218 caps1
->dwDeviceZBufferBitDepth
= caps7
->dwDeviceZBufferBitDepth
;
1219 caps1
->dwMaxBufferSize
= 0;
1220 caps1
->dwMaxVertexCount
= 65536;
1221 caps1
->dwMinTextureWidth
= caps7
->dwMinTextureWidth
;
1222 caps1
->dwMinTextureHeight
= caps7
->dwMinTextureHeight
;
1223 caps1
->dwMaxTextureWidth
= caps7
->dwMaxTextureWidth
;
1224 caps1
->dwMaxTextureHeight
= caps7
->dwMaxTextureHeight
;
1225 caps1
->dwMinStippleWidth
= 1;
1226 caps1
->dwMinStippleHeight
= 1;
1227 caps1
->dwMaxStippleWidth
= 32;
1228 caps1
->dwMaxStippleHeight
= 32;
1229 caps1
->dwMaxTextureRepeat
= caps7
->dwMaxTextureRepeat
;
1230 caps1
->dwMaxTextureAspectRatio
= caps7
->dwMaxTextureAspectRatio
;
1231 caps1
->dwMaxAnisotropy
= caps7
->dwMaxAnisotropy
;
1232 caps1
->dvGuardBandLeft
= caps7
->dvGuardBandLeft
;
1233 caps1
->dvGuardBandTop
= caps7
->dvGuardBandTop
;
1234 caps1
->dvGuardBandRight
= caps7
->dvGuardBandRight
;
1235 caps1
->dvGuardBandBottom
= caps7
->dvGuardBandBottom
;
1236 caps1
->dvExtentsAdjust
= caps7
->dvExtentsAdjust
;
1237 caps1
->dwStencilCaps
= caps7
->dwStencilCaps
;
1238 caps1
->dwFVFCaps
= caps7
->dwFVFCaps
;
1239 caps1
->dwTextureOpCaps
= caps7
->dwTextureOpCaps
;
1240 caps1
->wMaxTextureBlendStages
= caps7
->wMaxTextureBlendStages
;
1241 caps1
->wMaxSimultaneousTextures
= caps7
->wMaxSimultaneousTextures
;
1244 HRESULT
ddraw_get_d3dcaps(const struct ddraw
*ddraw
, D3DDEVICEDESC7
*caps
)
1246 WINED3DCAPS wined3d_caps
;
1249 TRACE("ddraw %p, caps %p.\n", ddraw
, caps
);
1251 memset(&wined3d_caps
, 0, sizeof(wined3d_caps
));
1253 wined3d_mutex_lock();
1254 hr
= wined3d_get_device_caps(ddraw
->wined3d
, 0, WINED3D_DEVICE_TYPE_HAL
, &wined3d_caps
);
1255 wined3d_mutex_unlock();
1258 WARN("Failed to get device caps, hr %#x.\n", hr
);
1262 caps
->dwDevCaps
= wined3d_caps
.DevCaps
;
1263 caps
->dpcLineCaps
.dwMiscCaps
= wined3d_caps
.PrimitiveMiscCaps
;
1264 caps
->dpcLineCaps
.dwRasterCaps
= wined3d_caps
.RasterCaps
;
1265 caps
->dpcLineCaps
.dwZCmpCaps
= wined3d_caps
.ZCmpCaps
;
1266 caps
->dpcLineCaps
.dwSrcBlendCaps
= wined3d_caps
.SrcBlendCaps
;
1267 caps
->dpcLineCaps
.dwDestBlendCaps
= wined3d_caps
.DestBlendCaps
;
1268 caps
->dpcLineCaps
.dwAlphaCmpCaps
= wined3d_caps
.AlphaCmpCaps
;
1269 caps
->dpcLineCaps
.dwShadeCaps
= wined3d_caps
.ShadeCaps
;
1270 caps
->dpcLineCaps
.dwTextureCaps
= wined3d_caps
.TextureCaps
;
1271 caps
->dpcLineCaps
.dwTextureFilterCaps
= wined3d_caps
.TextureFilterCaps
;
1272 caps
->dpcLineCaps
.dwTextureAddressCaps
= wined3d_caps
.TextureAddressCaps
;
1274 caps
->dwMaxTextureWidth
= wined3d_caps
.MaxTextureWidth
;
1275 caps
->dwMaxTextureHeight
= wined3d_caps
.MaxTextureHeight
;
1277 caps
->dwMaxTextureRepeat
= wined3d_caps
.MaxTextureRepeat
;
1278 caps
->dwMaxTextureAspectRatio
= wined3d_caps
.MaxTextureAspectRatio
;
1279 caps
->dwMaxAnisotropy
= wined3d_caps
.MaxAnisotropy
;
1280 caps
->dvMaxVertexW
= wined3d_caps
.MaxVertexW
;
1282 caps
->dvGuardBandLeft
= wined3d_caps
.GuardBandLeft
;
1283 caps
->dvGuardBandTop
= wined3d_caps
.GuardBandTop
;
1284 caps
->dvGuardBandRight
= wined3d_caps
.GuardBandRight
;
1285 caps
->dvGuardBandBottom
= wined3d_caps
.GuardBandBottom
;
1287 caps
->dvExtentsAdjust
= wined3d_caps
.ExtentsAdjust
;
1288 caps
->dwStencilCaps
= wined3d_caps
.StencilCaps
;
1290 caps
->dwFVFCaps
= wined3d_caps
.FVFCaps
;
1291 caps
->dwTextureOpCaps
= wined3d_caps
.TextureOpCaps
;
1293 caps
->dwVertexProcessingCaps
= wined3d_caps
.VertexProcessingCaps
;
1294 caps
->dwMaxActiveLights
= wined3d_caps
.MaxActiveLights
;
1296 /* Remove all non-d3d7 caps */
1297 caps
->dwDevCaps
&= (
1298 D3DDEVCAPS_FLOATTLVERTEX
| D3DDEVCAPS_SORTINCREASINGZ
| D3DDEVCAPS_SORTDECREASINGZ
|
1299 D3DDEVCAPS_SORTEXACT
| D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
|
1300 D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
| D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
|
1301 D3DDEVCAPS_TEXTUREVIDEOMEMORY
| D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
|
1302 D3DDEVCAPS_TEXTURENONLOCALVIDMEM
| D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
1303 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
1304 D3DDEVCAPS_HWRASTERIZATION
);
1306 caps
->dwStencilCaps
&= (
1307 D3DSTENCILCAPS_KEEP
| D3DSTENCILCAPS_ZERO
| D3DSTENCILCAPS_REPLACE
|
1308 D3DSTENCILCAPS_INCRSAT
| D3DSTENCILCAPS_DECRSAT
| D3DSTENCILCAPS_INVERT
|
1309 D3DSTENCILCAPS_INCR
| D3DSTENCILCAPS_DECR
);
1313 caps
->dwTextureOpCaps
&= (
1314 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_SELECTARG2
|
1315 D3DTEXOPCAPS_MODULATE
| D3DTEXOPCAPS_MODULATE2X
| D3DTEXOPCAPS_MODULATE4X
|
1316 D3DTEXOPCAPS_ADD
| D3DTEXOPCAPS_ADDSIGNED
| D3DTEXOPCAPS_ADDSIGNED2X
|
1317 D3DTEXOPCAPS_SUBTRACT
| D3DTEXOPCAPS_ADDSMOOTH
| D3DTEXOPCAPS_BLENDTEXTUREALPHA
|
1318 D3DTEXOPCAPS_BLENDFACTORALPHA
| D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
| D3DTEXOPCAPS_BLENDCURRENTALPHA
|
1319 D3DTEXOPCAPS_PREMODULATE
| D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
|
1320 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
| D3DTEXOPCAPS_BUMPENVMAP
|
1321 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
| D3DTEXOPCAPS_DOTPRODUCT3
);
1323 caps
->dwVertexProcessingCaps
&= (
1324 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_VERTEXFOG
|
1325 D3DVTXPCAPS_DIRECTIONALLIGHTS
| D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
);
1327 caps
->dpcLineCaps
.dwMiscCaps
&= (
1328 D3DPMISCCAPS_MASKPLANES
| D3DPMISCCAPS_MASKZ
| D3DPMISCCAPS_LINEPATTERNREP
|
1329 D3DPMISCCAPS_CONFORMANT
| D3DPMISCCAPS_CULLNONE
| D3DPMISCCAPS_CULLCW
|
1330 D3DPMISCCAPS_CULLCCW
);
1332 caps
->dpcLineCaps
.dwRasterCaps
&= (
1333 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ROP2
| D3DPRASTERCAPS_XOR
|
1334 D3DPRASTERCAPS_PAT
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_SUBPIXEL
|
1335 D3DPRASTERCAPS_SUBPIXELX
| D3DPRASTERCAPS_FOGVERTEX
| D3DPRASTERCAPS_FOGTABLE
|
1336 D3DPRASTERCAPS_STIPPLE
| D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT
| D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT
|
1337 D3DPRASTERCAPS_ANTIALIASEDGES
| D3DPRASTERCAPS_MIPMAPLODBIAS
| D3DPRASTERCAPS_ZBIAS
|
1338 D3DPRASTERCAPS_ZBUFFERLESSHSR
| D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
|
1339 D3DPRASTERCAPS_WBUFFER
| D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT
| D3DPRASTERCAPS_WFOG
|
1340 D3DPRASTERCAPS_ZFOG
);
1342 caps
->dpcLineCaps
.dwZCmpCaps
&= (
1343 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
1344 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
1345 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
1347 caps
->dpcLineCaps
.dwSrcBlendCaps
&= (
1348 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
1349 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
1350 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
1351 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
1352 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
1354 caps
->dpcLineCaps
.dwDestBlendCaps
&= (
1355 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
1356 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
1357 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
1358 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
1359 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
1361 caps
->dpcLineCaps
.dwAlphaCmpCaps
&= (
1362 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
1363 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
1364 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
1366 caps
->dpcLineCaps
.dwShadeCaps
&= (
1367 D3DPSHADECAPS_COLORFLATMONO
| D3DPSHADECAPS_COLORFLATRGB
| D3DPSHADECAPS_COLORGOURAUDMONO
|
1368 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_COLORPHONGMONO
| D3DPSHADECAPS_COLORPHONGRGB
|
1369 D3DPSHADECAPS_SPECULARFLATMONO
| D3DPSHADECAPS_SPECULARFLATRGB
| D3DPSHADECAPS_SPECULARGOURAUDMONO
|
1370 D3DPSHADECAPS_SPECULARGOURAUDRGB
| D3DPSHADECAPS_SPECULARPHONGMONO
| D3DPSHADECAPS_SPECULARPHONGRGB
|
1371 D3DPSHADECAPS_ALPHAFLATBLEND
| D3DPSHADECAPS_ALPHAFLATSTIPPLED
| D3DPSHADECAPS_ALPHAGOURAUDBLEND
|
1372 D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED
| D3DPSHADECAPS_ALPHAPHONGBLEND
| D3DPSHADECAPS_ALPHAPHONGSTIPPLED
|
1373 D3DPSHADECAPS_FOGFLAT
| D3DPSHADECAPS_FOGGOURAUD
| D3DPSHADECAPS_FOGPHONG
);
1375 caps
->dpcLineCaps
.dwTextureCaps
&= (
1376 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
1377 D3DPTEXTURECAPS_TRANSPARENCY
| D3DPTEXTURECAPS_BORDER
| D3DPTEXTURECAPS_SQUAREONLY
|
1378 D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
| D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
1379 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_COLORKEYBLEND
);
1381 caps
->dpcLineCaps
.dwTextureFilterCaps
&= (
1382 D3DPTFILTERCAPS_NEAREST
| D3DPTFILTERCAPS_LINEAR
| D3DPTFILTERCAPS_MIPNEAREST
|
1383 D3DPTFILTERCAPS_MIPLINEAR
| D3DPTFILTERCAPS_LINEARMIPNEAREST
| D3DPTFILTERCAPS_LINEARMIPLINEAR
|
1384 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
1385 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
1386 D3DPTFILTERCAPS_MAGFLINEAR
| D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
|
1387 D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
);
1389 caps
->dpcLineCaps
.dwTextureAddressCaps
&= (
1390 D3DPTADDRESSCAPS_WRAP
| D3DPTADDRESSCAPS_MIRROR
| D3DPTADDRESSCAPS_CLAMP
|
1391 D3DPTADDRESSCAPS_BORDER
| D3DPTADDRESSCAPS_INDEPENDENTUV
);
1393 if (!(caps
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
))
1395 /* DirectX7 always has the np2 flag set, no matter what the card
1396 * supports. Some old games (Rollcage) check the caps incorrectly.
1397 * If wined3d supports nonpow2 textures it also has np2 conditional
1399 caps
->dpcLineCaps
.dwTextureCaps
|= D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
;
1402 /* Fill the missing members, and do some fixup */
1403 caps
->dpcLineCaps
.dwSize
= sizeof(caps
->dpcLineCaps
);
1404 caps
->dpcLineCaps
.dwTextureBlendCaps
= D3DPTBLENDCAPS_ADD
1405 | D3DPTBLENDCAPS_MODULATEMASK
1406 | D3DPTBLENDCAPS_COPY
1407 | D3DPTBLENDCAPS_DECAL
1408 | D3DPTBLENDCAPS_DECALALPHA
1409 | D3DPTBLENDCAPS_DECALMASK
1410 | D3DPTBLENDCAPS_MODULATE
1411 | D3DPTBLENDCAPS_MODULATEALPHA
;
1412 caps
->dpcLineCaps
.dwStippleWidth
= 32;
1413 caps
->dpcLineCaps
.dwStippleHeight
= 32;
1414 /* Use the same for the TriCaps */
1415 caps
->dpcTriCaps
= caps
->dpcLineCaps
;
1417 caps
->dwDeviceRenderBitDepth
= DDBD_16
| DDBD_24
| DDBD_32
;
1418 caps
->dwDeviceZBufferBitDepth
= DDBD_16
| DDBD_24
;
1419 caps
->dwMinTextureWidth
= 1;
1420 caps
->dwMinTextureHeight
= 1;
1422 /* Convert DWORDs safely to WORDs */
1423 caps
->wMaxTextureBlendStages
= min(wined3d_caps
.MaxTextureBlendStages
, 0xffff);
1424 caps
->wMaxSimultaneousTextures
= min(wined3d_caps
.MaxSimultaneousTextures
, 0xffff);
1425 caps
->wMaxUserClipPlanes
= min(wined3d_caps
.MaxUserClipPlanes
, D3DMAXUSERCLIPPLANES
);
1426 caps
->wMaxVertexBlendMatrices
= min(wined3d_caps
.MaxVertexBlendMatrices
, 0xffff);
1428 caps
->deviceGUID
= IID_IDirect3DTnLHalDevice
;
1430 caps
->dwReserved1
= 0;
1431 caps
->dwReserved2
= 0;
1432 caps
->dwReserved3
= 0;
1433 caps
->dwReserved4
= 0;
1438 /*****************************************************************************
1439 * IDirectDraw7::GetCaps
1441 * Returns the drives capabilities
1443 * Used for version 1, 2, 4 and 7
1446 * DriverCaps: Structure to write the Hardware accelerated caps to
1447 * HelCaps: Structure to write the emulation caps to
1450 * This implementation returns DD_OK only
1452 *****************************************************************************/
1453 static HRESULT WINAPI
ddraw7_GetCaps(IDirectDraw7
*iface
, DDCAPS
*DriverCaps
, DDCAPS
*HELCaps
)
1455 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1457 WINED3DCAPS winecaps
;
1459 DDSCAPS2 ddscaps
= {0, 0, 0, {0}};
1461 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, DriverCaps
, HELCaps
);
1463 /* One structure must be != NULL */
1464 if (!DriverCaps
&& !HELCaps
)
1466 WARN("Invalid parameters.\n");
1467 return DDERR_INVALIDPARAMS
;
1470 memset(&caps
, 0, sizeof(caps
));
1471 memset(&winecaps
, 0, sizeof(winecaps
));
1472 caps
.dwSize
= sizeof(caps
);
1474 wined3d_mutex_lock();
1475 hr
= wined3d_device_get_device_caps(ddraw
->wined3d_device
, &winecaps
);
1478 WARN("Failed to get device caps, %#x.\n", hr
);
1479 wined3d_mutex_unlock();
1483 hr
= IDirectDraw7_GetAvailableVidMem(iface
, &ddscaps
, &caps
.dwVidMemTotal
, &caps
.dwVidMemFree
);
1486 WARN("IDirectDraw7::GetAvailableVidMem failed\n");
1487 wined3d_mutex_unlock();
1491 hr
= IDirectDraw7_GetFourCCCodes(iface
, &caps
.dwNumFourCCCodes
, NULL
);
1492 wined3d_mutex_unlock();
1495 WARN("IDirectDraw7::GetFourCCCodes failed\n");
1499 caps
.dwCaps
= winecaps
.ddraw_caps
.caps
;
1500 caps
.dwCaps2
= winecaps
.ddraw_caps
.caps2
;
1501 caps
.dwCKeyCaps
= winecaps
.ddraw_caps
.color_key_caps
;
1502 caps
.dwFXCaps
= winecaps
.ddraw_caps
.fx_caps
;
1503 caps
.dwPalCaps
= DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
;
1504 caps
.ddsCaps
.dwCaps
= winecaps
.ddraw_caps
.dds_caps
;
1505 caps
.dwSVBCaps
= winecaps
.ddraw_caps
.svb_caps
;
1506 caps
.dwSVBCKeyCaps
= winecaps
.ddraw_caps
.svb_color_key_caps
;
1507 caps
.dwSVBFXCaps
= winecaps
.ddraw_caps
.svb_fx_caps
;
1508 caps
.dwVSBCaps
= winecaps
.ddraw_caps
.vsb_caps
;
1509 caps
.dwVSBCKeyCaps
= winecaps
.ddraw_caps
.vsb_color_key_caps
;
1510 caps
.dwVSBFXCaps
= winecaps
.ddraw_caps
.vsb_fx_caps
;
1511 caps
.dwSSBCaps
= winecaps
.ddraw_caps
.ssb_caps
;
1512 caps
.dwSSBCKeyCaps
= winecaps
.ddraw_caps
.ssb_color_key_caps
;
1513 caps
.dwSSBFXCaps
= winecaps
.ddraw_caps
.ssb_fx_caps
;
1515 caps
.dwCaps
|= DDCAPS_ALIGNSTRIDE
;
1516 caps
.dwAlignStrideAlign
= DDRAW_STRIDE_ALIGNMENT
;
1520 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &caps
);
1521 if (TRACE_ON(ddraw
))
1523 TRACE("Driver Caps :\n");
1524 DDRAW_dump_DDCAPS(DriverCaps
);
1530 DD_STRUCT_COPY_BYSIZE(HELCaps
, &caps
);
1531 if (TRACE_ON(ddraw
))
1533 TRACE("HEL Caps :\n");
1534 DDRAW_dump_DDCAPS(HELCaps
);
1541 static HRESULT WINAPI
ddraw4_GetCaps(IDirectDraw4
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1543 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1545 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1547 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1550 static HRESULT WINAPI
ddraw2_GetCaps(IDirectDraw2
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1552 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1554 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1556 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1559 static HRESULT WINAPI
ddraw1_GetCaps(IDirectDraw
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1561 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1563 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1565 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1568 /*****************************************************************************
1569 * IDirectDraw7::Compact
1571 * No idea what it does, MSDN says it's not implemented.
1574 * DD_OK, but this is unchecked
1576 *****************************************************************************/
1577 static HRESULT WINAPI
ddraw7_Compact(IDirectDraw7
*iface
)
1579 TRACE("iface %p.\n", iface
);
1584 static HRESULT WINAPI
ddraw4_Compact(IDirectDraw4
*iface
)
1586 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1588 TRACE("iface %p.\n", iface
);
1590 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1593 static HRESULT WINAPI
ddraw2_Compact(IDirectDraw2
*iface
)
1595 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1597 TRACE("iface %p.\n", iface
);
1599 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1602 static HRESULT WINAPI
ddraw1_Compact(IDirectDraw
*iface
)
1604 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1606 TRACE("iface %p.\n", iface
);
1608 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1611 /*****************************************************************************
1612 * IDirectDraw7::GetDisplayMode
1614 * Returns information about the current display mode
1616 * Exists in versions 1, 2, 4 and 7
1619 * DDSD: Address of a surface description structure to write the info to
1624 *****************************************************************************/
1625 static HRESULT WINAPI
ddraw7_GetDisplayMode(IDirectDraw7
*iface
, DDSURFACEDESC2
*DDSD
)
1627 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1628 struct wined3d_display_mode mode
;
1631 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
1633 /* This seems sane */
1634 if (!DDSD
|| (DDSD
->dwSize
!= sizeof(DDSURFACEDESC
) && DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
)))
1635 return DDERR_INVALIDPARAMS
;
1637 wined3d_mutex_lock();
1639 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1641 ERR("Failed to get display mode, hr %#x.\n", hr
);
1642 wined3d_mutex_unlock();
1646 memset(DDSD
, 0, DDSD
->dwSize
);
1647 DDSD
->dwSize
= sizeof(*DDSD
);
1648 DDSD
->dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
1649 DDSD
->dwWidth
= mode
.width
;
1650 DDSD
->dwHeight
= mode
.height
;
1651 DDSD
->u2
.dwRefreshRate
= 60;
1652 DDSD
->ddsCaps
.dwCaps
= 0;
1653 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
1654 ddrawformat_from_wined3dformat(&DDSD
->u4
.ddpfPixelFormat
, mode
.format_id
);
1655 DDSD
->u1
.lPitch
= mode
.width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
1659 TRACE("Returning surface desc :\n");
1660 DDRAW_dump_surface_desc(DDSD
);
1663 wined3d_mutex_unlock();
1668 static HRESULT WINAPI
ddraw4_GetDisplayMode(IDirectDraw4
*iface
, DDSURFACEDESC2
*surface_desc
)
1670 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1672 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1674 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, surface_desc
);
1677 static HRESULT WINAPI
ddraw2_GetDisplayMode(IDirectDraw2
*iface
, DDSURFACEDESC
*surface_desc
)
1679 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1682 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1684 hr
= ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1685 if (SUCCEEDED(hr
)) surface_desc
->dwSize
= sizeof(*surface_desc
);
1689 static HRESULT WINAPI
ddraw1_GetDisplayMode(IDirectDraw
*iface
, DDSURFACEDESC
*surface_desc
)
1691 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1694 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1696 hr
= ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1697 if (SUCCEEDED(hr
)) surface_desc
->dwSize
= sizeof(*surface_desc
);
1701 /*****************************************************************************
1702 * IDirectDraw7::GetFourCCCodes
1704 * Returns an array of supported FourCC codes.
1706 * Exists in versions 1, 2, 4 and 7
1709 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
1710 * of enumerated codes
1711 * Codes: Pointer to an array of DWORDs where the supported codes are written
1715 * Always returns DD_OK, as it's a stub for now
1717 *****************************************************************************/
1718 static HRESULT WINAPI
ddraw7_GetFourCCCodes(IDirectDraw7
*iface
, DWORD
*NumCodes
, DWORD
*Codes
)
1720 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1721 static const enum wined3d_format_id formats
[] =
1723 WINED3DFMT_YUY2
, WINED3DFMT_UYVY
, WINED3DFMT_YV12
,
1724 WINED3DFMT_DXT1
, WINED3DFMT_DXT2
, WINED3DFMT_DXT3
, WINED3DFMT_DXT4
, WINED3DFMT_DXT5
,
1725 WINED3DFMT_ATI2N
, WINED3DFMT_NVHU
, WINED3DFMT_NVHS
1727 struct wined3d_display_mode mode
;
1728 DWORD count
= 0, i
, outsize
;
1731 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, NumCodes
, Codes
);
1733 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1735 ERR("Failed to get display mode, hr %#x.\n", hr
);
1739 outsize
= NumCodes
&& Codes
? *NumCodes
: 0;
1741 for (i
= 0; i
< (sizeof(formats
) / sizeof(formats
[0])); ++i
)
1743 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, WINED3D_DEVICE_TYPE_HAL
,
1744 mode
.format_id
, 0, WINED3D_RTYPE_TEXTURE_2D
, formats
[i
])))
1746 if (count
< outsize
)
1747 Codes
[count
] = formats
[i
];
1752 TRACE("Returning %u FourCC codes\n", count
);
1759 static HRESULT WINAPI
ddraw4_GetFourCCCodes(IDirectDraw4
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1761 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1763 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1765 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1768 static HRESULT WINAPI
ddraw2_GetFourCCCodes(IDirectDraw2
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1770 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1772 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1774 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1777 static HRESULT WINAPI
ddraw1_GetFourCCCodes(IDirectDraw
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1779 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1781 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1783 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1786 static HRESULT WINAPI
ddraw7_GetMonitorFrequency(IDirectDraw7
*iface
, DWORD
*frequency
)
1788 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1789 struct wined3d_display_mode mode
;
1792 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1794 wined3d_mutex_lock();
1795 hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
);
1796 wined3d_mutex_unlock();
1799 WARN("Failed to get display mode, hr %#x.\n", hr
);
1803 *frequency
= mode
.refresh_rate
;
1808 static HRESULT WINAPI
ddraw4_GetMonitorFrequency(IDirectDraw4
*iface
, DWORD
*frequency
)
1810 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1812 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1814 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1817 static HRESULT WINAPI
ddraw2_GetMonitorFrequency(IDirectDraw2
*iface
, DWORD
*frequency
)
1819 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1821 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1823 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1826 static HRESULT WINAPI
ddraw1_GetMonitorFrequency(IDirectDraw
*iface
, DWORD
*frequency
)
1828 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1830 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1832 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1835 static HRESULT WINAPI
ddraw7_GetVerticalBlankStatus(IDirectDraw7
*iface
, BOOL
*status
)
1837 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1838 struct wined3d_raster_status raster_status
;
1841 TRACE("iface %p, status %p.\n", iface
, status
);
1844 return DDERR_INVALIDPARAMS
;
1846 wined3d_mutex_lock();
1847 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
1848 wined3d_mutex_unlock();
1851 WARN("Failed to get raster status, hr %#x.\n", hr
);
1855 *status
= raster_status
.in_vblank
;
1860 static HRESULT WINAPI
ddraw4_GetVerticalBlankStatus(IDirectDraw4
*iface
, BOOL
*status
)
1862 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1864 TRACE("iface %p, status %p.\n", iface
, status
);
1866 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1869 static HRESULT WINAPI
ddraw2_GetVerticalBlankStatus(IDirectDraw2
*iface
, BOOL
*status
)
1871 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1873 TRACE("iface %p, status %p.\n", iface
, status
);
1875 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1878 static HRESULT WINAPI
ddraw1_GetVerticalBlankStatus(IDirectDraw
*iface
, BOOL
*status
)
1880 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1882 TRACE("iface %p, status %p.\n", iface
, status
);
1884 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1887 /*****************************************************************************
1888 * IDirectDraw7::GetAvailableVidMem
1890 * Returns the total and free video memory
1893 * caps: Specifies the memory type asked for
1894 * total: Pointer to a DWORD to be filled with the total memory
1895 * free: Pointer to a DWORD to be filled with the free memory
1899 * DDERR_INVALIDPARAMS if free and total are NULL
1901 *****************************************************************************/
1902 static HRESULT WINAPI
ddraw7_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*caps
, DWORD
*total
,
1905 unsigned int framebuffer_size
, total_vidmem
, free_vidmem
;
1906 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1907 struct wined3d_display_mode mode
;
1910 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1912 if (!total
&& !free
)
1913 return DDERR_INVALIDPARAMS
;
1915 if (TRACE_ON(ddraw
))
1917 TRACE("Asked for memory with description: ");
1918 DDRAW_dump_DDSCAPS2(caps
);
1920 wined3d_mutex_lock();
1922 /* Todo: System memory vs local video memory vs non-local video memory
1923 * The MSDN also mentions differences between texture memory and other
1924 * resources, but that's not important
1927 /* Some applications (e.g. 3DMark 2000) assume that the reported amount of
1928 * video memory doesn't include the memory used by the default framebuffer.
1930 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1932 WARN("Failed to get display mode, hr %#x.\n", hr
);
1933 wined3d_mutex_unlock();
1936 framebuffer_size
= wined3d_calculate_format_pitch(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
1937 mode
.format_id
, mode
.width
);
1938 framebuffer_size
*= mode
.height
;
1942 free_vidmem
= wined3d_device_get_available_texture_mem(ddraw
->wined3d_device
);
1943 *free
= framebuffer_size
> free_vidmem
? 0 : free_vidmem
- framebuffer_size
;
1944 TRACE("Free video memory %#x.\n", *free
);
1949 struct wined3d_adapter_identifier desc
= {0};
1951 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0, &desc
);
1952 total_vidmem
= min(UINT_MAX
, desc
.video_memory
);
1953 *total
= framebuffer_size
> total_vidmem
? 0 : total_vidmem
- framebuffer_size
;
1954 TRACE("Total video memory %#x.\n", *total
);
1957 wined3d_mutex_unlock();
1962 static HRESULT WINAPI
ddraw4_GetAvailableVidMem(IDirectDraw4
*iface
,
1963 DDSCAPS2
*caps
, DWORD
*total
, DWORD
*free
)
1965 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1967 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1969 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, caps
, total
, free
);
1972 static HRESULT WINAPI
ddraw2_GetAvailableVidMem(IDirectDraw2
*iface
,
1973 DDSCAPS
*caps
, DWORD
*total
, DWORD
*free
)
1975 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1978 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1980 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
1981 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, &caps2
, total
, free
);
1984 /*****************************************************************************
1985 * IDirectDraw7::Initialize
1987 * Initializes a DirectDraw interface.
1990 * GUID: Interface identifier. Well, don't know what this is really good
1994 * Returns DD_OK on the first call,
1995 * DDERR_ALREADYINITIALIZED on repeated calls
1997 *****************************************************************************/
1998 static HRESULT WINAPI
ddraw7_Initialize(IDirectDraw7
*iface
, GUID
*guid
)
2000 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2002 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2004 if (ddraw
->flags
& DDRAW_INITIALIZED
)
2005 return DDERR_ALREADYINITIALIZED
;
2007 /* FIXME: To properly take the GUID into account we should call
2008 * ddraw_init() here instead of in DDRAW_Create(). */
2010 FIXME("Ignoring guid %s.\n", debugstr_guid(guid
));
2012 ddraw
->flags
|= DDRAW_INITIALIZED
;
2016 static HRESULT WINAPI
ddraw4_Initialize(IDirectDraw4
*iface
, GUID
*guid
)
2018 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2020 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2022 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2025 static HRESULT WINAPI
ddraw2_Initialize(IDirectDraw2
*iface
, GUID
*guid
)
2027 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2029 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2031 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2034 static HRESULT WINAPI
ddraw1_Initialize(IDirectDraw
*iface
, GUID
*guid
)
2036 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2038 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2040 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2043 static HRESULT WINAPI
d3d1_Initialize(IDirect3D
*iface
, REFIID riid
)
2045 TRACE("iface %p, riid %s.\n", iface
, debugstr_guid(riid
));
2047 return DDERR_ALREADYINITIALIZED
;
2050 /*****************************************************************************
2051 * IDirectDraw7::FlipToGDISurface
2053 * "Makes the surface that the GDI writes to the primary surface"
2054 * Looks like some windows specific thing we don't have to care about.
2055 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
2056 * show error boxes ;)
2057 * Well, just return DD_OK.
2060 * Always returns DD_OK
2062 *****************************************************************************/
2063 static HRESULT WINAPI
ddraw7_FlipToGDISurface(IDirectDraw7
*iface
)
2065 FIXME("iface %p stub!\n", iface
);
2070 static HRESULT WINAPI
ddraw4_FlipToGDISurface(IDirectDraw4
*iface
)
2072 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2074 TRACE("iface %p.\n", iface
);
2076 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2079 static HRESULT WINAPI
ddraw2_FlipToGDISurface(IDirectDraw2
*iface
)
2081 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2083 TRACE("iface %p.\n", iface
);
2085 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2088 static HRESULT WINAPI
ddraw1_FlipToGDISurface(IDirectDraw
*iface
)
2090 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2092 TRACE("iface %p.\n", iface
);
2094 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2097 /*****************************************************************************
2098 * IDirectDraw7::WaitForVerticalBlank
2100 * This method allows applications to get in sync with the vertical blank
2102 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
2103 * redraw the screen, most likely because of this stub
2106 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
2107 * or DDWAITVB_BLOCKEND
2108 * h: Not used, according to MSDN
2111 * Always returns DD_OK
2113 *****************************************************************************/
2114 static HRESULT WINAPI
ddraw7_WaitForVerticalBlank(IDirectDraw7
*iface
, DWORD Flags
, HANDLE event
)
2118 TRACE("iface %p, flags %#x, event %p.\n", iface
, Flags
, event
);
2120 /* This function is called often, so print the fixme only once */
2123 FIXME("iface %p, flags %#x, event %p stub!\n", iface
, Flags
, event
);
2127 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
2128 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
2129 return DDERR_UNSUPPORTED
; /* unchecked */
2134 static HRESULT WINAPI
ddraw4_WaitForVerticalBlank(IDirectDraw4
*iface
, DWORD flags
, HANDLE event
)
2136 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2138 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2140 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2143 static HRESULT WINAPI
ddraw2_WaitForVerticalBlank(IDirectDraw2
*iface
, DWORD flags
, HANDLE event
)
2145 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2147 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2149 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2152 static HRESULT WINAPI
ddraw1_WaitForVerticalBlank(IDirectDraw
*iface
, DWORD flags
, HANDLE event
)
2154 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2156 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2158 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2161 static HRESULT WINAPI
ddraw7_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
2163 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2164 struct wined3d_raster_status raster_status
;
2167 TRACE("iface %p, line %p.\n", iface
, Scanline
);
2169 wined3d_mutex_lock();
2170 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
2171 wined3d_mutex_unlock();
2174 WARN("Failed to get raster status, hr %#x.\n", hr
);
2178 *Scanline
= raster_status
.scan_line
;
2180 if (raster_status
.in_vblank
)
2181 return DDERR_VERTICALBLANKINPROGRESS
;
2186 static HRESULT WINAPI
ddraw4_GetScanLine(IDirectDraw4
*iface
, DWORD
*line
)
2188 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2190 TRACE("iface %p, line %p.\n", iface
, line
);
2192 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2195 static HRESULT WINAPI
ddraw2_GetScanLine(IDirectDraw2
*iface
, DWORD
*line
)
2197 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2199 TRACE("iface %p, line %p.\n", iface
, line
);
2201 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2204 static HRESULT WINAPI
ddraw1_GetScanLine(IDirectDraw
*iface
, DWORD
*line
)
2206 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2208 TRACE("iface %p, line %p.\n", iface
, line
);
2210 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2213 static HRESULT WINAPI
ddraw7_TestCooperativeLevel(IDirectDraw7
*iface
)
2215 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2217 TRACE("iface %p.\n", iface
);
2219 return ddraw
->device_state
== DDRAW_DEVICE_STATE_LOST
? DDERR_NOEXCLUSIVEMODE
: DD_OK
;
2222 static HRESULT WINAPI
ddraw4_TestCooperativeLevel(IDirectDraw4
*iface
)
2224 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2226 TRACE("iface %p.\n", iface
);
2228 return ddraw7_TestCooperativeLevel(&ddraw
->IDirectDraw7_iface
);
2231 /*****************************************************************************
2232 * IDirectDraw7::GetGDISurface
2234 * Returns the surface that GDI is treating as the primary surface.
2235 * For Wine this is the front buffer
2238 * GDISurface: Address to write the surface pointer to
2241 * DD_OK if the surface was found
2242 * DDERR_NOTFOUND if the GDI surface wasn't found
2244 *****************************************************************************/
2245 static HRESULT WINAPI
ddraw7_GetGDISurface(IDirectDraw7
*iface
, IDirectDrawSurface7
**GDISurface
)
2247 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2249 TRACE("iface %p, surface %p.\n", iface
, GDISurface
);
2251 wined3d_mutex_lock();
2253 if (!(*GDISurface
= &ddraw
->primary
->IDirectDrawSurface7_iface
))
2255 WARN("Primary not created yet.\n");
2256 wined3d_mutex_unlock();
2257 return DDERR_NOTFOUND
;
2259 IDirectDrawSurface7_AddRef(*GDISurface
);
2261 wined3d_mutex_unlock();
2266 static HRESULT WINAPI
ddraw4_GetGDISurface(IDirectDraw4
*iface
, IDirectDrawSurface4
**surface
)
2268 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2269 struct ddraw_surface
*surface_impl
;
2270 IDirectDrawSurface7
*surface7
;
2273 TRACE("iface %p, surface %p.\n", iface
, surface
);
2275 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2281 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2282 *surface
= &surface_impl
->IDirectDrawSurface4_iface
;
2283 IDirectDrawSurface4_AddRef(*surface
);
2284 IDirectDrawSurface7_Release(surface7
);
2289 static HRESULT WINAPI
ddraw2_GetGDISurface(IDirectDraw2
*iface
, IDirectDrawSurface
**surface
)
2291 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2292 struct ddraw_surface
*surface_impl
;
2293 IDirectDrawSurface7
*surface7
;
2296 TRACE("iface %p, surface %p.\n", iface
, surface
);
2298 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2304 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2305 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2306 IDirectDrawSurface_AddRef(*surface
);
2307 IDirectDrawSurface7_Release(surface7
);
2312 static HRESULT WINAPI
ddraw1_GetGDISurface(IDirectDraw
*iface
, IDirectDrawSurface
**surface
)
2314 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2315 struct ddraw_surface
*surface_impl
;
2316 IDirectDrawSurface7
*surface7
;
2319 TRACE("iface %p, surface %p.\n", iface
, surface
);
2321 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2327 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2328 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2329 IDirectDrawSurface_AddRef(*surface
);
2330 IDirectDrawSurface7_Release(surface7
);
2335 struct displaymodescallback_context
2337 LPDDENUMMODESCALLBACK func
;
2341 static HRESULT CALLBACK
EnumDisplayModesCallbackThunk(DDSURFACEDESC2
*surface_desc
, void *context
)
2343 struct displaymodescallback_context
*cbcontext
= context
;
2346 DDSD2_to_DDSD(surface_desc
, &desc
);
2347 return cbcontext
->func(&desc
, cbcontext
->context
);
2350 /*****************************************************************************
2351 * IDirectDraw7::EnumDisplayModes
2353 * Enumerates the supported Display modes. The modes can be filtered with
2354 * the DDSD parameter.
2357 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES. For old ddraw
2358 * versions (3 and older?) this is reserved and must be 0.
2359 * DDSD: Surface description to filter the modes
2360 * Context: Pointer passed back to the callback function
2361 * cb: Application-provided callback function
2365 * DDERR_INVALIDPARAMS if the callback wasn't set
2367 *****************************************************************************/
2368 static HRESULT WINAPI
ddraw7_EnumDisplayModes(IDirectDraw7
*iface
, DWORD Flags
,
2369 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMMODESCALLBACK2 cb
)
2371 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2372 struct wined3d_display_mode
*enum_modes
= NULL
;
2373 struct wined3d_display_mode mode
;
2374 unsigned int modenum
, fmt
;
2375 DDSURFACEDESC2 callback_sd
;
2376 unsigned enum_mode_count
= 0, enum_mode_array_size
= 16;
2377 DDPIXELFORMAT pixelformat
;
2379 static const enum wined3d_format_id checkFormatList
[] =
2381 WINED3DFMT_B8G8R8X8_UNORM
,
2382 WINED3DFMT_B5G6R5_UNORM
,
2386 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2387 iface
, Flags
, DDSD
, Context
, cb
);
2390 return DDERR_INVALIDPARAMS
;
2392 enum_modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(*enum_modes
) * enum_mode_array_size
);
2393 if (!enum_modes
) return DDERR_OUTOFMEMORY
;
2395 wined3d_mutex_lock();
2397 pixelformat
.dwSize
= sizeof(pixelformat
);
2398 for(fmt
= 0; fmt
< (sizeof(checkFormatList
) / sizeof(checkFormatList
[0])); fmt
++)
2401 while (wined3d_enum_adapter_modes(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, checkFormatList
[fmt
],
2402 WINED3D_SCANLINE_ORDERING_UNKNOWN
, modenum
++, &mode
) == WINED3D_OK
)
2407 ddrawformat_from_wined3dformat(&pixelformat
, mode
.format_id
);
2410 if (DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.width
!= DDSD
->dwWidth
)
2412 if (DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.height
!= DDSD
->dwHeight
)
2414 if (DDSD
->dwFlags
& DDSD_REFRESHRATE
&& mode
.refresh_rate
!= DDSD
->u2
.dwRefreshRate
)
2416 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
2417 && pixelformat
.u1
.dwRGBBitCount
!= DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
)
2421 /* DX docs state EnumDisplayMode should return only unique modes */
2422 for (i
= 0; i
< enum_mode_count
; i
++)
2424 if (enum_modes
[i
].width
== mode
.width
&& enum_modes
[i
].height
== mode
.height
2425 && enum_modes
[i
].format_id
== mode
.format_id
2426 && (enum_modes
[i
].refresh_rate
== mode
.refresh_rate
|| !(Flags
& DDEDM_REFRESHRATES
)))
2434 memset(&callback_sd
, 0, sizeof(callback_sd
));
2435 callback_sd
.dwSize
= sizeof(callback_sd
);
2436 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2438 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
|DDSD_REFRESHRATE
;
2439 if (Flags
& DDEDM_REFRESHRATES
)
2440 callback_sd
.u2
.dwRefreshRate
= mode
.refresh_rate
;
2442 callback_sd
.dwWidth
= mode
.width
;
2443 callback_sd
.dwHeight
= mode
.height
;
2445 callback_sd
.u4
.ddpfPixelFormat
=pixelformat
;
2447 /* Calc pitch and DWORD align like MSDN says */
2448 callback_sd
.u1
.lPitch
= (callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8) * mode
.width
;
2449 callback_sd
.u1
.lPitch
= (callback_sd
.u1
.lPitch
+ 3) & ~3;
2451 TRACE("Enumerating %dx%dx%d @%d\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
,
2452 callback_sd
.u2
.dwRefreshRate
);
2454 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
2456 TRACE("Application asked to terminate the enumeration\n");
2457 HeapFree(GetProcessHeap(), 0, enum_modes
);
2458 wined3d_mutex_unlock();
2462 if (enum_mode_count
== enum_mode_array_size
)
2464 struct wined3d_display_mode
*new_enum_modes
;
2466 enum_mode_array_size
*= 2;
2467 new_enum_modes
= HeapReAlloc(GetProcessHeap(), 0, enum_modes
,
2468 sizeof(*new_enum_modes
) * enum_mode_array_size
);
2469 if (!new_enum_modes
)
2471 HeapFree(GetProcessHeap(), 0, enum_modes
);
2472 wined3d_mutex_unlock();
2473 return DDERR_OUTOFMEMORY
;
2476 enum_modes
= new_enum_modes
;
2478 enum_modes
[enum_mode_count
++] = mode
;
2482 TRACE("End of enumeration\n");
2483 HeapFree(GetProcessHeap(), 0, enum_modes
);
2484 wined3d_mutex_unlock();
2489 static HRESULT WINAPI
ddraw4_EnumDisplayModes(IDirectDraw4
*iface
, DWORD flags
,
2490 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK2 callback
)
2492 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2494 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2495 iface
, flags
, surface_desc
, context
, callback
);
2497 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
, context
, callback
);
2500 static HRESULT WINAPI
ddraw2_EnumDisplayModes(IDirectDraw2
*iface
, DWORD flags
,
2501 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2503 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2504 struct displaymodescallback_context cbcontext
;
2505 DDSURFACEDESC2 surface_desc2
;
2507 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2508 iface
, flags
, surface_desc
, context
, callback
);
2510 cbcontext
.func
= callback
;
2511 cbcontext
.context
= context
;
2513 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2514 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2515 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2518 static HRESULT WINAPI
ddraw1_EnumDisplayModes(IDirectDraw
*iface
, DWORD flags
,
2519 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2521 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2522 struct displaymodescallback_context cbcontext
;
2523 DDSURFACEDESC2 surface_desc2
;
2525 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2526 iface
, flags
, surface_desc
, context
, callback
);
2528 cbcontext
.func
= callback
;
2529 cbcontext
.context
= context
;
2531 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2532 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2533 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2536 /*****************************************************************************
2537 * IDirectDraw7::EvaluateMode
2539 * Used with IDirectDraw7::StartModeTest to test video modes.
2540 * EvaluateMode is used to pass or fail a mode, and continue with the next
2544 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
2545 * Timeout: Returns the amount of seconds left before the mode would have
2546 * been failed automatically
2549 * This implementation always DD_OK, because it's a stub
2551 *****************************************************************************/
2552 static HRESULT WINAPI
ddraw7_EvaluateMode(IDirectDraw7
*iface
, DWORD Flags
, DWORD
*Timeout
)
2554 FIXME("iface %p, flags %#x, timeout %p stub!\n", iface
, Flags
, Timeout
);
2556 /* When implementing this, implement it in WineD3D */
2561 /*****************************************************************************
2562 * IDirectDraw7::GetDeviceIdentifier
2564 * Returns the device identifier, which gives information about the driver
2565 * Our device identifier is defined at the beginning of this file.
2568 * DDDI: Address for the returned structure
2569 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
2572 * On success it returns DD_OK
2573 * DDERR_INVALIDPARAMS if DDDI is NULL
2575 *****************************************************************************/
2576 static HRESULT WINAPI
ddraw7_GetDeviceIdentifier(IDirectDraw7
*iface
,
2577 DDDEVICEIDENTIFIER2
*DDDI
, DWORD Flags
)
2579 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2580 struct wined3d_adapter_identifier adapter_id
;
2583 TRACE("iface %p, device_identifier %p, flags %#x.\n", iface
, DDDI
, Flags
);
2586 return DDERR_INVALIDPARAMS
;
2588 if (Flags
& DDGDI_GETHOSTIDENTIFIER
)
2590 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
2591 * host adapter, if there's a secondary 3D adapter. This doesn't apply
2592 * to any modern hardware, nor is it interesting for Wine, so ignore it.
2593 * Size of DDDEVICEIDENTIFIER2 may be aligned to 8 bytes and thus 4
2594 * bytes too long. So only copy the relevant part of the structure
2597 memcpy(DDDI
, &deviceidentifier
, FIELD_OFFSET(DDDEVICEIDENTIFIER2
, dwWHQLLevel
) + sizeof(DWORD
));
2601 /* Drakan: Order of the Flame expects accurate D3D device information from ddraw */
2602 adapter_id
.driver
= DDDI
->szDriver
;
2603 adapter_id
.driver_size
= sizeof(DDDI
->szDriver
);
2604 adapter_id
.description
= DDDI
->szDescription
;
2605 adapter_id
.description_size
= sizeof(DDDI
->szDescription
);
2606 adapter_id
.device_name_size
= 0;
2607 wined3d_mutex_lock();
2608 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0x0, &adapter_id
);
2609 wined3d_mutex_unlock();
2610 if (FAILED(hr
)) return hr
;
2612 DDDI
->liDriverVersion
= adapter_id
.driver_version
;
2613 DDDI
->dwVendorId
= adapter_id
.vendor_id
;
2614 DDDI
->dwDeviceId
= adapter_id
.device_id
;
2615 DDDI
->dwSubSysId
= adapter_id
.subsystem_id
;
2616 DDDI
->dwRevision
= adapter_id
.revision
;
2617 DDDI
->guidDeviceIdentifier
= adapter_id
.device_identifier
;
2618 DDDI
->dwWHQLLevel
= adapter_id
.whql_level
;
2622 static HRESULT WINAPI
ddraw4_GetDeviceIdentifier(IDirectDraw4
*iface
,
2623 DDDEVICEIDENTIFIER
*identifier
, DWORD flags
)
2625 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2626 DDDEVICEIDENTIFIER2 identifier2
;
2629 TRACE("iface %p, identifier %p, flags %#x.\n", iface
, identifier
, flags
);
2631 hr
= ddraw7_GetDeviceIdentifier(&ddraw
->IDirectDraw7_iface
, &identifier2
, flags
);
2632 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&identifier2
, identifier
);
2637 /*****************************************************************************
2638 * IDirectDraw7::GetSurfaceFromDC
2640 * Returns the Surface for a GDI device context handle.
2641 * Is this related to IDirectDrawSurface::GetDC ???
2644 * hdc: hdc to return the surface for
2645 * Surface: Address to write the surface pointer to
2648 * Always returns DD_OK because it's a stub
2650 *****************************************************************************/
2651 static HRESULT WINAPI
ddraw7_GetSurfaceFromDC(IDirectDraw7
*iface
,
2652 HDC dc
, IDirectDrawSurface7
**surface
)
2654 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2655 struct ddraw_surface
*surface_impl
;
2657 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2660 return E_INVALIDARG
;
2665 wined3d_mutex_lock();
2666 LIST_FOR_EACH_ENTRY(surface_impl
, &ddraw
->surface_list
, struct ddraw_surface
, surface_list_entry
)
2668 if (surface_impl
->dc
!= dc
)
2671 TRACE("Found surface %p for dc %p.\n", surface_impl
, dc
);
2672 *surface
= &surface_impl
->IDirectDrawSurface7_iface
;
2673 IDirectDrawSurface7_AddRef(*surface
);
2674 wined3d_mutex_unlock();
2677 wined3d_mutex_unlock();
2680 TRACE("No surface found for dc %p.\n", dc
);
2682 return DDERR_NOTFOUND
;
2685 static HRESULT WINAPI
ddraw4_GetSurfaceFromDC(IDirectDraw4
*iface
, HDC dc
,
2686 IDirectDrawSurface4
**surface
)
2688 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2689 struct ddraw_surface
*surface_impl
;
2690 IDirectDrawSurface7
*surface7
;
2693 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2695 if (!surface
) return E_INVALIDARG
;
2697 hr
= ddraw7_GetSurfaceFromDC(&ddraw
->IDirectDraw7_iface
, dc
, &surface7
);
2703 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2704 /* Tests say this is true */
2705 *surface
= (IDirectDrawSurface4
*)&surface_impl
->IDirectDrawSurface_iface
;
2706 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2707 IDirectDrawSurface7_Release(surface7
);
2712 static HRESULT CALLBACK
restore_callback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
2714 IDirectDrawSurface_Restore(surface
);
2715 IDirectDrawSurface_Release(surface
);
2717 return DDENUMRET_OK
;
2720 static HRESULT WINAPI
ddraw7_RestoreAllSurfaces(IDirectDraw7
*iface
)
2722 TRACE("iface %p.\n", iface
);
2724 return IDirectDraw7_EnumSurfaces(iface
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
2725 NULL
, NULL
, restore_callback
);
2728 static HRESULT WINAPI
ddraw4_RestoreAllSurfaces(IDirectDraw4
*iface
)
2730 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2732 TRACE("iface %p.\n", iface
);
2734 return ddraw7_RestoreAllSurfaces(&ddraw
->IDirectDraw7_iface
);
2737 /*****************************************************************************
2738 * IDirectDraw7::StartModeTest
2740 * Tests the specified video modes to update the system registry with
2741 * refresh rate information. StartModeTest starts the mode test,
2742 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
2743 * isn't called within 15 seconds, the mode is failed automatically
2745 * As refresh rates are handled by the X server, I don't think this
2746 * Method is important
2749 * Modes: An array of mode specifications
2750 * NumModes: The number of modes in Modes
2751 * Flags: Some flags...
2754 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
2755 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
2758 *****************************************************************************/
2759 static HRESULT WINAPI
ddraw7_StartModeTest(IDirectDraw7
*iface
, SIZE
*Modes
, DWORD NumModes
, DWORD Flags
)
2761 FIXME("iface %p, modes %p, mode_count %u, flags %#x partial stub!\n",
2762 iface
, Modes
, NumModes
, Flags
);
2764 /* This looks sane */
2765 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
2767 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
2768 * As it is not, DDERR_TESTFINISHED is returned
2769 * (hopefully that's correct
2771 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
2772 * well, that value doesn't (yet) exist in the wine headers, so ignore it
2778 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
, DDSURFACEDESC2
*surface_desc
,
2779 IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
2781 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2782 struct ddraw_surface
*impl
;
2785 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2786 iface
, surface_desc
, surface
, outer_unknown
);
2788 wined3d_mutex_lock();
2790 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2792 WARN("Cooperative level not set.\n");
2793 wined3d_mutex_unlock();
2794 return DDERR_NOCOOPERATIVELEVELSET
;
2797 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2799 WARN("Application supplied invalid surface descriptor\n");
2800 wined3d_mutex_unlock();
2801 return DDERR_INVALIDPARAMS
;
2810 WARN("Surface pointer %p is invalid.\n", surface
);
2811 wined3d_mutex_unlock();
2812 return DDERR_INVALIDPARAMS
;
2816 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2818 if (TRACE_ON(ddraw
))
2820 TRACE(" (%p) Requesting surface desc :\n", iface
);
2821 DDRAW_dump_surface_desc(surface_desc
);
2824 WARN("Application tried to create an explicit front or back buffer\n");
2825 wined3d_mutex_unlock();
2826 return DDERR_INVALIDCAPS
;
2829 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 7);
2830 wined3d_mutex_unlock();
2834 *surface
= &impl
->IDirectDrawSurface7_iface
;
2835 IDirectDraw7_AddRef(iface
);
2836 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2841 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
2842 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
2844 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2845 struct ddraw_surface
*impl
;
2848 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2849 iface
, surface_desc
, surface
, outer_unknown
);
2851 wined3d_mutex_lock();
2853 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2855 WARN("Cooperative level not set.\n");
2856 wined3d_mutex_unlock();
2857 return DDERR_NOCOOPERATIVELEVELSET
;
2860 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2862 WARN("Application supplied invalid surface descriptor\n");
2863 wined3d_mutex_unlock();
2864 return DDERR_INVALIDPARAMS
;
2873 WARN("Surface pointer %p is invalid.\n", surface
);
2874 wined3d_mutex_unlock();
2875 return DDERR_INVALIDPARAMS
;
2879 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2881 if (TRACE_ON(ddraw
))
2883 TRACE(" (%p) Requesting surface desc :\n", iface
);
2884 DDRAW_dump_surface_desc(surface_desc
);
2887 WARN("Application tried to create an explicit front or back buffer\n");
2888 wined3d_mutex_unlock();
2889 return DDERR_INVALIDCAPS
;
2892 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 4);
2893 wined3d_mutex_unlock();
2897 *surface
= &impl
->IDirectDrawSurface4_iface
;
2898 IDirectDraw4_AddRef(iface
);
2899 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2904 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
2905 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2907 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2908 struct ddraw_surface
*impl
;
2910 DDSURFACEDESC2 surface_desc2
;
2912 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2913 iface
, surface_desc
, surface
, outer_unknown
);
2915 wined3d_mutex_lock();
2917 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2919 WARN("Cooperative level not set.\n");
2920 wined3d_mutex_unlock();
2921 return DDERR_NOCOOPERATIVELEVELSET
;
2924 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2926 WARN("Application supplied invalid surface descriptor\n");
2927 wined3d_mutex_unlock();
2928 return DDERR_INVALIDPARAMS
;
2937 WARN("Surface pointer %p is invalid.\n", surface
);
2938 wined3d_mutex_unlock();
2939 return DDERR_INVALIDPARAMS
;
2943 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2944 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2946 if (TRACE_ON(ddraw
))
2948 TRACE(" (%p) Requesting surface desc :\n", iface
);
2949 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
2952 WARN("Application tried to create an explicit front or back buffer\n");
2953 wined3d_mutex_unlock();
2954 return DDERR_INVALIDCAPS
;
2957 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 2);
2958 wined3d_mutex_unlock();
2962 *surface
= &impl
->IDirectDrawSurface_iface
;
2963 impl
->ifaceToRelease
= NULL
;
2968 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
2969 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2971 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2972 struct ddraw_surface
*impl
;
2974 DDSURFACEDESC2 surface_desc2
;
2976 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2977 iface
, surface_desc
, surface
, outer_unknown
);
2979 wined3d_mutex_lock();
2981 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2983 WARN("Cooperative level not set.\n");
2984 wined3d_mutex_unlock();
2985 return DDERR_NOCOOPERATIVELEVELSET
;
2988 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2990 WARN("Application supplied invalid surface descriptor\n");
2991 wined3d_mutex_unlock();
2992 return DDERR_INVALIDPARAMS
;
3001 WARN("Surface pointer %p is invalid.\n", surface
);
3002 wined3d_mutex_unlock();
3003 return DDERR_INVALIDPARAMS
;
3007 if ((surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
))
3008 == (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
)
3009 || (surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
))
3010 == ((DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
)))
3012 WARN("Application tried to create an explicit front or back buffer.\n");
3013 wined3d_mutex_unlock();
3014 return DDERR_INVALIDCAPS
;
3017 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3018 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 1);
3019 wined3d_mutex_unlock();
3023 *surface
= &impl
->IDirectDrawSurface_iface
;
3024 impl
->ifaceToRelease
= NULL
;
3030 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
3031 const DDPIXELFORMAT
*provided
)
3033 /* Some flags must be present in both or neither for a match. */
3034 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
3035 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
3036 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
3038 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3041 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
3044 if (requested
->dwFlags
& DDPF_FOURCC
)
3045 if (requested
->dwFourCC
!= provided
->dwFourCC
)
3048 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
3049 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3050 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
3053 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3054 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3055 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
3058 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
3059 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
3062 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
3063 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3065 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
3068 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
3069 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
3075 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3084 #define CMP(FLAG, FIELD) \
3085 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3086 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3088 static const struct compare_info compare
[] =
3090 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3091 CMP(BACKBUFFERCOUNT
, u5
.dwBackBufferCount
),
3093 CMP(CKDESTBLT
, ddckCKDestBlt
),
3094 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3095 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3096 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3097 CMP(HEIGHT
, dwHeight
),
3098 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3099 CMP(LPSURFACE
, lpSurface
),
3100 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3101 CMP(PITCH
, u1
/* lPitch */),
3102 /* PIXELFORMAT: manual */
3103 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3104 CMP(TEXTURESTAGE
, dwTextureStage
),
3105 CMP(WIDTH
, dwWidth
),
3106 /* ZBUFFERBITDEPTH: "obsolete" */
3113 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3116 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
3118 if (requested
->dwFlags
& compare
[i
].flag
3119 && memcmp((const char *)provided
+ compare
[i
].offset
,
3120 (const char *)requested
+ compare
[i
].offset
,
3121 compare
[i
].size
) != 0)
3125 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3127 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3128 &provided
->u4
.ddpfPixelFormat
))
3135 struct surfacescallback2_context
3137 LPDDENUMSURFACESCALLBACK2 func
;
3141 struct surfacescallback_context
3143 LPDDENUMSURFACESCALLBACK func
;
3147 static HRESULT CALLBACK
EnumSurfacesCallback2Thunk(IDirectDrawSurface7
*surface
,
3148 DDSURFACEDESC2
*surface_desc
, void *context
)
3150 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3151 struct surfacescallback2_context
*cbcontext
= context
;
3153 IDirectDrawSurface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
3154 IDirectDrawSurface7_Release(surface
);
3156 return cbcontext
->func(&surface_impl
->IDirectDrawSurface4_iface
,
3157 surface_desc
, cbcontext
->context
);
3160 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3161 DDSURFACEDESC2
*surface_desc
, void *context
)
3163 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3164 struct surfacescallback_context
*cbcontext
= context
;
3166 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
3167 IDirectDrawSurface7_Release(surface
);
3169 return cbcontext
->func(&surface_impl
->IDirectDrawSurface_iface
,
3170 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3173 /*****************************************************************************
3174 * IDirectDraw7::EnumSurfaces
3176 * Loops through all surfaces attached to this device and calls the
3177 * application callback. This can't be relayed to WineD3DDevice,
3178 * because some WineD3DSurfaces' parents are IParent objects
3181 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3182 * DDSD: Description to filter for
3183 * Context: Application-provided pointer, it's passed unmodified to the
3185 * Callback: Address to call for each surface
3188 * DDERR_INVALIDPARAMS if the callback is NULL
3191 *****************************************************************************/
3192 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD Flags
,
3193 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMSURFACESCALLBACK7 Callback
)
3195 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3196 struct ddraw_surface
*surf
;
3198 DDSURFACEDESC2 desc
;
3199 struct list
*entry
, *entry2
;
3201 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3202 iface
, Flags
, DDSD
, Context
, Callback
);
3204 all
= Flags
& DDENUMSURFACES_ALL
;
3205 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
3208 return DDERR_INVALIDPARAMS
;
3210 wined3d_mutex_lock();
3212 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
3213 LIST_FOR_EACH_SAFE(entry
, entry2
, &ddraw
->surface_list
)
3215 surf
= LIST_ENTRY(entry
, struct ddraw_surface
, surface_list_entry
);
3217 if (!surf
->iface_count
)
3219 WARN("Not enumerating surface %p because it doesn't have any references.\n", surf
);
3223 if (all
|| (nomatch
!= ddraw_match_surface_desc(DDSD
, &surf
->surface_desc
)))
3225 TRACE("Enumerating surface %p.\n", surf
);
3226 desc
= surf
->surface_desc
;
3227 IDirectDrawSurface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
3228 if (Callback(&surf
->IDirectDrawSurface7_iface
, &desc
, Context
) != DDENUMRET_OK
)
3230 wined3d_mutex_unlock();
3236 wined3d_mutex_unlock();
3241 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3242 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3244 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3245 struct surfacescallback2_context cbcontext
;
3247 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3248 iface
, flags
, surface_desc
, context
, callback
);
3250 cbcontext
.func
= callback
;
3251 cbcontext
.context
= context
;
3253 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
,
3254 &cbcontext
, EnumSurfacesCallback2Thunk
);
3257 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3258 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3260 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3261 struct surfacescallback_context cbcontext
;
3262 DDSURFACEDESC2 surface_desc2
;
3264 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3265 iface
, flags
, surface_desc
, context
, callback
);
3267 cbcontext
.func
= callback
;
3268 cbcontext
.context
= context
;
3270 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3271 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3272 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3275 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3276 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3278 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3279 struct surfacescallback_context cbcontext
;
3280 DDSURFACEDESC2 surface_desc2
;
3282 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3283 iface
, flags
, surface_desc
, context
, callback
);
3285 cbcontext
.func
= callback
;
3286 cbcontext
.context
= context
;
3288 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3289 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3290 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3293 /*****************************************************************************
3294 * DirectDrawCreateClipper (DDRAW.@)
3296 * Creates a new IDirectDrawClipper object.
3299 * Clipper: Address to write the interface pointer to
3300 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3304 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3305 * E_OUTOFMEMORY if allocating the object failed
3307 *****************************************************************************/
3308 HRESULT WINAPI
DirectDrawCreateClipper(DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3310 struct ddraw_clipper
*object
;
3313 TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
3314 flags
, clipper
, outer_unknown
);
3317 return CLASS_E_NOAGGREGATION
;
3319 wined3d_mutex_lock();
3321 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3324 wined3d_mutex_unlock();
3325 return E_OUTOFMEMORY
;
3328 hr
= ddraw_clipper_init(object
);
3331 WARN("Failed to initialize clipper, hr %#x.\n", hr
);
3332 HeapFree(GetProcessHeap(), 0, object
);
3333 wined3d_mutex_unlock();
3337 TRACE("Created clipper %p.\n", object
);
3338 *clipper
= &object
->IDirectDrawClipper_iface
;
3339 wined3d_mutex_unlock();
3344 /*****************************************************************************
3345 * IDirectDraw7::CreateClipper
3347 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3349 *****************************************************************************/
3350 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3351 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3353 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3354 iface
, Flags
, Clipper
, UnkOuter
);
3356 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3359 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
, DWORD flags
,
3360 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3362 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3364 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3365 iface
, flags
, clipper
, outer_unknown
);
3367 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3370 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
3371 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3373 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3375 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3376 iface
, flags
, clipper
, outer_unknown
);
3378 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3381 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
3382 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3384 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3386 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3387 iface
, flags
, clipper
, outer_unknown
);
3389 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3392 /*****************************************************************************
3393 * IDirectDraw7::CreatePalette
3395 * Creates a new IDirectDrawPalette object
3398 * Flags: The flags for the new clipper
3399 * ColorTable: Color table to assign to the new clipper
3400 * Palette: Address to write the interface pointer to
3401 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3405 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3406 * E_OUTOFMEMORY if allocating the object failed
3408 *****************************************************************************/
3409 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
3410 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
3412 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3413 struct ddraw_palette
*object
;
3416 TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
3417 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3420 return CLASS_E_NOAGGREGATION
;
3422 wined3d_mutex_lock();
3424 /* The refcount test shows that a cooplevel is required for this */
3425 if (!ddraw
->cooperative_level
)
3427 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3428 wined3d_mutex_unlock();
3429 return DDERR_NOCOOPERATIVELEVELSET
;
3432 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(*object
));
3435 ERR("Out of memory when allocating memory for a palette implementation\n");
3436 wined3d_mutex_unlock();
3437 return E_OUTOFMEMORY
;
3440 hr
= ddraw_palette_init(object
, ddraw
, Flags
, ColorTable
);
3443 WARN("Failed to initialize palette, hr %#x.\n", hr
);
3444 HeapFree(GetProcessHeap(), 0, object
);
3445 wined3d_mutex_unlock();
3449 TRACE("Created palette %p.\n", object
);
3450 *Palette
= &object
->IDirectDrawPalette_iface
;
3451 wined3d_mutex_unlock();
3456 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
, PALETTEENTRY
*entries
,
3457 IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3459 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3462 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3463 iface
, flags
, entries
, palette
, outer_unknown
);
3465 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3466 if (SUCCEEDED(hr
) && *palette
)
3468 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3469 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3470 IDirectDraw4_AddRef(iface
);
3471 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3476 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
3477 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3479 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3482 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3483 iface
, flags
, entries
, palette
, outer_unknown
);
3485 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3486 if (SUCCEEDED(hr
) && *palette
)
3488 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3489 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3490 impl
->ifaceToRelease
= NULL
;
3496 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
3497 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3499 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3502 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3503 iface
, flags
, entries
, palette
, outer_unknown
);
3505 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3506 if (SUCCEEDED(hr
) && *palette
)
3508 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3509 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3510 impl
->ifaceToRelease
= NULL
;
3516 /*****************************************************************************
3517 * IDirectDraw7::DuplicateSurface
3519 * Duplicates a surface. The surface memory points to the same memory as
3520 * the original surface, and it's released when the last surface referencing
3521 * it is released. I guess that's beyond Wine's surface management right now
3522 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3523 * test application to implement this)
3526 * Src: Address of the source surface
3527 * Dest: Address to write the new surface pointer to
3530 * See IDirectDraw7::CreateSurface
3532 *****************************************************************************/
3533 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
3534 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
3536 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(Src
);
3538 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
3540 /* For now, simply create a new, independent surface */
3541 return IDirectDraw7_CreateSurface(iface
, &src_surface
->surface_desc
, Dest
, NULL
);
3544 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
, IDirectDrawSurface4
*src
,
3545 IDirectDrawSurface4
**dst
)
3547 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
3548 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3549 struct ddraw_surface
*dst_impl
;
3550 IDirectDrawSurface7
*dst7
;
3553 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3555 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3556 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3562 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3563 *dst
= &dst_impl
->IDirectDrawSurface4_iface
;
3564 IDirectDrawSurface4_AddRef(*dst
);
3565 IDirectDrawSurface7_Release(dst7
);
3570 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
3571 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
3573 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3574 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3575 struct ddraw_surface
*dst_impl
;
3576 IDirectDrawSurface7
*dst7
;
3579 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3581 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3582 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3585 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3586 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3587 IDirectDrawSurface_AddRef(*dst
);
3588 IDirectDrawSurface7_Release(dst7
);
3593 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
, IDirectDrawSurface
*src
,
3594 IDirectDrawSurface
**dst
)
3596 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3597 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3598 struct ddraw_surface
*dst_impl
;
3599 IDirectDrawSurface7
*dst7
;
3602 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3604 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3605 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3608 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3609 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3610 IDirectDrawSurface_AddRef(*dst
);
3611 IDirectDrawSurface7_Release(dst7
);
3616 /*****************************************************************************
3617 * IDirect3D7::EnumDevices
3619 * The EnumDevices method for IDirect3D7. It enumerates all supported
3620 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
3623 * callback: Function to call for each enumerated device
3624 * context: Pointer to pass back to the app
3627 * D3D_OK, or the return value of the GetCaps call
3629 *****************************************************************************/
3630 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
3632 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
3633 D3DDEVICEDESC7 device_desc7
;
3637 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3640 return DDERR_INVALIDPARAMS
;
3642 wined3d_mutex_lock();
3644 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3646 wined3d_mutex_unlock();
3650 for (i
= 0; i
< sizeof(device_list7
)/sizeof(device_list7
[0]); i
++)
3654 device_desc7
.deviceGUID
= *device_list7
[i
].device_guid
;
3655 ret
= callback(device_list7
[i
].interface_name
, device_list7
[i
].device_name
, &device_desc7
, context
);
3656 if (ret
!= DDENUMRET_OK
)
3658 TRACE("Application cancelled the enumeration.\n");
3659 wined3d_mutex_unlock();
3664 TRACE("End of enumeration.\n");
3666 wined3d_mutex_unlock();
3671 /*****************************************************************************
3672 * IDirect3D3::EnumDevices
3674 * Enumerates all supported Direct3DDevice interfaces. This is the
3675 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
3677 * Versions 1, 2 and 3
3680 * callback: Application-provided routine to call for each enumerated device
3681 * Context: Pointer to pass to the callback
3684 * D3D_OK on success,
3685 * The result of IDirect3DImpl_GetCaps if it failed
3687 *****************************************************************************/
3688 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3690 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
3692 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3693 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
3694 D3DDEVICEDESC7 device_desc7
;
3697 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
3698 * name string. Let's put the string in a sufficiently sized array in
3699 * writable memory. */
3700 char device_name
[50];
3701 strcpy(device_name
,"Direct3D HEL");
3703 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3706 return DDERR_INVALIDPARAMS
;
3708 wined3d_mutex_lock();
3710 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3712 wined3d_mutex_unlock();
3715 ddraw_d3dcaps1_from_7(&device_desc1
, &device_desc7
);
3717 /* Do I have to enumerate the reference id? Note from old d3d7:
3718 * "It seems that enumerating the reference IID on Direct3D 1 games
3719 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
3721 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
3722 * EnumReference which enables / disables enumerating the reference
3723 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
3724 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
3725 * demo directory suggest this.
3727 * Some games(GTA 2) seem to use the second enumerated device, so I have
3728 * to enumerate at least 2 devices. So enumerate the reference device to
3731 * Other games (Rollcage) tell emulation and hal device apart by certain
3732 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
3733 * limitation flag), and it refuses all devices that have the perspective
3734 * flag set. This way it refuses the emulation device, and HAL devices
3735 * never have POW2 unset in d3d7 on windows. */
3736 if (ddraw
->d3dversion
!= 1)
3738 static CHAR reference_description
[] = "RGB Direct3D emulation";
3740 TRACE("Enumerating WineD3D D3DDevice interface.\n");
3741 hal_desc
= device_desc1
;
3742 hel_desc
= device_desc1
;
3743 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
3744 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3745 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3746 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3747 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3748 /* RGB, RAMP and MMX devices have a HAL dcmColorModel of 0 */
3749 hal_desc
.dcmColorModel
= 0;
3750 /* RGB, RAMP and MMX devices cannot report HAL hardware flags */
3751 hal_desc
.dwFlags
= 0;
3753 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
3754 device_name
, &hal_desc
, &hel_desc
, context
);
3755 if (hr
!= D3DENUMRET_OK
)
3757 TRACE("Application cancelled the enumeration.\n");
3758 wined3d_mutex_unlock();
3763 strcpy(device_name
,"Direct3D HAL");
3765 TRACE("Enumerating HAL Direct3D device.\n");
3766 hal_desc
= device_desc1
;
3767 hel_desc
= device_desc1
;
3769 /* The hal device does not have the pow2 flag set in hel, but in hal. */
3770 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3771 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3772 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3773 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3774 /* HAL devices have a HEL dcmColorModel of 0 */
3775 hel_desc
.dcmColorModel
= 0;
3777 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
3778 device_name
, &hal_desc
, &hel_desc
, context
);
3779 if (hr
!= D3DENUMRET_OK
)
3781 TRACE("Application cancelled the enumeration.\n");
3782 wined3d_mutex_unlock();
3786 TRACE("End of enumeration.\n");
3788 wined3d_mutex_unlock();
3793 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3795 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3797 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3799 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3802 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3804 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3806 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3808 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3811 /*****************************************************************************
3812 * IDirect3D3::CreateLight
3814 * Creates an IDirect3DLight interface. This interface is used in
3815 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
3816 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
3817 * uses the IDirect3DDevice7 interface with D3D7 lights.
3819 * Versions 1, 2 and 3
3822 * light: Address to store the new interface pointer
3823 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3828 * DDERR_OUTOFMEMORY if memory allocation failed
3829 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3831 *****************************************************************************/
3832 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
,
3833 IUnknown
*outer_unknown
)
3835 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3836 struct d3d_light
*object
;
3838 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3840 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3842 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3845 ERR("Failed to allocate light memory.\n");
3846 return DDERR_OUTOFMEMORY
;
3849 d3d_light_init(object
, ddraw
);
3851 TRACE("Created light %p.\n", object
);
3852 *light
= &object
->IDirect3DLight_iface
;
3857 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3859 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3861 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3863 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3866 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3868 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3870 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3872 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3875 /*****************************************************************************
3876 * IDirect3D3::CreateMaterial
3878 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
3879 * and older versions. The IDirect3DMaterial implementation wraps its
3880 * functionality to IDirect3DDevice7::SetMaterial and friends.
3882 * Versions 1, 2 and 3
3885 * material: Address to store the new interface's pointer to
3886 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3891 * DDERR_OUTOFMEMORY if memory allocation failed
3892 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3894 *****************************************************************************/
3895 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
,
3896 IUnknown
*outer_unknown
)
3898 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3899 struct d3d_material
*object
;
3901 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3903 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3905 object
= d3d_material_create(ddraw
);
3908 ERR("Failed to allocate material memory.\n");
3909 return DDERR_OUTOFMEMORY
;
3912 TRACE("Created material %p.\n", object
);
3913 *material
= &object
->IDirect3DMaterial3_iface
;
3918 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
,
3919 IUnknown
*outer_unknown
)
3921 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3922 struct d3d_material
*object
;
3924 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3926 object
= d3d_material_create(ddraw
);
3929 ERR("Failed to allocate material memory.\n");
3930 return DDERR_OUTOFMEMORY
;
3933 TRACE("Created material %p.\n", object
);
3934 *material
= &object
->IDirect3DMaterial2_iface
;
3939 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
,
3940 IUnknown
*outer_unknown
)
3942 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3943 struct d3d_material
*object
;
3945 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3947 object
= d3d_material_create(ddraw
);
3950 ERR("Failed to allocate material memory.\n");
3951 return DDERR_OUTOFMEMORY
;
3954 TRACE("Created material %p.\n", object
);
3955 *material
= &object
->IDirect3DMaterial_iface
;
3960 /*****************************************************************************
3961 * IDirect3D3::CreateViewport
3963 * Creates an IDirect3DViewport interface. This interface is used
3964 * by Direct3D and earlier versions for Viewport management. In Direct3D7
3965 * it has been replaced by a viewport structure and
3966 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
3967 * uses the IDirect3DDevice7 methods for its functionality
3970 * Viewport: Address to store the new interface pointer
3971 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3976 * DDERR_OUTOFMEMORY if memory allocation failed
3977 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3979 *****************************************************************************/
3980 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
,
3981 IUnknown
*outer_unknown
)
3983 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3984 struct d3d_viewport
*object
;
3986 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
3988 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3990 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3993 ERR("Failed to allocate viewport memory.\n");
3994 return DDERR_OUTOFMEMORY
;
3997 d3d_viewport_init(object
, ddraw
);
3999 TRACE("Created viewport %p.\n", object
);
4000 *viewport
= &object
->IDirect3DViewport3_iface
;
4005 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
4007 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4009 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4011 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4015 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
4017 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4019 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4021 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4025 /*****************************************************************************
4026 * IDirect3D3::FindDevice
4028 * This method finds a device with the requested properties and returns a
4029 * device description
4031 * Versions 1, 2 and 3
4033 * fds: Describes the requested device characteristics
4034 * fdr: Returns the device description
4038 * DDERR_INVALIDPARAMS if no device was found
4040 *****************************************************************************/
4041 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4043 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4044 D3DDEVICEDESC7 desc7
;
4045 D3DDEVICEDESC desc1
;
4048 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4050 if (!fds
|| !fdr
) return DDERR_INVALIDPARAMS
;
4052 if (fds
->dwSize
!= sizeof(D3DFINDDEVICESEARCH
)
4053 || fdr
->dwSize
!= sizeof(D3DFINDDEVICERESULT
))
4054 return DDERR_INVALIDPARAMS
;
4056 if ((fds
->dwFlags
& D3DFDS_COLORMODEL
)
4057 && fds
->dcmColorModel
!= D3DCOLOR_RGB
)
4059 WARN("Trying to request a non-RGB D3D color model. Not supported.\n");
4060 return DDERR_INVALIDPARAMS
; /* No real idea what to return here :-) */
4063 if (fds
->dwFlags
& D3DFDS_GUID
)
4065 TRACE("Trying to match guid %s.\n", debugstr_guid(&(fds
->guid
)));
4066 if (!IsEqualGUID(&IID_D3DDEVICE_WineD3D
, &fds
->guid
)
4067 && !IsEqualGUID(&IID_IDirect3DHALDevice
, &fds
->guid
)
4068 && !IsEqualGUID(&IID_IDirect3DRGBDevice
, &fds
->guid
))
4070 WARN("No match for this GUID.\n");
4071 return DDERR_NOTFOUND
;
4076 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &desc7
)))
4079 /* Now return our own GUID */
4080 ddraw_d3dcaps1_from_7(&desc1
, &desc7
);
4081 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4082 fdr
->ddHwDesc
= desc1
;
4083 fdr
->ddSwDesc
= desc1
;
4085 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4090 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4092 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4094 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4096 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4099 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4101 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4103 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4105 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4108 /*****************************************************************************
4109 * IDirect3D7::CreateDevice
4111 * Creates an IDirect3DDevice7 interface.
4113 * Versions 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4114 * DirectDraw surfaces and are created with
4115 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4116 * create the device object and QueryInterfaces for IDirect3DDevice
4119 * refiid: IID of the device to create
4120 * Surface: Initial rendertarget
4121 * Device: Address to return the interface pointer
4125 * DDERR_OUTOFMEMORY if memory allocation failed
4126 * DDERR_INVALIDPARAMS if a device exists already
4128 *****************************************************************************/
4129 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4130 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4132 struct ddraw_surface
*target
= unsafe_impl_from_IDirectDrawSurface7(surface
);
4133 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4134 struct d3d_device
*object
;
4137 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4139 wined3d_mutex_lock();
4140 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, target
, (IUnknown
*)surface
, 7, &object
, NULL
)))
4142 *device
= &object
->IDirect3DDevice7_iface
;
4146 WARN("Failed to create device, hr %#x.\n", hr
);
4149 wined3d_mutex_unlock();
4154 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4155 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4157 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface4(surface
);
4158 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4159 struct d3d_device
*device_impl
;
4162 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4163 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4166 return CLASS_E_NOAGGREGATION
;
4168 wined3d_mutex_lock();
4169 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 3, &device_impl
, NULL
)))
4171 *device
= &device_impl
->IDirect3DDevice3_iface
;
4175 WARN("Failed to create device, hr %#x.\n", hr
);
4178 wined3d_mutex_unlock();
4183 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4184 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4186 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface(surface
);
4187 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4188 struct d3d_device
*device_impl
;
4191 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4192 iface
, debugstr_guid(riid
), surface
, device
);
4194 wined3d_mutex_lock();
4195 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 2, &device_impl
, NULL
)))
4197 *device
= &device_impl
->IDirect3DDevice2_iface
;
4201 WARN("Failed to create device, hr %#x.\n", hr
);
4204 wined3d_mutex_unlock();
4209 /*****************************************************************************
4210 * IDirect3D7::CreateVertexBuffer
4212 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4218 * desc: Requested Vertex buffer properties
4219 * vertex_buffer: Address to return the interface pointer at
4220 * flags: Some flags, should be 0
4224 * DDERR_OUTOFMEMORY if memory allocation failed
4225 * DDERR_INVALIDPARAMS if desc or vertex_buffer is NULL
4227 *****************************************************************************/
4228 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4229 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4231 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4232 struct d3d_vertex_buffer
*object
;
4235 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
4236 iface
, desc
, vertex_buffer
, flags
);
4238 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4240 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4243 TRACE("Created vertex buffer %p.\n", object
);
4244 *vertex_buffer
= &object
->IDirect3DVertexBuffer7_iface
;
4247 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4252 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4253 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4255 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4256 struct d3d_vertex_buffer
*object
;
4259 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n",
4260 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4263 return CLASS_E_NOAGGREGATION
;
4264 if (!vertex_buffer
|| !desc
)
4265 return DDERR_INVALIDPARAMS
;
4267 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4270 TRACE("Created vertex buffer %p.\n", object
);
4271 *vertex_buffer
= (IDirect3DVertexBuffer
*)&object
->IDirect3DVertexBuffer7_iface
;
4274 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4279 /*****************************************************************************
4280 * IDirect3D7::EnumZBufferFormats
4282 * Enumerates all supported Z buffer pixel formats
4288 * callback: callback to call for each pixel format
4289 * context: Pointer to pass back to the callback
4293 * DDERR_INVALIDPARAMS if callback is NULL
4295 *****************************************************************************/
4296 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4297 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4299 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4300 struct wined3d_display_mode mode
;
4301 enum wined3d_device_type type
;
4305 /* Order matters. Specifically, BattleZone II (full version) expects the
4306 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4307 static const enum wined3d_format_id formats
[] =
4309 WINED3DFMT_S1_UINT_D15_UNORM
,
4310 WINED3DFMT_D16_UNORM
,
4311 WINED3DFMT_X8D24_UNORM
,
4312 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4313 WINED3DFMT_D24_UNORM_S8_UINT
,
4314 WINED3DFMT_D32_UNORM
,
4317 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4318 iface
, debugstr_guid(device_iid
), callback
, context
);
4320 if (!callback
) return DDERR_INVALIDPARAMS
;
4322 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4323 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4324 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4326 TRACE("Asked for HAL device.\n");
4327 type
= WINED3D_DEVICE_TYPE_HAL
;
4329 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4330 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4332 TRACE("Asked for SW device.\n");
4333 type
= WINED3D_DEVICE_TYPE_SW
;
4335 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4337 TRACE("Asked for REF device.\n");
4338 type
= WINED3D_DEVICE_TYPE_REF
;
4340 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4342 TRACE("Asked for NULLREF device.\n");
4343 type
= WINED3D_DEVICE_TYPE_NULLREF
;
4347 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4348 type
= WINED3D_DEVICE_TYPE_HAL
;
4351 wined3d_mutex_lock();
4352 /* We need an adapter format from somewhere to please wined3d and WGL.
4353 * Use the current display mode. So far all cards offer the same depth
4354 * stencil format for all modes, but if some do not and applications do
4355 * not like that we'll have to find some workaround, like iterating over
4356 * all imaginable formats and collecting all the depth stencil formats we
4358 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
4360 ERR("Failed to get display mode, hr %#x.\n", hr
);
4361 wined3d_mutex_unlock();
4365 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
4367 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4368 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_TEXTURE_2D
, formats
[i
])))
4370 DDPIXELFORMAT pformat
;
4372 memset(&pformat
, 0, sizeof(pformat
));
4373 pformat
.dwSize
= sizeof(pformat
);
4374 ddrawformat_from_wined3dformat(&pformat
, formats
[i
]);
4376 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
4377 hr
= callback(&pformat
, context
);
4378 if (hr
!= DDENUMRET_OK
)
4380 TRACE("Format enumeration cancelled by application.\n");
4381 wined3d_mutex_unlock();
4387 /* Historically some windows drivers used dwZBufferBitDepth=24 for WINED3DFMT_X8D24_UNORM,
4388 * while others used dwZBufferBitDepth=32. In either case the pitch matches a 32 bits per
4389 * pixel format, so we use dwZBufferBitDepth=32. Some games expect 24. Windows Vista and
4390 * newer enumerate both versions, so we do the same(bug 22434) */
4391 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4392 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_TEXTURE_2D
, WINED3DFMT_X8D24_UNORM
)))
4394 DDPIXELFORMAT x8d24
=
4396 sizeof(x8d24
), DDPF_ZBUFFER
, 0,
4397 {24}, {0x00000000}, {0x00ffffff}, {0x00000000}
4399 TRACE("Enumerating WINED3DFMT_X8D24_UNORM, dwZBufferBitDepth=24 version\n");
4400 callback(&x8d24
, context
);
4403 TRACE("End of enumeration.\n");
4405 wined3d_mutex_unlock();
4410 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
4411 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4413 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4415 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4416 iface
, debugstr_guid(device_iid
), callback
, context
);
4418 return d3d7_EnumZBufferFormats(&ddraw
->IDirect3D7_iface
, device_iid
, callback
, context
);
4421 /*****************************************************************************
4422 * IDirect3D7::EvictManagedTextures
4424 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
4425 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
4430 * D3D_OK, because it's a stub
4432 *****************************************************************************/
4433 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
4435 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4437 TRACE("iface %p!\n", iface
);
4439 wined3d_mutex_lock();
4440 if (ddraw
->flags
& DDRAW_D3D_INITIALIZED
)
4441 wined3d_device_evict_managed_resources(ddraw
->wined3d_device
);
4442 wined3d_mutex_unlock();
4447 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
4449 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4451 TRACE("iface %p.\n", iface
);
4453 return d3d7_EvictManagedTextures(&ddraw
->IDirect3D7_iface
);
4456 /*****************************************************************************
4457 * IDirectDraw7 VTable
4458 *****************************************************************************/
4459 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
4462 ddraw7_QueryInterface
,
4467 ddraw7_CreateClipper
,
4468 ddraw7_CreatePalette
,
4469 ddraw7_CreateSurface
,
4470 ddraw7_DuplicateSurface
,
4471 ddraw7_EnumDisplayModes
,
4472 ddraw7_EnumSurfaces
,
4473 ddraw7_FlipToGDISurface
,
4475 ddraw7_GetDisplayMode
,
4476 ddraw7_GetFourCCCodes
,
4477 ddraw7_GetGDISurface
,
4478 ddraw7_GetMonitorFrequency
,
4480 ddraw7_GetVerticalBlankStatus
,
4482 ddraw7_RestoreDisplayMode
,
4483 ddraw7_SetCooperativeLevel
,
4484 ddraw7_SetDisplayMode
,
4485 ddraw7_WaitForVerticalBlank
,
4487 ddraw7_GetAvailableVidMem
,
4489 ddraw7_GetSurfaceFromDC
,
4491 ddraw7_RestoreAllSurfaces
,
4492 ddraw7_TestCooperativeLevel
,
4493 ddraw7_GetDeviceIdentifier
,
4495 ddraw7_StartModeTest
,
4499 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
4502 ddraw4_QueryInterface
,
4507 ddraw4_CreateClipper
,
4508 ddraw4_CreatePalette
,
4509 ddraw4_CreateSurface
,
4510 ddraw4_DuplicateSurface
,
4511 ddraw4_EnumDisplayModes
,
4512 ddraw4_EnumSurfaces
,
4513 ddraw4_FlipToGDISurface
,
4515 ddraw4_GetDisplayMode
,
4516 ddraw4_GetFourCCCodes
,
4517 ddraw4_GetGDISurface
,
4518 ddraw4_GetMonitorFrequency
,
4520 ddraw4_GetVerticalBlankStatus
,
4522 ddraw4_RestoreDisplayMode
,
4523 ddraw4_SetCooperativeLevel
,
4524 ddraw4_SetDisplayMode
,
4525 ddraw4_WaitForVerticalBlank
,
4527 ddraw4_GetAvailableVidMem
,
4529 ddraw4_GetSurfaceFromDC
,
4531 ddraw4_RestoreAllSurfaces
,
4532 ddraw4_TestCooperativeLevel
,
4533 ddraw4_GetDeviceIdentifier
,
4536 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
4539 ddraw2_QueryInterface
,
4544 ddraw2_CreateClipper
,
4545 ddraw2_CreatePalette
,
4546 ddraw2_CreateSurface
,
4547 ddraw2_DuplicateSurface
,
4548 ddraw2_EnumDisplayModes
,
4549 ddraw2_EnumSurfaces
,
4550 ddraw2_FlipToGDISurface
,
4552 ddraw2_GetDisplayMode
,
4553 ddraw2_GetFourCCCodes
,
4554 ddraw2_GetGDISurface
,
4555 ddraw2_GetMonitorFrequency
,
4557 ddraw2_GetVerticalBlankStatus
,
4559 ddraw2_RestoreDisplayMode
,
4560 ddraw2_SetCooperativeLevel
,
4561 ddraw2_SetDisplayMode
,
4562 ddraw2_WaitForVerticalBlank
,
4564 ddraw2_GetAvailableVidMem
,
4567 static const struct IDirectDrawVtbl ddraw1_vtbl
=
4570 ddraw1_QueryInterface
,
4575 ddraw1_CreateClipper
,
4576 ddraw1_CreatePalette
,
4577 ddraw1_CreateSurface
,
4578 ddraw1_DuplicateSurface
,
4579 ddraw1_EnumDisplayModes
,
4580 ddraw1_EnumSurfaces
,
4581 ddraw1_FlipToGDISurface
,
4583 ddraw1_GetDisplayMode
,
4584 ddraw1_GetFourCCCodes
,
4585 ddraw1_GetGDISurface
,
4586 ddraw1_GetMonitorFrequency
,
4588 ddraw1_GetVerticalBlankStatus
,
4590 ddraw1_RestoreDisplayMode
,
4591 ddraw1_SetCooperativeLevel
,
4592 ddraw1_SetDisplayMode
,
4593 ddraw1_WaitForVerticalBlank
,
4596 static const struct IDirect3D7Vtbl d3d7_vtbl
=
4598 /* IUnknown methods */
4599 d3d7_QueryInterface
,
4602 /* IDirect3D7 methods */
4605 d3d7_CreateVertexBuffer
,
4606 d3d7_EnumZBufferFormats
,
4607 d3d7_EvictManagedTextures
4610 static const struct IDirect3D3Vtbl d3d3_vtbl
=
4612 /* IUnknown methods */
4613 d3d3_QueryInterface
,
4616 /* IDirect3D3 methods */
4619 d3d3_CreateMaterial
,
4620 d3d3_CreateViewport
,
4623 d3d3_CreateVertexBuffer
,
4624 d3d3_EnumZBufferFormats
,
4625 d3d3_EvictManagedTextures
4628 static const struct IDirect3D2Vtbl d3d2_vtbl
=
4630 /* IUnknown methods */
4631 d3d2_QueryInterface
,
4634 /* IDirect3D2 methods */
4637 d3d2_CreateMaterial
,
4638 d3d2_CreateViewport
,
4643 static const struct IDirect3DVtbl d3d1_vtbl
=
4645 /* IUnknown methods */
4646 d3d1_QueryInterface
,
4649 /* IDirect3D methods */
4653 d3d1_CreateMaterial
,
4654 d3d1_CreateViewport
,
4658 /*****************************************************************************
4661 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
4662 * if none was found.
4664 * This function is in ddraw.c and the DDraw object space because D3D7
4665 * vertex buffers are created using the IDirect3D interface to the ddraw
4666 * object, so they can be valid across D3D devices(theoretically. The ddraw
4667 * object also owns the wined3d device
4671 * fvf: Fvf to find the decl for
4674 * NULL in case of an error, the vertex declaration for the FVF otherwise.
4676 *****************************************************************************/
4677 struct wined3d_vertex_declaration
*ddraw_find_decl(struct ddraw
*This
, DWORD fvf
)
4679 struct wined3d_vertex_declaration
*pDecl
= NULL
;
4681 int p
, low
, high
; /* deliberately signed */
4682 struct FvfToDecl
*convertedDecls
= This
->decls
;
4684 TRACE("Searching for declaration for fvf %08x... ", fvf
);
4687 high
= This
->numConvertedDecls
- 1;
4688 while(low
<= high
) {
4689 p
= (low
+ high
) >> 1;
4691 if(convertedDecls
[p
].fvf
== fvf
) {
4692 TRACE("found %p\n", convertedDecls
[p
].decl
);
4693 return convertedDecls
[p
].decl
;
4694 } else if(convertedDecls
[p
].fvf
< fvf
) {
4700 TRACE("not found. Creating and inserting at position %d.\n", low
);
4702 hr
= wined3d_vertex_declaration_create_from_fvf(This
->wined3d_device
,
4703 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
4704 if (hr
!= S_OK
) return NULL
;
4706 if(This
->declArraySize
== This
->numConvertedDecls
) {
4707 int grow
= max(This
->declArraySize
/ 2, 8);
4708 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
4709 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
4710 if (!convertedDecls
)
4712 wined3d_vertex_declaration_decref(pDecl
);
4715 This
->decls
= convertedDecls
;
4716 This
->declArraySize
+= grow
;
4719 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
4720 convertedDecls
[low
].decl
= pDecl
;
4721 convertedDecls
[low
].fvf
= fvf
;
4722 This
->numConvertedDecls
++;
4724 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
4728 static inline struct ddraw
*ddraw_from_device_parent(struct wined3d_device_parent
*device_parent
)
4730 return CONTAINING_RECORD(device_parent
, struct ddraw
, device_parent
);
4733 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
4734 struct wined3d_device
*device
)
4736 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
4739 /* This is run from device_process_message() in wined3d, we can't take the
4741 /* FIXME: We only get mode change notifications in exclusive mode, but we
4742 * should mark surfaces as lost on mode changes in DDSCL_NORMAL mode as well. */
4743 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
4745 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4746 MONITORINFO monitor_info
;
4750 TRACE("device_parent %p.\n", device_parent
);
4752 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) || !ddraw
->swapchain_window
)
4754 TRACE("Nothing to resize.\n");
4758 monitor
= MonitorFromWindow(ddraw
->swapchain_window
, MONITOR_DEFAULTTOPRIMARY
);
4759 monitor_info
.cbSize
= sizeof(monitor_info
);
4760 if (!GetMonitorInfoW(monitor
, &monitor_info
))
4762 ERR("Failed to get monitor info.\n");
4766 r
= &monitor_info
.rcMonitor
;
4767 TRACE("Resizing window %p to %s.\n", ddraw
->swapchain_window
, wine_dbgstr_rect(r
));
4769 if (!SetWindowPos(ddraw
->swapchain_window
, HWND_TOP
, r
->left
, r
->top
,
4770 r
->right
- r
->left
, r
->bottom
- r
->top
, SWP_SHOWWINDOW
| SWP_NOACTIVATE
))
4771 ERR("Failed to resize window.\n");
4773 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_OK
);
4776 static void CDECL
device_parent_activate(struct wined3d_device_parent
*device_parent
, BOOL activate
)
4778 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4780 TRACE("device_parent %p, activate %#x.\n", device_parent
, activate
);
4784 ddraw
->device_state
= DDRAW_DEVICE_STATE_LOST
;
4785 exclusive_window
= NULL
;
4789 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_LOST
);
4793 void ddraw_update_lost_surfaces(struct ddraw
*ddraw
)
4795 struct ddraw_surface
*surface
;
4797 if (ddraw
->device_state
!= DDRAW_DEVICE_STATE_NOT_RESTORED
)
4800 LIST_FOR_EACH_ENTRY(surface
, &ddraw
->surface_list
, struct ddraw_surface
, surface_list_entry
)
4802 surface
->is_lost
= TRUE
;
4804 ddraw
->device_state
= DDRAW_DEVICE_STATE_OK
;
4807 static HRESULT CDECL
device_parent_surface_created(struct wined3d_device_parent
*device_parent
,
4808 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
4809 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
4811 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4812 struct ddraw_surface
*ddraw_surface
;
4814 TRACE("device_parent %p, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
4815 device_parent
, wined3d_texture
, sub_resource_idx
, parent
, parent_ops
);
4817 /* We have a swapchain or wined3d internal texture. */
4818 if (!wined3d_texture_get_parent(wined3d_texture
) || wined3d_texture_get_parent(wined3d_texture
) == ddraw
)
4821 *parent_ops
= &ddraw_null_wined3d_parent_ops
;
4826 if (!(ddraw_surface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ddraw_surface
))))
4828 ERR("Failed to allocate surface memory.\n");
4829 return DDERR_OUTOFVIDEOMEMORY
;
4832 ddraw_surface_init(ddraw_surface
, ddraw
, wined3d_texture
, sub_resource_idx
, parent_ops
);
4833 *parent
= ddraw_surface
;
4835 ddraw_update_lost_surfaces(ddraw
);
4836 list_add_head(&ddraw
->surface_list
, &ddraw_surface
->surface_list_entry
);
4838 TRACE("Created ddraw surface %p.\n", ddraw_surface
);
4843 static HRESULT CDECL
device_parent_volume_created(struct wined3d_device_parent
*device_parent
,
4844 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
4845 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
4847 TRACE("device_parent %p, texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
4848 device_parent
, wined3d_texture
, sub_resource_idx
, parent
, parent_ops
);
4851 *parent_ops
= &ddraw_null_wined3d_parent_ops
;
4856 static void STDMETHODCALLTYPE
ddraw_frontbuffer_destroyed(void *parent
)
4858 struct ddraw
*ddraw
= parent
;
4859 ddraw
->wined3d_frontbuffer
= NULL
;
4862 static const struct wined3d_parent_ops ddraw_frontbuffer_parent_ops
=
4864 ddraw_frontbuffer_destroyed
,
4867 static HRESULT CDECL
device_parent_create_swapchain_texture(struct wined3d_device_parent
*device_parent
,
4868 void *container_parent
, const struct wined3d_resource_desc
*desc
, DWORD texture_flags
,
4869 struct wined3d_texture
**texture
)
4871 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4874 TRACE("device_parent %p, container_parent %p, desc %p, texture flags %#x, texture %p.\n",
4875 device_parent
, container_parent
, desc
, texture_flags
, texture
);
4877 if (ddraw
->wined3d_frontbuffer
)
4879 ERR("Frontbuffer already created.\n");
4883 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, desc
, 1, 1,
4884 texture_flags
| WINED3D_TEXTURE_CREATE_MAPPABLE
, NULL
, ddraw
, &ddraw_frontbuffer_parent_ops
, texture
)))
4886 WARN("Failed to create texture, hr %#x.\n", hr
);
4890 ddraw
->wined3d_frontbuffer
= *texture
;
4895 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
4896 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
4898 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4901 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent
, desc
, swapchain
);
4903 if (ddraw
->wined3d_swapchain
)
4905 ERR("Swapchain already created.\n");
4909 if (FAILED(hr
= wined3d_swapchain_create(ddraw
->wined3d_device
, desc
, NULL
,
4910 &ddraw_null_wined3d_parent_ops
, swapchain
)))
4911 WARN("Failed to create swapchain, hr %#x.\n", hr
);
4916 static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops
=
4918 device_parent_wined3d_device_created
,
4919 device_parent_mode_changed
,
4920 device_parent_activate
,
4921 device_parent_surface_created
,
4922 device_parent_volume_created
,
4923 device_parent_create_swapchain_texture
,
4924 device_parent_create_swapchain
,
4927 HRESULT
ddraw_init(struct ddraw
*ddraw
, DWORD flags
, enum wined3d_device_type device_type
)
4932 ddraw
->IDirectDraw7_iface
.lpVtbl
= &ddraw7_vtbl
;
4933 ddraw
->IDirectDraw_iface
.lpVtbl
= &ddraw1_vtbl
;
4934 ddraw
->IDirectDraw2_iface
.lpVtbl
= &ddraw2_vtbl
;
4935 ddraw
->IDirectDraw4_iface
.lpVtbl
= &ddraw4_vtbl
;
4936 ddraw
->IDirect3D_iface
.lpVtbl
= &d3d1_vtbl
;
4937 ddraw
->IDirect3D2_iface
.lpVtbl
= &d3d2_vtbl
;
4938 ddraw
->IDirect3D3_iface
.lpVtbl
= &d3d3_vtbl
;
4939 ddraw
->IDirect3D7_iface
.lpVtbl
= &d3d7_vtbl
;
4940 ddraw
->device_parent
.ops
= &ddraw_wined3d_device_parent_ops
;
4941 ddraw
->numIfaces
= 1;
4944 flags
|= DDRAW_WINED3D_FLAGS
;
4945 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
4947 flags
|= WINED3D_NO3D
;
4948 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
4950 WARN("Failed to create a wined3d object.\n");
4955 if (FAILED(hr
= wined3d_get_device_caps(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
, &caps
)))
4957 ERR("Failed to get device caps, hr %#x.\n", hr
);
4958 wined3d_decref(ddraw
->wined3d
);
4962 if (!(caps
.ddraw_caps
.caps
& WINEDDCAPS_3D
))
4964 WARN("Created a wined3d object without 3D support.\n");
4965 ddraw
->flags
|= DDRAW_NO3D
;
4968 if (FAILED(hr
= wined3d_device_create(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
,
4969 NULL
, 0, DDRAW_STRIDE_ALIGNMENT
, &ddraw
->device_parent
, &ddraw
->wined3d_device
)))
4971 WARN("Failed to create a wined3d device, hr %#x.\n", hr
);
4972 wined3d_decref(ddraw
->wined3d
);
4976 list_init(&ddraw
->surface_list
);