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
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
26 #include "ddraw_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
30 static struct wined3d_display_mode original_mode
;
31 static const struct ddraw
*exclusive_ddraw
;
32 static BOOL restore_mode
;
34 /* Device identifier. Don't relay it to WineD3D */
35 static const DDDEVICEIDENTIFIER2 deviceidentifier
=
39 { { 0x00010001, 0x00010001 } },
41 /* a8373c10-7ac4-4deb-849a-009844d08b2d */
42 {0xa8373c10,0x7ac4,0x4deb, {0x84,0x9a,0x00,0x98,0x44,0xd0,0x8b,0x2d}},
46 static struct enum_device_entry
48 char interface_name
[100];
49 char device_name
[100];
50 const GUID
*device_guid
;
55 "WINE Direct3D7 Hardware Transform and Lighting acceleration using WineD3D",
57 &IID_IDirect3DTnLHalDevice
,
62 "WINE Direct3D7 Hardware acceleration using WineD3D",
64 &IID_IDirect3DHALDevice
,
69 "WINE Direct3D7 RGB Software Emulation using WineD3D",
71 &IID_IDirect3DRGBDevice
,
75 static void STDMETHODCALLTYPE
ddraw_null_wined3d_object_destroyed(void *parent
) {}
77 const struct wined3d_parent_ops ddraw_null_wined3d_parent_ops
=
79 ddraw_null_wined3d_object_destroyed
,
82 static inline struct ddraw
*impl_from_IDirectDraw(IDirectDraw
*iface
)
84 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw_iface
);
87 static inline struct ddraw
*impl_from_IDirectDraw2(IDirectDraw2
*iface
)
89 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw2_iface
);
92 static inline struct ddraw
*impl_from_IDirectDraw4(IDirectDraw4
*iface
)
94 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw4_iface
);
97 static inline struct ddraw
*impl_from_IDirectDraw7(IDirectDraw7
*iface
)
99 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw7_iface
);
102 static inline struct ddraw
*impl_from_IDirect3D(IDirect3D
*iface
)
104 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D_iface
);
107 static inline struct ddraw
*impl_from_IDirect3D2(IDirect3D2
*iface
)
109 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D2_iface
);
112 static inline struct ddraw
*impl_from_IDirect3D3(IDirect3D3
*iface
)
114 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D3_iface
);
117 static inline struct ddraw
*impl_from_IDirect3D7(IDirect3D7
*iface
)
119 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D7_iface
);
122 /*****************************************************************************
124 *****************************************************************************/
126 /*****************************************************************************
127 * IDirectDraw7::QueryInterface
129 * Queries different interfaces of the DirectDraw object. It can return
130 * IDirectDraw interfaces in version 1, 2, 4 and 7, and IDirect3D interfaces
131 * in version 1, 2, 3 and 7. An IDirect3DDevice can be created with this
133 * The returned interface is AddRef()-ed before it's returned
135 * Used for version 1, 2, 4 and 7
138 * refiid: Interface ID asked for
139 * obj: Used to return the interface pointer
142 * S_OK if an interface was found
143 * E_NOINTERFACE if the requested interface wasn't found
145 *****************************************************************************/
146 static HRESULT WINAPI
ddraw7_QueryInterface(IDirectDraw7
*iface
, REFIID refiid
, void **obj
)
148 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
150 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(refiid
), obj
);
152 /* Can change surface impl type */
153 wined3d_mutex_lock();
155 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
160 wined3d_mutex_unlock();
161 return DDERR_INVALIDPARAMS
;
164 /* Check DirectDraw Interfaces */
165 if ( IsEqualGUID( &IID_IUnknown
, refiid
) ||
166 IsEqualGUID( &IID_IDirectDraw7
, refiid
) )
168 *obj
= &This
->IDirectDraw7_iface
;
169 TRACE("(%p) Returning IDirectDraw7 interface at %p\n", This
, *obj
);
171 else if ( IsEqualGUID( &IID_IDirectDraw4
, refiid
) )
173 *obj
= &This
->IDirectDraw4_iface
;
174 TRACE("(%p) Returning IDirectDraw4 interface at %p\n", This
, *obj
);
176 else if ( IsEqualGUID( &IID_IDirectDraw3
, refiid
) )
178 /* This Interface exists in ddrawex.dll, it is implemented in a wrapper */
179 WARN("IDirectDraw3 is not valid in ddraw.dll\n");
181 wined3d_mutex_unlock();
182 return E_NOINTERFACE
;
184 else if ( IsEqualGUID( &IID_IDirectDraw2
, refiid
) )
186 *obj
= &This
->IDirectDraw2_iface
;
187 TRACE("(%p) Returning IDirectDraw2 interface at %p\n", This
, *obj
);
189 else if ( IsEqualGUID( &IID_IDirectDraw
, refiid
) )
191 *obj
= &This
->IDirectDraw_iface
;
192 TRACE("(%p) Returning IDirectDraw interface at %p\n", This
, *obj
);
196 * The refcount unit test revealed that an IDirect3D7 interface can only be queried
197 * from a DirectDraw object that was created as an IDirectDraw7 interface. No idea
198 * who had this idea and why. The older interfaces can query and IDirect3D version
199 * because they are all created as IDirectDraw(1). This isn't really crucial behavior,
200 * and messy to implement with the common creation function, so it has been left out here.
202 else if ( IsEqualGUID( &IID_IDirect3D
, refiid
) ||
203 IsEqualGUID( &IID_IDirect3D2
, refiid
) ||
204 IsEqualGUID( &IID_IDirect3D3
, refiid
) ||
205 IsEqualGUID( &IID_IDirect3D7
, refiid
) )
207 /* Check the surface implementation */
208 if (DefaultSurfaceType
!= WINED3D_SURFACE_TYPE_OPENGL
)
210 WARN("The app requests a Direct3D interface, but non-opengl surfaces where set in winecfg\n");
211 /* Do not abort here, only reject 3D Device creation */
214 if ( IsEqualGUID( &IID_IDirect3D
, refiid
) )
216 This
->d3dversion
= 1;
217 *obj
= &This
->IDirect3D_iface
;
218 TRACE(" returning Direct3D interface at %p.\n", *obj
);
220 else if ( IsEqualGUID( &IID_IDirect3D2
, refiid
) )
222 This
->d3dversion
= 2;
223 *obj
= &This
->IDirect3D2_iface
;
224 TRACE(" returning Direct3D2 interface at %p.\n", *obj
);
226 else if ( IsEqualGUID( &IID_IDirect3D3
, refiid
) )
228 This
->d3dversion
= 3;
229 *obj
= &This
->IDirect3D3_iface
;
230 TRACE(" returning Direct3D3 interface at %p.\n", *obj
);
232 else if(IsEqualGUID( &IID_IDirect3D7
, refiid
))
234 This
->d3dversion
= 7;
235 *obj
= &This
->IDirect3D7_iface
;
236 TRACE(" returning Direct3D7 interface at %p.\n", *obj
);
239 /* Unknown interface */
242 ERR("(%p)->(%s, %p): No interface found\n", This
, debugstr_guid(refiid
), obj
);
243 wined3d_mutex_unlock();
244 return E_NOINTERFACE
;
247 IUnknown_AddRef( (IUnknown
*) *obj
);
248 wined3d_mutex_unlock();
253 static HRESULT WINAPI
ddraw4_QueryInterface(IDirectDraw4
*iface
, REFIID riid
, void **object
)
255 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
257 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
259 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
262 static HRESULT WINAPI
ddraw2_QueryInterface(IDirectDraw2
*iface
, REFIID riid
, void **object
)
264 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
266 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
268 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
271 static HRESULT WINAPI
ddraw1_QueryInterface(IDirectDraw
*iface
, REFIID riid
, void **object
)
273 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
275 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
277 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
280 static HRESULT WINAPI
d3d7_QueryInterface(IDirect3D7
*iface
, REFIID riid
, void **object
)
282 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
284 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
286 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
289 static HRESULT WINAPI
d3d3_QueryInterface(IDirect3D3
*iface
, REFIID riid
, void **object
)
291 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
293 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
295 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
298 static HRESULT WINAPI
d3d2_QueryInterface(IDirect3D2
*iface
, REFIID riid
, void **object
)
300 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
302 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
304 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
307 static HRESULT WINAPI
d3d1_QueryInterface(IDirect3D
*iface
, REFIID riid
, void **object
)
309 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
311 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
313 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
316 /*****************************************************************************
317 * IDirectDraw7::AddRef
319 * Increases the interfaces refcount, basically
321 * DDraw refcounting is a bit tricky. The different DirectDraw interface
322 * versions have individual refcounts, but the IDirect3D interfaces do not.
323 * All interfaces are from one object, that means calling QueryInterface on an
324 * IDirectDraw7 interface for an IDirectDraw4 interface does not create a new
327 * That means all AddRef and Release implementations of IDirectDrawX work
328 * with their own counter, and IDirect3DX::AddRef thunk to IDirectDraw (1),
329 * except of IDirect3D7 which thunks to IDirectDraw7
331 * Returns: The new refcount
333 *****************************************************************************/
334 static ULONG WINAPI
ddraw7_AddRef(IDirectDraw7
*iface
)
336 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
337 ULONG ref
= InterlockedIncrement(&This
->ref7
);
339 TRACE("%p increasing refcount to %u.\n", This
, ref
);
341 if(ref
== 1) InterlockedIncrement(&This
->numIfaces
);
346 static ULONG WINAPI
ddraw4_AddRef(IDirectDraw4
*iface
)
348 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
349 ULONG ref
= InterlockedIncrement(&This
->ref4
);
351 TRACE("%p increasing refcount to %u.\n", This
, ref
);
353 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
358 static ULONG WINAPI
ddraw2_AddRef(IDirectDraw2
*iface
)
360 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
361 ULONG ref
= InterlockedIncrement(&This
->ref2
);
363 TRACE("%p increasing refcount to %u.\n", This
, ref
);
365 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
370 static ULONG WINAPI
ddraw1_AddRef(IDirectDraw
*iface
)
372 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
373 ULONG ref
= InterlockedIncrement(&This
->ref1
);
375 TRACE("%p increasing refcount to %u.\n", This
, ref
);
377 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
382 static ULONG WINAPI
d3d7_AddRef(IDirect3D7
*iface
)
384 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
386 TRACE("iface %p.\n", iface
);
388 return ddraw7_AddRef(&This
->IDirectDraw7_iface
);
391 static ULONG WINAPI
d3d3_AddRef(IDirect3D3
*iface
)
393 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
395 TRACE("iface %p.\n", iface
);
397 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
400 static ULONG WINAPI
d3d2_AddRef(IDirect3D2
*iface
)
402 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
404 TRACE("iface %p.\n", iface
);
406 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
409 static ULONG WINAPI
d3d1_AddRef(IDirect3D
*iface
)
411 struct ddraw
*This
= impl_from_IDirect3D(iface
);
413 TRACE("iface %p.\n", iface
);
415 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
418 void ddraw_destroy_swapchain(struct ddraw
*ddraw
)
420 TRACE("Destroying the swapchain.\n");
422 wined3d_swapchain_decref(ddraw
->wined3d_swapchain
);
423 ddraw
->wined3d_swapchain
= NULL
;
425 if (DefaultSurfaceType
== WINED3D_SURFACE_TYPE_OPENGL
)
429 for (i
= 0; i
< ddraw
->numConvertedDecls
; ++i
)
431 wined3d_vertex_declaration_decref(ddraw
->decls
[i
].decl
);
433 HeapFree(GetProcessHeap(), 0, ddraw
->decls
);
434 ddraw
->numConvertedDecls
= 0;
436 if (FAILED(wined3d_device_uninit_3d(ddraw
->wined3d_device
)))
438 ERR("Failed to uninit 3D.\n");
442 /* Free the d3d window if one was created. */
443 if (ddraw
->d3d_window
&& ddraw
->d3d_window
!= ddraw
->dest_window
)
445 TRACE("Destroying the hidden render window %p.\n", ddraw
->d3d_window
);
446 DestroyWindow(ddraw
->d3d_window
);
447 ddraw
->d3d_window
= 0;
451 ddraw
->d3d_initialized
= FALSE
;
455 wined3d_device_uninit_gdi(ddraw
->wined3d_device
);
458 ddraw_set_swapchain_window(ddraw
, NULL
);
460 TRACE("Swapchain destroyed.\n");
463 /*****************************************************************************
466 * Destroys a ddraw object if all refcounts are 0. This is to share code
467 * between the IDirectDrawX::Release functions
470 * This: DirectDraw object to destroy
472 *****************************************************************************/
473 static void ddraw_destroy(struct ddraw
*This
)
475 IDirectDraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, NULL
, DDSCL_NORMAL
);
476 IDirectDraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
478 /* Destroy the device window if we created one */
479 if(This
->devicewindow
!= 0)
481 TRACE(" (%p) Destroying the device window %p\n", This
, This
->devicewindow
);
482 DestroyWindow(This
->devicewindow
);
483 This
->devicewindow
= 0;
486 wined3d_mutex_lock();
487 list_remove(&This
->ddraw_list_entry
);
488 wined3d_mutex_unlock();
490 if (This
->wined3d_swapchain
)
491 ddraw_destroy_swapchain(This
);
492 wined3d_device_decref(This
->wined3d_device
);
493 wined3d_decref(This
->wined3d
);
495 /* Now free the object */
496 HeapFree(GetProcessHeap(), 0, This
);
499 /*****************************************************************************
500 * IDirectDraw7::Release
502 * Decreases the refcount. If the refcount falls to 0, the object is destroyed
504 * Returns: The new refcount
505 *****************************************************************************/
506 static ULONG WINAPI
ddraw7_Release(IDirectDraw7
*iface
)
508 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
509 ULONG ref
= InterlockedDecrement(&This
->ref7
);
511 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
513 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
519 static ULONG WINAPI
ddraw4_Release(IDirectDraw4
*iface
)
521 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
522 ULONG ref
= InterlockedDecrement(&This
->ref4
);
524 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
526 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
532 static ULONG WINAPI
ddraw2_Release(IDirectDraw2
*iface
)
534 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
535 ULONG ref
= InterlockedDecrement(&This
->ref2
);
537 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
539 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
545 static ULONG WINAPI
ddraw1_Release(IDirectDraw
*iface
)
547 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
548 ULONG ref
= InterlockedDecrement(&This
->ref1
);
550 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
552 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
558 static ULONG WINAPI
d3d7_Release(IDirect3D7
*iface
)
560 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
562 TRACE("iface %p.\n", iface
);
564 return ddraw7_Release(&This
->IDirectDraw7_iface
);
567 static ULONG WINAPI
d3d3_Release(IDirect3D3
*iface
)
569 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
571 TRACE("iface %p.\n", iface
);
573 return ddraw1_Release(&This
->IDirectDraw_iface
);
576 static ULONG WINAPI
d3d2_Release(IDirect3D2
*iface
)
578 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
580 TRACE("iface %p.\n", iface
);
582 return ddraw1_Release(&This
->IDirectDraw_iface
);
585 static ULONG WINAPI
d3d1_Release(IDirect3D
*iface
)
587 struct ddraw
*This
= impl_from_IDirect3D(iface
);
589 TRACE("iface %p.\n", iface
);
591 return ddraw1_Release(&This
->IDirectDraw_iface
);
594 /*****************************************************************************
595 * IDirectDraw methods
596 *****************************************************************************/
598 static HRESULT
ddraw_set_focus_window(struct ddraw
*ddraw
, HWND window
)
600 /* FIXME: This looks wrong, exclusive mode should imply a destination
602 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) && ddraw
->dest_window
)
604 TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET.\n");
605 return DDERR_HWNDALREADYSET
;
608 ddraw
->focuswindow
= window
;
610 /* Use the focus window for drawing too. */
611 ddraw
->dest_window
= ddraw
->focuswindow
;
616 static HRESULT
ddraw_attach_d3d_device(struct ddraw
*ddraw
,
617 struct wined3d_swapchain_desc
*swapchain_desc
)
619 HWND window
= swapchain_desc
->device_window
;
622 TRACE("ddraw %p.\n", ddraw
);
624 if (!window
|| window
== GetDesktopWindow())
626 window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "Hidden D3D Window",
627 WS_DISABLED
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
628 NULL
, NULL
, NULL
, NULL
);
631 ERR("Failed to create window, last error %#x.\n", GetLastError());
635 ShowWindow(window
, SW_HIDE
); /* Just to be sure */
636 WARN("No window for the Direct3DDevice, created hidden window %p.\n", window
);
638 swapchain_desc
->device_window
= window
;
642 TRACE("Using existing window %p for Direct3D rendering.\n", window
);
644 ddraw
->d3d_window
= window
;
646 /* Set this NOW, otherwise creating the depth stencil surface will cause a
647 * recursive loop until ram or emulated video memory is full. */
648 ddraw
->d3d_initialized
= TRUE
;
649 hr
= wined3d_device_init_3d(ddraw
->wined3d_device
, swapchain_desc
);
652 ddraw
->d3d_initialized
= FALSE
;
656 ddraw
->declArraySize
= 2;
657 ddraw
->decls
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ddraw
->decls
) * ddraw
->declArraySize
);
660 ERR("Error allocating an array for the converted vertex decls.\n");
661 ddraw
->declArraySize
= 0;
662 hr
= wined3d_device_uninit_3d(ddraw
->wined3d_device
);
663 return E_OUTOFMEMORY
;
666 TRACE("Successfully initialized 3D.\n");
671 static HRESULT
ddraw_create_swapchain(struct ddraw
*ddraw
, HWND window
, BOOL windowed
)
673 struct wined3d_swapchain_desc swapchain_desc
;
674 struct wined3d_display_mode mode
;
675 HRESULT hr
= WINED3D_OK
;
677 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
679 ERR("Failed to get display mode.\n");
683 memset(&swapchain_desc
, 0, sizeof(swapchain_desc
));
684 swapchain_desc
.backbuffer_width
= mode
.width
;
685 swapchain_desc
.backbuffer_height
= mode
.height
;
686 swapchain_desc
.backbuffer_format
= mode
.format_id
;
687 swapchain_desc
.swap_effect
= WINED3D_SWAP_EFFECT_COPY
;
688 swapchain_desc
.device_window
= window
;
689 swapchain_desc
.windowed
= windowed
;
691 if (DefaultSurfaceType
== WINED3D_SURFACE_TYPE_OPENGL
)
692 hr
= ddraw_attach_d3d_device(ddraw
, &swapchain_desc
);
694 hr
= wined3d_device_init_gdi(ddraw
->wined3d_device
, &swapchain_desc
);
698 ERR("Failed to create swapchain, hr %#x.\n", hr
);
702 if (!(ddraw
->wined3d_swapchain
= wined3d_device_get_swapchain(ddraw
->wined3d_device
, 0)))
704 ERR("Failed to get swapchain.\n");
705 return DDERR_INVALIDPARAMS
;
708 wined3d_swapchain_incref(ddraw
->wined3d_swapchain
);
709 ddraw_set_swapchain_window(ddraw
, window
);
714 /*****************************************************************************
715 * IDirectDraw7::SetCooperativeLevel
717 * Sets the cooperative level for the DirectDraw object, and the window
718 * assigned to it. The cooperative level determines the general behavior
719 * of the DirectDraw application
721 * Warning: This is quite tricky, as it's not really documented which
722 * cooperative levels can be combined with each other. If a game fails
723 * after this function, try to check the cooperative levels passed on
724 * Windows, and if it returns something different.
726 * If you think that this function caused the failure because it writes a
727 * fixme, be sure to run again with a +ddraw trace.
729 * What is known about cooperative levels (See the ddraw modes test):
730 * DDSCL_EXCLUSIVE and DDSCL_FULLSCREEN must be used with each other
731 * DDSCL_NORMAL is not compatible with DDSCL_EXCLUSIVE or DDSCL_FULLSCREEN
732 * DDSCL_SETFOCUSWINDOW can be passed only in DDSCL_NORMAL mode, but after that
733 * DDSCL_FULLSCREEN can be activated
734 * DDSCL_SETFOCUSWINDOW may only be used with DDSCL_NOWINDOWCHANGES
736 * Handled flags: DDSCL_NORMAL, DDSCL_FULLSCREEN, DDSCL_EXCLUSIVE,
737 * DDSCL_SETFOCUSWINDOW (partially),
738 * DDSCL_MULTITHREADED (work in progress)
740 * Unhandled flags, which should be implemented
741 * DDSCL_SETDEVICEWINDOW: Sets a window specially used for rendering (I don't
742 * expect any difference to a normal window for wine)
743 * DDSCL_CREATEDEVICEWINDOW: Tells ddraw to create its own window for
744 * rendering (Possible test case: Half-Life)
746 * Unsure about these: DDSCL_FPUSETUP DDSCL_FPURESERVE
748 * These don't seem very important for wine:
749 * DDSCL_ALLOWREBOOT, DDSCL_NOWINDOWCHANGES, DDSCL_ALLOWMODEX
752 * DD_OK if the cooperative level was set successfully
753 * DDERR_INVALIDPARAMS if the passed cooperative level combination is invalid
754 * DDERR_HWNDALREADYSET if DDSCL_SETFOCUSWINDOW is passed in exclusive mode
755 * (Probably others too, have to investigate)
757 *****************************************************************************/
758 static HRESULT WINAPI
ddraw7_SetCooperativeLevel(IDirectDraw7
*iface
, HWND hwnd
, DWORD cooplevel
)
760 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
761 struct wined3d_surface
*rt
= NULL
, *ds
= NULL
;
762 struct wined3d_stateblock
*stateblock
;
763 BOOL restore_state
= FALSE
;
767 TRACE("iface %p, window %p, flags %#x.\n", iface
, hwnd
, cooplevel
);
768 DDRAW_dump_cooperativelevel(cooplevel
);
770 wined3d_mutex_lock();
772 /* Get the old window */
773 window
= This
->dest_window
;
775 /* Tests suggest that we need one of them: */
776 if(!(cooplevel
& (DDSCL_SETFOCUSWINDOW
|
780 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
781 wined3d_mutex_unlock();
782 return DDERR_INVALIDPARAMS
;
785 if ((cooplevel
& DDSCL_CREATEDEVICEWINDOW
) && !(cooplevel
& DDSCL_EXCLUSIVE
))
787 WARN("DDSCL_CREATEDEVICEWINDOW requires DDSCL_EXCLUSIVE.\n");
788 wined3d_mutex_unlock();
789 return DDERR_INVALIDPARAMS
;
792 /* Handle those levels first which set various hwnds */
793 if ((cooplevel
& DDSCL_SETFOCUSWINDOW
) && !(cooplevel
& DDSCL_CREATEDEVICEWINDOW
))
795 /* This isn't compatible with a lot of flags */
796 if (cooplevel
& (DDSCL_MULTITHREADED
801 | DDSCL_SETDEVICEWINDOW
806 WARN("Called with incompatible flags, returning DDERR_INVALIDPARAMS.\n");
807 wined3d_mutex_unlock();
808 return DDERR_INVALIDPARAMS
;
811 hr
= ddraw_set_focus_window(This
, hwnd
);
812 wined3d_mutex_unlock();
816 if (cooplevel
& DDSCL_EXCLUSIVE
)
818 if (!(cooplevel
& DDSCL_FULLSCREEN
) || !(hwnd
|| (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)))
820 WARN("DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN and a window.\n");
821 wined3d_mutex_unlock();
822 return DDERR_INVALIDPARAMS
;
825 if (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)
829 if (!This
->focuswindow
&& !(cooplevel
& DDSCL_SETFOCUSWINDOW
))
831 WARN("No focus window set.\n");
832 wined3d_mutex_unlock();
833 return DDERR_NOFOCUSWINDOW
;
836 device_window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "DirectDrawDeviceWnd",
837 WS_POPUP
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
838 NULL
, NULL
, NULL
, NULL
);
841 ERR("Failed to create window, last error %#x.\n", GetLastError());
842 wined3d_mutex_unlock();
846 ShowWindow(device_window
, SW_SHOW
);
847 TRACE("Created a device window %p.\n", device_window
);
849 /* Native apparently leaks the created device window if setting the
850 * focus window below fails. */
851 This
->cooperative_level
|= DDSCL_CREATEDEVICEWINDOW
;
852 This
->devicewindow
= device_window
;
854 if (cooplevel
& DDSCL_SETFOCUSWINDOW
)
858 wined3d_mutex_unlock();
862 if (FAILED(hr
= ddraw_set_focus_window(This
, hwnd
)))
864 wined3d_mutex_unlock();
869 hwnd
= device_window
;
874 if (This
->cooperative_level
& DDSCL_CREATEDEVICEWINDOW
)
875 DestroyWindow(This
->devicewindow
);
876 This
->devicewindow
= NULL
;
877 This
->focuswindow
= NULL
;
880 if ((This
->cooperative_level
& DDSCL_EXCLUSIVE
)
881 && (hwnd
!= window
|| !(cooplevel
& DDSCL_EXCLUSIVE
)))
882 wined3d_device_release_focus_window(This
->wined3d_device
);
884 if ((cooplevel
& DDSCL_FULLSCREEN
) != (This
->cooperative_level
& DDSCL_FULLSCREEN
) || hwnd
!= window
)
886 if (This
->cooperative_level
& DDSCL_FULLSCREEN
)
887 wined3d_device_restore_fullscreen_window(This
->wined3d_device
, window
);
889 if (cooplevel
& DDSCL_FULLSCREEN
)
891 struct wined3d_display_mode display_mode
;
893 wined3d_get_adapter_display_mode(This
->wined3d
, WINED3DADAPTER_DEFAULT
, &display_mode
, NULL
);
894 wined3d_device_setup_fullscreen_window(This
->wined3d_device
, hwnd
,
895 display_mode
.width
, display_mode
.height
);
899 if ((cooplevel
& DDSCL_EXCLUSIVE
)
900 && (hwnd
!= window
|| !(This
->cooperative_level
& DDSCL_EXCLUSIVE
)))
902 hr
= wined3d_device_acquire_focus_window(This
->wined3d_device
, hwnd
);
905 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
906 wined3d_mutex_unlock();
911 /* Don't override focus windows or private device windows */
912 if (hwnd
&& !This
->focuswindow
&& !This
->devicewindow
&& (hwnd
!= window
))
913 This
->dest_window
= hwnd
;
915 if (cooplevel
& DDSCL_MULTITHREADED
&& !(This
->cooperative_level
& DDSCL_MULTITHREADED
))
916 wined3d_device_set_multithreaded(This
->wined3d_device
);
918 if (This
->wined3d_swapchain
)
920 if (DefaultSurfaceType
!= WINED3D_SURFACE_TYPE_GDI
)
922 restore_state
= TRUE
;
924 if (FAILED(hr
= wined3d_stateblock_create(This
->wined3d_device
, WINED3D_SBT_ALL
, &stateblock
)))
926 ERR("Failed to create stateblock, hr %#x.\n", hr
);
927 wined3d_mutex_unlock();
931 wined3d_stateblock_capture(stateblock
);
932 rt
= wined3d_device_get_render_target(This
->wined3d_device
, 0);
933 if (rt
== This
->wined3d_frontbuffer
)
936 wined3d_surface_incref(rt
);
938 if ((ds
= wined3d_device_get_depth_stencil(This
->wined3d_device
)))
939 wined3d_surface_incref(ds
);
942 ddraw_destroy_swapchain(This
);
945 if (FAILED(hr
= ddraw_create_swapchain(This
, This
->dest_window
, !(cooplevel
& DDSCL_FULLSCREEN
))))
946 ERR("Failed to create swapchain, hr %#x.\n", hr
);
952 wined3d_device_set_depth_stencil(This
->wined3d_device
, ds
);
953 wined3d_surface_decref(ds
);
958 wined3d_device_set_render_target(This
->wined3d_device
, 0, rt
, FALSE
);
959 wined3d_surface_decref(rt
);
962 wined3d_stateblock_apply(stateblock
);
963 wined3d_stateblock_decref(stateblock
);
966 /* Unhandled flags */
967 if(cooplevel
& DDSCL_ALLOWREBOOT
)
968 WARN("(%p) Unhandled flag DDSCL_ALLOWREBOOT, harmless\n", This
);
969 if(cooplevel
& DDSCL_ALLOWMODEX
)
970 WARN("(%p) Unhandled flag DDSCL_ALLOWMODEX, harmless\n", This
);
971 if(cooplevel
& DDSCL_FPUSETUP
)
972 WARN("(%p) Unhandled flag DDSCL_FPUSETUP, harmless\n", This
);
974 if (cooplevel
& DDSCL_EXCLUSIVE
)
975 exclusive_ddraw
= This
;
976 else if (exclusive_ddraw
== This
)
977 exclusive_ddraw
= NULL
;
979 /* Store the cooperative_level */
980 This
->cooperative_level
= cooplevel
;
981 TRACE("SetCooperativeLevel retuning DD_OK\n");
982 wined3d_mutex_unlock();
987 static HRESULT WINAPI
ddraw4_SetCooperativeLevel(IDirectDraw4
*iface
, HWND window
, DWORD flags
)
989 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
991 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
993 return ddraw7_SetCooperativeLevel(&ddraw
->IDirectDraw7_iface
, window
, flags
);
996 static HRESULT WINAPI
ddraw2_SetCooperativeLevel(IDirectDraw2
*iface
, HWND window
, DWORD flags
)
998 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1000 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1002 return ddraw7_SetCooperativeLevel(&ddraw
->IDirectDraw7_iface
, window
, flags
);
1005 static HRESULT WINAPI
ddraw1_SetCooperativeLevel(IDirectDraw
*iface
, HWND window
, DWORD flags
)
1007 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1009 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1011 return ddraw7_SetCooperativeLevel(&ddraw
->IDirectDraw7_iface
, window
, flags
);
1014 /*****************************************************************************
1015 * IDirectDraw7::SetDisplayMode
1017 * Sets the display screen resolution, color depth and refresh frequency
1018 * when in fullscreen mode (in theory).
1019 * Possible return values listed in the SDK suggest that this method fails
1020 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
1021 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
1022 * It seems to be valid to pass 0 for With and Height, this has to be tested
1023 * It could mean that the current video mode should be left as-is. (But why
1027 * Height, Width: Screen dimension
1028 * BPP: Color depth in Bits per pixel
1029 * Refreshrate: Screen refresh rate
1030 * Flags: Other stuff
1035 *****************************************************************************/
1036 static HRESULT WINAPI
ddraw7_SetDisplayMode(IDirectDraw7
*iface
, DWORD width
, DWORD height
,
1037 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1039 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1040 struct wined3d_display_mode mode
;
1041 enum wined3d_format_id format
;
1044 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1045 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1047 if (force_refresh_rate
!= 0)
1049 TRACE("ForceRefreshRate overriding passed-in refresh rate (%u Hz) to %u Hz\n",
1050 refresh_rate
, force_refresh_rate
);
1051 refresh_rate
= force_refresh_rate
;
1054 wined3d_mutex_lock();
1056 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
1058 wined3d_mutex_unlock();
1059 return DDERR_NOEXCLUSIVEMODE
;
1062 if (!width
|| !height
)
1064 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here. */
1065 wined3d_mutex_unlock();
1069 if (!restore_mode
&& FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
,
1070 WINED3DADAPTER_DEFAULT
, &original_mode
, NULL
)))
1071 ERR("Failed to get current display mode, hr %#x.\n", hr
);
1075 case 8: format
= WINED3DFMT_P8_UINT
; break;
1076 case 15: format
= WINED3DFMT_B5G5R5X1_UNORM
; break;
1077 case 16: format
= WINED3DFMT_B5G6R5_UNORM
; break;
1078 case 24: format
= WINED3DFMT_B8G8R8_UNORM
; break;
1079 case 32: format
= WINED3DFMT_B8G8R8X8_UNORM
; break;
1080 default: format
= WINED3DFMT_UNKNOWN
; break;
1084 mode
.height
= height
;
1085 mode
.refresh_rate
= refresh_rate
;
1086 mode
.format_id
= format
;
1087 mode
.scanline_ordering
= WINED3D_SCANLINE_ORDERING_UNKNOWN
;
1089 /* TODO: The possible return values from msdn suggest that the screen mode
1090 * can't be changed if a surface is locked or some drawing is in progress. */
1091 /* TODO: Lose the primary surface. */
1092 if (SUCCEEDED(hr
= wined3d_set_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
)))
1094 ddraw
->restore_mode
= TRUE
;
1095 restore_mode
= TRUE
;
1098 wined3d_mutex_unlock();
1102 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1107 static HRESULT WINAPI
ddraw4_SetDisplayMode(IDirectDraw4
*iface
, DWORD width
, DWORD height
,
1108 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1110 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1112 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1113 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1115 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1118 static HRESULT WINAPI
ddraw2_SetDisplayMode(IDirectDraw2
*iface
,
1119 DWORD width
, DWORD height
, DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1121 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1123 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1124 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1126 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1129 static HRESULT WINAPI
ddraw1_SetDisplayMode(IDirectDraw
*iface
, DWORD width
, DWORD height
, DWORD bpp
)
1131 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1133 TRACE("iface %p, width %u, height %u, bpp %u.\n", iface
, width
, height
, bpp
);
1135 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, 0, 0);
1138 /*****************************************************************************
1139 * IDirectDraw7::RestoreDisplayMode
1141 * Restores the display mode to what it was at creation time. Basically.
1145 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
1147 *****************************************************************************/
1148 static HRESULT WINAPI
ddraw7_RestoreDisplayMode(IDirectDraw7
*iface
)
1150 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1153 TRACE("iface %p.\n", iface
);
1155 wined3d_mutex_lock();
1157 if (!ddraw
->restore_mode
)
1159 wined3d_mutex_unlock();
1163 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
1165 wined3d_mutex_unlock();
1166 return DDERR_NOEXCLUSIVEMODE
;
1169 if (SUCCEEDED(hr
= wined3d_set_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &original_mode
)))
1171 ddraw
->restore_mode
= FALSE
;
1172 restore_mode
= FALSE
;
1175 wined3d_mutex_unlock();
1180 static HRESULT WINAPI
ddraw4_RestoreDisplayMode(IDirectDraw4
*iface
)
1182 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1184 TRACE("iface %p.\n", iface
);
1186 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
1189 static HRESULT WINAPI
ddraw2_RestoreDisplayMode(IDirectDraw2
*iface
)
1191 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1193 TRACE("iface %p.\n", iface
);
1195 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
1198 static HRESULT WINAPI
ddraw1_RestoreDisplayMode(IDirectDraw
*iface
)
1200 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1202 TRACE("iface %p.\n", iface
);
1204 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
1207 /*****************************************************************************
1208 * IDirectDraw7::GetCaps
1210 * Returns the drives capabilities
1212 * Used for version 1, 2, 4 and 7
1215 * DriverCaps: Structure to write the Hardware accelerated caps to
1216 * HelCaps: Structure to write the emulation caps to
1219 * This implementation returns DD_OK only
1221 *****************************************************************************/
1222 static HRESULT WINAPI
ddraw7_GetCaps(IDirectDraw7
*iface
, DDCAPS
*DriverCaps
, DDCAPS
*HELCaps
)
1224 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1226 WINED3DCAPS winecaps
;
1228 DDSCAPS2 ddscaps
= {0, 0, 0, 0};
1230 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, DriverCaps
, HELCaps
);
1232 /* One structure must be != NULL */
1233 if (!DriverCaps
&& !HELCaps
)
1235 WARN("Invalid parameters.\n");
1236 return DDERR_INVALIDPARAMS
;
1239 memset(&caps
, 0, sizeof(caps
));
1240 memset(&winecaps
, 0, sizeof(winecaps
));
1241 caps
.dwSize
= sizeof(caps
);
1243 wined3d_mutex_lock();
1244 hr
= wined3d_device_get_device_caps(ddraw
->wined3d_device
, &winecaps
);
1247 WARN("IWineD3DDevice::GetDeviceCaps failed\n");
1248 wined3d_mutex_unlock();
1252 hr
= IDirectDraw7_GetAvailableVidMem(iface
, &ddscaps
, &caps
.dwVidMemTotal
, &caps
.dwVidMemFree
);
1253 wined3d_mutex_unlock();
1255 WARN("IDirectDraw7::GetAvailableVidMem failed\n");
1259 caps
.dwCaps
= winecaps
.ddraw_caps
.caps
;
1260 caps
.dwCaps2
= winecaps
.ddraw_caps
.caps2
;
1261 caps
.dwCKeyCaps
= winecaps
.ddraw_caps
.color_key_caps
;
1262 caps
.dwFXCaps
= winecaps
.ddraw_caps
.fx_caps
;
1263 caps
.dwPalCaps
= winecaps
.ddraw_caps
.pal_caps
;
1264 caps
.ddsCaps
.dwCaps
= winecaps
.ddraw_caps
.dds_caps
;
1265 caps
.dwSVBCaps
= winecaps
.ddraw_caps
.svb_caps
;
1266 caps
.dwSVBCKeyCaps
= winecaps
.ddraw_caps
.svb_color_key_caps
;
1267 caps
.dwSVBFXCaps
= winecaps
.ddraw_caps
.svb_fx_caps
;
1268 caps
.dwVSBCaps
= winecaps
.ddraw_caps
.vsb_caps
;
1269 caps
.dwVSBCKeyCaps
= winecaps
.ddraw_caps
.vsb_color_key_caps
;
1270 caps
.dwVSBFXCaps
= winecaps
.ddraw_caps
.vsb_fx_caps
;
1271 caps
.dwSSBCaps
= winecaps
.ddraw_caps
.ssb_caps
;
1272 caps
.dwSSBCKeyCaps
= winecaps
.ddraw_caps
.ssb_color_key_caps
;
1273 caps
.dwSSBFXCaps
= winecaps
.ddraw_caps
.ssb_fx_caps
;
1275 /* Even if WineD3D supports 3D rendering, remove the cap if ddraw is configured
1278 if (DefaultSurfaceType
== WINED3D_SURFACE_TYPE_GDI
)
1280 caps
.dwCaps
&= ~DDCAPS_3D
;
1281 caps
.ddsCaps
.dwCaps
&= ~(DDSCAPS_3DDEVICE
| DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
| DDSCAPS_ZBUFFER
);
1283 if (winecaps
.ddraw_caps
.stride_align
)
1285 caps
.dwCaps
|= DDCAPS_ALIGNSTRIDE
;
1286 caps
.dwAlignStrideAlign
= winecaps
.ddraw_caps
.stride_align
;
1291 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &caps
);
1292 if (TRACE_ON(ddraw
))
1294 TRACE("Driver Caps :\n");
1295 DDRAW_dump_DDCAPS(DriverCaps
);
1301 DD_STRUCT_COPY_BYSIZE(HELCaps
, &caps
);
1302 if (TRACE_ON(ddraw
))
1304 TRACE("HEL Caps :\n");
1305 DDRAW_dump_DDCAPS(HELCaps
);
1312 static HRESULT WINAPI
ddraw4_GetCaps(IDirectDraw4
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1314 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1316 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1318 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1321 static HRESULT WINAPI
ddraw2_GetCaps(IDirectDraw2
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1323 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1325 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1327 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1330 static HRESULT WINAPI
ddraw1_GetCaps(IDirectDraw
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1332 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1334 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1336 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1339 /*****************************************************************************
1340 * IDirectDraw7::Compact
1342 * No idea what it does, MSDN says it's not implemented.
1345 * DD_OK, but this is unchecked
1347 *****************************************************************************/
1348 static HRESULT WINAPI
ddraw7_Compact(IDirectDraw7
*iface
)
1350 TRACE("iface %p.\n", iface
);
1355 static HRESULT WINAPI
ddraw4_Compact(IDirectDraw4
*iface
)
1357 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1359 TRACE("iface %p.\n", iface
);
1361 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1364 static HRESULT WINAPI
ddraw2_Compact(IDirectDraw2
*iface
)
1366 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1368 TRACE("iface %p.\n", iface
);
1370 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1373 static HRESULT WINAPI
ddraw1_Compact(IDirectDraw
*iface
)
1375 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1377 TRACE("iface %p.\n", iface
);
1379 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1382 /*****************************************************************************
1383 * IDirectDraw7::GetDisplayMode
1385 * Returns information about the current display mode
1387 * Exists in Version 1, 2, 4 and 7
1390 * DDSD: Address of a surface description structure to write the info to
1395 *****************************************************************************/
1396 static HRESULT WINAPI
ddraw7_GetDisplayMode(IDirectDraw7
*iface
, DDSURFACEDESC2
*DDSD
)
1398 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1399 struct wined3d_display_mode mode
;
1403 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
1405 wined3d_mutex_lock();
1406 /* This seems sane */
1409 wined3d_mutex_unlock();
1410 return DDERR_INVALIDPARAMS
;
1413 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1415 ERR("Failed to get display mode, hr %#x.\n", hr
);
1416 wined3d_mutex_unlock();
1420 Size
= DDSD
->dwSize
;
1421 memset(DDSD
, 0, Size
);
1423 DDSD
->dwSize
= Size
;
1424 DDSD
->dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
1425 DDSD
->dwWidth
= mode
.width
;
1426 DDSD
->dwHeight
= mode
.height
;
1427 DDSD
->u2
.dwRefreshRate
= 60;
1428 DDSD
->ddsCaps
.dwCaps
= 0;
1429 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
1430 PixelFormat_WineD3DtoDD(&DDSD
->u4
.ddpfPixelFormat
, mode
.format_id
);
1431 DDSD
->u1
.lPitch
= mode
.width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
1435 TRACE("Returning surface desc :\n");
1436 DDRAW_dump_surface_desc(DDSD
);
1439 wined3d_mutex_unlock();
1444 static HRESULT WINAPI
ddraw4_GetDisplayMode(IDirectDraw4
*iface
, DDSURFACEDESC2
*surface_desc
)
1446 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1448 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1450 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, surface_desc
);
1453 static HRESULT WINAPI
ddraw2_GetDisplayMode(IDirectDraw2
*iface
, DDSURFACEDESC
*surface_desc
)
1455 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1457 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1459 /* FIXME: Test sizes, properly convert surface_desc */
1460 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1463 static HRESULT WINAPI
ddraw1_GetDisplayMode(IDirectDraw
*iface
, DDSURFACEDESC
*surface_desc
)
1465 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1467 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1469 /* FIXME: Test sizes, properly convert surface_desc */
1470 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1473 /*****************************************************************************
1474 * IDirectDraw7::GetFourCCCodes
1476 * Returns an array of supported FourCC codes.
1478 * Exists in Version 1, 2, 4 and 7
1481 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
1482 * of enumerated codes
1483 * Codes: Pointer to an array of DWORDs where the supported codes are written
1487 * Always returns DD_OK, as it's a stub for now
1489 *****************************************************************************/
1490 static HRESULT WINAPI
ddraw7_GetFourCCCodes(IDirectDraw7
*iface
, DWORD
*NumCodes
, DWORD
*Codes
)
1492 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1493 static const enum wined3d_format_id formats
[] =
1495 WINED3DFMT_YUY2
, WINED3DFMT_UYVY
, WINED3DFMT_YV12
,
1496 WINED3DFMT_DXT1
, WINED3DFMT_DXT2
, WINED3DFMT_DXT3
, WINED3DFMT_DXT4
, WINED3DFMT_DXT5
,
1497 WINED3DFMT_ATI2N
, WINED3DFMT_NVHU
, WINED3DFMT_NVHS
1499 struct wined3d_display_mode mode
;
1500 DWORD count
= 0, i
, outsize
;
1503 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, NumCodes
, Codes
);
1505 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1507 ERR("Failed to get display mode, hr %#x.\n", hr
);
1511 outsize
= NumCodes
&& Codes
? *NumCodes
: 0;
1513 for (i
= 0; i
< (sizeof(formats
) / sizeof(formats
[0])); ++i
)
1515 hr
= wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, WINED3D_DEVICE_TYPE_HAL
,
1516 mode
.format_id
, 0, WINED3D_RTYPE_SURFACE
, formats
[i
], DefaultSurfaceType
);
1519 if (count
< outsize
)
1520 Codes
[count
] = formats
[i
];
1525 TRACE("Returning %u FourCC codes\n", count
);
1532 static HRESULT WINAPI
ddraw4_GetFourCCCodes(IDirectDraw4
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1534 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1536 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1538 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1541 static HRESULT WINAPI
ddraw2_GetFourCCCodes(IDirectDraw2
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1543 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1545 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1547 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1550 static HRESULT WINAPI
ddraw1_GetFourCCCodes(IDirectDraw
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1552 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1554 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1556 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1559 static HRESULT WINAPI
ddraw7_GetMonitorFrequency(IDirectDraw7
*iface
, DWORD
*frequency
)
1561 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1562 struct wined3d_display_mode mode
;
1565 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1567 wined3d_mutex_lock();
1568 hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
);
1569 wined3d_mutex_unlock();
1572 WARN("Failed to get display mode, hr %#x.\n", hr
);
1576 *frequency
= mode
.refresh_rate
;
1581 static HRESULT WINAPI
ddraw4_GetMonitorFrequency(IDirectDraw4
*iface
, DWORD
*frequency
)
1583 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1585 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1587 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1590 static HRESULT WINAPI
ddraw2_GetMonitorFrequency(IDirectDraw2
*iface
, DWORD
*frequency
)
1592 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1594 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1596 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1599 static HRESULT WINAPI
ddraw1_GetMonitorFrequency(IDirectDraw
*iface
, DWORD
*frequency
)
1601 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1603 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1605 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1608 static HRESULT WINAPI
ddraw7_GetVerticalBlankStatus(IDirectDraw7
*iface
, BOOL
*status
)
1610 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1611 struct wined3d_raster_status raster_status
;
1614 TRACE("iface %p, status %p.\n", iface
, status
);
1617 return DDERR_INVALIDPARAMS
;
1619 wined3d_mutex_lock();
1620 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
1621 wined3d_mutex_unlock();
1624 WARN("Failed to get raster status, hr %#x.\n", hr
);
1628 *status
= raster_status
.in_vblank
;
1633 static HRESULT WINAPI
ddraw4_GetVerticalBlankStatus(IDirectDraw4
*iface
, BOOL
*status
)
1635 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1637 TRACE("iface %p, status %p.\n", iface
, status
);
1639 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1642 static HRESULT WINAPI
ddraw2_GetVerticalBlankStatus(IDirectDraw2
*iface
, BOOL
*status
)
1644 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1646 TRACE("iface %p, status %p.\n", iface
, status
);
1648 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1651 static HRESULT WINAPI
ddraw1_GetVerticalBlankStatus(IDirectDraw
*iface
, BOOL
*status
)
1653 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1655 TRACE("iface %p, status %p.\n", iface
, status
);
1657 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1660 /*****************************************************************************
1661 * IDirectDraw7::GetAvailableVidMem
1663 * Returns the total and free video memory
1666 * Caps: Specifies the memory type asked for
1667 * total: Pointer to a DWORD to be filled with the total memory
1668 * free: Pointer to a DWORD to be filled with the free memory
1672 * DDERR_INVALIDPARAMS of free and total are NULL
1674 *****************************************************************************/
1675 static HRESULT WINAPI
ddraw7_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*Caps
, DWORD
*total
,
1678 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1681 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, Caps
, total
, free
);
1683 if (TRACE_ON(ddraw
))
1685 TRACE("Asked for memory with description: ");
1686 DDRAW_dump_DDSCAPS2(Caps
);
1688 wined3d_mutex_lock();
1690 /* Todo: System memory vs local video memory vs non-local video memory
1691 * The MSDN also mentions differences between texture memory and other
1692 * resources, but that's not important
1695 if( (!total
) && (!free
) )
1697 wined3d_mutex_unlock();
1698 return DDERR_INVALIDPARAMS
;
1702 *free
= wined3d_device_get_available_texture_mem(ddraw
->wined3d_device
);
1705 struct wined3d_adapter_identifier desc
= {0};
1707 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0, &desc
);
1708 *total
= desc
.video_memory
;
1711 wined3d_mutex_unlock();
1716 static HRESULT WINAPI
ddraw4_GetAvailableVidMem(IDirectDraw4
*iface
,
1717 DDSCAPS2
*caps
, DWORD
*total
, DWORD
*free
)
1719 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1721 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1723 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, caps
, total
, free
);
1726 static HRESULT WINAPI
ddraw2_GetAvailableVidMem(IDirectDraw2
*iface
,
1727 DDSCAPS
*caps
, DWORD
*total
, DWORD
*free
)
1729 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1732 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1734 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
1735 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, &caps2
, total
, free
);
1738 /*****************************************************************************
1739 * IDirectDraw7::Initialize
1741 * Initializes a DirectDraw interface.
1744 * GUID: Interface identifier. Well, don't know what this is really good
1748 * Returns DD_OK on the first call,
1749 * DDERR_ALREADYINITIALIZED on repeated calls
1751 *****************************************************************************/
1752 static HRESULT WINAPI
ddraw7_Initialize(IDirectDraw7
*iface
, GUID
*guid
)
1754 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1756 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1758 if (ddraw
->initialized
)
1759 return DDERR_ALREADYINITIALIZED
;
1761 /* FIXME: To properly take the GUID into account we should call
1762 * ddraw_init() here instead of in DDRAW_Create(). */
1764 FIXME("Ignoring guid %s.\n", debugstr_guid(guid
));
1766 ddraw
->initialized
= TRUE
;
1770 static HRESULT WINAPI
ddraw4_Initialize(IDirectDraw4
*iface
, GUID
*guid
)
1772 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1774 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1776 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
1779 static HRESULT WINAPI
ddraw2_Initialize(IDirectDraw2
*iface
, GUID
*guid
)
1781 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1783 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1785 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
1788 static HRESULT WINAPI
ddraw1_Initialize(IDirectDraw
*iface
, GUID
*guid
)
1790 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1792 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1794 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
1797 static HRESULT WINAPI
d3d1_Initialize(IDirect3D
*iface
, REFIID riid
)
1799 TRACE("iface %p, riid %s.\n", iface
, debugstr_guid(riid
));
1801 return DDERR_ALREADYINITIALIZED
;
1804 /*****************************************************************************
1805 * IDirectDraw7::FlipToGDISurface
1807 * "Makes the surface that the GDI writes to the primary surface"
1808 * Looks like some windows specific thing we don't have to care about.
1809 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
1810 * show error boxes ;)
1811 * Well, just return DD_OK.
1814 * Always returns DD_OK
1816 *****************************************************************************/
1817 static HRESULT WINAPI
ddraw7_FlipToGDISurface(IDirectDraw7
*iface
)
1819 FIXME("iface %p stub!\n", iface
);
1824 static HRESULT WINAPI
ddraw4_FlipToGDISurface(IDirectDraw4
*iface
)
1826 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1828 TRACE("iface %p.\n", iface
);
1830 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
1833 static HRESULT WINAPI
ddraw2_FlipToGDISurface(IDirectDraw2
*iface
)
1835 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1837 TRACE("iface %p.\n", iface
);
1839 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
1842 static HRESULT WINAPI
ddraw1_FlipToGDISurface(IDirectDraw
*iface
)
1844 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1846 TRACE("iface %p.\n", iface
);
1848 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
1851 /*****************************************************************************
1852 * IDirectDraw7::WaitForVerticalBlank
1854 * This method allows applications to get in sync with the vertical blank
1856 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
1857 * redraw the screen, most likely because of this stub
1860 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
1861 * or DDWAITVB_BLOCKEND
1862 * h: Not used, according to MSDN
1865 * Always returns DD_OK
1867 *****************************************************************************/
1868 static HRESULT WINAPI
ddraw7_WaitForVerticalBlank(IDirectDraw7
*iface
, DWORD Flags
, HANDLE event
)
1872 TRACE("iface %p, flags %#x, event %p.\n", iface
, Flags
, event
);
1874 /* This function is called often, so print the fixme only once */
1877 FIXME("iface %p, flags %#x, event %p stub!\n", iface
, Flags
, event
);
1881 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
1882 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
1883 return DDERR_UNSUPPORTED
; /* unchecked */
1888 static HRESULT WINAPI
ddraw4_WaitForVerticalBlank(IDirectDraw4
*iface
, DWORD flags
, HANDLE event
)
1890 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1892 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1894 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
1897 static HRESULT WINAPI
ddraw2_WaitForVerticalBlank(IDirectDraw2
*iface
, DWORD flags
, HANDLE event
)
1899 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1901 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1903 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
1906 static HRESULT WINAPI
ddraw1_WaitForVerticalBlank(IDirectDraw
*iface
, DWORD flags
, HANDLE event
)
1908 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1910 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1912 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
1915 static HRESULT WINAPI
ddraw7_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
1917 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1918 struct wined3d_raster_status raster_status
;
1921 TRACE("iface %p, line %p.\n", iface
, Scanline
);
1923 wined3d_mutex_lock();
1924 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
1925 wined3d_mutex_unlock();
1928 WARN("Failed to get raster status, hr %#x.\n", hr
);
1932 *Scanline
= raster_status
.scan_line
;
1934 if (raster_status
.in_vblank
)
1935 return DDERR_VERTICALBLANKINPROGRESS
;
1940 static HRESULT WINAPI
ddraw4_GetScanLine(IDirectDraw4
*iface
, DWORD
*line
)
1942 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1944 TRACE("iface %p, line %p.\n", iface
, line
);
1946 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
1949 static HRESULT WINAPI
ddraw2_GetScanLine(IDirectDraw2
*iface
, DWORD
*line
)
1951 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1953 TRACE("iface %p, line %p.\n", iface
, line
);
1955 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
1958 static HRESULT WINAPI
ddraw1_GetScanLine(IDirectDraw
*iface
, DWORD
*line
)
1960 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1962 TRACE("iface %p, line %p.\n", iface
, line
);
1964 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
1967 /*****************************************************************************
1968 * IDirectDraw7::TestCooperativeLevel
1970 * Informs the application about the state of the video adapter, depending
1971 * on the cooperative level
1974 * DD_OK if the device is in a sane state
1975 * DDERR_NOEXCLUSIVEMODE or DDERR_EXCLUSIVEMODEALREADYSET
1976 * if the state is not correct(See below)
1978 *****************************************************************************/
1979 static HRESULT WINAPI
ddraw7_TestCooperativeLevel(IDirectDraw7
*iface
)
1981 TRACE("iface %p.\n", iface
);
1986 static HRESULT WINAPI
ddraw4_TestCooperativeLevel(IDirectDraw4
*iface
)
1988 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1990 TRACE("iface %p.\n", iface
);
1992 return ddraw7_TestCooperativeLevel(&ddraw
->IDirectDraw7_iface
);
1995 /*****************************************************************************
1996 * IDirectDraw7::GetGDISurface
1998 * Returns the surface that GDI is treating as the primary surface.
1999 * For Wine this is the front buffer
2002 * GDISurface: Address to write the surface pointer to
2005 * DD_OK if the surface was found
2006 * DDERR_NOTFOUND if the GDI surface wasn't found
2008 *****************************************************************************/
2009 static HRESULT WINAPI
ddraw7_GetGDISurface(IDirectDraw7
*iface
, IDirectDrawSurface7
**GDISurface
)
2011 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2013 TRACE("iface %p, surface %p.\n", iface
, GDISurface
);
2015 wined3d_mutex_lock();
2017 if (!(*GDISurface
= &ddraw
->primary
->IDirectDrawSurface7_iface
))
2019 WARN("Primary not created yet.\n");
2020 wined3d_mutex_unlock();
2021 return DDERR_NOTFOUND
;
2023 IDirectDrawSurface7_AddRef(*GDISurface
);
2025 wined3d_mutex_unlock();
2030 static HRESULT WINAPI
ddraw4_GetGDISurface(IDirectDraw4
*iface
, IDirectDrawSurface4
**surface
)
2032 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2033 struct ddraw_surface
*surface_impl
;
2034 IDirectDrawSurface7
*surface7
;
2037 TRACE("iface %p, surface %p.\n", iface
, surface
);
2039 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2045 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2046 *surface
= &surface_impl
->IDirectDrawSurface4_iface
;
2047 IDirectDrawSurface4_AddRef(*surface
);
2048 IDirectDrawSurface7_Release(surface7
);
2053 static HRESULT WINAPI
ddraw2_GetGDISurface(IDirectDraw2
*iface
, IDirectDrawSurface
**surface
)
2055 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2056 struct ddraw_surface
*surface_impl
;
2057 IDirectDrawSurface7
*surface7
;
2060 TRACE("iface %p, surface %p.\n", iface
, surface
);
2062 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2068 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2069 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2070 IDirectDrawSurface_AddRef(*surface
);
2071 IDirectDrawSurface7_Release(surface7
);
2076 static HRESULT WINAPI
ddraw1_GetGDISurface(IDirectDraw
*iface
, IDirectDrawSurface
**surface
)
2078 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2079 struct ddraw_surface
*surface_impl
;
2080 IDirectDrawSurface7
*surface7
;
2083 TRACE("iface %p, surface %p.\n", iface
, surface
);
2085 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2091 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2092 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2093 IDirectDrawSurface_AddRef(*surface
);
2094 IDirectDrawSurface7_Release(surface7
);
2099 struct displaymodescallback_context
2101 LPDDENUMMODESCALLBACK func
;
2105 static HRESULT CALLBACK
EnumDisplayModesCallbackThunk(DDSURFACEDESC2
*surface_desc
, void *context
)
2107 struct displaymodescallback_context
*cbcontext
= context
;
2110 DDSD2_to_DDSD(surface_desc
, &desc
);
2111 return cbcontext
->func(&desc
, cbcontext
->context
);
2114 /*****************************************************************************
2115 * IDirectDraw7::EnumDisplayModes
2117 * Enumerates the supported Display modes. The modes can be filtered with
2118 * the DDSD parameter.
2121 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES. For old ddraw
2122 * versions (3 and older?) this is reserved and must be 0.
2123 * DDSD: Surface description to filter the modes
2124 * Context: Pointer passed back to the callback function
2125 * cb: Application-provided callback function
2129 * DDERR_INVALIDPARAMS if the callback wasn't set
2131 *****************************************************************************/
2132 static HRESULT WINAPI
ddraw7_EnumDisplayModes(IDirectDraw7
*iface
, DWORD Flags
,
2133 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMMODESCALLBACK2 cb
)
2135 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2136 struct wined3d_display_mode
*enum_modes
= NULL
;
2137 struct wined3d_display_mode mode
;
2138 unsigned int modenum
, fmt
;
2139 DDSURFACEDESC2 callback_sd
;
2140 unsigned enum_mode_count
= 0, enum_mode_array_size
= 0;
2141 DDPIXELFORMAT pixelformat
;
2143 static const enum wined3d_format_id checkFormatList
[] =
2145 WINED3DFMT_B8G8R8X8_UNORM
,
2146 WINED3DFMT_B5G6R5_UNORM
,
2150 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2151 iface
, Flags
, DDSD
, Context
, cb
);
2154 return DDERR_INVALIDPARAMS
;
2156 wined3d_mutex_lock();
2157 if(!(Flags
& DDEDM_REFRESHRATES
))
2159 enum_mode_array_size
= 16;
2160 enum_modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(*enum_modes
) * enum_mode_array_size
);
2163 ERR("Out of memory\n");
2164 wined3d_mutex_unlock();
2165 return DDERR_OUTOFMEMORY
;
2169 pixelformat
.dwSize
= sizeof(pixelformat
);
2170 for(fmt
= 0; fmt
< (sizeof(checkFormatList
) / sizeof(checkFormatList
[0])); fmt
++)
2173 while (wined3d_enum_adapter_modes(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, checkFormatList
[fmt
],
2174 WINED3D_SCANLINE_ORDERING_UNKNOWN
, modenum
++, &mode
) == WINED3D_OK
)
2176 PixelFormat_WineD3DtoDD(&pixelformat
, mode
.format_id
);
2179 if (DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.width
!= DDSD
->dwWidth
)
2181 if (DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.height
!= DDSD
->dwHeight
)
2183 if (DDSD
->dwFlags
& DDSD_REFRESHRATE
&& mode
.refresh_rate
!= DDSD
->u2
.dwRefreshRate
)
2185 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
2186 && pixelformat
.u1
.dwRGBBitCount
!= DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
)
2190 if(!(Flags
& DDEDM_REFRESHRATES
))
2192 /* DX docs state EnumDisplayMode should return only unique modes. If DDEDM_REFRESHRATES is not set, refresh
2193 * rate doesn't matter when determining if the mode is unique. So modes only differing in refresh rate have
2194 * to be reduced to a single unique result in such case.
2199 for (i
= 0; i
< enum_mode_count
; i
++)
2201 if (enum_modes
[i
].width
== mode
.width
&& enum_modes
[i
].height
== mode
.height
2202 && enum_modes
[i
].format_id
== mode
.format_id
)
2212 memset(&callback_sd
, 0, sizeof(callback_sd
));
2213 callback_sd
.dwSize
= sizeof(callback_sd
);
2214 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2216 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
|DDSD_REFRESHRATE
;
2217 if (Flags
& DDEDM_REFRESHRATES
)
2218 callback_sd
.u2
.dwRefreshRate
= mode
.refresh_rate
;
2220 callback_sd
.dwWidth
= mode
.width
;
2221 callback_sd
.dwHeight
= mode
.height
;
2223 callback_sd
.u4
.ddpfPixelFormat
=pixelformat
;
2225 /* Calc pitch and DWORD align like MSDN says */
2226 callback_sd
.u1
.lPitch
= (callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8) * mode
.width
;
2227 callback_sd
.u1
.lPitch
= (callback_sd
.u1
.lPitch
+ 3) & ~3;
2229 TRACE("Enumerating %dx%dx%d @%d\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
,
2230 callback_sd
.u2
.dwRefreshRate
);
2232 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
2234 TRACE("Application asked to terminate the enumeration\n");
2235 HeapFree(GetProcessHeap(), 0, enum_modes
);
2236 wined3d_mutex_unlock();
2240 if(!(Flags
& DDEDM_REFRESHRATES
))
2242 if (enum_mode_count
== enum_mode_array_size
)
2244 struct wined3d_display_mode
*new_enum_modes
;
2246 enum_mode_array_size
*= 2;
2247 new_enum_modes
= HeapReAlloc(GetProcessHeap(), 0, enum_modes
,
2248 sizeof(*new_enum_modes
) * enum_mode_array_size
);
2249 if (!new_enum_modes
)
2251 ERR("Out of memory\n");
2252 HeapFree(GetProcessHeap(), 0, enum_modes
);
2253 wined3d_mutex_unlock();
2254 return DDERR_OUTOFMEMORY
;
2257 enum_modes
= new_enum_modes
;
2260 enum_modes
[enum_mode_count
++] = mode
;
2265 TRACE("End of enumeration\n");
2266 HeapFree(GetProcessHeap(), 0, enum_modes
);
2267 wined3d_mutex_unlock();
2272 static HRESULT WINAPI
ddraw4_EnumDisplayModes(IDirectDraw4
*iface
, DWORD flags
,
2273 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK2 callback
)
2275 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2277 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2278 iface
, flags
, surface_desc
, context
, callback
);
2280 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
, context
, callback
);
2283 static HRESULT WINAPI
ddraw2_EnumDisplayModes(IDirectDraw2
*iface
, DWORD flags
,
2284 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2286 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2287 struct displaymodescallback_context cbcontext
;
2288 DDSURFACEDESC2 surface_desc2
;
2290 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2291 iface
, flags
, surface_desc
, context
, callback
);
2293 cbcontext
.func
= callback
;
2294 cbcontext
.context
= context
;
2296 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2297 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2298 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2301 static HRESULT WINAPI
ddraw1_EnumDisplayModes(IDirectDraw
*iface
, DWORD flags
,
2302 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2304 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2305 struct displaymodescallback_context cbcontext
;
2306 DDSURFACEDESC2 surface_desc2
;
2308 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2309 iface
, flags
, surface_desc
, context
, callback
);
2311 cbcontext
.func
= callback
;
2312 cbcontext
.context
= context
;
2314 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2315 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2316 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2319 /*****************************************************************************
2320 * IDirectDraw7::EvaluateMode
2322 * Used with IDirectDraw7::StartModeTest to test video modes.
2323 * EvaluateMode is used to pass or fail a mode, and continue with the next
2327 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
2328 * Timeout: Returns the amount of seconds left before the mode would have
2329 * been failed automatically
2332 * This implementation always DD_OK, because it's a stub
2334 *****************************************************************************/
2335 static HRESULT WINAPI
ddraw7_EvaluateMode(IDirectDraw7
*iface
, DWORD Flags
, DWORD
*Timeout
)
2337 FIXME("iface %p, flags %#x, timeout %p stub!\n", iface
, Flags
, Timeout
);
2339 /* When implementing this, implement it in WineD3D */
2344 /*****************************************************************************
2345 * IDirectDraw7::GetDeviceIdentifier
2347 * Returns the device identifier, which gives information about the driver
2348 * Our device identifier is defined at the beginning of this file.
2351 * DDDI: Address for the returned structure
2352 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
2355 * On success it returns DD_OK
2356 * DDERR_INVALIDPARAMS if DDDI is NULL
2358 *****************************************************************************/
2359 static HRESULT WINAPI
ddraw7_GetDeviceIdentifier(IDirectDraw7
*iface
,
2360 DDDEVICEIDENTIFIER2
*DDDI
, DWORD Flags
)
2362 TRACE("iface %p, device_identifier %p, flags %#x.\n", iface
, DDDI
, Flags
);
2365 return DDERR_INVALIDPARAMS
;
2367 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
2368 * host adapter, if there's a secondary 3D adapter. This doesn't apply
2369 * to any modern hardware, nor is it interesting for Wine, so ignore it.
2370 * Size of DDDEVICEIDENTIFIER2 may be aligned to 8 bytes and thus 4
2371 * bytes too long. So only copy the relevant part of the structure
2374 memcpy(DDDI
, &deviceidentifier
, FIELD_OFFSET(DDDEVICEIDENTIFIER2
, dwWHQLLevel
) + sizeof(DWORD
));
2378 static HRESULT WINAPI
ddraw4_GetDeviceIdentifier(IDirectDraw4
*iface
,
2379 DDDEVICEIDENTIFIER
*identifier
, DWORD flags
)
2381 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2382 DDDEVICEIDENTIFIER2 identifier2
;
2385 TRACE("iface %p, identifier %p, flags %#x.\n", iface
, identifier
, flags
);
2387 hr
= ddraw7_GetDeviceIdentifier(&ddraw
->IDirectDraw7_iface
, &identifier2
, flags
);
2388 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&identifier2
, identifier
);
2393 /*****************************************************************************
2394 * IDirectDraw7::GetSurfaceFromDC
2396 * Returns the Surface for a GDI device context handle.
2397 * Is this related to IDirectDrawSurface::GetDC ???
2400 * hdc: hdc to return the surface for
2401 * Surface: Address to write the surface pointer to
2404 * Always returns DD_OK because it's a stub
2406 *****************************************************************************/
2407 static HRESULT WINAPI
ddraw7_GetSurfaceFromDC(IDirectDraw7
*iface
, HDC hdc
,
2408 IDirectDrawSurface7
**Surface
)
2410 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2411 struct wined3d_surface
*wined3d_surface
;
2412 struct ddraw_surface
*surface_impl
;
2414 TRACE("iface %p, dc %p, surface %p.\n", iface
, hdc
, Surface
);
2416 if (!Surface
) return E_INVALIDARG
;
2418 if (!(wined3d_surface
= wined3d_device_get_surface_from_dc(ddraw
->wined3d_device
, hdc
)))
2420 TRACE("No surface found for dc %p.\n", hdc
);
2422 return DDERR_NOTFOUND
;
2425 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
2426 *Surface
= &surface_impl
->IDirectDrawSurface7_iface
;
2427 IDirectDrawSurface7_AddRef(*Surface
);
2428 TRACE("Returning surface %p.\n", Surface
);
2432 static HRESULT WINAPI
ddraw4_GetSurfaceFromDC(IDirectDraw4
*iface
, HDC dc
,
2433 IDirectDrawSurface4
**surface
)
2435 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2436 struct ddraw_surface
*surface_impl
;
2437 IDirectDrawSurface7
*surface7
;
2440 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2442 if (!surface
) return E_INVALIDARG
;
2444 hr
= ddraw7_GetSurfaceFromDC(&ddraw
->IDirectDraw7_iface
, dc
, &surface7
);
2450 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2451 /* Tests say this is true */
2452 *surface
= (IDirectDrawSurface4
*)&surface_impl
->IDirectDrawSurface_iface
;
2453 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2454 IDirectDrawSurface7_Release(surface7
);
2459 /*****************************************************************************
2460 * IDirectDraw7::RestoreAllSurfaces
2462 * Calls the restore method of all surfaces
2467 * Always returns DD_OK because it's a stub
2469 *****************************************************************************/
2470 static HRESULT WINAPI
ddraw7_RestoreAllSurfaces(IDirectDraw7
*iface
)
2472 FIXME("iface %p stub!\n", iface
);
2474 /* This isn't hard to implement: Enumerate all WineD3D surfaces,
2475 * get their parent and call their restore method. Do not implement
2476 * it in WineD3D, as restoring a surface means re-creating the
2482 static HRESULT WINAPI
ddraw4_RestoreAllSurfaces(IDirectDraw4
*iface
)
2484 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2486 TRACE("iface %p.\n", iface
);
2488 return ddraw7_RestoreAllSurfaces(&ddraw
->IDirectDraw7_iface
);
2491 /*****************************************************************************
2492 * IDirectDraw7::StartModeTest
2494 * Tests the specified video modes to update the system registry with
2495 * refresh rate information. StartModeTest starts the mode test,
2496 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
2497 * isn't called within 15 seconds, the mode is failed automatically
2499 * As refresh rates are handled by the X server, I don't think this
2500 * Method is important
2503 * Modes: An array of mode specifications
2504 * NumModes: The number of modes in Modes
2505 * Flags: Some flags...
2508 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
2509 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
2512 *****************************************************************************/
2513 static HRESULT WINAPI
ddraw7_StartModeTest(IDirectDraw7
*iface
, SIZE
*Modes
, DWORD NumModes
, DWORD Flags
)
2515 FIXME("iface %p, modes %p, mode_count %u, flags %#x partial stub!\n",
2516 iface
, Modes
, NumModes
, Flags
);
2518 /* This looks sane */
2519 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
2521 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
2522 * As it is not, DDERR_TESTFINISHED is returned
2523 * (hopefully that's correct
2525 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
2526 * well, that value doesn't (yet) exist in the wine headers, so ignore it
2532 /*****************************************************************************
2533 * ddraw_create_surface
2535 * A helper function for IDirectDraw7::CreateSurface. It creates a new surface
2536 * with the passed parameters.
2539 * DDSD: Description of the surface to create
2540 * Surf: Address to store the interface pointer at
2545 *****************************************************************************/
2546 static HRESULT
ddraw_create_surface(struct ddraw
*ddraw
, DDSURFACEDESC2
*pDDSD
,
2547 struct ddraw_surface
**surface
, UINT version
)
2551 TRACE("ddraw %p, surface_desc %p, surface %p.\n", ddraw
, pDDSD
, surface
);
2553 if (TRACE_ON(ddraw
))
2555 TRACE("Requesting surface desc:\n");
2556 DDRAW_dump_surface_desc(pDDSD
);
2559 if ((pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) && DefaultSurfaceType
!= WINED3D_SURFACE_TYPE_OPENGL
)
2561 WARN("The application requests a 3D capable surface, but a non-OpenGL surface type was set in the registry.\n");
2562 /* Do not fail surface creation, only fail 3D device creation. */
2565 /* Create the Surface object */
2566 *surface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(**surface
));
2569 ERR("Failed to allocate surface memory.\n");
2570 return DDERR_OUTOFVIDEOMEMORY
;
2573 if (FAILED(hr
= ddraw_surface_init(*surface
, ddraw
, pDDSD
, version
)))
2575 WARN("Failed to initialize surface, hr %#x.\n", hr
);
2576 HeapFree(GetProcessHeap(), 0, *surface
);
2580 /* Increase the surface counter, and attach the surface */
2581 list_add_head(&ddraw
->surface_list
, &(*surface
)->surface_list_entry
);
2583 TRACE("Created surface %p.\n", *surface
);
2588 static HRESULT CDECL
ddraw_reset_enum_callback(struct wined3d_resource
*resource
)
2593 /*****************************************************************************
2594 * IDirectDraw7::CreateSurface
2596 * Creates a new IDirectDrawSurface object and returns its interface.
2598 * The surface connections with wined3d are a bit tricky. Basically it works
2601 * |------------------------| |-----------------|
2602 * | DDraw surface | | WineD3DSurface |
2604 * | WineD3DSurface |-------------->| |
2605 * | Child |<------------->| Parent |
2606 * |------------------------| |-----------------|
2608 * The DDraw surface is the parent of the wined3d surface, and it releases
2609 * the WineD3DSurface when the ddraw surface is destroyed.
2611 * However, for all surfaces which can be in a container in WineD3D,
2612 * we have to do this. These surfaces are usually complex surfaces,
2613 * so this concerns primary surfaces with a front and a back buffer,
2616 * |------------------------| |-----------------|
2617 * | DDraw surface | | Container |
2619 * | Child |<------------->| Parent |
2620 * | Texture |<------------->| |
2621 * | WineD3DSurface |<----| | Levels |<--|
2622 * | Complex connection | | | | |
2623 * |------------------------| | |-----------------| |
2627 * | |------------------| | |-----------------| |
2628 * | | IParent | |-------->| WineD3DSurface | |
2630 * | | Child |<------------->| Parent | |
2631 * | | | | Container |<--|
2632 * | |------------------| |-----------------| |
2634 * | |----------------------| |
2635 * | | DDraw surface 2 | |
2637 * |<->| Complex root Child | |
2639 * | | WineD3DSurface |<----| |
2640 * | |----------------------| | |
2642 * | |---------------------| | |-----------------| |
2643 * | | IParent | |----->| WineD3DSurface | |
2645 * | | Child |<---------->| Parent | |
2646 * | |---------------------| | Container |<--|
2647 * | |-----------------| |
2649 * | ---More surfaces can follow--- |
2651 * The reason is that the IWineD3DSwapchain(render target container)
2652 * and the IWineD3DTexure(Texture container) release the parents
2653 * of their surface's children, but by releasing the complex root
2654 * the surfaces which are complexly attached to it are destroyed
2655 * too. See IDirectDrawSurface::Release for a more detailed
2659 * DDSD: Description of the surface to create
2660 * Surf: Address to store the interface pointer at
2661 * UnkOuter: Basically for aggregation support, but ddraw doesn't support
2662 * aggregation, so it has to be NULL
2666 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
2667 * DDERR_* if an error occurs
2669 *****************************************************************************/
2670 static HRESULT
CreateSurface(struct ddraw
*ddraw
, DDSURFACEDESC2
*DDSD
,
2671 struct ddraw_surface
**surface
, IUnknown
*UnkOuter
, UINT version
)
2673 struct ddraw_surface
*object
= NULL
;
2674 struct wined3d_display_mode mode
;
2676 DDSURFACEDESC2 desc2
;
2677 const DWORD sysvidmem
= DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
2679 TRACE("ddraw %p, surface_desc %p, surface %p, outer_unknown %p.\n", ddraw
, DDSD
, surface
, UnkOuter
);
2681 /* Some checks before we start */
2682 if (TRACE_ON(ddraw
))
2684 TRACE(" (%p) Requesting surface desc :\n", ddraw
);
2685 DDRAW_dump_surface_desc(DDSD
);
2688 if (UnkOuter
!= NULL
)
2690 FIXME("(%p) : outer != NULL?\n", ddraw
);
2691 return CLASS_E_NOAGGREGATION
; /* unchecked */
2696 FIXME("(%p) You want to get back a surface? Don't give NULL ptrs!\n", ddraw
);
2697 return E_POINTER
; /* unchecked */
2700 if (!(DDSD
->dwFlags
& DDSD_CAPS
))
2702 /* DVIDEO.DLL does forget the DDSD_CAPS flag ... *sigh* */
2703 DDSD
->dwFlags
|= DDSD_CAPS
;
2706 if (DDSD
->ddsCaps
.dwCaps
& DDSCAPS_ALLOCONLOAD
)
2708 /* If the surface is of the 'alloconload' type, ignore the LPSURFACE field */
2709 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2712 if ((DDSD
->dwFlags
& DDSD_LPSURFACE
) && (DDSD
->lpSurface
== NULL
))
2714 /* Frank Herbert's Dune specifies a null pointer for the surface, ignore the LPSURFACE field */
2715 WARN("(%p) Null surface pointer specified, ignore it!\n", ddraw
);
2716 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2719 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
) &&
2720 !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
2722 TRACE("(%p): Attempt to create a flipable primary surface without DDSCL_EXCLUSIVE set\n",
2725 return DDERR_NOEXCLUSIVEMODE
;
2728 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_BACKBUFFER
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_BACKBUFFER
| DDSCAPS_PRIMARYSURFACE
))
2730 WARN("Application wanted to create back buffer primary surface\n");
2731 return DDERR_INVALIDCAPS
;
2734 if((DDSD
->ddsCaps
.dwCaps
& sysvidmem
) == sysvidmem
)
2736 /* This is a special switch in ddrawex.dll, but not allowed in ddraw.dll */
2737 WARN("Application tries to put the surface in both system and video memory\n");
2739 return DDERR_INVALIDCAPS
;
2742 /* Check cube maps but only if the size includes them */
2743 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2745 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
&&
2746 !(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
2748 WARN("Cube map faces requested without cube map flag\n");
2749 return DDERR_INVALIDCAPS
;
2751 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2752 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) == 0)
2754 WARN("Cube map without faces requested\n");
2755 return DDERR_INVALIDPARAMS
;
2758 /* Quick tests confirm those can be created, but we don't do that yet */
2759 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2760 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
2762 FIXME("Partial cube maps not supported yet\n");
2766 /* According to the msdn this flag is ignored by CreateSurface */
2767 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2768 DDSD
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2770 /* Modify some flags */
2771 copy_to_surfacedesc2(&desc2
, DDSD
);
2772 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
); /* Just to be sure */
2774 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
2776 ERR("Failed to get display mode, hr %#x.\n", hr
);
2780 /* No pixelformat given? Use the current screen format */
2781 if(!(desc2
.dwFlags
& DDSD_PIXELFORMAT
))
2783 desc2
.dwFlags
|= DDSD_PIXELFORMAT
;
2784 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
);
2786 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, mode
.format_id
);
2789 /* No Width or no Height? Use the original screen size
2791 if(!(desc2
.dwFlags
& DDSD_WIDTH
) ||
2792 !(desc2
.dwFlags
& DDSD_HEIGHT
) )
2794 /* Invalid for non-render targets */
2795 if(!(desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
2797 WARN("Creating a non-Primary surface without Width or Height info, returning DDERR_INVALIDPARAMS\n");
2799 return DDERR_INVALIDPARAMS
;
2802 desc2
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
2803 desc2
.dwWidth
= mode
.width
;
2804 desc2
.dwHeight
= mode
.height
;
2807 if (!desc2
.dwWidth
|| !desc2
.dwHeight
)
2808 return DDERR_INVALIDPARAMS
;
2810 /* Mipmap count fixes */
2811 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
2813 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
2815 if(desc2
.dwFlags
& DDSD_MIPMAPCOUNT
)
2817 /* Mipmap count is given, should not be 0 */
2818 if( desc2
.u2
.dwMipMapCount
== 0 )
2819 return DDERR_INVALIDPARAMS
;
2823 /* Undocumented feature: Create sublevels until
2824 * either the width or the height is 1
2826 DWORD min
= desc2
.dwWidth
< desc2
.dwHeight
?
2827 desc2
.dwWidth
: desc2
.dwHeight
;
2828 desc2
.u2
.dwMipMapCount
= 0;
2831 desc2
.u2
.dwMipMapCount
+= 1;
2838 /* Not-complex mipmap -> Mipmapcount = 1 */
2839 desc2
.u2
.dwMipMapCount
= 1;
2842 /* There's a mipmap count in the created surface in any case */
2843 desc2
.dwFlags
|= DDSD_MIPMAPCOUNT
;
2845 /* If no mipmap is given, the texture has only one level */
2847 /* The first surface is a front buffer, the back buffer is created afterwards */
2848 if( (desc2
.dwFlags
& DDSD_CAPS
) && (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) )
2850 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
2853 /* The root surface in a cube map is positive x */
2854 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
2856 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
2857 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
2860 if ((desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) && (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
2862 struct wined3d_swapchain_desc swapchain_desc
;
2864 wined3d_swapchain_get_desc(ddraw
->wined3d_swapchain
, &swapchain_desc
);
2865 swapchain_desc
.backbuffer_width
= mode
.width
;
2866 swapchain_desc
.backbuffer_height
= mode
.height
;
2867 swapchain_desc
.backbuffer_format
= mode
.format_id
;
2869 hr
= wined3d_device_reset(ddraw
->wined3d_device
,
2870 &swapchain_desc
, NULL
, ddraw_reset_enum_callback
);
2873 ERR("Failed to reset device.\n");
2878 /* Create the first surface */
2879 if (FAILED(hr
= ddraw_create_surface(ddraw
, &desc2
, &object
, version
)))
2881 WARN("ddraw_create_surface failed, hr %#x.\n", hr
);
2884 object
->is_complex_root
= TRUE
;
2888 /* Create Additional surfaces if necessary
2889 * This applies to Primary surfaces which have a back buffer count
2890 * set, but not to mipmap textures. In case of Mipmap textures,
2891 * wineD3D takes care of the creation of additional surfaces
2893 if(DDSD
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
2895 struct ddraw_surface
*last
= object
;
2898 desc2
.ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
; /* It's not a front buffer */
2899 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
2900 desc2
.dwBackBufferCount
= 0;
2902 for (i
= 0; i
< DDSD
->dwBackBufferCount
; ++i
)
2904 struct ddraw_surface
*object2
= NULL
;
2906 if (FAILED(hr
= ddraw_create_surface(ddraw
, &desc2
, &object2
, version
)))
2909 IDirectDrawSurface7_Release(&object
->IDirectDrawSurface7_iface
);
2910 else if (version
== 4)
2911 IDirectDrawSurface4_Release(&object
->IDirectDrawSurface4_iface
);
2913 IDirectDrawSurface_Release(&object
->IDirectDrawSurface_iface
);
2918 /* Add the new surface to the complex attachment array. */
2919 last
->complex_array
[0] = object2
;
2922 /* Remove the (possible) back buffer cap from the new surface
2923 * description, because only one surface in the flipping chain is a
2924 * back buffer, one is a front buffer, the others are just primary
2926 desc2
.ddsCaps
.dwCaps
&= ~DDSCAPS_BACKBUFFER
;
2930 if (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2931 ddraw
->primary
= object
;
2933 /* Create a WineD3DTexture if a texture was requested */
2934 if (desc2
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
2935 ddraw_surface_create_texture(object
);
2940 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
, DDSURFACEDESC2
*surface_desc
,
2941 IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
2943 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2944 struct ddraw_surface
*impl
;
2947 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2948 iface
, surface_desc
, surface
, outer_unknown
);
2950 wined3d_mutex_lock();
2952 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2954 WARN("Cooperative level not set.\n");
2955 wined3d_mutex_unlock();
2956 return DDERR_NOCOOPERATIVELEVELSET
;
2959 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2961 WARN("Application supplied invalid surface descriptor\n");
2962 wined3d_mutex_unlock();
2963 return DDERR_INVALIDPARAMS
;
2966 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2968 if (TRACE_ON(ddraw
))
2970 TRACE(" (%p) Requesting surface desc :\n", iface
);
2971 DDRAW_dump_surface_desc(surface_desc
);
2974 WARN("Application tried to create an explicit front or back buffer\n");
2975 wined3d_mutex_unlock();
2976 return DDERR_INVALIDCAPS
;
2979 hr
= CreateSurface(ddraw
, surface_desc
, &impl
, outer_unknown
, 7);
2980 wined3d_mutex_unlock();
2987 *surface
= &impl
->IDirectDrawSurface7_iface
;
2988 IDirectDraw7_AddRef(iface
);
2989 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2994 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
2995 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
2997 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2998 struct ddraw_surface
*impl
;
3001 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3002 iface
, surface_desc
, surface
, outer_unknown
);
3004 wined3d_mutex_lock();
3006 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
3008 WARN("Cooperative level not set.\n");
3009 wined3d_mutex_unlock();
3010 return DDERR_NOCOOPERATIVELEVELSET
;
3013 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
3015 WARN("Application supplied invalid surface descriptor\n");
3016 wined3d_mutex_unlock();
3017 return DDERR_INVALIDPARAMS
;
3020 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3022 if (TRACE_ON(ddraw
))
3024 TRACE(" (%p) Requesting surface desc :\n", iface
);
3025 DDRAW_dump_surface_desc(surface_desc
);
3028 WARN("Application tried to create an explicit front or back buffer\n");
3029 wined3d_mutex_unlock();
3030 return DDERR_INVALIDCAPS
;
3033 hr
= CreateSurface(ddraw
, surface_desc
, &impl
, outer_unknown
, 4);
3034 wined3d_mutex_unlock();
3041 *surface
= &impl
->IDirectDrawSurface4_iface
;
3042 IDirectDraw4_AddRef(iface
);
3043 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3048 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
3049 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3051 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3052 struct ddraw_surface
*impl
;
3054 DDSURFACEDESC2 surface_desc2
;
3056 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3057 iface
, surface_desc
, surface
, outer_unknown
);
3059 wined3d_mutex_lock();
3061 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
3063 WARN("Cooperative level not set.\n");
3064 wined3d_mutex_unlock();
3065 return DDERR_NOCOOPERATIVELEVELSET
;
3068 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3070 WARN("Application supplied invalid surface descriptor\n");
3071 wined3d_mutex_unlock();
3072 return DDERR_INVALIDPARAMS
;
3075 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3076 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3078 if (TRACE_ON(ddraw
))
3080 TRACE(" (%p) Requesting surface desc :\n", iface
);
3081 DDRAW_dump_surface_desc((LPDDSURFACEDESC2
)surface_desc
);
3084 WARN("Application tried to create an explicit front or back buffer\n");
3085 wined3d_mutex_unlock();
3086 return DDERR_INVALIDCAPS
;
3089 hr
= CreateSurface(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 2);
3090 wined3d_mutex_unlock();
3097 *surface
= &impl
->IDirectDrawSurface_iface
;
3098 impl
->ifaceToRelease
= NULL
;
3103 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
3104 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3106 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3107 struct ddraw_surface
*impl
;
3109 DDSURFACEDESC2 surface_desc2
;
3111 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3112 iface
, surface_desc
, surface
, outer_unknown
);
3114 wined3d_mutex_lock();
3116 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
3118 WARN("Cooperative level not set.\n");
3119 wined3d_mutex_unlock();
3120 return DDERR_NOCOOPERATIVELEVELSET
;
3123 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3125 WARN("Application supplied invalid surface descriptor\n");
3126 wined3d_mutex_unlock();
3127 return DDERR_INVALIDPARAMS
;
3130 /* Remove front buffer flag, this causes failure in v7, and its added to normal
3131 * primaries anyway. */
3132 surface_desc
->ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
;
3133 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3134 hr
= CreateSurface(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 1);
3135 wined3d_mutex_unlock();
3142 *surface
= &impl
->IDirectDrawSurface_iface
;
3143 impl
->ifaceToRelease
= NULL
;
3148 #define DDENUMSURFACES_SEARCHTYPE (DDENUMSURFACES_CANBECREATED|DDENUMSURFACES_DOESEXIST)
3149 #define DDENUMSURFACES_MATCHTYPE (DDENUMSURFACES_ALL|DDENUMSURFACES_MATCH|DDENUMSURFACES_NOMATCH)
3152 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
3153 const DDPIXELFORMAT
*provided
)
3155 /* Some flags must be present in both or neither for a match. */
3156 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
3157 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
3158 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
3160 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3163 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
3166 if (requested
->dwFlags
& DDPF_FOURCC
)
3167 if (requested
->dwFourCC
!= provided
->dwFourCC
)
3170 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
3171 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3172 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
3175 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3176 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3177 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
3180 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
3181 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
3184 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
3185 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3187 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
3190 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
3191 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
3197 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3206 #define CMP(FLAG, FIELD) \
3207 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3208 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3210 static const struct compare_info compare
[] =
3212 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3213 CMP(BACKBUFFERCOUNT
, dwBackBufferCount
),
3215 CMP(CKDESTBLT
, ddckCKDestBlt
),
3216 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3217 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3218 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3219 CMP(HEIGHT
, dwHeight
),
3220 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3221 CMP(LPSURFACE
, lpSurface
),
3222 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3223 CMP(PITCH
, u1
/* lPitch */),
3224 /* PIXELFORMAT: manual */
3225 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3226 CMP(TEXTURESTAGE
, dwTextureStage
),
3227 CMP(WIDTH
, dwWidth
),
3228 /* ZBUFFERBITDEPTH: "obsolete" */
3235 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3238 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
3240 if (requested
->dwFlags
& compare
[i
].flag
3241 && memcmp((const char *)provided
+ compare
[i
].offset
,
3242 (const char *)requested
+ compare
[i
].offset
,
3243 compare
[i
].size
) != 0)
3247 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3249 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3250 &provided
->u4
.ddpfPixelFormat
))
3257 #undef DDENUMSURFACES_SEARCHTYPE
3258 #undef DDENUMSURFACES_MATCHTYPE
3260 struct surfacescallback2_context
3262 LPDDENUMSURFACESCALLBACK2 func
;
3266 struct surfacescallback_context
3268 LPDDENUMSURFACESCALLBACK func
;
3272 static HRESULT CALLBACK
EnumSurfacesCallback2Thunk(IDirectDrawSurface7
*surface
,
3273 DDSURFACEDESC2
*surface_desc
, void *context
)
3275 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3276 struct surfacescallback2_context
*cbcontext
= context
;
3278 IDirectDrawSurface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
3279 IDirectDrawSurface7_Release(surface
);
3281 return cbcontext
->func(&surface_impl
->IDirectDrawSurface4_iface
,
3282 surface_desc
, cbcontext
->context
);
3285 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3286 DDSURFACEDESC2
*surface_desc
, void *context
)
3288 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3289 struct surfacescallback_context
*cbcontext
= context
;
3291 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
3292 IDirectDrawSurface7_Release(surface
);
3294 return cbcontext
->func(&surface_impl
->IDirectDrawSurface_iface
,
3295 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3298 /*****************************************************************************
3299 * IDirectDraw7::EnumSurfaces
3301 * Loops through all surfaces attached to this device and calls the
3302 * application callback. This can't be relayed to WineD3DDevice,
3303 * because some WineD3DSurfaces' parents are IParent objects
3306 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3307 * DDSD: Description to filter for
3308 * Context: Application-provided pointer, it's passed unmodified to the
3310 * Callback: Address to call for each surface
3313 * DDERR_INVALIDPARAMS if the callback is NULL
3316 *****************************************************************************/
3317 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD Flags
,
3318 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMSURFACESCALLBACK7 Callback
)
3320 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3321 struct ddraw_surface
*surf
;
3323 DDSURFACEDESC2 desc
;
3324 struct list
*entry
, *entry2
;
3326 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3327 iface
, Flags
, DDSD
, Context
, Callback
);
3329 all
= Flags
& DDENUMSURFACES_ALL
;
3330 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
3333 return DDERR_INVALIDPARAMS
;
3335 wined3d_mutex_lock();
3337 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
3338 LIST_FOR_EACH_SAFE(entry
, entry2
, &ddraw
->surface_list
)
3340 surf
= LIST_ENTRY(entry
, struct ddraw_surface
, surface_list_entry
);
3342 if (!surf
->iface_count
)
3344 WARN("Not enumerating surface %p because it doesn't have any references.\n", surf
);
3348 if (all
|| (nomatch
!= ddraw_match_surface_desc(DDSD
, &surf
->surface_desc
)))
3350 TRACE("Enumerating surface %p.\n", surf
);
3351 desc
= surf
->surface_desc
;
3352 IDirectDrawSurface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
3353 if (Callback(&surf
->IDirectDrawSurface7_iface
, &desc
, Context
) != DDENUMRET_OK
)
3355 wined3d_mutex_unlock();
3361 wined3d_mutex_unlock();
3366 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3367 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3369 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3370 struct surfacescallback2_context cbcontext
;
3372 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3373 iface
, flags
, surface_desc
, context
, callback
);
3375 cbcontext
.func
= callback
;
3376 cbcontext
.context
= context
;
3378 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
,
3379 &cbcontext
, EnumSurfacesCallback2Thunk
);
3382 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3383 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3385 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3386 struct surfacescallback_context cbcontext
;
3387 DDSURFACEDESC2 surface_desc2
;
3389 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3390 iface
, flags
, surface_desc
, context
, callback
);
3392 cbcontext
.func
= callback
;
3393 cbcontext
.context
= context
;
3395 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3396 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3397 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3400 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3401 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3403 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3404 struct surfacescallback_context cbcontext
;
3405 DDSURFACEDESC2 surface_desc2
;
3407 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3408 iface
, flags
, surface_desc
, context
, callback
);
3410 cbcontext
.func
= callback
;
3411 cbcontext
.context
= context
;
3413 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3414 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3415 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3418 /*****************************************************************************
3419 * DirectDrawCreateClipper (DDRAW.@)
3421 * Creates a new IDirectDrawClipper object.
3424 * Clipper: Address to write the interface pointer to
3425 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3429 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3430 * E_OUTOFMEMORY if allocating the object failed
3432 *****************************************************************************/
3433 HRESULT WINAPI
DirectDrawCreateClipper(DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3435 struct ddraw_clipper
*object
;
3438 TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
3439 flags
, clipper
, outer_unknown
);
3442 return CLASS_E_NOAGGREGATION
;
3444 wined3d_mutex_lock();
3446 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3449 wined3d_mutex_unlock();
3450 return E_OUTOFMEMORY
;
3453 hr
= ddraw_clipper_init(object
);
3456 WARN("Failed to initialize clipper, hr %#x.\n", hr
);
3457 HeapFree(GetProcessHeap(), 0, object
);
3458 wined3d_mutex_unlock();
3462 TRACE("Created clipper %p.\n", object
);
3463 *clipper
= &object
->IDirectDrawClipper_iface
;
3464 wined3d_mutex_unlock();
3469 /*****************************************************************************
3470 * IDirectDraw7::CreateClipper
3472 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3474 *****************************************************************************/
3475 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3476 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3478 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3479 iface
, Flags
, Clipper
, UnkOuter
);
3481 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3484 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
, DWORD flags
,
3485 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3487 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3489 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3490 iface
, flags
, clipper
, outer_unknown
);
3492 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3495 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
3496 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3498 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3500 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3501 iface
, flags
, clipper
, outer_unknown
);
3503 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3506 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
3507 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3509 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3511 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3512 iface
, flags
, clipper
, outer_unknown
);
3514 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3517 /*****************************************************************************
3518 * IDirectDraw7::CreatePalette
3520 * Creates a new IDirectDrawPalette object
3523 * Flags: The flags for the new clipper
3524 * ColorTable: Color table to assign to the new clipper
3525 * Palette: Address to write the interface pointer to
3526 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3530 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3531 * E_OUTOFMEMORY if allocating the object failed
3533 *****************************************************************************/
3534 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
3535 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
3537 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3538 struct ddraw_palette
*object
;
3541 TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
3542 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3545 return CLASS_E_NOAGGREGATION
;
3547 wined3d_mutex_lock();
3549 /* The refcount test shows that a cooplevel is required for this */
3550 if (!ddraw
->cooperative_level
)
3552 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3553 wined3d_mutex_unlock();
3554 return DDERR_NOCOOPERATIVELEVELSET
;
3557 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(*object
));
3560 ERR("Out of memory when allocating memory for a palette implementation\n");
3561 wined3d_mutex_unlock();
3562 return E_OUTOFMEMORY
;
3565 hr
= ddraw_palette_init(object
, ddraw
, Flags
, ColorTable
);
3568 WARN("Failed to initialize palette, hr %#x.\n", hr
);
3569 HeapFree(GetProcessHeap(), 0, object
);
3570 wined3d_mutex_unlock();
3574 TRACE("Created palette %p.\n", object
);
3575 *Palette
= &object
->IDirectDrawPalette_iface
;
3576 wined3d_mutex_unlock();
3581 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
, PALETTEENTRY
*entries
,
3582 IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3584 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3587 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3588 iface
, flags
, entries
, palette
, outer_unknown
);
3590 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3591 if (SUCCEEDED(hr
) && *palette
)
3593 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3594 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3595 IDirectDraw4_AddRef(iface
);
3596 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3601 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
3602 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3604 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3607 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3608 iface
, flags
, entries
, palette
, outer_unknown
);
3610 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3611 if (SUCCEEDED(hr
) && *palette
)
3613 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3614 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3615 impl
->ifaceToRelease
= NULL
;
3621 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
3622 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3624 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3627 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3628 iface
, flags
, entries
, palette
, outer_unknown
);
3630 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3631 if (SUCCEEDED(hr
) && *palette
)
3633 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3634 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3635 impl
->ifaceToRelease
= NULL
;
3641 /*****************************************************************************
3642 * IDirectDraw7::DuplicateSurface
3644 * Duplicates a surface. The surface memory points to the same memory as
3645 * the original surface, and it's released when the last surface referencing
3646 * it is released. I guess that's beyond Wine's surface management right now
3647 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3648 * test application to implement this)
3651 * Src: Address of the source surface
3652 * Dest: Address to write the new surface pointer to
3655 * See IDirectDraw7::CreateSurface
3657 *****************************************************************************/
3658 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
3659 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
3661 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(Src
);
3663 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
3665 /* For now, simply create a new, independent surface */
3666 return IDirectDraw7_CreateSurface(iface
, &src_surface
->surface_desc
, Dest
, NULL
);
3669 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
, IDirectDrawSurface4
*src
,
3670 IDirectDrawSurface4
**dst
)
3672 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
3673 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3674 struct ddraw_surface
*dst_impl
;
3675 IDirectDrawSurface7
*dst7
;
3678 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3680 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3681 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3687 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3688 *dst
= &dst_impl
->IDirectDrawSurface4_iface
;
3689 IDirectDrawSurface4_AddRef(*dst
);
3690 IDirectDrawSurface7_Release(dst7
);
3695 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
3696 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
3698 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3699 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3700 struct ddraw_surface
*dst_impl
;
3701 IDirectDrawSurface7
*dst7
;
3704 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3706 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3707 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3710 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3711 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3712 IDirectDrawSurface_AddRef(*dst
);
3713 IDirectDrawSurface7_Release(dst7
);
3718 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
, IDirectDrawSurface
*src
,
3719 IDirectDrawSurface
**dst
)
3721 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3722 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3723 struct ddraw_surface
*dst_impl
;
3724 IDirectDrawSurface7
*dst7
;
3727 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3729 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3730 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3733 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3734 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3735 IDirectDrawSurface_AddRef(*dst
);
3736 IDirectDrawSurface7_Release(dst7
);
3741 /*****************************************************************************
3742 * IDirect3D7::EnumDevices
3744 * The EnumDevices method for IDirect3D7. It enumerates all supported
3745 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
3748 * callback: Function to call for each enumerated device
3749 * context: Pointer to pass back to the app
3752 * D3D_OK, or the return value of the GetCaps call
3754 *****************************************************************************/
3755 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
3757 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
3758 D3DDEVICEDESC7 device_desc7
;
3759 D3DDEVICEDESC device_desc1
;
3763 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3766 return DDERR_INVALIDPARAMS
;
3768 wined3d_mutex_lock();
3770 hr
= IDirect3DImpl_GetCaps(ddraw
->wined3d
, &device_desc1
, &device_desc7
);
3773 wined3d_mutex_unlock();
3777 for (i
= 0; i
< sizeof(device_list7
)/sizeof(device_list7
[0]); i
++)
3781 device_desc7
.deviceGUID
= *device_list7
[i
].device_guid
;
3782 ret
= callback(device_list7
[i
].interface_name
, device_list7
[i
].device_name
, &device_desc7
, context
);
3783 if (ret
!= DDENUMRET_OK
)
3785 TRACE("Application cancelled the enumeration.\n");
3786 wined3d_mutex_unlock();
3791 TRACE("End of enumeration.\n");
3793 wined3d_mutex_unlock();
3798 /*****************************************************************************
3799 * IDirect3D3::EnumDevices
3801 * Enumerates all supported Direct3DDevice interfaces. This is the
3802 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
3804 * Version 1, 2 and 3
3807 * callback: Application-provided routine to call for each enumerated device
3808 * Context: Pointer to pass to the callback
3811 * D3D_OK on success,
3812 * The result of IDirect3DImpl_GetCaps if it failed
3814 *****************************************************************************/
3815 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3817 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
3819 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3820 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
3821 D3DDEVICEDESC7 device_desc7
;
3824 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
3825 * name string. Let's put the string in a sufficiently sized array in
3826 * writable memory. */
3827 char device_name
[50];
3828 strcpy(device_name
,"Direct3D HEL");
3830 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3833 return DDERR_INVALIDPARAMS
;
3835 wined3d_mutex_lock();
3837 hr
= IDirect3DImpl_GetCaps(ddraw
->wined3d
, &device_desc1
, &device_desc7
);
3840 wined3d_mutex_unlock();
3844 /* Do I have to enumerate the reference id? Note from old d3d7:
3845 * "It seems that enumerating the reference IID on Direct3D 1 games
3846 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
3848 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
3849 * EnumReference which enables / disables enumerating the reference
3850 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
3851 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
3852 * demo directory suggest this.
3854 * Some games(GTA 2) seem to use the second enumerated device, so I have
3855 * to enumerate at least 2 devices. So enumerate the reference device to
3858 * Other games (Rollcage) tell emulation and hal device apart by certain
3859 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
3860 * limitation flag), and it refuses all devices that have the perspective
3861 * flag set. This way it refuses the emulation device, and HAL devices
3862 * never have POW2 unset in d3d7 on windows. */
3863 if (ddraw
->d3dversion
!= 1)
3865 static CHAR reference_description
[] = "RGB Direct3D emulation";
3867 TRACE("Enumerating WineD3D D3DDevice interface.\n");
3868 hal_desc
= device_desc1
;
3869 hel_desc
= device_desc1
;
3870 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
3871 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3872 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3873 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3874 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3875 /* RGB, RAMP and MMX devices have a HAL dcmColorModel of 0 */
3876 hal_desc
.dcmColorModel
= 0;
3878 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
3879 device_name
, &hal_desc
, &hel_desc
, context
);
3880 if (hr
!= D3DENUMRET_OK
)
3882 TRACE("Application cancelled the enumeration.\n");
3883 wined3d_mutex_unlock();
3888 strcpy(device_name
,"Direct3D HAL");
3890 TRACE("Enumerating HAL Direct3D device.\n");
3891 hal_desc
= device_desc1
;
3892 hel_desc
= device_desc1
;
3894 /* The hal device does not have the pow2 flag set in hel, but in hal. */
3895 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3896 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3897 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3898 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3899 /* HAL devices have a HEL dcmColorModel of 0 */
3900 hel_desc
.dcmColorModel
= 0;
3902 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
3903 device_name
, &hal_desc
, &hel_desc
, context
);
3904 if (hr
!= D3DENUMRET_OK
)
3906 TRACE("Application cancelled the enumeration.\n");
3907 wined3d_mutex_unlock();
3911 TRACE("End of enumeration.\n");
3913 wined3d_mutex_unlock();
3918 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3920 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3922 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3924 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3927 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3929 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3931 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3933 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3936 /*****************************************************************************
3937 * IDirect3D3::CreateLight
3939 * Creates an IDirect3DLight interface. This interface is used in
3940 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
3941 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
3942 * uses the IDirect3DDevice7 interface with D3D7 lights.
3944 * Version 1, 2 and 3
3947 * light: Address to store the new interface pointer
3948 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3953 * DDERR_OUTOFMEMORY if memory allocation failed
3954 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3956 *****************************************************************************/
3957 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
,
3958 IUnknown
*outer_unknown
)
3960 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3961 struct d3d_light
*object
;
3963 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3965 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3967 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3970 ERR("Failed to allocate light memory.\n");
3971 return DDERR_OUTOFMEMORY
;
3974 d3d_light_init(object
, ddraw
);
3976 TRACE("Created light %p.\n", object
);
3977 *light
= &object
->IDirect3DLight_iface
;
3982 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3984 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3986 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3988 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3991 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3993 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3995 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3997 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
4000 /*****************************************************************************
4001 * IDirect3D3::CreateMaterial
4003 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
4004 * and older versions. The IDirect3DMaterial implementation wraps its
4005 * functionality to IDirect3DDevice7::SetMaterial and friends.
4007 * Version 1, 2 and 3
4010 * material: Address to store the new interface's pointer to
4011 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4016 * DDERR_OUTOFMEMORY if memory allocation failed
4017 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4019 *****************************************************************************/
4020 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
,
4021 IUnknown
*outer_unknown
)
4023 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4024 struct d3d_material
*object
;
4026 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4028 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4030 object
= d3d_material_create(ddraw
);
4033 ERR("Failed to allocate material memory.\n");
4034 return DDERR_OUTOFMEMORY
;
4037 TRACE("Created material %p.\n", object
);
4038 *material
= &object
->IDirect3DMaterial3_iface
;
4043 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
,
4044 IUnknown
*outer_unknown
)
4046 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4047 struct d3d_material
*object
;
4049 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4051 object
= d3d_material_create(ddraw
);
4054 ERR("Failed to allocate material memory.\n");
4055 return DDERR_OUTOFMEMORY
;
4058 TRACE("Created material %p.\n", object
);
4059 *material
= &object
->IDirect3DMaterial2_iface
;
4064 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
,
4065 IUnknown
*outer_unknown
)
4067 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4068 struct d3d_material
*object
;
4070 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4072 object
= d3d_material_create(ddraw
);
4075 ERR("Failed to allocate material memory.\n");
4076 return DDERR_OUTOFMEMORY
;
4079 TRACE("Created material %p.\n", object
);
4080 *material
= &object
->IDirect3DMaterial_iface
;
4085 /*****************************************************************************
4086 * IDirect3D3::CreateViewport
4088 * Creates an IDirect3DViewport interface. This interface is used
4089 * by Direct3D and earlier versions for Viewport management. In Direct3D7
4090 * it has been replaced by a viewport structure and
4091 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
4092 * uses the IDirect3DDevice7 methods for its functionality
4095 * Viewport: Address to store the new interface pointer
4096 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4101 * DDERR_OUTOFMEMORY if memory allocation failed
4102 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4104 *****************************************************************************/
4105 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
,
4106 IUnknown
*outer_unknown
)
4108 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4109 struct d3d_viewport
*object
;
4111 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4113 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4115 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4118 ERR("Failed to allocate viewport memory.\n");
4119 return DDERR_OUTOFMEMORY
;
4122 d3d_viewport_init(object
, ddraw
);
4124 TRACE("Created viewport %p.\n", object
);
4125 *viewport
= &object
->IDirect3DViewport3_iface
;
4130 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
4132 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4134 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4136 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4140 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
4142 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4144 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4146 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4150 /*****************************************************************************
4151 * IDirect3D3::FindDevice
4153 * This method finds a device with the requested properties and returns a
4154 * device description
4158 * fds: Describes the requested device characteristics
4159 * fdr: Returns the device description
4163 * DDERR_INVALIDPARAMS if no device was found
4165 *****************************************************************************/
4166 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4168 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4169 D3DDEVICEDESC7 desc7
;
4170 D3DDEVICEDESC desc1
;
4173 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4175 if (!fds
|| !fdr
) return DDERR_INVALIDPARAMS
;
4177 if (fds
->dwSize
!= sizeof(D3DFINDDEVICESEARCH
)
4178 || fdr
->dwSize
!= sizeof(D3DFINDDEVICERESULT
))
4179 return DDERR_INVALIDPARAMS
;
4181 if ((fds
->dwFlags
& D3DFDS_COLORMODEL
)
4182 && fds
->dcmColorModel
!= D3DCOLOR_RGB
)
4184 WARN("Trying to request a non-RGB D3D color model. Not supported.\n");
4185 return DDERR_INVALIDPARAMS
; /* No real idea what to return here :-) */
4188 if (fds
->dwFlags
& D3DFDS_GUID
)
4190 TRACE("Trying to match guid %s.\n", debugstr_guid(&(fds
->guid
)));
4191 if (!IsEqualGUID(&IID_D3DDEVICE_WineD3D
, &fds
->guid
)
4192 && !IsEqualGUID(&IID_IDirect3DHALDevice
, &fds
->guid
)
4193 && !IsEqualGUID(&IID_IDirect3DRGBDevice
, &fds
->guid
))
4195 WARN("No match for this GUID.\n");
4196 return DDERR_NOTFOUND
;
4201 hr
= IDirect3DImpl_GetCaps(ddraw
->wined3d
, &desc1
, &desc7
);
4202 if (hr
!= D3D_OK
) return hr
;
4204 /* Now return our own GUID */
4205 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4206 fdr
->ddHwDesc
= desc1
;
4207 fdr
->ddSwDesc
= desc1
;
4209 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4214 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4216 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4218 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4220 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4223 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4225 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4227 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4229 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4232 /*****************************************************************************
4233 * IDirect3D7::CreateDevice
4235 * Creates an IDirect3DDevice7 interface.
4237 * Version 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4238 * DirectDraw surfaces and are created with
4239 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4240 * create the device object and QueryInterfaces for IDirect3DDevice
4243 * refiid: IID of the device to create
4244 * Surface: Initial rendertarget
4245 * Device: Address to return the interface pointer
4249 * DDERR_OUTOFMEMORY if memory allocation failed
4250 * DDERR_INVALIDPARAMS if a device exists already
4252 *****************************************************************************/
4253 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4254 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4256 struct ddraw_surface
*target
= unsafe_impl_from_IDirectDrawSurface7(surface
);
4257 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4258 struct d3d_device
*object
;
4261 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4263 wined3d_mutex_lock();
4264 hr
= d3d_device_create(ddraw
, target
, 7, &object
, NULL
);
4266 *device
= &object
->IDirect3DDevice7_iface
;
4269 WARN("Failed to create device, hr %#x.\n", hr
);
4272 wined3d_mutex_unlock();
4277 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4278 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4280 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface4(surface
);
4281 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4282 struct d3d_device
*device_impl
;
4285 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4286 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4289 return CLASS_E_NOAGGREGATION
;
4291 wined3d_mutex_lock();
4292 hr
= d3d_device_create(ddraw
, surface_impl
, 3, &device_impl
, NULL
);
4294 *device
= &device_impl
->IDirect3DDevice3_iface
;
4297 WARN("Failed to create device, hr %#x.\n", hr
);
4300 wined3d_mutex_unlock();
4305 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4306 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4308 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface(surface
);
4309 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4310 struct d3d_device
*device_impl
;
4313 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4314 iface
, debugstr_guid(riid
), surface
, device
);
4316 wined3d_mutex_lock();
4317 hr
= d3d_device_create(ddraw
, surface_impl
, 2, &device_impl
, NULL
);
4319 *device
= &device_impl
->IDirect3DDevice2_iface
;
4322 WARN("Failed to create device, hr %#x.\n", hr
);
4325 wined3d_mutex_unlock();
4330 /*****************************************************************************
4331 * IDirect3D7::CreateVertexBuffer
4333 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4339 * desc: Requested Vertex buffer properties
4340 * vertex_buffer: Address to return the interface pointer at
4341 * flags: Some flags, should be 0
4345 * DDERR_OUTOFMEMORY if memory allocation failed
4346 * The return value of IWineD3DDevice::CreateVertexBuffer if this call fails
4347 * DDERR_INVALIDPARAMS if desc or vertex_buffer are NULL
4349 *****************************************************************************/
4350 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4351 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4353 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4354 struct d3d_vertex_buffer
*object
;
4357 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
4358 iface
, desc
, vertex_buffer
, flags
);
4360 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4362 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4365 TRACE("Created vertex buffer %p.\n", object
);
4366 *vertex_buffer
= &object
->IDirect3DVertexBuffer7_iface
;
4369 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4374 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4375 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4377 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4378 struct d3d_vertex_buffer
*object
;
4381 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n",
4382 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4385 return CLASS_E_NOAGGREGATION
;
4386 if (!vertex_buffer
|| !desc
)
4387 return DDERR_INVALIDPARAMS
;
4389 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4392 TRACE("Created vertex buffer %p.\n", object
);
4393 *vertex_buffer
= &object
->IDirect3DVertexBuffer_iface
;
4396 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4401 /*****************************************************************************
4402 * IDirect3D7::EnumZBufferFormats
4404 * Enumerates all supported Z buffer pixel formats
4410 * callback: callback to call for each pixel format
4411 * context: Pointer to pass back to the callback
4415 * DDERR_INVALIDPARAMS if callback is NULL
4416 * For details, see IWineD3DDevice::EnumZBufferFormats
4418 *****************************************************************************/
4419 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4420 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4422 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4423 struct wined3d_display_mode mode
;
4424 enum wined3d_device_type type
;
4428 /* Order matters. Specifically, BattleZone II (full version) expects the
4429 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4430 static const enum wined3d_format_id formats
[] =
4432 WINED3DFMT_S1_UINT_D15_UNORM
,
4433 WINED3DFMT_D16_UNORM
,
4434 WINED3DFMT_X8D24_UNORM
,
4435 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4436 WINED3DFMT_D24_UNORM_S8_UINT
,
4437 WINED3DFMT_D32_UNORM
,
4440 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4441 iface
, debugstr_guid(device_iid
), callback
, context
);
4443 if (!callback
) return DDERR_INVALIDPARAMS
;
4445 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4446 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4447 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4449 TRACE("Asked for HAL device.\n");
4450 type
= WINED3D_DEVICE_TYPE_HAL
;
4452 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4453 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4455 TRACE("Asked for SW device.\n");
4456 type
= WINED3D_DEVICE_TYPE_SW
;
4458 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4460 TRACE("Asked for REF device.\n");
4461 type
= WINED3D_DEVICE_TYPE_REF
;
4463 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4465 TRACE("Asked for NULLREF device.\n");
4466 type
= WINED3D_DEVICE_TYPE_NULLREF
;
4470 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4471 type
= WINED3D_DEVICE_TYPE_HAL
;
4474 wined3d_mutex_lock();
4475 /* We need an adapter format from somewhere to please wined3d and WGL.
4476 * Use the current display mode. So far all cards offer the same depth
4477 * stencil format for all modes, but if some do not and applications do
4478 * not like that we'll have to find some workaround, like iterating over
4479 * all imaginable formats and collecting all the depth stencil formats we
4481 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
4483 ERR("Failed to get display mode, hr %#x.\n", hr
);
4484 wined3d_mutex_unlock();
4488 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
4490 hr
= wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4491 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_SURFACE
, formats
[i
], WINED3D_SURFACE_TYPE_OPENGL
);
4494 DDPIXELFORMAT pformat
;
4496 memset(&pformat
, 0, sizeof(pformat
));
4497 pformat
.dwSize
= sizeof(pformat
);
4498 PixelFormat_WineD3DtoDD(&pformat
, formats
[i
]);
4500 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
4501 hr
= callback(&pformat
, context
);
4502 if (hr
!= DDENUMRET_OK
)
4504 TRACE("Format enumeration cancelled by application.\n");
4505 wined3d_mutex_unlock();
4511 /* Historically some windows drivers used dwZBufferBitDepth=24 for WINED3DFMT_X8D24_UNORM,
4512 * while others used dwZBufferBitDepth=32. In either case the pitch matches a 32 bits per
4513 * pixel format, so we use dwZBufferBitDepth=32. Some games expect 24. Windows Vista and
4514 * newer enumerate both versions, so we do the same(bug 22434) */
4515 hr
= wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4516 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_SURFACE
, WINED3DFMT_X8D24_UNORM
, WINED3D_SURFACE_TYPE_OPENGL
);
4519 DDPIXELFORMAT x8d24
=
4521 sizeof(x8d24
), DDPF_ZBUFFER
, 0,
4522 {24}, {0x00000000}, {0x00ffffff}, {0x00000000}
4524 TRACE("Enumerating WINED3DFMT_X8D24_UNORM, dwZBufferBitDepth=24 version\n");
4525 callback(&x8d24
, context
);
4528 TRACE("End of enumeration.\n");
4530 wined3d_mutex_unlock();
4535 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
4536 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4538 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4540 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4541 iface
, debugstr_guid(device_iid
), callback
, context
);
4543 return d3d7_EnumZBufferFormats(&ddraw
->IDirect3D7_iface
, device_iid
, callback
, context
);
4546 /*****************************************************************************
4547 * IDirect3D7::EvictManagedTextures
4549 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
4550 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
4555 * D3D_OK, because it's a stub
4557 *****************************************************************************/
4558 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
4560 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4562 TRACE("iface %p!\n", iface
);
4564 wined3d_mutex_lock();
4565 if (ddraw
->d3d_initialized
)
4566 wined3d_device_evict_managed_resources(ddraw
->wined3d_device
);
4567 wined3d_mutex_unlock();
4572 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
4574 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4576 TRACE("iface %p.\n", iface
);
4578 return d3d7_EvictManagedTextures(&ddraw
->IDirect3D7_iface
);
4581 /*****************************************************************************
4582 * IDirect3DImpl_GetCaps
4584 * This function retrieves the device caps from wined3d
4585 * and converts it into a D3D7 and D3D - D3D3 structure
4586 * This is a helper function called from various places in ddraw
4589 * wined3d: The interface to get the caps from
4590 * desc1: Old D3D <3 structure to fill (needed)
4591 * desc7: D3D7 device desc structure to fill (needed)
4594 * D3D_OK on success, or the return value of IWineD3D::GetCaps
4596 *****************************************************************************/
4597 HRESULT
IDirect3DImpl_GetCaps(const struct wined3d
*wined3d
, D3DDEVICEDESC
*desc1
, D3DDEVICEDESC7
*desc7
)
4599 WINED3DCAPS wined3d_caps
;
4602 TRACE("wined3d %p, desc1 %p, desc7 %p.\n", wined3d
, desc1
, desc7
);
4604 memset(&wined3d_caps
, 0, sizeof(wined3d_caps
));
4606 wined3d_mutex_lock();
4607 hr
= wined3d_get_device_caps(wined3d
, 0, WINED3D_DEVICE_TYPE_HAL
, &wined3d_caps
);
4608 wined3d_mutex_unlock();
4611 WARN("Failed to get device caps, hr %#x.\n", hr
);
4615 /* Copy the results into the d3d7 and d3d3 structures */
4616 desc7
->dwDevCaps
= wined3d_caps
.DevCaps
;
4617 desc7
->dpcLineCaps
.dwMiscCaps
= wined3d_caps
.PrimitiveMiscCaps
;
4618 desc7
->dpcLineCaps
.dwRasterCaps
= wined3d_caps
.RasterCaps
;
4619 desc7
->dpcLineCaps
.dwZCmpCaps
= wined3d_caps
.ZCmpCaps
;
4620 desc7
->dpcLineCaps
.dwSrcBlendCaps
= wined3d_caps
.SrcBlendCaps
;
4621 desc7
->dpcLineCaps
.dwDestBlendCaps
= wined3d_caps
.DestBlendCaps
;
4622 desc7
->dpcLineCaps
.dwAlphaCmpCaps
= wined3d_caps
.AlphaCmpCaps
;
4623 desc7
->dpcLineCaps
.dwShadeCaps
= wined3d_caps
.ShadeCaps
;
4624 desc7
->dpcLineCaps
.dwTextureCaps
= wined3d_caps
.TextureCaps
;
4625 desc7
->dpcLineCaps
.dwTextureFilterCaps
= wined3d_caps
.TextureFilterCaps
;
4626 desc7
->dpcLineCaps
.dwTextureAddressCaps
= wined3d_caps
.TextureAddressCaps
;
4628 desc7
->dwMaxTextureWidth
= wined3d_caps
.MaxTextureWidth
;
4629 desc7
->dwMaxTextureHeight
= wined3d_caps
.MaxTextureHeight
;
4631 desc7
->dwMaxTextureRepeat
= wined3d_caps
.MaxTextureRepeat
;
4632 desc7
->dwMaxTextureAspectRatio
= wined3d_caps
.MaxTextureAspectRatio
;
4633 desc7
->dwMaxAnisotropy
= wined3d_caps
.MaxAnisotropy
;
4634 desc7
->dvMaxVertexW
= wined3d_caps
.MaxVertexW
;
4636 desc7
->dvGuardBandLeft
= wined3d_caps
.GuardBandLeft
;
4637 desc7
->dvGuardBandTop
= wined3d_caps
.GuardBandTop
;
4638 desc7
->dvGuardBandRight
= wined3d_caps
.GuardBandRight
;
4639 desc7
->dvGuardBandBottom
= wined3d_caps
.GuardBandBottom
;
4641 desc7
->dvExtentsAdjust
= wined3d_caps
.ExtentsAdjust
;
4642 desc7
->dwStencilCaps
= wined3d_caps
.StencilCaps
;
4644 desc7
->dwFVFCaps
= wined3d_caps
.FVFCaps
;
4645 desc7
->dwTextureOpCaps
= wined3d_caps
.TextureOpCaps
;
4647 desc7
->dwVertexProcessingCaps
= wined3d_caps
.VertexProcessingCaps
;
4648 desc7
->dwMaxActiveLights
= wined3d_caps
.MaxActiveLights
;
4650 /* Remove all non-d3d7 caps */
4651 desc7
->dwDevCaps
&= (
4652 D3DDEVCAPS_FLOATTLVERTEX
| D3DDEVCAPS_SORTINCREASINGZ
| D3DDEVCAPS_SORTDECREASINGZ
|
4653 D3DDEVCAPS_SORTEXACT
| D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
|
4654 D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
| D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
|
4655 D3DDEVCAPS_TEXTUREVIDEOMEMORY
| D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
|
4656 D3DDEVCAPS_TEXTURENONLOCALVIDMEM
| D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
4657 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
4658 D3DDEVCAPS_HWRASTERIZATION
);
4660 desc7
->dwStencilCaps
&= (
4661 D3DSTENCILCAPS_KEEP
| D3DSTENCILCAPS_ZERO
| D3DSTENCILCAPS_REPLACE
|
4662 D3DSTENCILCAPS_INCRSAT
| D3DSTENCILCAPS_DECRSAT
| D3DSTENCILCAPS_INVERT
|
4663 D3DSTENCILCAPS_INCR
| D3DSTENCILCAPS_DECR
);
4667 desc7
->dwTextureOpCaps
&= (
4668 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_SELECTARG2
|
4669 D3DTEXOPCAPS_MODULATE
| D3DTEXOPCAPS_MODULATE2X
| D3DTEXOPCAPS_MODULATE4X
|
4670 D3DTEXOPCAPS_ADD
| D3DTEXOPCAPS_ADDSIGNED
| D3DTEXOPCAPS_ADDSIGNED2X
|
4671 D3DTEXOPCAPS_SUBTRACT
| D3DTEXOPCAPS_ADDSMOOTH
| D3DTEXOPCAPS_BLENDTEXTUREALPHA
|
4672 D3DTEXOPCAPS_BLENDFACTORALPHA
| D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
| D3DTEXOPCAPS_BLENDCURRENTALPHA
|
4673 D3DTEXOPCAPS_PREMODULATE
| D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
|
4674 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
| D3DTEXOPCAPS_BUMPENVMAP
|
4675 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
| D3DTEXOPCAPS_DOTPRODUCT3
);
4677 desc7
->dwVertexProcessingCaps
&= (
4678 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_VERTEXFOG
|
4679 D3DVTXPCAPS_DIRECTIONALLIGHTS
| D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
);
4681 desc7
->dpcLineCaps
.dwMiscCaps
&= (
4682 D3DPMISCCAPS_MASKPLANES
| D3DPMISCCAPS_MASKZ
| D3DPMISCCAPS_LINEPATTERNREP
|
4683 D3DPMISCCAPS_CONFORMANT
| D3DPMISCCAPS_CULLNONE
| D3DPMISCCAPS_CULLCW
|
4684 D3DPMISCCAPS_CULLCCW
);
4686 desc7
->dpcLineCaps
.dwRasterCaps
&= (
4687 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ROP2
| D3DPRASTERCAPS_XOR
|
4688 D3DPRASTERCAPS_PAT
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_SUBPIXEL
|
4689 D3DPRASTERCAPS_SUBPIXELX
| D3DPRASTERCAPS_FOGVERTEX
| D3DPRASTERCAPS_FOGTABLE
|
4690 D3DPRASTERCAPS_STIPPLE
| D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT
| D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT
|
4691 D3DPRASTERCAPS_ANTIALIASEDGES
| D3DPRASTERCAPS_MIPMAPLODBIAS
| D3DPRASTERCAPS_ZBIAS
|
4692 D3DPRASTERCAPS_ZBUFFERLESSHSR
| D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
|
4693 D3DPRASTERCAPS_WBUFFER
| D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT
| D3DPRASTERCAPS_WFOG
|
4694 D3DPRASTERCAPS_ZFOG
);
4696 desc7
->dpcLineCaps
.dwZCmpCaps
&= (
4697 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
4698 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
4699 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
4701 desc7
->dpcLineCaps
.dwSrcBlendCaps
&= (
4702 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
4703 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
4704 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
4705 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
4706 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
4708 desc7
->dpcLineCaps
.dwDestBlendCaps
&= (
4709 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
4710 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
4711 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
4712 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
4713 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
4715 desc7
->dpcLineCaps
.dwAlphaCmpCaps
&= (
4716 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
4717 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
4718 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
4720 desc7
->dpcLineCaps
.dwShadeCaps
&= (
4721 D3DPSHADECAPS_COLORFLATMONO
| D3DPSHADECAPS_COLORFLATRGB
| D3DPSHADECAPS_COLORGOURAUDMONO
|
4722 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_COLORPHONGMONO
| D3DPSHADECAPS_COLORPHONGRGB
|
4723 D3DPSHADECAPS_SPECULARFLATMONO
| D3DPSHADECAPS_SPECULARFLATRGB
| D3DPSHADECAPS_SPECULARGOURAUDMONO
|
4724 D3DPSHADECAPS_SPECULARGOURAUDRGB
| D3DPSHADECAPS_SPECULARPHONGMONO
| D3DPSHADECAPS_SPECULARPHONGRGB
|
4725 D3DPSHADECAPS_ALPHAFLATBLEND
| D3DPSHADECAPS_ALPHAFLATSTIPPLED
| D3DPSHADECAPS_ALPHAGOURAUDBLEND
|
4726 D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED
| D3DPSHADECAPS_ALPHAPHONGBLEND
| D3DPSHADECAPS_ALPHAPHONGSTIPPLED
|
4727 D3DPSHADECAPS_FOGFLAT
| D3DPSHADECAPS_FOGGOURAUD
| D3DPSHADECAPS_FOGPHONG
);
4729 desc7
->dpcLineCaps
.dwTextureCaps
&= (
4730 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
4731 D3DPTEXTURECAPS_TRANSPARENCY
| D3DPTEXTURECAPS_BORDER
| D3DPTEXTURECAPS_SQUAREONLY
|
4732 D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
| D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
4733 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_COLORKEYBLEND
);
4735 desc7
->dpcLineCaps
.dwTextureFilterCaps
&= (
4736 D3DPTFILTERCAPS_NEAREST
| D3DPTFILTERCAPS_LINEAR
| D3DPTFILTERCAPS_MIPNEAREST
|
4737 D3DPTFILTERCAPS_MIPLINEAR
| D3DPTFILTERCAPS_LINEARMIPNEAREST
| D3DPTFILTERCAPS_LINEARMIPLINEAR
|
4738 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
4739 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
4740 D3DPTFILTERCAPS_MAGFLINEAR
| D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
|
4741 D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
);
4743 desc7
->dpcLineCaps
.dwTextureBlendCaps
&= (
4744 D3DPTBLENDCAPS_DECAL
| D3DPTBLENDCAPS_MODULATE
| D3DPTBLENDCAPS_DECALALPHA
|
4745 D3DPTBLENDCAPS_MODULATEALPHA
| D3DPTBLENDCAPS_DECALMASK
| D3DPTBLENDCAPS_MODULATEMASK
|
4746 D3DPTBLENDCAPS_COPY
| D3DPTBLENDCAPS_ADD
);
4748 desc7
->dpcLineCaps
.dwTextureAddressCaps
&= (
4749 D3DPTADDRESSCAPS_WRAP
| D3DPTADDRESSCAPS_MIRROR
| D3DPTADDRESSCAPS_CLAMP
|
4750 D3DPTADDRESSCAPS_BORDER
| D3DPTADDRESSCAPS_INDEPENDENTUV
);
4752 if (!(desc7
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
))
4754 /* DirectX7 always has the np2 flag set, no matter what the card
4755 * supports. Some old games (Rollcage) check the caps incorrectly.
4756 * If wined3d supports nonpow2 textures it also has np2 conditional
4758 desc7
->dpcLineCaps
.dwTextureCaps
|= D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
;
4761 /* Fill the missing members, and do some fixup */
4762 desc7
->dpcLineCaps
.dwSize
= sizeof(desc7
->dpcLineCaps
);
4763 desc7
->dpcLineCaps
.dwTextureBlendCaps
= D3DPTBLENDCAPS_ADD
| D3DPTBLENDCAPS_MODULATEMASK
|
4764 D3DPTBLENDCAPS_COPY
| D3DPTBLENDCAPS_DECAL
|
4765 D3DPTBLENDCAPS_DECALALPHA
| D3DPTBLENDCAPS_DECALMASK
|
4766 D3DPTBLENDCAPS_MODULATE
| D3DPTBLENDCAPS_MODULATEALPHA
;
4767 desc7
->dpcLineCaps
.dwStippleWidth
= 32;
4768 desc7
->dpcLineCaps
.dwStippleHeight
= 32;
4769 /* Use the same for the TriCaps */
4770 desc7
->dpcTriCaps
= desc7
->dpcLineCaps
;
4772 desc7
->dwDeviceRenderBitDepth
= DDBD_16
| DDBD_24
| DDBD_32
;
4773 desc7
->dwDeviceZBufferBitDepth
= DDBD_16
| DDBD_24
;
4774 desc7
->dwMinTextureWidth
= 1;
4775 desc7
->dwMinTextureHeight
= 1;
4777 /* Convert DWORDs safely to WORDs */
4778 if (wined3d_caps
.MaxTextureBlendStages
> 0xffff) desc7
->wMaxTextureBlendStages
= 0xffff;
4779 else desc7
->wMaxTextureBlendStages
= (WORD
)wined3d_caps
.MaxTextureBlendStages
;
4780 if (wined3d_caps
.MaxSimultaneousTextures
> 0xffff) desc7
->wMaxSimultaneousTextures
= 0xffff;
4781 else desc7
->wMaxSimultaneousTextures
= (WORD
)wined3d_caps
.MaxSimultaneousTextures
;
4783 if (wined3d_caps
.MaxUserClipPlanes
> 0xffff) desc7
->wMaxUserClipPlanes
= 0xffff;
4784 else desc7
->wMaxUserClipPlanes
= (WORD
)wined3d_caps
.MaxUserClipPlanes
;
4785 if (wined3d_caps
.MaxVertexBlendMatrices
> 0xffff) desc7
->wMaxVertexBlendMatrices
= 0xffff;
4786 else desc7
->wMaxVertexBlendMatrices
= (WORD
)wined3d_caps
.MaxVertexBlendMatrices
;
4788 desc7
->deviceGUID
= IID_IDirect3DTnLHalDevice
;
4790 desc7
->dwReserved1
= 0;
4791 desc7
->dwReserved2
= 0;
4792 desc7
->dwReserved3
= 0;
4793 desc7
->dwReserved4
= 0;
4795 /* Fill the old structure */
4796 memset(desc1
, 0, sizeof(*desc1
));
4797 desc1
->dwSize
= sizeof(D3DDEVICEDESC
);
4798 desc1
->dwFlags
= D3DDD_COLORMODEL
4800 | D3DDD_TRANSFORMCAPS
4802 | D3DDD_LIGHTINGCAPS
4805 | D3DDD_DEVICERENDERBITDEPTH
4806 | D3DDD_DEVICEZBUFFERBITDEPTH
4807 | D3DDD_MAXBUFFERSIZE
4808 | D3DDD_MAXVERTEXCOUNT
;
4810 desc1
->dcmColorModel
= D3DCOLOR_RGB
;
4811 desc1
->dwDevCaps
= desc7
->dwDevCaps
;
4812 desc1
->dtcTransformCaps
.dwSize
= sizeof(D3DTRANSFORMCAPS
);
4813 desc1
->dtcTransformCaps
.dwCaps
= D3DTRANSFORMCAPS_CLIP
;
4814 desc1
->bClipping
= TRUE
;
4815 desc1
->dlcLightingCaps
.dwSize
= sizeof(D3DLIGHTINGCAPS
);
4816 desc1
->dlcLightingCaps
.dwCaps
= D3DLIGHTCAPS_DIRECTIONAL
4817 | D3DLIGHTCAPS_PARALLELPOINT
4818 | D3DLIGHTCAPS_POINT
4819 | D3DLIGHTCAPS_SPOT
;
4821 desc1
->dlcLightingCaps
.dwLightingModel
= D3DLIGHTINGMODEL_RGB
;
4822 desc1
->dlcLightingCaps
.dwNumLights
= desc7
->dwMaxActiveLights
;
4824 desc1
->dpcLineCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
4825 desc1
->dpcLineCaps
.dwMiscCaps
= desc7
->dpcLineCaps
.dwMiscCaps
;
4826 desc1
->dpcLineCaps
.dwRasterCaps
= desc7
->dpcLineCaps
.dwRasterCaps
;
4827 desc1
->dpcLineCaps
.dwZCmpCaps
= desc7
->dpcLineCaps
.dwZCmpCaps
;
4828 desc1
->dpcLineCaps
.dwSrcBlendCaps
= desc7
->dpcLineCaps
.dwSrcBlendCaps
;
4829 desc1
->dpcLineCaps
.dwDestBlendCaps
= desc7
->dpcLineCaps
.dwDestBlendCaps
;
4830 desc1
->dpcLineCaps
.dwShadeCaps
= desc7
->dpcLineCaps
.dwShadeCaps
;
4831 desc1
->dpcLineCaps
.dwTextureCaps
= desc7
->dpcLineCaps
.dwTextureCaps
;
4832 desc1
->dpcLineCaps
.dwTextureFilterCaps
= desc7
->dpcLineCaps
.dwTextureFilterCaps
;
4833 desc1
->dpcLineCaps
.dwTextureBlendCaps
= desc7
->dpcLineCaps
.dwTextureBlendCaps
;
4834 desc1
->dpcLineCaps
.dwTextureAddressCaps
= desc7
->dpcLineCaps
.dwTextureAddressCaps
;
4835 desc1
->dpcLineCaps
.dwStippleWidth
= desc7
->dpcLineCaps
.dwStippleWidth
;
4836 desc1
->dpcLineCaps
.dwAlphaCmpCaps
= desc7
->dpcLineCaps
.dwAlphaCmpCaps
;
4838 desc1
->dpcTriCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
4839 desc1
->dpcTriCaps
.dwMiscCaps
= desc7
->dpcTriCaps
.dwMiscCaps
;
4840 desc1
->dpcTriCaps
.dwRasterCaps
= desc7
->dpcTriCaps
.dwRasterCaps
;
4841 desc1
->dpcTriCaps
.dwZCmpCaps
= desc7
->dpcTriCaps
.dwZCmpCaps
;
4842 desc1
->dpcTriCaps
.dwSrcBlendCaps
= desc7
->dpcTriCaps
.dwSrcBlendCaps
;
4843 desc1
->dpcTriCaps
.dwDestBlendCaps
= desc7
->dpcTriCaps
.dwDestBlendCaps
;
4844 desc1
->dpcTriCaps
.dwShadeCaps
= desc7
->dpcTriCaps
.dwShadeCaps
;
4845 desc1
->dpcTriCaps
.dwTextureCaps
= desc7
->dpcTriCaps
.dwTextureCaps
;
4846 desc1
->dpcTriCaps
.dwTextureFilterCaps
= desc7
->dpcTriCaps
.dwTextureFilterCaps
;
4847 desc1
->dpcTriCaps
.dwTextureBlendCaps
= desc7
->dpcTriCaps
.dwTextureBlendCaps
;
4848 desc1
->dpcTriCaps
.dwTextureAddressCaps
= desc7
->dpcTriCaps
.dwTextureAddressCaps
;
4849 desc1
->dpcTriCaps
.dwStippleWidth
= desc7
->dpcTriCaps
.dwStippleWidth
;
4850 desc1
->dpcTriCaps
.dwAlphaCmpCaps
= desc7
->dpcTriCaps
.dwAlphaCmpCaps
;
4852 desc1
->dwDeviceRenderBitDepth
= desc7
->dwDeviceRenderBitDepth
;
4853 desc1
->dwDeviceZBufferBitDepth
= desc7
->dwDeviceZBufferBitDepth
;
4854 desc1
->dwMaxBufferSize
= 0;
4855 desc1
->dwMaxVertexCount
= 65536;
4856 desc1
->dwMinTextureWidth
= desc7
->dwMinTextureWidth
;
4857 desc1
->dwMinTextureHeight
= desc7
->dwMinTextureHeight
;
4858 desc1
->dwMaxTextureWidth
= desc7
->dwMaxTextureWidth
;
4859 desc1
->dwMaxTextureHeight
= desc7
->dwMaxTextureHeight
;
4860 desc1
->dwMinStippleWidth
= 1;
4861 desc1
->dwMinStippleHeight
= 1;
4862 desc1
->dwMaxStippleWidth
= 32;
4863 desc1
->dwMaxStippleHeight
= 32;
4864 desc1
->dwMaxTextureRepeat
= desc7
->dwMaxTextureRepeat
;
4865 desc1
->dwMaxTextureAspectRatio
= desc7
->dwMaxTextureAspectRatio
;
4866 desc1
->dwMaxAnisotropy
= desc7
->dwMaxAnisotropy
;
4867 desc1
->dvGuardBandLeft
= desc7
->dvGuardBandLeft
;
4868 desc1
->dvGuardBandRight
= desc7
->dvGuardBandRight
;
4869 desc1
->dvGuardBandTop
= desc7
->dvGuardBandTop
;
4870 desc1
->dvGuardBandBottom
= desc7
->dvGuardBandBottom
;
4871 desc1
->dvExtentsAdjust
= desc7
->dvExtentsAdjust
;
4872 desc1
->dwStencilCaps
= desc7
->dwStencilCaps
;
4873 desc1
->dwFVFCaps
= desc7
->dwFVFCaps
;
4874 desc1
->dwTextureOpCaps
= desc7
->dwTextureOpCaps
;
4875 desc1
->wMaxTextureBlendStages
= desc7
->wMaxTextureBlendStages
;
4876 desc1
->wMaxSimultaneousTextures
= desc7
->wMaxSimultaneousTextures
;
4881 /*****************************************************************************
4882 * IDirectDraw7 VTable
4883 *****************************************************************************/
4884 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
4887 ddraw7_QueryInterface
,
4892 ddraw7_CreateClipper
,
4893 ddraw7_CreatePalette
,
4894 ddraw7_CreateSurface
,
4895 ddraw7_DuplicateSurface
,
4896 ddraw7_EnumDisplayModes
,
4897 ddraw7_EnumSurfaces
,
4898 ddraw7_FlipToGDISurface
,
4900 ddraw7_GetDisplayMode
,
4901 ddraw7_GetFourCCCodes
,
4902 ddraw7_GetGDISurface
,
4903 ddraw7_GetMonitorFrequency
,
4905 ddraw7_GetVerticalBlankStatus
,
4907 ddraw7_RestoreDisplayMode
,
4908 ddraw7_SetCooperativeLevel
,
4909 ddraw7_SetDisplayMode
,
4910 ddraw7_WaitForVerticalBlank
,
4912 ddraw7_GetAvailableVidMem
,
4914 ddraw7_GetSurfaceFromDC
,
4916 ddraw7_RestoreAllSurfaces
,
4917 ddraw7_TestCooperativeLevel
,
4918 ddraw7_GetDeviceIdentifier
,
4920 ddraw7_StartModeTest
,
4924 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
4927 ddraw4_QueryInterface
,
4932 ddraw4_CreateClipper
,
4933 ddraw4_CreatePalette
,
4934 ddraw4_CreateSurface
,
4935 ddraw4_DuplicateSurface
,
4936 ddraw4_EnumDisplayModes
,
4937 ddraw4_EnumSurfaces
,
4938 ddraw4_FlipToGDISurface
,
4940 ddraw4_GetDisplayMode
,
4941 ddraw4_GetFourCCCodes
,
4942 ddraw4_GetGDISurface
,
4943 ddraw4_GetMonitorFrequency
,
4945 ddraw4_GetVerticalBlankStatus
,
4947 ddraw4_RestoreDisplayMode
,
4948 ddraw4_SetCooperativeLevel
,
4949 ddraw4_SetDisplayMode
,
4950 ddraw4_WaitForVerticalBlank
,
4952 ddraw4_GetAvailableVidMem
,
4954 ddraw4_GetSurfaceFromDC
,
4956 ddraw4_RestoreAllSurfaces
,
4957 ddraw4_TestCooperativeLevel
,
4958 ddraw4_GetDeviceIdentifier
,
4961 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
4964 ddraw2_QueryInterface
,
4969 ddraw2_CreateClipper
,
4970 ddraw2_CreatePalette
,
4971 ddraw2_CreateSurface
,
4972 ddraw2_DuplicateSurface
,
4973 ddraw2_EnumDisplayModes
,
4974 ddraw2_EnumSurfaces
,
4975 ddraw2_FlipToGDISurface
,
4977 ddraw2_GetDisplayMode
,
4978 ddraw2_GetFourCCCodes
,
4979 ddraw2_GetGDISurface
,
4980 ddraw2_GetMonitorFrequency
,
4982 ddraw2_GetVerticalBlankStatus
,
4984 ddraw2_RestoreDisplayMode
,
4985 ddraw2_SetCooperativeLevel
,
4986 ddraw2_SetDisplayMode
,
4987 ddraw2_WaitForVerticalBlank
,
4989 ddraw2_GetAvailableVidMem
,
4992 static const struct IDirectDrawVtbl ddraw1_vtbl
=
4995 ddraw1_QueryInterface
,
5000 ddraw1_CreateClipper
,
5001 ddraw1_CreatePalette
,
5002 ddraw1_CreateSurface
,
5003 ddraw1_DuplicateSurface
,
5004 ddraw1_EnumDisplayModes
,
5005 ddraw1_EnumSurfaces
,
5006 ddraw1_FlipToGDISurface
,
5008 ddraw1_GetDisplayMode
,
5009 ddraw1_GetFourCCCodes
,
5010 ddraw1_GetGDISurface
,
5011 ddraw1_GetMonitorFrequency
,
5013 ddraw1_GetVerticalBlankStatus
,
5015 ddraw1_RestoreDisplayMode
,
5016 ddraw1_SetCooperativeLevel
,
5017 ddraw1_SetDisplayMode
,
5018 ddraw1_WaitForVerticalBlank
,
5021 static const struct IDirect3D7Vtbl d3d7_vtbl
=
5023 /* IUnknown methods */
5024 d3d7_QueryInterface
,
5027 /* IDirect3D7 methods */
5030 d3d7_CreateVertexBuffer
,
5031 d3d7_EnumZBufferFormats
,
5032 d3d7_EvictManagedTextures
5035 static const struct IDirect3D3Vtbl d3d3_vtbl
=
5037 /* IUnknown methods */
5038 d3d3_QueryInterface
,
5041 /* IDirect3D3 methods */
5044 d3d3_CreateMaterial
,
5045 d3d3_CreateViewport
,
5048 d3d3_CreateVertexBuffer
,
5049 d3d3_EnumZBufferFormats
,
5050 d3d3_EvictManagedTextures
5053 static const struct IDirect3D2Vtbl d3d2_vtbl
=
5055 /* IUnknown methods */
5056 d3d2_QueryInterface
,
5059 /* IDirect3D2 methods */
5062 d3d2_CreateMaterial
,
5063 d3d2_CreateViewport
,
5068 static const struct IDirect3DVtbl d3d1_vtbl
=
5070 /* IUnknown methods */
5071 d3d1_QueryInterface
,
5074 /* IDirect3D methods */
5078 d3d1_CreateMaterial
,
5079 d3d1_CreateViewport
,
5083 /*****************************************************************************
5086 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
5087 * if none was found.
5089 * This function is in ddraw.c and the DDraw object space because D3D7
5090 * vertex buffers are created using the IDirect3D interface to the ddraw
5091 * object, so they can be valid across D3D devices(theoretically. The ddraw
5092 * object also owns the wined3d device
5096 * fvf: Fvf to find the decl for
5099 * NULL in case of an error, the vertex declaration for the FVF otherwise.
5101 *****************************************************************************/
5102 struct wined3d_vertex_declaration
*ddraw_find_decl(struct ddraw
*This
, DWORD fvf
)
5104 struct wined3d_vertex_declaration
*pDecl
= NULL
;
5106 int p
, low
, high
; /* deliberately signed */
5107 struct FvfToDecl
*convertedDecls
= This
->decls
;
5109 TRACE("Searching for declaration for fvf %08x... ", fvf
);
5112 high
= This
->numConvertedDecls
- 1;
5113 while(low
<= high
) {
5114 p
= (low
+ high
) >> 1;
5116 if(convertedDecls
[p
].fvf
== fvf
) {
5117 TRACE("found %p\n", convertedDecls
[p
].decl
);
5118 return convertedDecls
[p
].decl
;
5119 } else if(convertedDecls
[p
].fvf
< fvf
) {
5125 TRACE("not found. Creating and inserting at position %d.\n", low
);
5127 hr
= wined3d_vertex_declaration_create_from_fvf(This
->wined3d_device
,
5128 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
5129 if (hr
!= S_OK
) return NULL
;
5131 if(This
->declArraySize
== This
->numConvertedDecls
) {
5132 int grow
= max(This
->declArraySize
/ 2, 8);
5133 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
5134 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
5135 if (!convertedDecls
)
5137 wined3d_vertex_declaration_decref(pDecl
);
5140 This
->decls
= convertedDecls
;
5141 This
->declArraySize
+= grow
;
5144 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
5145 convertedDecls
[low
].decl
= pDecl
;
5146 convertedDecls
[low
].fvf
= fvf
;
5147 This
->numConvertedDecls
++;
5149 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
5153 static inline struct ddraw
*ddraw_from_device_parent(struct wined3d_device_parent
*device_parent
)
5155 return CONTAINING_RECORD(device_parent
, struct ddraw
, device_parent
);
5158 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
5159 struct wined3d_device
*device
)
5161 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
5164 /* This is run from device_process_message() in wined3d, we can't take the
5166 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
5168 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
5169 MONITORINFO monitor_info
;
5174 TRACE("device_parent %p.\n", device_parent
);
5176 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) || !ddraw
->swapchain_window
)
5178 TRACE("Nothing to resize.\n");
5182 monitor
= MonitorFromWindow(ddraw
->swapchain_window
, MONITOR_DEFAULTTOPRIMARY
);
5183 monitor_info
.cbSize
= sizeof(monitor_info
);
5184 if (!(ret
= GetMonitorInfoW(monitor
, &monitor_info
)))
5186 ERR("Failed to get monitor info.\n");
5190 r
= &monitor_info
.rcMonitor
;
5191 TRACE("Resizing window %p to %s.\n", ddraw
->swapchain_window
, wine_dbgstr_rect(r
));
5193 if (!(ret
= SetWindowPos(ddraw
->swapchain_window
, HWND_TOP
, r
->left
, r
->top
,
5194 r
->right
- r
->left
, r
->bottom
- r
->top
, SWP_SHOWWINDOW
| SWP_NOACTIVATE
)))
5195 ERR("Failed to resize window.\n");
5198 static HRESULT CDECL
device_parent_create_texture_surface(struct wined3d_device_parent
*device_parent
,
5199 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
, DWORD usage
,
5200 enum wined3d_pool pool
, UINT sub_resource_idx
, struct wined3d_surface
**surface
)
5202 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
5203 struct ddraw_surface
*tex_root
= container_parent
;
5204 DDSURFACEDESC2 desc
= tex_root
->surface_desc
;
5205 struct ddraw_surface
*ddraw_surface
;
5208 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
5209 "\tpool %#x, sub_resource_idx %u, surface %p.\n",
5210 device_parent
, container_parent
, width
, height
, format
, usage
, pool
, sub_resource_idx
, surface
);
5212 /* The ddraw root surface is created before the wined3d texture. */
5213 if (!sub_resource_idx
)
5215 ddraw_surface
= tex_root
;
5219 desc
.dwWidth
= width
;
5220 desc
.dwHeight
= height
;
5222 /* FIXME: Validate that format, usage, pool, etc. really make sense. */
5223 if (FAILED(hr
= ddraw_create_surface(ddraw
, &desc
, &ddraw_surface
, tex_root
->version
)))
5227 *surface
= ddraw_surface
->wined3d_surface
;
5228 wined3d_surface_incref(*surface
);
5233 static void STDMETHODCALLTYPE
ddraw_frontbuffer_destroyed(void *parent
)
5235 struct ddraw
*ddraw
= parent
;
5236 ddraw
->wined3d_frontbuffer
= NULL
;
5239 static const struct wined3d_parent_ops ddraw_frontbuffer_parent_ops
=
5241 ddraw_frontbuffer_destroyed
,
5244 static HRESULT CDECL
device_parent_create_swapchain_surface(struct wined3d_device_parent
*device_parent
,
5245 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format_id
, DWORD usage
,
5246 enum wined3d_multisample_type multisample_type
, DWORD multisample_quality
, struct wined3d_surface
**surface
)
5248 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
5251 TRACE("device_parent %p, container_parent %p, width %u, height %u, format_id %#x, usage %#x,\n"
5252 "\tmultisample_type %#x, multisample_quality %u, surface %p.\n",
5253 device_parent
, container_parent
, width
, height
, format_id
, usage
,
5254 multisample_type
, multisample_quality
, surface
);
5256 if (ddraw
->wined3d_frontbuffer
)
5258 ERR("Frontbuffer already created.\n");
5262 if (SUCCEEDED(hr
= wined3d_surface_create(ddraw
->wined3d_device
, width
, height
, format_id
,
5263 usage
, WINED3D_POOL_DEFAULT
, multisample_type
, multisample_quality
, DefaultSurfaceType
,
5264 WINED3D_SURFACE_MAPPABLE
, ddraw
, &ddraw_frontbuffer_parent_ops
, surface
)))
5265 ddraw
->wined3d_frontbuffer
= *surface
;
5270 static HRESULT CDECL
device_parent_create_volume(struct wined3d_device_parent
*device_parent
,
5271 void *container_parent
, UINT width
, UINT height
, UINT depth
, enum wined3d_format_id format
,
5272 enum wined3d_pool pool
, DWORD usage
, struct wined3d_volume
**volume
)
5274 TRACE("device_parent %p, container_parent %p, width %u, height %u, depth %u, "
5275 "format %#x, pool %#x, usage %#x, volume %p.\n",
5276 device_parent
, container_parent
, width
, height
, depth
,
5277 format
, pool
, usage
, volume
);
5279 ERR("Not implemented!\n");
5284 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
5285 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
5287 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
5290 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent
, desc
, swapchain
);
5292 if (ddraw
->wined3d_swapchain
)
5294 ERR("Swapchain already created.\n");
5298 hr
= wined3d_swapchain_create(ddraw
->wined3d_device
, desc
,
5299 DefaultSurfaceType
, NULL
, &ddraw_null_wined3d_parent_ops
, swapchain
);
5301 WARN("Failed to create swapchain, hr %#x.\n", hr
);
5306 static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops
=
5308 device_parent_wined3d_device_created
,
5309 device_parent_mode_changed
,
5310 device_parent_create_swapchain_surface
,
5311 device_parent_create_texture_surface
,
5312 device_parent_create_volume
,
5313 device_parent_create_swapchain
,
5316 HRESULT
ddraw_init(struct ddraw
*ddraw
, enum wined3d_device_type device_type
)
5320 ddraw
->IDirectDraw7_iface
.lpVtbl
= &ddraw7_vtbl
;
5321 ddraw
->IDirectDraw_iface
.lpVtbl
= &ddraw1_vtbl
;
5322 ddraw
->IDirectDraw2_iface
.lpVtbl
= &ddraw2_vtbl
;
5323 ddraw
->IDirectDraw4_iface
.lpVtbl
= &ddraw4_vtbl
;
5324 ddraw
->IDirect3D_iface
.lpVtbl
= &d3d1_vtbl
;
5325 ddraw
->IDirect3D2_iface
.lpVtbl
= &d3d2_vtbl
;
5326 ddraw
->IDirect3D3_iface
.lpVtbl
= &d3d3_vtbl
;
5327 ddraw
->IDirect3D7_iface
.lpVtbl
= &d3d7_vtbl
;
5328 ddraw
->device_parent
.ops
= &ddraw_wined3d_device_parent_ops
;
5329 ddraw
->numIfaces
= 1;
5332 ddraw
->wined3d
= wined3d_create(7, WINED3D_LEGACY_DEPTH_BIAS
);
5333 if (!ddraw
->wined3d
)
5335 WARN("Failed to create a wined3d object.\n");
5336 return E_OUTOFMEMORY
;
5339 hr
= wined3d_device_create(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
,
5340 NULL
, 0, 8, &ddraw
->device_parent
, &ddraw
->wined3d_device
);
5343 WARN("Failed to create a wined3d device, hr %#x.\n", hr
);
5344 wined3d_decref(ddraw
->wined3d
);
5348 list_init(&ddraw
->surface_list
);