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"
28 #include "wine/exception.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
32 static const struct ddraw
*exclusive_ddraw
;
33 static HWND exclusive_window
;
35 /* Device identifier. Don't relay it to WineD3D */
36 static const DDDEVICEIDENTIFIER2 deviceidentifier
=
38 "vga.dll", /* default 2D driver */
40 { { 0x00010001, 0x00010001 } },
42 /* a8373c10-7ac4-4deb-849a-009844d08b2d */
43 {0xa8373c10,0x7ac4,0x4deb, {0x84,0x9a,0x00,0x98,0x44,0xd0,0x8b,0x2d}},
47 static struct enum_device_entry
49 char interface_name
[100];
50 char device_name
[100];
51 const GUID
*device_guid
;
52 DWORD unsupported_caps
;
57 "WINE Direct3D7 Hardware Transform and Lighting acceleration using WineD3D",
59 &IID_IDirect3DTnLHalDevice
,
65 "WINE Direct3D7 Hardware acceleration using WineD3D",
67 &IID_IDirect3DHALDevice
,
68 D3DDEVCAPS_HWTRANSFORMANDLIGHT
,
73 "WINE Direct3D7 RGB Software Emulation using WineD3D",
75 &IID_IDirect3DRGBDevice
,
76 D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWRASTERIZATION
,
80 static void STDMETHODCALLTYPE
ddraw_null_wined3d_object_destroyed(void *parent
) {}
82 const struct wined3d_parent_ops ddraw_null_wined3d_parent_ops
=
84 ddraw_null_wined3d_object_destroyed
,
87 static void CDECL
ddraw_swapchain_windowed_state_changed(struct wined3d_swapchain_state_parent
*parent
,
90 TRACE("parent %p, windowed %d.\n", parent
, windowed
);
93 static const struct wined3d_swapchain_state_parent_ops ddraw_swapchain_state_parent_ops
=
95 ddraw_swapchain_windowed_state_changed
,
98 static inline struct ddraw
*impl_from_IDirectDraw(IDirectDraw
*iface
)
100 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw_iface
);
103 static inline struct ddraw
*impl_from_IDirectDraw2(IDirectDraw2
*iface
)
105 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw2_iface
);
108 static inline struct ddraw
*impl_from_IDirectDraw4(IDirectDraw4
*iface
)
110 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw4_iface
);
113 static inline struct ddraw
*impl_from_IDirectDraw7(IDirectDraw7
*iface
)
115 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw7_iface
);
118 static inline struct ddraw
*impl_from_IDirect3D(IDirect3D
*iface
)
120 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D_iface
);
123 static inline struct ddraw
*impl_from_IDirect3D2(IDirect3D2
*iface
)
125 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D2_iface
);
128 static inline struct ddraw
*impl_from_IDirect3D3(IDirect3D3
*iface
)
130 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D3_iface
);
133 static inline struct ddraw
*impl_from_IDirect3D7(IDirect3D7
*iface
)
135 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D7_iface
);
138 static HRESULT WINAPI
ddraw7_QueryInterface(IDirectDraw7
*iface
, REFIID riid
, void **out
)
140 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
142 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
147 return DDERR_INVALIDPARAMS
;
150 /* The refcount unit test revealed that an IDirect3D7 interface can only
151 * be queried from a DirectDraw object that was created as an IDirectDraw7
152 * interface. The older interfaces can query any IDirect3D version except
153 * 7, because they are all initially created as IDirectDraw. This isn't
154 * really crucial behavior, and messy to implement with the common
155 * creation function, so it has been left out here. */
156 if (IsEqualGUID(&IID_IDirectDraw7
, riid
)
157 || IsEqualGUID(&IID_IUnknown
, riid
))
159 *out
= &ddraw
->IDirectDraw7_iface
;
160 TRACE("Returning IDirectDraw7 interface %p.\n", *out
);
162 else if (IsEqualGUID(&IID_IDirectDraw4
, riid
))
164 *out
= &ddraw
->IDirectDraw4_iface
;
165 TRACE("Returning IDirectDraw4 interface %p.\n", *out
);
167 else if (IsEqualGUID(&IID_IDirectDraw2
, riid
))
169 *out
= &ddraw
->IDirectDraw2_iface
;
170 TRACE("Returning IDirectDraw2 interface %p.\n", *out
);
172 else if (IsEqualGUID(&IID_IDirectDraw
, riid
))
174 *out
= &ddraw
->IDirectDraw_iface
;
175 TRACE("Returning IDirectDraw interface %p.\n", *out
);
177 else if (IsEqualGUID(&IID_IDirect3D7
, riid
))
179 ddraw
->d3dversion
= 7;
180 *out
= &ddraw
->IDirect3D7_iface
;
181 TRACE("Returning Direct3D7 interface %p.\n", *out
);
183 else if (IsEqualGUID(&IID_IDirect3D3
, riid
))
185 ddraw
->d3dversion
= 3;
186 *out
= &ddraw
->IDirect3D3_iface
;
187 TRACE("Returning Direct3D3 interface %p.\n", *out
);
189 else if (IsEqualGUID(&IID_IDirect3D2
, riid
))
191 ddraw
->d3dversion
= 2;
192 *out
= &ddraw
->IDirect3D2_iface
;
193 TRACE("Returning Direct3D2 interface %p.\n", *out
);
195 else if (IsEqualGUID(&IID_IDirect3D
, riid
))
197 ddraw
->d3dversion
= 1;
198 *out
= &ddraw
->IDirect3D_iface
;
199 TRACE("Returning Direct3D interface %p.\n", *out
);
201 /* Unknown interface */
204 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
206 return E_NOINTERFACE
;
209 IUnknown_AddRef((IUnknown
*)*out
);
213 static HRESULT WINAPI
ddraw4_QueryInterface(IDirectDraw4
*iface
, REFIID riid
, void **object
)
215 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
217 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
219 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
222 static HRESULT WINAPI
ddraw2_QueryInterface(IDirectDraw2
*iface
, REFIID riid
, void **object
)
224 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
226 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
228 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
231 static HRESULT WINAPI
ddraw1_QueryInterface(IDirectDraw
*iface
, REFIID riid
, void **object
)
233 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
235 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
237 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
240 static HRESULT WINAPI
d3d7_QueryInterface(IDirect3D7
*iface
, REFIID riid
, void **object
)
242 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
244 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
246 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
249 static HRESULT WINAPI
d3d3_QueryInterface(IDirect3D3
*iface
, REFIID riid
, void **object
)
251 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
253 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
255 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
258 static HRESULT WINAPI
d3d2_QueryInterface(IDirect3D2
*iface
, REFIID riid
, void **object
)
260 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
262 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
264 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
267 static HRESULT WINAPI
d3d1_QueryInterface(IDirect3D
*iface
, REFIID riid
, void **object
)
269 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
271 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
273 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
276 /*****************************************************************************
277 * IDirectDraw7::AddRef
279 * Increases the interfaces refcount, basically
281 * DDraw refcounting is a bit tricky. The different DirectDraw interface
282 * versions have individual refcounts, but the IDirect3D interfaces do not.
283 * All interfaces are from one object, that means calling QueryInterface on an
284 * IDirectDraw7 interface for an IDirectDraw4 interface does not create a new
287 * That means all AddRef and Release implementations of IDirectDrawX work
288 * with their own counter, and IDirect3DX::AddRef thunk to IDirectDraw (1),
289 * except of IDirect3D7 which thunks to IDirectDraw7
291 * Returns: The new refcount
293 *****************************************************************************/
294 static ULONG WINAPI
ddraw7_AddRef(IDirectDraw7
*iface
)
296 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
297 ULONG ref
= InterlockedIncrement(&This
->ref7
);
299 TRACE("%p increasing refcount to %lu.\n", This
, ref
);
301 if(ref
== 1) InterlockedIncrement(&This
->numIfaces
);
306 static ULONG WINAPI
ddraw4_AddRef(IDirectDraw4
*iface
)
308 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
309 ULONG ref
= InterlockedIncrement(&This
->ref4
);
311 TRACE("%p increasing refcount to %lu.\n", This
, ref
);
313 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
318 static ULONG WINAPI
ddraw2_AddRef(IDirectDraw2
*iface
)
320 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
321 ULONG ref
= InterlockedIncrement(&This
->ref2
);
323 TRACE("%p increasing refcount to %lu.\n", This
, ref
);
325 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
330 static ULONG WINAPI
ddraw1_AddRef(IDirectDraw
*iface
)
332 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
333 ULONG ref
= InterlockedIncrement(&This
->ref1
);
335 TRACE("%p increasing refcount to %lu.\n", This
, ref
);
337 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
342 static ULONG WINAPI
d3d7_AddRef(IDirect3D7
*iface
)
344 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
346 TRACE("iface %p.\n", iface
);
348 return ddraw7_AddRef(&This
->IDirectDraw7_iface
);
351 static ULONG WINAPI
d3d3_AddRef(IDirect3D3
*iface
)
353 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
355 TRACE("iface %p.\n", iface
);
357 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
360 static ULONG WINAPI
d3d2_AddRef(IDirect3D2
*iface
)
362 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
364 TRACE("iface %p.\n", iface
);
366 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
369 static ULONG WINAPI
d3d1_AddRef(IDirect3D
*iface
)
371 struct ddraw
*This
= impl_from_IDirect3D(iface
);
373 TRACE("iface %p.\n", iface
);
375 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
378 static void ddraw_destroy_swapchain(struct ddraw
*ddraw
)
382 TRACE("Destroying the swapchain.\n");
384 wined3d_swapchain_decref(ddraw
->wined3d_swapchain
);
386 for (i
= 0; i
< ddraw
->numConvertedDecls
; ++i
)
388 wined3d_vertex_declaration_decref(ddraw
->decls
[i
].decl
);
390 heap_free(ddraw
->decls
);
391 ddraw
->numConvertedDecls
= 0;
393 wined3d_swapchain_decref(ddraw
->wined3d_swapchain
);
394 ddraw
->wined3d_swapchain
= NULL
;
396 /* Free the d3d window if one was created. */
397 if (ddraw
->d3d_window
&& ddraw
->d3d_window
!= ddraw
->dest_window
)
399 TRACE("Destroying the hidden render window %p.\n", ddraw
->d3d_window
);
400 DestroyWindow(ddraw
->d3d_window
);
401 ddraw
->d3d_window
= 0;
404 ddraw
->flags
&= ~DDRAW_D3D_INITIALIZED
;
406 ddraw_set_swapchain_window(ddraw
, NULL
);
408 TRACE("Swapchain destroyed.\n");
411 /*****************************************************************************
414 * Destroys a ddraw object if all refcounts are 0. This is to share code
415 * between the IDirectDrawX::Release functions
418 * This: DirectDraw object to destroy
420 *****************************************************************************/
421 static void ddraw_destroy(struct ddraw
*This
)
423 IDirectDraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, NULL
, DDSCL_NORMAL
);
424 IDirectDraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
426 /* Destroy the device window if we created one */
427 if(This
->devicewindow
!= 0)
429 TRACE(" (%p) Destroying the device window %p\n", This
, This
->devicewindow
);
430 DestroyWindow(This
->devicewindow
);
431 This
->devicewindow
= 0;
434 wined3d_mutex_lock();
435 list_remove(&This
->ddraw_list_entry
);
436 wined3d_mutex_unlock();
438 if (This
->wined3d_swapchain
)
439 ddraw_destroy_swapchain(This
);
440 wined3d_stateblock_decref(This
->state
);
441 wined3d_device_decref(This
->wined3d_device
);
442 wined3d_decref(This
->wined3d
);
445 This
->d3ddevice
->ddraw
= NULL
;
447 /* Now free the object */
451 /*****************************************************************************
452 * IDirectDraw7::Release
454 * Decreases the refcount. If the refcount falls to 0, the object is destroyed
456 * Returns: The new refcount
457 *****************************************************************************/
458 static ULONG WINAPI
ddraw7_Release(IDirectDraw7
*iface
)
460 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
461 ULONG ref
= InterlockedDecrement(&This
->ref7
);
463 TRACE("%p decreasing refcount to %lu.\n", This
, ref
);
465 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
471 static ULONG WINAPI
ddraw4_Release(IDirectDraw4
*iface
)
473 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
474 ULONG ref
= InterlockedDecrement(&This
->ref4
);
476 TRACE("%p decreasing refcount to %lu.\n", This
, ref
);
478 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
484 static ULONG WINAPI
ddraw2_Release(IDirectDraw2
*iface
)
486 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
487 ULONG ref
= InterlockedDecrement(&This
->ref2
);
489 TRACE("%p decreasing refcount to %lu.\n", This
, ref
);
491 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
497 static ULONG WINAPI
ddraw1_Release(IDirectDraw
*iface
)
499 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
500 ULONG ref
= InterlockedDecrement(&This
->ref1
);
502 TRACE("%p decreasing refcount to %lu.\n", This
, ref
);
504 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
510 static ULONG WINAPI
d3d7_Release(IDirect3D7
*iface
)
512 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
514 TRACE("iface %p.\n", iface
);
516 return ddraw7_Release(&This
->IDirectDraw7_iface
);
519 static ULONG WINAPI
d3d3_Release(IDirect3D3
*iface
)
521 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
523 TRACE("iface %p.\n", iface
);
525 return ddraw1_Release(&This
->IDirectDraw_iface
);
528 static ULONG WINAPI
d3d2_Release(IDirect3D2
*iface
)
530 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
532 TRACE("iface %p.\n", iface
);
534 return ddraw1_Release(&This
->IDirectDraw_iface
);
537 static ULONG WINAPI
d3d1_Release(IDirect3D
*iface
)
539 struct ddraw
*This
= impl_from_IDirect3D(iface
);
541 TRACE("iface %p.\n", iface
);
543 return ddraw1_Release(&This
->IDirectDraw_iface
);
546 /*****************************************************************************
547 * IDirectDraw methods
548 *****************************************************************************/
550 static HRESULT
ddraw_set_focus_window(struct ddraw
*ddraw
, HWND window
)
552 /* FIXME: This looks wrong, exclusive mode should imply a destination
554 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) && ddraw
->dest_window
)
556 TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET.\n");
557 return DDERR_HWNDALREADYSET
;
560 ddraw
->focuswindow
= window
;
565 static HRESULT
ddraw_attach_d3d_device(struct ddraw
*ddraw
, HWND window
,
566 DWORD cooplevel
, struct wined3d_swapchain
**wined3d_swapchain
)
568 struct wined3d_swapchain_desc swapchain_desc
;
569 struct wined3d_display_mode mode
;
572 TRACE("ddraw %p.\n", ddraw
);
574 if (FAILED(hr
= wined3d_output_get_display_mode(ddraw
->wined3d_output
, &mode
, NULL
)))
576 ERR("Failed to get display mode.\n");
580 memset(&swapchain_desc
, 0, sizeof(swapchain_desc
));
581 swapchain_desc
.output
= ddraw
->wined3d_output
;
582 swapchain_desc
.backbuffer_width
= mode
.width
;
583 swapchain_desc
.backbuffer_height
= mode
.height
;
584 swapchain_desc
.backbuffer_format
= mode
.format_id
;
585 swapchain_desc
.backbuffer_bind_flags
= 0;
586 swapchain_desc
.backbuffer_count
= 1;
587 swapchain_desc
.swap_effect
= WINED3D_SWAP_EFFECT_DISCARD
;
588 swapchain_desc
.device_window
= window
;
589 swapchain_desc
.windowed
= !(cooplevel
& DDSCL_FULLSCREEN
);
590 swapchain_desc
.flags
= WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH
| WINED3D_SWAPCHAIN_IMPLICIT
;
592 if ((cooplevel
& DDSCL_NOWINDOWCHANGES
) || window
!= GetForegroundWindow())
593 swapchain_desc
.flags
|= WINED3D_SWAPCHAIN_NO_WINDOW_CHANGES
;
595 if (ddraw
->flags
& DDRAW_NO3D
)
596 return wined3d_swapchain_create(ddraw
->wined3d_device
, &swapchain_desc
,
597 &ddraw
->state_parent
, NULL
, &ddraw_null_wined3d_parent_ops
, wined3d_swapchain
);
599 if (!window
|| window
== GetDesktopWindow())
601 window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "Hidden D3D Window",
602 WS_DISABLED
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
603 NULL
, NULL
, NULL
, NULL
);
606 ERR("Failed to create window, last error %#lx.\n", GetLastError());
610 ShowWindow(window
, SW_HIDE
); /* Just to be sure */
611 WARN("No window for the Direct3DDevice, created hidden window %p.\n", window
);
613 swapchain_desc
.device_window
= window
;
617 TRACE("Using existing window %p for Direct3D rendering.\n", window
);
619 ddraw
->d3d_window
= window
;
621 /* Set this NOW, otherwise creating the depth stencil surface will cause a
622 * recursive loop until ram or emulated video memory is full. */
623 ddraw
->flags
|= DDRAW_D3D_INITIALIZED
;
624 if (FAILED(hr
= wined3d_swapchain_create(ddraw
->wined3d_device
, &swapchain_desc
,
625 &ddraw
->state_parent
, NULL
, &ddraw_null_wined3d_parent_ops
, wined3d_swapchain
)))
627 ddraw
->flags
&= ~DDRAW_D3D_INITIALIZED
;
628 DestroyWindow(window
);
629 ddraw
->d3d_window
= NULL
;
633 ddraw
->declArraySize
= 2;
634 if (!(ddraw
->decls
= heap_alloc_zero(ddraw
->declArraySize
* sizeof(*ddraw
->decls
))))
636 ERR("Error allocating an array for the converted vertex decls.\n");
637 ddraw
->declArraySize
= 0;
638 wined3d_swapchain_decref(*wined3d_swapchain
);
639 DestroyWindow(window
);
640 ddraw
->d3d_window
= NULL
;
641 return E_OUTOFMEMORY
;
644 TRACE("Successfully initialized 3D.\n");
649 static HRESULT
ddraw_create_swapchain(struct ddraw
*ddraw
, HWND window
, DWORD cooplevel
)
653 if (ddraw
->wined3d_swapchain
)
655 ERR("Swapchain already created.\n");
659 if (FAILED(hr
= ddraw_attach_d3d_device(ddraw
, window
, cooplevel
, &ddraw
->wined3d_swapchain
)))
661 ERR("Failed to create swapchain, hr %#lx.\n", hr
);
664 wined3d_swapchain_incref(ddraw
->wined3d_swapchain
);
666 ddraw_set_swapchain_window(ddraw
, window
);
668 if (ddraw
->primary
&& ddraw
->primary
->palette
)
669 wined3d_swapchain_set_palette(ddraw
->wined3d_swapchain
, ddraw
->primary
->palette
->wined3d_palette
);
674 /*****************************************************************************
675 * IDirectDraw7::RestoreDisplayMode
677 * Restores the display mode to what it was at creation time. Basically.
681 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
683 *****************************************************************************/
684 static HRESULT WINAPI
ddraw7_RestoreDisplayMode(IDirectDraw7
*iface
)
686 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
687 struct wined3d_display_mode mode
;
691 TRACE("iface %p.\n", iface
);
693 wined3d_mutex_lock();
695 if (!(ddraw
->flags
& DDRAW_RESTORE_MODE
))
697 wined3d_mutex_unlock();
701 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
703 wined3d_mutex_unlock();
704 return DDERR_NOEXCLUSIVEMODE
;
707 if (SUCCEEDED(hr
= wined3d_restore_display_modes(ddraw
->wined3d
)))
709 ddraw
->flags
&= ~DDRAW_RESTORE_MODE
;
710 if (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
&&
711 SUCCEEDED(hr
= wined3d_output_get_display_mode(ddraw
->wined3d_output
, &mode
, NULL
)))
713 SetRect(&clip_rect
, 0, 0, mode
.width
, mode
.height
);
714 ClipCursor(&clip_rect
);
718 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_OK
);
720 wined3d_mutex_unlock();
725 static HRESULT WINAPI
ddraw4_RestoreDisplayMode(IDirectDraw4
*iface
)
727 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
729 TRACE("iface %p.\n", iface
);
731 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
734 static HRESULT WINAPI
ddraw2_RestoreDisplayMode(IDirectDraw2
*iface
)
736 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
738 TRACE("iface %p.\n", iface
);
740 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
743 static HRESULT WINAPI
ddraw1_RestoreDisplayMode(IDirectDraw
*iface
)
745 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
747 TRACE("iface %p.\n", iface
);
749 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
752 /*****************************************************************************
753 * IDirectDraw7::SetCooperativeLevel
755 * Sets the cooperative level for the DirectDraw object, and the window
756 * assigned to it. The cooperative level determines the general behavior
757 * of the DirectDraw application
759 * Warning: This is quite tricky, as it's not really documented which
760 * cooperative levels can be combined with each other. If a game fails
761 * after this function, try to check the cooperative levels passed on
762 * Windows, and if it returns something different.
764 * If you think that this function caused the failure because it writes a
765 * fixme, be sure to run again with a +ddraw trace.
767 * What is known about cooperative levels (See the ddraw modes test):
768 * DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN.
769 * DDSCL_NORMAL is not compatible with DDSCL_EXCLUSIVE.
770 * Unlike what msdn claims, DDSCL_NORMAL | DDSCL_FULLSCREEN is allowed.
771 * DDSCL_SETFOCUSWINDOW can be passed only in DDSCL_NORMAL mode, but after that
772 * DDSCL_EXCLUSIVE can be activated.
773 * DDSCL_SETFOCUSWINDOW may only be used with DDSCL_NOWINDOWCHANGES or
774 * DDSCL_CREATEDEVICEWINDOW.
776 * Handled flags: DDSCL_NORMAL, DDSCL_FULLSCREEN, DDSCL_EXCLUSIVE,
777 * DDSCL_CREATEDEVICEWINDOW, DDSCL_SETDEVICEWINDOW
778 * DDSCL_SETFOCUSWINDOW (partially),
779 * DDSCL_MULTITHREADED (work in progress)
780 * DDSCL_FPUPRESERVE (see device.c)
782 * Unsure about this: DDSCL_FPUSETUP
784 * These don't seem very important for wine:
785 * DDSCL_ALLOWREBOOT, DDSCL_ALLOWMODEX
788 * DD_OK if the cooperative level was set successfully
789 * DDERR_INVALIDPARAMS if the passed cooperative level combination is invalid
790 * DDERR_HWNDALREADYSET if DDSCL_SETFOCUSWINDOW is passed in exclusive mode
791 * (Probably others too, have to investigate)
793 *****************************************************************************/
794 static HRESULT
ddraw_set_cooperative_level(struct ddraw
*ddraw
, HWND window
,
795 DWORD cooplevel
, BOOL restore_mode_on_normal
)
797 struct wined3d_rendertarget_view
*rtv
= NULL
, *dsv
= NULL
;
798 struct wined3d_stateblock
*stateblock
;
799 BOOL restore_state
= FALSE
;
803 TRACE("ddraw %p, window %p, flags %#lx, restore_mode_on_normal %x.\n", ddraw
, window
, cooplevel
,
804 restore_mode_on_normal
);
805 DDRAW_dump_cooperativelevel(cooplevel
);
807 wined3d_mutex_lock();
809 if (ddraw
->flags
& DDRAW_SCL_RECURSIVE
)
811 WARN("Recursive call, returning DD_OK.\n");
815 ddraw
->flags
|= DDRAW_SCL_RECURSIVE
;
817 /* Tests suggest that we need one of them: */
818 if(!(cooplevel
& (DDSCL_SETFOCUSWINDOW
|
822 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
823 hr
= DDERR_INVALIDPARAMS
;
827 if ((cooplevel
& DDSCL_CREATEDEVICEWINDOW
) && !(cooplevel
& DDSCL_EXCLUSIVE
))
829 WARN("DDSCL_CREATEDEVICEWINDOW requires DDSCL_EXCLUSIVE.\n");
830 hr
= DDERR_INVALIDPARAMS
;
834 /* Handle those levels first which set various hwnds */
835 if ((cooplevel
& DDSCL_SETFOCUSWINDOW
) && !(cooplevel
& DDSCL_CREATEDEVICEWINDOW
))
837 /* This isn't compatible with a lot of flags */
838 if (cooplevel
& (DDSCL_MULTITHREADED
843 | DDSCL_SETDEVICEWINDOW
848 WARN("Called with incompatible flags, returning DDERR_INVALIDPARAMS.\n");
849 hr
= DDERR_INVALIDPARAMS
;
853 hr
= ddraw_set_focus_window(ddraw
, window
);
857 if (cooplevel
& DDSCL_EXCLUSIVE
)
859 if (!(cooplevel
& DDSCL_FULLSCREEN
) || !(window
|| (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)))
861 WARN("DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN and a window.\n");
862 hr
= DDERR_INVALIDPARAMS
;
866 if (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)
870 if (!ddraw
->focuswindow
&& !(cooplevel
& DDSCL_SETFOCUSWINDOW
))
872 WARN("No focus window set.\n");
873 hr
= DDERR_NOFOCUSWINDOW
;
877 device_window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "DirectDrawDeviceWnd",
878 WS_POPUP
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
879 NULL
, NULL
, NULL
, NULL
);
882 ERR("Failed to create window, last error %#lx.\n", GetLastError());
887 ShowWindow(device_window
, SW_SHOW
);
888 TRACE("Created a device window %p.\n", device_window
);
890 /* Native apparently leaks the created device window if setting the
891 * focus window below fails. */
892 ddraw
->cooperative_level
|= DDSCL_CREATEDEVICEWINDOW
;
893 ddraw
->devicewindow
= device_window
;
895 if (cooplevel
& DDSCL_SETFOCUSWINDOW
)
903 if (FAILED(hr
= ddraw_set_focus_window(ddraw
, window
)))
907 window
= device_window
;
912 if (ddraw
->cooperative_level
& DDSCL_CREATEDEVICEWINDOW
)
913 DestroyWindow(ddraw
->devicewindow
);
914 ddraw
->devicewindow
= NULL
;
915 ddraw
->focuswindow
= NULL
;
918 if ((cooplevel
& DDSCL_EXCLUSIVE
) && exclusive_window
!= window
)
920 ddraw
->device_state
= DDRAW_DEVICE_STATE_NOT_RESTORED
;
921 exclusive_window
= window
;
924 if (cooplevel
& DDSCL_MULTITHREADED
&& !(ddraw
->cooperative_level
& DDSCL_MULTITHREADED
))
925 wined3d_device_set_multithreaded(ddraw
->wined3d_device
);
927 if (ddraw
->wined3d_swapchain
)
929 if (!(ddraw
->flags
& DDRAW_NO3D
))
931 restore_state
= TRUE
;
933 if (FAILED(hr
= wined3d_stateblock_create(ddraw
->wined3d_device
,
934 ddraw
->state
, WINED3D_SBT_ALL
, &stateblock
)))
936 ERR("Failed to create stateblock, hr %#lx.\n", hr
);
940 rtv
= wined3d_device_context_get_rendertarget_view(ddraw
->immediate_context
, 0);
941 /* Rendering to the wined3d frontbuffer. */
942 if (rtv
&& !wined3d_rendertarget_view_get_sub_resource_parent(rtv
))
945 wined3d_rendertarget_view_incref(rtv
);
947 if ((dsv
= wined3d_device_context_get_depth_stencil_view(ddraw
->immediate_context
)))
948 wined3d_rendertarget_view_incref(dsv
);
951 ddraw_destroy_swapchain(ddraw
);
954 if (FAILED(hr
= ddraw_create_swapchain(ddraw
, window
, cooplevel
)))
955 ERR("Failed to create swapchain, hr %#lx.\n", hr
);
961 wined3d_device_context_set_depth_stencil_view(ddraw
->immediate_context
, dsv
);
962 wined3d_rendertarget_view_decref(dsv
);
967 wined3d_device_context_set_rendertarget_views(ddraw
->immediate_context
, 0, 1, &rtv
, FALSE
);
968 wined3d_rendertarget_view_decref(rtv
);
971 wined3d_stateblock_apply(stateblock
, ddraw
->state
);
972 wined3d_stateblock_decref(stateblock
);
975 if (!(cooplevel
& DDSCL_EXCLUSIVE
) && (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
977 /* When going from exclusive mode to normal, ddraw removes the
978 topmost bit unless the DDSCL_NOWINDOWCHANGES flag is set in
979 this call that sets it to normal, not in the old coop level. */
980 if (!(cooplevel
& DDSCL_NOWINDOWCHANGES
))
981 SetWindowPos(window
, HWND_NOTOPMOST
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
983 if (restore_mode_on_normal
&& FAILED(ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
)))
984 ERR("RestoreDisplayMode failed\n");
988 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
989 && (window
!= ddraw
->dest_window
|| !(cooplevel
& DDSCL_EXCLUSIVE
)))
990 wined3d_device_release_focus_window(ddraw
->wined3d_device
);
992 if ((cooplevel
& DDSCL_EXCLUSIVE
)
993 && (window
!= ddraw
->dest_window
|| !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)))
995 hr
= wined3d_device_acquire_focus_window(ddraw
->wined3d_device
, window
);
998 ERR("Failed to acquire focus window, hr %#lx.\n", hr
);
1003 if (cooplevel
& DDSCL_EXCLUSIVE
)
1005 SetRect(&clip_rect
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
));
1006 ClipCursor(&clip_rect
);
1009 /* Unhandled flags */
1010 if (cooplevel
& DDSCL_ALLOWREBOOT
)
1011 WARN("Unhandled flag DDSCL_ALLOWREBOOT, harmless\n");
1012 if (cooplevel
& DDSCL_ALLOWMODEX
)
1013 WARN("Unhandled flag DDSCL_ALLOWMODEX, harmless\n");
1014 if (cooplevel
& DDSCL_FPUSETUP
)
1015 WARN("Unhandled flag DDSCL_FPUSETUP, harmless\n");
1017 if (cooplevel
& DDSCL_EXCLUSIVE
)
1018 exclusive_ddraw
= ddraw
;
1019 else if (exclusive_ddraw
== ddraw
)
1020 exclusive_ddraw
= NULL
;
1022 /* Store the cooperative_level */
1023 ddraw
->cooperative_level
= cooplevel
;
1024 ddraw
->dest_window
= window
;
1026 TRACE("SetCooperativeLevel returning DD_OK\n");
1029 ddraw
->flags
&= ~DDRAW_SCL_RECURSIVE
;
1030 wined3d_mutex_unlock();
1035 static HRESULT WINAPI
ddraw7_SetCooperativeLevel(IDirectDraw7
*iface
, HWND window
, DWORD flags
)
1037 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1039 TRACE("iface %p, window %p, flags %#lx.\n", iface
, window
, flags
);
1041 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1044 static HRESULT WINAPI
ddraw4_SetCooperativeLevel(IDirectDraw4
*iface
, HWND window
, DWORD flags
)
1046 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1048 TRACE("iface %p, window %p, flags %#lx.\n", iface
, window
, flags
);
1050 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1053 static HRESULT WINAPI
ddraw2_SetCooperativeLevel(IDirectDraw2
*iface
, HWND window
, DWORD flags
)
1055 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1057 TRACE("iface %p, window %p, flags %#lx.\n", iface
, window
, flags
);
1059 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1062 static HRESULT WINAPI
ddraw1_SetCooperativeLevel(IDirectDraw
*iface
, HWND window
, DWORD flags
)
1064 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1067 TRACE("iface %p, window %p, flags %#lx.\n", iface
, window
, flags
);
1069 hr
= ddraw_set_cooperative_level(ddraw
, window
, flags
, FALSE
);
1071 ddraw
->flags
|= DDRAW_SCL_DDRAW1
;
1075 /*****************************************************************************
1076 * IDirectDraw7::SetDisplayMode
1078 * Sets the display screen resolution, color depth and refresh frequency
1079 * when in fullscreen mode (in theory).
1080 * Possible return values listed in the SDK suggest that this method fails
1081 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
1082 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
1083 * It seems to be valid to pass 0 for With and Height, this has to be tested
1084 * It could mean that the current video mode should be left as-is. (But why
1088 * Height, Width: Screen dimension
1089 * BPP: Color depth in Bits per pixel
1090 * Refreshrate: Screen refresh rate
1091 * Flags: Other stuff
1096 *****************************************************************************/
1097 static HRESULT WINAPI
ddraw7_SetDisplayMode(IDirectDraw7
*iface
, DWORD width
, DWORD height
,
1098 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1100 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1101 struct wined3d_display_mode mode
;
1102 enum wined3d_format_id format
;
1106 TRACE("iface %p, width %lu, height %lu, bpp %lu, refresh_rate %lu, flags %#lx.\n",
1107 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1109 if (force_refresh_rate
!= 0)
1111 TRACE("ForceRefreshRate overriding passed-in refresh rate (%lu Hz) to %lu Hz\n",
1112 refresh_rate
, force_refresh_rate
);
1113 refresh_rate
= force_refresh_rate
;
1116 wined3d_mutex_lock();
1118 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
1120 wined3d_mutex_unlock();
1121 return DDERR_NOEXCLUSIVEMODE
;
1124 if (!width
|| !height
)
1126 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here. */
1127 wined3d_mutex_unlock();
1133 case 8: format
= WINED3DFMT_P8_UINT
; break;
1134 case 15: format
= WINED3DFMT_B5G5R5X1_UNORM
; break;
1135 case 16: format
= WINED3DFMT_B5G6R5_UNORM
; break;
1136 case 24: format
= WINED3DFMT_B8G8R8_UNORM
; break;
1137 case 32: format
= WINED3DFMT_B8G8R8X8_UNORM
; break;
1138 default: format
= WINED3DFMT_UNKNOWN
; break;
1142 mode
.height
= height
;
1143 mode
.refresh_rate
= refresh_rate
;
1144 mode
.format_id
= format
;
1145 mode
.scanline_ordering
= WINED3D_SCANLINE_ORDERING_UNKNOWN
;
1147 /* TODO: The possible return values from msdn suggest that the screen mode
1148 * can't be changed if a surface is locked or some drawing is in progress. */
1149 if (SUCCEEDED(hr
= wined3d_output_set_display_mode(ddraw
->wined3d_output
, &mode
)))
1153 DDSURFACEDESC2
*surface_desc
= &ddraw
->primary
->surface_desc
;
1155 if (FAILED(hr
= wined3d_swapchain_resize_buffers(ddraw
->wined3d_swapchain
, 0,
1156 surface_desc
->dwWidth
, surface_desc
->dwHeight
, mode
.format_id
, WINED3D_MULTISAMPLE_NONE
, 0)))
1157 ERR("Failed to resize buffers, hr %#lx.\n", hr
);
1159 ddrawformat_from_wined3dformat(&ddraw
->primary
->surface_desc
.u4
.ddpfPixelFormat
, mode
.format_id
);
1161 ddraw
->flags
|= DDRAW_RESTORE_MODE
;
1163 if (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
1165 SetRect(&clip_rect
, 0, 0, width
, height
);
1166 ClipCursor(&clip_rect
);
1170 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_OK
);
1172 wined3d_mutex_unlock();
1174 return hr_ddraw_from_wined3d(hr
);
1177 static HRESULT WINAPI
ddraw4_SetDisplayMode(IDirectDraw4
*iface
, DWORD width
, DWORD height
,
1178 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1180 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1182 TRACE("iface %p, width %lu, height %lu, bpp %lu, refresh_rate %lu, flags %#lx.\n",
1183 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1185 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1188 static HRESULT WINAPI
ddraw2_SetDisplayMode(IDirectDraw2
*iface
,
1189 DWORD width
, DWORD height
, DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1191 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1193 TRACE("iface %p, width %lu, height %lu, bpp %lu, refresh_rate %lu, flags %#lx.\n",
1194 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1196 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1199 static HRESULT WINAPI
ddraw1_SetDisplayMode(IDirectDraw
*iface
, DWORD width
, DWORD height
, DWORD bpp
)
1201 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1203 TRACE("iface %p, width %lu, height %lu, bpp %lu.\n", iface
, width
, height
, bpp
);
1205 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, 0, 0);
1208 void ddraw_d3dcaps1_from_7(D3DDEVICEDESC
*caps1
, D3DDEVICEDESC7
*caps7
)
1210 memset(caps1
, 0, sizeof(*caps1
));
1211 caps1
->dwSize
= sizeof(*caps1
);
1212 caps1
->dwFlags
= D3DDD_COLORMODEL
1214 | D3DDD_TRANSFORMCAPS
1216 | D3DDD_LIGHTINGCAPS
1219 | D3DDD_DEVICERENDERBITDEPTH
1220 | D3DDD_DEVICEZBUFFERBITDEPTH
1221 | D3DDD_MAXBUFFERSIZE
1222 | D3DDD_MAXVERTEXCOUNT
;
1223 caps1
->dcmColorModel
= D3DCOLOR_RGB
;
1224 caps1
->dwDevCaps
= caps7
->dwDevCaps
;
1225 caps1
->dtcTransformCaps
.dwSize
= sizeof(caps1
->dtcTransformCaps
);
1226 caps1
->dtcTransformCaps
.dwCaps
= D3DTRANSFORMCAPS_CLIP
;
1227 caps1
->bClipping
= TRUE
;
1228 caps1
->dlcLightingCaps
.dwSize
= sizeof(caps1
->dlcLightingCaps
);
1229 caps1
->dlcLightingCaps
.dwCaps
= D3DLIGHTCAPS_DIRECTIONAL
1230 | D3DLIGHTCAPS_PARALLELPOINT
1231 | D3DLIGHTCAPS_POINT
1232 | D3DLIGHTCAPS_SPOT
;
1233 caps1
->dlcLightingCaps
.dwLightingModel
= D3DLIGHTINGMODEL_RGB
;
1234 caps1
->dlcLightingCaps
.dwNumLights
= caps7
->dwMaxActiveLights
;
1235 caps1
->dpcLineCaps
= caps7
->dpcLineCaps
;
1236 caps1
->dpcTriCaps
= caps7
->dpcTriCaps
;
1237 caps1
->dwDeviceRenderBitDepth
= caps7
->dwDeviceRenderBitDepth
;
1238 caps1
->dwDeviceZBufferBitDepth
= caps7
->dwDeviceZBufferBitDepth
;
1239 caps1
->dwMaxBufferSize
= 0;
1240 caps1
->dwMaxVertexCount
= 65536;
1241 caps1
->dwMinTextureWidth
= caps7
->dwMinTextureWidth
;
1242 caps1
->dwMinTextureHeight
= caps7
->dwMinTextureHeight
;
1243 caps1
->dwMaxTextureWidth
= caps7
->dwMaxTextureWidth
;
1244 caps1
->dwMaxTextureHeight
= caps7
->dwMaxTextureHeight
;
1245 caps1
->dwMinStippleWidth
= 1;
1246 caps1
->dwMinStippleHeight
= 1;
1247 caps1
->dwMaxStippleWidth
= 32;
1248 caps1
->dwMaxStippleHeight
= 32;
1249 caps1
->dwMaxTextureRepeat
= caps7
->dwMaxTextureRepeat
;
1250 caps1
->dwMaxTextureAspectRatio
= caps7
->dwMaxTextureAspectRatio
;
1251 caps1
->dwMaxAnisotropy
= caps7
->dwMaxAnisotropy
;
1252 caps1
->dvGuardBandLeft
= caps7
->dvGuardBandLeft
;
1253 caps1
->dvGuardBandTop
= caps7
->dvGuardBandTop
;
1254 caps1
->dvGuardBandRight
= caps7
->dvGuardBandRight
;
1255 caps1
->dvGuardBandBottom
= caps7
->dvGuardBandBottom
;
1256 caps1
->dvExtentsAdjust
= caps7
->dvExtentsAdjust
;
1257 caps1
->dwStencilCaps
= caps7
->dwStencilCaps
;
1258 caps1
->dwFVFCaps
= caps7
->dwFVFCaps
;
1259 caps1
->dwTextureOpCaps
= caps7
->dwTextureOpCaps
;
1260 caps1
->wMaxTextureBlendStages
= caps7
->wMaxTextureBlendStages
;
1261 caps1
->wMaxSimultaneousTextures
= caps7
->wMaxSimultaneousTextures
;
1264 HRESULT
ddraw_get_d3dcaps(const struct ddraw
*ddraw
, D3DDEVICEDESC7
*caps
)
1266 struct wined3d_caps wined3d_caps
;
1269 TRACE("ddraw %p, caps %p.\n", ddraw
, caps
);
1271 memset(&wined3d_caps
, 0, sizeof(wined3d_caps
));
1273 wined3d_mutex_lock();
1274 hr
= wined3d_get_device_caps(ddraw
->wined3d_adapter
, WINED3D_DEVICE_TYPE_HAL
, &wined3d_caps
);
1275 wined3d_mutex_unlock();
1278 WARN("Failed to get device caps, hr %#lx.\n", hr
);
1282 caps
->dwDevCaps
= wined3d_caps
.DevCaps
;
1283 caps
->dpcLineCaps
.dwMiscCaps
= wined3d_caps
.PrimitiveMiscCaps
;
1284 caps
->dpcLineCaps
.dwRasterCaps
= wined3d_caps
.RasterCaps
;
1285 caps
->dpcLineCaps
.dwZCmpCaps
= wined3d_caps
.ZCmpCaps
;
1286 caps
->dpcLineCaps
.dwSrcBlendCaps
= wined3d_caps
.SrcBlendCaps
;
1287 caps
->dpcLineCaps
.dwDestBlendCaps
= wined3d_caps
.DestBlendCaps
;
1288 caps
->dpcLineCaps
.dwAlphaCmpCaps
= wined3d_caps
.AlphaCmpCaps
;
1289 caps
->dpcLineCaps
.dwShadeCaps
= wined3d_caps
.ShadeCaps
;
1290 caps
->dpcLineCaps
.dwTextureCaps
= wined3d_caps
.TextureCaps
;
1291 caps
->dpcLineCaps
.dwTextureFilterCaps
= wined3d_caps
.TextureFilterCaps
;
1292 caps
->dpcLineCaps
.dwTextureAddressCaps
= wined3d_caps
.TextureAddressCaps
;
1294 caps
->dwMaxTextureWidth
= wined3d_caps
.MaxTextureWidth
;
1295 caps
->dwMaxTextureHeight
= wined3d_caps
.MaxTextureHeight
;
1297 caps
->dwMaxTextureRepeat
= wined3d_caps
.MaxTextureRepeat
;
1298 caps
->dwMaxTextureAspectRatio
= wined3d_caps
.MaxTextureAspectRatio
;
1299 caps
->dwMaxAnisotropy
= wined3d_caps
.MaxAnisotropy
;
1300 caps
->dvMaxVertexW
= wined3d_caps
.MaxVertexW
;
1302 caps
->dvGuardBandLeft
= wined3d_caps
.GuardBandLeft
;
1303 caps
->dvGuardBandTop
= wined3d_caps
.GuardBandTop
;
1304 caps
->dvGuardBandRight
= wined3d_caps
.GuardBandRight
;
1305 caps
->dvGuardBandBottom
= wined3d_caps
.GuardBandBottom
;
1307 caps
->dvExtentsAdjust
= wined3d_caps
.ExtentsAdjust
;
1308 caps
->dwStencilCaps
= wined3d_caps
.StencilCaps
;
1310 caps
->dwFVFCaps
= wined3d_caps
.FVFCaps
;
1311 caps
->dwTextureOpCaps
= wined3d_caps
.TextureOpCaps
;
1313 caps
->dwVertexProcessingCaps
= wined3d_caps
.VertexProcessingCaps
;
1314 caps
->dwMaxActiveLights
= wined3d_caps
.MaxActiveLights
;
1316 /* Remove all non-d3d7 caps */
1317 caps
->dwDevCaps
&= (
1318 D3DDEVCAPS_FLOATTLVERTEX
| D3DDEVCAPS_SORTINCREASINGZ
| D3DDEVCAPS_SORTDECREASINGZ
|
1319 D3DDEVCAPS_SORTEXACT
| D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
|
1320 D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
| D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
|
1321 D3DDEVCAPS_TEXTUREVIDEOMEMORY
| D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
|
1322 D3DDEVCAPS_TEXTURENONLOCALVIDMEM
| D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
1323 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
1324 D3DDEVCAPS_HWRASTERIZATION
);
1326 caps
->dwStencilCaps
&= (
1327 D3DSTENCILCAPS_KEEP
| D3DSTENCILCAPS_ZERO
| D3DSTENCILCAPS_REPLACE
|
1328 D3DSTENCILCAPS_INCRSAT
| D3DSTENCILCAPS_DECRSAT
| D3DSTENCILCAPS_INVERT
|
1329 D3DSTENCILCAPS_INCR
| D3DSTENCILCAPS_DECR
);
1333 caps
->dwTextureOpCaps
&= (
1334 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_SELECTARG2
|
1335 D3DTEXOPCAPS_MODULATE
| D3DTEXOPCAPS_MODULATE2X
| D3DTEXOPCAPS_MODULATE4X
|
1336 D3DTEXOPCAPS_ADD
| D3DTEXOPCAPS_ADDSIGNED
| D3DTEXOPCAPS_ADDSIGNED2X
|
1337 D3DTEXOPCAPS_SUBTRACT
| D3DTEXOPCAPS_ADDSMOOTH
| D3DTEXOPCAPS_BLENDTEXTUREALPHA
|
1338 D3DTEXOPCAPS_BLENDFACTORALPHA
| D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
| D3DTEXOPCAPS_BLENDCURRENTALPHA
|
1339 D3DTEXOPCAPS_PREMODULATE
| D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
|
1340 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
| D3DTEXOPCAPS_BUMPENVMAP
|
1341 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
| D3DTEXOPCAPS_DOTPRODUCT3
);
1343 caps
->dwVertexProcessingCaps
&= (
1344 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_VERTEXFOG
|
1345 D3DVTXPCAPS_DIRECTIONALLIGHTS
| D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
);
1347 caps
->dpcLineCaps
.dwMiscCaps
&= (
1348 D3DPMISCCAPS_MASKPLANES
| D3DPMISCCAPS_MASKZ
| D3DPMISCCAPS_LINEPATTERNREP
|
1349 D3DPMISCCAPS_CONFORMANT
| D3DPMISCCAPS_CULLNONE
| D3DPMISCCAPS_CULLCW
|
1350 D3DPMISCCAPS_CULLCCW
);
1352 caps
->dpcLineCaps
.dwRasterCaps
&= (
1353 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ROP2
| D3DPRASTERCAPS_XOR
|
1354 D3DPRASTERCAPS_PAT
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_SUBPIXEL
|
1355 D3DPRASTERCAPS_SUBPIXELX
| D3DPRASTERCAPS_FOGVERTEX
| D3DPRASTERCAPS_FOGTABLE
|
1356 D3DPRASTERCAPS_STIPPLE
| D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT
| D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT
|
1357 D3DPRASTERCAPS_ANTIALIASEDGES
| D3DPRASTERCAPS_MIPMAPLODBIAS
|
1358 D3DPRASTERCAPS_ZBUFFERLESSHSR
| D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
|
1359 D3DPRASTERCAPS_WBUFFER
| D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT
| D3DPRASTERCAPS_WFOG
|
1360 D3DPRASTERCAPS_ZFOG
| WINED3DPRASTERCAPS_DEPTHBIAS
);
1361 if (caps
->dpcLineCaps
.dwRasterCaps
& WINED3DPRASTERCAPS_DEPTHBIAS
)
1362 caps
->dpcLineCaps
.dwRasterCaps
= (caps
->dpcLineCaps
.dwRasterCaps
| D3DPRASTERCAPS_ZBIAS
)
1363 & ~WINED3DPRASTERCAPS_DEPTHBIAS
;
1364 if (wined3d_caps
.LineCaps
& WINED3DLINECAPS_ANTIALIAS
)
1365 caps
->dpcLineCaps
.dwRasterCaps
|= D3DPRASTERCAPS_ANTIALIASEDGES
;
1367 caps
->dpcLineCaps
.dwZCmpCaps
&= (
1368 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
1369 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
1370 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
1372 caps
->dpcLineCaps
.dwSrcBlendCaps
&= (
1373 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
1374 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
1375 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
1376 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
1377 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
1379 caps
->dpcLineCaps
.dwDestBlendCaps
&= (
1380 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
1381 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
1382 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
1383 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
1384 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
1386 caps
->dpcLineCaps
.dwAlphaCmpCaps
&= (
1387 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
1388 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
1389 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
1391 caps
->dpcLineCaps
.dwShadeCaps
&= (
1392 D3DPSHADECAPS_COLORFLATMONO
| D3DPSHADECAPS_COLORFLATRGB
| D3DPSHADECAPS_COLORGOURAUDMONO
|
1393 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_COLORPHONGMONO
| D3DPSHADECAPS_COLORPHONGRGB
|
1394 D3DPSHADECAPS_SPECULARFLATMONO
| D3DPSHADECAPS_SPECULARFLATRGB
| D3DPSHADECAPS_SPECULARGOURAUDMONO
|
1395 D3DPSHADECAPS_SPECULARGOURAUDRGB
| D3DPSHADECAPS_SPECULARPHONGMONO
| D3DPSHADECAPS_SPECULARPHONGRGB
|
1396 D3DPSHADECAPS_ALPHAFLATBLEND
| D3DPSHADECAPS_ALPHAFLATSTIPPLED
| D3DPSHADECAPS_ALPHAGOURAUDBLEND
|
1397 D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED
| D3DPSHADECAPS_ALPHAPHONGBLEND
| D3DPSHADECAPS_ALPHAPHONGSTIPPLED
|
1398 D3DPSHADECAPS_FOGFLAT
| D3DPSHADECAPS_FOGGOURAUD
| D3DPSHADECAPS_FOGPHONG
);
1400 caps
->dpcLineCaps
.dwTextureCaps
&= (
1401 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
1402 D3DPTEXTURECAPS_TRANSPARENCY
| D3DPTEXTURECAPS_BORDER
| D3DPTEXTURECAPS_SQUAREONLY
|
1403 D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
| D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
1404 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_COLORKEYBLEND
);
1406 caps
->dpcLineCaps
.dwTextureFilterCaps
&= (
1407 D3DPTFILTERCAPS_NEAREST
| D3DPTFILTERCAPS_LINEAR
| D3DPTFILTERCAPS_MIPNEAREST
|
1408 D3DPTFILTERCAPS_MIPLINEAR
| D3DPTFILTERCAPS_LINEARMIPNEAREST
| D3DPTFILTERCAPS_LINEARMIPLINEAR
|
1409 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
1410 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
1411 D3DPTFILTERCAPS_MAGFLINEAR
| D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
|
1412 D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
);
1414 caps
->dpcLineCaps
.dwTextureAddressCaps
&= (
1415 D3DPTADDRESSCAPS_WRAP
| D3DPTADDRESSCAPS_MIRROR
| D3DPTADDRESSCAPS_CLAMP
|
1416 D3DPTADDRESSCAPS_BORDER
| D3DPTADDRESSCAPS_INDEPENDENTUV
);
1418 if (!(caps
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
))
1420 /* DirectX7 always has the np2 flag set, no matter what the card
1421 * supports. Some old games (Rollcage) check the caps incorrectly.
1422 * If wined3d supports nonpow2 textures it also has np2 conditional
1424 caps
->dpcLineCaps
.dwTextureCaps
|= D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
;
1427 /* Fill the missing members, and do some fixup */
1428 caps
->dpcLineCaps
.dwSize
= sizeof(caps
->dpcLineCaps
);
1429 caps
->dpcLineCaps
.dwTextureBlendCaps
= D3DPTBLENDCAPS_ADD
1430 | D3DPTBLENDCAPS_MODULATEMASK
1431 | D3DPTBLENDCAPS_COPY
1432 | D3DPTBLENDCAPS_DECAL
1433 | D3DPTBLENDCAPS_DECALALPHA
1434 | D3DPTBLENDCAPS_DECALMASK
1435 | D3DPTBLENDCAPS_MODULATE
1436 | D3DPTBLENDCAPS_MODULATEALPHA
;
1437 caps
->dpcLineCaps
.dwStippleWidth
= 32;
1438 caps
->dpcLineCaps
.dwStippleHeight
= 32;
1439 /* Use the same for the TriCaps */
1440 caps
->dpcTriCaps
= caps
->dpcLineCaps
;
1442 caps
->dwDeviceRenderBitDepth
= DDBD_16
| DDBD_24
| DDBD_32
;
1443 caps
->dwDeviceZBufferBitDepth
= DDBD_16
| DDBD_24
;
1444 caps
->dwMinTextureWidth
= 1;
1445 caps
->dwMinTextureHeight
= 1;
1447 /* Convert DWORDs safely to WORDs */
1448 caps
->wMaxTextureBlendStages
= min(wined3d_caps
.MaxTextureBlendStages
, 0xffff);
1449 caps
->wMaxSimultaneousTextures
= min(wined3d_caps
.MaxSimultaneousTextures
, 0xffff);
1450 caps
->wMaxUserClipPlanes
= min(wined3d_caps
.MaxUserClipPlanes
, D3DMAXUSERCLIPPLANES
);
1451 caps
->wMaxVertexBlendMatrices
= min(wined3d_caps
.MaxVertexBlendMatrices
, 0xffff);
1453 caps
->deviceGUID
= IID_IDirect3DTnLHalDevice
;
1455 caps
->dwReserved1
= 0;
1456 caps
->dwReserved2
= 0;
1457 caps
->dwReserved3
= 0;
1458 caps
->dwReserved4
= 0;
1463 /*****************************************************************************
1464 * IDirectDraw7::GetCaps
1466 * Returns the drives capabilities
1468 * Used for version 1, 2, 4 and 7
1471 * DriverCaps: Structure to write the Hardware accelerated caps to
1472 * HelCaps: Structure to write the emulation caps to
1475 * This implementation returns DD_OK only
1477 *****************************************************************************/
1478 static HRESULT WINAPI
ddraw7_GetCaps(IDirectDraw7
*iface
, DDCAPS
*DriverCaps
, DDCAPS
*HELCaps
)
1480 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1481 DDSCAPS2 ddscaps
= {0, 0, 0, {0}};
1482 struct wined3d_caps winecaps
;
1486 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, DriverCaps
, HELCaps
);
1488 /* One structure must be != NULL */
1489 if (!DriverCaps
&& !HELCaps
)
1491 WARN("Invalid parameters.\n");
1492 return DDERR_INVALIDPARAMS
;
1495 memset(&caps
, 0, sizeof(caps
));
1496 memset(&winecaps
, 0, sizeof(winecaps
));
1497 caps
.dwSize
= sizeof(caps
);
1499 wined3d_mutex_lock();
1500 hr
= wined3d_device_get_device_caps(ddraw
->wined3d_device
, &winecaps
);
1503 WARN("Failed to get device caps, %#lx.\n", hr
);
1504 wined3d_mutex_unlock();
1508 hr
= IDirectDraw7_GetAvailableVidMem(iface
, &ddscaps
, &caps
.dwVidMemTotal
, &caps
.dwVidMemFree
);
1511 WARN("IDirectDraw7::GetAvailableVidMem failed\n");
1512 wined3d_mutex_unlock();
1516 hr
= IDirectDraw7_GetFourCCCodes(iface
, &caps
.dwNumFourCCCodes
, NULL
);
1517 wined3d_mutex_unlock();
1520 WARN("IDirectDraw7::GetFourCCCodes failed\n");
1524 caps
.dwCaps
= winecaps
.ddraw_caps
.caps
;
1525 caps
.dwCaps2
= winecaps
.ddraw_caps
.caps2
;
1526 caps
.dwCKeyCaps
= winecaps
.ddraw_caps
.color_key_caps
;
1527 caps
.dwFXCaps
= winecaps
.ddraw_caps
.fx_caps
;
1528 caps
.dwPalCaps
= DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
;
1529 caps
.ddsCaps
.dwCaps
= winecaps
.ddraw_caps
.dds_caps
;
1530 caps
.dwSVBCaps
= winecaps
.ddraw_caps
.svb_caps
;
1531 caps
.dwSVBCKeyCaps
= winecaps
.ddraw_caps
.svb_color_key_caps
;
1532 caps
.dwSVBFXCaps
= winecaps
.ddraw_caps
.svb_fx_caps
;
1533 caps
.dwVSBCaps
= winecaps
.ddraw_caps
.vsb_caps
;
1534 caps
.dwVSBCKeyCaps
= winecaps
.ddraw_caps
.vsb_color_key_caps
;
1535 caps
.dwVSBFXCaps
= winecaps
.ddraw_caps
.vsb_fx_caps
;
1536 caps
.dwSSBCaps
= winecaps
.ddraw_caps
.ssb_caps
;
1537 caps
.dwSSBCKeyCaps
= winecaps
.ddraw_caps
.ssb_color_key_caps
;
1538 caps
.dwSSBFXCaps
= winecaps
.ddraw_caps
.ssb_fx_caps
;
1540 caps
.dwCaps
|= DDCAPS_ALIGNSTRIDE
;
1541 caps
.dwAlignStrideAlign
= DDRAW_STRIDE_ALIGNMENT
;
1543 caps
.ddsOldCaps
.dwCaps
= caps
.ddsCaps
.dwCaps
;
1547 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &caps
);
1548 if (TRACE_ON(ddraw
))
1550 TRACE("Driver Caps :\n");
1551 DDRAW_dump_DDCAPS(DriverCaps
);
1557 DD_STRUCT_COPY_BYSIZE(HELCaps
, &caps
);
1558 if (TRACE_ON(ddraw
))
1560 TRACE("HEL Caps :\n");
1561 DDRAW_dump_DDCAPS(HELCaps
);
1568 static HRESULT WINAPI
ddraw4_GetCaps(IDirectDraw4
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1570 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1572 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1574 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1577 static HRESULT WINAPI
ddraw2_GetCaps(IDirectDraw2
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1579 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1581 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1583 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1586 static HRESULT WINAPI
ddraw1_GetCaps(IDirectDraw
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1588 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1590 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1592 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1595 /*****************************************************************************
1596 * IDirectDraw7::Compact
1598 * No idea what it does, MSDN says it's not implemented.
1601 * DD_OK, but this is unchecked
1603 *****************************************************************************/
1604 static HRESULT WINAPI
ddraw7_Compact(IDirectDraw7
*iface
)
1606 TRACE("iface %p.\n", iface
);
1611 static HRESULT WINAPI
ddraw4_Compact(IDirectDraw4
*iface
)
1613 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1615 TRACE("iface %p.\n", iface
);
1617 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1620 static HRESULT WINAPI
ddraw2_Compact(IDirectDraw2
*iface
)
1622 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1624 TRACE("iface %p.\n", iface
);
1626 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1629 static HRESULT WINAPI
ddraw1_Compact(IDirectDraw
*iface
)
1631 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1633 TRACE("iface %p.\n", iface
);
1635 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1638 /*****************************************************************************
1639 * IDirectDraw7::GetDisplayMode
1641 * Returns information about the current display mode
1643 * Exists in versions 1, 2, 4 and 7
1646 * DDSD: Address of a surface description structure to write the info to
1651 *****************************************************************************/
1652 static HRESULT WINAPI
ddraw7_GetDisplayMode(IDirectDraw7
*iface
, DDSURFACEDESC2
*DDSD
)
1654 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1655 struct wined3d_display_mode mode
;
1658 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
1660 /* This seems sane */
1661 if (!DDSD
|| (DDSD
->dwSize
!= sizeof(DDSURFACEDESC
) && DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
)))
1662 return DDERR_INVALIDPARAMS
;
1664 wined3d_mutex_lock();
1666 if (FAILED(hr
= wined3d_output_get_display_mode(ddraw
->wined3d_output
, &mode
, NULL
)))
1668 ERR("Failed to get display mode, hr %#lx.\n", hr
);
1669 wined3d_mutex_unlock();
1673 memset(DDSD
, 0, DDSD
->dwSize
);
1674 DDSD
->dwSize
= sizeof(*DDSD
);
1675 DDSD
->dwFlags
= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
1676 DDSD
->dwWidth
= mode
.width
;
1677 DDSD
->dwHeight
= mode
.height
;
1678 DDSD
->u2
.dwRefreshRate
= mode
.refresh_rate
;
1679 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
1680 ddrawformat_from_wined3dformat(&DDSD
->u4
.ddpfPixelFormat
, mode
.format_id
);
1681 DDSD
->u1
.lPitch
= mode
.width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
1685 TRACE("Returning surface desc :\n");
1686 DDRAW_dump_surface_desc(DDSD
);
1689 wined3d_mutex_unlock();
1694 static HRESULT WINAPI
ddraw4_GetDisplayMode(IDirectDraw4
*iface
, DDSURFACEDESC2
*surface_desc
)
1696 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1698 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1700 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, surface_desc
);
1703 static HRESULT WINAPI
ddraw2_GetDisplayMode(IDirectDraw2
*iface
, DDSURFACEDESC
*surface_desc
)
1705 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1708 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1710 hr
= ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1711 if (SUCCEEDED(hr
)) surface_desc
->dwSize
= sizeof(*surface_desc
);
1715 static HRESULT WINAPI
ddraw1_GetDisplayMode(IDirectDraw
*iface
, DDSURFACEDESC
*surface_desc
)
1717 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1720 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1722 hr
= ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1723 if (SUCCEEDED(hr
)) surface_desc
->dwSize
= sizeof(*surface_desc
);
1727 /*****************************************************************************
1728 * IDirectDraw7::GetFourCCCodes
1730 * Returns an array of supported FourCC codes.
1732 * Exists in versions 1, 2, 4 and 7
1735 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
1736 * of enumerated codes
1737 * Codes: Pointer to an array of DWORDs where the supported codes are written
1741 * Always returns DD_OK, as it's a stub for now
1743 *****************************************************************************/
1744 static HRESULT WINAPI
ddraw7_GetFourCCCodes(IDirectDraw7
*iface
, DWORD
*NumCodes
, DWORD
*Codes
)
1746 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1747 static const enum wined3d_format_id formats
[] =
1749 WINED3DFMT_YUY2
, WINED3DFMT_UYVY
, WINED3DFMT_YV12
,
1750 WINED3DFMT_DXT1
, WINED3DFMT_DXT2
, WINED3DFMT_DXT3
, WINED3DFMT_DXT4
, WINED3DFMT_DXT5
,
1751 WINED3DFMT_ATI2N
, WINED3DFMT_NVHU
, WINED3DFMT_NVHS
1753 struct wined3d_display_mode mode
;
1754 DWORD count
= 0, i
, outsize
;
1757 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, NumCodes
, Codes
);
1759 if (FAILED(hr
= wined3d_output_get_display_mode(ddraw
->wined3d_output
, &mode
, NULL
)))
1761 ERR("Failed to get display mode, hr %#lx.\n", hr
);
1765 outsize
= NumCodes
&& Codes
? *NumCodes
: 0;
1767 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
)
1769 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, ddraw
->wined3d_adapter
, WINED3D_DEVICE_TYPE_HAL
,
1770 mode
.format_id
, 0, 0, WINED3D_RTYPE_TEXTURE_2D
, formats
[i
])))
1772 if (count
< outsize
)
1773 Codes
[count
] = formats
[i
];
1778 TRACE("Returning %lu FourCC codes\n", count
);
1785 static HRESULT WINAPI
ddraw4_GetFourCCCodes(IDirectDraw4
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1787 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1789 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1791 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1794 static HRESULT WINAPI
ddraw2_GetFourCCCodes(IDirectDraw2
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1796 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1798 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1800 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1803 static HRESULT WINAPI
ddraw1_GetFourCCCodes(IDirectDraw
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1805 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1807 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1809 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1812 static HRESULT WINAPI
ddraw7_GetMonitorFrequency(IDirectDraw7
*iface
, DWORD
*frequency
)
1814 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1815 struct wined3d_display_mode mode
;
1818 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1820 wined3d_mutex_lock();
1821 hr
= wined3d_output_get_display_mode(ddraw
->wined3d_output
, &mode
, NULL
);
1822 wined3d_mutex_unlock();
1825 WARN("Failed to get display mode, hr %#lx.\n", hr
);
1829 *frequency
= mode
.refresh_rate
;
1834 static HRESULT WINAPI
ddraw4_GetMonitorFrequency(IDirectDraw4
*iface
, DWORD
*frequency
)
1836 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1838 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1840 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1843 static HRESULT WINAPI
ddraw2_GetMonitorFrequency(IDirectDraw2
*iface
, DWORD
*frequency
)
1845 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1847 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1849 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1852 static HRESULT WINAPI
ddraw1_GetMonitorFrequency(IDirectDraw
*iface
, DWORD
*frequency
)
1854 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1856 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1858 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1861 static HRESULT WINAPI
ddraw7_GetVerticalBlankStatus(IDirectDraw7
*iface
, BOOL
*status
)
1863 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1864 struct wined3d_raster_status raster_status
;
1867 TRACE("iface %p, status %p.\n", iface
, status
);
1870 return DDERR_INVALIDPARAMS
;
1872 wined3d_mutex_lock();
1873 hr
= wined3d_output_get_raster_status(ddraw
->wined3d_output
, &raster_status
);
1874 wined3d_mutex_unlock();
1877 WARN("Failed to get raster status, hr %#lx.\n", hr
);
1881 *status
= raster_status
.in_vblank
;
1886 static HRESULT WINAPI
ddraw4_GetVerticalBlankStatus(IDirectDraw4
*iface
, BOOL
*status
)
1888 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1890 TRACE("iface %p, status %p.\n", iface
, status
);
1892 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1895 static HRESULT WINAPI
ddraw2_GetVerticalBlankStatus(IDirectDraw2
*iface
, BOOL
*status
)
1897 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1899 TRACE("iface %p, status %p.\n", iface
, status
);
1901 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1904 static HRESULT WINAPI
ddraw1_GetVerticalBlankStatus(IDirectDraw
*iface
, BOOL
*status
)
1906 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1908 TRACE("iface %p, status %p.\n", iface
, status
);
1910 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1913 /*****************************************************************************
1914 * IDirectDraw7::GetAvailableVidMem
1916 * Returns the total and free video memory
1919 * caps: Specifies the memory type asked for
1920 * total: Pointer to a DWORD to be filled with the total memory
1921 * free: Pointer to a DWORD to be filled with the free memory
1925 * DDERR_INVALIDPARAMS if free and total are NULL
1927 *****************************************************************************/
1928 static HRESULT WINAPI
ddraw7_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*caps
, DWORD
*total
,
1931 unsigned int framebuffer_size
, total_vidmem
, free_vidmem
;
1932 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1933 struct wined3d_display_mode mode
;
1936 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1938 if (!total
&& !free
)
1939 return DDERR_INVALIDPARAMS
;
1941 if (TRACE_ON(ddraw
))
1943 TRACE("Asked for memory with description: ");
1944 DDRAW_dump_DDSCAPS2(caps
);
1946 wined3d_mutex_lock();
1948 /* Todo: System memory vs local video memory vs non-local video memory
1949 * The MSDN also mentions differences between texture memory and other
1950 * resources, but that's not important
1953 /* Some applications (e.g. 3DMark 2000) assume that the reported amount of
1954 * video memory doesn't include the memory used by the default framebuffer.
1956 if (FAILED(hr
= wined3d_output_get_display_mode(ddraw
->wined3d_output
, &mode
, NULL
)))
1958 WARN("Failed to get display mode, hr %#lx.\n", hr
);
1959 wined3d_mutex_unlock();
1962 framebuffer_size
= wined3d_calculate_format_pitch(ddraw
->wined3d_adapter
,
1963 mode
.format_id
, mode
.width
);
1964 framebuffer_size
*= mode
.height
;
1968 free_vidmem
= wined3d_device_get_available_texture_mem(ddraw
->wined3d_device
);
1969 *free
= framebuffer_size
> free_vidmem
? 0 : free_vidmem
- framebuffer_size
;
1970 TRACE("Free video memory %#lx.\n", *free
);
1975 struct wined3d_adapter_identifier desc
= {0};
1977 hr
= wined3d_adapter_get_identifier(ddraw
->wined3d_adapter
, 0, &desc
);
1978 total_vidmem
= min(UINT_MAX
, desc
.video_memory
);
1979 *total
= framebuffer_size
> total_vidmem
? 0 : total_vidmem
- framebuffer_size
;
1980 TRACE("Total video memory %#lx.\n", *total
);
1983 wined3d_mutex_unlock();
1988 static HRESULT WINAPI
ddraw4_GetAvailableVidMem(IDirectDraw4
*iface
,
1989 DDSCAPS2
*caps
, DWORD
*total
, DWORD
*free
)
1991 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1993 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1995 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, caps
, total
, free
);
1998 static HRESULT WINAPI
ddraw2_GetAvailableVidMem(IDirectDraw2
*iface
,
1999 DDSCAPS
*caps
, DWORD
*total
, DWORD
*free
)
2001 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2004 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
2006 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
2007 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, &caps2
, total
, free
);
2010 /*****************************************************************************
2011 * IDirectDraw7::Initialize
2013 * Initializes a DirectDraw interface.
2016 * GUID: Interface identifier. Well, don't know what this is really good
2020 * Returns DD_OK on the first call,
2021 * DDERR_ALREADYINITIALIZED on repeated calls
2023 *****************************************************************************/
2024 static HRESULT WINAPI
ddraw7_Initialize(IDirectDraw7
*iface
, GUID
*guid
)
2026 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2028 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2030 if (ddraw
->flags
& DDRAW_INITIALIZED
)
2031 return DDERR_ALREADYINITIALIZED
;
2033 /* FIXME: To properly take the GUID into account we should call
2034 * ddraw_init() here instead of in DDRAW_Create(). */
2036 FIXME("Ignoring guid %s.\n", debugstr_guid(guid
));
2038 ddraw
->flags
|= DDRAW_INITIALIZED
;
2042 static HRESULT WINAPI
ddraw4_Initialize(IDirectDraw4
*iface
, GUID
*guid
)
2044 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2046 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2048 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2051 static HRESULT WINAPI
ddraw2_Initialize(IDirectDraw2
*iface
, GUID
*guid
)
2053 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2055 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2057 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2060 static HRESULT WINAPI
ddraw1_Initialize(IDirectDraw
*iface
, GUID
*guid
)
2062 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2064 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2066 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2069 static HRESULT WINAPI
d3d1_Initialize(IDirect3D
*iface
, REFIID riid
)
2071 TRACE("iface %p, riid %s.\n", iface
, debugstr_guid(riid
));
2073 return DDERR_ALREADYINITIALIZED
;
2076 /*****************************************************************************
2077 * IDirectDraw7::FlipToGDISurface
2079 * "Makes the surface that the GDI writes to the primary surface"
2080 * Looks like some windows specific thing we don't have to care about.
2081 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
2082 * show error boxes ;)
2083 * Well, just return DD_OK.
2086 * Always returns DD_OK
2088 *****************************************************************************/
2089 static HRESULT WINAPI
ddraw7_FlipToGDISurface(IDirectDraw7
*iface
)
2091 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2092 IDirectDrawSurface7
*gdi_surface
;
2093 struct ddraw_surface
*gdi_impl
;
2096 TRACE("iface %p.\n", iface
);
2098 wined3d_mutex_lock();
2100 if (FAILED(hr
= IDirectDraw7_GetGDISurface(iface
, &gdi_surface
)))
2102 WARN("Failed to retrieve GDI surface, hr %#lx.\n", hr
);
2103 wined3d_mutex_unlock();
2107 gdi_impl
= impl_from_IDirectDrawSurface7(gdi_surface
);
2108 if (gdi_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
2111 hr
= IDirectDrawSurface7_Flip(&ddraw
->primary
->IDirectDrawSurface7_iface
, gdi_surface
, DDFLIP_WAIT
);
2112 IDirectDrawSurface7_Release(gdi_surface
);
2114 wined3d_mutex_unlock();
2119 static HRESULT WINAPI
ddraw4_FlipToGDISurface(IDirectDraw4
*iface
)
2121 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2123 TRACE("iface %p.\n", iface
);
2125 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2128 static HRESULT WINAPI
ddraw2_FlipToGDISurface(IDirectDraw2
*iface
)
2130 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2132 TRACE("iface %p.\n", iface
);
2134 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2137 static HRESULT WINAPI
ddraw1_FlipToGDISurface(IDirectDraw
*iface
)
2139 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2141 TRACE("iface %p.\n", iface
);
2143 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2146 /*****************************************************************************
2147 * IDirectDraw7::WaitForVerticalBlank
2149 * This method allows applications to get in sync with the vertical blank
2151 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
2152 * redraw the screen, most likely because of this stub
2155 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
2156 * or DDWAITVB_BLOCKEND
2157 * h: Not used, according to MSDN
2160 * Always returns DD_OK
2162 *****************************************************************************/
2163 static HRESULT WINAPI
ddraw7_WaitForVerticalBlank(IDirectDraw7
*iface
, DWORD Flags
, HANDLE event
)
2167 TRACE("iface %p, flags %#lx, event %p.\n", iface
, Flags
, event
);
2169 /* This function is called often, so print the fixme only once */
2172 FIXME("iface %p, flags %#lx, event %p stub!\n", iface
, Flags
, event
);
2176 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
2177 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
2178 return DDERR_UNSUPPORTED
; /* unchecked */
2183 static HRESULT WINAPI
ddraw4_WaitForVerticalBlank(IDirectDraw4
*iface
, DWORD flags
, HANDLE event
)
2185 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2187 TRACE("iface %p, flags %#lx, event %p.\n", iface
, flags
, event
);
2189 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2192 static HRESULT WINAPI
ddraw2_WaitForVerticalBlank(IDirectDraw2
*iface
, DWORD flags
, HANDLE event
)
2194 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2196 TRACE("iface %p, flags %#lx, event %p.\n", iface
, flags
, event
);
2198 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2201 static HRESULT WINAPI
ddraw1_WaitForVerticalBlank(IDirectDraw
*iface
, DWORD flags
, HANDLE event
)
2203 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2205 TRACE("iface %p, flags %#lx, event %p.\n", iface
, flags
, event
);
2207 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2210 static HRESULT WINAPI
ddraw7_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
2212 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2213 struct wined3d_raster_status raster_status
;
2216 TRACE("iface %p, line %p.\n", iface
, Scanline
);
2218 wined3d_mutex_lock();
2219 hr
= wined3d_output_get_raster_status(ddraw
->wined3d_output
, &raster_status
);
2220 wined3d_mutex_unlock();
2223 WARN("Failed to get raster status, hr %#lx.\n", hr
);
2227 *Scanline
= raster_status
.scan_line
;
2229 if (raster_status
.in_vblank
)
2230 return DDERR_VERTICALBLANKINPROGRESS
;
2235 static HRESULT WINAPI
ddraw4_GetScanLine(IDirectDraw4
*iface
, DWORD
*line
)
2237 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2239 TRACE("iface %p, line %p.\n", iface
, line
);
2241 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2244 static HRESULT WINAPI
ddraw2_GetScanLine(IDirectDraw2
*iface
, DWORD
*line
)
2246 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2248 TRACE("iface %p, line %p.\n", iface
, line
);
2250 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2253 static HRESULT WINAPI
ddraw1_GetScanLine(IDirectDraw
*iface
, DWORD
*line
)
2255 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2257 TRACE("iface %p, line %p.\n", iface
, line
);
2259 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2262 static HRESULT WINAPI
ddraw7_TestCooperativeLevel(IDirectDraw7
*iface
)
2264 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2266 TRACE("iface %p.\n", iface
);
2268 return ddraw
->device_state
== DDRAW_DEVICE_STATE_LOST
? DDERR_NOEXCLUSIVEMODE
: DD_OK
;
2271 static HRESULT WINAPI
ddraw4_TestCooperativeLevel(IDirectDraw4
*iface
)
2273 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2275 TRACE("iface %p.\n", iface
);
2277 return ddraw7_TestCooperativeLevel(&ddraw
->IDirectDraw7_iface
);
2280 /*****************************************************************************
2281 * IDirectDraw7::GetGDISurface
2283 * Returns the surface that GDI is treating as the primary surface.
2284 * For Wine this is the front buffer
2287 * GDISurface: Address to write the surface pointer to
2290 * DD_OK if the surface was found
2291 * DDERR_NOTFOUND if the GDI surface wasn't found
2293 *****************************************************************************/
2294 static HRESULT WINAPI
ddraw7_GetGDISurface(IDirectDraw7
*iface
, IDirectDrawSurface7
**surface
)
2296 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2297 struct ddraw_surface
*ddraw_surface
;
2299 TRACE("iface %p, surface %p.\n", iface
, surface
);
2301 wined3d_mutex_lock();
2303 if (!ddraw
->gdi_surface
|| !(ddraw_surface
= wined3d_texture_get_sub_resource_parent(ddraw
->gdi_surface
, 0)))
2305 WARN("GDI surface not available.\n");
2307 wined3d_mutex_unlock();
2308 return DDERR_NOTFOUND
;
2310 *surface
= &ddraw_surface
->IDirectDrawSurface7_iface
;
2311 IDirectDrawSurface7_AddRef(*surface
);
2313 wined3d_mutex_unlock();
2318 static HRESULT WINAPI
ddraw4_GetGDISurface(IDirectDraw4
*iface
, IDirectDrawSurface4
**surface
)
2320 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2321 struct ddraw_surface
*surface_impl
;
2322 IDirectDrawSurface7
*surface7
;
2325 TRACE("iface %p, surface %p.\n", iface
, surface
);
2327 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2333 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2334 *surface
= &surface_impl
->IDirectDrawSurface4_iface
;
2335 IDirectDrawSurface4_AddRef(*surface
);
2336 IDirectDrawSurface7_Release(surface7
);
2341 static HRESULT WINAPI
ddraw2_GetGDISurface(IDirectDraw2
*iface
, IDirectDrawSurface
**surface
)
2343 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2344 struct ddraw_surface
*surface_impl
;
2345 IDirectDrawSurface7
*surface7
;
2348 TRACE("iface %p, surface %p.\n", iface
, surface
);
2350 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2356 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2357 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2358 IDirectDrawSurface_AddRef(*surface
);
2359 IDirectDrawSurface7_Release(surface7
);
2364 static HRESULT WINAPI
ddraw1_GetGDISurface(IDirectDraw
*iface
, IDirectDrawSurface
**surface
)
2366 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2367 struct ddraw_surface
*surface_impl
;
2368 IDirectDrawSurface7
*surface7
;
2371 TRACE("iface %p, surface %p.\n", iface
, surface
);
2373 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2379 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2380 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2381 IDirectDrawSurface_AddRef(*surface
);
2382 IDirectDrawSurface7_Release(surface7
);
2387 struct displaymodescallback_context
2389 LPDDENUMMODESCALLBACK func
;
2393 static HRESULT CALLBACK
EnumDisplayModesCallbackThunk(DDSURFACEDESC2
*surface_desc
, void *context
)
2395 struct displaymodescallback_context
*cbcontext
= context
;
2398 DDSD2_to_DDSD(surface_desc
, &desc
);
2399 return cbcontext
->func(&desc
, cbcontext
->context
);
2402 /*****************************************************************************
2403 * IDirectDraw7::EnumDisplayModes
2405 * Enumerates the supported Display modes. The modes can be filtered with
2406 * the DDSD parameter.
2409 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES. For old ddraw
2410 * versions (3 and older?) this is reserved and must be 0.
2411 * DDSD: Surface description to filter the modes
2412 * Context: Pointer passed back to the callback function
2413 * cb: Application-provided callback function
2417 * DDERR_INVALIDPARAMS if the callback wasn't set
2419 *****************************************************************************/
2420 static HRESULT WINAPI
ddraw7_EnumDisplayModes(IDirectDraw7
*iface
, DWORD Flags
,
2421 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMMODESCALLBACK2 cb
)
2423 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2424 struct wined3d_display_mode
*enum_modes
= NULL
;
2425 struct wined3d_display_mode mode
;
2426 unsigned int modenum
, fmt
;
2427 DDSURFACEDESC2 callback_sd
;
2428 unsigned enum_mode_count
= 0, enum_mode_array_size
= 16;
2429 DDPIXELFORMAT pixelformat
;
2431 static const enum wined3d_format_id checkFormatList
[] =
2433 WINED3DFMT_B8G8R8X8_UNORM
,
2434 WINED3DFMT_B5G6R5_UNORM
,
2438 TRACE("iface %p, flags %#lx, surface_desc %p, context %p, callback %p.\n",
2439 iface
, Flags
, DDSD
, Context
, cb
);
2442 return DDERR_INVALIDPARAMS
;
2444 if (!(enum_modes
= heap_alloc(enum_mode_array_size
* sizeof(*enum_modes
))))
2445 return DDERR_OUTOFMEMORY
;
2447 wined3d_mutex_lock();
2449 pixelformat
.dwSize
= sizeof(pixelformat
);
2450 for(fmt
= 0; fmt
< ARRAY_SIZE(checkFormatList
); fmt
++)
2453 while (wined3d_output_get_mode(ddraw
->wined3d_output
, checkFormatList
[fmt
],
2454 WINED3D_SCANLINE_ORDERING_UNKNOWN
, modenum
++, &mode
, false) == WINED3D_OK
)
2459 ddrawformat_from_wined3dformat(&pixelformat
, mode
.format_id
);
2462 if (DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.width
!= DDSD
->dwWidth
)
2464 if (DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.height
!= DDSD
->dwHeight
)
2466 if (DDSD
->dwFlags
& DDSD_REFRESHRATE
&& mode
.refresh_rate
!= DDSD
->u2
.dwRefreshRate
)
2468 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
2469 && pixelformat
.u1
.dwRGBBitCount
!= DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
)
2473 /* DX docs state EnumDisplayMode should return only unique modes */
2474 for (i
= 0; i
< enum_mode_count
; i
++)
2476 if (enum_modes
[i
].width
== mode
.width
&& enum_modes
[i
].height
== mode
.height
2477 && enum_modes
[i
].format_id
== mode
.format_id
2478 && (enum_modes
[i
].refresh_rate
== mode
.refresh_rate
|| !(Flags
& DDEDM_REFRESHRATES
)))
2486 memset(&callback_sd
, 0, sizeof(callback_sd
));
2487 callback_sd
.dwSize
= sizeof(callback_sd
);
2488 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2490 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
|DDSD_REFRESHRATE
;
2491 if (Flags
& DDEDM_REFRESHRATES
)
2492 callback_sd
.u2
.dwRefreshRate
= mode
.refresh_rate
;
2494 callback_sd
.dwWidth
= mode
.width
;
2495 callback_sd
.dwHeight
= mode
.height
;
2497 callback_sd
.u4
.ddpfPixelFormat
=pixelformat
;
2499 /* Calc pitch and DWORD align like MSDN says */
2500 callback_sd
.u1
.lPitch
= (callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8) * mode
.width
;
2501 callback_sd
.u1
.lPitch
= (callback_sd
.u1
.lPitch
+ 3) & ~3;
2503 TRACE("Enumerating %lux%lux%lu @%lu\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
,
2504 callback_sd
.u2
.dwRefreshRate
);
2506 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
2508 TRACE("Application asked to terminate the enumeration\n");
2509 heap_free(enum_modes
);
2510 wined3d_mutex_unlock();
2514 if (enum_mode_count
== enum_mode_array_size
)
2516 struct wined3d_display_mode
*new_enum_modes
;
2518 enum_mode_array_size
*= 2;
2519 if (!(new_enum_modes
= heap_realloc(enum_modes
, enum_mode_array_size
* sizeof(*new_enum_modes
))))
2521 heap_free(enum_modes
);
2522 wined3d_mutex_unlock();
2523 return DDERR_OUTOFMEMORY
;
2526 enum_modes
= new_enum_modes
;
2528 enum_modes
[enum_mode_count
++] = mode
;
2532 TRACE("End of enumeration\n");
2533 heap_free(enum_modes
);
2534 wined3d_mutex_unlock();
2539 static HRESULT WINAPI
ddraw4_EnumDisplayModes(IDirectDraw4
*iface
, DWORD flags
,
2540 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK2 callback
)
2542 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2544 TRACE("iface %p, flags %#lx, surface_desc %p, context %p, callback %p.\n",
2545 iface
, flags
, surface_desc
, context
, callback
);
2547 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
, context
, callback
);
2550 static HRESULT WINAPI
ddraw2_EnumDisplayModes(IDirectDraw2
*iface
, DWORD flags
,
2551 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2553 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2554 struct displaymodescallback_context cbcontext
;
2555 DDSURFACEDESC2 surface_desc2
;
2557 TRACE("iface %p, flags %#lx, surface_desc %p, context %p, callback %p.\n",
2558 iface
, flags
, surface_desc
, context
, callback
);
2560 cbcontext
.func
= callback
;
2561 cbcontext
.context
= context
;
2563 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2564 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2565 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2568 static HRESULT WINAPI
ddraw1_EnumDisplayModes(IDirectDraw
*iface
, DWORD flags
,
2569 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2571 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2572 struct displaymodescallback_context cbcontext
;
2573 DDSURFACEDESC2 surface_desc2
;
2575 TRACE("iface %p, flags %#lx, surface_desc %p, context %p, callback %p.\n",
2576 iface
, flags
, surface_desc
, context
, callback
);
2578 cbcontext
.func
= callback
;
2579 cbcontext
.context
= context
;
2581 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2582 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2583 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2586 /*****************************************************************************
2587 * IDirectDraw7::EvaluateMode
2589 * Used with IDirectDraw7::StartModeTest to test video modes.
2590 * EvaluateMode is used to pass or fail a mode, and continue with the next
2594 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
2595 * Timeout: Returns the amount of seconds left before the mode would have
2596 * been failed automatically
2599 * This implementation always DD_OK, because it's a stub
2601 *****************************************************************************/
2602 static HRESULT WINAPI
ddraw7_EvaluateMode(IDirectDraw7
*iface
, DWORD Flags
, DWORD
*Timeout
)
2604 FIXME("iface %p, flags %#lx, timeout %p stub!\n", iface
, Flags
, Timeout
);
2606 /* When implementing this, implement it in WineD3D */
2611 /*****************************************************************************
2612 * IDirectDraw7::GetDeviceIdentifier
2614 * Returns the device identifier, which gives information about the driver
2615 * Our device identifier is defined at the beginning of this file.
2618 * DDDI: Address for the returned structure
2619 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
2622 * On success it returns DD_OK
2623 * DDERR_INVALIDPARAMS if DDDI is NULL
2625 *****************************************************************************/
2626 static HRESULT WINAPI
ddraw7_GetDeviceIdentifier(IDirectDraw7
*iface
,
2627 DDDEVICEIDENTIFIER2
*DDDI
, DWORD Flags
)
2629 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2630 struct wined3d_adapter_identifier adapter_id
;
2633 TRACE("iface %p, device_identifier %p, flags %#lx.\n", iface
, DDDI
, Flags
);
2636 return DDERR_INVALIDPARAMS
;
2638 if (Flags
& DDGDI_GETHOSTIDENTIFIER
)
2640 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
2641 * host adapter, if there's a secondary 3D adapter. This doesn't apply
2642 * to any modern hardware, nor is it interesting for Wine, so ignore it.
2643 * Size of DDDEVICEIDENTIFIER2 may be aligned to 8 bytes and thus 4
2644 * bytes too long. So only copy the relevant part of the structure
2647 memcpy(DDDI
, &deviceidentifier
, FIELD_OFFSET(DDDEVICEIDENTIFIER2
, dwWHQLLevel
) + sizeof(DWORD
));
2651 /* Drakan: Order of the Flame expects accurate D3D device information from ddraw */
2652 adapter_id
.driver
= DDDI
->szDriver
;
2653 adapter_id
.driver_size
= sizeof(DDDI
->szDriver
);
2654 adapter_id
.description
= DDDI
->szDescription
;
2655 adapter_id
.description_size
= sizeof(DDDI
->szDescription
);
2656 wined3d_mutex_lock();
2657 hr
= wined3d_adapter_get_identifier(ddraw
->wined3d_adapter
, WINED3DENUM_WHQL_LEVEL
, &adapter_id
);
2658 wined3d_mutex_unlock();
2659 if (FAILED(hr
)) return hr
;
2661 DDDI
->liDriverVersion
= adapter_id
.driver_version
;
2662 DDDI
->dwVendorId
= adapter_id
.vendor_id
;
2663 DDDI
->dwDeviceId
= adapter_id
.device_id
;
2664 DDDI
->dwSubSysId
= adapter_id
.subsystem_id
;
2665 DDDI
->dwRevision
= adapter_id
.revision
;
2666 DDDI
->guidDeviceIdentifier
= adapter_id
.device_identifier
;
2667 DDDI
->dwWHQLLevel
= adapter_id
.whql_level
;
2671 static HRESULT WINAPI
ddraw4_GetDeviceIdentifier(IDirectDraw4
*iface
,
2672 DDDEVICEIDENTIFIER
*identifier
, DWORD flags
)
2674 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2675 DDDEVICEIDENTIFIER2 identifier2
;
2678 TRACE("iface %p, identifier %p, flags %#lx.\n", iface
, identifier
, flags
);
2680 hr
= ddraw7_GetDeviceIdentifier(&ddraw
->IDirectDraw7_iface
, &identifier2
, flags
);
2681 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&identifier2
, identifier
);
2686 /*****************************************************************************
2687 * IDirectDraw7::GetSurfaceFromDC
2689 * Returns the Surface for a GDI device context handle.
2690 * Is this related to IDirectDrawSurface::GetDC ???
2693 * hdc: hdc to return the surface for
2694 * Surface: Address to write the surface pointer to
2697 * Always returns DD_OK because it's a stub
2699 *****************************************************************************/
2700 static HRESULT WINAPI
ddraw7_GetSurfaceFromDC(IDirectDraw7
*iface
,
2701 HDC dc
, IDirectDrawSurface7
**surface
)
2703 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2704 struct ddraw_surface
*surface_impl
;
2706 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2709 return E_INVALIDARG
;
2714 wined3d_mutex_lock();
2715 LIST_FOR_EACH_ENTRY(surface_impl
, &ddraw
->surface_list
, struct ddraw_surface
, surface_list_entry
)
2717 if (surface_impl
->dc
!= dc
)
2720 TRACE("Found surface %p for dc %p.\n", surface_impl
, dc
);
2721 *surface
= &surface_impl
->IDirectDrawSurface7_iface
;
2722 IDirectDrawSurface7_AddRef(*surface
);
2723 wined3d_mutex_unlock();
2726 wined3d_mutex_unlock();
2729 TRACE("No surface found for dc %p.\n", dc
);
2731 return DDERR_NOTFOUND
;
2734 static HRESULT WINAPI
ddraw4_GetSurfaceFromDC(IDirectDraw4
*iface
, HDC dc
,
2735 IDirectDrawSurface4
**surface
)
2737 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2738 struct ddraw_surface
*surface_impl
;
2739 IDirectDrawSurface7
*surface7
;
2742 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2744 if (!surface
) return E_INVALIDARG
;
2746 hr
= ddraw7_GetSurfaceFromDC(&ddraw
->IDirectDraw7_iface
, dc
, &surface7
);
2752 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2753 /* Tests say this is true */
2754 *surface
= (IDirectDrawSurface4
*)&surface_impl
->IDirectDrawSurface_iface
;
2755 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2756 IDirectDrawSurface7_Release(surface7
);
2761 static HRESULT CALLBACK
restore_callback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
2763 IDirectDrawSurface_Restore(surface
);
2764 IDirectDrawSurface_Release(surface
);
2766 return DDENUMRET_OK
;
2769 static HRESULT WINAPI
ddraw7_RestoreAllSurfaces(IDirectDraw7
*iface
)
2771 TRACE("iface %p.\n", iface
);
2773 return IDirectDraw7_EnumSurfaces(iface
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
2774 NULL
, NULL
, restore_callback
);
2777 static HRESULT WINAPI
ddraw4_RestoreAllSurfaces(IDirectDraw4
*iface
)
2779 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2781 TRACE("iface %p.\n", iface
);
2783 return ddraw7_RestoreAllSurfaces(&ddraw
->IDirectDraw7_iface
);
2786 /*****************************************************************************
2787 * IDirectDraw7::StartModeTest
2789 * Tests the specified video modes to update the system registry with
2790 * refresh rate information. StartModeTest starts the mode test,
2791 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
2792 * isn't called within 15 seconds, the mode is failed automatically
2794 * As refresh rates are handled by the X server, I don't think this
2795 * Method is important
2798 * Modes: An array of mode specifications
2799 * NumModes: The number of modes in Modes
2800 * Flags: Some flags...
2803 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
2804 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
2807 *****************************************************************************/
2808 static HRESULT WINAPI
ddraw7_StartModeTest(IDirectDraw7
*iface
, SIZE
*Modes
, DWORD NumModes
, DWORD Flags
)
2810 FIXME("iface %p, modes %p, mode_count %lu, flags %#lx partial stub!\n",
2811 iface
, Modes
, NumModes
, Flags
);
2813 /* This looks sane */
2814 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
2816 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
2817 * As it is not, DDERR_TESTFINISHED is returned
2818 * (hopefully that's correct
2820 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
2821 * well, that value doesn't (yet) exist in the wine headers, so ignore it
2827 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
, DDSURFACEDESC2
*surface_desc
,
2828 IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
2830 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2831 struct ddraw_surface
*impl
;
2834 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2835 iface
, surface_desc
, surface
, outer_unknown
);
2837 wined3d_mutex_lock();
2839 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2841 WARN("Cooperative level not set.\n");
2842 wined3d_mutex_unlock();
2843 return DDERR_NOCOOPERATIVELEVELSET
;
2846 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2848 WARN("Application supplied invalid surface descriptor\n");
2849 wined3d_mutex_unlock();
2850 return DDERR_INVALIDPARAMS
;
2859 WARN("Surface pointer %p is invalid.\n", surface
);
2860 wined3d_mutex_unlock();
2861 return DDERR_INVALIDPARAMS
;
2865 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2867 if (TRACE_ON(ddraw
))
2869 TRACE(" (%p) Requesting surface desc :\n", iface
);
2870 DDRAW_dump_surface_desc(surface_desc
);
2873 WARN("Application tried to create an explicit front or back buffer\n");
2874 wined3d_mutex_unlock();
2875 return DDERR_INVALIDCAPS
;
2878 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 7);
2879 wined3d_mutex_unlock();
2883 *surface
= &impl
->IDirectDrawSurface7_iface
;
2884 IDirectDraw7_AddRef(iface
);
2885 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2890 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
2891 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
2893 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2894 struct ddraw_surface
*impl
;
2897 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2898 iface
, surface_desc
, surface
, outer_unknown
);
2900 wined3d_mutex_lock();
2902 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2904 WARN("Cooperative level not set.\n");
2905 wined3d_mutex_unlock();
2906 return DDERR_NOCOOPERATIVELEVELSET
;
2909 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2911 WARN("Application supplied invalid surface descriptor\n");
2912 wined3d_mutex_unlock();
2913 return DDERR_INVALIDPARAMS
;
2922 WARN("Surface pointer %p is invalid.\n", surface
);
2923 wined3d_mutex_unlock();
2924 return DDERR_INVALIDPARAMS
;
2928 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2930 if (TRACE_ON(ddraw
))
2932 TRACE(" (%p) Requesting surface desc :\n", iface
);
2933 DDRAW_dump_surface_desc(surface_desc
);
2936 WARN("Application tried to create an explicit front or back buffer\n");
2937 wined3d_mutex_unlock();
2938 return DDERR_INVALIDCAPS
;
2941 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 4);
2942 wined3d_mutex_unlock();
2946 *surface
= &impl
->IDirectDrawSurface4_iface
;
2947 IDirectDraw4_AddRef(iface
);
2948 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2953 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
2954 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2956 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2957 struct ddraw_surface
*impl
;
2959 DDSURFACEDESC2 surface_desc2
;
2961 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2962 iface
, surface_desc
, surface
, outer_unknown
);
2964 wined3d_mutex_lock();
2966 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2968 WARN("Cooperative level not set.\n");
2969 wined3d_mutex_unlock();
2970 return DDERR_NOCOOPERATIVELEVELSET
;
2973 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2975 WARN("Application supplied invalid surface descriptor\n");
2976 wined3d_mutex_unlock();
2977 return DDERR_INVALIDPARAMS
;
2986 WARN("Surface pointer %p is invalid.\n", surface
);
2987 wined3d_mutex_unlock();
2988 return DDERR_INVALIDPARAMS
;
2992 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2993 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2995 if (TRACE_ON(ddraw
))
2997 TRACE(" (%p) Requesting surface desc :\n", iface
);
2998 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
3001 WARN("Application tried to create an explicit front or back buffer\n");
3002 wined3d_mutex_unlock();
3003 return DDERR_INVALIDCAPS
;
3006 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 2);
3007 wined3d_mutex_unlock();
3011 *surface
= &impl
->IDirectDrawSurface_iface
;
3012 impl
->ifaceToRelease
= NULL
;
3017 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
3018 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3020 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3021 struct ddraw_surface
*impl
;
3023 DDSURFACEDESC2 surface_desc2
;
3025 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3026 iface
, surface_desc
, surface
, outer_unknown
);
3028 wined3d_mutex_lock();
3030 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
3032 WARN("Cooperative level not set.\n");
3033 wined3d_mutex_unlock();
3034 return DDERR_NOCOOPERATIVELEVELSET
;
3037 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3039 WARN("Application supplied invalid surface descriptor\n");
3040 wined3d_mutex_unlock();
3041 return DDERR_INVALIDPARAMS
;
3050 WARN("Surface pointer %p is invalid.\n", surface
);
3051 wined3d_mutex_unlock();
3052 return DDERR_INVALIDPARAMS
;
3056 if ((surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
))
3057 == (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
)
3058 || (surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
))
3059 == ((DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
)))
3061 WARN("Application tried to create an explicit front or back buffer.\n");
3062 wined3d_mutex_unlock();
3063 return DDERR_INVALIDCAPS
;
3066 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3067 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 1);
3068 wined3d_mutex_unlock();
3072 *surface
= &impl
->IDirectDrawSurface_iface
;
3073 impl
->ifaceToRelease
= NULL
;
3079 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
3080 const DDPIXELFORMAT
*provided
)
3082 /* Some flags must be present in both or neither for a match. */
3083 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
3084 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
3085 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
3087 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3090 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
3093 if (requested
->dwFlags
& DDPF_FOURCC
)
3094 if (requested
->dwFourCC
!= provided
->dwFourCC
)
3097 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
3098 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3099 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
3102 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3103 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3104 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
3107 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
3108 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
3111 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
3112 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3114 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
3117 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
3118 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
3124 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3133 #define CMP(FLAG, FIELD) \
3134 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3135 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3137 static const struct compare_info compare
[] =
3139 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3140 CMP(BACKBUFFERCOUNT
, u5
.dwBackBufferCount
),
3142 CMP(CKDESTBLT
, ddckCKDestBlt
),
3143 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3144 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3145 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3146 CMP(HEIGHT
, dwHeight
),
3147 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3148 CMP(LPSURFACE
, lpSurface
),
3149 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3150 CMP(PITCH
, u1
/* lPitch */),
3151 /* PIXELFORMAT: manual */
3152 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3153 CMP(TEXTURESTAGE
, dwTextureStage
),
3154 CMP(WIDTH
, dwWidth
),
3155 /* ZBUFFERBITDEPTH: "obsolete" */
3162 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3165 for (i
=0; i
< ARRAY_SIZE(compare
); i
++)
3167 if (requested
->dwFlags
& compare
[i
].flag
3168 && memcmp((const char *)provided
+ compare
[i
].offset
,
3169 (const char *)requested
+ compare
[i
].offset
,
3170 compare
[i
].size
) != 0)
3174 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3176 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3177 &provided
->u4
.ddpfPixelFormat
))
3184 struct surfacescallback2_context
3186 LPDDENUMSURFACESCALLBACK2 func
;
3190 struct surfacescallback_context
3192 LPDDENUMSURFACESCALLBACK func
;
3196 static HRESULT CALLBACK
EnumSurfacesCallback2Thunk(IDirectDrawSurface7
*surface
,
3197 DDSURFACEDESC2
*surface_desc
, void *context
)
3199 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3200 struct surfacescallback2_context
*cbcontext
= context
;
3203 return cbcontext
->func(NULL
, surface_desc
, cbcontext
->context
);
3205 IDirectDrawSurface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
3206 IDirectDrawSurface7_Release(surface
);
3208 return cbcontext
->func(&surface_impl
->IDirectDrawSurface4_iface
,
3209 surface_desc
, cbcontext
->context
);
3212 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3213 DDSURFACEDESC2
*surface_desc
, void *context
)
3215 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3216 struct surfacescallback_context
*cbcontext
= context
;
3219 return cbcontext
->func(NULL
, (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3221 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
3222 IDirectDrawSurface7_Release(surface
);
3224 return cbcontext
->func(&surface_impl
->IDirectDrawSurface_iface
,
3225 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3228 struct enum_surface_mode_params
3230 IDirectDraw7
*ddraw
;
3231 const DDSURFACEDESC2
*desc
;
3232 LPDDENUMSURFACESCALLBACK7 callback
;
3236 static HRESULT CALLBACK
enum_surface_mode_callback(DDSURFACEDESC2
*surface_desc
, void *context
)
3238 const struct enum_surface_mode_params
*params
= context
;
3239 DDSURFACEDESC2 desc
= *params
->desc
;
3240 IDirectDrawSurface7
*surface
;
3242 desc
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PITCH
| DDSD_PIXELFORMAT
;
3243 desc
.dwWidth
= surface_desc
->dwWidth
;
3244 desc
.dwHeight
= surface_desc
->dwHeight
;
3245 desc
.u1
.lPitch
= surface_desc
->u1
.lPitch
;
3246 desc
.u4
.ddpfPixelFormat
= surface_desc
->u4
.ddpfPixelFormat
;
3248 if (SUCCEEDED(ddraw7_CreateSurface(params
->ddraw
, &desc
, &surface
, NULL
)))
3250 IDirectDrawSurface7_Release(surface
);
3251 return params
->callback(NULL
, &desc
, params
->context
);
3253 return DDENUMRET_OK
;
3256 /*****************************************************************************
3257 * IDirectDraw7::EnumSurfaces
3259 * Loops through all surfaces attached to this device and calls the
3260 * application callback. This can't be relayed to WineD3DDevice,
3261 * because some WineD3DSurfaces' parents are IParent objects
3264 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3265 * DDSD: Description to filter for
3266 * Context: Application-provided pointer, it's passed unmodified to the
3268 * Callback: Address to call for each surface
3271 * DDERR_INVALIDPARAMS if the callback is NULL
3274 *****************************************************************************/
3275 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD flags
,
3276 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK7 callback
)
3278 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3281 TRACE("iface %p, flags %#lx, surface_desc %p, context %p, callback %p.\n",
3282 iface
, flags
, surface_desc
, context
, callback
);
3285 return DDERR_INVALIDPARAMS
;
3287 if (flags
& DDENUMSURFACES_CANBECREATED
)
3289 IDirectDrawSurface7
*surface
;
3291 if ((flags
& (DDENUMSURFACES_ALL
| DDENUMSURFACES_MATCH
| DDENUMSURFACES_NOMATCH
)) != DDENUMSURFACES_MATCH
)
3292 return DDERR_INVALIDPARAMS
;
3294 wined3d_mutex_lock();
3296 if (surface_desc
->dwFlags
& (DDSD_WIDTH
| DDSD_HEIGHT
))
3298 if (SUCCEEDED(ddraw7_CreateSurface(iface
, surface_desc
, &surface
, NULL
)))
3300 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3301 callback(NULL
, &surface_impl
->surface_desc
, context
);
3302 IDirectDrawSurface7_Release(surface
);
3307 DDSURFACEDESC2 desc
=
3309 .dwSize
= sizeof(desc
),
3310 .dwFlags
= DDSD_PIXELFORMAT
,
3311 .u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
),
3313 struct enum_surface_mode_params params
=
3316 .desc
= surface_desc
,
3317 .callback
= callback
,
3320 struct wined3d_display_mode mode
;
3322 if (FAILED(hr
= wined3d_output_get_display_mode(ddraw
->wined3d_output
, &mode
, NULL
)))
3324 ERR("Failed to get display mode, hr %#lx.\n", hr
);
3325 wined3d_mutex_unlock();
3326 return hr_ddraw_from_wined3d(hr
);
3329 ddrawformat_from_wined3dformat(&desc
.u4
.ddpfPixelFormat
, mode
.format_id
);
3330 hr
= ddraw7_EnumDisplayModes(iface
, 0, &desc
, ¶ms
, enum_surface_mode_callback
);
3333 wined3d_mutex_unlock();
3335 else if (flags
& DDENUMSURFACES_DOESEXIST
)
3337 struct ddraw_surface
*surface
, *cursor
;
3338 BOOL nomatch
= !!(flags
& DDENUMSURFACES_NOMATCH
);
3340 wined3d_mutex_lock();
3342 /* Use the safe enumeration, as the callback may destroy surfaces. */
3343 LIST_FOR_EACH_ENTRY_SAFE(surface
, cursor
, &ddraw
->surface_list
, struct ddraw_surface
, surface_list_entry
)
3345 if (!surface
->iface_count
)
3347 WARN("Not enumerating surface %p because it doesn't have any references.\n", surface
);
3351 if ((flags
& DDENUMSURFACES_ALL
)
3352 || nomatch
!= ddraw_match_surface_desc(surface_desc
, &surface
->surface_desc
))
3354 DDSURFACEDESC2 desc
= surface
->surface_desc
;
3356 TRACE("Enumerating surface %p.\n", surface
);
3357 IDirectDrawSurface7_AddRef(&surface
->IDirectDrawSurface7_iface
);
3358 if (callback(&surface
->IDirectDrawSurface7_iface
, &desc
, context
) != DDENUMRET_OK
)
3363 wined3d_mutex_unlock();
3367 return DDERR_INVALIDPARAMS
;
3373 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3374 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3376 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3377 struct surfacescallback2_context cbcontext
;
3379 TRACE("iface %p, flags %#lx, surface_desc %p, context %p, callback %p.\n",
3380 iface
, flags
, surface_desc
, context
, callback
);
3382 cbcontext
.func
= callback
;
3383 cbcontext
.context
= context
;
3385 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
,
3386 &cbcontext
, EnumSurfacesCallback2Thunk
);
3389 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3390 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3392 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3393 struct surfacescallback_context cbcontext
;
3394 DDSURFACEDESC2 surface_desc2
;
3396 TRACE("iface %p, flags %#lx, surface_desc %p, context %p, callback %p.\n",
3397 iface
, flags
, surface_desc
, context
, callback
);
3399 cbcontext
.func
= callback
;
3400 cbcontext
.context
= context
;
3402 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3403 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3404 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3407 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3408 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3410 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3411 struct surfacescallback_context cbcontext
;
3412 DDSURFACEDESC2 surface_desc2
;
3414 TRACE("iface %p, flags %#lx, surface_desc %p, context %p, callback %p.\n",
3415 iface
, flags
, surface_desc
, context
, callback
);
3417 cbcontext
.func
= callback
;
3418 cbcontext
.context
= context
;
3420 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3421 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3422 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3425 /*****************************************************************************
3426 * DirectDrawCreateClipper (DDRAW.@)
3428 * Creates a new IDirectDrawClipper object.
3431 * Clipper: Address to write the interface pointer to
3432 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3436 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3437 * E_OUTOFMEMORY if allocating the object failed
3439 *****************************************************************************/
3440 HRESULT WINAPI
DirectDrawCreateClipper(DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3442 struct ddraw_clipper
*object
;
3445 TRACE("flags %#lx, clipper %p, outer_unknown %p.\n",
3446 flags
, clipper
, outer_unknown
);
3449 return CLASS_E_NOAGGREGATION
;
3451 wined3d_mutex_lock();
3453 if (!(object
= heap_alloc_zero(sizeof(*object
))))
3455 wined3d_mutex_unlock();
3456 return E_OUTOFMEMORY
;
3459 hr
= ddraw_clipper_init(object
);
3462 WARN("Failed to initialize clipper, hr %#lx.\n", hr
);
3464 wined3d_mutex_unlock();
3468 TRACE("Created clipper %p.\n", object
);
3469 *clipper
= &object
->IDirectDrawClipper_iface
;
3470 wined3d_mutex_unlock();
3475 /*****************************************************************************
3476 * IDirectDraw7::CreateClipper
3478 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3480 *****************************************************************************/
3481 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3482 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3484 TRACE("iface %p, flags %#lx, clipper %p, outer_unknown %p.\n",
3485 iface
, Flags
, Clipper
, UnkOuter
);
3487 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3490 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
, DWORD flags
,
3491 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3493 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3495 TRACE("iface %p, flags %#lx, clipper %p, outer_unknown %p.\n",
3496 iface
, flags
, clipper
, outer_unknown
);
3498 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3501 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
3502 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3504 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3506 TRACE("iface %p, flags %#lx, clipper %p, outer_unknown %p.\n",
3507 iface
, flags
, clipper
, outer_unknown
);
3509 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3512 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
3513 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3515 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3517 TRACE("iface %p, flags %#lx, clipper %p, outer_unknown %p.\n",
3518 iface
, flags
, clipper
, outer_unknown
);
3520 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3523 /*****************************************************************************
3524 * IDirectDraw7::CreatePalette
3526 * Creates a new IDirectDrawPalette object
3529 * Flags: The flags for the new clipper
3530 * ColorTable: Color table to assign to the new clipper
3531 * Palette: Address to write the interface pointer to
3532 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3536 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3537 * E_OUTOFMEMORY if allocating the object failed
3539 *****************************************************************************/
3540 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
3541 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
3543 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3544 struct ddraw_palette
*object
;
3547 TRACE("iface %p, flags %#lx, color_table %p, palette %p, outer_unknown %p.\n",
3548 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3551 return CLASS_E_NOAGGREGATION
;
3553 wined3d_mutex_lock();
3555 /* The refcount test shows that a cooplevel is required for this */
3556 if (!ddraw
->cooperative_level
)
3558 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3559 wined3d_mutex_unlock();
3560 return DDERR_NOCOOPERATIVELEVELSET
;
3563 if (!(object
= heap_alloc(sizeof(*object
))))
3565 ERR("Out of memory when allocating memory for a palette implementation\n");
3566 wined3d_mutex_unlock();
3567 return E_OUTOFMEMORY
;
3570 hr
= ddraw_palette_init(object
, ddraw
, Flags
, ColorTable
);
3573 WARN("Failed to initialize palette, hr %#lx.\n", hr
);
3575 wined3d_mutex_unlock();
3579 TRACE("Created palette %p.\n", object
);
3580 *Palette
= &object
->IDirectDrawPalette_iface
;
3581 wined3d_mutex_unlock();
3586 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
, PALETTEENTRY
*entries
,
3587 IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3589 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3592 TRACE("iface %p, flags %#lx, entries %p, palette %p, outer_unknown %p.\n",
3593 iface
, flags
, entries
, palette
, outer_unknown
);
3595 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3596 if (SUCCEEDED(hr
) && *palette
)
3598 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3599 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3600 IDirectDraw4_AddRef(iface
);
3601 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3606 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
3607 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3609 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3612 TRACE("iface %p, flags %#lx, entries %p, palette %p, outer_unknown %p.\n",
3613 iface
, flags
, entries
, palette
, outer_unknown
);
3615 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3616 if (SUCCEEDED(hr
) && *palette
)
3618 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3619 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3620 impl
->ifaceToRelease
= NULL
;
3626 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
3627 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3629 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3632 TRACE("iface %p, flags %#lx, entries %p, palette %p, outer_unknown %p.\n",
3633 iface
, flags
, entries
, palette
, outer_unknown
);
3635 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3636 if (SUCCEEDED(hr
) && *palette
)
3638 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3639 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3640 impl
->ifaceToRelease
= NULL
;
3646 /*****************************************************************************
3647 * IDirectDraw7::DuplicateSurface
3649 * Duplicates a surface. The surface memory points to the same memory as
3650 * the original surface, and it's released when the last surface referencing
3651 * it is released. I guess that's beyond Wine's surface management right now
3652 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3653 * test application to implement this)
3656 * Src: Address of the source surface
3657 * Dest: Address to write the new surface pointer to
3660 * See IDirectDraw7::CreateSurface
3662 *****************************************************************************/
3663 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
3664 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
3666 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(Src
);
3668 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
3670 /* For now, simply create a new, independent surface */
3671 return IDirectDraw7_CreateSurface(iface
, &src_surface
->surface_desc
, Dest
, NULL
);
3674 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
, IDirectDrawSurface4
*src
,
3675 IDirectDrawSurface4
**dst
)
3677 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
3678 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3679 struct ddraw_surface
*dst_impl
;
3680 IDirectDrawSurface7
*dst7
;
3683 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3685 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3686 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3692 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3693 *dst
= &dst_impl
->IDirectDrawSurface4_iface
;
3694 IDirectDrawSurface4_AddRef(*dst
);
3695 IDirectDrawSurface7_Release(dst7
);
3700 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
3701 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
3703 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3704 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3705 struct ddraw_surface
*dst_impl
;
3706 IDirectDrawSurface7
*dst7
;
3709 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3711 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3712 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3715 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3716 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3717 IDirectDrawSurface_AddRef(*dst
);
3718 IDirectDrawSurface7_Release(dst7
);
3723 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
, IDirectDrawSurface
*src
,
3724 IDirectDrawSurface
**dst
)
3726 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3727 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3728 struct ddraw_surface
*dst_impl
;
3729 IDirectDrawSurface7
*dst7
;
3732 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3734 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3735 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3738 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3739 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3740 IDirectDrawSurface_AddRef(*dst
);
3741 IDirectDrawSurface7_Release(dst7
);
3746 /*****************************************************************************
3747 * IDirect3D7::EnumDevices
3749 * The EnumDevices method for IDirect3D7. It enumerates all supported
3750 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
3753 * callback: Function to call for each enumerated device
3754 * context: Pointer to pass back to the app
3757 * D3D_OK, or the return value of the GetCaps call
3759 *****************************************************************************/
3760 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
3762 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
3763 D3DDEVICEDESC7 device_desc7
;
3768 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3771 return DDERR_INVALIDPARAMS
;
3773 wined3d_mutex_lock();
3775 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3777 wined3d_mutex_unlock();
3780 dev_caps
= device_desc7
.dwDevCaps
;
3782 for (i
= 0; i
< ARRAY_SIZE(device_list7
); i
++)
3786 device_desc7
.deviceGUID
= *device_list7
[i
].device_guid
;
3787 device_desc7
.dwDevCaps
= dev_caps
& ~device_list7
[i
].unsupported_caps
;
3788 ret
= callback(device_list7
[i
].interface_name
, device_list7
[i
].device_name
, &device_desc7
, context
);
3789 if (ret
!= DDENUMRET_OK
)
3791 TRACE("Application cancelled the enumeration.\n");
3792 wined3d_mutex_unlock();
3797 TRACE("End of enumeration.\n");
3799 wined3d_mutex_unlock();
3804 /*****************************************************************************
3805 * IDirect3D3::EnumDevices
3807 * Enumerates all supported Direct3DDevice interfaces. This is the
3808 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
3810 * Versions 1, 2 and 3
3813 * callback: Application-provided routine to call for each enumerated device
3814 * Context: Pointer to pass to the callback
3817 * D3D_OK on success,
3818 * The result of IDirect3DImpl_GetCaps if it failed
3820 *****************************************************************************/
3821 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3823 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
3825 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3826 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
3827 D3DDEVICEDESC7 device_desc7
;
3830 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
3831 * name string. Let's put the string in a sufficiently sized array in
3832 * writable memory. */
3833 char device_name
[50];
3834 strcpy(device_name
,"Direct3D HEL");
3836 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3839 return DDERR_INVALIDPARAMS
;
3841 wined3d_mutex_lock();
3843 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3845 wined3d_mutex_unlock();
3848 ddraw_d3dcaps1_from_7(&device_desc1
, &device_desc7
);
3850 /* Do I have to enumerate the reference id? Note from old d3d7:
3851 * "It seems that enumerating the reference IID on Direct3D 1 games
3852 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
3854 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
3855 * EnumReference which enables / disables enumerating the reference
3856 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
3857 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
3858 * demo directory suggest this.
3860 * Some games(GTA 2) seem to use the second enumerated device, so I have
3861 * to enumerate at least 2 devices. So enumerate the reference device to
3864 * Other games (Rollcage) tell emulation and hal device apart by certain
3865 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
3866 * limitation flag), and it refuses all devices that have the perspective
3867 * flag set. This way it refuses the emulation device, and HAL devices
3868 * never have POW2 unset in d3d7 on windows. */
3869 if (ddraw
->d3dversion
!= 1)
3871 static CHAR reference_description
[] = "RGB Direct3D emulation";
3873 TRACE("Enumerating WineD3D D3DDevice interface.\n");
3874 hal_desc
= device_desc1
;
3875 hel_desc
= device_desc1
;
3876 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
3877 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3878 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3879 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3880 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3881 /* RGB, RAMP and MMX devices have a HAL dcmColorModel of 0 */
3882 hal_desc
.dcmColorModel
= 0;
3883 /* RGB, RAMP and MMX devices cannot report HAL hardware flags */
3884 hal_desc
.dwFlags
= 0;
3885 /* RGB, REF, RAMP and MMX devices don't report hardware transform and lighting capability */
3886 hal_desc
.dwDevCaps
&= ~(D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWRASTERIZATION
);
3887 hel_desc
.dwDevCaps
&= ~(D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWRASTERIZATION
);
3889 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
3890 device_name
, &hal_desc
, &hel_desc
, context
);
3891 if (hr
!= D3DENUMRET_OK
)
3893 TRACE("Application cancelled the enumeration.\n");
3894 wined3d_mutex_unlock();
3899 strcpy(device_name
,"Direct3D HAL");
3901 TRACE("Enumerating HAL Direct3D device.\n");
3902 hal_desc
= device_desc1
;
3903 hel_desc
= device_desc1
;
3905 /* The hal device does not have the pow2 flag set in hel, but in hal. */
3906 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3907 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3908 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3909 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3910 /* HAL devices have a HEL dcmColorModel of 0 */
3911 hel_desc
.dcmColorModel
= 0;
3912 /* HAL devices report hardware transform and lighting capability, but not in hel */
3913 hel_desc
.dwDevCaps
&= ~(D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_DRAWPRIMITIVES2EX
);
3915 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
3916 device_name
, &hal_desc
, &hel_desc
, context
);
3917 if (hr
!= D3DENUMRET_OK
)
3919 TRACE("Application cancelled the enumeration.\n");
3920 wined3d_mutex_unlock();
3924 TRACE("End of enumeration.\n");
3926 wined3d_mutex_unlock();
3931 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3933 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3935 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3937 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3940 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3942 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3944 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3946 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3949 /*****************************************************************************
3950 * IDirect3D3::CreateLight
3952 * Creates an IDirect3DLight interface. This interface is used in
3953 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
3954 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
3955 * uses the IDirect3DDevice7 interface with D3D7 lights.
3957 * Versions 1, 2 and 3
3960 * light: Address to store the new interface pointer
3961 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3966 * DDERR_OUTOFMEMORY if memory allocation failed
3967 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3969 *****************************************************************************/
3970 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
,
3971 IUnknown
*outer_unknown
)
3973 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3974 struct d3d_light
*object
;
3976 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3979 return CLASS_E_NOAGGREGATION
;
3981 if (!(object
= heap_alloc_zero(sizeof(*object
))))
3983 ERR("Failed to allocate light memory.\n");
3984 return DDERR_OUTOFMEMORY
;
3987 d3d_light_init(object
, ddraw
);
3989 TRACE("Created light %p.\n", object
);
3990 *light
= &object
->IDirect3DLight_iface
;
3995 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3997 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3999 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4001 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
4004 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
4006 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4008 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4010 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
4013 /*****************************************************************************
4014 * IDirect3D3::CreateMaterial
4016 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
4017 * and older versions. The IDirect3DMaterial implementation wraps its
4018 * functionality to IDirect3DDevice7::SetMaterial and friends.
4020 * Versions 1, 2 and 3
4023 * material: Address to store the new interface's pointer to
4024 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4029 * DDERR_OUTOFMEMORY if memory allocation failed
4030 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4032 *****************************************************************************/
4033 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
,
4034 IUnknown
*outer_unknown
)
4036 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4037 struct d3d_material
*object
;
4039 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4041 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4043 object
= d3d_material_create(ddraw
);
4046 ERR("Failed to allocate material memory.\n");
4047 return DDERR_OUTOFMEMORY
;
4050 TRACE("Created material %p.\n", object
);
4051 *material
= &object
->IDirect3DMaterial3_iface
;
4056 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
,
4057 IUnknown
*outer_unknown
)
4059 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4060 struct d3d_material
*object
;
4062 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4064 object
= d3d_material_create(ddraw
);
4067 ERR("Failed to allocate material memory.\n");
4068 return DDERR_OUTOFMEMORY
;
4071 TRACE("Created material %p.\n", object
);
4072 *material
= &object
->IDirect3DMaterial2_iface
;
4077 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
,
4078 IUnknown
*outer_unknown
)
4080 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4081 struct d3d_material
*object
;
4083 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4085 object
= d3d_material_create(ddraw
);
4088 ERR("Failed to allocate material memory.\n");
4089 return DDERR_OUTOFMEMORY
;
4092 TRACE("Created material %p.\n", object
);
4093 *material
= &object
->IDirect3DMaterial_iface
;
4098 /*****************************************************************************
4099 * IDirect3D3::CreateViewport
4101 * Creates an IDirect3DViewport interface. This interface is used
4102 * by Direct3D and earlier versions for Viewport management. In Direct3D7
4103 * it has been replaced by a viewport structure and
4104 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
4105 * uses the IDirect3DDevice7 methods for its functionality
4108 * Viewport: Address to store the new interface pointer
4109 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4114 * DDERR_OUTOFMEMORY if memory allocation failed
4115 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4117 *****************************************************************************/
4118 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
,
4119 IUnknown
*outer_unknown
)
4121 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4122 struct d3d_viewport
*object
;
4124 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4126 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4128 if (!(object
= heap_alloc_zero(sizeof(*object
))))
4130 ERR("Failed to allocate viewport memory.\n");
4131 return DDERR_OUTOFMEMORY
;
4134 d3d_viewport_init(object
, ddraw
);
4136 TRACE("Created viewport %p.\n", object
);
4137 *viewport
= &object
->IDirect3DViewport3_iface
;
4142 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
4144 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4146 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4148 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4152 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
4154 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4156 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4158 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4162 static HRESULT
ddraw_find_device(struct ddraw
*ddraw
, const D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
,
4163 unsigned int guid_count
, const GUID
* const *guids
, DWORD device_desc_size
)
4165 struct ddraw_find_device_result_v1
4169 D3DDEVICEDESC_V1 hw_desc
;
4170 D3DDEVICEDESC_V1 sw_desc
;
4172 struct ddraw_find_device_result_v2
4176 D3DDEVICEDESC_V2 hw_desc
;
4177 D3DDEVICEDESC_V2 sw_desc
;
4179 D3DDEVICEDESC7 desc7
;
4180 D3DDEVICEDESC desc1
;
4184 TRACE("ddraw %p, fds %p, fdr %p, guid_count %u, guids %p, device_desc_size %lu.\n",
4185 ddraw
, fds
, fdr
, guid_count
, guids
, device_desc_size
);
4188 return DDERR_INVALIDPARAMS
;
4190 if (fds
->dwSize
!= sizeof(*fds
))
4192 WARN("Got invalid search structure size %lu.\n", fds
->dwSize
);
4193 return DDERR_INVALIDPARAMS
;
4196 if (fdr
->dwSize
!= sizeof(*fdr
) && fdr
->dwSize
!= sizeof(*fdr2
) && fdr
->dwSize
!= sizeof(*fdr1
))
4198 WARN("Got invalid result structure size %lu.\n", fdr
->dwSize
);
4199 return DDERR_INVALIDPARAMS
;
4202 if (fds
->dwFlags
& D3DFDS_COLORMODEL
)
4203 WARN("Ignoring colour model %#lx.\n", fds
->dcmColorModel
);
4205 if (fds
->dwFlags
& D3DFDS_GUID
)
4209 TRACE("Trying to match GUID %s.\n", debugstr_guid(&fds
->guid
));
4211 if ((ddraw
->flags
& DDRAW_NO3D
) && IsEqualGUID(&fds
->guid
, &IID_IDirect3DHALDevice
))
4213 WARN("HAL device not available without 3D support.\n");
4214 return DDERR_NOTFOUND
;
4217 for (i
= 0; i
< guid_count
; ++i
)
4219 if (IsEqualGUID(guids
[i
], &fds
->guid
))
4228 WARN("Failed to match GUID %s.\n", debugstr_guid(&fds
->guid
));
4229 return DDERR_NOTFOUND
;
4234 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &desc7
)))
4237 /* Now return our own GUID */
4238 ddraw_d3dcaps1_from_7(&desc1
, &desc7
);
4239 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4241 /* Note that "device_desc_size" doesn't necessarily have any relation to
4242 * the actual structure size. However, this matches the behaviour of
4243 * Windows since at least Windows 2000. */
4244 if (fdr
->dwSize
== sizeof(*fdr1
))
4246 fdr1
= (struct ddraw_find_device_result_v1
*)fdr
;
4247 memcpy(&fdr1
->hw_desc
, &desc1
, sizeof(fdr1
->hw_desc
));
4248 fdr1
->hw_desc
.dwSize
= device_desc_size
;
4249 memcpy(&fdr1
->sw_desc
, &desc1
, sizeof(fdr1
->sw_desc
));
4250 fdr1
->sw_desc
.dwSize
= device_desc_size
;
4252 else if (fdr
->dwSize
== sizeof(*fdr2
))
4254 fdr2
= (struct ddraw_find_device_result_v2
*)fdr
;
4255 memcpy(&fdr2
->hw_desc
, &desc1
, sizeof(fdr2
->hw_desc
));
4256 fdr2
->hw_desc
.dwSize
= device_desc_size
;
4257 memcpy(&fdr2
->sw_desc
, &desc1
, sizeof(fdr2
->sw_desc
));
4258 fdr2
->sw_desc
.dwSize
= device_desc_size
;
4262 fdr
->ddHwDesc
= desc1
;
4263 fdr
->ddHwDesc
.dwSize
= device_desc_size
;
4264 fdr
->ddSwDesc
= desc1
;
4265 fdr
->ddSwDesc
.dwSize
= device_desc_size
;
4268 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4273 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4275 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4276 static const GUID
* const guids
[] =
4278 &IID_D3DDEVICE_WineD3D
,
4279 &IID_IDirect3DHALDevice
,
4280 &IID_IDirect3DRGBDevice
,
4283 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4285 return ddraw_find_device(ddraw
, fds
, fdr
, ARRAY_SIZE(guids
), guids
, sizeof(D3DDEVICEDESC_V3
));
4288 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4290 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4291 static const GUID
* const guids
[] =
4293 &IID_D3DDEVICE_WineD3D
,
4294 &IID_IDirect3DHALDevice
,
4295 &IID_IDirect3DMMXDevice
,
4296 &IID_IDirect3DRGBDevice
,
4297 &IID_IDirect3DRampDevice
,
4300 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4302 return ddraw_find_device(ddraw
, fds
, fdr
, ARRAY_SIZE(guids
), guids
, sizeof(D3DDEVICEDESC_V2
));
4305 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4307 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4308 static const GUID
* const guids
[] =
4310 &IID_D3DDEVICE_WineD3D
,
4311 &IID_IDirect3DHALDevice
,
4312 &IID_IDirect3DRGBDevice
,
4313 &IID_IDirect3DRampDevice
,
4316 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4318 return ddraw_find_device(ddraw
, fds
, fdr
, ARRAY_SIZE(guids
), guids
, sizeof(D3DDEVICEDESC_V1
));
4321 /*****************************************************************************
4322 * IDirect3D7::CreateDevice
4324 * Creates an IDirect3DDevice7 interface.
4326 * Versions 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4327 * DirectDraw surfaces and are created with
4328 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4329 * create the device object and QueryInterfaces for IDirect3DDevice
4332 * refiid: IID of the device to create
4333 * Surface: Initial rendertarget
4334 * Device: Address to return the interface pointer
4338 * DDERR_OUTOFMEMORY if memory allocation failed
4339 * DDERR_INVALIDPARAMS if a device exists already
4341 *****************************************************************************/
4342 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4343 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4345 struct ddraw_surface
*target
= unsafe_impl_from_IDirectDrawSurface7(surface
);
4346 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4347 struct d3d_device
*object
;
4350 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4352 wined3d_mutex_lock();
4353 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, riid
, target
, (IUnknown
*)surface
, 7, &object
, NULL
)))
4355 *device
= &object
->IDirect3DDevice7_iface
;
4359 WARN("Failed to create device, hr %#lx.\n", hr
);
4362 wined3d_mutex_unlock();
4367 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4368 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4370 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface4(surface
);
4371 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4372 struct d3d_device
*device_impl
;
4375 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4376 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4379 return CLASS_E_NOAGGREGATION
;
4381 wined3d_mutex_lock();
4382 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, riid
, surface_impl
, (IUnknown
*)surface
, 3, &device_impl
, NULL
)))
4384 *device
= &device_impl
->IDirect3DDevice3_iface
;
4388 WARN("Failed to create device, hr %#lx.\n", hr
);
4391 wined3d_mutex_unlock();
4396 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4397 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4399 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface(surface
);
4400 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4401 struct d3d_device
*device_impl
;
4404 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4405 iface
, debugstr_guid(riid
), surface
, device
);
4407 wined3d_mutex_lock();
4408 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, riid
, surface_impl
, (IUnknown
*)surface
, 2, &device_impl
, NULL
)))
4410 *device
= &device_impl
->IDirect3DDevice2_iface
;
4414 WARN("Failed to create device, hr %#lx.\n", hr
);
4417 wined3d_mutex_unlock();
4422 /*****************************************************************************
4423 * IDirect3D7::CreateVertexBuffer
4425 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4431 * desc: Requested Vertex buffer properties
4432 * vertex_buffer: Address to return the interface pointer at
4433 * flags: Some flags, should be 0
4437 * DDERR_OUTOFMEMORY if memory allocation failed
4438 * DDERR_INVALIDPARAMS if desc or vertex_buffer is NULL
4440 *****************************************************************************/
4441 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4442 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4444 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4445 struct d3d_vertex_buffer
*object
;
4448 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#lx.\n",
4449 iface
, desc
, vertex_buffer
, flags
);
4451 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4453 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4456 TRACE("Created vertex buffer %p.\n", object
);
4457 *vertex_buffer
= &object
->IDirect3DVertexBuffer7_iface
;
4460 WARN("Failed to create vertex buffer, hr %#lx.\n", hr
);
4465 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4466 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4468 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4469 struct d3d_vertex_buffer
*object
;
4472 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#lx, outer_unknown %p.\n",
4473 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4476 return CLASS_E_NOAGGREGATION
;
4477 if (!vertex_buffer
|| !desc
)
4478 return DDERR_INVALIDPARAMS
;
4480 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4483 TRACE("Created vertex buffer %p.\n", object
);
4484 *vertex_buffer
= (IDirect3DVertexBuffer
*)&object
->IDirect3DVertexBuffer7_iface
;
4487 WARN("Failed to create vertex buffer, hr %#lx.\n", hr
);
4492 /*****************************************************************************
4493 * IDirect3D7::EnumZBufferFormats
4495 * Enumerates all supported Z buffer pixel formats
4501 * callback: callback to call for each pixel format
4502 * context: Pointer to pass back to the callback
4506 * DDERR_INVALIDPARAMS if callback is NULL
4508 *****************************************************************************/
4509 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4510 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4512 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4513 struct wined3d_display_mode mode
;
4514 enum wined3d_device_type type
;
4518 /* Order matters. Specifically, BattleZone II (full version) expects the
4519 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4520 static const enum wined3d_format_id formats
[] =
4522 WINED3DFMT_S1_UINT_D15_UNORM
,
4523 WINED3DFMT_D16_UNORM
,
4524 WINED3DFMT_X8D24_UNORM
,
4525 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4526 WINED3DFMT_D24_UNORM_S8_UINT
,
4527 WINED3DFMT_D32_UNORM
,
4530 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4531 iface
, debugstr_guid(device_iid
), callback
, context
);
4533 if (!callback
) return DDERR_INVALIDPARAMS
;
4535 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4536 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4537 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4539 TRACE("Asked for HAL device.\n");
4540 type
= WINED3D_DEVICE_TYPE_HAL
;
4542 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4543 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4545 TRACE("Asked for SW device.\n");
4546 type
= WINED3D_DEVICE_TYPE_SW
;
4548 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4550 TRACE("Asked for REF device.\n");
4551 type
= WINED3D_DEVICE_TYPE_REF
;
4553 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4555 TRACE("Asked for NULLREF device.\n");
4556 type
= WINED3D_DEVICE_TYPE_NULLREF
;
4560 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4561 type
= WINED3D_DEVICE_TYPE_HAL
;
4564 wined3d_mutex_lock();
4565 /* We need an adapter format from somewhere to please wined3d and WGL.
4566 * Use the current display mode. So far all cards offer the same depth
4567 * stencil format for all modes, but if some do not and applications do
4568 * not like that we'll have to find some workaround, like iterating over
4569 * all imaginable formats and collecting all the depth stencil formats we
4571 if (FAILED(hr
= wined3d_output_get_display_mode(ddraw
->wined3d_output
, &mode
, NULL
)))
4573 ERR("Failed to get display mode, hr %#lx.\n", hr
);
4574 wined3d_mutex_unlock();
4578 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
)
4580 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, ddraw
->wined3d_adapter
, type
,
4581 mode
.format_id
, 0, WINED3D_BIND_DEPTH_STENCIL
, WINED3D_RTYPE_TEXTURE_2D
, formats
[i
])))
4583 DDPIXELFORMAT pformat
;
4585 memset(&pformat
, 0, sizeof(pformat
));
4586 pformat
.dwSize
= sizeof(pformat
);
4587 ddrawformat_from_wined3dformat(&pformat
, formats
[i
]);
4589 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
4590 hr
= callback(&pformat
, context
);
4591 if (hr
!= DDENUMRET_OK
)
4593 TRACE("Format enumeration cancelled by application.\n");
4594 wined3d_mutex_unlock();
4600 /* Historically some windows drivers used dwZBufferBitDepth=24 for WINED3DFMT_X8D24_UNORM,
4601 * while others used dwZBufferBitDepth=32. In either case the pitch matches a 32 bits per
4602 * pixel format, so we use dwZBufferBitDepth=32. Some games expect 24. Windows Vista and
4603 * newer enumerate both versions, so we do the same(bug 22434) */
4604 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, ddraw
->wined3d_adapter
, type
, mode
.format_id
,
4605 0, WINED3D_BIND_DEPTH_STENCIL
, WINED3D_RTYPE_TEXTURE_2D
, WINED3DFMT_X8D24_UNORM
)))
4607 DDPIXELFORMAT x8d24
=
4609 sizeof(x8d24
), DDPF_ZBUFFER
, 0,
4610 {24}, {0x00000000}, {0x00ffffff}, {0x00000000}
4612 TRACE("Enumerating WINED3DFMT_X8D24_UNORM, dwZBufferBitDepth=24 version\n");
4613 callback(&x8d24
, context
);
4616 TRACE("End of enumeration.\n");
4618 wined3d_mutex_unlock();
4623 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
4624 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4626 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4628 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4629 iface
, debugstr_guid(device_iid
), callback
, context
);
4631 return d3d7_EnumZBufferFormats(&ddraw
->IDirect3D7_iface
, device_iid
, callback
, context
);
4634 /*****************************************************************************
4635 * IDirect3D7::EvictManagedTextures
4637 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
4638 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
4643 * D3D_OK, because it's a stub
4645 *****************************************************************************/
4646 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
4648 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4650 TRACE("iface %p!\n", iface
);
4652 wined3d_mutex_lock();
4653 if (ddraw
->flags
& DDRAW_D3D_INITIALIZED
)
4654 wined3d_device_evict_managed_resources(ddraw
->wined3d_device
);
4655 wined3d_mutex_unlock();
4660 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
4662 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4664 TRACE("iface %p.\n", iface
);
4666 return d3d7_EvictManagedTextures(&ddraw
->IDirect3D7_iface
);
4669 /*****************************************************************************
4670 * IDirectDraw7 VTable
4671 *****************************************************************************/
4672 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
4675 ddraw7_QueryInterface
,
4680 ddraw7_CreateClipper
,
4681 ddraw7_CreatePalette
,
4682 ddraw7_CreateSurface
,
4683 ddraw7_DuplicateSurface
,
4684 ddraw7_EnumDisplayModes
,
4685 ddraw7_EnumSurfaces
,
4686 ddraw7_FlipToGDISurface
,
4688 ddraw7_GetDisplayMode
,
4689 ddraw7_GetFourCCCodes
,
4690 ddraw7_GetGDISurface
,
4691 ddraw7_GetMonitorFrequency
,
4693 ddraw7_GetVerticalBlankStatus
,
4695 ddraw7_RestoreDisplayMode
,
4696 ddraw7_SetCooperativeLevel
,
4697 ddraw7_SetDisplayMode
,
4698 ddraw7_WaitForVerticalBlank
,
4700 ddraw7_GetAvailableVidMem
,
4702 ddraw7_GetSurfaceFromDC
,
4704 ddraw7_RestoreAllSurfaces
,
4705 ddraw7_TestCooperativeLevel
,
4706 ddraw7_GetDeviceIdentifier
,
4708 ddraw7_StartModeTest
,
4712 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
4715 ddraw4_QueryInterface
,
4720 ddraw4_CreateClipper
,
4721 ddraw4_CreatePalette
,
4722 ddraw4_CreateSurface
,
4723 ddraw4_DuplicateSurface
,
4724 ddraw4_EnumDisplayModes
,
4725 ddraw4_EnumSurfaces
,
4726 ddraw4_FlipToGDISurface
,
4728 ddraw4_GetDisplayMode
,
4729 ddraw4_GetFourCCCodes
,
4730 ddraw4_GetGDISurface
,
4731 ddraw4_GetMonitorFrequency
,
4733 ddraw4_GetVerticalBlankStatus
,
4735 ddraw4_RestoreDisplayMode
,
4736 ddraw4_SetCooperativeLevel
,
4737 ddraw4_SetDisplayMode
,
4738 ddraw4_WaitForVerticalBlank
,
4740 ddraw4_GetAvailableVidMem
,
4742 ddraw4_GetSurfaceFromDC
,
4744 ddraw4_RestoreAllSurfaces
,
4745 ddraw4_TestCooperativeLevel
,
4746 ddraw4_GetDeviceIdentifier
,
4749 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
4752 ddraw2_QueryInterface
,
4757 ddraw2_CreateClipper
,
4758 ddraw2_CreatePalette
,
4759 ddraw2_CreateSurface
,
4760 ddraw2_DuplicateSurface
,
4761 ddraw2_EnumDisplayModes
,
4762 ddraw2_EnumSurfaces
,
4763 ddraw2_FlipToGDISurface
,
4765 ddraw2_GetDisplayMode
,
4766 ddraw2_GetFourCCCodes
,
4767 ddraw2_GetGDISurface
,
4768 ddraw2_GetMonitorFrequency
,
4770 ddraw2_GetVerticalBlankStatus
,
4772 ddraw2_RestoreDisplayMode
,
4773 ddraw2_SetCooperativeLevel
,
4774 ddraw2_SetDisplayMode
,
4775 ddraw2_WaitForVerticalBlank
,
4777 ddraw2_GetAvailableVidMem
,
4780 /* Bad Mojo Redux expects this vtbl to be writable. */
4781 static struct IDirectDrawVtbl ddraw1_vtbl
=
4784 ddraw1_QueryInterface
,
4789 ddraw1_CreateClipper
,
4790 ddraw1_CreatePalette
,
4791 ddraw1_CreateSurface
,
4792 ddraw1_DuplicateSurface
,
4793 ddraw1_EnumDisplayModes
,
4794 ddraw1_EnumSurfaces
,
4795 ddraw1_FlipToGDISurface
,
4797 ddraw1_GetDisplayMode
,
4798 ddraw1_GetFourCCCodes
,
4799 ddraw1_GetGDISurface
,
4800 ddraw1_GetMonitorFrequency
,
4802 ddraw1_GetVerticalBlankStatus
,
4804 ddraw1_RestoreDisplayMode
,
4805 ddraw1_SetCooperativeLevel
,
4806 ddraw1_SetDisplayMode
,
4807 ddraw1_WaitForVerticalBlank
,
4810 static const struct IDirect3D7Vtbl d3d7_vtbl
=
4812 /* IUnknown methods */
4813 d3d7_QueryInterface
,
4816 /* IDirect3D7 methods */
4819 d3d7_CreateVertexBuffer
,
4820 d3d7_EnumZBufferFormats
,
4821 d3d7_EvictManagedTextures
4824 static const struct IDirect3D3Vtbl d3d3_vtbl
=
4826 /* IUnknown methods */
4827 d3d3_QueryInterface
,
4830 /* IDirect3D3 methods */
4833 d3d3_CreateMaterial
,
4834 d3d3_CreateViewport
,
4837 d3d3_CreateVertexBuffer
,
4838 d3d3_EnumZBufferFormats
,
4839 d3d3_EvictManagedTextures
4842 static const struct IDirect3D2Vtbl d3d2_vtbl
=
4844 /* IUnknown methods */
4845 d3d2_QueryInterface
,
4848 /* IDirect3D2 methods */
4851 d3d2_CreateMaterial
,
4852 d3d2_CreateViewport
,
4857 static const struct IDirect3DVtbl d3d1_vtbl
=
4859 /* IUnknown methods */
4860 d3d1_QueryInterface
,
4863 /* IDirect3D methods */
4867 d3d1_CreateMaterial
,
4868 d3d1_CreateViewport
,
4872 /*****************************************************************************
4875 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
4876 * if none was found.
4878 * This function is in ddraw.c and the DDraw object space because D3D7
4879 * vertex buffers are created using the IDirect3D interface to the ddraw
4880 * object, so they can be valid across D3D devices(theoretically. The ddraw
4881 * object also owns the wined3d device
4885 * fvf: Fvf to find the decl for
4888 * NULL in case of an error, the vertex declaration for the FVF otherwise.
4890 *****************************************************************************/
4891 struct wined3d_vertex_declaration
*ddraw_find_decl(struct ddraw
*This
, DWORD fvf
)
4893 struct wined3d_vertex_declaration
*pDecl
= NULL
;
4895 int p
, low
, high
; /* deliberately signed */
4896 struct FvfToDecl
*convertedDecls
= This
->decls
;
4898 TRACE("Searching for declaration for fvf %08lx... ", fvf
);
4901 high
= This
->numConvertedDecls
- 1;
4902 while(low
<= high
) {
4903 p
= (low
+ high
) >> 1;
4905 if(convertedDecls
[p
].fvf
== fvf
) {
4906 TRACE("found %p\n", convertedDecls
[p
].decl
);
4907 return convertedDecls
[p
].decl
;
4908 } else if(convertedDecls
[p
].fvf
< fvf
) {
4914 TRACE("not found. Creating and inserting at position %d.\n", low
);
4916 hr
= wined3d_vertex_declaration_create_from_fvf(This
->wined3d_device
,
4917 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
4918 if (hr
!= S_OK
) return NULL
;
4920 if (This
->declArraySize
== This
->numConvertedDecls
)
4922 unsigned int grow
= max(This
->declArraySize
/ 2, 8);
4924 if (!(convertedDecls
= heap_realloc(convertedDecls
,
4925 (This
->numConvertedDecls
+ grow
) * sizeof(*convertedDecls
))))
4927 wined3d_vertex_declaration_decref(pDecl
);
4930 This
->decls
= convertedDecls
;
4931 This
->declArraySize
+= grow
;
4934 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
4935 convertedDecls
[low
].decl
= pDecl
;
4936 convertedDecls
[low
].fvf
= fvf
;
4937 This
->numConvertedDecls
++;
4939 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
4943 static inline struct ddraw
*ddraw_from_device_parent(struct wined3d_device_parent
*device_parent
)
4945 return CONTAINING_RECORD(device_parent
, struct ddraw
, device_parent
);
4948 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
4949 struct wined3d_device
*device
)
4951 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
4954 /* This is run from device_process_message() in wined3d, we can't take the
4956 /* FIXME: We only get mode change notifications in exclusive mode, but we
4957 * should mark surfaces as lost on mode changes in DDSCL_NORMAL mode as well. */
4958 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
4960 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4961 struct wined3d_output_desc output_desc
;
4964 TRACE("device_parent %p.\n", device_parent
);
4966 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) || !ddraw
->swapchain_window
)
4968 TRACE("Nothing to resize.\n");
4972 if (FAILED(wined3d_output_get_desc(ddraw
->wined3d_output
, &output_desc
)))
4974 ERR("Failed to get output description.\n");
4978 r
= &output_desc
.desktop_rect
;
4979 TRACE("Resizing window %p to %s.\n", ddraw
->swapchain_window
, wine_dbgstr_rect(r
));
4981 if (!SetWindowPos(ddraw
->swapchain_window
, HWND_TOP
, r
->left
, r
->top
,
4982 r
->right
- r
->left
, r
->bottom
- r
->top
, SWP_SHOWWINDOW
| SWP_NOACTIVATE
))
4983 ERR("Failed to resize window.\n");
4985 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_OK
);
4988 static void CDECL
device_parent_activate(struct wined3d_device_parent
*device_parent
, BOOL activate
)
4990 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4992 TRACE("device_parent %p, activate %#x.\n", device_parent
, activate
);
4996 ddraw
->device_state
= DDRAW_DEVICE_STATE_LOST
;
4997 exclusive_window
= NULL
;
5001 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_LOST
);
5005 void ddraw_update_lost_surfaces(struct ddraw
*ddraw
)
5007 struct ddraw_surface
*surface
;
5009 /* Railroad Tycoon 2 tries to restore surfaces from within a
5010 * WM_QUERYNEWPALETTE message handler and expects it to succeed. We
5011 * haven't received the WM_ACTIVATEAPP message by that point, so the
5012 * device state is still DDRAW_DEVICE_STATE_LOST, even though we are in
5013 * the foreground. */
5014 if (ddraw
->device_state
== DDRAW_DEVICE_STATE_LOST
)
5016 HWND window
= ddraw
->focuswindow
? ddraw
->focuswindow
: ddraw
->dest_window
;
5018 if (window
&& GetForegroundWindow() == window
)
5019 ddraw
->device_state
= DDRAW_DEVICE_STATE_NOT_RESTORED
;
5022 if (ddraw
->device_state
!= DDRAW_DEVICE_STATE_NOT_RESTORED
)
5025 LIST_FOR_EACH_ENTRY(surface
, &ddraw
->surface_list
, struct ddraw_surface
, surface_list_entry
)
5027 surface
->is_lost
= ddraw_surface_can_be_lost(surface
);
5029 ddraw
->device_state
= DDRAW_DEVICE_STATE_OK
;
5032 static HRESULT CDECL
device_parent_texture_sub_resource_created(struct wined3d_device_parent
*device_parent
,
5033 enum wined3d_resource_type type
, struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
5034 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
5036 TRACE("device_parent %p, type %#x, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
5037 device_parent
, type
, wined3d_texture
, sub_resource_idx
, parent
, parent_ops
);
5040 *parent_ops
= &ddraw_null_wined3d_parent_ops
;
5045 static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops
=
5047 device_parent_wined3d_device_created
,
5048 device_parent_mode_changed
,
5049 device_parent_activate
,
5050 device_parent_texture_sub_resource_created
,
5053 HRESULT
ddraw_init(struct ddraw
*ddraw
, DWORD flags
, enum wined3d_device_type device_type
)
5055 struct wined3d_caps caps
;
5058 static const enum wined3d_feature_level feature_levels
[] =
5060 WINED3D_FEATURE_LEVEL_7
,
5061 WINED3D_FEATURE_LEVEL_6
,
5062 WINED3D_FEATURE_LEVEL_5
,
5065 ddraw
->IDirectDraw7_iface
.lpVtbl
= &ddraw7_vtbl
;
5066 ddraw
->IDirectDraw_iface
.lpVtbl
= &ddraw1_vtbl
;
5067 ddraw
->IDirectDraw2_iface
.lpVtbl
= &ddraw2_vtbl
;
5068 ddraw
->IDirectDraw4_iface
.lpVtbl
= &ddraw4_vtbl
;
5069 ddraw
->IDirect3D_iface
.lpVtbl
= &d3d1_vtbl
;
5070 ddraw
->IDirect3D2_iface
.lpVtbl
= &d3d2_vtbl
;
5071 ddraw
->IDirect3D3_iface
.lpVtbl
= &d3d3_vtbl
;
5072 ddraw
->IDirect3D7_iface
.lpVtbl
= &d3d7_vtbl
;
5073 ddraw
->device_parent
.ops
= &ddraw_wined3d_device_parent_ops
;
5074 ddraw
->state_parent
.ops
= &ddraw_swapchain_state_parent_ops
;
5075 ddraw
->numIfaces
= 1;
5078 flags
|= DDRAW_WINED3D_FLAGS
;
5079 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
5081 flags
|= WINED3D_NO3D
;
5082 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
5084 WARN("Failed to create a wined3d object.\n");
5089 if (!(ddraw
->wined3d_adapter
= wined3d_get_adapter(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
)))
5091 WARN("Failed to get the default wined3d adapter.\n");
5092 wined3d_decref(ddraw
->wined3d
);
5096 if (!(ddraw
->wined3d_output
= wined3d_adapter_get_output(ddraw
->wined3d_adapter
, 0)))
5098 WARN("Failed to get the default wined3d output.\n");
5099 wined3d_decref(ddraw
->wined3d
);
5103 if (FAILED(hr
= wined3d_get_device_caps(ddraw
->wined3d_adapter
, device_type
, &caps
)))
5105 ERR("Failed to get device caps, hr %#lx.\n", hr
);
5106 wined3d_decref(ddraw
->wined3d
);
5110 if (!(caps
.ddraw_caps
.caps
& WINEDDCAPS_3D
))
5112 WARN("Created a wined3d object without 3D support.\n");
5113 ddraw
->flags
|= DDRAW_NO3D
;
5116 if (FAILED(hr
= wined3d_device_create(ddraw
->wined3d
, ddraw
->wined3d_adapter
, device_type
,
5117 NULL
, 0, DDRAW_STRIDE_ALIGNMENT
, feature_levels
, ARRAY_SIZE(feature_levels
),
5118 &ddraw
->device_parent
, &ddraw
->wined3d_device
)))
5120 WARN("Failed to create a wined3d device, hr %#lx.\n", hr
);
5121 wined3d_decref(ddraw
->wined3d
);
5124 ddraw
->immediate_context
= wined3d_device_get_immediate_context(ddraw
->wined3d_device
);
5126 list_init(&ddraw
->surface_list
);
5128 if (FAILED(hr
= wined3d_stateblock_create(ddraw
->wined3d_device
, NULL
, WINED3D_SBT_PRIMARY
, &ddraw
->state
)))
5130 ERR("Failed to create the primary stateblock, hr %#lx.\n", hr
);
5131 wined3d_device_decref(ddraw
->wined3d_device
);
5132 wined3d_decref(ddraw
->wined3d
);
5135 ddraw
->stateblock_state
= wined3d_stateblock_get_state(ddraw
->state
);