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 static const struct ddraw
*exclusive_ddraw
;
28 /* Device identifier. Don't relay it to WineD3D */
29 static const DDDEVICEIDENTIFIER2 deviceidentifier
=
31 "vga.dll", /* default 2D driver */
33 { { 0x00010001, 0x00010001 } },
35 /* a8373c10-7ac4-4deb-849a-009844d08b2d */
36 {0xa8373c10,0x7ac4,0x4deb, {0x84,0x9a,0x00,0x98,0x44,0xd0,0x8b,0x2d}},
40 static struct enum_device_entry
42 char interface_name
[100];
43 char device_name
[100];
44 const GUID
*device_guid
;
49 "WINE Direct3D7 Hardware Transform and Lighting acceleration using WineD3D",
51 &IID_IDirect3DTnLHalDevice
,
56 "WINE Direct3D7 Hardware acceleration using WineD3D",
58 &IID_IDirect3DHALDevice
,
63 "WINE Direct3D7 RGB Software Emulation using WineD3D",
65 &IID_IDirect3DRGBDevice
,
69 static void STDMETHODCALLTYPE
ddraw_null_wined3d_object_destroyed(void *parent
) {}
71 const struct wined3d_parent_ops ddraw_null_wined3d_parent_ops
=
73 ddraw_null_wined3d_object_destroyed
,
76 static inline struct ddraw
*impl_from_IDirectDraw(IDirectDraw
*iface
)
78 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw_iface
);
81 static inline struct ddraw
*impl_from_IDirectDraw2(IDirectDraw2
*iface
)
83 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw2_iface
);
86 static inline struct ddraw
*impl_from_IDirectDraw4(IDirectDraw4
*iface
)
88 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw4_iface
);
91 static inline struct ddraw
*impl_from_IDirectDraw7(IDirectDraw7
*iface
)
93 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw7_iface
);
96 static inline struct ddraw
*impl_from_IDirect3D(IDirect3D
*iface
)
98 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D_iface
);
101 static inline struct ddraw
*impl_from_IDirect3D2(IDirect3D2
*iface
)
103 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D2_iface
);
106 static inline struct ddraw
*impl_from_IDirect3D3(IDirect3D3
*iface
)
108 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D3_iface
);
111 static inline struct ddraw
*impl_from_IDirect3D7(IDirect3D7
*iface
)
113 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D7_iface
);
116 static HRESULT WINAPI
ddraw7_QueryInterface(IDirectDraw7
*iface
, REFIID riid
, void **out
)
118 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
120 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
125 return DDERR_INVALIDPARAMS
;
128 /* The refcount unit test revealed that an IDirect3D7 interface can only
129 * be queried from a DirectDraw object that was created as an IDirectDraw7
130 * interface. The older interfaces can query any IDirect3D version except
131 * 7, because they are all initially created as IDirectDraw. This isn't
132 * really crucial behavior, and messy to implement with the common
133 * creation function, so it has been left out here. */
134 if (IsEqualGUID(&IID_IDirectDraw7
, riid
)
135 || IsEqualGUID(&IID_IUnknown
, riid
))
137 *out
= &ddraw
->IDirectDraw7_iface
;
138 TRACE("Returning IDirectDraw7 interface %p.\n", *out
);
140 else if (IsEqualGUID(&IID_IDirectDraw4
, riid
))
142 *out
= &ddraw
->IDirectDraw4_iface
;
143 TRACE("Returning IDirectDraw4 interface %p.\n", *out
);
145 else if (IsEqualGUID(&IID_IDirectDraw2
, riid
))
147 *out
= &ddraw
->IDirectDraw2_iface
;
148 TRACE("Returning IDirectDraw2 interface %p.\n", *out
);
150 else if (IsEqualGUID(&IID_IDirectDraw
, riid
))
152 *out
= &ddraw
->IDirectDraw_iface
;
153 TRACE("Returning IDirectDraw interface %p.\n", *out
);
155 else if (IsEqualGUID(&IID_IDirect3D7
, riid
))
157 ddraw
->d3dversion
= 7;
158 *out
= &ddraw
->IDirect3D7_iface
;
159 TRACE("Returning Direct3D7 interface %p.\n", *out
);
161 else if (IsEqualGUID(&IID_IDirect3D3
, riid
))
163 ddraw
->d3dversion
= 3;
164 *out
= &ddraw
->IDirect3D3_iface
;
165 TRACE("Returning Direct3D3 interface %p.\n", *out
);
167 else if (IsEqualGUID(&IID_IDirect3D2
, riid
))
169 ddraw
->d3dversion
= 2;
170 *out
= &ddraw
->IDirect3D2_iface
;
171 TRACE("Returning Direct3D2 interface %p.\n", *out
);
173 else if (IsEqualGUID(&IID_IDirect3D
, riid
))
175 ddraw
->d3dversion
= 1;
176 *out
= &ddraw
->IDirect3D_iface
;
177 TRACE("Returning Direct3D interface %p.\n", *out
);
179 /* Unknown interface */
182 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
184 return E_NOINTERFACE
;
187 IUnknown_AddRef((IUnknown
*)*out
);
191 static HRESULT WINAPI
ddraw4_QueryInterface(IDirectDraw4
*iface
, REFIID riid
, void **object
)
193 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
195 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
197 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
200 static HRESULT WINAPI
ddraw2_QueryInterface(IDirectDraw2
*iface
, REFIID riid
, void **object
)
202 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
204 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
206 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
209 static HRESULT WINAPI
ddraw1_QueryInterface(IDirectDraw
*iface
, REFIID riid
, void **object
)
211 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
213 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
215 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
218 static HRESULT WINAPI
d3d7_QueryInterface(IDirect3D7
*iface
, REFIID riid
, void **object
)
220 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
222 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
224 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
227 static HRESULT WINAPI
d3d3_QueryInterface(IDirect3D3
*iface
, REFIID riid
, void **object
)
229 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
231 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
233 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
236 static HRESULT WINAPI
d3d2_QueryInterface(IDirect3D2
*iface
, REFIID riid
, void **object
)
238 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
240 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
242 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
245 static HRESULT WINAPI
d3d1_QueryInterface(IDirect3D
*iface
, REFIID riid
, void **object
)
247 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
249 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
251 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
254 /*****************************************************************************
255 * IDirectDraw7::AddRef
257 * Increases the interfaces refcount, basically
259 * DDraw refcounting is a bit tricky. The different DirectDraw interface
260 * versions have individual refcounts, but the IDirect3D interfaces do not.
261 * All interfaces are from one object, that means calling QueryInterface on an
262 * IDirectDraw7 interface for an IDirectDraw4 interface does not create a new
265 * That means all AddRef and Release implementations of IDirectDrawX work
266 * with their own counter, and IDirect3DX::AddRef thunk to IDirectDraw (1),
267 * except of IDirect3D7 which thunks to IDirectDraw7
269 * Returns: The new refcount
271 *****************************************************************************/
272 static ULONG WINAPI
ddraw7_AddRef(IDirectDraw7
*iface
)
274 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
275 ULONG ref
= InterlockedIncrement(&This
->ref7
);
277 TRACE("%p increasing refcount to %u.\n", This
, ref
);
279 if(ref
== 1) InterlockedIncrement(&This
->numIfaces
);
284 static ULONG WINAPI
ddraw4_AddRef(IDirectDraw4
*iface
)
286 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
287 ULONG ref
= InterlockedIncrement(&This
->ref4
);
289 TRACE("%p increasing refcount to %u.\n", This
, ref
);
291 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
296 static ULONG WINAPI
ddraw2_AddRef(IDirectDraw2
*iface
)
298 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
299 ULONG ref
= InterlockedIncrement(&This
->ref2
);
301 TRACE("%p increasing refcount to %u.\n", This
, ref
);
303 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
308 static ULONG WINAPI
ddraw1_AddRef(IDirectDraw
*iface
)
310 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
311 ULONG ref
= InterlockedIncrement(&This
->ref1
);
313 TRACE("%p increasing refcount to %u.\n", This
, ref
);
315 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
320 static ULONG WINAPI
d3d7_AddRef(IDirect3D7
*iface
)
322 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
324 TRACE("iface %p.\n", iface
);
326 return ddraw7_AddRef(&This
->IDirectDraw7_iface
);
329 static ULONG WINAPI
d3d3_AddRef(IDirect3D3
*iface
)
331 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
333 TRACE("iface %p.\n", iface
);
335 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
338 static ULONG WINAPI
d3d2_AddRef(IDirect3D2
*iface
)
340 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
342 TRACE("iface %p.\n", iface
);
344 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
347 static ULONG WINAPI
d3d1_AddRef(IDirect3D
*iface
)
349 struct ddraw
*This
= impl_from_IDirect3D(iface
);
351 TRACE("iface %p.\n", iface
);
353 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
356 void ddraw_destroy_swapchain(struct ddraw
*ddraw
)
358 TRACE("Destroying the swapchain.\n");
360 wined3d_swapchain_decref(ddraw
->wined3d_swapchain
);
361 ddraw
->wined3d_swapchain
= NULL
;
363 if (!(ddraw
->flags
& DDRAW_NO3D
))
367 for (i
= 0; i
< ddraw
->numConvertedDecls
; ++i
)
369 wined3d_vertex_declaration_decref(ddraw
->decls
[i
].decl
);
371 HeapFree(GetProcessHeap(), 0, ddraw
->decls
);
372 ddraw
->numConvertedDecls
= 0;
374 if (FAILED(wined3d_device_uninit_3d(ddraw
->wined3d_device
)))
376 ERR("Failed to uninit 3D.\n");
380 /* Free the d3d window if one was created. */
381 if (ddraw
->d3d_window
&& ddraw
->d3d_window
!= ddraw
->dest_window
)
383 TRACE("Destroying the hidden render window %p.\n", ddraw
->d3d_window
);
384 DestroyWindow(ddraw
->d3d_window
);
385 ddraw
->d3d_window
= 0;
389 ddraw
->flags
&= ~DDRAW_D3D_INITIALIZED
;
393 wined3d_device_uninit_gdi(ddraw
->wined3d_device
);
396 ddraw_set_swapchain_window(ddraw
, NULL
);
398 TRACE("Swapchain destroyed.\n");
401 /*****************************************************************************
404 * Destroys a ddraw object if all refcounts are 0. This is to share code
405 * between the IDirectDrawX::Release functions
408 * This: DirectDraw object to destroy
410 *****************************************************************************/
411 static void ddraw_destroy(struct ddraw
*This
)
413 IDirectDraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, NULL
, DDSCL_NORMAL
);
414 IDirectDraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
416 /* Destroy the device window if we created one */
417 if(This
->devicewindow
!= 0)
419 TRACE(" (%p) Destroying the device window %p\n", This
, This
->devicewindow
);
420 DestroyWindow(This
->devicewindow
);
421 This
->devicewindow
= 0;
424 wined3d_mutex_lock();
425 list_remove(&This
->ddraw_list_entry
);
426 wined3d_mutex_unlock();
428 if (This
->wined3d_swapchain
)
429 ddraw_destroy_swapchain(This
);
430 wined3d_device_decref(This
->wined3d_device
);
431 wined3d_decref(This
->wined3d
);
434 This
->d3ddevice
->ddraw
= NULL
;
436 /* Now free the object */
437 HeapFree(GetProcessHeap(), 0, This
);
440 /*****************************************************************************
441 * IDirectDraw7::Release
443 * Decreases the refcount. If the refcount falls to 0, the object is destroyed
445 * Returns: The new refcount
446 *****************************************************************************/
447 static ULONG WINAPI
ddraw7_Release(IDirectDraw7
*iface
)
449 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
450 ULONG ref
= InterlockedDecrement(&This
->ref7
);
452 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
454 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
460 static ULONG WINAPI
ddraw4_Release(IDirectDraw4
*iface
)
462 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
463 ULONG ref
= InterlockedDecrement(&This
->ref4
);
465 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
467 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
473 static ULONG WINAPI
ddraw2_Release(IDirectDraw2
*iface
)
475 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
476 ULONG ref
= InterlockedDecrement(&This
->ref2
);
478 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
480 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
486 static ULONG WINAPI
ddraw1_Release(IDirectDraw
*iface
)
488 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
489 ULONG ref
= InterlockedDecrement(&This
->ref1
);
491 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
493 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
499 static ULONG WINAPI
d3d7_Release(IDirect3D7
*iface
)
501 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
503 TRACE("iface %p.\n", iface
);
505 return ddraw7_Release(&This
->IDirectDraw7_iface
);
508 static ULONG WINAPI
d3d3_Release(IDirect3D3
*iface
)
510 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
512 TRACE("iface %p.\n", iface
);
514 return ddraw1_Release(&This
->IDirectDraw_iface
);
517 static ULONG WINAPI
d3d2_Release(IDirect3D2
*iface
)
519 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
521 TRACE("iface %p.\n", iface
);
523 return ddraw1_Release(&This
->IDirectDraw_iface
);
526 static ULONG WINAPI
d3d1_Release(IDirect3D
*iface
)
528 struct ddraw
*This
= impl_from_IDirect3D(iface
);
530 TRACE("iface %p.\n", iface
);
532 return ddraw1_Release(&This
->IDirectDraw_iface
);
535 /*****************************************************************************
536 * IDirectDraw methods
537 *****************************************************************************/
539 static HRESULT
ddraw_set_focus_window(struct ddraw
*ddraw
, HWND window
)
541 /* FIXME: This looks wrong, exclusive mode should imply a destination
543 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) && ddraw
->dest_window
)
545 TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET.\n");
546 return DDERR_HWNDALREADYSET
;
549 ddraw
->focuswindow
= window
;
554 static HRESULT
ddraw_attach_d3d_device(struct ddraw
*ddraw
,
555 struct wined3d_swapchain_desc
*swapchain_desc
)
557 HWND window
= swapchain_desc
->device_window
;
560 TRACE("ddraw %p.\n", ddraw
);
562 if (!window
|| window
== GetDesktopWindow())
564 window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "Hidden D3D Window",
565 WS_DISABLED
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
566 NULL
, NULL
, NULL
, NULL
);
569 ERR("Failed to create window, last error %#x.\n", GetLastError());
573 ShowWindow(window
, SW_HIDE
); /* Just to be sure */
574 WARN("No window for the Direct3DDevice, created hidden window %p.\n", window
);
576 swapchain_desc
->device_window
= window
;
580 TRACE("Using existing window %p for Direct3D rendering.\n", window
);
582 ddraw
->d3d_window
= window
;
584 /* Set this NOW, otherwise creating the depth stencil surface will cause a
585 * recursive loop until ram or emulated video memory is full. */
586 ddraw
->flags
|= DDRAW_D3D_INITIALIZED
;
587 hr
= wined3d_device_init_3d(ddraw
->wined3d_device
, swapchain_desc
);
590 ddraw
->flags
&= ~DDRAW_D3D_INITIALIZED
;
594 ddraw
->declArraySize
= 2;
595 ddraw
->decls
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ddraw
->decls
) * ddraw
->declArraySize
);
598 ERR("Error allocating an array for the converted vertex decls.\n");
599 ddraw
->declArraySize
= 0;
600 hr
= wined3d_device_uninit_3d(ddraw
->wined3d_device
);
601 return E_OUTOFMEMORY
;
604 TRACE("Successfully initialized 3D.\n");
609 static HRESULT
ddraw_create_swapchain(struct ddraw
*ddraw
, HWND window
, BOOL windowed
)
611 struct wined3d_swapchain_desc swapchain_desc
;
612 struct wined3d_display_mode mode
;
613 HRESULT hr
= WINED3D_OK
;
615 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
617 ERR("Failed to get display mode.\n");
621 memset(&swapchain_desc
, 0, sizeof(swapchain_desc
));
622 swapchain_desc
.backbuffer_width
= mode
.width
;
623 swapchain_desc
.backbuffer_height
= mode
.height
;
624 swapchain_desc
.backbuffer_format
= mode
.format_id
;
625 swapchain_desc
.swap_effect
= WINED3D_SWAP_EFFECT_COPY
;
626 swapchain_desc
.device_window
= window
;
627 swapchain_desc
.windowed
= windowed
;
629 if (!(ddraw
->flags
& DDRAW_NO3D
))
630 hr
= ddraw_attach_d3d_device(ddraw
, &swapchain_desc
);
632 hr
= wined3d_device_init_gdi(ddraw
->wined3d_device
, &swapchain_desc
);
636 ERR("Failed to create swapchain, hr %#x.\n", hr
);
640 if (!(ddraw
->wined3d_swapchain
= wined3d_device_get_swapchain(ddraw
->wined3d_device
, 0)))
642 ERR("Failed to get swapchain.\n");
643 return DDERR_INVALIDPARAMS
;
646 wined3d_swapchain_incref(ddraw
->wined3d_swapchain
);
647 ddraw_set_swapchain_window(ddraw
, window
);
652 /*****************************************************************************
653 * IDirectDraw7::RestoreDisplayMode
655 * Restores the display mode to what it was at creation time. Basically.
659 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
661 *****************************************************************************/
662 static HRESULT WINAPI
ddraw7_RestoreDisplayMode(IDirectDraw7
*iface
)
664 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
667 TRACE("iface %p.\n", iface
);
669 wined3d_mutex_lock();
671 if (!(ddraw
->flags
& DDRAW_RESTORE_MODE
))
673 wined3d_mutex_unlock();
677 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
679 wined3d_mutex_unlock();
680 return DDERR_NOEXCLUSIVEMODE
;
683 if (SUCCEEDED(hr
= wined3d_set_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, NULL
)))
684 ddraw
->flags
&= ~DDRAW_RESTORE_MODE
;
686 wined3d_mutex_unlock();
691 static HRESULT WINAPI
ddraw4_RestoreDisplayMode(IDirectDraw4
*iface
)
693 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
695 TRACE("iface %p.\n", iface
);
697 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
700 static HRESULT WINAPI
ddraw2_RestoreDisplayMode(IDirectDraw2
*iface
)
702 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
704 TRACE("iface %p.\n", iface
);
706 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
709 static HRESULT WINAPI
ddraw1_RestoreDisplayMode(IDirectDraw
*iface
)
711 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
713 TRACE("iface %p.\n", iface
);
715 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
718 /*****************************************************************************
719 * IDirectDraw7::SetCooperativeLevel
721 * Sets the cooperative level for the DirectDraw object, and the window
722 * assigned to it. The cooperative level determines the general behavior
723 * of the DirectDraw application
725 * Warning: This is quite tricky, as it's not really documented which
726 * cooperative levels can be combined with each other. If a game fails
727 * after this function, try to check the cooperative levels passed on
728 * Windows, and if it returns something different.
730 * If you think that this function caused the failure because it writes a
731 * fixme, be sure to run again with a +ddraw trace.
733 * What is known about cooperative levels (See the ddraw modes test):
734 * DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN.
735 * DDSCL_NORMAL is not compatible with DDSCL_EXCLUSIVE.
736 * Unlike what msdn claims, DDSCL_NORMAL | DDSCL_FULLSCREEN is allowed.
737 * DDSCL_SETFOCUSWINDOW can be passed only in DDSCL_NORMAL mode, but after that
738 * DDSCL_EXCLUSIVE can be activated.
739 * DDSCL_SETFOCUSWINDOW may only be used with DDSCL_NOWINDOWCHANGES or
740 * DDSCL_CREATEDEVICEWINDOW.
742 * Handled flags: DDSCL_NORMAL, DDSCL_FULLSCREEN, DDSCL_EXCLUSIVE,
743 * DDSCL_CREATEDEVICEWINDOW, DDSCL_SETDEVICEWINDOW
744 * DDSCL_SETFOCUSWINDOW (partially),
745 * DDSCL_MULTITHREADED (work in progress)
746 * DDSCL_FPUPRESERVE (see device.c)
748 * Unsure about this: DDSCL_FPUSETUP
750 * These don't seem very important for wine:
751 * DDSCL_ALLOWREBOOT, DDSCL_NOWINDOWCHANGES, DDSCL_ALLOWMODEX
754 * DD_OK if the cooperative level was set successfully
755 * DDERR_INVALIDPARAMS if the passed cooperative level combination is invalid
756 * DDERR_HWNDALREADYSET if DDSCL_SETFOCUSWINDOW is passed in exclusive mode
757 * (Probably others too, have to investigate)
759 *****************************************************************************/
760 static HRESULT
ddraw_set_cooperative_level(struct ddraw
*ddraw
, HWND window
,
761 DWORD cooplevel
, BOOL restore_mode_on_normal
)
763 struct wined3d_rendertarget_view
*rtv
= NULL
, *dsv
= NULL
;
764 struct wined3d_stateblock
*stateblock
;
765 BOOL restore_state
= FALSE
;
768 TRACE("ddraw %p, window %p, flags %#x, restore_mode_on_normal %x.\n", ddraw
, window
, cooplevel
,
769 restore_mode_on_normal
);
770 DDRAW_dump_cooperativelevel(cooplevel
);
772 wined3d_mutex_lock();
774 if (ddraw
->flags
& DDRAW_SCL_RECURSIVE
)
776 WARN("Recursive call, returning DD_OK.\n");
780 ddraw
->flags
|= DDRAW_SCL_RECURSIVE
;
782 /* Tests suggest that we need one of them: */
783 if(!(cooplevel
& (DDSCL_SETFOCUSWINDOW
|
787 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
788 hr
= DDERR_INVALIDPARAMS
;
792 if ((cooplevel
& DDSCL_CREATEDEVICEWINDOW
) && !(cooplevel
& DDSCL_EXCLUSIVE
))
794 WARN("DDSCL_CREATEDEVICEWINDOW requires DDSCL_EXCLUSIVE.\n");
795 hr
= DDERR_INVALIDPARAMS
;
799 /* Handle those levels first which set various hwnds */
800 if ((cooplevel
& DDSCL_SETFOCUSWINDOW
) && !(cooplevel
& DDSCL_CREATEDEVICEWINDOW
))
802 /* This isn't compatible with a lot of flags */
803 if (cooplevel
& (DDSCL_MULTITHREADED
808 | DDSCL_SETDEVICEWINDOW
813 WARN("Called with incompatible flags, returning DDERR_INVALIDPARAMS.\n");
814 hr
= DDERR_INVALIDPARAMS
;
818 hr
= ddraw_set_focus_window(ddraw
, window
);
822 if (cooplevel
& DDSCL_EXCLUSIVE
)
824 if (!(cooplevel
& DDSCL_FULLSCREEN
) || !(window
|| (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)))
826 WARN("DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN and a window.\n");
827 hr
= DDERR_INVALIDPARAMS
;
831 if (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)
835 if (!ddraw
->focuswindow
&& !(cooplevel
& DDSCL_SETFOCUSWINDOW
))
837 WARN("No focus window set.\n");
838 hr
= DDERR_NOFOCUSWINDOW
;
842 device_window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "DirectDrawDeviceWnd",
843 WS_POPUP
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
844 NULL
, NULL
, NULL
, NULL
);
847 ERR("Failed to create window, last error %#x.\n", GetLastError());
852 ShowWindow(device_window
, SW_SHOW
);
853 TRACE("Created a device window %p.\n", device_window
);
855 /* Native apparently leaks the created device window if setting the
856 * focus window below fails. */
857 ddraw
->cooperative_level
|= DDSCL_CREATEDEVICEWINDOW
;
858 ddraw
->devicewindow
= device_window
;
860 if (cooplevel
& DDSCL_SETFOCUSWINDOW
)
868 if (FAILED(hr
= ddraw_set_focus_window(ddraw
, window
)))
872 window
= device_window
;
877 if (ddraw
->cooperative_level
& DDSCL_CREATEDEVICEWINDOW
)
878 DestroyWindow(ddraw
->devicewindow
);
879 ddraw
->devicewindow
= NULL
;
880 ddraw
->focuswindow
= NULL
;
883 if ((cooplevel
& DDSCL_FULLSCREEN
) != (ddraw
->cooperative_level
& DDSCL_FULLSCREEN
) || window
!= ddraw
->dest_window
)
885 if (ddraw
->cooperative_level
& DDSCL_FULLSCREEN
)
886 wined3d_device_restore_fullscreen_window(ddraw
->wined3d_device
, ddraw
->dest_window
);
888 if (cooplevel
& DDSCL_FULLSCREEN
)
890 struct wined3d_display_mode display_mode
;
892 wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &display_mode
, NULL
);
893 wined3d_device_setup_fullscreen_window(ddraw
->wined3d_device
, window
,
894 display_mode
.width
, display_mode
.height
);
898 if (cooplevel
& DDSCL_MULTITHREADED
&& !(ddraw
->cooperative_level
& DDSCL_MULTITHREADED
))
899 wined3d_device_set_multithreaded(ddraw
->wined3d_device
);
901 if (ddraw
->wined3d_swapchain
)
903 if (!(ddraw
->flags
& DDRAW_NO3D
))
905 restore_state
= TRUE
;
907 if (FAILED(hr
= wined3d_stateblock_create(ddraw
->wined3d_device
, WINED3D_SBT_ALL
, &stateblock
)))
909 ERR("Failed to create stateblock, hr %#x.\n", hr
);
913 wined3d_stateblock_capture(stateblock
);
914 rtv
= wined3d_device_get_rendertarget_view(ddraw
->wined3d_device
, 0);
915 /* Rendering to ddraw->wined3d_frontbuffer. */
916 if (rtv
&& !wined3d_rendertarget_view_get_sub_resource_parent(rtv
))
919 wined3d_rendertarget_view_incref(rtv
);
921 if ((dsv
= wined3d_device_get_depth_stencil_view(ddraw
->wined3d_device
)))
922 wined3d_rendertarget_view_incref(dsv
);
925 ddraw_destroy_swapchain(ddraw
);
928 if (FAILED(hr
= ddraw_create_swapchain(ddraw
, window
, !(cooplevel
& DDSCL_FULLSCREEN
))))
929 ERR("Failed to create swapchain, hr %#x.\n", hr
);
935 wined3d_device_set_depth_stencil_view(ddraw
->wined3d_device
, dsv
);
936 wined3d_rendertarget_view_decref(dsv
);
941 wined3d_device_set_rendertarget_view(ddraw
->wined3d_device
, 0, rtv
, FALSE
);
942 wined3d_rendertarget_view_decref(rtv
);
945 wined3d_stateblock_apply(stateblock
);
946 wined3d_stateblock_decref(stateblock
);
949 if (!(cooplevel
& DDSCL_EXCLUSIVE
) && (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
950 && restore_mode_on_normal
)
952 hr
= ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
954 ERR("RestoreDisplayMode failed\n");
957 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
958 && (window
!= ddraw
->dest_window
|| !(cooplevel
& DDSCL_EXCLUSIVE
)))
959 wined3d_device_release_focus_window(ddraw
->wined3d_device
);
961 if ((cooplevel
& DDSCL_EXCLUSIVE
)
962 && (window
!= ddraw
->dest_window
|| !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)))
964 hr
= wined3d_device_acquire_focus_window(ddraw
->wined3d_device
, window
);
967 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
972 /* Unhandled flags */
973 if (cooplevel
& DDSCL_ALLOWREBOOT
)
974 WARN("Unhandled flag DDSCL_ALLOWREBOOT, harmless\n");
975 if (cooplevel
& DDSCL_ALLOWMODEX
)
976 WARN("Unhandled flag DDSCL_ALLOWMODEX, harmless\n");
977 if (cooplevel
& DDSCL_FPUSETUP
)
978 WARN("Unhandled flag DDSCL_FPUSETUP, harmless\n");
980 if (cooplevel
& DDSCL_EXCLUSIVE
)
981 exclusive_ddraw
= ddraw
;
982 else if (exclusive_ddraw
== ddraw
)
983 exclusive_ddraw
= NULL
;
985 /* Store the cooperative_level */
986 ddraw
->cooperative_level
= cooplevel
;
987 ddraw
->dest_window
= window
;
989 TRACE("SetCooperativeLevel retuning DD_OK\n");
992 ddraw
->flags
&= ~DDRAW_SCL_RECURSIVE
;
993 wined3d_mutex_unlock();
998 static HRESULT WINAPI
ddraw7_SetCooperativeLevel(IDirectDraw7
*iface
, HWND window
, DWORD flags
)
1000 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1002 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1004 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1007 static HRESULT WINAPI
ddraw4_SetCooperativeLevel(IDirectDraw4
*iface
, HWND window
, DWORD flags
)
1009 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1011 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1013 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1016 static HRESULT WINAPI
ddraw2_SetCooperativeLevel(IDirectDraw2
*iface
, HWND window
, DWORD flags
)
1018 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1020 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1022 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1025 static HRESULT WINAPI
ddraw1_SetCooperativeLevel(IDirectDraw
*iface
, HWND window
, DWORD flags
)
1027 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1030 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1032 hr
= ddraw_set_cooperative_level(ddraw
, window
, flags
, FALSE
);
1034 ddraw
->flags
|= DDRAW_SCL_DDRAW1
;
1038 /*****************************************************************************
1039 * IDirectDraw7::SetDisplayMode
1041 * Sets the display screen resolution, color depth and refresh frequency
1042 * when in fullscreen mode (in theory).
1043 * Possible return values listed in the SDK suggest that this method fails
1044 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
1045 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
1046 * It seems to be valid to pass 0 for With and Height, this has to be tested
1047 * It could mean that the current video mode should be left as-is. (But why
1051 * Height, Width: Screen dimension
1052 * BPP: Color depth in Bits per pixel
1053 * Refreshrate: Screen refresh rate
1054 * Flags: Other stuff
1059 *****************************************************************************/
1060 static HRESULT WINAPI
ddraw7_SetDisplayMode(IDirectDraw7
*iface
, DWORD width
, DWORD height
,
1061 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1063 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1064 struct wined3d_display_mode mode
;
1065 enum wined3d_format_id format
;
1068 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1069 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1071 if (force_refresh_rate
!= 0)
1073 TRACE("ForceRefreshRate overriding passed-in refresh rate (%u Hz) to %u Hz\n",
1074 refresh_rate
, force_refresh_rate
);
1075 refresh_rate
= force_refresh_rate
;
1078 wined3d_mutex_lock();
1080 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
1082 wined3d_mutex_unlock();
1083 return DDERR_NOEXCLUSIVEMODE
;
1086 if (!width
|| !height
)
1088 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here. */
1089 wined3d_mutex_unlock();
1095 case 8: format
= WINED3DFMT_P8_UINT
; break;
1096 case 15: format
= WINED3DFMT_B5G5R5X1_UNORM
; break;
1097 case 16: format
= WINED3DFMT_B5G6R5_UNORM
; break;
1098 case 24: format
= WINED3DFMT_B8G8R8_UNORM
; break;
1099 case 32: format
= WINED3DFMT_B8G8R8X8_UNORM
; break;
1100 default: format
= WINED3DFMT_UNKNOWN
; break;
1104 mode
.height
= height
;
1105 mode
.refresh_rate
= refresh_rate
;
1106 mode
.format_id
= format
;
1107 mode
.scanline_ordering
= WINED3D_SCANLINE_ORDERING_UNKNOWN
;
1109 /* TODO: The possible return values from msdn suggest that the screen mode
1110 * can't be changed if a surface is locked or some drawing is in progress. */
1111 /* TODO: Lose the primary surface. */
1112 if (SUCCEEDED(hr
= wined3d_set_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
)))
1113 ddraw
->flags
|= DDRAW_RESTORE_MODE
;
1115 wined3d_mutex_unlock();
1119 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1124 static HRESULT WINAPI
ddraw4_SetDisplayMode(IDirectDraw4
*iface
, DWORD width
, DWORD height
,
1125 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1127 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1129 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1130 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1132 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1135 static HRESULT WINAPI
ddraw2_SetDisplayMode(IDirectDraw2
*iface
,
1136 DWORD width
, DWORD height
, DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1138 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1140 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1141 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1143 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1146 static HRESULT WINAPI
ddraw1_SetDisplayMode(IDirectDraw
*iface
, DWORD width
, DWORD height
, DWORD bpp
)
1148 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1150 TRACE("iface %p, width %u, height %u, bpp %u.\n", iface
, width
, height
, bpp
);
1152 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, 0, 0);
1155 void ddraw_d3dcaps1_from_7(D3DDEVICEDESC
*caps1
, D3DDEVICEDESC7
*caps7
)
1157 memset(caps1
, 0, sizeof(*caps1
));
1158 caps1
->dwSize
= sizeof(*caps1
);
1159 caps1
->dwFlags
= D3DDD_COLORMODEL
1161 | D3DDD_TRANSFORMCAPS
1163 | D3DDD_LIGHTINGCAPS
1166 | D3DDD_DEVICERENDERBITDEPTH
1167 | D3DDD_DEVICEZBUFFERBITDEPTH
1168 | D3DDD_MAXBUFFERSIZE
1169 | D3DDD_MAXVERTEXCOUNT
;
1170 caps1
->dcmColorModel
= D3DCOLOR_RGB
;
1171 caps1
->dwDevCaps
= caps7
->dwDevCaps
;
1172 caps1
->dtcTransformCaps
.dwSize
= sizeof(caps1
->dtcTransformCaps
);
1173 caps1
->dtcTransformCaps
.dwCaps
= D3DTRANSFORMCAPS_CLIP
;
1174 caps1
->bClipping
= TRUE
;
1175 caps1
->dlcLightingCaps
.dwSize
= sizeof(caps1
->dlcLightingCaps
);
1176 caps1
->dlcLightingCaps
.dwCaps
= D3DLIGHTCAPS_DIRECTIONAL
1177 | D3DLIGHTCAPS_PARALLELPOINT
1178 | D3DLIGHTCAPS_POINT
1179 | D3DLIGHTCAPS_SPOT
;
1180 caps1
->dlcLightingCaps
.dwLightingModel
= D3DLIGHTINGMODEL_RGB
;
1181 caps1
->dlcLightingCaps
.dwNumLights
= caps7
->dwMaxActiveLights
;
1182 caps1
->dpcLineCaps
= caps7
->dpcLineCaps
;
1183 caps1
->dpcTriCaps
= caps7
->dpcTriCaps
;
1184 caps1
->dwDeviceRenderBitDepth
= caps7
->dwDeviceRenderBitDepth
;
1185 caps1
->dwDeviceZBufferBitDepth
= caps7
->dwDeviceZBufferBitDepth
;
1186 caps1
->dwMaxBufferSize
= 0;
1187 caps1
->dwMaxVertexCount
= 65536;
1188 caps1
->dwMinTextureWidth
= caps7
->dwMinTextureWidth
;
1189 caps1
->dwMinTextureHeight
= caps7
->dwMinTextureHeight
;
1190 caps1
->dwMaxTextureWidth
= caps7
->dwMaxTextureWidth
;
1191 caps1
->dwMaxTextureHeight
= caps7
->dwMaxTextureHeight
;
1192 caps1
->dwMinStippleWidth
= 1;
1193 caps1
->dwMinStippleHeight
= 1;
1194 caps1
->dwMaxStippleWidth
= 32;
1195 caps1
->dwMaxStippleHeight
= 32;
1196 caps1
->dwMaxTextureRepeat
= caps7
->dwMaxTextureRepeat
;
1197 caps1
->dwMaxTextureAspectRatio
= caps7
->dwMaxTextureAspectRatio
;
1198 caps1
->dwMaxAnisotropy
= caps7
->dwMaxAnisotropy
;
1199 caps1
->dvGuardBandLeft
= caps7
->dvGuardBandLeft
;
1200 caps1
->dvGuardBandTop
= caps7
->dvGuardBandTop
;
1201 caps1
->dvGuardBandRight
= caps7
->dvGuardBandRight
;
1202 caps1
->dvGuardBandBottom
= caps7
->dvGuardBandBottom
;
1203 caps1
->dvExtentsAdjust
= caps7
->dvExtentsAdjust
;
1204 caps1
->dwStencilCaps
= caps7
->dwStencilCaps
;
1205 caps1
->dwFVFCaps
= caps7
->dwFVFCaps
;
1206 caps1
->dwTextureOpCaps
= caps7
->dwTextureOpCaps
;
1207 caps1
->wMaxTextureBlendStages
= caps7
->wMaxTextureBlendStages
;
1208 caps1
->wMaxSimultaneousTextures
= caps7
->wMaxSimultaneousTextures
;
1211 HRESULT
ddraw_get_d3dcaps(const struct ddraw
*ddraw
, D3DDEVICEDESC7
*caps
)
1213 WINED3DCAPS wined3d_caps
;
1216 TRACE("ddraw %p, caps %p.\n", ddraw
, caps
);
1218 memset(&wined3d_caps
, 0, sizeof(wined3d_caps
));
1220 wined3d_mutex_lock();
1221 hr
= wined3d_get_device_caps(ddraw
->wined3d
, 0, WINED3D_DEVICE_TYPE_HAL
, &wined3d_caps
);
1222 wined3d_mutex_unlock();
1225 WARN("Failed to get device caps, hr %#x.\n", hr
);
1229 caps
->dwDevCaps
= wined3d_caps
.DevCaps
;
1230 caps
->dpcLineCaps
.dwMiscCaps
= wined3d_caps
.PrimitiveMiscCaps
;
1231 caps
->dpcLineCaps
.dwRasterCaps
= wined3d_caps
.RasterCaps
;
1232 caps
->dpcLineCaps
.dwZCmpCaps
= wined3d_caps
.ZCmpCaps
;
1233 caps
->dpcLineCaps
.dwSrcBlendCaps
= wined3d_caps
.SrcBlendCaps
;
1234 caps
->dpcLineCaps
.dwDestBlendCaps
= wined3d_caps
.DestBlendCaps
;
1235 caps
->dpcLineCaps
.dwAlphaCmpCaps
= wined3d_caps
.AlphaCmpCaps
;
1236 caps
->dpcLineCaps
.dwShadeCaps
= wined3d_caps
.ShadeCaps
;
1237 caps
->dpcLineCaps
.dwTextureCaps
= wined3d_caps
.TextureCaps
;
1238 caps
->dpcLineCaps
.dwTextureFilterCaps
= wined3d_caps
.TextureFilterCaps
;
1239 caps
->dpcLineCaps
.dwTextureAddressCaps
= wined3d_caps
.TextureAddressCaps
;
1241 caps
->dwMaxTextureWidth
= wined3d_caps
.MaxTextureWidth
;
1242 caps
->dwMaxTextureHeight
= wined3d_caps
.MaxTextureHeight
;
1244 caps
->dwMaxTextureRepeat
= wined3d_caps
.MaxTextureRepeat
;
1245 caps
->dwMaxTextureAspectRatio
= wined3d_caps
.MaxTextureAspectRatio
;
1246 caps
->dwMaxAnisotropy
= wined3d_caps
.MaxAnisotropy
;
1247 caps
->dvMaxVertexW
= wined3d_caps
.MaxVertexW
;
1249 caps
->dvGuardBandLeft
= wined3d_caps
.GuardBandLeft
;
1250 caps
->dvGuardBandTop
= wined3d_caps
.GuardBandTop
;
1251 caps
->dvGuardBandRight
= wined3d_caps
.GuardBandRight
;
1252 caps
->dvGuardBandBottom
= wined3d_caps
.GuardBandBottom
;
1254 caps
->dvExtentsAdjust
= wined3d_caps
.ExtentsAdjust
;
1255 caps
->dwStencilCaps
= wined3d_caps
.StencilCaps
;
1257 caps
->dwFVFCaps
= wined3d_caps
.FVFCaps
;
1258 caps
->dwTextureOpCaps
= wined3d_caps
.TextureOpCaps
;
1260 caps
->dwVertexProcessingCaps
= wined3d_caps
.VertexProcessingCaps
;
1261 caps
->dwMaxActiveLights
= wined3d_caps
.MaxActiveLights
;
1263 /* Remove all non-d3d7 caps */
1264 caps
->dwDevCaps
&= (
1265 D3DDEVCAPS_FLOATTLVERTEX
| D3DDEVCAPS_SORTINCREASINGZ
| D3DDEVCAPS_SORTDECREASINGZ
|
1266 D3DDEVCAPS_SORTEXACT
| D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
|
1267 D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
| D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
|
1268 D3DDEVCAPS_TEXTUREVIDEOMEMORY
| D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
|
1269 D3DDEVCAPS_TEXTURENONLOCALVIDMEM
| D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
1270 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
1271 D3DDEVCAPS_HWRASTERIZATION
);
1273 caps
->dwStencilCaps
&= (
1274 D3DSTENCILCAPS_KEEP
| D3DSTENCILCAPS_ZERO
| D3DSTENCILCAPS_REPLACE
|
1275 D3DSTENCILCAPS_INCRSAT
| D3DSTENCILCAPS_DECRSAT
| D3DSTENCILCAPS_INVERT
|
1276 D3DSTENCILCAPS_INCR
| D3DSTENCILCAPS_DECR
);
1280 caps
->dwTextureOpCaps
&= (
1281 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_SELECTARG2
|
1282 D3DTEXOPCAPS_MODULATE
| D3DTEXOPCAPS_MODULATE2X
| D3DTEXOPCAPS_MODULATE4X
|
1283 D3DTEXOPCAPS_ADD
| D3DTEXOPCAPS_ADDSIGNED
| D3DTEXOPCAPS_ADDSIGNED2X
|
1284 D3DTEXOPCAPS_SUBTRACT
| D3DTEXOPCAPS_ADDSMOOTH
| D3DTEXOPCAPS_BLENDTEXTUREALPHA
|
1285 D3DTEXOPCAPS_BLENDFACTORALPHA
| D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
| D3DTEXOPCAPS_BLENDCURRENTALPHA
|
1286 D3DTEXOPCAPS_PREMODULATE
| D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
|
1287 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
| D3DTEXOPCAPS_BUMPENVMAP
|
1288 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
| D3DTEXOPCAPS_DOTPRODUCT3
);
1290 caps
->dwVertexProcessingCaps
&= (
1291 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_VERTEXFOG
|
1292 D3DVTXPCAPS_DIRECTIONALLIGHTS
| D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
);
1294 caps
->dpcLineCaps
.dwMiscCaps
&= (
1295 D3DPMISCCAPS_MASKPLANES
| D3DPMISCCAPS_MASKZ
| D3DPMISCCAPS_LINEPATTERNREP
|
1296 D3DPMISCCAPS_CONFORMANT
| D3DPMISCCAPS_CULLNONE
| D3DPMISCCAPS_CULLCW
|
1297 D3DPMISCCAPS_CULLCCW
);
1299 caps
->dpcLineCaps
.dwRasterCaps
&= (
1300 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ROP2
| D3DPRASTERCAPS_XOR
|
1301 D3DPRASTERCAPS_PAT
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_SUBPIXEL
|
1302 D3DPRASTERCAPS_SUBPIXELX
| D3DPRASTERCAPS_FOGVERTEX
| D3DPRASTERCAPS_FOGTABLE
|
1303 D3DPRASTERCAPS_STIPPLE
| D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT
| D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT
|
1304 D3DPRASTERCAPS_ANTIALIASEDGES
| D3DPRASTERCAPS_MIPMAPLODBIAS
| D3DPRASTERCAPS_ZBIAS
|
1305 D3DPRASTERCAPS_ZBUFFERLESSHSR
| D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
|
1306 D3DPRASTERCAPS_WBUFFER
| D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT
| D3DPRASTERCAPS_WFOG
|
1307 D3DPRASTERCAPS_ZFOG
);
1309 caps
->dpcLineCaps
.dwZCmpCaps
&= (
1310 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
1311 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
1312 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
1314 caps
->dpcLineCaps
.dwSrcBlendCaps
&= (
1315 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
1316 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
1317 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
1318 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
1319 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
1321 caps
->dpcLineCaps
.dwDestBlendCaps
&= (
1322 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
1323 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
1324 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
1325 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
1326 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
1328 caps
->dpcLineCaps
.dwAlphaCmpCaps
&= (
1329 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
1330 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
1331 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
1333 caps
->dpcLineCaps
.dwShadeCaps
&= (
1334 D3DPSHADECAPS_COLORFLATMONO
| D3DPSHADECAPS_COLORFLATRGB
| D3DPSHADECAPS_COLORGOURAUDMONO
|
1335 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_COLORPHONGMONO
| D3DPSHADECAPS_COLORPHONGRGB
|
1336 D3DPSHADECAPS_SPECULARFLATMONO
| D3DPSHADECAPS_SPECULARFLATRGB
| D3DPSHADECAPS_SPECULARGOURAUDMONO
|
1337 D3DPSHADECAPS_SPECULARGOURAUDRGB
| D3DPSHADECAPS_SPECULARPHONGMONO
| D3DPSHADECAPS_SPECULARPHONGRGB
|
1338 D3DPSHADECAPS_ALPHAFLATBLEND
| D3DPSHADECAPS_ALPHAFLATSTIPPLED
| D3DPSHADECAPS_ALPHAGOURAUDBLEND
|
1339 D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED
| D3DPSHADECAPS_ALPHAPHONGBLEND
| D3DPSHADECAPS_ALPHAPHONGSTIPPLED
|
1340 D3DPSHADECAPS_FOGFLAT
| D3DPSHADECAPS_FOGGOURAUD
| D3DPSHADECAPS_FOGPHONG
);
1342 caps
->dpcLineCaps
.dwTextureCaps
&= (
1343 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
1344 D3DPTEXTURECAPS_TRANSPARENCY
| D3DPTEXTURECAPS_BORDER
| D3DPTEXTURECAPS_SQUAREONLY
|
1345 D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
| D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
1346 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_COLORKEYBLEND
);
1348 caps
->dpcLineCaps
.dwTextureFilterCaps
&= (
1349 D3DPTFILTERCAPS_NEAREST
| D3DPTFILTERCAPS_LINEAR
| D3DPTFILTERCAPS_MIPNEAREST
|
1350 D3DPTFILTERCAPS_MIPLINEAR
| D3DPTFILTERCAPS_LINEARMIPNEAREST
| D3DPTFILTERCAPS_LINEARMIPLINEAR
|
1351 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
1352 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
1353 D3DPTFILTERCAPS_MAGFLINEAR
| D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
|
1354 D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
);
1356 caps
->dpcLineCaps
.dwTextureAddressCaps
&= (
1357 D3DPTADDRESSCAPS_WRAP
| D3DPTADDRESSCAPS_MIRROR
| D3DPTADDRESSCAPS_CLAMP
|
1358 D3DPTADDRESSCAPS_BORDER
| D3DPTADDRESSCAPS_INDEPENDENTUV
);
1360 if (!(caps
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
))
1362 /* DirectX7 always has the np2 flag set, no matter what the card
1363 * supports. Some old games (Rollcage) check the caps incorrectly.
1364 * If wined3d supports nonpow2 textures it also has np2 conditional
1366 caps
->dpcLineCaps
.dwTextureCaps
|= D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
;
1369 /* Fill the missing members, and do some fixup */
1370 caps
->dpcLineCaps
.dwSize
= sizeof(caps
->dpcLineCaps
);
1371 caps
->dpcLineCaps
.dwTextureBlendCaps
= D3DPTBLENDCAPS_ADD
1372 | D3DPTBLENDCAPS_MODULATEMASK
1373 | D3DPTBLENDCAPS_COPY
1374 | D3DPTBLENDCAPS_DECAL
1375 | D3DPTBLENDCAPS_DECALALPHA
1376 | D3DPTBLENDCAPS_DECALMASK
1377 | D3DPTBLENDCAPS_MODULATE
1378 | D3DPTBLENDCAPS_MODULATEALPHA
;
1379 caps
->dpcLineCaps
.dwStippleWidth
= 32;
1380 caps
->dpcLineCaps
.dwStippleHeight
= 32;
1381 /* Use the same for the TriCaps */
1382 caps
->dpcTriCaps
= caps
->dpcLineCaps
;
1384 caps
->dwDeviceRenderBitDepth
= DDBD_16
| DDBD_24
| DDBD_32
;
1385 caps
->dwDeviceZBufferBitDepth
= DDBD_16
| DDBD_24
;
1386 caps
->dwMinTextureWidth
= 1;
1387 caps
->dwMinTextureHeight
= 1;
1389 /* Convert DWORDs safely to WORDs */
1390 if (wined3d_caps
.MaxTextureBlendStages
> 0xffff)
1391 caps
->wMaxTextureBlendStages
= 0xffff;
1393 caps
->wMaxTextureBlendStages
= (WORD
)wined3d_caps
.MaxTextureBlendStages
;
1394 if (wined3d_caps
.MaxSimultaneousTextures
> 0xffff)
1395 caps
->wMaxSimultaneousTextures
= 0xffff;
1397 caps
->wMaxSimultaneousTextures
= (WORD
)wined3d_caps
.MaxSimultaneousTextures
;
1399 if (wined3d_caps
.MaxUserClipPlanes
> 0xffff)
1400 caps
->wMaxUserClipPlanes
= 0xffff;
1402 caps
->wMaxUserClipPlanes
= (WORD
)wined3d_caps
.MaxUserClipPlanes
;
1403 if (wined3d_caps
.MaxVertexBlendMatrices
> 0xffff)
1404 caps
->wMaxVertexBlendMatrices
= 0xffff;
1406 caps
->wMaxVertexBlendMatrices
= (WORD
)wined3d_caps
.MaxVertexBlendMatrices
;
1408 caps
->deviceGUID
= IID_IDirect3DTnLHalDevice
;
1410 caps
->dwReserved1
= 0;
1411 caps
->dwReserved2
= 0;
1412 caps
->dwReserved3
= 0;
1413 caps
->dwReserved4
= 0;
1418 /*****************************************************************************
1419 * IDirectDraw7::GetCaps
1421 * Returns the drives capabilities
1423 * Used for version 1, 2, 4 and 7
1426 * DriverCaps: Structure to write the Hardware accelerated caps to
1427 * HelCaps: Structure to write the emulation caps to
1430 * This implementation returns DD_OK only
1432 *****************************************************************************/
1433 static HRESULT WINAPI
ddraw7_GetCaps(IDirectDraw7
*iface
, DDCAPS
*DriverCaps
, DDCAPS
*HELCaps
)
1435 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1437 WINED3DCAPS winecaps
;
1439 DDSCAPS2 ddscaps
= {0, 0, 0, {0}};
1441 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, DriverCaps
, HELCaps
);
1443 /* One structure must be != NULL */
1444 if (!DriverCaps
&& !HELCaps
)
1446 WARN("Invalid parameters.\n");
1447 return DDERR_INVALIDPARAMS
;
1450 memset(&caps
, 0, sizeof(caps
));
1451 memset(&winecaps
, 0, sizeof(winecaps
));
1452 caps
.dwSize
= sizeof(caps
);
1454 wined3d_mutex_lock();
1455 hr
= wined3d_device_get_device_caps(ddraw
->wined3d_device
, &winecaps
);
1458 WARN("IWineD3DDevice::GetDeviceCaps failed\n");
1459 wined3d_mutex_unlock();
1463 hr
= IDirectDraw7_GetAvailableVidMem(iface
, &ddscaps
, &caps
.dwVidMemTotal
, &caps
.dwVidMemFree
);
1466 WARN("IDirectDraw7::GetAvailableVidMem failed\n");
1467 wined3d_mutex_unlock();
1471 hr
= IDirectDraw7_GetFourCCCodes(iface
, &caps
.dwNumFourCCCodes
, NULL
);
1472 wined3d_mutex_unlock();
1475 WARN("IDirectDraw7::GetFourCCCodes failed\n");
1479 caps
.dwCaps
= winecaps
.ddraw_caps
.caps
;
1480 caps
.dwCaps2
= winecaps
.ddraw_caps
.caps2
;
1481 caps
.dwCKeyCaps
= winecaps
.ddraw_caps
.color_key_caps
;
1482 caps
.dwFXCaps
= winecaps
.ddraw_caps
.fx_caps
;
1483 caps
.dwPalCaps
= DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
;
1484 caps
.ddsCaps
.dwCaps
= winecaps
.ddraw_caps
.dds_caps
;
1485 caps
.dwSVBCaps
= winecaps
.ddraw_caps
.svb_caps
;
1486 caps
.dwSVBCKeyCaps
= winecaps
.ddraw_caps
.svb_color_key_caps
;
1487 caps
.dwSVBFXCaps
= winecaps
.ddraw_caps
.svb_fx_caps
;
1488 caps
.dwVSBCaps
= winecaps
.ddraw_caps
.vsb_caps
;
1489 caps
.dwVSBCKeyCaps
= winecaps
.ddraw_caps
.vsb_color_key_caps
;
1490 caps
.dwVSBFXCaps
= winecaps
.ddraw_caps
.vsb_fx_caps
;
1491 caps
.dwSSBCaps
= winecaps
.ddraw_caps
.ssb_caps
;
1492 caps
.dwSSBCKeyCaps
= winecaps
.ddraw_caps
.ssb_color_key_caps
;
1493 caps
.dwSSBFXCaps
= winecaps
.ddraw_caps
.ssb_fx_caps
;
1495 caps
.dwCaps
|= DDCAPS_ALIGNSTRIDE
;
1496 caps
.dwAlignStrideAlign
= DDRAW_STRIDE_ALIGNMENT
;
1500 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &caps
);
1501 if (TRACE_ON(ddraw
))
1503 TRACE("Driver Caps :\n");
1504 DDRAW_dump_DDCAPS(DriverCaps
);
1510 DD_STRUCT_COPY_BYSIZE(HELCaps
, &caps
);
1511 if (TRACE_ON(ddraw
))
1513 TRACE("HEL Caps :\n");
1514 DDRAW_dump_DDCAPS(HELCaps
);
1521 static HRESULT WINAPI
ddraw4_GetCaps(IDirectDraw4
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1523 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1525 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1527 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1530 static HRESULT WINAPI
ddraw2_GetCaps(IDirectDraw2
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1532 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1534 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1536 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1539 static HRESULT WINAPI
ddraw1_GetCaps(IDirectDraw
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1541 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1543 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1545 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1548 /*****************************************************************************
1549 * IDirectDraw7::Compact
1551 * No idea what it does, MSDN says it's not implemented.
1554 * DD_OK, but this is unchecked
1556 *****************************************************************************/
1557 static HRESULT WINAPI
ddraw7_Compact(IDirectDraw7
*iface
)
1559 TRACE("iface %p.\n", iface
);
1564 static HRESULT WINAPI
ddraw4_Compact(IDirectDraw4
*iface
)
1566 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1568 TRACE("iface %p.\n", iface
);
1570 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1573 static HRESULT WINAPI
ddraw2_Compact(IDirectDraw2
*iface
)
1575 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1577 TRACE("iface %p.\n", iface
);
1579 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1582 static HRESULT WINAPI
ddraw1_Compact(IDirectDraw
*iface
)
1584 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1586 TRACE("iface %p.\n", iface
);
1588 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1591 /*****************************************************************************
1592 * IDirectDraw7::GetDisplayMode
1594 * Returns information about the current display mode
1596 * Exists in Version 1, 2, 4 and 7
1599 * DDSD: Address of a surface description structure to write the info to
1604 *****************************************************************************/
1605 static HRESULT WINAPI
ddraw7_GetDisplayMode(IDirectDraw7
*iface
, DDSURFACEDESC2
*DDSD
)
1607 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1608 struct wined3d_display_mode mode
;
1612 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
1614 wined3d_mutex_lock();
1615 /* This seems sane */
1618 wined3d_mutex_unlock();
1619 return DDERR_INVALIDPARAMS
;
1622 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1624 ERR("Failed to get display mode, hr %#x.\n", hr
);
1625 wined3d_mutex_unlock();
1629 Size
= DDSD
->dwSize
;
1630 memset(DDSD
, 0, Size
);
1632 DDSD
->dwSize
= Size
;
1633 DDSD
->dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
1634 DDSD
->dwWidth
= mode
.width
;
1635 DDSD
->dwHeight
= mode
.height
;
1636 DDSD
->u2
.dwRefreshRate
= 60;
1637 DDSD
->ddsCaps
.dwCaps
= 0;
1638 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
1639 ddrawformat_from_wined3dformat(&DDSD
->u4
.ddpfPixelFormat
, mode
.format_id
);
1640 DDSD
->u1
.lPitch
= mode
.width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
1644 TRACE("Returning surface desc :\n");
1645 DDRAW_dump_surface_desc(DDSD
);
1648 wined3d_mutex_unlock();
1653 static HRESULT WINAPI
ddraw4_GetDisplayMode(IDirectDraw4
*iface
, DDSURFACEDESC2
*surface_desc
)
1655 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1657 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1659 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, surface_desc
);
1662 static HRESULT WINAPI
ddraw2_GetDisplayMode(IDirectDraw2
*iface
, DDSURFACEDESC
*surface_desc
)
1664 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1666 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1668 /* FIXME: Test sizes, properly convert surface_desc */
1669 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1672 static HRESULT WINAPI
ddraw1_GetDisplayMode(IDirectDraw
*iface
, DDSURFACEDESC
*surface_desc
)
1674 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1676 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1678 /* FIXME: Test sizes, properly convert surface_desc */
1679 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1682 /*****************************************************************************
1683 * IDirectDraw7::GetFourCCCodes
1685 * Returns an array of supported FourCC codes.
1687 * Exists in Version 1, 2, 4 and 7
1690 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
1691 * of enumerated codes
1692 * Codes: Pointer to an array of DWORDs where the supported codes are written
1696 * Always returns DD_OK, as it's a stub for now
1698 *****************************************************************************/
1699 static HRESULT WINAPI
ddraw7_GetFourCCCodes(IDirectDraw7
*iface
, DWORD
*NumCodes
, DWORD
*Codes
)
1701 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1702 static const enum wined3d_format_id formats
[] =
1704 WINED3DFMT_YUY2
, WINED3DFMT_UYVY
, WINED3DFMT_YV12
,
1705 WINED3DFMT_DXT1
, WINED3DFMT_DXT2
, WINED3DFMT_DXT3
, WINED3DFMT_DXT4
, WINED3DFMT_DXT5
,
1706 WINED3DFMT_ATI2N
, WINED3DFMT_NVHU
, WINED3DFMT_NVHS
1708 struct wined3d_display_mode mode
;
1709 DWORD count
= 0, i
, outsize
;
1712 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, NumCodes
, Codes
);
1714 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1716 ERR("Failed to get display mode, hr %#x.\n", hr
);
1720 outsize
= NumCodes
&& Codes
? *NumCodes
: 0;
1722 for (i
= 0; i
< (sizeof(formats
) / sizeof(formats
[0])); ++i
)
1724 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, WINED3D_DEVICE_TYPE_HAL
,
1725 mode
.format_id
, 0, WINED3D_RTYPE_SURFACE
, formats
[i
])))
1727 if (count
< outsize
)
1728 Codes
[count
] = formats
[i
];
1733 TRACE("Returning %u FourCC codes\n", count
);
1740 static HRESULT WINAPI
ddraw4_GetFourCCCodes(IDirectDraw4
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1742 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1744 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1746 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1749 static HRESULT WINAPI
ddraw2_GetFourCCCodes(IDirectDraw2
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1751 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1753 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1755 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1758 static HRESULT WINAPI
ddraw1_GetFourCCCodes(IDirectDraw
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1760 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1762 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1764 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1767 static HRESULT WINAPI
ddraw7_GetMonitorFrequency(IDirectDraw7
*iface
, DWORD
*frequency
)
1769 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1770 struct wined3d_display_mode mode
;
1773 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1775 wined3d_mutex_lock();
1776 hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
);
1777 wined3d_mutex_unlock();
1780 WARN("Failed to get display mode, hr %#x.\n", hr
);
1784 *frequency
= mode
.refresh_rate
;
1789 static HRESULT WINAPI
ddraw4_GetMonitorFrequency(IDirectDraw4
*iface
, DWORD
*frequency
)
1791 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1793 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1795 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1798 static HRESULT WINAPI
ddraw2_GetMonitorFrequency(IDirectDraw2
*iface
, DWORD
*frequency
)
1800 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1802 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1804 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1807 static HRESULT WINAPI
ddraw1_GetMonitorFrequency(IDirectDraw
*iface
, DWORD
*frequency
)
1809 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1811 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1813 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1816 static HRESULT WINAPI
ddraw7_GetVerticalBlankStatus(IDirectDraw7
*iface
, BOOL
*status
)
1818 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1819 struct wined3d_raster_status raster_status
;
1822 TRACE("iface %p, status %p.\n", iface
, status
);
1825 return DDERR_INVALIDPARAMS
;
1827 wined3d_mutex_lock();
1828 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
1829 wined3d_mutex_unlock();
1832 WARN("Failed to get raster status, hr %#x.\n", hr
);
1836 *status
= raster_status
.in_vblank
;
1841 static HRESULT WINAPI
ddraw4_GetVerticalBlankStatus(IDirectDraw4
*iface
, BOOL
*status
)
1843 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1845 TRACE("iface %p, status %p.\n", iface
, status
);
1847 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1850 static HRESULT WINAPI
ddraw2_GetVerticalBlankStatus(IDirectDraw2
*iface
, BOOL
*status
)
1852 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1854 TRACE("iface %p, status %p.\n", iface
, status
);
1856 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1859 static HRESULT WINAPI
ddraw1_GetVerticalBlankStatus(IDirectDraw
*iface
, BOOL
*status
)
1861 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1863 TRACE("iface %p, status %p.\n", iface
, status
);
1865 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1868 /*****************************************************************************
1869 * IDirectDraw7::GetAvailableVidMem
1871 * Returns the total and free video memory
1874 * Caps: Specifies the memory type asked for
1875 * total: Pointer to a DWORD to be filled with the total memory
1876 * free: Pointer to a DWORD to be filled with the free memory
1880 * DDERR_INVALIDPARAMS if free and total are NULL
1882 *****************************************************************************/
1883 static HRESULT WINAPI
ddraw7_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*Caps
, DWORD
*total
,
1886 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1889 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, Caps
, total
, free
);
1891 if (TRACE_ON(ddraw
))
1893 TRACE("Asked for memory with description: ");
1894 DDRAW_dump_DDSCAPS2(Caps
);
1896 wined3d_mutex_lock();
1898 /* Todo: System memory vs local video memory vs non-local video memory
1899 * The MSDN also mentions differences between texture memory and other
1900 * resources, but that's not important
1903 if( (!total
) && (!free
) )
1905 wined3d_mutex_unlock();
1906 return DDERR_INVALIDPARAMS
;
1910 *free
= wined3d_device_get_available_texture_mem(ddraw
->wined3d_device
);
1913 struct wined3d_adapter_identifier desc
= {0};
1915 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0, &desc
);
1916 *total
= min(UINT_MAX
, desc
.video_memory
);
1919 wined3d_mutex_unlock();
1924 static HRESULT WINAPI
ddraw4_GetAvailableVidMem(IDirectDraw4
*iface
,
1925 DDSCAPS2
*caps
, DWORD
*total
, DWORD
*free
)
1927 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1929 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1931 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, caps
, total
, free
);
1934 static HRESULT WINAPI
ddraw2_GetAvailableVidMem(IDirectDraw2
*iface
,
1935 DDSCAPS
*caps
, DWORD
*total
, DWORD
*free
)
1937 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1940 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1942 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
1943 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, &caps2
, total
, free
);
1946 /*****************************************************************************
1947 * IDirectDraw7::Initialize
1949 * Initializes a DirectDraw interface.
1952 * GUID: Interface identifier. Well, don't know what this is really good
1956 * Returns DD_OK on the first call,
1957 * DDERR_ALREADYINITIALIZED on repeated calls
1959 *****************************************************************************/
1960 static HRESULT WINAPI
ddraw7_Initialize(IDirectDraw7
*iface
, GUID
*guid
)
1962 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1964 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1966 if (ddraw
->flags
& DDRAW_INITIALIZED
)
1967 return DDERR_ALREADYINITIALIZED
;
1969 /* FIXME: To properly take the GUID into account we should call
1970 * ddraw_init() here instead of in DDRAW_Create(). */
1972 FIXME("Ignoring guid %s.\n", debugstr_guid(guid
));
1974 ddraw
->flags
|= DDRAW_INITIALIZED
;
1978 static HRESULT WINAPI
ddraw4_Initialize(IDirectDraw4
*iface
, GUID
*guid
)
1980 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1982 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1984 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
1987 static HRESULT WINAPI
ddraw2_Initialize(IDirectDraw2
*iface
, GUID
*guid
)
1989 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1991 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1993 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
1996 static HRESULT WINAPI
ddraw1_Initialize(IDirectDraw
*iface
, GUID
*guid
)
1998 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2000 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2002 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2005 static HRESULT WINAPI
d3d1_Initialize(IDirect3D
*iface
, REFIID riid
)
2007 TRACE("iface %p, riid %s.\n", iface
, debugstr_guid(riid
));
2009 return DDERR_ALREADYINITIALIZED
;
2012 /*****************************************************************************
2013 * IDirectDraw7::FlipToGDISurface
2015 * "Makes the surface that the GDI writes to the primary surface"
2016 * Looks like some windows specific thing we don't have to care about.
2017 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
2018 * show error boxes ;)
2019 * Well, just return DD_OK.
2022 * Always returns DD_OK
2024 *****************************************************************************/
2025 static HRESULT WINAPI
ddraw7_FlipToGDISurface(IDirectDraw7
*iface
)
2027 FIXME("iface %p stub!\n", iface
);
2032 static HRESULT WINAPI
ddraw4_FlipToGDISurface(IDirectDraw4
*iface
)
2034 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2036 TRACE("iface %p.\n", iface
);
2038 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2041 static HRESULT WINAPI
ddraw2_FlipToGDISurface(IDirectDraw2
*iface
)
2043 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2045 TRACE("iface %p.\n", iface
);
2047 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2050 static HRESULT WINAPI
ddraw1_FlipToGDISurface(IDirectDraw
*iface
)
2052 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2054 TRACE("iface %p.\n", iface
);
2056 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2059 /*****************************************************************************
2060 * IDirectDraw7::WaitForVerticalBlank
2062 * This method allows applications to get in sync with the vertical blank
2064 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
2065 * redraw the screen, most likely because of this stub
2068 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
2069 * or DDWAITVB_BLOCKEND
2070 * h: Not used, according to MSDN
2073 * Always returns DD_OK
2075 *****************************************************************************/
2076 static HRESULT WINAPI
ddraw7_WaitForVerticalBlank(IDirectDraw7
*iface
, DWORD Flags
, HANDLE event
)
2080 TRACE("iface %p, flags %#x, event %p.\n", iface
, Flags
, event
);
2082 /* This function is called often, so print the fixme only once */
2085 FIXME("iface %p, flags %#x, event %p stub!\n", iface
, Flags
, event
);
2089 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
2090 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
2091 return DDERR_UNSUPPORTED
; /* unchecked */
2096 static HRESULT WINAPI
ddraw4_WaitForVerticalBlank(IDirectDraw4
*iface
, DWORD flags
, HANDLE event
)
2098 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2100 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2102 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2105 static HRESULT WINAPI
ddraw2_WaitForVerticalBlank(IDirectDraw2
*iface
, DWORD flags
, HANDLE event
)
2107 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2109 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2111 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2114 static HRESULT WINAPI
ddraw1_WaitForVerticalBlank(IDirectDraw
*iface
, DWORD flags
, HANDLE event
)
2116 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2118 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2120 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2123 static HRESULT WINAPI
ddraw7_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
2125 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2126 struct wined3d_raster_status raster_status
;
2129 TRACE("iface %p, line %p.\n", iface
, Scanline
);
2131 wined3d_mutex_lock();
2132 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
2133 wined3d_mutex_unlock();
2136 WARN("Failed to get raster status, hr %#x.\n", hr
);
2140 *Scanline
= raster_status
.scan_line
;
2142 if (raster_status
.in_vblank
)
2143 return DDERR_VERTICALBLANKINPROGRESS
;
2148 static HRESULT WINAPI
ddraw4_GetScanLine(IDirectDraw4
*iface
, DWORD
*line
)
2150 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2152 TRACE("iface %p, line %p.\n", iface
, line
);
2154 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2157 static HRESULT WINAPI
ddraw2_GetScanLine(IDirectDraw2
*iface
, DWORD
*line
)
2159 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2161 TRACE("iface %p, line %p.\n", iface
, line
);
2163 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2166 static HRESULT WINAPI
ddraw1_GetScanLine(IDirectDraw
*iface
, DWORD
*line
)
2168 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2170 TRACE("iface %p, line %p.\n", iface
, line
);
2172 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2175 static HRESULT WINAPI
ddraw7_TestCooperativeLevel(IDirectDraw7
*iface
)
2177 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2179 TRACE("iface %p.\n", iface
);
2181 return ddraw
->device_state
== DDRAW_DEVICE_STATE_OK
? DD_OK
: DDERR_NOEXCLUSIVEMODE
;
2184 static HRESULT WINAPI
ddraw4_TestCooperativeLevel(IDirectDraw4
*iface
)
2186 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2188 TRACE("iface %p.\n", iface
);
2190 return ddraw7_TestCooperativeLevel(&ddraw
->IDirectDraw7_iface
);
2193 /*****************************************************************************
2194 * IDirectDraw7::GetGDISurface
2196 * Returns the surface that GDI is treating as the primary surface.
2197 * For Wine this is the front buffer
2200 * GDISurface: Address to write the surface pointer to
2203 * DD_OK if the surface was found
2204 * DDERR_NOTFOUND if the GDI surface wasn't found
2206 *****************************************************************************/
2207 static HRESULT WINAPI
ddraw7_GetGDISurface(IDirectDraw7
*iface
, IDirectDrawSurface7
**GDISurface
)
2209 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2211 TRACE("iface %p, surface %p.\n", iface
, GDISurface
);
2213 wined3d_mutex_lock();
2215 if (!(*GDISurface
= &ddraw
->primary
->IDirectDrawSurface7_iface
))
2217 WARN("Primary not created yet.\n");
2218 wined3d_mutex_unlock();
2219 return DDERR_NOTFOUND
;
2221 IDirectDrawSurface7_AddRef(*GDISurface
);
2223 wined3d_mutex_unlock();
2228 static HRESULT WINAPI
ddraw4_GetGDISurface(IDirectDraw4
*iface
, IDirectDrawSurface4
**surface
)
2230 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2231 struct ddraw_surface
*surface_impl
;
2232 IDirectDrawSurface7
*surface7
;
2235 TRACE("iface %p, surface %p.\n", iface
, surface
);
2237 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2243 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2244 *surface
= &surface_impl
->IDirectDrawSurface4_iface
;
2245 IDirectDrawSurface4_AddRef(*surface
);
2246 IDirectDrawSurface7_Release(surface7
);
2251 static HRESULT WINAPI
ddraw2_GetGDISurface(IDirectDraw2
*iface
, IDirectDrawSurface
**surface
)
2253 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2254 struct ddraw_surface
*surface_impl
;
2255 IDirectDrawSurface7
*surface7
;
2258 TRACE("iface %p, surface %p.\n", iface
, surface
);
2260 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2266 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2267 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2268 IDirectDrawSurface_AddRef(*surface
);
2269 IDirectDrawSurface7_Release(surface7
);
2274 static HRESULT WINAPI
ddraw1_GetGDISurface(IDirectDraw
*iface
, IDirectDrawSurface
**surface
)
2276 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2277 struct ddraw_surface
*surface_impl
;
2278 IDirectDrawSurface7
*surface7
;
2281 TRACE("iface %p, surface %p.\n", iface
, surface
);
2283 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2289 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2290 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2291 IDirectDrawSurface_AddRef(*surface
);
2292 IDirectDrawSurface7_Release(surface7
);
2297 struct displaymodescallback_context
2299 LPDDENUMMODESCALLBACK func
;
2303 static HRESULT CALLBACK
EnumDisplayModesCallbackThunk(DDSURFACEDESC2
*surface_desc
, void *context
)
2305 struct displaymodescallback_context
*cbcontext
= context
;
2308 DDSD2_to_DDSD(surface_desc
, &desc
);
2309 return cbcontext
->func(&desc
, cbcontext
->context
);
2312 /*****************************************************************************
2313 * IDirectDraw7::EnumDisplayModes
2315 * Enumerates the supported Display modes. The modes can be filtered with
2316 * the DDSD parameter.
2319 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES. For old ddraw
2320 * versions (3 and older?) this is reserved and must be 0.
2321 * DDSD: Surface description to filter the modes
2322 * Context: Pointer passed back to the callback function
2323 * cb: Application-provided callback function
2327 * DDERR_INVALIDPARAMS if the callback wasn't set
2329 *****************************************************************************/
2330 static HRESULT WINAPI
ddraw7_EnumDisplayModes(IDirectDraw7
*iface
, DWORD Flags
,
2331 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMMODESCALLBACK2 cb
)
2333 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2334 struct wined3d_display_mode
*enum_modes
= NULL
;
2335 struct wined3d_display_mode mode
;
2336 unsigned int modenum
, fmt
;
2337 DDSURFACEDESC2 callback_sd
;
2338 unsigned enum_mode_count
= 0, enum_mode_array_size
= 16;
2339 DDPIXELFORMAT pixelformat
;
2341 static const enum wined3d_format_id checkFormatList
[] =
2343 WINED3DFMT_B8G8R8X8_UNORM
,
2344 WINED3DFMT_B5G6R5_UNORM
,
2348 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2349 iface
, Flags
, DDSD
, Context
, cb
);
2352 return DDERR_INVALIDPARAMS
;
2354 enum_modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(*enum_modes
) * enum_mode_array_size
);
2355 if (!enum_modes
) return DDERR_OUTOFMEMORY
;
2357 wined3d_mutex_lock();
2359 pixelformat
.dwSize
= sizeof(pixelformat
);
2360 for(fmt
= 0; fmt
< (sizeof(checkFormatList
) / sizeof(checkFormatList
[0])); fmt
++)
2363 while (wined3d_enum_adapter_modes(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, checkFormatList
[fmt
],
2364 WINED3D_SCANLINE_ORDERING_UNKNOWN
, modenum
++, &mode
) == WINED3D_OK
)
2369 ddrawformat_from_wined3dformat(&pixelformat
, mode
.format_id
);
2372 if (DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.width
!= DDSD
->dwWidth
)
2374 if (DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.height
!= DDSD
->dwHeight
)
2376 if (DDSD
->dwFlags
& DDSD_REFRESHRATE
&& mode
.refresh_rate
!= DDSD
->u2
.dwRefreshRate
)
2378 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
2379 && pixelformat
.u1
.dwRGBBitCount
!= DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
)
2383 /* DX docs state EnumDisplayMode should return only unique modes */
2384 for (i
= 0; i
< enum_mode_count
; i
++)
2386 if (enum_modes
[i
].width
== mode
.width
&& enum_modes
[i
].height
== mode
.height
2387 && enum_modes
[i
].format_id
== mode
.format_id
2388 && (enum_modes
[i
].refresh_rate
== mode
.refresh_rate
|| !(Flags
& DDEDM_REFRESHRATES
)))
2396 memset(&callback_sd
, 0, sizeof(callback_sd
));
2397 callback_sd
.dwSize
= sizeof(callback_sd
);
2398 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2400 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
|DDSD_REFRESHRATE
;
2401 if (Flags
& DDEDM_REFRESHRATES
)
2402 callback_sd
.u2
.dwRefreshRate
= mode
.refresh_rate
;
2404 callback_sd
.dwWidth
= mode
.width
;
2405 callback_sd
.dwHeight
= mode
.height
;
2407 callback_sd
.u4
.ddpfPixelFormat
=pixelformat
;
2409 /* Calc pitch and DWORD align like MSDN says */
2410 callback_sd
.u1
.lPitch
= (callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8) * mode
.width
;
2411 callback_sd
.u1
.lPitch
= (callback_sd
.u1
.lPitch
+ 3) & ~3;
2413 TRACE("Enumerating %dx%dx%d @%d\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
,
2414 callback_sd
.u2
.dwRefreshRate
);
2416 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
2418 TRACE("Application asked to terminate the enumeration\n");
2419 HeapFree(GetProcessHeap(), 0, enum_modes
);
2420 wined3d_mutex_unlock();
2424 if (enum_mode_count
== enum_mode_array_size
)
2426 struct wined3d_display_mode
*new_enum_modes
;
2428 enum_mode_array_size
*= 2;
2429 new_enum_modes
= HeapReAlloc(GetProcessHeap(), 0, enum_modes
,
2430 sizeof(*new_enum_modes
) * enum_mode_array_size
);
2431 if (!new_enum_modes
)
2433 HeapFree(GetProcessHeap(), 0, enum_modes
);
2434 wined3d_mutex_unlock();
2435 return DDERR_OUTOFMEMORY
;
2438 enum_modes
= new_enum_modes
;
2440 enum_modes
[enum_mode_count
++] = mode
;
2444 TRACE("End of enumeration\n");
2445 HeapFree(GetProcessHeap(), 0, enum_modes
);
2446 wined3d_mutex_unlock();
2451 static HRESULT WINAPI
ddraw4_EnumDisplayModes(IDirectDraw4
*iface
, DWORD flags
,
2452 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK2 callback
)
2454 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2456 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2457 iface
, flags
, surface_desc
, context
, callback
);
2459 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
, context
, callback
);
2462 static HRESULT WINAPI
ddraw2_EnumDisplayModes(IDirectDraw2
*iface
, DWORD flags
,
2463 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2465 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2466 struct displaymodescallback_context cbcontext
;
2467 DDSURFACEDESC2 surface_desc2
;
2469 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2470 iface
, flags
, surface_desc
, context
, callback
);
2472 cbcontext
.func
= callback
;
2473 cbcontext
.context
= context
;
2475 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2476 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2477 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2480 static HRESULT WINAPI
ddraw1_EnumDisplayModes(IDirectDraw
*iface
, DWORD flags
,
2481 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2483 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2484 struct displaymodescallback_context cbcontext
;
2485 DDSURFACEDESC2 surface_desc2
;
2487 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2488 iface
, flags
, surface_desc
, context
, callback
);
2490 cbcontext
.func
= callback
;
2491 cbcontext
.context
= context
;
2493 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2494 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2495 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2498 /*****************************************************************************
2499 * IDirectDraw7::EvaluateMode
2501 * Used with IDirectDraw7::StartModeTest to test video modes.
2502 * EvaluateMode is used to pass or fail a mode, and continue with the next
2506 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
2507 * Timeout: Returns the amount of seconds left before the mode would have
2508 * been failed automatically
2511 * This implementation always DD_OK, because it's a stub
2513 *****************************************************************************/
2514 static HRESULT WINAPI
ddraw7_EvaluateMode(IDirectDraw7
*iface
, DWORD Flags
, DWORD
*Timeout
)
2516 FIXME("iface %p, flags %#x, timeout %p stub!\n", iface
, Flags
, Timeout
);
2518 /* When implementing this, implement it in WineD3D */
2523 /*****************************************************************************
2524 * IDirectDraw7::GetDeviceIdentifier
2526 * Returns the device identifier, which gives information about the driver
2527 * Our device identifier is defined at the beginning of this file.
2530 * DDDI: Address for the returned structure
2531 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
2534 * On success it returns DD_OK
2535 * DDERR_INVALIDPARAMS if DDDI is NULL
2537 *****************************************************************************/
2538 static HRESULT WINAPI
ddraw7_GetDeviceIdentifier(IDirectDraw7
*iface
,
2539 DDDEVICEIDENTIFIER2
*DDDI
, DWORD Flags
)
2541 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2542 struct wined3d_adapter_identifier adapter_id
;
2545 TRACE("iface %p, device_identifier %p, flags %#x.\n", iface
, DDDI
, Flags
);
2548 return DDERR_INVALIDPARAMS
;
2550 if (Flags
& DDGDI_GETHOSTIDENTIFIER
)
2552 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
2553 * host adapter, if there's a secondary 3D adapter. This doesn't apply
2554 * to any modern hardware, nor is it interesting for Wine, so ignore it.
2555 * Size of DDDEVICEIDENTIFIER2 may be aligned to 8 bytes and thus 4
2556 * bytes too long. So only copy the relevant part of the structure
2559 memcpy(DDDI
, &deviceidentifier
, FIELD_OFFSET(DDDEVICEIDENTIFIER2
, dwWHQLLevel
) + sizeof(DWORD
));
2563 /* Drakan: Order of the Flame expects accurate D3D device information from ddraw */
2564 adapter_id
.driver
= DDDI
->szDriver
;
2565 adapter_id
.driver_size
= sizeof(DDDI
->szDriver
);
2566 adapter_id
.description
= DDDI
->szDescription
;
2567 adapter_id
.description_size
= sizeof(DDDI
->szDescription
);
2568 adapter_id
.device_name_size
= 0;
2569 wined3d_mutex_lock();
2570 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0x0, &adapter_id
);
2571 wined3d_mutex_unlock();
2572 if (FAILED(hr
)) return hr
;
2574 DDDI
->liDriverVersion
= adapter_id
.driver_version
;
2575 DDDI
->dwVendorId
= adapter_id
.vendor_id
;
2576 DDDI
->dwDeviceId
= adapter_id
.device_id
;
2577 DDDI
->dwSubSysId
= adapter_id
.subsystem_id
;
2578 DDDI
->dwRevision
= adapter_id
.revision
;
2579 DDDI
->guidDeviceIdentifier
= adapter_id
.device_identifier
;
2580 DDDI
->dwWHQLLevel
= adapter_id
.whql_level
;
2584 static HRESULT WINAPI
ddraw4_GetDeviceIdentifier(IDirectDraw4
*iface
,
2585 DDDEVICEIDENTIFIER
*identifier
, DWORD flags
)
2587 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2588 DDDEVICEIDENTIFIER2 identifier2
;
2591 TRACE("iface %p, identifier %p, flags %#x.\n", iface
, identifier
, flags
);
2593 hr
= ddraw7_GetDeviceIdentifier(&ddraw
->IDirectDraw7_iface
, &identifier2
, flags
);
2594 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&identifier2
, identifier
);
2599 /*****************************************************************************
2600 * IDirectDraw7::GetSurfaceFromDC
2602 * Returns the Surface for a GDI device context handle.
2603 * Is this related to IDirectDrawSurface::GetDC ???
2606 * hdc: hdc to return the surface for
2607 * Surface: Address to write the surface pointer to
2610 * Always returns DD_OK because it's a stub
2612 *****************************************************************************/
2613 static HRESULT WINAPI
ddraw7_GetSurfaceFromDC(IDirectDraw7
*iface
, HDC hdc
,
2614 IDirectDrawSurface7
**Surface
)
2616 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2617 struct wined3d_surface
*wined3d_surface
;
2618 struct ddraw_surface
*surface_impl
;
2620 TRACE("iface %p, dc %p, surface %p.\n", iface
, hdc
, Surface
);
2622 if (!Surface
) return E_INVALIDARG
;
2624 if (!(wined3d_surface
= wined3d_device_get_surface_from_dc(ddraw
->wined3d_device
, hdc
)))
2626 TRACE("No surface found for dc %p.\n", hdc
);
2628 return DDERR_NOTFOUND
;
2631 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
2632 *Surface
= &surface_impl
->IDirectDrawSurface7_iface
;
2633 IDirectDrawSurface7_AddRef(*Surface
);
2634 TRACE("Returning surface %p.\n", Surface
);
2638 static HRESULT WINAPI
ddraw4_GetSurfaceFromDC(IDirectDraw4
*iface
, HDC dc
,
2639 IDirectDrawSurface4
**surface
)
2641 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2642 struct ddraw_surface
*surface_impl
;
2643 IDirectDrawSurface7
*surface7
;
2646 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2648 if (!surface
) return E_INVALIDARG
;
2650 hr
= ddraw7_GetSurfaceFromDC(&ddraw
->IDirectDraw7_iface
, dc
, &surface7
);
2656 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2657 /* Tests say this is true */
2658 *surface
= (IDirectDrawSurface4
*)&surface_impl
->IDirectDrawSurface_iface
;
2659 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2660 IDirectDrawSurface7_Release(surface7
);
2665 static HRESULT CALLBACK
restore_callback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
2667 IDirectDrawSurface_Restore(surface
);
2668 IDirectDrawSurface_Release(surface
);
2670 return DDENUMRET_OK
;
2673 static HRESULT WINAPI
ddraw7_RestoreAllSurfaces(IDirectDraw7
*iface
)
2675 TRACE("iface %p.\n", iface
);
2677 return IDirectDraw7_EnumSurfaces(iface
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
2678 NULL
, NULL
, restore_callback
);
2681 static HRESULT WINAPI
ddraw4_RestoreAllSurfaces(IDirectDraw4
*iface
)
2683 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2685 TRACE("iface %p.\n", iface
);
2687 return ddraw7_RestoreAllSurfaces(&ddraw
->IDirectDraw7_iface
);
2690 /*****************************************************************************
2691 * IDirectDraw7::StartModeTest
2693 * Tests the specified video modes to update the system registry with
2694 * refresh rate information. StartModeTest starts the mode test,
2695 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
2696 * isn't called within 15 seconds, the mode is failed automatically
2698 * As refresh rates are handled by the X server, I don't think this
2699 * Method is important
2702 * Modes: An array of mode specifications
2703 * NumModes: The number of modes in Modes
2704 * Flags: Some flags...
2707 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
2708 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
2711 *****************************************************************************/
2712 static HRESULT WINAPI
ddraw7_StartModeTest(IDirectDraw7
*iface
, SIZE
*Modes
, DWORD NumModes
, DWORD Flags
)
2714 FIXME("iface %p, modes %p, mode_count %u, flags %#x partial stub!\n",
2715 iface
, Modes
, NumModes
, Flags
);
2717 /* This looks sane */
2718 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
2720 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
2721 * As it is not, DDERR_TESTFINISHED is returned
2722 * (hopefully that's correct
2724 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
2725 * well, that value doesn't (yet) exist in the wine headers, so ignore it
2731 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
, DDSURFACEDESC2
*surface_desc
,
2732 IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
2734 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2735 struct ddraw_surface
*impl
;
2738 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2739 iface
, surface_desc
, surface
, outer_unknown
);
2741 wined3d_mutex_lock();
2743 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2745 WARN("Cooperative level not set.\n");
2746 wined3d_mutex_unlock();
2747 return DDERR_NOCOOPERATIVELEVELSET
;
2750 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2752 WARN("Application supplied invalid surface descriptor\n");
2753 wined3d_mutex_unlock();
2754 return DDERR_INVALIDPARAMS
;
2757 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2759 if (TRACE_ON(ddraw
))
2761 TRACE(" (%p) Requesting surface desc :\n", iface
);
2762 DDRAW_dump_surface_desc(surface_desc
);
2765 WARN("Application tried to create an explicit front or back buffer\n");
2766 wined3d_mutex_unlock();
2767 return DDERR_INVALIDCAPS
;
2770 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 7);
2771 wined3d_mutex_unlock();
2778 *surface
= &impl
->IDirectDrawSurface7_iface
;
2779 IDirectDraw7_AddRef(iface
);
2780 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2785 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
2786 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
2788 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2789 struct ddraw_surface
*impl
;
2792 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2793 iface
, surface_desc
, surface
, outer_unknown
);
2795 wined3d_mutex_lock();
2797 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2799 WARN("Cooperative level not set.\n");
2800 wined3d_mutex_unlock();
2801 return DDERR_NOCOOPERATIVELEVELSET
;
2804 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2806 WARN("Application supplied invalid surface descriptor\n");
2807 wined3d_mutex_unlock();
2808 return DDERR_INVALIDPARAMS
;
2811 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2813 if (TRACE_ON(ddraw
))
2815 TRACE(" (%p) Requesting surface desc :\n", iface
);
2816 DDRAW_dump_surface_desc(surface_desc
);
2819 WARN("Application tried to create an explicit front or back buffer\n");
2820 wined3d_mutex_unlock();
2821 return DDERR_INVALIDCAPS
;
2824 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 4);
2825 wined3d_mutex_unlock();
2832 *surface
= &impl
->IDirectDrawSurface4_iface
;
2833 IDirectDraw4_AddRef(iface
);
2834 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2839 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
2840 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2842 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2843 struct ddraw_surface
*impl
;
2845 DDSURFACEDESC2 surface_desc2
;
2847 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2848 iface
, surface_desc
, surface
, outer_unknown
);
2850 wined3d_mutex_lock();
2852 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2854 WARN("Cooperative level not set.\n");
2855 wined3d_mutex_unlock();
2856 return DDERR_NOCOOPERATIVELEVELSET
;
2859 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2861 WARN("Application supplied invalid surface descriptor\n");
2862 wined3d_mutex_unlock();
2863 return DDERR_INVALIDPARAMS
;
2866 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2867 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2869 if (TRACE_ON(ddraw
))
2871 TRACE(" (%p) Requesting surface desc :\n", iface
);
2872 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
2875 WARN("Application tried to create an explicit front or back buffer\n");
2876 wined3d_mutex_unlock();
2877 return DDERR_INVALIDCAPS
;
2880 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 2);
2881 wined3d_mutex_unlock();
2888 *surface
= &impl
->IDirectDrawSurface_iface
;
2889 impl
->ifaceToRelease
= NULL
;
2894 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
2895 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2897 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2898 struct ddraw_surface
*impl
;
2900 DDSURFACEDESC2 surface_desc2
;
2902 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2903 iface
, surface_desc
, surface
, outer_unknown
);
2905 wined3d_mutex_lock();
2907 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2909 WARN("Cooperative level not set.\n");
2910 wined3d_mutex_unlock();
2911 return DDERR_NOCOOPERATIVELEVELSET
;
2914 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2916 WARN("Application supplied invalid surface descriptor\n");
2917 wined3d_mutex_unlock();
2918 return DDERR_INVALIDPARAMS
;
2921 if ((surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
))
2922 == (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
)
2923 || (surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
))
2924 == ((DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
)))
2926 WARN("Application tried to create an explicit front or back buffer.\n");
2927 wined3d_mutex_unlock();
2928 return DDERR_INVALIDCAPS
;
2931 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2932 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 1);
2933 wined3d_mutex_unlock();
2940 *surface
= &impl
->IDirectDrawSurface_iface
;
2941 impl
->ifaceToRelease
= NULL
;
2946 #define DDENUMSURFACES_SEARCHTYPE (DDENUMSURFACES_CANBECREATED|DDENUMSURFACES_DOESEXIST)
2947 #define DDENUMSURFACES_MATCHTYPE (DDENUMSURFACES_ALL|DDENUMSURFACES_MATCH|DDENUMSURFACES_NOMATCH)
2950 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
2951 const DDPIXELFORMAT
*provided
)
2953 /* Some flags must be present in both or neither for a match. */
2954 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
2955 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
2956 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
2958 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
2961 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
2964 if (requested
->dwFlags
& DDPF_FOURCC
)
2965 if (requested
->dwFourCC
!= provided
->dwFourCC
)
2968 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
2969 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
2970 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
2973 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
2974 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
2975 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
2978 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
2979 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
2982 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
2983 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
2985 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
2988 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
2989 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
2995 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3004 #define CMP(FLAG, FIELD) \
3005 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3006 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3008 static const struct compare_info compare
[] =
3010 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3011 CMP(BACKBUFFERCOUNT
, u5
.dwBackBufferCount
),
3013 CMP(CKDESTBLT
, ddckCKDestBlt
),
3014 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3015 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3016 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3017 CMP(HEIGHT
, dwHeight
),
3018 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3019 CMP(LPSURFACE
, lpSurface
),
3020 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3021 CMP(PITCH
, u1
/* lPitch */),
3022 /* PIXELFORMAT: manual */
3023 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3024 CMP(TEXTURESTAGE
, dwTextureStage
),
3025 CMP(WIDTH
, dwWidth
),
3026 /* ZBUFFERBITDEPTH: "obsolete" */
3033 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3036 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
3038 if (requested
->dwFlags
& compare
[i
].flag
3039 && memcmp((const char *)provided
+ compare
[i
].offset
,
3040 (const char *)requested
+ compare
[i
].offset
,
3041 compare
[i
].size
) != 0)
3045 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3047 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3048 &provided
->u4
.ddpfPixelFormat
))
3055 #undef DDENUMSURFACES_SEARCHTYPE
3056 #undef DDENUMSURFACES_MATCHTYPE
3058 struct surfacescallback2_context
3060 LPDDENUMSURFACESCALLBACK2 func
;
3064 struct surfacescallback_context
3066 LPDDENUMSURFACESCALLBACK func
;
3070 static HRESULT CALLBACK
EnumSurfacesCallback2Thunk(IDirectDrawSurface7
*surface
,
3071 DDSURFACEDESC2
*surface_desc
, void *context
)
3073 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3074 struct surfacescallback2_context
*cbcontext
= context
;
3076 IDirectDrawSurface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
3077 IDirectDrawSurface7_Release(surface
);
3079 return cbcontext
->func(&surface_impl
->IDirectDrawSurface4_iface
,
3080 surface_desc
, cbcontext
->context
);
3083 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3084 DDSURFACEDESC2
*surface_desc
, void *context
)
3086 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3087 struct surfacescallback_context
*cbcontext
= context
;
3089 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
3090 IDirectDrawSurface7_Release(surface
);
3092 return cbcontext
->func(&surface_impl
->IDirectDrawSurface_iface
,
3093 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3096 /*****************************************************************************
3097 * IDirectDraw7::EnumSurfaces
3099 * Loops through all surfaces attached to this device and calls the
3100 * application callback. This can't be relayed to WineD3DDevice,
3101 * because some WineD3DSurfaces' parents are IParent objects
3104 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3105 * DDSD: Description to filter for
3106 * Context: Application-provided pointer, it's passed unmodified to the
3108 * Callback: Address to call for each surface
3111 * DDERR_INVALIDPARAMS if the callback is NULL
3114 *****************************************************************************/
3115 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD Flags
,
3116 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMSURFACESCALLBACK7 Callback
)
3118 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3119 struct ddraw_surface
*surf
;
3120 DWORD match_flags
= Flags
& (DDENUMSURFACES_ALL
| DDENUMSURFACES_NOMATCH
| DDENUMSURFACES_MATCH
);
3122 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3123 iface
, Flags
, DDSD
, Context
, Callback
);
3126 return DDERR_INVALIDPARAMS
;
3128 if (Flags
& DDENUMSURFACES_CANBECREATED
)
3130 IDirectDrawSurface7
*surface
;
3131 DDSURFACEDESC2 testdesc
;
3133 if (match_flags
!= DDENUMSURFACES_MATCH
)
3134 return DDERR_INVALIDPARAMS
;
3137 return DDERR_INVALIDPARAMS
;
3139 memcpy(&testdesc
, DDSD
, sizeof(testdesc
));
3141 if (!(testdesc
.dwFlags
& DDSD_WIDTH
))
3143 testdesc
.dwFlags
|= DDSD_WIDTH
;
3144 testdesc
.dwWidth
= 512;
3147 if (!(testdesc
.dwFlags
& DDSD_HEIGHT
))
3149 testdesc
.dwFlags
|= DDSD_HEIGHT
;
3150 testdesc
.dwHeight
= 512;
3153 if (IDirectDraw7_CreateSurface(iface
, &testdesc
, &surface
, NULL
) == DD_OK
)
3155 surf
= unsafe_impl_from_IDirectDrawSurface7(surface
);
3156 Callback(NULL
, &surf
->surface_desc
, Context
);
3157 IDirectDrawSurface7_Release(surface
);
3160 FIXME("Failed to create surface!\n");
3162 else if (Flags
& DDENUMSURFACES_DOESEXIST
)
3164 DDSURFACEDESC2 desc
;
3165 struct list
*entry
, *entry2
;
3168 /* a combination of match flags is not allowed */
3169 if (match_flags
!= 0 &&
3170 match_flags
!= DDENUMSURFACES_ALL
&&
3171 match_flags
!= DDENUMSURFACES_MATCH
&&
3172 match_flags
!= DDENUMSURFACES_NOMATCH
)
3173 return DDERR_INVALIDPARAMS
;
3175 all
= (Flags
& DDENUMSURFACES_ALL
) != 0;
3176 nomatch
= (Flags
& DDENUMSURFACES_NOMATCH
) != 0;
3179 return DDERR_INVALIDPARAMS
;
3181 wined3d_mutex_lock();
3183 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
3184 LIST_FOR_EACH_SAFE(entry
, entry2
, &ddraw
->surface_list
)
3186 surf
= LIST_ENTRY(entry
, struct ddraw_surface
, surface_list_entry
);
3188 if (!surf
->iface_count
)
3190 WARN("Not enumerating surface %p because it doesn't have any references.\n", surf
);
3194 if (all
|| (nomatch
!= ddraw_match_surface_desc(DDSD
, &surf
->surface_desc
)))
3196 TRACE("Enumerating surface %p.\n", surf
);
3197 desc
= surf
->surface_desc
;
3198 IDirectDrawSurface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
3199 if (Callback(&surf
->IDirectDrawSurface7_iface
, &desc
, Context
) != DDENUMRET_OK
)
3201 wined3d_mutex_unlock();
3207 wined3d_mutex_unlock();
3210 return DDERR_INVALIDPARAMS
;
3215 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3216 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3218 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3219 struct surfacescallback2_context cbcontext
;
3221 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3222 iface
, flags
, surface_desc
, context
, callback
);
3224 cbcontext
.func
= callback
;
3225 cbcontext
.context
= context
;
3227 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
,
3228 &cbcontext
, EnumSurfacesCallback2Thunk
);
3231 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3232 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3234 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3235 struct surfacescallback_context cbcontext
;
3236 DDSURFACEDESC2 surface_desc2
;
3238 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3239 iface
, flags
, surface_desc
, context
, callback
);
3241 cbcontext
.func
= callback
;
3242 cbcontext
.context
= context
;
3244 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3245 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3246 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3249 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3250 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3252 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3253 struct surfacescallback_context cbcontext
;
3254 DDSURFACEDESC2 surface_desc2
;
3256 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3257 iface
, flags
, surface_desc
, context
, callback
);
3259 cbcontext
.func
= callback
;
3260 cbcontext
.context
= context
;
3262 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3263 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3264 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3267 /*****************************************************************************
3268 * DirectDrawCreateClipper (DDRAW.@)
3270 * Creates a new IDirectDrawClipper object.
3273 * Clipper: Address to write the interface pointer to
3274 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3278 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3279 * E_OUTOFMEMORY if allocating the object failed
3281 *****************************************************************************/
3282 HRESULT WINAPI
DirectDrawCreateClipper(DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3284 struct ddraw_clipper
*object
;
3287 TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
3288 flags
, clipper
, outer_unknown
);
3291 return CLASS_E_NOAGGREGATION
;
3293 wined3d_mutex_lock();
3295 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3298 wined3d_mutex_unlock();
3299 return E_OUTOFMEMORY
;
3302 hr
= ddraw_clipper_init(object
);
3305 WARN("Failed to initialize clipper, hr %#x.\n", hr
);
3306 HeapFree(GetProcessHeap(), 0, object
);
3307 wined3d_mutex_unlock();
3311 TRACE("Created clipper %p.\n", object
);
3312 *clipper
= &object
->IDirectDrawClipper_iface
;
3313 wined3d_mutex_unlock();
3318 /*****************************************************************************
3319 * IDirectDraw7::CreateClipper
3321 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3323 *****************************************************************************/
3324 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3325 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3327 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3328 iface
, Flags
, Clipper
, UnkOuter
);
3330 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3333 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
, DWORD flags
,
3334 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3336 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3338 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3339 iface
, flags
, clipper
, outer_unknown
);
3341 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3344 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
3345 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3347 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3349 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3350 iface
, flags
, clipper
, outer_unknown
);
3352 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3355 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
3356 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3358 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3360 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3361 iface
, flags
, clipper
, outer_unknown
);
3363 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3366 /*****************************************************************************
3367 * IDirectDraw7::CreatePalette
3369 * Creates a new IDirectDrawPalette object
3372 * Flags: The flags for the new clipper
3373 * ColorTable: Color table to assign to the new clipper
3374 * Palette: Address to write the interface pointer to
3375 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3379 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3380 * E_OUTOFMEMORY if allocating the object failed
3382 *****************************************************************************/
3383 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
3384 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
3386 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3387 struct ddraw_palette
*object
;
3390 TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
3391 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3394 return CLASS_E_NOAGGREGATION
;
3396 wined3d_mutex_lock();
3398 /* The refcount test shows that a cooplevel is required for this */
3399 if (!ddraw
->cooperative_level
)
3401 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3402 wined3d_mutex_unlock();
3403 return DDERR_NOCOOPERATIVELEVELSET
;
3406 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(*object
));
3409 ERR("Out of memory when allocating memory for a palette implementation\n");
3410 wined3d_mutex_unlock();
3411 return E_OUTOFMEMORY
;
3414 hr
= ddraw_palette_init(object
, ddraw
, Flags
, ColorTable
);
3417 WARN("Failed to initialize palette, hr %#x.\n", hr
);
3418 HeapFree(GetProcessHeap(), 0, object
);
3419 wined3d_mutex_unlock();
3423 TRACE("Created palette %p.\n", object
);
3424 *Palette
= &object
->IDirectDrawPalette_iface
;
3425 wined3d_mutex_unlock();
3430 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
, PALETTEENTRY
*entries
,
3431 IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3433 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3436 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3437 iface
, flags
, entries
, palette
, outer_unknown
);
3439 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3440 if (SUCCEEDED(hr
) && *palette
)
3442 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3443 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3444 IDirectDraw4_AddRef(iface
);
3445 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3450 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
3451 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3453 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3456 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3457 iface
, flags
, entries
, palette
, outer_unknown
);
3459 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3460 if (SUCCEEDED(hr
) && *palette
)
3462 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3463 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3464 impl
->ifaceToRelease
= NULL
;
3470 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
3471 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3473 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3476 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3477 iface
, flags
, entries
, palette
, outer_unknown
);
3479 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3480 if (SUCCEEDED(hr
) && *palette
)
3482 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3483 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3484 impl
->ifaceToRelease
= NULL
;
3490 /*****************************************************************************
3491 * IDirectDraw7::DuplicateSurface
3493 * Duplicates a surface. The surface memory points to the same memory as
3494 * the original surface, and it's released when the last surface referencing
3495 * it is released. I guess that's beyond Wine's surface management right now
3496 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3497 * test application to implement this)
3500 * Src: Address of the source surface
3501 * Dest: Address to write the new surface pointer to
3504 * See IDirectDraw7::CreateSurface
3506 *****************************************************************************/
3507 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
3508 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
3510 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(Src
);
3512 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
3514 /* For now, simply create a new, independent surface */
3515 return IDirectDraw7_CreateSurface(iface
, &src_surface
->surface_desc
, Dest
, NULL
);
3518 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
, IDirectDrawSurface4
*src
,
3519 IDirectDrawSurface4
**dst
)
3521 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
3522 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3523 struct ddraw_surface
*dst_impl
;
3524 IDirectDrawSurface7
*dst7
;
3527 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3529 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3530 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3536 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3537 *dst
= &dst_impl
->IDirectDrawSurface4_iface
;
3538 IDirectDrawSurface4_AddRef(*dst
);
3539 IDirectDrawSurface7_Release(dst7
);
3544 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
3545 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
3547 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3548 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3549 struct ddraw_surface
*dst_impl
;
3550 IDirectDrawSurface7
*dst7
;
3553 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3555 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3556 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3559 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3560 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3561 IDirectDrawSurface_AddRef(*dst
);
3562 IDirectDrawSurface7_Release(dst7
);
3567 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
, IDirectDrawSurface
*src
,
3568 IDirectDrawSurface
**dst
)
3570 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3571 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3572 struct ddraw_surface
*dst_impl
;
3573 IDirectDrawSurface7
*dst7
;
3576 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3578 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3579 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3582 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3583 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3584 IDirectDrawSurface_AddRef(*dst
);
3585 IDirectDrawSurface7_Release(dst7
);
3590 /*****************************************************************************
3591 * IDirect3D7::EnumDevices
3593 * The EnumDevices method for IDirect3D7. It enumerates all supported
3594 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
3597 * callback: Function to call for each enumerated device
3598 * context: Pointer to pass back to the app
3601 * D3D_OK, or the return value of the GetCaps call
3603 *****************************************************************************/
3604 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
3606 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
3607 D3DDEVICEDESC7 device_desc7
;
3611 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3614 return DDERR_INVALIDPARAMS
;
3616 wined3d_mutex_lock();
3618 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3620 wined3d_mutex_unlock();
3624 for (i
= 0; i
< sizeof(device_list7
)/sizeof(device_list7
[0]); i
++)
3628 device_desc7
.deviceGUID
= *device_list7
[i
].device_guid
;
3629 ret
= callback(device_list7
[i
].interface_name
, device_list7
[i
].device_name
, &device_desc7
, context
);
3630 if (ret
!= DDENUMRET_OK
)
3632 TRACE("Application cancelled the enumeration.\n");
3633 wined3d_mutex_unlock();
3638 TRACE("End of enumeration.\n");
3640 wined3d_mutex_unlock();
3645 /*****************************************************************************
3646 * IDirect3D3::EnumDevices
3648 * Enumerates all supported Direct3DDevice interfaces. This is the
3649 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
3651 * Version 1, 2 and 3
3654 * callback: Application-provided routine to call for each enumerated device
3655 * Context: Pointer to pass to the callback
3658 * D3D_OK on success,
3659 * The result of IDirect3DImpl_GetCaps if it failed
3661 *****************************************************************************/
3662 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3664 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
3666 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3667 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
3668 D3DDEVICEDESC7 device_desc7
;
3671 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
3672 * name string. Let's put the string in a sufficiently sized array in
3673 * writable memory. */
3674 char device_name
[50];
3675 strcpy(device_name
,"Direct3D HEL");
3677 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3680 return DDERR_INVALIDPARAMS
;
3682 wined3d_mutex_lock();
3684 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3686 wined3d_mutex_unlock();
3689 ddraw_d3dcaps1_from_7(&device_desc1
, &device_desc7
);
3691 /* Do I have to enumerate the reference id? Note from old d3d7:
3692 * "It seems that enumerating the reference IID on Direct3D 1 games
3693 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
3695 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
3696 * EnumReference which enables / disables enumerating the reference
3697 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
3698 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
3699 * demo directory suggest this.
3701 * Some games(GTA 2) seem to use the second enumerated device, so I have
3702 * to enumerate at least 2 devices. So enumerate the reference device to
3705 * Other games (Rollcage) tell emulation and hal device apart by certain
3706 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
3707 * limitation flag), and it refuses all devices that have the perspective
3708 * flag set. This way it refuses the emulation device, and HAL devices
3709 * never have POW2 unset in d3d7 on windows. */
3710 if (ddraw
->d3dversion
!= 1)
3712 static CHAR reference_description
[] = "RGB Direct3D emulation";
3714 TRACE("Enumerating WineD3D D3DDevice interface.\n");
3715 hal_desc
= device_desc1
;
3716 hel_desc
= device_desc1
;
3717 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
3718 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3719 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3720 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3721 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3722 /* RGB, RAMP and MMX devices have a HAL dcmColorModel of 0 */
3723 hal_desc
.dcmColorModel
= 0;
3724 /* RGB, RAMP and MMX devices cannot report HAL hardware flags */
3725 hal_desc
.dwFlags
= 0;
3727 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
3728 device_name
, &hal_desc
, &hel_desc
, context
);
3729 if (hr
!= D3DENUMRET_OK
)
3731 TRACE("Application cancelled the enumeration.\n");
3732 wined3d_mutex_unlock();
3737 strcpy(device_name
,"Direct3D HAL");
3739 TRACE("Enumerating HAL Direct3D device.\n");
3740 hal_desc
= device_desc1
;
3741 hel_desc
= device_desc1
;
3743 /* The hal device does not have the pow2 flag set in hel, but in hal. */
3744 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3745 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3746 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3747 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3748 /* HAL devices have a HEL dcmColorModel of 0 */
3749 hel_desc
.dcmColorModel
= 0;
3751 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
3752 device_name
, &hal_desc
, &hel_desc
, context
);
3753 if (hr
!= D3DENUMRET_OK
)
3755 TRACE("Application cancelled the enumeration.\n");
3756 wined3d_mutex_unlock();
3760 TRACE("End of enumeration.\n");
3762 wined3d_mutex_unlock();
3767 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3769 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3771 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3773 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3776 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3778 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3780 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3782 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3785 /*****************************************************************************
3786 * IDirect3D3::CreateLight
3788 * Creates an IDirect3DLight interface. This interface is used in
3789 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
3790 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
3791 * uses the IDirect3DDevice7 interface with D3D7 lights.
3793 * Version 1, 2 and 3
3796 * light: Address to store the new interface pointer
3797 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3802 * DDERR_OUTOFMEMORY if memory allocation failed
3803 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3805 *****************************************************************************/
3806 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
,
3807 IUnknown
*outer_unknown
)
3809 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3810 struct d3d_light
*object
;
3812 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3814 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3816 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3819 ERR("Failed to allocate light memory.\n");
3820 return DDERR_OUTOFMEMORY
;
3823 d3d_light_init(object
, ddraw
);
3825 TRACE("Created light %p.\n", object
);
3826 *light
= &object
->IDirect3DLight_iface
;
3831 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3833 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3835 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3837 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3840 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3842 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3844 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3846 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3849 /*****************************************************************************
3850 * IDirect3D3::CreateMaterial
3852 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
3853 * and older versions. The IDirect3DMaterial implementation wraps its
3854 * functionality to IDirect3DDevice7::SetMaterial and friends.
3856 * Version 1, 2 and 3
3859 * material: Address to store the new interface's pointer to
3860 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3865 * DDERR_OUTOFMEMORY if memory allocation failed
3866 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3868 *****************************************************************************/
3869 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
,
3870 IUnknown
*outer_unknown
)
3872 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3873 struct d3d_material
*object
;
3875 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3877 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3879 object
= d3d_material_create(ddraw
);
3882 ERR("Failed to allocate material memory.\n");
3883 return DDERR_OUTOFMEMORY
;
3886 TRACE("Created material %p.\n", object
);
3887 *material
= &object
->IDirect3DMaterial3_iface
;
3892 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
,
3893 IUnknown
*outer_unknown
)
3895 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3896 struct d3d_material
*object
;
3898 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3900 object
= d3d_material_create(ddraw
);
3903 ERR("Failed to allocate material memory.\n");
3904 return DDERR_OUTOFMEMORY
;
3907 TRACE("Created material %p.\n", object
);
3908 *material
= &object
->IDirect3DMaterial2_iface
;
3913 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
,
3914 IUnknown
*outer_unknown
)
3916 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3917 struct d3d_material
*object
;
3919 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3921 object
= d3d_material_create(ddraw
);
3924 ERR("Failed to allocate material memory.\n");
3925 return DDERR_OUTOFMEMORY
;
3928 TRACE("Created material %p.\n", object
);
3929 *material
= &object
->IDirect3DMaterial_iface
;
3934 /*****************************************************************************
3935 * IDirect3D3::CreateViewport
3937 * Creates an IDirect3DViewport interface. This interface is used
3938 * by Direct3D and earlier versions for Viewport management. In Direct3D7
3939 * it has been replaced by a viewport structure and
3940 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
3941 * uses the IDirect3DDevice7 methods for its functionality
3944 * Viewport: Address to store the new interface pointer
3945 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3950 * DDERR_OUTOFMEMORY if memory allocation failed
3951 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3953 *****************************************************************************/
3954 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
,
3955 IUnknown
*outer_unknown
)
3957 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3958 struct d3d_viewport
*object
;
3960 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
3962 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3964 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3967 ERR("Failed to allocate viewport memory.\n");
3968 return DDERR_OUTOFMEMORY
;
3971 d3d_viewport_init(object
, ddraw
);
3973 TRACE("Created viewport %p.\n", object
);
3974 *viewport
= &object
->IDirect3DViewport3_iface
;
3979 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
3981 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3983 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
3985 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
3989 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
3991 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3993 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
3995 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
3999 /*****************************************************************************
4000 * IDirect3D3::FindDevice
4002 * This method finds a device with the requested properties and returns a
4003 * device description
4007 * fds: Describes the requested device characteristics
4008 * fdr: Returns the device description
4012 * DDERR_INVALIDPARAMS if no device was found
4014 *****************************************************************************/
4015 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4017 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4018 D3DDEVICEDESC7 desc7
;
4019 D3DDEVICEDESC desc1
;
4022 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4024 if (!fds
|| !fdr
) return DDERR_INVALIDPARAMS
;
4026 if (fds
->dwSize
!= sizeof(D3DFINDDEVICESEARCH
)
4027 || fdr
->dwSize
!= sizeof(D3DFINDDEVICERESULT
))
4028 return DDERR_INVALIDPARAMS
;
4030 if ((fds
->dwFlags
& D3DFDS_COLORMODEL
)
4031 && fds
->dcmColorModel
!= D3DCOLOR_RGB
)
4033 WARN("Trying to request a non-RGB D3D color model. Not supported.\n");
4034 return DDERR_INVALIDPARAMS
; /* No real idea what to return here :-) */
4037 if (fds
->dwFlags
& D3DFDS_GUID
)
4039 TRACE("Trying to match guid %s.\n", debugstr_guid(&(fds
->guid
)));
4040 if (!IsEqualGUID(&IID_D3DDEVICE_WineD3D
, &fds
->guid
)
4041 && !IsEqualGUID(&IID_IDirect3DHALDevice
, &fds
->guid
)
4042 && !IsEqualGUID(&IID_IDirect3DRGBDevice
, &fds
->guid
))
4044 WARN("No match for this GUID.\n");
4045 return DDERR_NOTFOUND
;
4050 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &desc7
)))
4053 /* Now return our own GUID */
4054 ddraw_d3dcaps1_from_7(&desc1
, &desc7
);
4055 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4056 fdr
->ddHwDesc
= desc1
;
4057 fdr
->ddSwDesc
= desc1
;
4059 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4064 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4066 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4068 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4070 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4073 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4075 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4077 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4079 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4082 /*****************************************************************************
4083 * IDirect3D7::CreateDevice
4085 * Creates an IDirect3DDevice7 interface.
4087 * Version 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4088 * DirectDraw surfaces and are created with
4089 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4090 * create the device object and QueryInterfaces for IDirect3DDevice
4093 * refiid: IID of the device to create
4094 * Surface: Initial rendertarget
4095 * Device: Address to return the interface pointer
4099 * DDERR_OUTOFMEMORY if memory allocation failed
4100 * DDERR_INVALIDPARAMS if a device exists already
4102 *****************************************************************************/
4103 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4104 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4106 struct ddraw_surface
*target
= unsafe_impl_from_IDirectDrawSurface7(surface
);
4107 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4108 struct d3d_device
*object
;
4111 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4113 wined3d_mutex_lock();
4114 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, target
, (IUnknown
*)surface
, 7, &object
, NULL
)))
4116 *device
= &object
->IDirect3DDevice7_iface
;
4120 WARN("Failed to create device, hr %#x.\n", hr
);
4123 wined3d_mutex_unlock();
4128 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4129 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4131 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface4(surface
);
4132 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4133 struct d3d_device
*device_impl
;
4136 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4137 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4140 return CLASS_E_NOAGGREGATION
;
4142 wined3d_mutex_lock();
4143 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 3, &device_impl
, NULL
)))
4145 *device
= &device_impl
->IDirect3DDevice3_iface
;
4149 WARN("Failed to create device, hr %#x.\n", hr
);
4152 wined3d_mutex_unlock();
4157 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4158 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4160 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface(surface
);
4161 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4162 struct d3d_device
*device_impl
;
4165 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4166 iface
, debugstr_guid(riid
), surface
, device
);
4168 wined3d_mutex_lock();
4169 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 2, &device_impl
, NULL
)))
4171 *device
= &device_impl
->IDirect3DDevice2_iface
;
4175 WARN("Failed to create device, hr %#x.\n", hr
);
4178 wined3d_mutex_unlock();
4183 /*****************************************************************************
4184 * IDirect3D7::CreateVertexBuffer
4186 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4192 * desc: Requested Vertex buffer properties
4193 * vertex_buffer: Address to return the interface pointer at
4194 * flags: Some flags, should be 0
4198 * DDERR_OUTOFMEMORY if memory allocation failed
4199 * The return value of IWineD3DDevice::CreateVertexBuffer if this call fails
4200 * DDERR_INVALIDPARAMS if desc or vertex_buffer is NULL
4202 *****************************************************************************/
4203 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4204 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4206 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4207 struct d3d_vertex_buffer
*object
;
4210 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
4211 iface
, desc
, vertex_buffer
, flags
);
4213 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4215 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4218 TRACE("Created vertex buffer %p.\n", object
);
4219 *vertex_buffer
= &object
->IDirect3DVertexBuffer7_iface
;
4222 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4227 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4228 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4230 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4231 struct d3d_vertex_buffer
*object
;
4234 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n",
4235 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4238 return CLASS_E_NOAGGREGATION
;
4239 if (!vertex_buffer
|| !desc
)
4240 return DDERR_INVALIDPARAMS
;
4242 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4245 TRACE("Created vertex buffer %p.\n", object
);
4246 *vertex_buffer
= &object
->IDirect3DVertexBuffer_iface
;
4249 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4254 /*****************************************************************************
4255 * IDirect3D7::EnumZBufferFormats
4257 * Enumerates all supported Z buffer pixel formats
4263 * callback: callback to call for each pixel format
4264 * context: Pointer to pass back to the callback
4268 * DDERR_INVALIDPARAMS if callback is NULL
4269 * For details, see IWineD3DDevice::EnumZBufferFormats
4271 *****************************************************************************/
4272 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4273 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4275 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4276 struct wined3d_display_mode mode
;
4277 enum wined3d_device_type type
;
4281 /* Order matters. Specifically, BattleZone II (full version) expects the
4282 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4283 static const enum wined3d_format_id formats
[] =
4285 WINED3DFMT_S1_UINT_D15_UNORM
,
4286 WINED3DFMT_D16_UNORM
,
4287 WINED3DFMT_X8D24_UNORM
,
4288 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4289 WINED3DFMT_D24_UNORM_S8_UINT
,
4290 WINED3DFMT_D32_UNORM
,
4293 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4294 iface
, debugstr_guid(device_iid
), callback
, context
);
4296 if (!callback
) return DDERR_INVALIDPARAMS
;
4298 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4299 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4300 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4302 TRACE("Asked for HAL device.\n");
4303 type
= WINED3D_DEVICE_TYPE_HAL
;
4305 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4306 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4308 TRACE("Asked for SW device.\n");
4309 type
= WINED3D_DEVICE_TYPE_SW
;
4311 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4313 TRACE("Asked for REF device.\n");
4314 type
= WINED3D_DEVICE_TYPE_REF
;
4316 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4318 TRACE("Asked for NULLREF device.\n");
4319 type
= WINED3D_DEVICE_TYPE_NULLREF
;
4323 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4324 type
= WINED3D_DEVICE_TYPE_HAL
;
4327 wined3d_mutex_lock();
4328 /* We need an adapter format from somewhere to please wined3d and WGL.
4329 * Use the current display mode. So far all cards offer the same depth
4330 * stencil format for all modes, but if some do not and applications do
4331 * not like that we'll have to find some workaround, like iterating over
4332 * all imaginable formats and collecting all the depth stencil formats we
4334 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
4336 ERR("Failed to get display mode, hr %#x.\n", hr
);
4337 wined3d_mutex_unlock();
4341 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
4343 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4344 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_SURFACE
, formats
[i
])))
4346 DDPIXELFORMAT pformat
;
4348 memset(&pformat
, 0, sizeof(pformat
));
4349 pformat
.dwSize
= sizeof(pformat
);
4350 ddrawformat_from_wined3dformat(&pformat
, formats
[i
]);
4352 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
4353 hr
= callback(&pformat
, context
);
4354 if (hr
!= DDENUMRET_OK
)
4356 TRACE("Format enumeration cancelled by application.\n");
4357 wined3d_mutex_unlock();
4363 /* Historically some windows drivers used dwZBufferBitDepth=24 for WINED3DFMT_X8D24_UNORM,
4364 * while others used dwZBufferBitDepth=32. In either case the pitch matches a 32 bits per
4365 * pixel format, so we use dwZBufferBitDepth=32. Some games expect 24. Windows Vista and
4366 * newer enumerate both versions, so we do the same(bug 22434) */
4367 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4368 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_SURFACE
, WINED3DFMT_X8D24_UNORM
)))
4370 DDPIXELFORMAT x8d24
=
4372 sizeof(x8d24
), DDPF_ZBUFFER
, 0,
4373 {24}, {0x00000000}, {0x00ffffff}, {0x00000000}
4375 TRACE("Enumerating WINED3DFMT_X8D24_UNORM, dwZBufferBitDepth=24 version\n");
4376 callback(&x8d24
, context
);
4379 TRACE("End of enumeration.\n");
4381 wined3d_mutex_unlock();
4386 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
4387 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4389 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4391 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4392 iface
, debugstr_guid(device_iid
), callback
, context
);
4394 return d3d7_EnumZBufferFormats(&ddraw
->IDirect3D7_iface
, device_iid
, callback
, context
);
4397 /*****************************************************************************
4398 * IDirect3D7::EvictManagedTextures
4400 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
4401 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
4406 * D3D_OK, because it's a stub
4408 *****************************************************************************/
4409 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
4411 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4413 TRACE("iface %p!\n", iface
);
4415 wined3d_mutex_lock();
4416 if (ddraw
->flags
& DDRAW_D3D_INITIALIZED
)
4417 wined3d_device_evict_managed_resources(ddraw
->wined3d_device
);
4418 wined3d_mutex_unlock();
4423 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
4425 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4427 TRACE("iface %p.\n", iface
);
4429 return d3d7_EvictManagedTextures(&ddraw
->IDirect3D7_iface
);
4432 /*****************************************************************************
4433 * IDirectDraw7 VTable
4434 *****************************************************************************/
4435 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
4438 ddraw7_QueryInterface
,
4443 ddraw7_CreateClipper
,
4444 ddraw7_CreatePalette
,
4445 ddraw7_CreateSurface
,
4446 ddraw7_DuplicateSurface
,
4447 ddraw7_EnumDisplayModes
,
4448 ddraw7_EnumSurfaces
,
4449 ddraw7_FlipToGDISurface
,
4451 ddraw7_GetDisplayMode
,
4452 ddraw7_GetFourCCCodes
,
4453 ddraw7_GetGDISurface
,
4454 ddraw7_GetMonitorFrequency
,
4456 ddraw7_GetVerticalBlankStatus
,
4458 ddraw7_RestoreDisplayMode
,
4459 ddraw7_SetCooperativeLevel
,
4460 ddraw7_SetDisplayMode
,
4461 ddraw7_WaitForVerticalBlank
,
4463 ddraw7_GetAvailableVidMem
,
4465 ddraw7_GetSurfaceFromDC
,
4467 ddraw7_RestoreAllSurfaces
,
4468 ddraw7_TestCooperativeLevel
,
4469 ddraw7_GetDeviceIdentifier
,
4471 ddraw7_StartModeTest
,
4475 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
4478 ddraw4_QueryInterface
,
4483 ddraw4_CreateClipper
,
4484 ddraw4_CreatePalette
,
4485 ddraw4_CreateSurface
,
4486 ddraw4_DuplicateSurface
,
4487 ddraw4_EnumDisplayModes
,
4488 ddraw4_EnumSurfaces
,
4489 ddraw4_FlipToGDISurface
,
4491 ddraw4_GetDisplayMode
,
4492 ddraw4_GetFourCCCodes
,
4493 ddraw4_GetGDISurface
,
4494 ddraw4_GetMonitorFrequency
,
4496 ddraw4_GetVerticalBlankStatus
,
4498 ddraw4_RestoreDisplayMode
,
4499 ddraw4_SetCooperativeLevel
,
4500 ddraw4_SetDisplayMode
,
4501 ddraw4_WaitForVerticalBlank
,
4503 ddraw4_GetAvailableVidMem
,
4505 ddraw4_GetSurfaceFromDC
,
4507 ddraw4_RestoreAllSurfaces
,
4508 ddraw4_TestCooperativeLevel
,
4509 ddraw4_GetDeviceIdentifier
,
4512 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
4515 ddraw2_QueryInterface
,
4520 ddraw2_CreateClipper
,
4521 ddraw2_CreatePalette
,
4522 ddraw2_CreateSurface
,
4523 ddraw2_DuplicateSurface
,
4524 ddraw2_EnumDisplayModes
,
4525 ddraw2_EnumSurfaces
,
4526 ddraw2_FlipToGDISurface
,
4528 ddraw2_GetDisplayMode
,
4529 ddraw2_GetFourCCCodes
,
4530 ddraw2_GetGDISurface
,
4531 ddraw2_GetMonitorFrequency
,
4533 ddraw2_GetVerticalBlankStatus
,
4535 ddraw2_RestoreDisplayMode
,
4536 ddraw2_SetCooperativeLevel
,
4537 ddraw2_SetDisplayMode
,
4538 ddraw2_WaitForVerticalBlank
,
4540 ddraw2_GetAvailableVidMem
,
4543 static const struct IDirectDrawVtbl ddraw1_vtbl
=
4546 ddraw1_QueryInterface
,
4551 ddraw1_CreateClipper
,
4552 ddraw1_CreatePalette
,
4553 ddraw1_CreateSurface
,
4554 ddraw1_DuplicateSurface
,
4555 ddraw1_EnumDisplayModes
,
4556 ddraw1_EnumSurfaces
,
4557 ddraw1_FlipToGDISurface
,
4559 ddraw1_GetDisplayMode
,
4560 ddraw1_GetFourCCCodes
,
4561 ddraw1_GetGDISurface
,
4562 ddraw1_GetMonitorFrequency
,
4564 ddraw1_GetVerticalBlankStatus
,
4566 ddraw1_RestoreDisplayMode
,
4567 ddraw1_SetCooperativeLevel
,
4568 ddraw1_SetDisplayMode
,
4569 ddraw1_WaitForVerticalBlank
,
4572 static const struct IDirect3D7Vtbl d3d7_vtbl
=
4574 /* IUnknown methods */
4575 d3d7_QueryInterface
,
4578 /* IDirect3D7 methods */
4581 d3d7_CreateVertexBuffer
,
4582 d3d7_EnumZBufferFormats
,
4583 d3d7_EvictManagedTextures
4586 static const struct IDirect3D3Vtbl d3d3_vtbl
=
4588 /* IUnknown methods */
4589 d3d3_QueryInterface
,
4592 /* IDirect3D3 methods */
4595 d3d3_CreateMaterial
,
4596 d3d3_CreateViewport
,
4599 d3d3_CreateVertexBuffer
,
4600 d3d3_EnumZBufferFormats
,
4601 d3d3_EvictManagedTextures
4604 static const struct IDirect3D2Vtbl d3d2_vtbl
=
4606 /* IUnknown methods */
4607 d3d2_QueryInterface
,
4610 /* IDirect3D2 methods */
4613 d3d2_CreateMaterial
,
4614 d3d2_CreateViewport
,
4619 static const struct IDirect3DVtbl d3d1_vtbl
=
4621 /* IUnknown methods */
4622 d3d1_QueryInterface
,
4625 /* IDirect3D methods */
4629 d3d1_CreateMaterial
,
4630 d3d1_CreateViewport
,
4634 /*****************************************************************************
4637 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
4638 * if none was found.
4640 * This function is in ddraw.c and the DDraw object space because D3D7
4641 * vertex buffers are created using the IDirect3D interface to the ddraw
4642 * object, so they can be valid across D3D devices(theoretically. The ddraw
4643 * object also owns the wined3d device
4647 * fvf: Fvf to find the decl for
4650 * NULL in case of an error, the vertex declaration for the FVF otherwise.
4652 *****************************************************************************/
4653 struct wined3d_vertex_declaration
*ddraw_find_decl(struct ddraw
*This
, DWORD fvf
)
4655 struct wined3d_vertex_declaration
*pDecl
= NULL
;
4657 int p
, low
, high
; /* deliberately signed */
4658 struct FvfToDecl
*convertedDecls
= This
->decls
;
4660 TRACE("Searching for declaration for fvf %08x... ", fvf
);
4663 high
= This
->numConvertedDecls
- 1;
4664 while(low
<= high
) {
4665 p
= (low
+ high
) >> 1;
4667 if(convertedDecls
[p
].fvf
== fvf
) {
4668 TRACE("found %p\n", convertedDecls
[p
].decl
);
4669 return convertedDecls
[p
].decl
;
4670 } else if(convertedDecls
[p
].fvf
< fvf
) {
4676 TRACE("not found. Creating and inserting at position %d.\n", low
);
4678 hr
= wined3d_vertex_declaration_create_from_fvf(This
->wined3d_device
,
4679 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
4680 if (hr
!= S_OK
) return NULL
;
4682 if(This
->declArraySize
== This
->numConvertedDecls
) {
4683 int grow
= max(This
->declArraySize
/ 2, 8);
4684 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
4685 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
4686 if (!convertedDecls
)
4688 wined3d_vertex_declaration_decref(pDecl
);
4691 This
->decls
= convertedDecls
;
4692 This
->declArraySize
+= grow
;
4695 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
4696 convertedDecls
[low
].decl
= pDecl
;
4697 convertedDecls
[low
].fvf
= fvf
;
4698 This
->numConvertedDecls
++;
4700 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
4704 static inline struct ddraw
*ddraw_from_device_parent(struct wined3d_device_parent
*device_parent
)
4706 return CONTAINING_RECORD(device_parent
, struct ddraw
, device_parent
);
4709 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
4710 struct wined3d_device
*device
)
4712 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
4715 /* This is run from device_process_message() in wined3d, we can't take the
4717 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
4719 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4720 MONITORINFO monitor_info
;
4724 TRACE("device_parent %p.\n", device_parent
);
4726 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) || !ddraw
->swapchain_window
)
4728 TRACE("Nothing to resize.\n");
4732 monitor
= MonitorFromWindow(ddraw
->swapchain_window
, MONITOR_DEFAULTTOPRIMARY
);
4733 monitor_info
.cbSize
= sizeof(monitor_info
);
4734 if (!GetMonitorInfoW(monitor
, &monitor_info
))
4736 ERR("Failed to get monitor info.\n");
4740 r
= &monitor_info
.rcMonitor
;
4741 TRACE("Resizing window %p to %s.\n", ddraw
->swapchain_window
, wine_dbgstr_rect(r
));
4743 if (!SetWindowPos(ddraw
->swapchain_window
, HWND_TOP
, r
->left
, r
->top
,
4744 r
->right
- r
->left
, r
->bottom
- r
->top
, SWP_SHOWWINDOW
| SWP_NOACTIVATE
))
4745 ERR("Failed to resize window.\n");
4748 static void CDECL
device_parent_activate(struct wined3d_device_parent
*device_parent
, BOOL activate
)
4750 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4752 TRACE("device_parent %p, activate %#x.\n", device_parent
, activate
);
4755 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_LOST
, DDRAW_DEVICE_STATE_OK
);
4757 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_OK
, DDRAW_DEVICE_STATE_LOST
);
4760 static HRESULT CDECL
device_parent_surface_created(struct wined3d_device_parent
*device_parent
,
4761 void *container_parent
, struct wined3d_surface
*surface
,
4762 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
4764 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4765 struct ddraw_surface
*ddraw_surface
;
4767 TRACE("device_parent %p, container_parent %p, surface %p, parent %p, parent_ops %p.\n",
4768 device_parent
, container_parent
, surface
, parent
, parent_ops
);
4770 /* We have a swapchain or wined3d internal texture. */
4771 if (!container_parent
|| container_parent
== ddraw
)
4774 *parent_ops
= &ddraw_null_wined3d_parent_ops
;
4779 if (!(ddraw_surface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ddraw_surface
))))
4781 ERR("Failed to allocate surface memory.\n");
4782 return DDERR_OUTOFVIDEOMEMORY
;
4785 ddraw_surface_init(ddraw_surface
, ddraw
, container_parent
, surface
, parent_ops
);
4786 *parent
= ddraw_surface
;
4787 list_add_head(&ddraw
->surface_list
, &ddraw_surface
->surface_list_entry
);
4789 TRACE("Created ddraw surface %p.\n", ddraw_surface
);
4794 static HRESULT CDECL
device_parent_volume_created(struct wined3d_device_parent
*device_parent
,
4795 void *container_parent
, struct wined3d_volume
*volume
,
4796 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
4798 TRACE("device_parent %p, container_parent %p, volume %p, parent %p, parent_ops %p.\n",
4799 device_parent
, container_parent
, volume
, parent
, parent_ops
);
4802 *parent_ops
= &ddraw_null_wined3d_parent_ops
;
4807 static void STDMETHODCALLTYPE
ddraw_frontbuffer_destroyed(void *parent
)
4809 struct ddraw
*ddraw
= parent
;
4810 ddraw
->wined3d_frontbuffer
= NULL
;
4813 static const struct wined3d_parent_ops ddraw_frontbuffer_parent_ops
=
4815 ddraw_frontbuffer_destroyed
,
4818 static HRESULT CDECL
device_parent_create_swapchain_surface(struct wined3d_device_parent
*device_parent
,
4819 void *container_parent
, const struct wined3d_resource_desc
*desc
, struct wined3d_surface
**surface
)
4821 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4822 struct wined3d_resource_desc texture_desc
;
4823 struct wined3d_texture
*texture
;
4826 TRACE("device_parent %p, container_parent %p, desc %p, surface %p.\n",
4827 device_parent
, container_parent
, desc
, surface
);
4829 if (ddraw
->wined3d_frontbuffer
)
4831 ERR("Frontbuffer already created.\n");
4835 texture_desc
= *desc
;
4836 texture_desc
.resource_type
= WINED3D_RTYPE_TEXTURE
;
4837 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, &texture_desc
, 1,
4838 WINED3D_SURFACE_MAPPABLE
, NULL
, ddraw
, &ddraw_frontbuffer_parent_ops
, &texture
)))
4840 WARN("Failed to create texture, hr %#x.\n", hr
);
4844 *surface
= wined3d_surface_from_resource(wined3d_texture_get_sub_resource(texture
, 0));
4845 ddraw
->wined3d_frontbuffer
= *surface
;
4846 wined3d_surface_incref(*surface
);
4847 wined3d_texture_decref(texture
);
4852 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
4853 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
4855 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4858 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent
, desc
, swapchain
);
4860 if (ddraw
->wined3d_swapchain
)
4862 ERR("Swapchain already created.\n");
4866 if (FAILED(hr
= wined3d_swapchain_create(ddraw
->wined3d_device
, desc
, NULL
,
4867 &ddraw_null_wined3d_parent_ops
, swapchain
)))
4868 WARN("Failed to create swapchain, hr %#x.\n", hr
);
4873 static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops
=
4875 device_parent_wined3d_device_created
,
4876 device_parent_mode_changed
,
4877 device_parent_activate
,
4878 device_parent_surface_created
,
4879 device_parent_volume_created
,
4880 device_parent_create_swapchain_surface
,
4881 device_parent_create_swapchain
,
4884 HRESULT
ddraw_init(struct ddraw
*ddraw
, DWORD flags
, enum wined3d_device_type device_type
)
4889 ddraw
->IDirectDraw7_iface
.lpVtbl
= &ddraw7_vtbl
;
4890 ddraw
->IDirectDraw_iface
.lpVtbl
= &ddraw1_vtbl
;
4891 ddraw
->IDirectDraw2_iface
.lpVtbl
= &ddraw2_vtbl
;
4892 ddraw
->IDirectDraw4_iface
.lpVtbl
= &ddraw4_vtbl
;
4893 ddraw
->IDirect3D_iface
.lpVtbl
= &d3d1_vtbl
;
4894 ddraw
->IDirect3D2_iface
.lpVtbl
= &d3d2_vtbl
;
4895 ddraw
->IDirect3D3_iface
.lpVtbl
= &d3d3_vtbl
;
4896 ddraw
->IDirect3D7_iface
.lpVtbl
= &d3d7_vtbl
;
4897 ddraw
->device_parent
.ops
= &ddraw_wined3d_device_parent_ops
;
4898 ddraw
->numIfaces
= 1;
4901 flags
|= DDRAW_WINED3D_FLAGS
;
4902 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
4904 flags
|= WINED3D_NO3D
;
4905 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
4907 WARN("Failed to create a wined3d object.\n");
4912 if (FAILED(hr
= wined3d_get_device_caps(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
, &caps
)))
4914 ERR("Failed to get device caps, hr %#x.\n", hr
);
4915 wined3d_decref(ddraw
->wined3d
);
4919 if (!(caps
.ddraw_caps
.caps
& WINEDDCAPS_3D
))
4921 WARN("Created a wined3d object without 3D support.\n");
4922 ddraw
->flags
|= DDRAW_NO3D
;
4925 if (FAILED(hr
= wined3d_device_create(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
,
4926 NULL
, 0, DDRAW_STRIDE_ALIGNMENT
, &ddraw
->device_parent
, &ddraw
->wined3d_device
)))
4928 WARN("Failed to create a wined3d device, hr %#x.\n", hr
);
4929 wined3d_decref(ddraw
->wined3d
);
4933 list_init(&ddraw
->surface_list
);