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
24 #include "ddraw_private.h"
26 #include <wine/exception.h>
28 static const struct ddraw
*exclusive_ddraw
;
29 static HWND exclusive_window
;
31 /* Device identifier. Don't relay it to WineD3D */
32 static const DDDEVICEIDENTIFIER2 deviceidentifier
=
34 "vga.dll", /* default 2D driver */
36 { { 0x00010001, 0x00010001 } },
38 /* a8373c10-7ac4-4deb-849a-009844d08b2d */
39 {0xa8373c10,0x7ac4,0x4deb, {0x84,0x9a,0x00,0x98,0x44,0xd0,0x8b,0x2d}},
43 static struct enum_device_entry
45 char interface_name
[100];
46 char device_name
[100];
47 const GUID
*device_guid
;
53 "WINE Direct3D7 Hardware Transform and Lighting acceleration using WineD3D",
55 &IID_IDirect3DTnLHalDevice
,
61 "WINE Direct3D7 Hardware acceleration using WineD3D",
63 &IID_IDirect3DHALDevice
,
69 "WINE Direct3D7 RGB Software Emulation using WineD3D",
71 &IID_IDirect3DRGBDevice
,
72 D3DDEVCAPS_HWTRANSFORMANDLIGHT
,
76 static void STDMETHODCALLTYPE
ddraw_null_wined3d_object_destroyed(void *parent
) {}
78 const struct wined3d_parent_ops ddraw_null_wined3d_parent_ops
=
80 ddraw_null_wined3d_object_destroyed
,
83 static inline struct ddraw
*impl_from_IDirectDraw(IDirectDraw
*iface
)
85 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw_iface
);
88 static inline struct ddraw
*impl_from_IDirectDraw2(IDirectDraw2
*iface
)
90 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw2_iface
);
93 static inline struct ddraw
*impl_from_IDirectDraw4(IDirectDraw4
*iface
)
95 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw4_iface
);
98 static inline struct ddraw
*impl_from_IDirectDraw7(IDirectDraw7
*iface
)
100 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw7_iface
);
103 static inline struct ddraw
*impl_from_IDirect3D(IDirect3D
*iface
)
105 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D_iface
);
108 static inline struct ddraw
*impl_from_IDirect3D2(IDirect3D2
*iface
)
110 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D2_iface
);
113 static inline struct ddraw
*impl_from_IDirect3D3(IDirect3D3
*iface
)
115 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D3_iface
);
118 static inline struct ddraw
*impl_from_IDirect3D7(IDirect3D7
*iface
)
120 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D7_iface
);
123 static HRESULT WINAPI
ddraw7_QueryInterface(IDirectDraw7
*iface
, REFIID riid
, void **out
)
125 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
127 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
132 return DDERR_INVALIDPARAMS
;
135 /* The refcount unit test revealed that an IDirect3D7 interface can only
136 * be queried from a DirectDraw object that was created as an IDirectDraw7
137 * interface. The older interfaces can query any IDirect3D version except
138 * 7, because they are all initially created as IDirectDraw. This isn't
139 * really crucial behavior, and messy to implement with the common
140 * creation function, so it has been left out here. */
141 if (IsEqualGUID(&IID_IDirectDraw7
, riid
)
142 || IsEqualGUID(&IID_IUnknown
, riid
))
144 *out
= &ddraw
->IDirectDraw7_iface
;
145 TRACE("Returning IDirectDraw7 interface %p.\n", *out
);
147 else if (IsEqualGUID(&IID_IDirectDraw4
, riid
))
149 *out
= &ddraw
->IDirectDraw4_iface
;
150 TRACE("Returning IDirectDraw4 interface %p.\n", *out
);
152 else if (IsEqualGUID(&IID_IDirectDraw2
, riid
))
154 *out
= &ddraw
->IDirectDraw2_iface
;
155 TRACE("Returning IDirectDraw2 interface %p.\n", *out
);
157 else if (IsEqualGUID(&IID_IDirectDraw
, riid
))
159 *out
= &ddraw
->IDirectDraw_iface
;
160 TRACE("Returning IDirectDraw interface %p.\n", *out
);
162 else if (IsEqualGUID(&IID_IDirect3D7
, riid
))
164 ddraw
->d3dversion
= 7;
165 *out
= &ddraw
->IDirect3D7_iface
;
166 TRACE("Returning Direct3D7 interface %p.\n", *out
);
168 else if (IsEqualGUID(&IID_IDirect3D3
, riid
))
170 ddraw
->d3dversion
= 3;
171 *out
= &ddraw
->IDirect3D3_iface
;
172 TRACE("Returning Direct3D3 interface %p.\n", *out
);
174 else if (IsEqualGUID(&IID_IDirect3D2
, riid
))
176 ddraw
->d3dversion
= 2;
177 *out
= &ddraw
->IDirect3D2_iface
;
178 TRACE("Returning Direct3D2 interface %p.\n", *out
);
180 else if (IsEqualGUID(&IID_IDirect3D
, riid
))
182 ddraw
->d3dversion
= 1;
183 *out
= &ddraw
->IDirect3D_iface
;
184 TRACE("Returning Direct3D interface %p.\n", *out
);
186 /* Unknown interface */
189 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
191 return E_NOINTERFACE
;
194 IUnknown_AddRef((IUnknown
*)*out
);
198 static HRESULT WINAPI
ddraw4_QueryInterface(IDirectDraw4
*iface
, REFIID riid
, void **object
)
200 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
202 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
204 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
207 static HRESULT WINAPI
ddraw2_QueryInterface(IDirectDraw2
*iface
, REFIID riid
, void **object
)
209 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
211 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
213 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
216 static HRESULT WINAPI
ddraw1_QueryInterface(IDirectDraw
*iface
, REFIID riid
, void **object
)
218 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
220 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
222 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
225 static HRESULT WINAPI
d3d7_QueryInterface(IDirect3D7
*iface
, REFIID riid
, void **object
)
227 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
229 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
231 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
234 static HRESULT WINAPI
d3d3_QueryInterface(IDirect3D3
*iface
, REFIID riid
, void **object
)
236 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
238 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
240 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
243 static HRESULT WINAPI
d3d2_QueryInterface(IDirect3D2
*iface
, REFIID riid
, void **object
)
245 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
247 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
249 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
252 static HRESULT WINAPI
d3d1_QueryInterface(IDirect3D
*iface
, REFIID riid
, void **object
)
254 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
256 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
258 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
261 /*****************************************************************************
262 * IDirectDraw7::AddRef
264 * Increases the interfaces refcount, basically
266 * DDraw refcounting is a bit tricky. The different DirectDraw interface
267 * versions have individual refcounts, but the IDirect3D interfaces do not.
268 * All interfaces are from one object, that means calling QueryInterface on an
269 * IDirectDraw7 interface for an IDirectDraw4 interface does not create a new
272 * That means all AddRef and Release implementations of IDirectDrawX work
273 * with their own counter, and IDirect3DX::AddRef thunk to IDirectDraw (1),
274 * except of IDirect3D7 which thunks to IDirectDraw7
276 * Returns: The new refcount
278 *****************************************************************************/
279 static ULONG WINAPI
ddraw7_AddRef(IDirectDraw7
*iface
)
281 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
282 ULONG ref
= InterlockedIncrement(&This
->ref7
);
284 TRACE("%p increasing refcount to %u.\n", This
, ref
);
286 if(ref
== 1) InterlockedIncrement(&This
->numIfaces
);
291 static ULONG WINAPI
ddraw4_AddRef(IDirectDraw4
*iface
)
293 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
294 ULONG ref
= InterlockedIncrement(&This
->ref4
);
296 TRACE("%p increasing refcount to %u.\n", This
, ref
);
298 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
303 static ULONG WINAPI
ddraw2_AddRef(IDirectDraw2
*iface
)
305 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
306 ULONG ref
= InterlockedIncrement(&This
->ref2
);
308 TRACE("%p increasing refcount to %u.\n", This
, ref
);
310 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
315 static ULONG WINAPI
ddraw1_AddRef(IDirectDraw
*iface
)
317 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
318 ULONG ref
= InterlockedIncrement(&This
->ref1
);
320 TRACE("%p increasing refcount to %u.\n", This
, ref
);
322 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
327 static ULONG WINAPI
d3d7_AddRef(IDirect3D7
*iface
)
329 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
331 TRACE("iface %p.\n", iface
);
333 return ddraw7_AddRef(&This
->IDirectDraw7_iface
);
336 static ULONG WINAPI
d3d3_AddRef(IDirect3D3
*iface
)
338 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
340 TRACE("iface %p.\n", iface
);
342 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
345 static ULONG WINAPI
d3d2_AddRef(IDirect3D2
*iface
)
347 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
349 TRACE("iface %p.\n", iface
);
351 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
354 static ULONG WINAPI
d3d1_AddRef(IDirect3D
*iface
)
356 struct ddraw
*This
= impl_from_IDirect3D(iface
);
358 TRACE("iface %p.\n", iface
);
360 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
363 static void ddraw_destroy_swapchain(struct ddraw
*ddraw
)
365 TRACE("Destroying the swapchain.\n");
367 wined3d_swapchain_decref(ddraw
->wined3d_swapchain
);
368 ddraw
->wined3d_swapchain
= NULL
;
370 if (!(ddraw
->flags
& DDRAW_NO3D
))
374 for (i
= 0; i
< ddraw
->numConvertedDecls
; ++i
)
376 wined3d_vertex_declaration_decref(ddraw
->decls
[i
].decl
);
378 HeapFree(GetProcessHeap(), 0, ddraw
->decls
);
379 ddraw
->numConvertedDecls
= 0;
381 if (FAILED(wined3d_device_uninit_3d(ddraw
->wined3d_device
)))
383 ERR("Failed to uninit 3D.\n");
387 /* Free the d3d window if one was created. */
388 if (ddraw
->d3d_window
&& ddraw
->d3d_window
!= ddraw
->dest_window
)
390 TRACE("Destroying the hidden render window %p.\n", ddraw
->d3d_window
);
391 DestroyWindow(ddraw
->d3d_window
);
392 ddraw
->d3d_window
= 0;
396 ddraw
->flags
&= ~DDRAW_D3D_INITIALIZED
;
400 wined3d_device_uninit_gdi(ddraw
->wined3d_device
);
403 ddraw_set_swapchain_window(ddraw
, NULL
);
405 TRACE("Swapchain destroyed.\n");
408 /*****************************************************************************
411 * Destroys a ddraw object if all refcounts are 0. This is to share code
412 * between the IDirectDrawX::Release functions
415 * This: DirectDraw object to destroy
417 *****************************************************************************/
418 static void ddraw_destroy(struct ddraw
*This
)
420 IDirectDraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, NULL
, DDSCL_NORMAL
);
421 IDirectDraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
423 /* Destroy the device window if we created one */
424 if(This
->devicewindow
!= 0)
426 TRACE(" (%p) Destroying the device window %p\n", This
, This
->devicewindow
);
427 DestroyWindow(This
->devicewindow
);
428 This
->devicewindow
= 0;
431 wined3d_mutex_lock();
432 list_remove(&This
->ddraw_list_entry
);
433 wined3d_mutex_unlock();
435 if (This
->wined3d_swapchain
)
436 ddraw_destroy_swapchain(This
);
437 wined3d_device_decref(This
->wined3d_device
);
438 wined3d_decref(This
->wined3d
);
441 This
->d3ddevice
->ddraw
= NULL
;
443 /* Now free the object */
444 HeapFree(GetProcessHeap(), 0, This
);
447 /*****************************************************************************
448 * IDirectDraw7::Release
450 * Decreases the refcount. If the refcount falls to 0, the object is destroyed
452 * Returns: The new refcount
453 *****************************************************************************/
454 static ULONG WINAPI
ddraw7_Release(IDirectDraw7
*iface
)
456 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
457 ULONG ref
= InterlockedDecrement(&This
->ref7
);
459 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
461 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
467 static ULONG WINAPI
ddraw4_Release(IDirectDraw4
*iface
)
469 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
470 ULONG ref
= InterlockedDecrement(&This
->ref4
);
472 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
474 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
480 static ULONG WINAPI
ddraw2_Release(IDirectDraw2
*iface
)
482 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
483 ULONG ref
= InterlockedDecrement(&This
->ref2
);
485 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
487 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
493 static ULONG WINAPI
ddraw1_Release(IDirectDraw
*iface
)
495 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
496 ULONG ref
= InterlockedDecrement(&This
->ref1
);
498 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
500 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
506 static ULONG WINAPI
d3d7_Release(IDirect3D7
*iface
)
508 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
510 TRACE("iface %p.\n", iface
);
512 return ddraw7_Release(&This
->IDirectDraw7_iface
);
515 static ULONG WINAPI
d3d3_Release(IDirect3D3
*iface
)
517 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
519 TRACE("iface %p.\n", iface
);
521 return ddraw1_Release(&This
->IDirectDraw_iface
);
524 static ULONG WINAPI
d3d2_Release(IDirect3D2
*iface
)
526 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
528 TRACE("iface %p.\n", iface
);
530 return ddraw1_Release(&This
->IDirectDraw_iface
);
533 static ULONG WINAPI
d3d1_Release(IDirect3D
*iface
)
535 struct ddraw
*This
= impl_from_IDirect3D(iface
);
537 TRACE("iface %p.\n", iface
);
539 return ddraw1_Release(&This
->IDirectDraw_iface
);
542 /*****************************************************************************
543 * IDirectDraw methods
544 *****************************************************************************/
546 static HRESULT
ddraw_set_focus_window(struct ddraw
*ddraw
, HWND window
)
548 /* FIXME: This looks wrong, exclusive mode should imply a destination
550 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) && ddraw
->dest_window
)
552 TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET.\n");
553 return DDERR_HWNDALREADYSET
;
556 ddraw
->focuswindow
= window
;
561 static HRESULT
ddraw_attach_d3d_device(struct ddraw
*ddraw
,
562 struct wined3d_swapchain_desc
*swapchain_desc
)
564 HWND window
= swapchain_desc
->device_window
;
567 TRACE("ddraw %p.\n", ddraw
);
569 if (!window
|| window
== GetDesktopWindow())
571 window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "Hidden D3D Window",
572 WS_DISABLED
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
573 NULL
, NULL
, NULL
, NULL
);
576 ERR("Failed to create window, last error %#x.\n", GetLastError());
580 ShowWindow(window
, SW_HIDE
); /* Just to be sure */
581 WARN("No window for the Direct3DDevice, created hidden window %p.\n", window
);
583 swapchain_desc
->device_window
= window
;
587 TRACE("Using existing window %p for Direct3D rendering.\n", window
);
589 ddraw
->d3d_window
= window
;
591 /* Set this NOW, otherwise creating the depth stencil surface will cause a
592 * recursive loop until ram or emulated video memory is full. */
593 ddraw
->flags
|= DDRAW_D3D_INITIALIZED
;
594 hr
= wined3d_device_init_3d(ddraw
->wined3d_device
, swapchain_desc
);
597 ddraw
->flags
&= ~DDRAW_D3D_INITIALIZED
;
601 ddraw
->declArraySize
= 2;
602 ddraw
->decls
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ddraw
->decls
) * ddraw
->declArraySize
);
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
.swap_effect
= WINED3D_SWAP_EFFECT_COPY
;
633 swapchain_desc
.device_window
= window
;
634 swapchain_desc
.windowed
= windowed
;
635 swapchain_desc
.flags
= WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH
;
637 if (!(ddraw
->flags
& DDRAW_NO3D
))
638 hr
= ddraw_attach_d3d_device(ddraw
, &swapchain_desc
);
640 hr
= wined3d_device_init_gdi(ddraw
->wined3d_device
, &swapchain_desc
);
644 ERR("Failed to create swapchain, hr %#x.\n", hr
);
648 if (!(ddraw
->wined3d_swapchain
= wined3d_device_get_swapchain(ddraw
->wined3d_device
, 0)))
650 ERR("Failed to get swapchain.\n");
651 return DDERR_INVALIDPARAMS
;
654 wined3d_swapchain_incref(ddraw
->wined3d_swapchain
);
655 ddraw_set_swapchain_window(ddraw
, window
);
657 if (ddraw
->primary
&& ddraw
->primary
->palette
)
658 wined3d_swapchain_set_palette(ddraw
->wined3d_swapchain
, ddraw
->primary
->palette
->wined3d_palette
);
663 /*****************************************************************************
664 * IDirectDraw7::RestoreDisplayMode
666 * Restores the display mode to what it was at creation time. Basically.
670 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
672 *****************************************************************************/
673 static HRESULT WINAPI
ddraw7_RestoreDisplayMode(IDirectDraw7
*iface
)
675 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
678 TRACE("iface %p.\n", iface
);
680 wined3d_mutex_lock();
682 if (!(ddraw
->flags
& DDRAW_RESTORE_MODE
))
684 wined3d_mutex_unlock();
688 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
690 wined3d_mutex_unlock();
691 return DDERR_NOEXCLUSIVEMODE
;
694 if (SUCCEEDED(hr
= wined3d_set_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, NULL
)))
695 ddraw
->flags
&= ~DDRAW_RESTORE_MODE
;
697 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_OK
);
699 wined3d_mutex_unlock();
704 static HRESULT WINAPI
ddraw4_RestoreDisplayMode(IDirectDraw4
*iface
)
706 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
708 TRACE("iface %p.\n", iface
);
710 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
713 static HRESULT WINAPI
ddraw2_RestoreDisplayMode(IDirectDraw2
*iface
)
715 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
717 TRACE("iface %p.\n", iface
);
719 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
722 static HRESULT WINAPI
ddraw1_RestoreDisplayMode(IDirectDraw
*iface
)
724 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
726 TRACE("iface %p.\n", iface
);
728 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
731 /*****************************************************************************
732 * IDirectDraw7::SetCooperativeLevel
734 * Sets the cooperative level for the DirectDraw object, and the window
735 * assigned to it. The cooperative level determines the general behavior
736 * of the DirectDraw application
738 * Warning: This is quite tricky, as it's not really documented which
739 * cooperative levels can be combined with each other. If a game fails
740 * after this function, try to check the cooperative levels passed on
741 * Windows, and if it returns something different.
743 * If you think that this function caused the failure because it writes a
744 * fixme, be sure to run again with a +ddraw trace.
746 * What is known about cooperative levels (See the ddraw modes test):
747 * DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN.
748 * DDSCL_NORMAL is not compatible with DDSCL_EXCLUSIVE.
749 * Unlike what msdn claims, DDSCL_NORMAL | DDSCL_FULLSCREEN is allowed.
750 * DDSCL_SETFOCUSWINDOW can be passed only in DDSCL_NORMAL mode, but after that
751 * DDSCL_EXCLUSIVE can be activated.
752 * DDSCL_SETFOCUSWINDOW may only be used with DDSCL_NOWINDOWCHANGES or
753 * DDSCL_CREATEDEVICEWINDOW.
755 * Handled flags: DDSCL_NORMAL, DDSCL_FULLSCREEN, DDSCL_EXCLUSIVE,
756 * DDSCL_CREATEDEVICEWINDOW, DDSCL_SETDEVICEWINDOW
757 * DDSCL_SETFOCUSWINDOW (partially),
758 * DDSCL_MULTITHREADED (work in progress)
759 * DDSCL_FPUPRESERVE (see device.c)
761 * Unsure about this: DDSCL_FPUSETUP
763 * These don't seem very important for wine:
764 * DDSCL_ALLOWREBOOT, DDSCL_NOWINDOWCHANGES, DDSCL_ALLOWMODEX
767 * DD_OK if the cooperative level was set successfully
768 * DDERR_INVALIDPARAMS if the passed cooperative level combination is invalid
769 * DDERR_HWNDALREADYSET if DDSCL_SETFOCUSWINDOW is passed in exclusive mode
770 * (Probably others too, have to investigate)
772 *****************************************************************************/
773 static HRESULT
ddraw_set_cooperative_level(struct ddraw
*ddraw
, HWND window
,
774 DWORD cooplevel
, BOOL restore_mode_on_normal
)
776 struct wined3d_rendertarget_view
*rtv
= NULL
, *dsv
= NULL
;
777 struct wined3d_stateblock
*stateblock
;
778 BOOL restore_state
= FALSE
;
781 TRACE("ddraw %p, window %p, flags %#x, restore_mode_on_normal %x.\n", ddraw
, window
, cooplevel
,
782 restore_mode_on_normal
);
783 DDRAW_dump_cooperativelevel(cooplevel
);
785 wined3d_mutex_lock();
787 if (ddraw
->flags
& DDRAW_SCL_RECURSIVE
)
789 WARN("Recursive call, returning DD_OK.\n");
793 ddraw
->flags
|= DDRAW_SCL_RECURSIVE
;
795 /* Tests suggest that we need one of them: */
796 if(!(cooplevel
& (DDSCL_SETFOCUSWINDOW
|
800 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
801 hr
= DDERR_INVALIDPARAMS
;
805 if ((cooplevel
& DDSCL_CREATEDEVICEWINDOW
) && !(cooplevel
& DDSCL_EXCLUSIVE
))
807 WARN("DDSCL_CREATEDEVICEWINDOW requires DDSCL_EXCLUSIVE.\n");
808 hr
= DDERR_INVALIDPARAMS
;
812 /* Handle those levels first which set various hwnds */
813 if ((cooplevel
& DDSCL_SETFOCUSWINDOW
) && !(cooplevel
& DDSCL_CREATEDEVICEWINDOW
))
815 /* This isn't compatible with a lot of flags */
816 if (cooplevel
& (DDSCL_MULTITHREADED
821 | DDSCL_SETDEVICEWINDOW
826 WARN("Called with incompatible flags, returning DDERR_INVALIDPARAMS.\n");
827 hr
= DDERR_INVALIDPARAMS
;
831 hr
= ddraw_set_focus_window(ddraw
, window
);
835 if (cooplevel
& DDSCL_EXCLUSIVE
)
837 if (!(cooplevel
& DDSCL_FULLSCREEN
) || !(window
|| (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)))
839 WARN("DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN and a window.\n");
840 hr
= DDERR_INVALIDPARAMS
;
844 if (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)
848 if (!ddraw
->focuswindow
&& !(cooplevel
& DDSCL_SETFOCUSWINDOW
))
850 WARN("No focus window set.\n");
851 hr
= DDERR_NOFOCUSWINDOW
;
855 device_window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "DirectDrawDeviceWnd",
856 WS_POPUP
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
857 NULL
, NULL
, NULL
, NULL
);
860 ERR("Failed to create window, last error %#x.\n", GetLastError());
865 ShowWindow(device_window
, SW_SHOW
);
866 TRACE("Created a device window %p.\n", device_window
);
868 /* Native apparently leaks the created device window if setting the
869 * focus window below fails. */
870 ddraw
->cooperative_level
|= DDSCL_CREATEDEVICEWINDOW
;
871 ddraw
->devicewindow
= device_window
;
873 if (cooplevel
& DDSCL_SETFOCUSWINDOW
)
881 if (FAILED(hr
= ddraw_set_focus_window(ddraw
, window
)))
885 window
= device_window
;
890 if (ddraw
->cooperative_level
& DDSCL_CREATEDEVICEWINDOW
)
891 DestroyWindow(ddraw
->devicewindow
);
892 ddraw
->devicewindow
= NULL
;
893 ddraw
->focuswindow
= NULL
;
896 if ((cooplevel
& DDSCL_FULLSCREEN
) != (ddraw
->cooperative_level
& DDSCL_FULLSCREEN
) || window
!= ddraw
->dest_window
)
898 if (ddraw
->cooperative_level
& DDSCL_FULLSCREEN
)
899 wined3d_device_restore_fullscreen_window(ddraw
->wined3d_device
, ddraw
->dest_window
, NULL
);
901 if (cooplevel
& DDSCL_FULLSCREEN
)
903 struct wined3d_display_mode display_mode
;
905 wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &display_mode
, NULL
);
906 wined3d_device_setup_fullscreen_window(ddraw
->wined3d_device
, window
,
907 display_mode
.width
, display_mode
.height
);
911 if ((cooplevel
& DDSCL_EXCLUSIVE
) && exclusive_window
!= window
)
913 ddraw
->device_state
= DDRAW_DEVICE_STATE_NOT_RESTORED
;
914 exclusive_window
= window
;
917 if (cooplevel
& DDSCL_MULTITHREADED
&& !(ddraw
->cooperative_level
& DDSCL_MULTITHREADED
))
918 wined3d_device_set_multithreaded(ddraw
->wined3d_device
);
920 if (ddraw
->wined3d_swapchain
)
922 if (!(ddraw
->flags
& DDRAW_NO3D
))
924 restore_state
= TRUE
;
926 if (FAILED(hr
= wined3d_stateblock_create(ddraw
->wined3d_device
, WINED3D_SBT_ALL
, &stateblock
)))
928 ERR("Failed to create stateblock, hr %#x.\n", hr
);
932 wined3d_stateblock_capture(stateblock
);
933 rtv
= wined3d_device_get_rendertarget_view(ddraw
->wined3d_device
, 0);
934 /* Rendering to ddraw->wined3d_frontbuffer. */
935 if (rtv
&& !wined3d_rendertarget_view_get_sub_resource_parent(rtv
))
938 wined3d_rendertarget_view_incref(rtv
);
940 if ((dsv
= wined3d_device_get_depth_stencil_view(ddraw
->wined3d_device
)))
941 wined3d_rendertarget_view_incref(dsv
);
944 ddraw_destroy_swapchain(ddraw
);
947 if (FAILED(hr
= ddraw_create_swapchain(ddraw
, window
, !(cooplevel
& DDSCL_FULLSCREEN
))))
948 ERR("Failed to create swapchain, hr %#x.\n", hr
);
954 wined3d_device_set_depth_stencil_view(ddraw
->wined3d_device
, dsv
);
955 wined3d_rendertarget_view_decref(dsv
);
960 wined3d_device_set_rendertarget_view(ddraw
->wined3d_device
, 0, rtv
, FALSE
);
961 wined3d_rendertarget_view_decref(rtv
);
964 wined3d_stateblock_apply(stateblock
);
965 wined3d_stateblock_decref(stateblock
);
968 if (!(cooplevel
& DDSCL_EXCLUSIVE
) && (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
969 && restore_mode_on_normal
)
971 hr
= ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
973 ERR("RestoreDisplayMode failed\n");
976 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
977 && (window
!= ddraw
->dest_window
|| !(cooplevel
& DDSCL_EXCLUSIVE
)))
978 wined3d_device_release_focus_window(ddraw
->wined3d_device
);
980 if ((cooplevel
& DDSCL_EXCLUSIVE
)
981 && (window
!= ddraw
->dest_window
|| !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)))
983 hr
= wined3d_device_acquire_focus_window(ddraw
->wined3d_device
, window
);
986 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
991 /* Unhandled flags */
992 if (cooplevel
& DDSCL_ALLOWREBOOT
)
993 WARN("Unhandled flag DDSCL_ALLOWREBOOT, harmless\n");
994 if (cooplevel
& DDSCL_ALLOWMODEX
)
995 WARN("Unhandled flag DDSCL_ALLOWMODEX, harmless\n");
996 if (cooplevel
& DDSCL_FPUSETUP
)
997 WARN("Unhandled flag DDSCL_FPUSETUP, harmless\n");
999 if (cooplevel
& DDSCL_EXCLUSIVE
)
1000 exclusive_ddraw
= ddraw
;
1001 else if (exclusive_ddraw
== ddraw
)
1002 exclusive_ddraw
= NULL
;
1004 /* Store the cooperative_level */
1005 ddraw
->cooperative_level
= cooplevel
;
1006 ddraw
->dest_window
= window
;
1008 TRACE("SetCooperativeLevel returning DD_OK\n");
1011 ddraw
->flags
&= ~DDRAW_SCL_RECURSIVE
;
1012 wined3d_mutex_unlock();
1017 static HRESULT WINAPI
ddraw7_SetCooperativeLevel(IDirectDraw7
*iface
, HWND window
, DWORD flags
)
1019 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1021 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1023 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1026 static HRESULT WINAPI
ddraw4_SetCooperativeLevel(IDirectDraw4
*iface
, HWND window
, DWORD flags
)
1028 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1030 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1032 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1035 static HRESULT WINAPI
ddraw2_SetCooperativeLevel(IDirectDraw2
*iface
, HWND window
, DWORD flags
)
1037 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1039 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1041 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1044 static HRESULT WINAPI
ddraw1_SetCooperativeLevel(IDirectDraw
*iface
, HWND window
, DWORD flags
)
1046 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1049 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1051 hr
= ddraw_set_cooperative_level(ddraw
, window
, flags
, FALSE
);
1053 ddraw
->flags
|= DDRAW_SCL_DDRAW1
;
1057 /*****************************************************************************
1058 * IDirectDraw7::SetDisplayMode
1060 * Sets the display screen resolution, color depth and refresh frequency
1061 * when in fullscreen mode (in theory).
1062 * Possible return values listed in the SDK suggest that this method fails
1063 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
1064 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
1065 * It seems to be valid to pass 0 for With and Height, this has to be tested
1066 * It could mean that the current video mode should be left as-is. (But why
1070 * Height, Width: Screen dimension
1071 * BPP: Color depth in Bits per pixel
1072 * Refreshrate: Screen refresh rate
1073 * Flags: Other stuff
1078 *****************************************************************************/
1079 static HRESULT WINAPI
ddraw7_SetDisplayMode(IDirectDraw7
*iface
, DWORD width
, DWORD height
,
1080 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1082 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1083 struct wined3d_display_mode mode
;
1084 enum wined3d_format_id format
;
1087 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1088 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1090 if (force_refresh_rate
!= 0)
1092 TRACE("ForceRefreshRate overriding passed-in refresh rate (%u Hz) to %u Hz\n",
1093 refresh_rate
, force_refresh_rate
);
1094 refresh_rate
= force_refresh_rate
;
1097 wined3d_mutex_lock();
1099 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
1101 wined3d_mutex_unlock();
1102 return DDERR_NOEXCLUSIVEMODE
;
1105 if (!width
|| !height
)
1107 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here. */
1108 wined3d_mutex_unlock();
1114 case 8: format
= WINED3DFMT_P8_UINT
; break;
1115 case 15: format
= WINED3DFMT_B5G5R5X1_UNORM
; break;
1116 case 16: format
= WINED3DFMT_B5G6R5_UNORM
; break;
1117 case 24: format
= WINED3DFMT_B8G8R8_UNORM
; break;
1118 case 32: format
= WINED3DFMT_B8G8R8X8_UNORM
; break;
1119 default: format
= WINED3DFMT_UNKNOWN
; break;
1123 mode
.height
= height
;
1124 mode
.refresh_rate
= refresh_rate
;
1125 mode
.format_id
= format
;
1126 mode
.scanline_ordering
= WINED3D_SCANLINE_ORDERING_UNKNOWN
;
1128 /* TODO: The possible return values from msdn suggest that the screen mode
1129 * can't be changed if a surface is locked or some drawing is in progress. */
1130 if (SUCCEEDED(hr
= wined3d_set_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
)))
1134 DDSURFACEDESC2
*surface_desc
= &ddraw
->primary
->surface_desc
;
1136 if (FAILED(hr
= wined3d_swapchain_resize_buffers(ddraw
->wined3d_swapchain
, 0,
1137 surface_desc
->dwWidth
, surface_desc
->dwHeight
, mode
.format_id
, WINED3D_MULTISAMPLE_NONE
, 0)))
1138 ERR("Failed to resize buffers, hr %#x.\n", hr
);
1140 ddrawformat_from_wined3dformat(&ddraw
->primary
->surface_desc
.u4
.ddpfPixelFormat
, mode
.format_id
);
1142 ddraw
->flags
|= DDRAW_RESTORE_MODE
;
1145 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_OK
);
1147 wined3d_mutex_unlock();
1151 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1156 static HRESULT WINAPI
ddraw4_SetDisplayMode(IDirectDraw4
*iface
, DWORD width
, DWORD height
,
1157 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1159 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1161 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1162 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1164 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1167 static HRESULT WINAPI
ddraw2_SetDisplayMode(IDirectDraw2
*iface
,
1168 DWORD width
, DWORD height
, DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1170 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1172 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1173 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1175 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1178 static HRESULT WINAPI
ddraw1_SetDisplayMode(IDirectDraw
*iface
, DWORD width
, DWORD height
, DWORD bpp
)
1180 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1182 TRACE("iface %p, width %u, height %u, bpp %u.\n", iface
, width
, height
, bpp
);
1184 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, 0, 0);
1187 void ddraw_d3dcaps1_from_7(D3DDEVICEDESC
*caps1
, D3DDEVICEDESC7
*caps7
)
1189 memset(caps1
, 0, sizeof(*caps1
));
1190 caps1
->dwSize
= sizeof(*caps1
);
1191 caps1
->dwFlags
= D3DDD_COLORMODEL
1193 | D3DDD_TRANSFORMCAPS
1195 | D3DDD_LIGHTINGCAPS
1198 | D3DDD_DEVICERENDERBITDEPTH
1199 | D3DDD_DEVICEZBUFFERBITDEPTH
1200 | D3DDD_MAXBUFFERSIZE
1201 | D3DDD_MAXVERTEXCOUNT
;
1202 caps1
->dcmColorModel
= D3DCOLOR_RGB
;
1203 caps1
->dwDevCaps
= caps7
->dwDevCaps
;
1204 caps1
->dtcTransformCaps
.dwSize
= sizeof(caps1
->dtcTransformCaps
);
1205 caps1
->dtcTransformCaps
.dwCaps
= D3DTRANSFORMCAPS_CLIP
;
1206 caps1
->bClipping
= TRUE
;
1207 caps1
->dlcLightingCaps
.dwSize
= sizeof(caps1
->dlcLightingCaps
);
1208 caps1
->dlcLightingCaps
.dwCaps
= D3DLIGHTCAPS_DIRECTIONAL
1209 | D3DLIGHTCAPS_PARALLELPOINT
1210 | D3DLIGHTCAPS_POINT
1211 | D3DLIGHTCAPS_SPOT
;
1212 caps1
->dlcLightingCaps
.dwLightingModel
= D3DLIGHTINGMODEL_RGB
;
1213 caps1
->dlcLightingCaps
.dwNumLights
= caps7
->dwMaxActiveLights
;
1214 caps1
->dpcLineCaps
= caps7
->dpcLineCaps
;
1215 caps1
->dpcTriCaps
= caps7
->dpcTriCaps
;
1216 caps1
->dwDeviceRenderBitDepth
= caps7
->dwDeviceRenderBitDepth
;
1217 caps1
->dwDeviceZBufferBitDepth
= caps7
->dwDeviceZBufferBitDepth
;
1218 caps1
->dwMaxBufferSize
= 0;
1219 caps1
->dwMaxVertexCount
= 65536;
1220 caps1
->dwMinTextureWidth
= caps7
->dwMinTextureWidth
;
1221 caps1
->dwMinTextureHeight
= caps7
->dwMinTextureHeight
;
1222 caps1
->dwMaxTextureWidth
= caps7
->dwMaxTextureWidth
;
1223 caps1
->dwMaxTextureHeight
= caps7
->dwMaxTextureHeight
;
1224 caps1
->dwMinStippleWidth
= 1;
1225 caps1
->dwMinStippleHeight
= 1;
1226 caps1
->dwMaxStippleWidth
= 32;
1227 caps1
->dwMaxStippleHeight
= 32;
1228 caps1
->dwMaxTextureRepeat
= caps7
->dwMaxTextureRepeat
;
1229 caps1
->dwMaxTextureAspectRatio
= caps7
->dwMaxTextureAspectRatio
;
1230 caps1
->dwMaxAnisotropy
= caps7
->dwMaxAnisotropy
;
1231 caps1
->dvGuardBandLeft
= caps7
->dvGuardBandLeft
;
1232 caps1
->dvGuardBandTop
= caps7
->dvGuardBandTop
;
1233 caps1
->dvGuardBandRight
= caps7
->dvGuardBandRight
;
1234 caps1
->dvGuardBandBottom
= caps7
->dvGuardBandBottom
;
1235 caps1
->dvExtentsAdjust
= caps7
->dvExtentsAdjust
;
1236 caps1
->dwStencilCaps
= caps7
->dwStencilCaps
;
1237 caps1
->dwFVFCaps
= caps7
->dwFVFCaps
;
1238 caps1
->dwTextureOpCaps
= caps7
->dwTextureOpCaps
;
1239 caps1
->wMaxTextureBlendStages
= caps7
->wMaxTextureBlendStages
;
1240 caps1
->wMaxSimultaneousTextures
= caps7
->wMaxSimultaneousTextures
;
1243 HRESULT
ddraw_get_d3dcaps(const struct ddraw
*ddraw
, D3DDEVICEDESC7
*caps
)
1245 WINED3DCAPS wined3d_caps
;
1248 TRACE("ddraw %p, caps %p.\n", ddraw
, caps
);
1250 memset(&wined3d_caps
, 0, sizeof(wined3d_caps
));
1252 wined3d_mutex_lock();
1253 hr
= wined3d_get_device_caps(ddraw
->wined3d
, 0, WINED3D_DEVICE_TYPE_HAL
, &wined3d_caps
);
1254 wined3d_mutex_unlock();
1257 WARN("Failed to get device caps, hr %#x.\n", hr
);
1261 caps
->dwDevCaps
= wined3d_caps
.DevCaps
;
1262 caps
->dpcLineCaps
.dwMiscCaps
= wined3d_caps
.PrimitiveMiscCaps
;
1263 caps
->dpcLineCaps
.dwRasterCaps
= wined3d_caps
.RasterCaps
;
1264 caps
->dpcLineCaps
.dwZCmpCaps
= wined3d_caps
.ZCmpCaps
;
1265 caps
->dpcLineCaps
.dwSrcBlendCaps
= wined3d_caps
.SrcBlendCaps
;
1266 caps
->dpcLineCaps
.dwDestBlendCaps
= wined3d_caps
.DestBlendCaps
;
1267 caps
->dpcLineCaps
.dwAlphaCmpCaps
= wined3d_caps
.AlphaCmpCaps
;
1268 caps
->dpcLineCaps
.dwShadeCaps
= wined3d_caps
.ShadeCaps
;
1269 caps
->dpcLineCaps
.dwTextureCaps
= wined3d_caps
.TextureCaps
;
1270 caps
->dpcLineCaps
.dwTextureFilterCaps
= wined3d_caps
.TextureFilterCaps
;
1271 caps
->dpcLineCaps
.dwTextureAddressCaps
= wined3d_caps
.TextureAddressCaps
;
1273 caps
->dwMaxTextureWidth
= wined3d_caps
.MaxTextureWidth
;
1274 caps
->dwMaxTextureHeight
= wined3d_caps
.MaxTextureHeight
;
1276 caps
->dwMaxTextureRepeat
= wined3d_caps
.MaxTextureRepeat
;
1277 caps
->dwMaxTextureAspectRatio
= wined3d_caps
.MaxTextureAspectRatio
;
1278 caps
->dwMaxAnisotropy
= wined3d_caps
.MaxAnisotropy
;
1279 caps
->dvMaxVertexW
= wined3d_caps
.MaxVertexW
;
1281 caps
->dvGuardBandLeft
= wined3d_caps
.GuardBandLeft
;
1282 caps
->dvGuardBandTop
= wined3d_caps
.GuardBandTop
;
1283 caps
->dvGuardBandRight
= wined3d_caps
.GuardBandRight
;
1284 caps
->dvGuardBandBottom
= wined3d_caps
.GuardBandBottom
;
1286 caps
->dvExtentsAdjust
= wined3d_caps
.ExtentsAdjust
;
1287 caps
->dwStencilCaps
= wined3d_caps
.StencilCaps
;
1289 caps
->dwFVFCaps
= wined3d_caps
.FVFCaps
;
1290 caps
->dwTextureOpCaps
= wined3d_caps
.TextureOpCaps
;
1292 caps
->dwVertexProcessingCaps
= wined3d_caps
.VertexProcessingCaps
;
1293 caps
->dwMaxActiveLights
= wined3d_caps
.MaxActiveLights
;
1295 /* Remove all non-d3d7 caps */
1296 caps
->dwDevCaps
&= (
1297 D3DDEVCAPS_FLOATTLVERTEX
| D3DDEVCAPS_SORTINCREASINGZ
| D3DDEVCAPS_SORTDECREASINGZ
|
1298 D3DDEVCAPS_SORTEXACT
| D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
|
1299 D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
| D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
|
1300 D3DDEVCAPS_TEXTUREVIDEOMEMORY
| D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
|
1301 D3DDEVCAPS_TEXTURENONLOCALVIDMEM
| D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
1302 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
1303 D3DDEVCAPS_HWRASTERIZATION
);
1305 caps
->dwStencilCaps
&= (
1306 D3DSTENCILCAPS_KEEP
| D3DSTENCILCAPS_ZERO
| D3DSTENCILCAPS_REPLACE
|
1307 D3DSTENCILCAPS_INCRSAT
| D3DSTENCILCAPS_DECRSAT
| D3DSTENCILCAPS_INVERT
|
1308 D3DSTENCILCAPS_INCR
| D3DSTENCILCAPS_DECR
);
1312 caps
->dwTextureOpCaps
&= (
1313 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_SELECTARG2
|
1314 D3DTEXOPCAPS_MODULATE
| D3DTEXOPCAPS_MODULATE2X
| D3DTEXOPCAPS_MODULATE4X
|
1315 D3DTEXOPCAPS_ADD
| D3DTEXOPCAPS_ADDSIGNED
| D3DTEXOPCAPS_ADDSIGNED2X
|
1316 D3DTEXOPCAPS_SUBTRACT
| D3DTEXOPCAPS_ADDSMOOTH
| D3DTEXOPCAPS_BLENDTEXTUREALPHA
|
1317 D3DTEXOPCAPS_BLENDFACTORALPHA
| D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
| D3DTEXOPCAPS_BLENDCURRENTALPHA
|
1318 D3DTEXOPCAPS_PREMODULATE
| D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
|
1319 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
| D3DTEXOPCAPS_BUMPENVMAP
|
1320 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
| D3DTEXOPCAPS_DOTPRODUCT3
);
1322 caps
->dwVertexProcessingCaps
&= (
1323 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_VERTEXFOG
|
1324 D3DVTXPCAPS_DIRECTIONALLIGHTS
| D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
);
1326 caps
->dpcLineCaps
.dwMiscCaps
&= (
1327 D3DPMISCCAPS_MASKPLANES
| D3DPMISCCAPS_MASKZ
| D3DPMISCCAPS_LINEPATTERNREP
|
1328 D3DPMISCCAPS_CONFORMANT
| D3DPMISCCAPS_CULLNONE
| D3DPMISCCAPS_CULLCW
|
1329 D3DPMISCCAPS_CULLCCW
);
1331 caps
->dpcLineCaps
.dwRasterCaps
&= (
1332 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ROP2
| D3DPRASTERCAPS_XOR
|
1333 D3DPRASTERCAPS_PAT
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_SUBPIXEL
|
1334 D3DPRASTERCAPS_SUBPIXELX
| D3DPRASTERCAPS_FOGVERTEX
| D3DPRASTERCAPS_FOGTABLE
|
1335 D3DPRASTERCAPS_STIPPLE
| D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT
| D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT
|
1336 D3DPRASTERCAPS_ANTIALIASEDGES
| D3DPRASTERCAPS_MIPMAPLODBIAS
| D3DPRASTERCAPS_ZBIAS
|
1337 D3DPRASTERCAPS_ZBUFFERLESSHSR
| D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
|
1338 D3DPRASTERCAPS_WBUFFER
| D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT
| D3DPRASTERCAPS_WFOG
|
1339 D3DPRASTERCAPS_ZFOG
);
1341 caps
->dpcLineCaps
.dwZCmpCaps
&= (
1342 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
1343 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
1344 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
1346 caps
->dpcLineCaps
.dwSrcBlendCaps
&= (
1347 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
1348 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
1349 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
1350 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
1351 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
1353 caps
->dpcLineCaps
.dwDestBlendCaps
&= (
1354 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
1355 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
1356 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
1357 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
1358 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
1360 caps
->dpcLineCaps
.dwAlphaCmpCaps
&= (
1361 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
1362 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
1363 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
1365 caps
->dpcLineCaps
.dwShadeCaps
&= (
1366 D3DPSHADECAPS_COLORFLATMONO
| D3DPSHADECAPS_COLORFLATRGB
| D3DPSHADECAPS_COLORGOURAUDMONO
|
1367 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_COLORPHONGMONO
| D3DPSHADECAPS_COLORPHONGRGB
|
1368 D3DPSHADECAPS_SPECULARFLATMONO
| D3DPSHADECAPS_SPECULARFLATRGB
| D3DPSHADECAPS_SPECULARGOURAUDMONO
|
1369 D3DPSHADECAPS_SPECULARGOURAUDRGB
| D3DPSHADECAPS_SPECULARPHONGMONO
| D3DPSHADECAPS_SPECULARPHONGRGB
|
1370 D3DPSHADECAPS_ALPHAFLATBLEND
| D3DPSHADECAPS_ALPHAFLATSTIPPLED
| D3DPSHADECAPS_ALPHAGOURAUDBLEND
|
1371 D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED
| D3DPSHADECAPS_ALPHAPHONGBLEND
| D3DPSHADECAPS_ALPHAPHONGSTIPPLED
|
1372 D3DPSHADECAPS_FOGFLAT
| D3DPSHADECAPS_FOGGOURAUD
| D3DPSHADECAPS_FOGPHONG
);
1374 caps
->dpcLineCaps
.dwTextureCaps
&= (
1375 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
1376 D3DPTEXTURECAPS_TRANSPARENCY
| D3DPTEXTURECAPS_BORDER
| D3DPTEXTURECAPS_SQUAREONLY
|
1377 D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
| D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
1378 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_COLORKEYBLEND
);
1380 caps
->dpcLineCaps
.dwTextureFilterCaps
&= (
1381 D3DPTFILTERCAPS_NEAREST
| D3DPTFILTERCAPS_LINEAR
| D3DPTFILTERCAPS_MIPNEAREST
|
1382 D3DPTFILTERCAPS_MIPLINEAR
| D3DPTFILTERCAPS_LINEARMIPNEAREST
| D3DPTFILTERCAPS_LINEARMIPLINEAR
|
1383 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
1384 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
1385 D3DPTFILTERCAPS_MAGFLINEAR
| D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
|
1386 D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
);
1388 caps
->dpcLineCaps
.dwTextureAddressCaps
&= (
1389 D3DPTADDRESSCAPS_WRAP
| D3DPTADDRESSCAPS_MIRROR
| D3DPTADDRESSCAPS_CLAMP
|
1390 D3DPTADDRESSCAPS_BORDER
| D3DPTADDRESSCAPS_INDEPENDENTUV
);
1392 if (!(caps
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
))
1394 /* DirectX7 always has the np2 flag set, no matter what the card
1395 * supports. Some old games (Rollcage) check the caps incorrectly.
1396 * If wined3d supports nonpow2 textures it also has np2 conditional
1398 caps
->dpcLineCaps
.dwTextureCaps
|= D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
;
1401 /* Fill the missing members, and do some fixup */
1402 caps
->dpcLineCaps
.dwSize
= sizeof(caps
->dpcLineCaps
);
1403 caps
->dpcLineCaps
.dwTextureBlendCaps
= D3DPTBLENDCAPS_ADD
1404 | D3DPTBLENDCAPS_MODULATEMASK
1405 | D3DPTBLENDCAPS_COPY
1406 | D3DPTBLENDCAPS_DECAL
1407 | D3DPTBLENDCAPS_DECALALPHA
1408 | D3DPTBLENDCAPS_DECALMASK
1409 | D3DPTBLENDCAPS_MODULATE
1410 | D3DPTBLENDCAPS_MODULATEALPHA
;
1411 caps
->dpcLineCaps
.dwStippleWidth
= 32;
1412 caps
->dpcLineCaps
.dwStippleHeight
= 32;
1413 /* Use the same for the TriCaps */
1414 caps
->dpcTriCaps
= caps
->dpcLineCaps
;
1416 caps
->dwDeviceRenderBitDepth
= DDBD_16
| DDBD_24
| DDBD_32
;
1417 caps
->dwDeviceZBufferBitDepth
= DDBD_16
| DDBD_24
;
1418 caps
->dwMinTextureWidth
= 1;
1419 caps
->dwMinTextureHeight
= 1;
1421 /* Convert DWORDs safely to WORDs */
1422 if (wined3d_caps
.MaxTextureBlendStages
> 0xffff)
1423 caps
->wMaxTextureBlendStages
= 0xffff;
1425 caps
->wMaxTextureBlendStages
= (WORD
)wined3d_caps
.MaxTextureBlendStages
;
1426 if (wined3d_caps
.MaxSimultaneousTextures
> 0xffff)
1427 caps
->wMaxSimultaneousTextures
= 0xffff;
1429 caps
->wMaxSimultaneousTextures
= (WORD
)wined3d_caps
.MaxSimultaneousTextures
;
1431 if (wined3d_caps
.MaxUserClipPlanes
> 0xffff)
1432 caps
->wMaxUserClipPlanes
= 0xffff;
1434 caps
->wMaxUserClipPlanes
= (WORD
)wined3d_caps
.MaxUserClipPlanes
;
1435 if (wined3d_caps
.MaxVertexBlendMatrices
> 0xffff)
1436 caps
->wMaxVertexBlendMatrices
= 0xffff;
1438 caps
->wMaxVertexBlendMatrices
= (WORD
)wined3d_caps
.MaxVertexBlendMatrices
;
1440 caps
->deviceGUID
= IID_IDirect3DTnLHalDevice
;
1442 caps
->dwReserved1
= 0;
1443 caps
->dwReserved2
= 0;
1444 caps
->dwReserved3
= 0;
1445 caps
->dwReserved4
= 0;
1450 HRESULT CALLBACK
enum_zbuffer(DDPIXELFORMAT
*format
, void *ctx
)
1454 switch (format
->u1
.dwZBufferBitDepth
)
1457 caps
->dwZBufferBitDepths
|= DDBD_8
;
1460 caps
->dwZBufferBitDepths
|= DDBD_16
;
1463 caps
->dwZBufferBitDepths
|= DDBD_24
;
1466 caps
->dwZBufferBitDepths
|= DDBD_32
;
1469 return D3DENUMRET_OK
;
1472 /*****************************************************************************
1473 * IDirectDraw7::GetCaps
1475 * Returns the drives capabilities
1477 * Used for version 1, 2, 4 and 7
1480 * DriverCaps: Structure to write the Hardware accelerated caps to
1481 * HelCaps: Structure to write the emulation caps to
1484 * This implementation returns DD_OK only
1486 *****************************************************************************/
1487 static HRESULT WINAPI
ddraw7_GetCaps(IDirectDraw7
*iface
, DDCAPS
*DriverCaps
, DDCAPS
*HELCaps
)
1489 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1491 WINED3DCAPS winecaps
;
1493 DDSCAPS2 ddscaps
= {0, 0, 0, {0}};
1495 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, DriverCaps
, HELCaps
);
1497 /* One structure must be != NULL */
1498 if (!DriverCaps
&& !HELCaps
)
1500 WARN("Invalid parameters.\n");
1501 return DDERR_INVALIDPARAMS
;
1504 memset(&caps
, 0, sizeof(caps
));
1505 memset(&winecaps
, 0, sizeof(winecaps
));
1506 caps
.dwSize
= sizeof(caps
);
1508 wined3d_mutex_lock();
1509 hr
= wined3d_device_get_device_caps(ddraw
->wined3d_device
, &winecaps
);
1512 WARN("Failed to get device caps, %#x.\n", hr
);
1513 wined3d_mutex_unlock();
1517 hr
= IDirectDraw7_GetAvailableVidMem(iface
, &ddscaps
, &caps
.dwVidMemTotal
, &caps
.dwVidMemFree
);
1520 WARN("IDirectDraw7::GetAvailableVidMem failed\n");
1521 wined3d_mutex_unlock();
1525 hr
= IDirectDraw7_GetFourCCCodes(iface
, &caps
.dwNumFourCCCodes
, NULL
);
1526 wined3d_mutex_unlock();
1529 WARN("IDirectDraw7::GetFourCCCodes failed\n");
1533 caps
.dwCaps
= winecaps
.ddraw_caps
.caps
;
1534 caps
.dwCaps2
= winecaps
.ddraw_caps
.caps2
;
1535 caps
.dwCKeyCaps
= winecaps
.ddraw_caps
.color_key_caps
;
1536 caps
.dwFXCaps
= winecaps
.ddraw_caps
.fx_caps
;
1537 caps
.dwPalCaps
= DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
;
1538 caps
.ddsCaps
.dwCaps
= winecaps
.ddraw_caps
.dds_caps
;
1539 caps
.dwSVBCaps
= winecaps
.ddraw_caps
.svb_caps
;
1540 caps
.dwSVBCKeyCaps
= winecaps
.ddraw_caps
.svb_color_key_caps
;
1541 caps
.dwSVBFXCaps
= winecaps
.ddraw_caps
.svb_fx_caps
;
1542 caps
.dwVSBCaps
= winecaps
.ddraw_caps
.vsb_caps
;
1543 caps
.dwVSBCKeyCaps
= winecaps
.ddraw_caps
.vsb_color_key_caps
;
1544 caps
.dwVSBFXCaps
= winecaps
.ddraw_caps
.vsb_fx_caps
;
1545 caps
.dwSSBCaps
= winecaps
.ddraw_caps
.ssb_caps
;
1546 caps
.dwSSBCKeyCaps
= winecaps
.ddraw_caps
.ssb_color_key_caps
;
1547 caps
.dwSSBFXCaps
= winecaps
.ddraw_caps
.ssb_fx_caps
;
1549 caps
.dwCaps
|= DDCAPS_ALIGNSTRIDE
;
1550 caps
.dwAlignStrideAlign
= DDRAW_STRIDE_ALIGNMENT
;
1552 caps
.ddsOldCaps
.dwCaps
= caps
.ddsCaps
.dwCaps
;
1554 IDirect3D7_EnumZBufferFormats(&ddraw
->IDirect3D7_iface
, &IID_IDirect3DHALDevice
, enum_zbuffer
, &caps
);
1558 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &caps
);
1559 if (TRACE_ON(ddraw
))
1561 TRACE("Driver Caps :\n");
1562 DDRAW_dump_DDCAPS(DriverCaps
);
1568 DD_STRUCT_COPY_BYSIZE(HELCaps
, &caps
);
1569 if (TRACE_ON(ddraw
))
1571 TRACE("HEL Caps :\n");
1572 DDRAW_dump_DDCAPS(HELCaps
);
1579 static HRESULT WINAPI
ddraw4_GetCaps(IDirectDraw4
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1581 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1583 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1585 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1588 static HRESULT WINAPI
ddraw2_GetCaps(IDirectDraw2
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1590 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1592 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1594 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1597 static HRESULT WINAPI
ddraw1_GetCaps(IDirectDraw
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1599 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1601 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1603 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1606 /*****************************************************************************
1607 * IDirectDraw7::Compact
1609 * No idea what it does, MSDN says it's not implemented.
1612 * DD_OK, but this is unchecked
1614 *****************************************************************************/
1615 static HRESULT WINAPI
ddraw7_Compact(IDirectDraw7
*iface
)
1617 TRACE("iface %p.\n", iface
);
1622 static HRESULT WINAPI
ddraw4_Compact(IDirectDraw4
*iface
)
1624 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1626 TRACE("iface %p.\n", iface
);
1628 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1631 static HRESULT WINAPI
ddraw2_Compact(IDirectDraw2
*iface
)
1633 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1635 TRACE("iface %p.\n", iface
);
1637 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1640 static HRESULT WINAPI
ddraw1_Compact(IDirectDraw
*iface
)
1642 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1644 TRACE("iface %p.\n", iface
);
1646 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1649 /*****************************************************************************
1650 * IDirectDraw7::GetDisplayMode
1652 * Returns information about the current display mode
1654 * Exists in versions 1, 2, 4 and 7
1657 * DDSD: Address of a surface description structure to write the info to
1662 *****************************************************************************/
1663 static HRESULT WINAPI
ddraw7_GetDisplayMode(IDirectDraw7
*iface
, DDSURFACEDESC2
*DDSD
)
1665 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1666 struct wined3d_display_mode mode
;
1670 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
1672 wined3d_mutex_lock();
1673 /* This seems sane */
1676 wined3d_mutex_unlock();
1677 return DDERR_INVALIDPARAMS
;
1680 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1682 ERR("Failed to get display mode, hr %#x.\n", hr
);
1683 wined3d_mutex_unlock();
1687 Size
= DDSD
->dwSize
;
1688 memset(DDSD
, 0, Size
);
1690 DDSD
->dwSize
= Size
;
1691 DDSD
->dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
1692 DDSD
->dwWidth
= mode
.width
;
1693 DDSD
->dwHeight
= mode
.height
;
1694 DDSD
->u2
.dwRefreshRate
= 60;
1695 DDSD
->ddsCaps
.dwCaps
= 0;
1696 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
1697 ddrawformat_from_wined3dformat(&DDSD
->u4
.ddpfPixelFormat
, mode
.format_id
);
1698 DDSD
->u1
.lPitch
= mode
.width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
1702 TRACE("Returning surface desc :\n");
1703 DDRAW_dump_surface_desc(DDSD
);
1706 wined3d_mutex_unlock();
1711 static HRESULT WINAPI
ddraw4_GetDisplayMode(IDirectDraw4
*iface
, DDSURFACEDESC2
*surface_desc
)
1713 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1715 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1717 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, surface_desc
);
1720 static HRESULT WINAPI
ddraw2_GetDisplayMode(IDirectDraw2
*iface
, DDSURFACEDESC
*surface_desc
)
1722 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1724 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1726 /* FIXME: Test sizes, properly convert surface_desc */
1727 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1730 static HRESULT WINAPI
ddraw1_GetDisplayMode(IDirectDraw
*iface
, DDSURFACEDESC
*surface_desc
)
1732 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1734 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1736 /* FIXME: Test sizes, properly convert surface_desc */
1737 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1740 /*****************************************************************************
1741 * IDirectDraw7::GetFourCCCodes
1743 * Returns an array of supported FourCC codes.
1745 * Exists in versions 1, 2, 4 and 7
1748 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
1749 * of enumerated codes
1750 * Codes: Pointer to an array of DWORDs where the supported codes are written
1754 * Always returns DD_OK, as it's a stub for now
1756 *****************************************************************************/
1757 static HRESULT WINAPI
ddraw7_GetFourCCCodes(IDirectDraw7
*iface
, DWORD
*NumCodes
, DWORD
*Codes
)
1759 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1760 static const enum wined3d_format_id formats
[] =
1762 WINED3DFMT_YUY2
, WINED3DFMT_UYVY
, WINED3DFMT_YV12
,
1763 WINED3DFMT_DXT1
, WINED3DFMT_DXT2
, WINED3DFMT_DXT3
, WINED3DFMT_DXT4
, WINED3DFMT_DXT5
,
1764 WINED3DFMT_ATI2N
, WINED3DFMT_NVHU
, WINED3DFMT_NVHS
1766 struct wined3d_display_mode mode
;
1767 DWORD count
= 0, i
, outsize
;
1770 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, NumCodes
, Codes
);
1772 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1774 ERR("Failed to get display mode, hr %#x.\n", hr
);
1778 outsize
= NumCodes
&& Codes
? *NumCodes
: 0;
1780 for (i
= 0; i
< (sizeof(formats
) / sizeof(formats
[0])); ++i
)
1782 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, WINED3D_DEVICE_TYPE_HAL
,
1783 mode
.format_id
, 0, WINED3D_RTYPE_TEXTURE_2D
, formats
[i
])))
1785 if (count
< outsize
)
1786 Codes
[count
] = formats
[i
];
1791 TRACE("Returning %u FourCC codes\n", count
);
1798 static HRESULT WINAPI
ddraw4_GetFourCCCodes(IDirectDraw4
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1800 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1802 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1804 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1807 static HRESULT WINAPI
ddraw2_GetFourCCCodes(IDirectDraw2
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1809 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1811 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1813 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1816 static HRESULT WINAPI
ddraw1_GetFourCCCodes(IDirectDraw
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1818 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1820 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1822 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1825 static HRESULT WINAPI
ddraw7_GetMonitorFrequency(IDirectDraw7
*iface
, DWORD
*frequency
)
1827 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1828 struct wined3d_display_mode mode
;
1831 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1833 wined3d_mutex_lock();
1834 hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
);
1835 wined3d_mutex_unlock();
1838 WARN("Failed to get display mode, hr %#x.\n", hr
);
1842 *frequency
= mode
.refresh_rate
;
1847 static HRESULT WINAPI
ddraw4_GetMonitorFrequency(IDirectDraw4
*iface
, DWORD
*frequency
)
1849 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1851 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1853 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1856 static HRESULT WINAPI
ddraw2_GetMonitorFrequency(IDirectDraw2
*iface
, DWORD
*frequency
)
1858 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1860 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1862 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1865 static HRESULT WINAPI
ddraw1_GetMonitorFrequency(IDirectDraw
*iface
, DWORD
*frequency
)
1867 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1869 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1871 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1874 static HRESULT WINAPI
ddraw7_GetVerticalBlankStatus(IDirectDraw7
*iface
, BOOL
*status
)
1876 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1877 struct wined3d_raster_status raster_status
;
1880 TRACE("iface %p, status %p.\n", iface
, status
);
1883 return DDERR_INVALIDPARAMS
;
1885 wined3d_mutex_lock();
1886 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
1887 wined3d_mutex_unlock();
1890 WARN("Failed to get raster status, hr %#x.\n", hr
);
1894 *status
= raster_status
.in_vblank
;
1899 static HRESULT WINAPI
ddraw4_GetVerticalBlankStatus(IDirectDraw4
*iface
, BOOL
*status
)
1901 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1903 TRACE("iface %p, status %p.\n", iface
, status
);
1905 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1908 static HRESULT WINAPI
ddraw2_GetVerticalBlankStatus(IDirectDraw2
*iface
, BOOL
*status
)
1910 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1912 TRACE("iface %p, status %p.\n", iface
, status
);
1914 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1917 static HRESULT WINAPI
ddraw1_GetVerticalBlankStatus(IDirectDraw
*iface
, BOOL
*status
)
1919 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1921 TRACE("iface %p, status %p.\n", iface
, status
);
1923 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1926 /*****************************************************************************
1927 * IDirectDraw7::GetAvailableVidMem
1929 * Returns the total and free video memory
1932 * caps: Specifies the memory type asked for
1933 * total: Pointer to a DWORD to be filled with the total memory
1934 * free: Pointer to a DWORD to be filled with the free memory
1938 * DDERR_INVALIDPARAMS if free and total are NULL
1940 *****************************************************************************/
1941 static HRESULT WINAPI
ddraw7_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*caps
, DWORD
*total
,
1944 unsigned int framebuffer_size
, total_vidmem
, free_vidmem
;
1945 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1946 struct wined3d_display_mode mode
;
1949 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1951 if (!total
&& !free
)
1952 return DDERR_INVALIDPARAMS
;
1954 if (TRACE_ON(ddraw
))
1956 TRACE("Asked for memory with description: ");
1957 DDRAW_dump_DDSCAPS2(caps
);
1959 wined3d_mutex_lock();
1961 /* Todo: System memory vs local video memory vs non-local video memory
1962 * The MSDN also mentions differences between texture memory and other
1963 * resources, but that's not important
1966 /* Some applications (e.g. 3DMark 2000) assume that the reported amount of
1967 * video memory doesn't include the memory used by the default framebuffer.
1969 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1971 WARN("Failed to get display mode, hr %#x.\n", hr
);
1972 wined3d_mutex_unlock();
1975 framebuffer_size
= wined3d_calculate_format_pitch(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
1976 mode
.format_id
, mode
.width
);
1977 framebuffer_size
*= mode
.height
;
1981 free_vidmem
= wined3d_device_get_available_texture_mem(ddraw
->wined3d_device
);
1982 *free
= framebuffer_size
> free_vidmem
? 0 : free_vidmem
- framebuffer_size
;
1983 TRACE("Free video memory %#x.\n", *free
);
1988 struct wined3d_adapter_identifier desc
= {0};
1990 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0, &desc
);
1991 total_vidmem
= min(UINT_MAX
, desc
.video_memory
);
1992 *total
= framebuffer_size
> total_vidmem
? 0 : total_vidmem
- framebuffer_size
;
1993 TRACE("Total video memory %#x.\n", *total
);
1996 wined3d_mutex_unlock();
2001 static HRESULT WINAPI
ddraw4_GetAvailableVidMem(IDirectDraw4
*iface
,
2002 DDSCAPS2
*caps
, DWORD
*total
, DWORD
*free
)
2004 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2006 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
2008 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, caps
, total
, free
);
2011 static HRESULT WINAPI
ddraw2_GetAvailableVidMem(IDirectDraw2
*iface
,
2012 DDSCAPS
*caps
, DWORD
*total
, DWORD
*free
)
2014 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2017 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
2019 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
2020 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, &caps2
, total
, free
);
2023 /*****************************************************************************
2024 * IDirectDraw7::Initialize
2026 * Initializes a DirectDraw interface.
2029 * GUID: Interface identifier. Well, don't know what this is really good
2033 * Returns DD_OK on the first call,
2034 * DDERR_ALREADYINITIALIZED on repeated calls
2036 *****************************************************************************/
2037 static HRESULT WINAPI
ddraw7_Initialize(IDirectDraw7
*iface
, GUID
*guid
)
2039 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2041 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2043 if (ddraw
->flags
& DDRAW_INITIALIZED
)
2044 return DDERR_ALREADYINITIALIZED
;
2046 /* FIXME: To properly take the GUID into account we should call
2047 * ddraw_init() here instead of in DDRAW_Create(). */
2049 FIXME("Ignoring guid %s.\n", debugstr_guid(guid
));
2051 ddraw
->flags
|= DDRAW_INITIALIZED
;
2055 static HRESULT WINAPI
ddraw4_Initialize(IDirectDraw4
*iface
, GUID
*guid
)
2057 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2059 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2061 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2064 static HRESULT WINAPI
ddraw2_Initialize(IDirectDraw2
*iface
, GUID
*guid
)
2066 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2068 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2070 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2073 static HRESULT WINAPI
ddraw1_Initialize(IDirectDraw
*iface
, GUID
*guid
)
2075 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2077 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2079 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2082 static HRESULT WINAPI
d3d1_Initialize(IDirect3D
*iface
, REFIID riid
)
2084 TRACE("iface %p, riid %s.\n", iface
, debugstr_guid(riid
));
2086 return DDERR_ALREADYINITIALIZED
;
2089 /*****************************************************************************
2090 * IDirectDraw7::FlipToGDISurface
2092 * "Makes the surface that the GDI writes to the primary surface"
2093 * Looks like some windows specific thing we don't have to care about.
2094 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
2095 * show error boxes ;)
2096 * Well, just return DD_OK.
2099 * Always returns DD_OK
2101 *****************************************************************************/
2102 static HRESULT WINAPI
ddraw7_FlipToGDISurface(IDirectDraw7
*iface
)
2104 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2106 TRACE("iface %p.\n", iface
);
2108 ddraw
->flags
|= DDRAW_GDI_FLIP
;
2111 ddraw_surface_update_frontbuffer(ddraw
->primary
, NULL
, FALSE
);
2116 static HRESULT WINAPI
ddraw4_FlipToGDISurface(IDirectDraw4
*iface
)
2118 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2120 TRACE("iface %p.\n", iface
);
2122 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2125 static HRESULT WINAPI
ddraw2_FlipToGDISurface(IDirectDraw2
*iface
)
2127 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2129 TRACE("iface %p.\n", iface
);
2131 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2134 static HRESULT WINAPI
ddraw1_FlipToGDISurface(IDirectDraw
*iface
)
2136 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2138 TRACE("iface %p.\n", iface
);
2140 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2143 /*****************************************************************************
2144 * IDirectDraw7::WaitForVerticalBlank
2146 * This method allows applications to get in sync with the vertical blank
2148 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
2149 * redraw the screen, most likely because of this stub
2152 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
2153 * or DDWAITVB_BLOCKEND
2154 * h: Not used, according to MSDN
2157 * Always returns DD_OK
2159 *****************************************************************************/
2160 static HRESULT WINAPI
ddraw7_WaitForVerticalBlank(IDirectDraw7
*iface
, DWORD Flags
, HANDLE event
)
2164 TRACE("iface %p, flags %#x, event %p.\n", iface
, Flags
, event
);
2166 /* This function is called often, so print the fixme only once */
2169 FIXME("iface %p, flags %#x, event %p stub!\n", iface
, Flags
, event
);
2173 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
2174 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
2175 return DDERR_UNSUPPORTED
; /* unchecked */
2180 static HRESULT WINAPI
ddraw4_WaitForVerticalBlank(IDirectDraw4
*iface
, DWORD flags
, HANDLE event
)
2182 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2184 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2186 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2189 static HRESULT WINAPI
ddraw2_WaitForVerticalBlank(IDirectDraw2
*iface
, DWORD flags
, HANDLE event
)
2191 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2193 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2195 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2198 static HRESULT WINAPI
ddraw1_WaitForVerticalBlank(IDirectDraw
*iface
, DWORD flags
, HANDLE event
)
2200 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2202 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2204 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2207 static HRESULT WINAPI
ddraw7_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
2209 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2210 struct wined3d_raster_status raster_status
;
2213 TRACE("iface %p, line %p.\n", iface
, Scanline
);
2215 wined3d_mutex_lock();
2216 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
2217 wined3d_mutex_unlock();
2220 WARN("Failed to get raster status, hr %#x.\n", hr
);
2224 *Scanline
= raster_status
.scan_line
;
2226 if (raster_status
.in_vblank
)
2227 return DDERR_VERTICALBLANKINPROGRESS
;
2232 static HRESULT WINAPI
ddraw4_GetScanLine(IDirectDraw4
*iface
, DWORD
*line
)
2234 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2236 TRACE("iface %p, line %p.\n", iface
, line
);
2238 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2241 static HRESULT WINAPI
ddraw2_GetScanLine(IDirectDraw2
*iface
, DWORD
*line
)
2243 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2245 TRACE("iface %p, line %p.\n", iface
, line
);
2247 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2250 static HRESULT WINAPI
ddraw1_GetScanLine(IDirectDraw
*iface
, DWORD
*line
)
2252 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2254 TRACE("iface %p, line %p.\n", iface
, line
);
2256 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2259 static HRESULT WINAPI
ddraw7_TestCooperativeLevel(IDirectDraw7
*iface
)
2261 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2263 TRACE("iface %p.\n", iface
);
2265 return ddraw
->device_state
== DDRAW_DEVICE_STATE_LOST
? DDERR_NOEXCLUSIVEMODE
: DD_OK
;
2268 static HRESULT WINAPI
ddraw4_TestCooperativeLevel(IDirectDraw4
*iface
)
2270 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2272 TRACE("iface %p.\n", iface
);
2274 return ddraw7_TestCooperativeLevel(&ddraw
->IDirectDraw7_iface
);
2277 /*****************************************************************************
2278 * IDirectDraw7::GetGDISurface
2280 * Returns the surface that GDI is treating as the primary surface.
2281 * For Wine this is the front buffer
2284 * GDISurface: Address to write the surface pointer to
2287 * DD_OK if the surface was found
2288 * DDERR_NOTFOUND if the GDI surface wasn't found
2290 *****************************************************************************/
2291 static HRESULT WINAPI
ddraw7_GetGDISurface(IDirectDraw7
*iface
, IDirectDrawSurface7
**GDISurface
)
2293 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2295 TRACE("iface %p, surface %p.\n", iface
, GDISurface
);
2297 wined3d_mutex_lock();
2299 if (!(*GDISurface
= &ddraw
->primary
->IDirectDrawSurface7_iface
))
2301 WARN("Primary not created yet.\n");
2302 wined3d_mutex_unlock();
2303 return DDERR_NOTFOUND
;
2305 IDirectDrawSurface7_AddRef(*GDISurface
);
2307 wined3d_mutex_unlock();
2312 static HRESULT WINAPI
ddraw4_GetGDISurface(IDirectDraw4
*iface
, IDirectDrawSurface4
**surface
)
2314 struct ddraw
*ddraw
= impl_from_IDirectDraw4(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
->IDirectDrawSurface4_iface
;
2329 IDirectDrawSurface4_AddRef(*surface
);
2330 IDirectDrawSurface7_Release(surface7
);
2335 static HRESULT WINAPI
ddraw2_GetGDISurface(IDirectDraw2
*iface
, IDirectDrawSurface
**surface
)
2337 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2338 struct ddraw_surface
*surface_impl
;
2339 IDirectDrawSurface7
*surface7
;
2342 TRACE("iface %p, surface %p.\n", iface
, surface
);
2344 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2350 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2351 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2352 IDirectDrawSurface_AddRef(*surface
);
2353 IDirectDrawSurface7_Release(surface7
);
2358 static HRESULT WINAPI
ddraw1_GetGDISurface(IDirectDraw
*iface
, IDirectDrawSurface
**surface
)
2360 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2361 struct ddraw_surface
*surface_impl
;
2362 IDirectDrawSurface7
*surface7
;
2365 TRACE("iface %p, surface %p.\n", iface
, surface
);
2367 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2373 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2374 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2375 IDirectDrawSurface_AddRef(*surface
);
2376 IDirectDrawSurface7_Release(surface7
);
2381 struct displaymodescallback_context
2383 LPDDENUMMODESCALLBACK func
;
2387 static HRESULT CALLBACK
EnumDisplayModesCallbackThunk(DDSURFACEDESC2
*surface_desc
, void *context
)
2389 struct displaymodescallback_context
*cbcontext
= context
;
2392 DDSD2_to_DDSD(surface_desc
, &desc
);
2393 return cbcontext
->func(&desc
, cbcontext
->context
);
2396 /*****************************************************************************
2397 * IDirectDraw7::EnumDisplayModes
2399 * Enumerates the supported Display modes. The modes can be filtered with
2400 * the DDSD parameter.
2403 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES. For old ddraw
2404 * versions (3 and older?) this is reserved and must be 0.
2405 * DDSD: Surface description to filter the modes
2406 * Context: Pointer passed back to the callback function
2407 * cb: Application-provided callback function
2411 * DDERR_INVALIDPARAMS if the callback wasn't set
2413 *****************************************************************************/
2414 static HRESULT WINAPI
ddraw7_EnumDisplayModes(IDirectDraw7
*iface
, DWORD Flags
,
2415 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMMODESCALLBACK2 cb
)
2417 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2418 struct wined3d_display_mode
*enum_modes
= NULL
;
2419 struct wined3d_display_mode mode
;
2420 unsigned int modenum
, fmt
;
2421 DDSURFACEDESC2 callback_sd
;
2422 unsigned enum_mode_count
= 0, enum_mode_array_size
= 16;
2423 DDPIXELFORMAT pixelformat
;
2425 static const enum wined3d_format_id checkFormatList
[] =
2427 WINED3DFMT_B8G8R8X8_UNORM
,
2428 WINED3DFMT_B5G6R5_UNORM
,
2432 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2433 iface
, Flags
, DDSD
, Context
, cb
);
2436 return DDERR_INVALIDPARAMS
;
2438 enum_modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(*enum_modes
) * enum_mode_array_size
);
2439 if (!enum_modes
) return DDERR_OUTOFMEMORY
;
2441 wined3d_mutex_lock();
2443 pixelformat
.dwSize
= sizeof(pixelformat
);
2444 for(fmt
= 0; fmt
< (sizeof(checkFormatList
) / sizeof(checkFormatList
[0])); fmt
++)
2447 while (wined3d_enum_adapter_modes(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, checkFormatList
[fmt
],
2448 WINED3D_SCANLINE_ORDERING_UNKNOWN
, modenum
++, &mode
) == WINED3D_OK
)
2453 ddrawformat_from_wined3dformat(&pixelformat
, mode
.format_id
);
2456 if (DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.width
!= DDSD
->dwWidth
)
2458 if (DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.height
!= DDSD
->dwHeight
)
2460 if (DDSD
->dwFlags
& DDSD_REFRESHRATE
&& mode
.refresh_rate
!= DDSD
->u2
.dwRefreshRate
)
2462 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
2463 && pixelformat
.u1
.dwRGBBitCount
!= DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
)
2467 /* DX docs state EnumDisplayMode should return only unique modes */
2468 for (i
= 0; i
< enum_mode_count
; i
++)
2470 if (enum_modes
[i
].width
== mode
.width
&& enum_modes
[i
].height
== mode
.height
2471 && enum_modes
[i
].format_id
== mode
.format_id
2472 && (enum_modes
[i
].refresh_rate
== mode
.refresh_rate
|| !(Flags
& DDEDM_REFRESHRATES
)))
2480 memset(&callback_sd
, 0, sizeof(callback_sd
));
2481 callback_sd
.dwSize
= sizeof(callback_sd
);
2482 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2484 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
|DDSD_REFRESHRATE
;
2485 if (Flags
& DDEDM_REFRESHRATES
)
2486 callback_sd
.u2
.dwRefreshRate
= mode
.refresh_rate
;
2488 callback_sd
.dwWidth
= mode
.width
;
2489 callback_sd
.dwHeight
= mode
.height
;
2491 callback_sd
.u4
.ddpfPixelFormat
=pixelformat
;
2493 /* Calc pitch and DWORD align like MSDN says */
2494 callback_sd
.u1
.lPitch
= (callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8) * mode
.width
;
2495 callback_sd
.u1
.lPitch
= (callback_sd
.u1
.lPitch
+ 3) & ~3;
2497 TRACE("Enumerating %dx%dx%d @%d\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
,
2498 callback_sd
.u2
.dwRefreshRate
);
2500 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
2502 TRACE("Application asked to terminate the enumeration\n");
2503 HeapFree(GetProcessHeap(), 0, enum_modes
);
2504 wined3d_mutex_unlock();
2508 if (enum_mode_count
== enum_mode_array_size
)
2510 struct wined3d_display_mode
*new_enum_modes
;
2512 enum_mode_array_size
*= 2;
2513 new_enum_modes
= HeapReAlloc(GetProcessHeap(), 0, enum_modes
,
2514 sizeof(*new_enum_modes
) * enum_mode_array_size
);
2515 if (!new_enum_modes
)
2517 HeapFree(GetProcessHeap(), 0, enum_modes
);
2518 wined3d_mutex_unlock();
2519 return DDERR_OUTOFMEMORY
;
2522 enum_modes
= new_enum_modes
;
2524 enum_modes
[enum_mode_count
++] = mode
;
2528 TRACE("End of enumeration\n");
2529 HeapFree(GetProcessHeap(), 0, enum_modes
);
2530 wined3d_mutex_unlock();
2535 static HRESULT WINAPI
ddraw4_EnumDisplayModes(IDirectDraw4
*iface
, DWORD flags
,
2536 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK2 callback
)
2538 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2540 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2541 iface
, flags
, surface_desc
, context
, callback
);
2543 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
, context
, callback
);
2546 static HRESULT WINAPI
ddraw2_EnumDisplayModes(IDirectDraw2
*iface
, DWORD flags
,
2547 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2549 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2550 struct displaymodescallback_context cbcontext
;
2551 DDSURFACEDESC2 surface_desc2
;
2553 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2554 iface
, flags
, surface_desc
, context
, callback
);
2556 cbcontext
.func
= callback
;
2557 cbcontext
.context
= context
;
2559 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2560 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2561 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2564 static HRESULT WINAPI
ddraw1_EnumDisplayModes(IDirectDraw
*iface
, DWORD flags
,
2565 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2567 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2568 struct displaymodescallback_context cbcontext
;
2569 DDSURFACEDESC2 surface_desc2
;
2571 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2572 iface
, flags
, surface_desc
, context
, callback
);
2574 cbcontext
.func
= callback
;
2575 cbcontext
.context
= context
;
2577 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2578 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2579 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2582 /*****************************************************************************
2583 * IDirectDraw7::EvaluateMode
2585 * Used with IDirectDraw7::StartModeTest to test video modes.
2586 * EvaluateMode is used to pass or fail a mode, and continue with the next
2590 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
2591 * Timeout: Returns the amount of seconds left before the mode would have
2592 * been failed automatically
2595 * This implementation always DD_OK, because it's a stub
2597 *****************************************************************************/
2598 static HRESULT WINAPI
ddraw7_EvaluateMode(IDirectDraw7
*iface
, DWORD Flags
, DWORD
*Timeout
)
2600 FIXME("iface %p, flags %#x, timeout %p stub!\n", iface
, Flags
, Timeout
);
2602 /* When implementing this, implement it in WineD3D */
2607 /*****************************************************************************
2608 * IDirectDraw7::GetDeviceIdentifier
2610 * Returns the device identifier, which gives information about the driver
2611 * Our device identifier is defined at the beginning of this file.
2614 * DDDI: Address for the returned structure
2615 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
2618 * On success it returns DD_OK
2619 * DDERR_INVALIDPARAMS if DDDI is NULL
2621 *****************************************************************************/
2622 static HRESULT WINAPI
ddraw7_GetDeviceIdentifier(IDirectDraw7
*iface
,
2623 DDDEVICEIDENTIFIER2
*DDDI
, DWORD Flags
)
2625 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2626 struct wined3d_adapter_identifier adapter_id
;
2629 TRACE("iface %p, device_identifier %p, flags %#x.\n", iface
, DDDI
, Flags
);
2632 return DDERR_INVALIDPARAMS
;
2634 if (Flags
& DDGDI_GETHOSTIDENTIFIER
)
2636 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
2637 * host adapter, if there's a secondary 3D adapter. This doesn't apply
2638 * to any modern hardware, nor is it interesting for Wine, so ignore it.
2639 * Size of DDDEVICEIDENTIFIER2 may be aligned to 8 bytes and thus 4
2640 * bytes too long. So only copy the relevant part of the structure
2643 memcpy(DDDI
, &deviceidentifier
, FIELD_OFFSET(DDDEVICEIDENTIFIER2
, dwWHQLLevel
) + sizeof(DWORD
));
2647 /* Drakan: Order of the Flame expects accurate D3D device information from ddraw */
2648 adapter_id
.driver
= DDDI
->szDriver
;
2649 adapter_id
.driver_size
= sizeof(DDDI
->szDriver
);
2650 adapter_id
.description
= DDDI
->szDescription
;
2651 adapter_id
.description_size
= sizeof(DDDI
->szDescription
);
2652 adapter_id
.device_name_size
= 0;
2653 wined3d_mutex_lock();
2654 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0x0, &adapter_id
);
2655 wined3d_mutex_unlock();
2656 if (FAILED(hr
)) return hr
;
2658 DDDI
->liDriverVersion
= adapter_id
.driver_version
;
2659 DDDI
->dwVendorId
= adapter_id
.vendor_id
;
2660 DDDI
->dwDeviceId
= adapter_id
.device_id
;
2661 DDDI
->dwSubSysId
= adapter_id
.subsystem_id
;
2662 DDDI
->dwRevision
= adapter_id
.revision
;
2663 DDDI
->guidDeviceIdentifier
= adapter_id
.device_identifier
;
2664 DDDI
->dwWHQLLevel
= adapter_id
.whql_level
;
2668 static HRESULT WINAPI
ddraw4_GetDeviceIdentifier(IDirectDraw4
*iface
,
2669 DDDEVICEIDENTIFIER
*identifier
, DWORD flags
)
2671 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2672 DDDEVICEIDENTIFIER2 identifier2
;
2675 TRACE("iface %p, identifier %p, flags %#x.\n", iface
, identifier
, flags
);
2677 hr
= ddraw7_GetDeviceIdentifier(&ddraw
->IDirectDraw7_iface
, &identifier2
, flags
);
2678 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&identifier2
, identifier
);
2683 /*****************************************************************************
2684 * IDirectDraw7::GetSurfaceFromDC
2686 * Returns the Surface for a GDI device context handle.
2687 * Is this related to IDirectDrawSurface::GetDC ???
2690 * hdc: hdc to return the surface for
2691 * Surface: Address to write the surface pointer to
2694 * Always returns DD_OK because it's a stub
2696 *****************************************************************************/
2697 static HRESULT WINAPI
ddraw7_GetSurfaceFromDC(IDirectDraw7
*iface
,
2698 HDC dc
, IDirectDrawSurface7
**surface
)
2700 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2701 struct ddraw_surface
*surface_impl
;
2703 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2706 return E_INVALIDARG
;
2711 wined3d_mutex_lock();
2712 LIST_FOR_EACH_ENTRY(surface_impl
, &ddraw
->surface_list
, struct ddraw_surface
, surface_list_entry
)
2714 if (surface_impl
->dc
!= dc
)
2717 TRACE("Found surface %p for dc %p.\n", surface_impl
, dc
);
2718 *surface
= &surface_impl
->IDirectDrawSurface7_iface
;
2719 IDirectDrawSurface7_AddRef(*surface
);
2720 wined3d_mutex_unlock();
2723 wined3d_mutex_unlock();
2726 TRACE("No surface found for dc %p.\n", dc
);
2728 return DDERR_NOTFOUND
;
2731 static HRESULT WINAPI
ddraw4_GetSurfaceFromDC(IDirectDraw4
*iface
, HDC dc
,
2732 IDirectDrawSurface4
**surface
)
2734 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2735 struct ddraw_surface
*surface_impl
;
2736 IDirectDrawSurface7
*surface7
;
2739 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2741 if (!surface
) return E_INVALIDARG
;
2743 hr
= ddraw7_GetSurfaceFromDC(&ddraw
->IDirectDraw7_iface
, dc
, &surface7
);
2749 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2750 /* Tests say this is true */
2751 *surface
= (IDirectDrawSurface4
*)&surface_impl
->IDirectDrawSurface_iface
;
2752 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2753 IDirectDrawSurface7_Release(surface7
);
2758 static HRESULT CALLBACK
restore_callback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
2760 IDirectDrawSurface_Restore(surface
);
2761 IDirectDrawSurface_Release(surface
);
2763 return DDENUMRET_OK
;
2766 static HRESULT WINAPI
ddraw7_RestoreAllSurfaces(IDirectDraw7
*iface
)
2768 TRACE("iface %p.\n", iface
);
2770 return IDirectDraw7_EnumSurfaces(iface
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
2771 NULL
, NULL
, restore_callback
);
2774 static HRESULT WINAPI
ddraw4_RestoreAllSurfaces(IDirectDraw4
*iface
)
2776 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2778 TRACE("iface %p.\n", iface
);
2780 return ddraw7_RestoreAllSurfaces(&ddraw
->IDirectDraw7_iface
);
2783 /*****************************************************************************
2784 * IDirectDraw7::StartModeTest
2786 * Tests the specified video modes to update the system registry with
2787 * refresh rate information. StartModeTest starts the mode test,
2788 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
2789 * isn't called within 15 seconds, the mode is failed automatically
2791 * As refresh rates are handled by the X server, I don't think this
2792 * Method is important
2795 * Modes: An array of mode specifications
2796 * NumModes: The number of modes in Modes
2797 * Flags: Some flags...
2800 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
2801 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
2804 *****************************************************************************/
2805 static HRESULT WINAPI
ddraw7_StartModeTest(IDirectDraw7
*iface
, SIZE
*Modes
, DWORD NumModes
, DWORD Flags
)
2807 FIXME("iface %p, modes %p, mode_count %u, flags %#x partial stub!\n",
2808 iface
, Modes
, NumModes
, Flags
);
2810 /* This looks sane */
2811 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
2813 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
2814 * As it is not, DDERR_TESTFINISHED is returned
2815 * (hopefully that's correct
2817 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
2818 * well, that value doesn't (yet) exist in the wine headers, so ignore it
2824 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
, DDSURFACEDESC2
*surface_desc
,
2825 IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
2827 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2828 struct ddraw_surface
*impl
;
2831 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2832 iface
, surface_desc
, surface
, outer_unknown
);
2834 wined3d_mutex_lock();
2836 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2838 WARN("Cooperative level not set.\n");
2839 wined3d_mutex_unlock();
2840 return DDERR_NOCOOPERATIVELEVELSET
;
2843 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2845 WARN("Application supplied invalid surface descriptor\n");
2846 wined3d_mutex_unlock();
2847 return DDERR_INVALIDPARAMS
;
2856 WARN("Surface pointer %p is invalid.\n", surface
);
2857 wined3d_mutex_unlock();
2858 return DDERR_INVALIDPARAMS
;
2862 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2864 if (TRACE_ON(ddraw
))
2866 TRACE(" (%p) Requesting surface desc :\n", iface
);
2867 DDRAW_dump_surface_desc(surface_desc
);
2870 WARN("Application tried to create an explicit front or back buffer\n");
2871 wined3d_mutex_unlock();
2872 return DDERR_INVALIDCAPS
;
2875 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 7);
2876 wined3d_mutex_unlock();
2880 *surface
= &impl
->IDirectDrawSurface7_iface
;
2881 IDirectDraw7_AddRef(iface
);
2882 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2887 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
2888 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
2890 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2891 struct ddraw_surface
*impl
;
2894 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2895 iface
, surface_desc
, surface
, outer_unknown
);
2897 wined3d_mutex_lock();
2899 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2901 WARN("Cooperative level not set.\n");
2902 wined3d_mutex_unlock();
2903 return DDERR_NOCOOPERATIVELEVELSET
;
2906 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2908 WARN("Application supplied invalid surface descriptor\n");
2909 wined3d_mutex_unlock();
2910 return DDERR_INVALIDPARAMS
;
2919 WARN("Surface pointer %p is invalid.\n", surface
);
2920 wined3d_mutex_unlock();
2921 return DDERR_INVALIDPARAMS
;
2925 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2927 if (TRACE_ON(ddraw
))
2929 TRACE(" (%p) Requesting surface desc :\n", iface
);
2930 DDRAW_dump_surface_desc(surface_desc
);
2933 WARN("Application tried to create an explicit front or back buffer\n");
2934 wined3d_mutex_unlock();
2935 return DDERR_INVALIDCAPS
;
2938 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 4);
2939 wined3d_mutex_unlock();
2943 *surface
= &impl
->IDirectDrawSurface4_iface
;
2944 IDirectDraw4_AddRef(iface
);
2945 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2950 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
2951 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2953 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2954 struct ddraw_surface
*impl
;
2956 DDSURFACEDESC2 surface_desc2
;
2958 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2959 iface
, surface_desc
, surface
, outer_unknown
);
2961 wined3d_mutex_lock();
2963 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2965 WARN("Cooperative level not set.\n");
2966 wined3d_mutex_unlock();
2967 return DDERR_NOCOOPERATIVELEVELSET
;
2970 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2972 WARN("Application supplied invalid surface descriptor\n");
2973 wined3d_mutex_unlock();
2974 return DDERR_INVALIDPARAMS
;
2983 WARN("Surface pointer %p is invalid.\n", surface
);
2984 wined3d_mutex_unlock();
2985 return DDERR_INVALIDPARAMS
;
2989 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2990 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2992 if (TRACE_ON(ddraw
))
2994 TRACE(" (%p) Requesting surface desc :\n", iface
);
2995 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
2998 WARN("Application tried to create an explicit front or back buffer\n");
2999 wined3d_mutex_unlock();
3000 return DDERR_INVALIDCAPS
;
3003 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 2);
3004 wined3d_mutex_unlock();
3008 *surface
= &impl
->IDirectDrawSurface_iface
;
3009 impl
->ifaceToRelease
= NULL
;
3014 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
3015 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3017 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3018 struct ddraw_surface
*impl
;
3020 DDSURFACEDESC2 surface_desc2
;
3022 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3023 iface
, surface_desc
, surface
, outer_unknown
);
3025 wined3d_mutex_lock();
3027 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
3029 WARN("Cooperative level not set.\n");
3030 wined3d_mutex_unlock();
3031 return DDERR_NOCOOPERATIVELEVELSET
;
3034 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3036 WARN("Application supplied invalid surface descriptor\n");
3037 wined3d_mutex_unlock();
3038 return DDERR_INVALIDPARAMS
;
3047 WARN("Surface pointer %p is invalid.\n", surface
);
3048 wined3d_mutex_unlock();
3049 return DDERR_INVALIDPARAMS
;
3053 if ((surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
))
3054 == (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
)
3055 || (surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
))
3056 == ((DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
)))
3058 WARN("Application tried to create an explicit front or back buffer.\n");
3059 wined3d_mutex_unlock();
3060 return DDERR_INVALIDCAPS
;
3063 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3064 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 1);
3065 wined3d_mutex_unlock();
3069 *surface
= &impl
->IDirectDrawSurface_iface
;
3070 impl
->ifaceToRelease
= NULL
;
3076 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
3077 const DDPIXELFORMAT
*provided
)
3079 /* Some flags must be present in both or neither for a match. */
3080 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
3081 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
3082 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
3084 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3087 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
3090 if (requested
->dwFlags
& DDPF_FOURCC
)
3091 if (requested
->dwFourCC
!= provided
->dwFourCC
)
3094 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
3095 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3096 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
3099 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3100 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3101 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
3104 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
3105 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
3108 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
3109 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3111 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
3114 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
3115 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
3121 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3130 #define CMP(FLAG, FIELD) \
3131 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3132 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3134 static const struct compare_info compare
[] =
3136 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3137 CMP(BACKBUFFERCOUNT
, u5
.dwBackBufferCount
),
3139 CMP(CKDESTBLT
, ddckCKDestBlt
),
3140 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3141 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3142 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3143 CMP(HEIGHT
, dwHeight
),
3144 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3145 CMP(LPSURFACE
, lpSurface
),
3146 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3147 CMP(PITCH
, u1
/* lPitch */),
3148 /* PIXELFORMAT: manual */
3149 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3150 CMP(TEXTURESTAGE
, dwTextureStage
),
3151 CMP(WIDTH
, dwWidth
),
3152 /* ZBUFFERBITDEPTH: "obsolete" */
3159 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3162 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
3164 if (requested
->dwFlags
& compare
[i
].flag
3165 && memcmp((const char *)provided
+ compare
[i
].offset
,
3166 (const char *)requested
+ compare
[i
].offset
,
3167 compare
[i
].size
) != 0)
3171 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3173 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3174 &provided
->u4
.ddpfPixelFormat
))
3181 struct surfacescallback2_context
3183 LPDDENUMSURFACESCALLBACK2 func
;
3187 struct surfacescallback_context
3189 LPDDENUMSURFACESCALLBACK func
;
3193 static HRESULT CALLBACK
EnumSurfacesCallback2Thunk(IDirectDrawSurface7
*surface
,
3194 DDSURFACEDESC2
*surface_desc
, void *context
)
3196 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3197 struct surfacescallback2_context
*cbcontext
= context
;
3199 IDirectDrawSurface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
3200 IDirectDrawSurface7_Release(surface
);
3202 return cbcontext
->func(&surface_impl
->IDirectDrawSurface4_iface
,
3203 surface_desc
, cbcontext
->context
);
3206 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3207 DDSURFACEDESC2
*surface_desc
, void *context
)
3209 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3210 struct surfacescallback_context
*cbcontext
= context
;
3212 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
3213 IDirectDrawSurface7_Release(surface
);
3215 return cbcontext
->func(&surface_impl
->IDirectDrawSurface_iface
,
3216 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3219 /*****************************************************************************
3220 * IDirectDraw7::EnumSurfaces
3222 * Loops through all surfaces attached to this device and calls the
3223 * application callback. This can't be relayed to WineD3DDevice,
3224 * because some WineD3DSurfaces' parents are IParent objects
3227 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3228 * DDSD: Description to filter for
3229 * Context: Application-provided pointer, it's passed unmodified to the
3231 * Callback: Address to call for each surface
3234 * DDERR_INVALIDPARAMS if the callback is NULL
3237 *****************************************************************************/
3238 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD Flags
,
3239 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMSURFACESCALLBACK7 Callback
)
3241 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3242 struct ddraw_surface
*surf
;
3243 DWORD match_flags
= Flags
& (DDENUMSURFACES_ALL
| DDENUMSURFACES_NOMATCH
| DDENUMSURFACES_MATCH
);
3245 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3246 iface
, Flags
, DDSD
, Context
, Callback
);
3249 return DDERR_INVALIDPARAMS
;
3251 if (Flags
& DDENUMSURFACES_CANBECREATED
)
3253 IDirectDrawSurface7
*surface
;
3254 DDSURFACEDESC2 testdesc
;
3257 if (match_flags
!= DDENUMSURFACES_MATCH
)
3258 return DDERR_INVALIDPARAMS
;
3261 return DDERR_INVALIDPARAMS
;
3263 memcpy(&testdesc
, DDSD
, sizeof(testdesc
));
3264 if (!(testdesc
.dwFlags
& DDSD_WIDTH
))
3266 testdesc
.dwFlags
|= DDSD_WIDTH
;
3267 testdesc
.dwWidth
= 512;
3269 if (!(testdesc
.dwFlags
& DDSD_HEIGHT
))
3271 testdesc
.dwFlags
|= DDSD_HEIGHT
;
3272 testdesc
.dwHeight
= 512;
3275 hr
= IDirectDraw7_CreateSurface(iface
, &testdesc
, &surface
, NULL
);
3278 surf
= unsafe_impl_from_IDirectDrawSurface7(surface
);
3279 Callback(NULL
, &surf
->surface_desc
, Context
);
3280 IDirectDrawSurface7_Release(surface
);
3283 ERR("Failed to create surface, hr %#x.\n", hr
);
3285 else if (Flags
& DDENUMSURFACES_DOESEXIST
)
3288 DDSURFACEDESC2 desc
;
3289 struct list
*entry
, *entry2
;
3291 /* a combination of match flags is not allowed */
3292 if (match_flags
!= 0 &&
3293 match_flags
!= DDENUMSURFACES_ALL
&&
3294 match_flags
!= DDENUMSURFACES_MATCH
&&
3295 match_flags
!= DDENUMSURFACES_NOMATCH
)
3296 return DDERR_INVALIDPARAMS
;
3298 all
= (Flags
& DDENUMSURFACES_ALL
) != 0;
3299 nomatch
= (Flags
& DDENUMSURFACES_NOMATCH
) != 0;
3302 return DDERR_INVALIDPARAMS
;
3304 wined3d_mutex_lock();
3306 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
3307 LIST_FOR_EACH_SAFE(entry
, entry2
, &ddraw
->surface_list
)
3309 surf
= LIST_ENTRY(entry
, struct ddraw_surface
, surface_list_entry
);
3311 if (!surf
->iface_count
)
3313 WARN("Not enumerating surface %p because it doesn't have any references.\n", surf
);
3317 if (all
|| (nomatch
!= ddraw_match_surface_desc(DDSD
, &surf
->surface_desc
)))
3319 TRACE("Enumerating surface %p.\n", surf
);
3320 desc
= surf
->surface_desc
;
3321 IDirectDrawSurface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
3322 if (Callback(&surf
->IDirectDrawSurface7_iface
, &desc
, Context
) != DDENUMRET_OK
)
3324 wined3d_mutex_unlock();
3330 wined3d_mutex_unlock();
3333 return DDERR_INVALIDPARAMS
;
3338 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3339 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3341 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3342 struct surfacescallback2_context cbcontext
;
3344 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3345 iface
, flags
, surface_desc
, context
, callback
);
3347 cbcontext
.func
= callback
;
3348 cbcontext
.context
= context
;
3350 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
,
3351 &cbcontext
, EnumSurfacesCallback2Thunk
);
3354 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3355 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3357 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3358 struct surfacescallback_context cbcontext
;
3359 DDSURFACEDESC2 surface_desc2
;
3361 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3362 iface
, flags
, surface_desc
, context
, callback
);
3364 cbcontext
.func
= callback
;
3365 cbcontext
.context
= context
;
3367 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3368 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3369 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3372 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3373 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3375 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3376 struct surfacescallback_context cbcontext
;
3377 DDSURFACEDESC2 surface_desc2
;
3379 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3380 iface
, flags
, surface_desc
, context
, callback
);
3382 cbcontext
.func
= callback
;
3383 cbcontext
.context
= context
;
3385 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3386 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3387 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3390 /*****************************************************************************
3391 * DirectDrawCreateClipper (DDRAW.@)
3393 * Creates a new IDirectDrawClipper object.
3396 * Clipper: Address to write the interface pointer to
3397 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3401 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3402 * E_OUTOFMEMORY if allocating the object failed
3404 *****************************************************************************/
3405 HRESULT WINAPI
DirectDrawCreateClipper(DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3407 struct ddraw_clipper
*object
;
3410 TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
3411 flags
, clipper
, outer_unknown
);
3414 return CLASS_E_NOAGGREGATION
;
3416 wined3d_mutex_lock();
3418 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3421 wined3d_mutex_unlock();
3422 return E_OUTOFMEMORY
;
3425 hr
= ddraw_clipper_init(object
);
3428 WARN("Failed to initialize clipper, hr %#x.\n", hr
);
3429 HeapFree(GetProcessHeap(), 0, object
);
3430 wined3d_mutex_unlock();
3434 TRACE("Created clipper %p.\n", object
);
3435 *clipper
= &object
->IDirectDrawClipper_iface
;
3436 wined3d_mutex_unlock();
3441 /*****************************************************************************
3442 * IDirectDraw7::CreateClipper
3444 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3446 *****************************************************************************/
3447 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3448 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3450 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3451 iface
, Flags
, Clipper
, UnkOuter
);
3453 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3456 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
, DWORD flags
,
3457 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3459 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3461 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3462 iface
, flags
, clipper
, outer_unknown
);
3464 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3467 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
3468 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3470 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3472 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3473 iface
, flags
, clipper
, outer_unknown
);
3475 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3478 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
3479 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3481 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3483 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3484 iface
, flags
, clipper
, outer_unknown
);
3486 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3489 /*****************************************************************************
3490 * IDirectDraw7::CreatePalette
3492 * Creates a new IDirectDrawPalette object
3495 * Flags: The flags for the new clipper
3496 * ColorTable: Color table to assign to the new clipper
3497 * Palette: Address to write the interface pointer to
3498 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3502 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3503 * E_OUTOFMEMORY if allocating the object failed
3505 *****************************************************************************/
3506 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
3507 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
3509 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3510 struct ddraw_palette
*object
;
3513 TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
3514 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3517 return CLASS_E_NOAGGREGATION
;
3519 wined3d_mutex_lock();
3521 /* The refcount test shows that a cooplevel is required for this */
3522 if (!ddraw
->cooperative_level
)
3524 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3525 wined3d_mutex_unlock();
3526 return DDERR_NOCOOPERATIVELEVELSET
;
3529 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(*object
));
3532 ERR("Out of memory when allocating memory for a palette implementation\n");
3533 wined3d_mutex_unlock();
3534 return E_OUTOFMEMORY
;
3537 hr
= ddraw_palette_init(object
, ddraw
, Flags
, ColorTable
);
3540 WARN("Failed to initialize palette, hr %#x.\n", hr
);
3541 HeapFree(GetProcessHeap(), 0, object
);
3542 wined3d_mutex_unlock();
3546 TRACE("Created palette %p.\n", object
);
3547 *Palette
= &object
->IDirectDrawPalette_iface
;
3548 wined3d_mutex_unlock();
3553 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
, PALETTEENTRY
*entries
,
3554 IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3556 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3559 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3560 iface
, flags
, entries
, palette
, outer_unknown
);
3562 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3563 if (SUCCEEDED(hr
) && *palette
)
3565 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3566 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3567 IDirectDraw4_AddRef(iface
);
3568 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3573 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
3574 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3576 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3579 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3580 iface
, flags
, entries
, palette
, outer_unknown
);
3582 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3583 if (SUCCEEDED(hr
) && *palette
)
3585 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3586 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3587 impl
->ifaceToRelease
= NULL
;
3593 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
3594 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3596 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3599 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3600 iface
, flags
, entries
, palette
, outer_unknown
);
3602 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3603 if (SUCCEEDED(hr
) && *palette
)
3605 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3606 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3607 impl
->ifaceToRelease
= NULL
;
3613 /*****************************************************************************
3614 * IDirectDraw7::DuplicateSurface
3616 * Duplicates a surface. The surface memory points to the same memory as
3617 * the original surface, and it's released when the last surface referencing
3618 * it is released. I guess that's beyond Wine's surface management right now
3619 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3620 * test application to implement this)
3623 * Src: Address of the source surface
3624 * Dest: Address to write the new surface pointer to
3627 * See IDirectDraw7::CreateSurface
3629 *****************************************************************************/
3630 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
3631 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
3633 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(Src
);
3635 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
3637 /* For now, simply create a new, independent surface */
3638 return IDirectDraw7_CreateSurface(iface
, &src_surface
->surface_desc
, Dest
, NULL
);
3641 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
, IDirectDrawSurface4
*src
,
3642 IDirectDrawSurface4
**dst
)
3644 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
3645 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3646 struct ddraw_surface
*dst_impl
;
3647 IDirectDrawSurface7
*dst7
;
3650 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3652 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3653 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3659 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3660 *dst
= &dst_impl
->IDirectDrawSurface4_iface
;
3661 IDirectDrawSurface4_AddRef(*dst
);
3662 IDirectDrawSurface7_Release(dst7
);
3667 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
3668 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
3670 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3671 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3672 struct ddraw_surface
*dst_impl
;
3673 IDirectDrawSurface7
*dst7
;
3676 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3678 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3679 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3682 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3683 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3684 IDirectDrawSurface_AddRef(*dst
);
3685 IDirectDrawSurface7_Release(dst7
);
3690 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
, IDirectDrawSurface
*src
,
3691 IDirectDrawSurface
**dst
)
3693 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3694 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3695 struct ddraw_surface
*dst_impl
;
3696 IDirectDrawSurface7
*dst7
;
3699 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3701 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3702 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3705 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3706 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3707 IDirectDrawSurface_AddRef(*dst
);
3708 IDirectDrawSurface7_Release(dst7
);
3713 /*****************************************************************************
3714 * IDirect3D7::EnumDevices
3716 * The EnumDevices method for IDirect3D7. It enumerates all supported
3717 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
3720 * callback: Function to call for each enumerated device
3721 * context: Pointer to pass back to the app
3724 * D3D_OK, or the return value of the GetCaps call
3726 *****************************************************************************/
3727 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
3729 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
3730 D3DDEVICEDESC7 device_desc7
;
3735 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3738 return DDERR_INVALIDPARAMS
;
3740 wined3d_mutex_lock();
3742 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3744 wined3d_mutex_unlock();
3748 dev_caps
= device_desc7
.dwDevCaps
;
3750 for (i
= 0; i
< sizeof(device_list7
)/sizeof(device_list7
[0]); i
++)
3754 device_desc7
.deviceGUID
= *device_list7
[i
].device_guid
;
3755 device_desc7
.dwDevCaps
= dev_caps
& ~device_list7
[i
].remove_caps
;
3757 ret
= callback(device_list7
[i
].interface_name
, device_list7
[i
].device_name
, &device_desc7
, context
);
3758 if (ret
!= DDENUMRET_OK
)
3760 TRACE("Application cancelled the enumeration.\n");
3761 wined3d_mutex_unlock();
3766 TRACE("End of enumeration.\n");
3768 wined3d_mutex_unlock();
3773 /*****************************************************************************
3774 * IDirect3D3::EnumDevices
3776 * Enumerates all supported Direct3DDevice interfaces. This is the
3777 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
3779 * Versions 1, 2 and 3
3782 * callback: Application-provided routine to call for each enumerated device
3783 * Context: Pointer to pass to the callback
3786 * D3D_OK on success,
3787 * The result of IDirect3DImpl_GetCaps if it failed
3789 *****************************************************************************/
3790 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3792 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
3794 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3795 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
3796 D3DDEVICEDESC7 device_desc7
;
3799 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
3800 * name string. Let's put the string in a sufficiently sized array in
3801 * writable memory. */
3802 char device_name
[50];
3803 strcpy(device_name
,"Direct3D HEL");
3805 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3808 return DDERR_INVALIDPARAMS
;
3810 wined3d_mutex_lock();
3812 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3814 wined3d_mutex_unlock();
3817 ddraw_d3dcaps1_from_7(&device_desc1
, &device_desc7
);
3819 /* Do I have to enumerate the reference id? Note from old d3d7:
3820 * "It seems that enumerating the reference IID on Direct3D 1 games
3821 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
3823 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
3824 * EnumReference which enables / disables enumerating the reference
3825 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
3826 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
3827 * demo directory suggest this.
3829 * Some games(GTA 2) seem to use the second enumerated device, so I have
3830 * to enumerate at least 2 devices. So enumerate the reference device to
3833 * Other games (Rollcage) tell emulation and hal device apart by certain
3834 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
3835 * limitation flag), and it refuses all devices that have the perspective
3836 * flag set. This way it refuses the emulation device, and HAL devices
3837 * never have POW2 unset in d3d7 on windows. */
3838 if (ddraw
->d3dversion
!= 1)
3840 static CHAR reference_description
[] = "RGB Direct3D emulation";
3842 TRACE("Enumerating WineD3D D3DDevice interface.\n");
3843 hal_desc
= device_desc1
;
3844 hel_desc
= device_desc1
;
3845 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
3846 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3847 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3848 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3849 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3850 /* RGB, RAMP and MMX devices have a HAL dcmColorModel of 0 */
3851 hal_desc
.dcmColorModel
= 0;
3852 /* RGB, RAMP and MMX devices cannot report HAL hardware flags */
3853 hal_desc
.dwFlags
= 0;
3855 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
3856 device_name
, &hal_desc
, &hel_desc
, context
);
3857 if (hr
!= D3DENUMRET_OK
)
3859 TRACE("Application cancelled the enumeration.\n");
3860 wined3d_mutex_unlock();
3865 strcpy(device_name
,"Direct3D HAL");
3867 TRACE("Enumerating HAL Direct3D device.\n");
3868 hal_desc
= device_desc1
;
3869 hel_desc
= device_desc1
;
3871 /* The hal device does not have the pow2 flag set in hel, but in hal. */
3872 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3873 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3874 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3875 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3876 /* HAL devices have a HEL dcmColorModel of 0 */
3877 hel_desc
.dcmColorModel
= 0;
3879 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
3880 device_name
, &hal_desc
, &hel_desc
, context
);
3881 if (hr
!= D3DENUMRET_OK
)
3883 TRACE("Application cancelled the enumeration.\n");
3884 wined3d_mutex_unlock();
3888 TRACE("End of enumeration.\n");
3890 wined3d_mutex_unlock();
3895 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3897 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3899 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3901 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3904 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3906 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3908 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3910 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3913 /*****************************************************************************
3914 * IDirect3D3::CreateLight
3916 * Creates an IDirect3DLight interface. This interface is used in
3917 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
3918 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
3919 * uses the IDirect3DDevice7 interface with D3D7 lights.
3921 * Versions 1, 2 and 3
3924 * light: Address to store the new interface pointer
3925 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3930 * DDERR_OUTOFMEMORY if memory allocation failed
3931 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3933 *****************************************************************************/
3934 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
,
3935 IUnknown
*outer_unknown
)
3937 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3938 struct d3d_light
*object
;
3940 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3942 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3944 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3947 ERR("Failed to allocate light memory.\n");
3948 return DDERR_OUTOFMEMORY
;
3951 d3d_light_init(object
, ddraw
);
3953 TRACE("Created light %p.\n", object
);
3954 *light
= &object
->IDirect3DLight_iface
;
3959 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3961 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3963 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3965 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3968 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3970 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3972 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3974 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3977 /*****************************************************************************
3978 * IDirect3D3::CreateMaterial
3980 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
3981 * and older versions. The IDirect3DMaterial implementation wraps its
3982 * functionality to IDirect3DDevice7::SetMaterial and friends.
3984 * Versions 1, 2 and 3
3987 * material: Address to store the new interface's pointer to
3988 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3993 * DDERR_OUTOFMEMORY if memory allocation failed
3994 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3996 *****************************************************************************/
3997 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
,
3998 IUnknown
*outer_unknown
)
4000 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4001 struct d3d_material
*object
;
4003 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4005 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4007 object
= d3d_material_create(ddraw
);
4010 ERR("Failed to allocate material memory.\n");
4011 return DDERR_OUTOFMEMORY
;
4014 TRACE("Created material %p.\n", object
);
4015 *material
= &object
->IDirect3DMaterial3_iface
;
4020 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
,
4021 IUnknown
*outer_unknown
)
4023 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4024 struct d3d_material
*object
;
4026 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4028 object
= d3d_material_create(ddraw
);
4031 ERR("Failed to allocate material memory.\n");
4032 return DDERR_OUTOFMEMORY
;
4035 TRACE("Created material %p.\n", object
);
4036 *material
= &object
->IDirect3DMaterial2_iface
;
4041 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
,
4042 IUnknown
*outer_unknown
)
4044 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4045 struct d3d_material
*object
;
4047 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4049 object
= d3d_material_create(ddraw
);
4052 ERR("Failed to allocate material memory.\n");
4053 return DDERR_OUTOFMEMORY
;
4056 TRACE("Created material %p.\n", object
);
4057 *material
= &object
->IDirect3DMaterial_iface
;
4062 /*****************************************************************************
4063 * IDirect3D3::CreateViewport
4065 * Creates an IDirect3DViewport interface. This interface is used
4066 * by Direct3D and earlier versions for Viewport management. In Direct3D7
4067 * it has been replaced by a viewport structure and
4068 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
4069 * uses the IDirect3DDevice7 methods for its functionality
4072 * Viewport: Address to store the new interface pointer
4073 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4078 * DDERR_OUTOFMEMORY if memory allocation failed
4079 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4081 *****************************************************************************/
4082 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
,
4083 IUnknown
*outer_unknown
)
4085 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4086 struct d3d_viewport
*object
;
4088 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4090 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4092 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4095 ERR("Failed to allocate viewport memory.\n");
4096 return DDERR_OUTOFMEMORY
;
4099 d3d_viewport_init(object
, ddraw
);
4101 TRACE("Created viewport %p.\n", object
);
4102 *viewport
= &object
->IDirect3DViewport3_iface
;
4107 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
4109 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4111 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4113 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4117 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
4119 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4121 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4123 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4127 /*****************************************************************************
4128 * IDirect3D3::FindDevice
4130 * This method finds a device with the requested properties and returns a
4131 * device description
4133 * Versions 1, 2 and 3
4135 * fds: Describes the requested device characteristics
4136 * fdr: Returns the device description
4140 * DDERR_INVALIDPARAMS if no device was found
4142 *****************************************************************************/
4143 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4145 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4146 D3DDEVICEDESC7 desc7
;
4147 D3DDEVICEDESC desc1
;
4150 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4152 if (!fds
|| !fdr
) return DDERR_INVALIDPARAMS
;
4154 if (fds
->dwSize
!= sizeof(D3DFINDDEVICESEARCH
) || (fdr
->dwSize
!= sizeof(D3DFINDDEVICERESULT1
) &&
4155 fdr
->dwSize
!= sizeof(D3DFINDDEVICERESULT2
) && fdr
->dwSize
!= sizeof(D3DFINDDEVICERESULT
)))
4156 return DDERR_INVALIDPARAMS
;
4158 if ((fds
->dwFlags
& D3DFDS_COLORMODEL
)
4159 && fds
->dcmColorModel
!= D3DCOLOR_RGB
)
4161 WARN("Trying to request a non-RGB D3D color model. Not supported.\n");
4162 return DDERR_INVALIDPARAMS
; /* No real idea what to return here :-) */
4165 if (fds
->dwFlags
& D3DFDS_GUID
)
4167 TRACE("Trying to match guid %s.\n", debugstr_guid(&(fds
->guid
)));
4168 if (!IsEqualGUID(&IID_D3DDEVICE_WineD3D
, &fds
->guid
)
4169 && !IsEqualGUID(&IID_IDirect3DHALDevice
, &fds
->guid
)
4170 && !IsEqualGUID(&IID_IDirect3DRGBDevice
, &fds
->guid
))
4172 WARN("No match for this GUID.\n");
4173 return DDERR_NOTFOUND
;
4178 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &desc7
)))
4181 /* Now return our own GUID */
4182 ddraw_d3dcaps1_from_7(&desc1
, &desc7
);
4183 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4185 if (fdr
->dwSize
== sizeof(D3DFINDDEVICERESULT1
))
4187 D3DFINDDEVICERESULT1
*fdr1
= (D3DFINDDEVICERESULT1
*)fdr
;
4188 memcpy(&fdr1
->ddHwDesc
, &desc1
, sizeof(fdr1
->ddHwDesc
));
4189 memcpy(&fdr1
->ddSwDesc
, &desc1
, sizeof(fdr1
->ddSwDesc
));
4191 else if (fdr
->dwSize
== sizeof(D3DFINDDEVICERESULT2
))
4193 D3DFINDDEVICERESULT2
*fdr2
= (D3DFINDDEVICERESULT2
*)fdr
;
4194 memcpy(&fdr2
->ddHwDesc
, &desc1
, sizeof(fdr2
->ddHwDesc
));
4195 memcpy(&fdr2
->ddSwDesc
, &desc1
, sizeof(fdr2
->ddSwDesc
));
4199 fdr
->ddHwDesc
= desc1
;
4200 fdr
->ddSwDesc
= desc1
;
4203 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4208 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4210 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4212 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4214 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4217 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4219 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4221 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4223 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4226 /*****************************************************************************
4227 * IDirect3D7::CreateDevice
4229 * Creates an IDirect3DDevice7 interface.
4231 * Versions 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4232 * DirectDraw surfaces and are created with
4233 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4234 * create the device object and QueryInterfaces for IDirect3DDevice
4237 * refiid: IID of the device to create
4238 * Surface: Initial rendertarget
4239 * Device: Address to return the interface pointer
4243 * DDERR_OUTOFMEMORY if memory allocation failed
4244 * DDERR_INVALIDPARAMS if a device exists already
4246 *****************************************************************************/
4247 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4248 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4250 struct ddraw_surface
*target
= unsafe_impl_from_IDirectDrawSurface7(surface
);
4251 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4252 struct d3d_device
*object
;
4255 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4257 wined3d_mutex_lock();
4258 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, riid
, target
, (IUnknown
*)surface
, 7, &object
, NULL
)))
4260 *device
= &object
->IDirect3DDevice7_iface
;
4264 WARN("Failed to create device, hr %#x.\n", hr
);
4267 wined3d_mutex_unlock();
4272 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4273 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4275 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface4(surface
);
4276 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4277 struct d3d_device
*device_impl
;
4280 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4281 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4284 return CLASS_E_NOAGGREGATION
;
4286 wined3d_mutex_lock();
4287 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, riid
, surface_impl
, (IUnknown
*)surface
, 3, &device_impl
, NULL
)))
4289 *device
= &device_impl
->IDirect3DDevice3_iface
;
4293 WARN("Failed to create device, hr %#x.\n", hr
);
4296 wined3d_mutex_unlock();
4301 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4302 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4304 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface(surface
);
4305 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4306 struct d3d_device
*device_impl
;
4309 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4310 iface
, debugstr_guid(riid
), surface
, device
);
4312 wined3d_mutex_lock();
4313 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, riid
, surface_impl
, (IUnknown
*)surface
, 2, &device_impl
, NULL
)))
4315 *device
= &device_impl
->IDirect3DDevice2_iface
;
4319 WARN("Failed to create device, hr %#x.\n", hr
);
4322 wined3d_mutex_unlock();
4327 /*****************************************************************************
4328 * IDirect3D7::CreateVertexBuffer
4330 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4336 * desc: Requested Vertex buffer properties
4337 * vertex_buffer: Address to return the interface pointer at
4338 * flags: Some flags, should be 0
4342 * DDERR_OUTOFMEMORY if memory allocation failed
4343 * DDERR_INVALIDPARAMS if desc or vertex_buffer is NULL
4345 *****************************************************************************/
4346 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4347 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4349 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4350 struct d3d_vertex_buffer
*object
;
4353 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
4354 iface
, desc
, vertex_buffer
, flags
);
4356 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4358 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4361 TRACE("Created vertex buffer %p.\n", object
);
4362 *vertex_buffer
= &object
->IDirect3DVertexBuffer7_iface
;
4365 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4370 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4371 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4373 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4374 struct d3d_vertex_buffer
*object
;
4377 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n",
4378 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4381 return CLASS_E_NOAGGREGATION
;
4382 if (!vertex_buffer
|| !desc
)
4383 return DDERR_INVALIDPARAMS
;
4385 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4388 TRACE("Created vertex buffer %p.\n", object
);
4389 *vertex_buffer
= (IDirect3DVertexBuffer
*)&object
->IDirect3DVertexBuffer7_iface
;
4392 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4397 /*****************************************************************************
4398 * IDirect3D7::EnumZBufferFormats
4400 * Enumerates all supported Z buffer pixel formats
4406 * callback: callback to call for each pixel format
4407 * context: Pointer to pass back to the callback
4411 * DDERR_INVALIDPARAMS if callback is NULL
4413 *****************************************************************************/
4414 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4415 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4417 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4418 struct wined3d_display_mode mode
;
4419 enum wined3d_device_type type
;
4423 /* Order matters. Specifically, BattleZone II (full version) expects the
4424 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4425 static const enum wined3d_format_id formats
[] =
4427 WINED3DFMT_S1_UINT_D15_UNORM
,
4428 WINED3DFMT_D16_UNORM
,
4429 WINED3DFMT_X8D24_UNORM
,
4430 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4431 WINED3DFMT_D24_UNORM_S8_UINT
,
4432 WINED3DFMT_D32_UNORM
,
4435 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4436 iface
, debugstr_guid(device_iid
), callback
, context
);
4438 if (!callback
) return DDERR_INVALIDPARAMS
;
4440 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4441 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4442 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4444 TRACE("Asked for HAL device.\n");
4445 type
= WINED3D_DEVICE_TYPE_HAL
;
4447 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4448 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4450 TRACE("Asked for SW device.\n");
4451 type
= WINED3D_DEVICE_TYPE_SW
;
4453 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4455 TRACE("Asked for REF device.\n");
4456 type
= WINED3D_DEVICE_TYPE_REF
;
4458 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4460 TRACE("Asked for NULLREF device.\n");
4461 type
= WINED3D_DEVICE_TYPE_NULLREF
;
4465 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4466 type
= WINED3D_DEVICE_TYPE_HAL
;
4469 wined3d_mutex_lock();
4470 /* We need an adapter format from somewhere to please wined3d and WGL.
4471 * Use the current display mode. So far all cards offer the same depth
4472 * stencil format for all modes, but if some do not and applications do
4473 * not like that we'll have to find some workaround, like iterating over
4474 * all imaginable formats and collecting all the depth stencil formats we
4476 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
4478 ERR("Failed to get display mode, hr %#x.\n", hr
);
4479 wined3d_mutex_unlock();
4483 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
4485 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4486 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_TEXTURE_2D
, formats
[i
])))
4488 DDPIXELFORMAT pformat
;
4490 memset(&pformat
, 0, sizeof(pformat
));
4491 pformat
.dwSize
= sizeof(pformat
);
4492 ddrawformat_from_wined3dformat(&pformat
, formats
[i
]);
4494 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
4495 hr
= callback(&pformat
, context
);
4496 if (hr
!= DDENUMRET_OK
)
4498 TRACE("Format enumeration cancelled by application.\n");
4499 wined3d_mutex_unlock();
4505 /* Historically some windows drivers used dwZBufferBitDepth=24 for WINED3DFMT_X8D24_UNORM,
4506 * while others used dwZBufferBitDepth=32. In either case the pitch matches a 32 bits per
4507 * pixel format, so we use dwZBufferBitDepth=32. Some games expect 24. Windows Vista and
4508 * newer enumerate both versions, so we do the same(bug 22434) */
4509 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4510 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_TEXTURE_2D
, WINED3DFMT_X8D24_UNORM
)))
4512 DDPIXELFORMAT x8d24
=
4514 sizeof(x8d24
), DDPF_ZBUFFER
, 0,
4515 {24}, {0x00000000}, {0x00ffffff}, {0x00000000}
4517 TRACE("Enumerating WINED3DFMT_X8D24_UNORM, dwZBufferBitDepth=24 version\n");
4518 callback(&x8d24
, context
);
4521 TRACE("End of enumeration.\n");
4523 wined3d_mutex_unlock();
4528 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
4529 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4531 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4533 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4534 iface
, debugstr_guid(device_iid
), callback
, context
);
4536 return d3d7_EnumZBufferFormats(&ddraw
->IDirect3D7_iface
, device_iid
, callback
, context
);
4539 /*****************************************************************************
4540 * IDirect3D7::EvictManagedTextures
4542 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
4543 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
4548 * D3D_OK, because it's a stub
4550 *****************************************************************************/
4551 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
4553 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4555 TRACE("iface %p!\n", iface
);
4557 wined3d_mutex_lock();
4558 if (ddraw
->flags
& DDRAW_D3D_INITIALIZED
)
4559 wined3d_device_evict_managed_resources(ddraw
->wined3d_device
);
4560 wined3d_mutex_unlock();
4565 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
4567 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4569 TRACE("iface %p.\n", iface
);
4571 return d3d7_EvictManagedTextures(&ddraw
->IDirect3D7_iface
);
4574 /*****************************************************************************
4575 * IDirectDraw7 VTable
4576 *****************************************************************************/
4577 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
4580 ddraw7_QueryInterface
,
4585 ddraw7_CreateClipper
,
4586 ddraw7_CreatePalette
,
4587 ddraw7_CreateSurface
,
4588 ddraw7_DuplicateSurface
,
4589 ddraw7_EnumDisplayModes
,
4590 ddraw7_EnumSurfaces
,
4591 ddraw7_FlipToGDISurface
,
4593 ddraw7_GetDisplayMode
,
4594 ddraw7_GetFourCCCodes
,
4595 ddraw7_GetGDISurface
,
4596 ddraw7_GetMonitorFrequency
,
4598 ddraw7_GetVerticalBlankStatus
,
4600 ddraw7_RestoreDisplayMode
,
4601 ddraw7_SetCooperativeLevel
,
4602 ddraw7_SetDisplayMode
,
4603 ddraw7_WaitForVerticalBlank
,
4605 ddraw7_GetAvailableVidMem
,
4607 ddraw7_GetSurfaceFromDC
,
4609 ddraw7_RestoreAllSurfaces
,
4610 ddraw7_TestCooperativeLevel
,
4611 ddraw7_GetDeviceIdentifier
,
4613 ddraw7_StartModeTest
,
4617 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
4620 ddraw4_QueryInterface
,
4625 ddraw4_CreateClipper
,
4626 ddraw4_CreatePalette
,
4627 ddraw4_CreateSurface
,
4628 ddraw4_DuplicateSurface
,
4629 ddraw4_EnumDisplayModes
,
4630 ddraw4_EnumSurfaces
,
4631 ddraw4_FlipToGDISurface
,
4633 ddraw4_GetDisplayMode
,
4634 ddraw4_GetFourCCCodes
,
4635 ddraw4_GetGDISurface
,
4636 ddraw4_GetMonitorFrequency
,
4638 ddraw4_GetVerticalBlankStatus
,
4640 ddraw4_RestoreDisplayMode
,
4641 ddraw4_SetCooperativeLevel
,
4642 ddraw4_SetDisplayMode
,
4643 ddraw4_WaitForVerticalBlank
,
4645 ddraw4_GetAvailableVidMem
,
4647 ddraw4_GetSurfaceFromDC
,
4649 ddraw4_RestoreAllSurfaces
,
4650 ddraw4_TestCooperativeLevel
,
4651 ddraw4_GetDeviceIdentifier
,
4654 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
4657 ddraw2_QueryInterface
,
4662 ddraw2_CreateClipper
,
4663 ddraw2_CreatePalette
,
4664 ddraw2_CreateSurface
,
4665 ddraw2_DuplicateSurface
,
4666 ddraw2_EnumDisplayModes
,
4667 ddraw2_EnumSurfaces
,
4668 ddraw2_FlipToGDISurface
,
4670 ddraw2_GetDisplayMode
,
4671 ddraw2_GetFourCCCodes
,
4672 ddraw2_GetGDISurface
,
4673 ddraw2_GetMonitorFrequency
,
4675 ddraw2_GetVerticalBlankStatus
,
4677 ddraw2_RestoreDisplayMode
,
4678 ddraw2_SetCooperativeLevel
,
4679 ddraw2_SetDisplayMode
,
4680 ddraw2_WaitForVerticalBlank
,
4682 ddraw2_GetAvailableVidMem
,
4685 static struct IDirectDrawVtbl ddraw1_vtbl
=
4688 ddraw1_QueryInterface
,
4693 ddraw1_CreateClipper
,
4694 ddraw1_CreatePalette
,
4695 ddraw1_CreateSurface
,
4696 ddraw1_DuplicateSurface
,
4697 ddraw1_EnumDisplayModes
,
4698 ddraw1_EnumSurfaces
,
4699 ddraw1_FlipToGDISurface
,
4701 ddraw1_GetDisplayMode
,
4702 ddraw1_GetFourCCCodes
,
4703 ddraw1_GetGDISurface
,
4704 ddraw1_GetMonitorFrequency
,
4706 ddraw1_GetVerticalBlankStatus
,
4708 ddraw1_RestoreDisplayMode
,
4709 ddraw1_SetCooperativeLevel
,
4710 ddraw1_SetDisplayMode
,
4711 ddraw1_WaitForVerticalBlank
,
4714 static const struct IDirect3D7Vtbl d3d7_vtbl
=
4716 /* IUnknown methods */
4717 d3d7_QueryInterface
,
4720 /* IDirect3D7 methods */
4723 d3d7_CreateVertexBuffer
,
4724 d3d7_EnumZBufferFormats
,
4725 d3d7_EvictManagedTextures
4728 static const struct IDirect3D3Vtbl d3d3_vtbl
=
4730 /* IUnknown methods */
4731 d3d3_QueryInterface
,
4734 /* IDirect3D3 methods */
4737 d3d3_CreateMaterial
,
4738 d3d3_CreateViewport
,
4741 d3d3_CreateVertexBuffer
,
4742 d3d3_EnumZBufferFormats
,
4743 d3d3_EvictManagedTextures
4746 static const struct IDirect3D2Vtbl d3d2_vtbl
=
4748 /* IUnknown methods */
4749 d3d2_QueryInterface
,
4752 /* IDirect3D2 methods */
4755 d3d2_CreateMaterial
,
4756 d3d2_CreateViewport
,
4761 static const struct IDirect3DVtbl d3d1_vtbl
=
4763 /* IUnknown methods */
4764 d3d1_QueryInterface
,
4767 /* IDirect3D methods */
4771 d3d1_CreateMaterial
,
4772 d3d1_CreateViewport
,
4776 /*****************************************************************************
4779 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
4780 * if none was found.
4782 * This function is in ddraw.c and the DDraw object space because D3D7
4783 * vertex buffers are created using the IDirect3D interface to the ddraw
4784 * object, so they can be valid across D3D devices(theoretically. The ddraw
4785 * object also owns the wined3d device
4789 * fvf: Fvf to find the decl for
4792 * NULL in case of an error, the vertex declaration for the FVF otherwise.
4794 *****************************************************************************/
4795 struct wined3d_vertex_declaration
*ddraw_find_decl(struct ddraw
*This
, DWORD fvf
)
4797 struct wined3d_vertex_declaration
*pDecl
= NULL
;
4799 int p
, low
, high
; /* deliberately signed */
4800 struct FvfToDecl
*convertedDecls
= This
->decls
;
4802 TRACE("Searching for declaration for fvf %08x... ", fvf
);
4805 high
= This
->numConvertedDecls
- 1;
4806 while(low
<= high
) {
4807 p
= (low
+ high
) >> 1;
4809 if(convertedDecls
[p
].fvf
== fvf
) {
4810 TRACE("found %p\n", convertedDecls
[p
].decl
);
4811 return convertedDecls
[p
].decl
;
4812 } else if(convertedDecls
[p
].fvf
< fvf
) {
4818 TRACE("not found. Creating and inserting at position %d.\n", low
);
4820 hr
= wined3d_vertex_declaration_create_from_fvf(This
->wined3d_device
,
4821 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
4822 if (hr
!= S_OK
) return NULL
;
4824 if(This
->declArraySize
== This
->numConvertedDecls
) {
4825 int grow
= max(This
->declArraySize
/ 2, 8);
4826 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
4827 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
4828 if (!convertedDecls
)
4830 wined3d_vertex_declaration_decref(pDecl
);
4833 This
->decls
= convertedDecls
;
4834 This
->declArraySize
+= grow
;
4837 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
4838 convertedDecls
[low
].decl
= pDecl
;
4839 convertedDecls
[low
].fvf
= fvf
;
4840 This
->numConvertedDecls
++;
4842 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
4846 static inline struct ddraw
*ddraw_from_device_parent(struct wined3d_device_parent
*device_parent
)
4848 return CONTAINING_RECORD(device_parent
, struct ddraw
, device_parent
);
4851 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
4852 struct wined3d_device
*device
)
4854 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
4857 /* This is run from device_process_message() in wined3d, we can't take the
4859 /* FIXME: We only get mode change notifications in exclusive mode, but we
4860 * should mark surfaces as lost on mode changes in DDSCL_NORMAL mode as well. */
4861 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
4863 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4864 MONITORINFO monitor_info
;
4868 TRACE("device_parent %p.\n", device_parent
);
4870 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) || !ddraw
->swapchain_window
)
4872 TRACE("Nothing to resize.\n");
4876 monitor
= MonitorFromWindow(ddraw
->swapchain_window
, MONITOR_DEFAULTTOPRIMARY
);
4877 monitor_info
.cbSize
= sizeof(monitor_info
);
4878 if (!GetMonitorInfoW(monitor
, &monitor_info
))
4880 ERR("Failed to get monitor info.\n");
4884 r
= &monitor_info
.rcMonitor
;
4885 TRACE("Resizing window %p to %s.\n", ddraw
->swapchain_window
, wine_dbgstr_rect(r
));
4887 if (!SetWindowPos(ddraw
->swapchain_window
, HWND_TOP
, r
->left
, r
->top
,
4888 r
->right
- r
->left
, r
->bottom
- r
->top
, SWP_SHOWWINDOW
| SWP_NOACTIVATE
))
4889 ERR("Failed to resize window.\n");
4891 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_OK
);
4894 static void CDECL
device_parent_activate(struct wined3d_device_parent
*device_parent
, BOOL activate
)
4896 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4898 TRACE("device_parent %p, activate %#x.\n", device_parent
, activate
);
4902 ddraw
->device_state
= DDRAW_DEVICE_STATE_LOST
;
4903 exclusive_window
= NULL
;
4907 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_LOST
);
4911 void ddraw_update_lost_surfaces(struct ddraw
*ddraw
)
4913 struct ddraw_surface
*surface
;
4915 if (ddraw
->device_state
!= DDRAW_DEVICE_STATE_NOT_RESTORED
)
4918 LIST_FOR_EACH_ENTRY(surface
, &ddraw
->surface_list
, struct ddraw_surface
, surface_list_entry
)
4920 surface
->is_lost
= TRUE
;
4922 ddraw
->device_state
= DDRAW_DEVICE_STATE_OK
;
4925 static HRESULT CDECL
device_parent_surface_created(struct wined3d_device_parent
*device_parent
,
4926 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
4927 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
4929 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4930 struct ddraw_surface
*ddraw_surface
;
4932 TRACE("device_parent %p, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
4933 device_parent
, wined3d_texture
, sub_resource_idx
, parent
, parent_ops
);
4935 /* We have a swapchain or wined3d internal texture. */
4936 if (!wined3d_texture_get_parent(wined3d_texture
) || wined3d_texture_get_parent(wined3d_texture
) == ddraw
)
4939 *parent_ops
= &ddraw_null_wined3d_parent_ops
;
4944 if (!(ddraw_surface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ddraw_surface
))))
4946 ERR("Failed to allocate surface memory.\n");
4947 return DDERR_OUTOFVIDEOMEMORY
;
4950 ddraw_surface_init(ddraw_surface
, ddraw
, wined3d_texture
, sub_resource_idx
, parent_ops
);
4951 *parent
= ddraw_surface
;
4953 ddraw_update_lost_surfaces(ddraw
);
4954 list_add_head(&ddraw
->surface_list
, &ddraw_surface
->surface_list_entry
);
4956 TRACE("Created ddraw surface %p.\n", ddraw_surface
);
4961 static HRESULT CDECL
device_parent_volume_created(struct wined3d_device_parent
*device_parent
,
4962 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
4963 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
4965 TRACE("device_parent %p, texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
4966 device_parent
, wined3d_texture
, sub_resource_idx
, parent
, parent_ops
);
4969 *parent_ops
= &ddraw_null_wined3d_parent_ops
;
4974 static void STDMETHODCALLTYPE
ddraw_frontbuffer_destroyed(void *parent
)
4976 struct ddraw
*ddraw
= parent
;
4977 ddraw
->wined3d_frontbuffer
= NULL
;
4980 static const struct wined3d_parent_ops ddraw_frontbuffer_parent_ops
=
4982 ddraw_frontbuffer_destroyed
,
4985 static HRESULT CDECL
device_parent_create_swapchain_texture(struct wined3d_device_parent
*device_parent
,
4986 void *container_parent
, const struct wined3d_resource_desc
*desc
, DWORD texture_flags
,
4987 struct wined3d_texture
**texture
)
4989 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4992 TRACE("device_parent %p, container_parent %p, desc %p, texture flags %#x, texture %p.\n",
4993 device_parent
, container_parent
, desc
, texture_flags
, texture
);
4995 if (ddraw
->wined3d_frontbuffer
)
4997 ERR("Frontbuffer already created.\n");
5001 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, desc
, 1, 1,
5002 texture_flags
| WINED3D_TEXTURE_CREATE_MAPPABLE
, NULL
, ddraw
, &ddraw_frontbuffer_parent_ops
, texture
)))
5004 WARN("Failed to create texture, hr %#x.\n", hr
);
5008 ddraw
->wined3d_frontbuffer
= *texture
;
5013 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
5014 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
5016 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
5019 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent
, desc
, swapchain
);
5021 if (ddraw
->wined3d_swapchain
)
5023 ERR("Swapchain already created.\n");
5027 if (FAILED(hr
= wined3d_swapchain_create(ddraw
->wined3d_device
, desc
, NULL
,
5028 &ddraw_null_wined3d_parent_ops
, swapchain
)))
5029 WARN("Failed to create swapchain, hr %#x.\n", hr
);
5034 static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops
=
5036 device_parent_wined3d_device_created
,
5037 device_parent_mode_changed
,
5038 device_parent_activate
,
5039 device_parent_surface_created
,
5040 device_parent_volume_created
,
5041 device_parent_create_swapchain_texture
,
5042 device_parent_create_swapchain
,
5045 HRESULT
ddraw_init(struct ddraw
*ddraw
, DWORD flags
, enum wined3d_device_type device_type
)
5050 ddraw
->IDirectDraw7_iface
.lpVtbl
= &ddraw7_vtbl
;
5051 ddraw
->IDirectDraw_iface
.lpVtbl
= &ddraw1_vtbl
;
5052 ddraw
->IDirectDraw2_iface
.lpVtbl
= &ddraw2_vtbl
;
5053 ddraw
->IDirectDraw4_iface
.lpVtbl
= &ddraw4_vtbl
;
5054 ddraw
->IDirect3D_iface
.lpVtbl
= &d3d1_vtbl
;
5055 ddraw
->IDirect3D2_iface
.lpVtbl
= &d3d2_vtbl
;
5056 ddraw
->IDirect3D3_iface
.lpVtbl
= &d3d3_vtbl
;
5057 ddraw
->IDirect3D7_iface
.lpVtbl
= &d3d7_vtbl
;
5058 ddraw
->device_parent
.ops
= &ddraw_wined3d_device_parent_ops
;
5059 ddraw
->numIfaces
= 1;
5062 flags
|= DDRAW_WINED3D_FLAGS
;
5063 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
5065 flags
|= WINED3D_NO3D
;
5066 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
5068 WARN("Failed to create a wined3d object.\n");
5073 if (FAILED(hr
= wined3d_get_device_caps(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
, &caps
)))
5075 ERR("Failed to get device caps, hr %#x.\n", hr
);
5076 wined3d_decref(ddraw
->wined3d
);
5080 if (!(caps
.ddraw_caps
.caps
& WINEDDCAPS_3D
))
5082 WARN("Created a wined3d object without 3D support.\n");
5083 ddraw
->flags
|= DDRAW_NO3D
;
5086 if (FAILED(hr
= wined3d_device_create(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
,
5087 NULL
, 0, DDRAW_STRIDE_ALIGNMENT
, &ddraw
->device_parent
, &ddraw
->wined3d_device
)))
5089 WARN("Failed to create a wined3d device, hr %#x.\n", hr
);
5090 wined3d_decref(ddraw
->wined3d
);
5094 list_init(&ddraw
->surface_list
);