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 heap_free(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 */
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 if (!(ddraw
->decls
= heap_alloc_zero(ddraw
->declArraySize
* sizeof(*ddraw
->decls
))))
605 ERR("Error allocating an array for the converted vertex decls.\n");
606 ddraw
->declArraySize
= 0;
607 hr
= wined3d_device_uninit_3d(ddraw
->wined3d_device
);
608 return E_OUTOFMEMORY
;
611 TRACE("Successfully initialized 3D.\n");
616 static HRESULT
ddraw_create_swapchain(struct ddraw
*ddraw
, HWND window
, BOOL windowed
)
618 struct wined3d_swapchain_desc swapchain_desc
;
619 struct wined3d_display_mode mode
;
620 HRESULT hr
= WINED3D_OK
;
622 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
624 ERR("Failed to get display mode.\n");
628 memset(&swapchain_desc
, 0, sizeof(swapchain_desc
));
629 swapchain_desc
.backbuffer_width
= mode
.width
;
630 swapchain_desc
.backbuffer_height
= mode
.height
;
631 swapchain_desc
.backbuffer_format
= mode
.format_id
;
632 swapchain_desc
.backbuffer_usage
= WINED3DUSAGE_RENDERTARGET
;
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 if (!(enum_modes
= heap_alloc(enum_mode_array_size
* sizeof(*enum_modes
))))
2393 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 heap_free(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 if (!(new_enum_modes
= heap_realloc(enum_modes
, enum_mode_array_size
* sizeof(*new_enum_modes
))))
2469 heap_free(enum_modes
);
2470 wined3d_mutex_unlock();
2471 return DDERR_OUTOFMEMORY
;
2474 enum_modes
= new_enum_modes
;
2476 enum_modes
[enum_mode_count
++] = mode
;
2480 TRACE("End of enumeration\n");
2481 heap_free(enum_modes
);
2482 wined3d_mutex_unlock();
2487 static HRESULT WINAPI
ddraw4_EnumDisplayModes(IDirectDraw4
*iface
, DWORD flags
,
2488 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK2 callback
)
2490 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2492 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2493 iface
, flags
, surface_desc
, context
, callback
);
2495 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
, context
, callback
);
2498 static HRESULT WINAPI
ddraw2_EnumDisplayModes(IDirectDraw2
*iface
, DWORD flags
,
2499 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2501 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2502 struct displaymodescallback_context cbcontext
;
2503 DDSURFACEDESC2 surface_desc2
;
2505 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2506 iface
, flags
, surface_desc
, context
, callback
);
2508 cbcontext
.func
= callback
;
2509 cbcontext
.context
= context
;
2511 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2512 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2513 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2516 static HRESULT WINAPI
ddraw1_EnumDisplayModes(IDirectDraw
*iface
, DWORD flags
,
2517 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2519 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2520 struct displaymodescallback_context cbcontext
;
2521 DDSURFACEDESC2 surface_desc2
;
2523 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2524 iface
, flags
, surface_desc
, context
, callback
);
2526 cbcontext
.func
= callback
;
2527 cbcontext
.context
= context
;
2529 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2530 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2531 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2534 /*****************************************************************************
2535 * IDirectDraw7::EvaluateMode
2537 * Used with IDirectDraw7::StartModeTest to test video modes.
2538 * EvaluateMode is used to pass or fail a mode, and continue with the next
2542 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
2543 * Timeout: Returns the amount of seconds left before the mode would have
2544 * been failed automatically
2547 * This implementation always DD_OK, because it's a stub
2549 *****************************************************************************/
2550 static HRESULT WINAPI
ddraw7_EvaluateMode(IDirectDraw7
*iface
, DWORD Flags
, DWORD
*Timeout
)
2552 FIXME("iface %p, flags %#x, timeout %p stub!\n", iface
, Flags
, Timeout
);
2554 /* When implementing this, implement it in WineD3D */
2559 /*****************************************************************************
2560 * IDirectDraw7::GetDeviceIdentifier
2562 * Returns the device identifier, which gives information about the driver
2563 * Our device identifier is defined at the beginning of this file.
2566 * DDDI: Address for the returned structure
2567 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
2570 * On success it returns DD_OK
2571 * DDERR_INVALIDPARAMS if DDDI is NULL
2573 *****************************************************************************/
2574 static HRESULT WINAPI
ddraw7_GetDeviceIdentifier(IDirectDraw7
*iface
,
2575 DDDEVICEIDENTIFIER2
*DDDI
, DWORD Flags
)
2577 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2578 struct wined3d_adapter_identifier adapter_id
;
2581 TRACE("iface %p, device_identifier %p, flags %#x.\n", iface
, DDDI
, Flags
);
2584 return DDERR_INVALIDPARAMS
;
2586 if (Flags
& DDGDI_GETHOSTIDENTIFIER
)
2588 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
2589 * host adapter, if there's a secondary 3D adapter. This doesn't apply
2590 * to any modern hardware, nor is it interesting for Wine, so ignore it.
2591 * Size of DDDEVICEIDENTIFIER2 may be aligned to 8 bytes and thus 4
2592 * bytes too long. So only copy the relevant part of the structure
2595 memcpy(DDDI
, &deviceidentifier
, FIELD_OFFSET(DDDEVICEIDENTIFIER2
, dwWHQLLevel
) + sizeof(DWORD
));
2599 /* Drakan: Order of the Flame expects accurate D3D device information from ddraw */
2600 adapter_id
.driver
= DDDI
->szDriver
;
2601 adapter_id
.driver_size
= sizeof(DDDI
->szDriver
);
2602 adapter_id
.description
= DDDI
->szDescription
;
2603 adapter_id
.description_size
= sizeof(DDDI
->szDescription
);
2604 adapter_id
.device_name_size
= 0;
2605 wined3d_mutex_lock();
2606 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0x0, &adapter_id
);
2607 wined3d_mutex_unlock();
2608 if (FAILED(hr
)) return hr
;
2610 DDDI
->liDriverVersion
= adapter_id
.driver_version
;
2611 DDDI
->dwVendorId
= adapter_id
.vendor_id
;
2612 DDDI
->dwDeviceId
= adapter_id
.device_id
;
2613 DDDI
->dwSubSysId
= adapter_id
.subsystem_id
;
2614 DDDI
->dwRevision
= adapter_id
.revision
;
2615 DDDI
->guidDeviceIdentifier
= adapter_id
.device_identifier
;
2616 DDDI
->dwWHQLLevel
= adapter_id
.whql_level
;
2620 static HRESULT WINAPI
ddraw4_GetDeviceIdentifier(IDirectDraw4
*iface
,
2621 DDDEVICEIDENTIFIER
*identifier
, DWORD flags
)
2623 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2624 DDDEVICEIDENTIFIER2 identifier2
;
2627 TRACE("iface %p, identifier %p, flags %#x.\n", iface
, identifier
, flags
);
2629 hr
= ddraw7_GetDeviceIdentifier(&ddraw
->IDirectDraw7_iface
, &identifier2
, flags
);
2630 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&identifier2
, identifier
);
2635 /*****************************************************************************
2636 * IDirectDraw7::GetSurfaceFromDC
2638 * Returns the Surface for a GDI device context handle.
2639 * Is this related to IDirectDrawSurface::GetDC ???
2642 * hdc: hdc to return the surface for
2643 * Surface: Address to write the surface pointer to
2646 * Always returns DD_OK because it's a stub
2648 *****************************************************************************/
2649 static HRESULT WINAPI
ddraw7_GetSurfaceFromDC(IDirectDraw7
*iface
,
2650 HDC dc
, IDirectDrawSurface7
**surface
)
2652 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2653 struct ddraw_surface
*surface_impl
;
2655 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2658 return E_INVALIDARG
;
2663 wined3d_mutex_lock();
2664 LIST_FOR_EACH_ENTRY(surface_impl
, &ddraw
->surface_list
, struct ddraw_surface
, surface_list_entry
)
2666 if (surface_impl
->dc
!= dc
)
2669 TRACE("Found surface %p for dc %p.\n", surface_impl
, dc
);
2670 *surface
= &surface_impl
->IDirectDrawSurface7_iface
;
2671 IDirectDrawSurface7_AddRef(*surface
);
2672 wined3d_mutex_unlock();
2675 wined3d_mutex_unlock();
2678 TRACE("No surface found for dc %p.\n", dc
);
2680 return DDERR_NOTFOUND
;
2683 static HRESULT WINAPI
ddraw4_GetSurfaceFromDC(IDirectDraw4
*iface
, HDC dc
,
2684 IDirectDrawSurface4
**surface
)
2686 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2687 struct ddraw_surface
*surface_impl
;
2688 IDirectDrawSurface7
*surface7
;
2691 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2693 if (!surface
) return E_INVALIDARG
;
2695 hr
= ddraw7_GetSurfaceFromDC(&ddraw
->IDirectDraw7_iface
, dc
, &surface7
);
2701 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2702 /* Tests say this is true */
2703 *surface
= (IDirectDrawSurface4
*)&surface_impl
->IDirectDrawSurface_iface
;
2704 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2705 IDirectDrawSurface7_Release(surface7
);
2710 static HRESULT CALLBACK
restore_callback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
2712 IDirectDrawSurface_Restore(surface
);
2713 IDirectDrawSurface_Release(surface
);
2715 return DDENUMRET_OK
;
2718 static HRESULT WINAPI
ddraw7_RestoreAllSurfaces(IDirectDraw7
*iface
)
2720 TRACE("iface %p.\n", iface
);
2722 return IDirectDraw7_EnumSurfaces(iface
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
2723 NULL
, NULL
, restore_callback
);
2726 static HRESULT WINAPI
ddraw4_RestoreAllSurfaces(IDirectDraw4
*iface
)
2728 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2730 TRACE("iface %p.\n", iface
);
2732 return ddraw7_RestoreAllSurfaces(&ddraw
->IDirectDraw7_iface
);
2735 /*****************************************************************************
2736 * IDirectDraw7::StartModeTest
2738 * Tests the specified video modes to update the system registry with
2739 * refresh rate information. StartModeTest starts the mode test,
2740 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
2741 * isn't called within 15 seconds, the mode is failed automatically
2743 * As refresh rates are handled by the X server, I don't think this
2744 * Method is important
2747 * Modes: An array of mode specifications
2748 * NumModes: The number of modes in Modes
2749 * Flags: Some flags...
2752 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
2753 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
2756 *****************************************************************************/
2757 static HRESULT WINAPI
ddraw7_StartModeTest(IDirectDraw7
*iface
, SIZE
*Modes
, DWORD NumModes
, DWORD Flags
)
2759 FIXME("iface %p, modes %p, mode_count %u, flags %#x partial stub!\n",
2760 iface
, Modes
, NumModes
, Flags
);
2762 /* This looks sane */
2763 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
2765 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
2766 * As it is not, DDERR_TESTFINISHED is returned
2767 * (hopefully that's correct
2769 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
2770 * well, that value doesn't (yet) exist in the wine headers, so ignore it
2776 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
, DDSURFACEDESC2
*surface_desc
,
2777 IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
2779 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2780 struct ddraw_surface
*impl
;
2783 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2784 iface
, surface_desc
, surface
, outer_unknown
);
2786 wined3d_mutex_lock();
2788 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2790 WARN("Cooperative level not set.\n");
2791 wined3d_mutex_unlock();
2792 return DDERR_NOCOOPERATIVELEVELSET
;
2795 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2797 WARN("Application supplied invalid surface descriptor\n");
2798 wined3d_mutex_unlock();
2799 return DDERR_INVALIDPARAMS
;
2808 WARN("Surface pointer %p is invalid.\n", surface
);
2809 wined3d_mutex_unlock();
2810 return DDERR_INVALIDPARAMS
;
2814 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2816 if (TRACE_ON(ddraw
))
2818 TRACE(" (%p) Requesting surface desc :\n", iface
);
2819 DDRAW_dump_surface_desc(surface_desc
);
2822 WARN("Application tried to create an explicit front or back buffer\n");
2823 wined3d_mutex_unlock();
2824 return DDERR_INVALIDCAPS
;
2827 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 7);
2828 wined3d_mutex_unlock();
2832 *surface
= &impl
->IDirectDrawSurface7_iface
;
2833 IDirectDraw7_AddRef(iface
);
2834 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2839 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
2840 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
2842 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2843 struct ddraw_surface
*impl
;
2846 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2847 iface
, surface_desc
, surface
, outer_unknown
);
2849 wined3d_mutex_lock();
2851 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2853 WARN("Cooperative level not set.\n");
2854 wined3d_mutex_unlock();
2855 return DDERR_NOCOOPERATIVELEVELSET
;
2858 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2860 WARN("Application supplied invalid surface descriptor\n");
2861 wined3d_mutex_unlock();
2862 return DDERR_INVALIDPARAMS
;
2871 WARN("Surface pointer %p is invalid.\n", surface
);
2872 wined3d_mutex_unlock();
2873 return DDERR_INVALIDPARAMS
;
2877 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2879 if (TRACE_ON(ddraw
))
2881 TRACE(" (%p) Requesting surface desc :\n", iface
);
2882 DDRAW_dump_surface_desc(surface_desc
);
2885 WARN("Application tried to create an explicit front or back buffer\n");
2886 wined3d_mutex_unlock();
2887 return DDERR_INVALIDCAPS
;
2890 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 4);
2891 wined3d_mutex_unlock();
2895 *surface
= &impl
->IDirectDrawSurface4_iface
;
2896 IDirectDraw4_AddRef(iface
);
2897 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2902 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
2903 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2905 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2906 struct ddraw_surface
*impl
;
2908 DDSURFACEDESC2 surface_desc2
;
2910 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2911 iface
, surface_desc
, surface
, outer_unknown
);
2913 wined3d_mutex_lock();
2915 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2917 WARN("Cooperative level not set.\n");
2918 wined3d_mutex_unlock();
2919 return DDERR_NOCOOPERATIVELEVELSET
;
2922 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2924 WARN("Application supplied invalid surface descriptor\n");
2925 wined3d_mutex_unlock();
2926 return DDERR_INVALIDPARAMS
;
2935 WARN("Surface pointer %p is invalid.\n", surface
);
2936 wined3d_mutex_unlock();
2937 return DDERR_INVALIDPARAMS
;
2941 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2942 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2944 if (TRACE_ON(ddraw
))
2946 TRACE(" (%p) Requesting surface desc :\n", iface
);
2947 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
2950 WARN("Application tried to create an explicit front or back buffer\n");
2951 wined3d_mutex_unlock();
2952 return DDERR_INVALIDCAPS
;
2955 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 2);
2956 wined3d_mutex_unlock();
2960 *surface
= &impl
->IDirectDrawSurface_iface
;
2961 impl
->ifaceToRelease
= NULL
;
2966 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
2967 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2969 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2970 struct ddraw_surface
*impl
;
2972 DDSURFACEDESC2 surface_desc2
;
2974 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2975 iface
, surface_desc
, surface
, outer_unknown
);
2977 wined3d_mutex_lock();
2979 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2981 WARN("Cooperative level not set.\n");
2982 wined3d_mutex_unlock();
2983 return DDERR_NOCOOPERATIVELEVELSET
;
2986 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2988 WARN("Application supplied invalid surface descriptor\n");
2989 wined3d_mutex_unlock();
2990 return DDERR_INVALIDPARAMS
;
2999 WARN("Surface pointer %p is invalid.\n", surface
);
3000 wined3d_mutex_unlock();
3001 return DDERR_INVALIDPARAMS
;
3005 if ((surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
))
3006 == (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
)
3007 || (surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
))
3008 == ((DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
)))
3010 WARN("Application tried to create an explicit front or back buffer.\n");
3011 wined3d_mutex_unlock();
3012 return DDERR_INVALIDCAPS
;
3015 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3016 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 1);
3017 wined3d_mutex_unlock();
3021 *surface
= &impl
->IDirectDrawSurface_iface
;
3022 impl
->ifaceToRelease
= NULL
;
3028 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
3029 const DDPIXELFORMAT
*provided
)
3031 /* Some flags must be present in both or neither for a match. */
3032 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
3033 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
3034 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
3036 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3039 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
3042 if (requested
->dwFlags
& DDPF_FOURCC
)
3043 if (requested
->dwFourCC
!= provided
->dwFourCC
)
3046 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
3047 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3048 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
3051 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3052 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3053 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
3056 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
3057 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
3060 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
3061 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3063 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
3066 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
3067 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
3073 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3082 #define CMP(FLAG, FIELD) \
3083 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3084 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3086 static const struct compare_info compare
[] =
3088 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3089 CMP(BACKBUFFERCOUNT
, u5
.dwBackBufferCount
),
3091 CMP(CKDESTBLT
, ddckCKDestBlt
),
3092 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3093 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3094 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3095 CMP(HEIGHT
, dwHeight
),
3096 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3097 CMP(LPSURFACE
, lpSurface
),
3098 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3099 CMP(PITCH
, u1
/* lPitch */),
3100 /* PIXELFORMAT: manual */
3101 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3102 CMP(TEXTURESTAGE
, dwTextureStage
),
3103 CMP(WIDTH
, dwWidth
),
3104 /* ZBUFFERBITDEPTH: "obsolete" */
3111 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3114 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
3116 if (requested
->dwFlags
& compare
[i
].flag
3117 && memcmp((const char *)provided
+ compare
[i
].offset
,
3118 (const char *)requested
+ compare
[i
].offset
,
3119 compare
[i
].size
) != 0)
3123 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3125 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3126 &provided
->u4
.ddpfPixelFormat
))
3133 struct surfacescallback2_context
3135 LPDDENUMSURFACESCALLBACK2 func
;
3139 struct surfacescallback_context
3141 LPDDENUMSURFACESCALLBACK func
;
3145 static HRESULT CALLBACK
EnumSurfacesCallback2Thunk(IDirectDrawSurface7
*surface
,
3146 DDSURFACEDESC2
*surface_desc
, void *context
)
3148 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3149 struct surfacescallback2_context
*cbcontext
= context
;
3151 IDirectDrawSurface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
3152 IDirectDrawSurface7_Release(surface
);
3154 return cbcontext
->func(&surface_impl
->IDirectDrawSurface4_iface
,
3155 surface_desc
, cbcontext
->context
);
3158 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3159 DDSURFACEDESC2
*surface_desc
, void *context
)
3161 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3162 struct surfacescallback_context
*cbcontext
= context
;
3164 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
3165 IDirectDrawSurface7_Release(surface
);
3167 return cbcontext
->func(&surface_impl
->IDirectDrawSurface_iface
,
3168 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3171 /*****************************************************************************
3172 * IDirectDraw7::EnumSurfaces
3174 * Loops through all surfaces attached to this device and calls the
3175 * application callback. This can't be relayed to WineD3DDevice,
3176 * because some WineD3DSurfaces' parents are IParent objects
3179 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3180 * DDSD: Description to filter for
3181 * Context: Application-provided pointer, it's passed unmodified to the
3183 * Callback: Address to call for each surface
3186 * DDERR_INVALIDPARAMS if the callback is NULL
3189 *****************************************************************************/
3190 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD Flags
,
3191 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMSURFACESCALLBACK7 Callback
)
3193 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3194 struct ddraw_surface
*surf
;
3196 DDSURFACEDESC2 desc
;
3197 struct list
*entry
, *entry2
;
3199 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3200 iface
, Flags
, DDSD
, Context
, Callback
);
3202 all
= Flags
& DDENUMSURFACES_ALL
;
3203 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
3206 return DDERR_INVALIDPARAMS
;
3208 wined3d_mutex_lock();
3210 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
3211 LIST_FOR_EACH_SAFE(entry
, entry2
, &ddraw
->surface_list
)
3213 surf
= LIST_ENTRY(entry
, struct ddraw_surface
, surface_list_entry
);
3215 if (!surf
->iface_count
)
3217 WARN("Not enumerating surface %p because it doesn't have any references.\n", surf
);
3221 if (all
|| (nomatch
!= ddraw_match_surface_desc(DDSD
, &surf
->surface_desc
)))
3223 TRACE("Enumerating surface %p.\n", surf
);
3224 desc
= surf
->surface_desc
;
3225 IDirectDrawSurface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
3226 if (Callback(&surf
->IDirectDrawSurface7_iface
, &desc
, Context
) != DDENUMRET_OK
)
3228 wined3d_mutex_unlock();
3234 wined3d_mutex_unlock();
3239 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3240 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3242 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3243 struct surfacescallback2_context cbcontext
;
3245 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3246 iface
, flags
, surface_desc
, context
, callback
);
3248 cbcontext
.func
= callback
;
3249 cbcontext
.context
= context
;
3251 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
,
3252 &cbcontext
, EnumSurfacesCallback2Thunk
);
3255 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3256 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3258 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3259 struct surfacescallback_context cbcontext
;
3260 DDSURFACEDESC2 surface_desc2
;
3262 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3263 iface
, flags
, surface_desc
, context
, callback
);
3265 cbcontext
.func
= callback
;
3266 cbcontext
.context
= context
;
3268 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3269 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3270 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3273 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3274 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3276 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3277 struct surfacescallback_context cbcontext
;
3278 DDSURFACEDESC2 surface_desc2
;
3280 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3281 iface
, flags
, surface_desc
, context
, callback
);
3283 cbcontext
.func
= callback
;
3284 cbcontext
.context
= context
;
3286 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3287 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3288 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3291 /*****************************************************************************
3292 * DirectDrawCreateClipper (DDRAW.@)
3294 * Creates a new IDirectDrawClipper object.
3297 * Clipper: Address to write the interface pointer to
3298 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3302 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3303 * E_OUTOFMEMORY if allocating the object failed
3305 *****************************************************************************/
3306 HRESULT WINAPI
DirectDrawCreateClipper(DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3308 struct ddraw_clipper
*object
;
3311 TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
3312 flags
, clipper
, outer_unknown
);
3315 return CLASS_E_NOAGGREGATION
;
3317 wined3d_mutex_lock();
3319 if (!(object
= heap_alloc_zero(sizeof(*object
))))
3321 wined3d_mutex_unlock();
3322 return E_OUTOFMEMORY
;
3325 hr
= ddraw_clipper_init(object
);
3328 WARN("Failed to initialize clipper, hr %#x.\n", hr
);
3330 wined3d_mutex_unlock();
3334 TRACE("Created clipper %p.\n", object
);
3335 *clipper
= &object
->IDirectDrawClipper_iface
;
3336 wined3d_mutex_unlock();
3341 /*****************************************************************************
3342 * IDirectDraw7::CreateClipper
3344 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3346 *****************************************************************************/
3347 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3348 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3350 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3351 iface
, Flags
, Clipper
, UnkOuter
);
3353 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3356 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
, DWORD flags
,
3357 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3359 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3361 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3362 iface
, flags
, clipper
, outer_unknown
);
3364 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3367 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
3368 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3370 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3372 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3373 iface
, flags
, clipper
, outer_unknown
);
3375 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3378 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
3379 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3381 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3383 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3384 iface
, flags
, clipper
, outer_unknown
);
3386 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3389 /*****************************************************************************
3390 * IDirectDraw7::CreatePalette
3392 * Creates a new IDirectDrawPalette object
3395 * Flags: The flags for the new clipper
3396 * ColorTable: Color table to assign to the new clipper
3397 * Palette: Address to write the interface pointer to
3398 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3402 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3403 * E_OUTOFMEMORY if allocating the object failed
3405 *****************************************************************************/
3406 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
3407 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
3409 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3410 struct ddraw_palette
*object
;
3413 TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
3414 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3417 return CLASS_E_NOAGGREGATION
;
3419 wined3d_mutex_lock();
3421 /* The refcount test shows that a cooplevel is required for this */
3422 if (!ddraw
->cooperative_level
)
3424 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3425 wined3d_mutex_unlock();
3426 return DDERR_NOCOOPERATIVELEVELSET
;
3429 if (!(object
= heap_alloc(sizeof(*object
))))
3431 ERR("Out of memory when allocating memory for a palette implementation\n");
3432 wined3d_mutex_unlock();
3433 return E_OUTOFMEMORY
;
3436 hr
= ddraw_palette_init(object
, ddraw
, Flags
, ColorTable
);
3439 WARN("Failed to initialize palette, hr %#x.\n", hr
);
3441 wined3d_mutex_unlock();
3445 TRACE("Created palette %p.\n", object
);
3446 *Palette
= &object
->IDirectDrawPalette_iface
;
3447 wined3d_mutex_unlock();
3452 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
, PALETTEENTRY
*entries
,
3453 IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3455 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3458 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3459 iface
, flags
, entries
, palette
, outer_unknown
);
3461 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3462 if (SUCCEEDED(hr
) && *palette
)
3464 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3465 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3466 IDirectDraw4_AddRef(iface
);
3467 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3472 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
3473 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3475 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3478 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3479 iface
, flags
, entries
, palette
, outer_unknown
);
3481 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3482 if (SUCCEEDED(hr
) && *palette
)
3484 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3485 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3486 impl
->ifaceToRelease
= NULL
;
3492 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
3493 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3495 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3498 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3499 iface
, flags
, entries
, palette
, outer_unknown
);
3501 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3502 if (SUCCEEDED(hr
) && *palette
)
3504 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3505 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3506 impl
->ifaceToRelease
= NULL
;
3512 /*****************************************************************************
3513 * IDirectDraw7::DuplicateSurface
3515 * Duplicates a surface. The surface memory points to the same memory as
3516 * the original surface, and it's released when the last surface referencing
3517 * it is released. I guess that's beyond Wine's surface management right now
3518 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3519 * test application to implement this)
3522 * Src: Address of the source surface
3523 * Dest: Address to write the new surface pointer to
3526 * See IDirectDraw7::CreateSurface
3528 *****************************************************************************/
3529 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
3530 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
3532 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(Src
);
3534 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
3536 /* For now, simply create a new, independent surface */
3537 return IDirectDraw7_CreateSurface(iface
, &src_surface
->surface_desc
, Dest
, NULL
);
3540 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
, IDirectDrawSurface4
*src
,
3541 IDirectDrawSurface4
**dst
)
3543 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
3544 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3545 struct ddraw_surface
*dst_impl
;
3546 IDirectDrawSurface7
*dst7
;
3549 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3551 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3552 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3558 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3559 *dst
= &dst_impl
->IDirectDrawSurface4_iface
;
3560 IDirectDrawSurface4_AddRef(*dst
);
3561 IDirectDrawSurface7_Release(dst7
);
3566 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
3567 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
3569 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3570 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3571 struct ddraw_surface
*dst_impl
;
3572 IDirectDrawSurface7
*dst7
;
3575 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3577 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3578 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3581 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3582 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3583 IDirectDrawSurface_AddRef(*dst
);
3584 IDirectDrawSurface7_Release(dst7
);
3589 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
, IDirectDrawSurface
*src
,
3590 IDirectDrawSurface
**dst
)
3592 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3593 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3594 struct ddraw_surface
*dst_impl
;
3595 IDirectDrawSurface7
*dst7
;
3598 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3600 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3601 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3604 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3605 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3606 IDirectDrawSurface_AddRef(*dst
);
3607 IDirectDrawSurface7_Release(dst7
);
3612 /*****************************************************************************
3613 * IDirect3D7::EnumDevices
3615 * The EnumDevices method for IDirect3D7. It enumerates all supported
3616 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
3619 * callback: Function to call for each enumerated device
3620 * context: Pointer to pass back to the app
3623 * D3D_OK, or the return value of the GetCaps call
3625 *****************************************************************************/
3626 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
3628 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
3629 D3DDEVICEDESC7 device_desc7
;
3633 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3636 return DDERR_INVALIDPARAMS
;
3638 wined3d_mutex_lock();
3640 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3642 wined3d_mutex_unlock();
3646 for (i
= 0; i
< sizeof(device_list7
)/sizeof(device_list7
[0]); i
++)
3650 device_desc7
.deviceGUID
= *device_list7
[i
].device_guid
;
3651 ret
= callback(device_list7
[i
].interface_name
, device_list7
[i
].device_name
, &device_desc7
, context
);
3652 if (ret
!= DDENUMRET_OK
)
3654 TRACE("Application cancelled the enumeration.\n");
3655 wined3d_mutex_unlock();
3660 TRACE("End of enumeration.\n");
3662 wined3d_mutex_unlock();
3667 /*****************************************************************************
3668 * IDirect3D3::EnumDevices
3670 * Enumerates all supported Direct3DDevice interfaces. This is the
3671 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
3673 * Versions 1, 2 and 3
3676 * callback: Application-provided routine to call for each enumerated device
3677 * Context: Pointer to pass to the callback
3680 * D3D_OK on success,
3681 * The result of IDirect3DImpl_GetCaps if it failed
3683 *****************************************************************************/
3684 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3686 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
3688 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3689 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
3690 D3DDEVICEDESC7 device_desc7
;
3693 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
3694 * name string. Let's put the string in a sufficiently sized array in
3695 * writable memory. */
3696 char device_name
[50];
3697 strcpy(device_name
,"Direct3D HEL");
3699 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3702 return DDERR_INVALIDPARAMS
;
3704 wined3d_mutex_lock();
3706 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3708 wined3d_mutex_unlock();
3711 ddraw_d3dcaps1_from_7(&device_desc1
, &device_desc7
);
3713 /* Do I have to enumerate the reference id? Note from old d3d7:
3714 * "It seems that enumerating the reference IID on Direct3D 1 games
3715 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
3717 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
3718 * EnumReference which enables / disables enumerating the reference
3719 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
3720 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
3721 * demo directory suggest this.
3723 * Some games(GTA 2) seem to use the second enumerated device, so I have
3724 * to enumerate at least 2 devices. So enumerate the reference device to
3727 * Other games (Rollcage) tell emulation and hal device apart by certain
3728 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
3729 * limitation flag), and it refuses all devices that have the perspective
3730 * flag set. This way it refuses the emulation device, and HAL devices
3731 * never have POW2 unset in d3d7 on windows. */
3732 if (ddraw
->d3dversion
!= 1)
3734 static CHAR reference_description
[] = "RGB Direct3D emulation";
3736 TRACE("Enumerating WineD3D D3DDevice interface.\n");
3737 hal_desc
= device_desc1
;
3738 hel_desc
= device_desc1
;
3739 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
3740 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3741 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3742 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3743 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3744 /* RGB, RAMP and MMX devices have a HAL dcmColorModel of 0 */
3745 hal_desc
.dcmColorModel
= 0;
3746 /* RGB, RAMP and MMX devices cannot report HAL hardware flags */
3747 hal_desc
.dwFlags
= 0;
3749 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
3750 device_name
, &hal_desc
, &hel_desc
, context
);
3751 if (hr
!= D3DENUMRET_OK
)
3753 TRACE("Application cancelled the enumeration.\n");
3754 wined3d_mutex_unlock();
3759 strcpy(device_name
,"Direct3D HAL");
3761 TRACE("Enumerating HAL Direct3D device.\n");
3762 hal_desc
= device_desc1
;
3763 hel_desc
= device_desc1
;
3765 /* The hal device does not have the pow2 flag set in hel, but in hal. */
3766 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3767 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3768 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3769 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3770 /* HAL devices have a HEL dcmColorModel of 0 */
3771 hel_desc
.dcmColorModel
= 0;
3773 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
3774 device_name
, &hal_desc
, &hel_desc
, context
);
3775 if (hr
!= D3DENUMRET_OK
)
3777 TRACE("Application cancelled the enumeration.\n");
3778 wined3d_mutex_unlock();
3782 TRACE("End of enumeration.\n");
3784 wined3d_mutex_unlock();
3789 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3791 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3793 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3795 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3798 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3800 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3802 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3804 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3807 /*****************************************************************************
3808 * IDirect3D3::CreateLight
3810 * Creates an IDirect3DLight interface. This interface is used in
3811 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
3812 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
3813 * uses the IDirect3DDevice7 interface with D3D7 lights.
3815 * Versions 1, 2 and 3
3818 * light: Address to store the new interface pointer
3819 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3824 * DDERR_OUTOFMEMORY if memory allocation failed
3825 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3827 *****************************************************************************/
3828 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
,
3829 IUnknown
*outer_unknown
)
3831 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3832 struct d3d_light
*object
;
3834 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3837 return CLASS_E_NOAGGREGATION
;
3839 if (!(object
= heap_alloc_zero(sizeof(*object
))))
3841 ERR("Failed to allocate light memory.\n");
3842 return DDERR_OUTOFMEMORY
;
3845 d3d_light_init(object
, ddraw
);
3847 TRACE("Created light %p.\n", object
);
3848 *light
= &object
->IDirect3DLight_iface
;
3853 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3855 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3857 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3859 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3862 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3864 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3866 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3868 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3871 /*****************************************************************************
3872 * IDirect3D3::CreateMaterial
3874 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
3875 * and older versions. The IDirect3DMaterial implementation wraps its
3876 * functionality to IDirect3DDevice7::SetMaterial and friends.
3878 * Versions 1, 2 and 3
3881 * material: Address to store the new interface's pointer to
3882 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3887 * DDERR_OUTOFMEMORY if memory allocation failed
3888 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3890 *****************************************************************************/
3891 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
,
3892 IUnknown
*outer_unknown
)
3894 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3895 struct d3d_material
*object
;
3897 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3899 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3901 object
= d3d_material_create(ddraw
);
3904 ERR("Failed to allocate material memory.\n");
3905 return DDERR_OUTOFMEMORY
;
3908 TRACE("Created material %p.\n", object
);
3909 *material
= &object
->IDirect3DMaterial3_iface
;
3914 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
,
3915 IUnknown
*outer_unknown
)
3917 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3918 struct d3d_material
*object
;
3920 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3922 object
= d3d_material_create(ddraw
);
3925 ERR("Failed to allocate material memory.\n");
3926 return DDERR_OUTOFMEMORY
;
3929 TRACE("Created material %p.\n", object
);
3930 *material
= &object
->IDirect3DMaterial2_iface
;
3935 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
,
3936 IUnknown
*outer_unknown
)
3938 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3939 struct d3d_material
*object
;
3941 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3943 object
= d3d_material_create(ddraw
);
3946 ERR("Failed to allocate material memory.\n");
3947 return DDERR_OUTOFMEMORY
;
3950 TRACE("Created material %p.\n", object
);
3951 *material
= &object
->IDirect3DMaterial_iface
;
3956 /*****************************************************************************
3957 * IDirect3D3::CreateViewport
3959 * Creates an IDirect3DViewport interface. This interface is used
3960 * by Direct3D and earlier versions for Viewport management. In Direct3D7
3961 * it has been replaced by a viewport structure and
3962 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
3963 * uses the IDirect3DDevice7 methods for its functionality
3966 * Viewport: Address to store the new interface pointer
3967 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3972 * DDERR_OUTOFMEMORY if memory allocation failed
3973 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3975 *****************************************************************************/
3976 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
,
3977 IUnknown
*outer_unknown
)
3979 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3980 struct d3d_viewport
*object
;
3982 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
3984 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3986 if (!(object
= heap_alloc_zero(sizeof(*object
))))
3988 ERR("Failed to allocate viewport memory.\n");
3989 return DDERR_OUTOFMEMORY
;
3992 d3d_viewport_init(object
, ddraw
);
3994 TRACE("Created viewport %p.\n", object
);
3995 *viewport
= &object
->IDirect3DViewport3_iface
;
4000 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
4002 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4004 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4006 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4010 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
4012 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4014 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4016 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4020 /*****************************************************************************
4021 * IDirect3D3::FindDevice
4023 * This method finds a device with the requested properties and returns a
4024 * device description
4026 * Versions 1, 2 and 3
4028 * fds: Describes the requested device characteristics
4029 * fdr: Returns the device description
4033 * DDERR_INVALIDPARAMS if no device was found
4035 *****************************************************************************/
4036 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4038 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4039 D3DDEVICEDESC7 desc7
;
4040 D3DDEVICEDESC desc1
;
4043 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4045 if (!fds
|| !fdr
) return DDERR_INVALIDPARAMS
;
4047 if (fds
->dwSize
!= sizeof(D3DFINDDEVICESEARCH
)
4048 || fdr
->dwSize
!= sizeof(D3DFINDDEVICERESULT
))
4049 return DDERR_INVALIDPARAMS
;
4051 if ((fds
->dwFlags
& D3DFDS_COLORMODEL
)
4052 && fds
->dcmColorModel
!= D3DCOLOR_RGB
)
4054 WARN("Trying to request a non-RGB D3D color model. Not supported.\n");
4055 return DDERR_INVALIDPARAMS
; /* No real idea what to return here :-) */
4058 if (fds
->dwFlags
& D3DFDS_GUID
)
4060 TRACE("Trying to match guid %s.\n", debugstr_guid(&(fds
->guid
)));
4061 if (!IsEqualGUID(&IID_D3DDEVICE_WineD3D
, &fds
->guid
)
4062 && !IsEqualGUID(&IID_IDirect3DHALDevice
, &fds
->guid
)
4063 && !IsEqualGUID(&IID_IDirect3DRGBDevice
, &fds
->guid
))
4065 WARN("No match for this GUID.\n");
4066 return DDERR_NOTFOUND
;
4071 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &desc7
)))
4074 /* Now return our own GUID */
4075 ddraw_d3dcaps1_from_7(&desc1
, &desc7
);
4076 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4077 fdr
->ddHwDesc
= desc1
;
4078 fdr
->ddSwDesc
= desc1
;
4080 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4085 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4087 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4089 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4091 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4094 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4096 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4098 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4100 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4103 /*****************************************************************************
4104 * IDirect3D7::CreateDevice
4106 * Creates an IDirect3DDevice7 interface.
4108 * Versions 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4109 * DirectDraw surfaces and are created with
4110 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4111 * create the device object and QueryInterfaces for IDirect3DDevice
4114 * refiid: IID of the device to create
4115 * Surface: Initial rendertarget
4116 * Device: Address to return the interface pointer
4120 * DDERR_OUTOFMEMORY if memory allocation failed
4121 * DDERR_INVALIDPARAMS if a device exists already
4123 *****************************************************************************/
4124 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4125 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4127 struct ddraw_surface
*target
= unsafe_impl_from_IDirectDrawSurface7(surface
);
4128 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4129 struct d3d_device
*object
;
4132 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4134 wined3d_mutex_lock();
4135 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, target
, (IUnknown
*)surface
, 7, &object
, NULL
)))
4137 *device
= &object
->IDirect3DDevice7_iface
;
4141 WARN("Failed to create device, hr %#x.\n", hr
);
4144 wined3d_mutex_unlock();
4149 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4150 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4152 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface4(surface
);
4153 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4154 struct d3d_device
*device_impl
;
4157 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4158 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4161 return CLASS_E_NOAGGREGATION
;
4163 wined3d_mutex_lock();
4164 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 3, &device_impl
, NULL
)))
4166 *device
= &device_impl
->IDirect3DDevice3_iface
;
4170 WARN("Failed to create device, hr %#x.\n", hr
);
4173 wined3d_mutex_unlock();
4178 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4179 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4181 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface(surface
);
4182 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4183 struct d3d_device
*device_impl
;
4186 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4187 iface
, debugstr_guid(riid
), surface
, device
);
4189 wined3d_mutex_lock();
4190 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 2, &device_impl
, NULL
)))
4192 *device
= &device_impl
->IDirect3DDevice2_iface
;
4196 WARN("Failed to create device, hr %#x.\n", hr
);
4199 wined3d_mutex_unlock();
4204 /*****************************************************************************
4205 * IDirect3D7::CreateVertexBuffer
4207 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4213 * desc: Requested Vertex buffer properties
4214 * vertex_buffer: Address to return the interface pointer at
4215 * flags: Some flags, should be 0
4219 * DDERR_OUTOFMEMORY if memory allocation failed
4220 * DDERR_INVALIDPARAMS if desc or vertex_buffer is NULL
4222 *****************************************************************************/
4223 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4224 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4226 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4227 struct d3d_vertex_buffer
*object
;
4230 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
4231 iface
, desc
, vertex_buffer
, flags
);
4233 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4235 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4238 TRACE("Created vertex buffer %p.\n", object
);
4239 *vertex_buffer
= &object
->IDirect3DVertexBuffer7_iface
;
4242 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4247 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4248 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4250 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4251 struct d3d_vertex_buffer
*object
;
4254 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n",
4255 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4258 return CLASS_E_NOAGGREGATION
;
4259 if (!vertex_buffer
|| !desc
)
4260 return DDERR_INVALIDPARAMS
;
4262 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4265 TRACE("Created vertex buffer %p.\n", object
);
4266 *vertex_buffer
= (IDirect3DVertexBuffer
*)&object
->IDirect3DVertexBuffer7_iface
;
4269 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4274 /*****************************************************************************
4275 * IDirect3D7::EnumZBufferFormats
4277 * Enumerates all supported Z buffer pixel formats
4283 * callback: callback to call for each pixel format
4284 * context: Pointer to pass back to the callback
4288 * DDERR_INVALIDPARAMS if callback is NULL
4290 *****************************************************************************/
4291 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4292 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4294 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4295 struct wined3d_display_mode mode
;
4296 enum wined3d_device_type type
;
4300 /* Order matters. Specifically, BattleZone II (full version) expects the
4301 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4302 static const enum wined3d_format_id formats
[] =
4304 WINED3DFMT_S1_UINT_D15_UNORM
,
4305 WINED3DFMT_D16_UNORM
,
4306 WINED3DFMT_X8D24_UNORM
,
4307 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4308 WINED3DFMT_D24_UNORM_S8_UINT
,
4309 WINED3DFMT_D32_UNORM
,
4312 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4313 iface
, debugstr_guid(device_iid
), callback
, context
);
4315 if (!callback
) return DDERR_INVALIDPARAMS
;
4317 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4318 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4319 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4321 TRACE("Asked for HAL device.\n");
4322 type
= WINED3D_DEVICE_TYPE_HAL
;
4324 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4325 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4327 TRACE("Asked for SW device.\n");
4328 type
= WINED3D_DEVICE_TYPE_SW
;
4330 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4332 TRACE("Asked for REF device.\n");
4333 type
= WINED3D_DEVICE_TYPE_REF
;
4335 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4337 TRACE("Asked for NULLREF device.\n");
4338 type
= WINED3D_DEVICE_TYPE_NULLREF
;
4342 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4343 type
= WINED3D_DEVICE_TYPE_HAL
;
4346 wined3d_mutex_lock();
4347 /* We need an adapter format from somewhere to please wined3d and WGL.
4348 * Use the current display mode. So far all cards offer the same depth
4349 * stencil format for all modes, but if some do not and applications do
4350 * not like that we'll have to find some workaround, like iterating over
4351 * all imaginable formats and collecting all the depth stencil formats we
4353 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
4355 ERR("Failed to get display mode, hr %#x.\n", hr
);
4356 wined3d_mutex_unlock();
4360 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
4362 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4363 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_TEXTURE_2D
, formats
[i
])))
4365 DDPIXELFORMAT pformat
;
4367 memset(&pformat
, 0, sizeof(pformat
));
4368 pformat
.dwSize
= sizeof(pformat
);
4369 ddrawformat_from_wined3dformat(&pformat
, formats
[i
]);
4371 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
4372 hr
= callback(&pformat
, context
);
4373 if (hr
!= DDENUMRET_OK
)
4375 TRACE("Format enumeration cancelled by application.\n");
4376 wined3d_mutex_unlock();
4382 /* Historically some windows drivers used dwZBufferBitDepth=24 for WINED3DFMT_X8D24_UNORM,
4383 * while others used dwZBufferBitDepth=32. In either case the pitch matches a 32 bits per
4384 * pixel format, so we use dwZBufferBitDepth=32. Some games expect 24. Windows Vista and
4385 * newer enumerate both versions, so we do the same(bug 22434) */
4386 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4387 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_TEXTURE_2D
, WINED3DFMT_X8D24_UNORM
)))
4389 DDPIXELFORMAT x8d24
=
4391 sizeof(x8d24
), DDPF_ZBUFFER
, 0,
4392 {24}, {0x00000000}, {0x00ffffff}, {0x00000000}
4394 TRACE("Enumerating WINED3DFMT_X8D24_UNORM, dwZBufferBitDepth=24 version\n");
4395 callback(&x8d24
, context
);
4398 TRACE("End of enumeration.\n");
4400 wined3d_mutex_unlock();
4405 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
4406 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4408 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4410 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4411 iface
, debugstr_guid(device_iid
), callback
, context
);
4413 return d3d7_EnumZBufferFormats(&ddraw
->IDirect3D7_iface
, device_iid
, callback
, context
);
4416 /*****************************************************************************
4417 * IDirect3D7::EvictManagedTextures
4419 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
4420 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
4425 * D3D_OK, because it's a stub
4427 *****************************************************************************/
4428 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
4430 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4432 TRACE("iface %p!\n", iface
);
4434 wined3d_mutex_lock();
4435 if (ddraw
->flags
& DDRAW_D3D_INITIALIZED
)
4436 wined3d_device_evict_managed_resources(ddraw
->wined3d_device
);
4437 wined3d_mutex_unlock();
4442 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
4444 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4446 TRACE("iface %p.\n", iface
);
4448 return d3d7_EvictManagedTextures(&ddraw
->IDirect3D7_iface
);
4451 /*****************************************************************************
4452 * IDirectDraw7 VTable
4453 *****************************************************************************/
4454 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
4457 ddraw7_QueryInterface
,
4462 ddraw7_CreateClipper
,
4463 ddraw7_CreatePalette
,
4464 ddraw7_CreateSurface
,
4465 ddraw7_DuplicateSurface
,
4466 ddraw7_EnumDisplayModes
,
4467 ddraw7_EnumSurfaces
,
4468 ddraw7_FlipToGDISurface
,
4470 ddraw7_GetDisplayMode
,
4471 ddraw7_GetFourCCCodes
,
4472 ddraw7_GetGDISurface
,
4473 ddraw7_GetMonitorFrequency
,
4475 ddraw7_GetVerticalBlankStatus
,
4477 ddraw7_RestoreDisplayMode
,
4478 ddraw7_SetCooperativeLevel
,
4479 ddraw7_SetDisplayMode
,
4480 ddraw7_WaitForVerticalBlank
,
4482 ddraw7_GetAvailableVidMem
,
4484 ddraw7_GetSurfaceFromDC
,
4486 ddraw7_RestoreAllSurfaces
,
4487 ddraw7_TestCooperativeLevel
,
4488 ddraw7_GetDeviceIdentifier
,
4490 ddraw7_StartModeTest
,
4494 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
4497 ddraw4_QueryInterface
,
4502 ddraw4_CreateClipper
,
4503 ddraw4_CreatePalette
,
4504 ddraw4_CreateSurface
,
4505 ddraw4_DuplicateSurface
,
4506 ddraw4_EnumDisplayModes
,
4507 ddraw4_EnumSurfaces
,
4508 ddraw4_FlipToGDISurface
,
4510 ddraw4_GetDisplayMode
,
4511 ddraw4_GetFourCCCodes
,
4512 ddraw4_GetGDISurface
,
4513 ddraw4_GetMonitorFrequency
,
4515 ddraw4_GetVerticalBlankStatus
,
4517 ddraw4_RestoreDisplayMode
,
4518 ddraw4_SetCooperativeLevel
,
4519 ddraw4_SetDisplayMode
,
4520 ddraw4_WaitForVerticalBlank
,
4522 ddraw4_GetAvailableVidMem
,
4524 ddraw4_GetSurfaceFromDC
,
4526 ddraw4_RestoreAllSurfaces
,
4527 ddraw4_TestCooperativeLevel
,
4528 ddraw4_GetDeviceIdentifier
,
4531 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
4534 ddraw2_QueryInterface
,
4539 ddraw2_CreateClipper
,
4540 ddraw2_CreatePalette
,
4541 ddraw2_CreateSurface
,
4542 ddraw2_DuplicateSurface
,
4543 ddraw2_EnumDisplayModes
,
4544 ddraw2_EnumSurfaces
,
4545 ddraw2_FlipToGDISurface
,
4547 ddraw2_GetDisplayMode
,
4548 ddraw2_GetFourCCCodes
,
4549 ddraw2_GetGDISurface
,
4550 ddraw2_GetMonitorFrequency
,
4552 ddraw2_GetVerticalBlankStatus
,
4554 ddraw2_RestoreDisplayMode
,
4555 ddraw2_SetCooperativeLevel
,
4556 ddraw2_SetDisplayMode
,
4557 ddraw2_WaitForVerticalBlank
,
4559 ddraw2_GetAvailableVidMem
,
4562 static const struct IDirectDrawVtbl ddraw1_vtbl
=
4565 ddraw1_QueryInterface
,
4570 ddraw1_CreateClipper
,
4571 ddraw1_CreatePalette
,
4572 ddraw1_CreateSurface
,
4573 ddraw1_DuplicateSurface
,
4574 ddraw1_EnumDisplayModes
,
4575 ddraw1_EnumSurfaces
,
4576 ddraw1_FlipToGDISurface
,
4578 ddraw1_GetDisplayMode
,
4579 ddraw1_GetFourCCCodes
,
4580 ddraw1_GetGDISurface
,
4581 ddraw1_GetMonitorFrequency
,
4583 ddraw1_GetVerticalBlankStatus
,
4585 ddraw1_RestoreDisplayMode
,
4586 ddraw1_SetCooperativeLevel
,
4587 ddraw1_SetDisplayMode
,
4588 ddraw1_WaitForVerticalBlank
,
4591 static const struct IDirect3D7Vtbl d3d7_vtbl
=
4593 /* IUnknown methods */
4594 d3d7_QueryInterface
,
4597 /* IDirect3D7 methods */
4600 d3d7_CreateVertexBuffer
,
4601 d3d7_EnumZBufferFormats
,
4602 d3d7_EvictManagedTextures
4605 static const struct IDirect3D3Vtbl d3d3_vtbl
=
4607 /* IUnknown methods */
4608 d3d3_QueryInterface
,
4611 /* IDirect3D3 methods */
4614 d3d3_CreateMaterial
,
4615 d3d3_CreateViewport
,
4618 d3d3_CreateVertexBuffer
,
4619 d3d3_EnumZBufferFormats
,
4620 d3d3_EvictManagedTextures
4623 static const struct IDirect3D2Vtbl d3d2_vtbl
=
4625 /* IUnknown methods */
4626 d3d2_QueryInterface
,
4629 /* IDirect3D2 methods */
4632 d3d2_CreateMaterial
,
4633 d3d2_CreateViewport
,
4638 static const struct IDirect3DVtbl d3d1_vtbl
=
4640 /* IUnknown methods */
4641 d3d1_QueryInterface
,
4644 /* IDirect3D methods */
4648 d3d1_CreateMaterial
,
4649 d3d1_CreateViewport
,
4653 /*****************************************************************************
4656 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
4657 * if none was found.
4659 * This function is in ddraw.c and the DDraw object space because D3D7
4660 * vertex buffers are created using the IDirect3D interface to the ddraw
4661 * object, so they can be valid across D3D devices(theoretically. The ddraw
4662 * object also owns the wined3d device
4666 * fvf: Fvf to find the decl for
4669 * NULL in case of an error, the vertex declaration for the FVF otherwise.
4671 *****************************************************************************/
4672 struct wined3d_vertex_declaration
*ddraw_find_decl(struct ddraw
*This
, DWORD fvf
)
4674 struct wined3d_vertex_declaration
*pDecl
= NULL
;
4676 int p
, low
, high
; /* deliberately signed */
4677 struct FvfToDecl
*convertedDecls
= This
->decls
;
4679 TRACE("Searching for declaration for fvf %08x... ", fvf
);
4682 high
= This
->numConvertedDecls
- 1;
4683 while(low
<= high
) {
4684 p
= (low
+ high
) >> 1;
4686 if(convertedDecls
[p
].fvf
== fvf
) {
4687 TRACE("found %p\n", convertedDecls
[p
].decl
);
4688 return convertedDecls
[p
].decl
;
4689 } else if(convertedDecls
[p
].fvf
< fvf
) {
4695 TRACE("not found. Creating and inserting at position %d.\n", low
);
4697 hr
= wined3d_vertex_declaration_create_from_fvf(This
->wined3d_device
,
4698 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
4699 if (hr
!= S_OK
) return NULL
;
4701 if (This
->declArraySize
== This
->numConvertedDecls
)
4703 unsigned int grow
= max(This
->declArraySize
/ 2, 8);
4705 if (!(convertedDecls
= heap_realloc(convertedDecls
,
4706 (This
->numConvertedDecls
+ grow
) * sizeof(*convertedDecls
))))
4708 wined3d_vertex_declaration_decref(pDecl
);
4711 This
->decls
= convertedDecls
;
4712 This
->declArraySize
+= grow
;
4715 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
4716 convertedDecls
[low
].decl
= pDecl
;
4717 convertedDecls
[low
].fvf
= fvf
;
4718 This
->numConvertedDecls
++;
4720 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
4724 static inline struct ddraw
*ddraw_from_device_parent(struct wined3d_device_parent
*device_parent
)
4726 return CONTAINING_RECORD(device_parent
, struct ddraw
, device_parent
);
4729 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
4730 struct wined3d_device
*device
)
4732 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
4735 /* This is run from device_process_message() in wined3d, we can't take the
4737 /* FIXME: We only get mode change notifications in exclusive mode, but we
4738 * should mark surfaces as lost on mode changes in DDSCL_NORMAL mode as well. */
4739 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
4741 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4742 MONITORINFO monitor_info
;
4746 TRACE("device_parent %p.\n", device_parent
);
4748 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) || !ddraw
->swapchain_window
)
4750 TRACE("Nothing to resize.\n");
4754 monitor
= MonitorFromWindow(ddraw
->swapchain_window
, MONITOR_DEFAULTTOPRIMARY
);
4755 monitor_info
.cbSize
= sizeof(monitor_info
);
4756 if (!GetMonitorInfoW(monitor
, &monitor_info
))
4758 ERR("Failed to get monitor info.\n");
4762 r
= &monitor_info
.rcMonitor
;
4763 TRACE("Resizing window %p to %s.\n", ddraw
->swapchain_window
, wine_dbgstr_rect(r
));
4765 if (!SetWindowPos(ddraw
->swapchain_window
, HWND_TOP
, r
->left
, r
->top
,
4766 r
->right
- r
->left
, r
->bottom
- r
->top
, SWP_SHOWWINDOW
| SWP_NOACTIVATE
))
4767 ERR("Failed to resize window.\n");
4769 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_OK
);
4772 static void CDECL
device_parent_activate(struct wined3d_device_parent
*device_parent
, BOOL activate
)
4774 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4776 TRACE("device_parent %p, activate %#x.\n", device_parent
, activate
);
4780 ddraw
->device_state
= DDRAW_DEVICE_STATE_LOST
;
4781 exclusive_window
= NULL
;
4785 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_LOST
);
4789 void ddraw_update_lost_surfaces(struct ddraw
*ddraw
)
4791 struct ddraw_surface
*surface
;
4793 if (ddraw
->device_state
!= DDRAW_DEVICE_STATE_NOT_RESTORED
)
4796 LIST_FOR_EACH_ENTRY(surface
, &ddraw
->surface_list
, struct ddraw_surface
, surface_list_entry
)
4798 surface
->is_lost
= TRUE
;
4800 ddraw
->device_state
= DDRAW_DEVICE_STATE_OK
;
4803 static HRESULT CDECL
device_parent_surface_created(struct wined3d_device_parent
*device_parent
,
4804 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
4805 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
4807 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4808 struct ddraw_surface
*ddraw_surface
;
4810 TRACE("device_parent %p, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
4811 device_parent
, wined3d_texture
, sub_resource_idx
, parent
, parent_ops
);
4813 /* We have a swapchain or wined3d internal texture. */
4814 if (!wined3d_texture_get_parent(wined3d_texture
) || wined3d_texture_get_parent(wined3d_texture
) == ddraw
)
4817 *parent_ops
= &ddraw_null_wined3d_parent_ops
;
4822 if (!(ddraw_surface
= heap_alloc_zero(sizeof(*ddraw_surface
))))
4824 ERR("Failed to allocate surface memory.\n");
4825 return DDERR_OUTOFVIDEOMEMORY
;
4828 ddraw_surface_init(ddraw_surface
, ddraw
, wined3d_texture
, sub_resource_idx
, parent_ops
);
4829 *parent
= ddraw_surface
;
4831 ddraw_update_lost_surfaces(ddraw
);
4832 list_add_head(&ddraw
->surface_list
, &ddraw_surface
->surface_list_entry
);
4834 TRACE("Created ddraw surface %p.\n", ddraw_surface
);
4839 static HRESULT CDECL
device_parent_volume_created(struct wined3d_device_parent
*device_parent
,
4840 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
4841 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
4843 TRACE("device_parent %p, texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
4844 device_parent
, wined3d_texture
, sub_resource_idx
, parent
, parent_ops
);
4847 *parent_ops
= &ddraw_null_wined3d_parent_ops
;
4852 static void STDMETHODCALLTYPE
ddraw_frontbuffer_destroyed(void *parent
)
4854 struct ddraw
*ddraw
= parent
;
4855 ddraw
->wined3d_frontbuffer
= NULL
;
4858 static const struct wined3d_parent_ops ddraw_frontbuffer_parent_ops
=
4860 ddraw_frontbuffer_destroyed
,
4863 static HRESULT CDECL
device_parent_create_swapchain_texture(struct wined3d_device_parent
*device_parent
,
4864 void *container_parent
, const struct wined3d_resource_desc
*desc
, DWORD texture_flags
,
4865 struct wined3d_texture
**texture
)
4867 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4870 TRACE("device_parent %p, container_parent %p, desc %p, texture flags %#x, texture %p.\n",
4871 device_parent
, container_parent
, desc
, texture_flags
, texture
);
4873 if (ddraw
->wined3d_frontbuffer
)
4875 ERR("Frontbuffer already created.\n");
4879 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, desc
, 1, 1,
4880 texture_flags
| WINED3D_TEXTURE_CREATE_MAPPABLE
, NULL
, ddraw
, &ddraw_frontbuffer_parent_ops
, texture
)))
4882 WARN("Failed to create texture, hr %#x.\n", hr
);
4886 ddraw
->wined3d_frontbuffer
= *texture
;
4891 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
4892 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
4894 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4897 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent
, desc
, swapchain
);
4899 if (ddraw
->wined3d_swapchain
)
4901 ERR("Swapchain already created.\n");
4905 if (FAILED(hr
= wined3d_swapchain_create(ddraw
->wined3d_device
, desc
, NULL
,
4906 &ddraw_null_wined3d_parent_ops
, swapchain
)))
4907 WARN("Failed to create swapchain, hr %#x.\n", hr
);
4912 static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops
=
4914 device_parent_wined3d_device_created
,
4915 device_parent_mode_changed
,
4916 device_parent_activate
,
4917 device_parent_surface_created
,
4918 device_parent_volume_created
,
4919 device_parent_create_swapchain_texture
,
4920 device_parent_create_swapchain
,
4923 HRESULT
ddraw_init(struct ddraw
*ddraw
, DWORD flags
, enum wined3d_device_type device_type
)
4928 ddraw
->IDirectDraw7_iface
.lpVtbl
= &ddraw7_vtbl
;
4929 ddraw
->IDirectDraw_iface
.lpVtbl
= &ddraw1_vtbl
;
4930 ddraw
->IDirectDraw2_iface
.lpVtbl
= &ddraw2_vtbl
;
4931 ddraw
->IDirectDraw4_iface
.lpVtbl
= &ddraw4_vtbl
;
4932 ddraw
->IDirect3D_iface
.lpVtbl
= &d3d1_vtbl
;
4933 ddraw
->IDirect3D2_iface
.lpVtbl
= &d3d2_vtbl
;
4934 ddraw
->IDirect3D3_iface
.lpVtbl
= &d3d3_vtbl
;
4935 ddraw
->IDirect3D7_iface
.lpVtbl
= &d3d7_vtbl
;
4936 ddraw
->device_parent
.ops
= &ddraw_wined3d_device_parent_ops
;
4937 ddraw
->numIfaces
= 1;
4940 flags
|= DDRAW_WINED3D_FLAGS
;
4941 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
4943 flags
|= WINED3D_NO3D
;
4944 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
4946 WARN("Failed to create a wined3d object.\n");
4951 if (FAILED(hr
= wined3d_get_device_caps(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
, &caps
)))
4953 ERR("Failed to get device caps, hr %#x.\n", hr
);
4954 wined3d_decref(ddraw
->wined3d
);
4958 if (!(caps
.ddraw_caps
.caps
& WINEDDCAPS_3D
))
4960 WARN("Created a wined3d object without 3D support.\n");
4961 ddraw
->flags
|= DDRAW_NO3D
;
4964 if (FAILED(hr
= wined3d_device_create(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
,
4965 NULL
, 0, DDRAW_STRIDE_ALIGNMENT
, &ddraw
->device_parent
, &ddraw
->wined3d_device
)))
4967 WARN("Failed to create a wined3d device, hr %#x.\n", hr
);
4968 wined3d_decref(ddraw
->wined3d
);
4972 list_init(&ddraw
->surface_list
);