2 * Copyright 1997-2000 Marcus Meissner
3 * Copyright 1998-2000 Lionel Ulmer
4 * Copyright 2000-2001 TransGaming Technologies Inc.
5 * Copyright 2006 Stefan Dösinger
6 * Copyright 2008 Denver Gingerich
7 * Copyright 2007-2008, 2011, 2013 Stefan Dösinger for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/port.h"
27 #include "ddraw_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
31 static const struct ddraw
*exclusive_ddraw
;
32 static HWND exclusive_window
;
34 /* Device identifier. Don't relay it to WineD3D */
35 static const DDDEVICEIDENTIFIER2 deviceidentifier
=
37 "vga.dll", /* default 2D driver */
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 static HRESULT WINAPI
ddraw7_QueryInterface(IDirectDraw7
*iface
, REFIID riid
, void **out
)
124 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
126 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
131 return DDERR_INVALIDPARAMS
;
134 /* The refcount unit test revealed that an IDirect3D7 interface can only
135 * be queried from a DirectDraw object that was created as an IDirectDraw7
136 * interface. The older interfaces can query any IDirect3D version except
137 * 7, because they are all initially created as IDirectDraw. This isn't
138 * really crucial behavior, and messy to implement with the common
139 * creation function, so it has been left out here. */
140 if (IsEqualGUID(&IID_IDirectDraw7
, riid
)
141 || IsEqualGUID(&IID_IUnknown
, riid
))
143 *out
= &ddraw
->IDirectDraw7_iface
;
144 TRACE("Returning IDirectDraw7 interface %p.\n", *out
);
146 else if (IsEqualGUID(&IID_IDirectDraw4
, riid
))
148 *out
= &ddraw
->IDirectDraw4_iface
;
149 TRACE("Returning IDirectDraw4 interface %p.\n", *out
);
151 else if (IsEqualGUID(&IID_IDirectDraw2
, riid
))
153 *out
= &ddraw
->IDirectDraw2_iface
;
154 TRACE("Returning IDirectDraw2 interface %p.\n", *out
);
156 else if (IsEqualGUID(&IID_IDirectDraw
, riid
))
158 *out
= &ddraw
->IDirectDraw_iface
;
159 TRACE("Returning IDirectDraw interface %p.\n", *out
);
161 else if (IsEqualGUID(&IID_IDirect3D7
, riid
))
163 ddraw
->d3dversion
= 7;
164 *out
= &ddraw
->IDirect3D7_iface
;
165 TRACE("Returning Direct3D7 interface %p.\n", *out
);
167 else if (IsEqualGUID(&IID_IDirect3D3
, riid
))
169 ddraw
->d3dversion
= 3;
170 *out
= &ddraw
->IDirect3D3_iface
;
171 TRACE("Returning Direct3D3 interface %p.\n", *out
);
173 else if (IsEqualGUID(&IID_IDirect3D2
, riid
))
175 ddraw
->d3dversion
= 2;
176 *out
= &ddraw
->IDirect3D2_iface
;
177 TRACE("Returning Direct3D2 interface %p.\n", *out
);
179 else if (IsEqualGUID(&IID_IDirect3D
, riid
))
181 ddraw
->d3dversion
= 1;
182 *out
= &ddraw
->IDirect3D_iface
;
183 TRACE("Returning Direct3D interface %p.\n", *out
);
185 /* Unknown interface */
188 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
190 return E_NOINTERFACE
;
193 IUnknown_AddRef((IUnknown
*)*out
);
197 static HRESULT WINAPI
ddraw4_QueryInterface(IDirectDraw4
*iface
, REFIID riid
, void **object
)
199 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
201 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
203 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
206 static HRESULT WINAPI
ddraw2_QueryInterface(IDirectDraw2
*iface
, REFIID riid
, void **object
)
208 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
210 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
212 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
215 static HRESULT WINAPI
ddraw1_QueryInterface(IDirectDraw
*iface
, REFIID riid
, void **object
)
217 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
219 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
221 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
224 static HRESULT WINAPI
d3d7_QueryInterface(IDirect3D7
*iface
, REFIID riid
, void **object
)
226 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
228 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
230 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
233 static HRESULT WINAPI
d3d3_QueryInterface(IDirect3D3
*iface
, REFIID riid
, void **object
)
235 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
237 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
239 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
242 static HRESULT WINAPI
d3d2_QueryInterface(IDirect3D2
*iface
, REFIID riid
, void **object
)
244 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
246 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
248 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
251 static HRESULT WINAPI
d3d1_QueryInterface(IDirect3D
*iface
, REFIID riid
, void **object
)
253 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
255 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
257 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
260 /*****************************************************************************
261 * IDirectDraw7::AddRef
263 * Increases the interfaces refcount, basically
265 * DDraw refcounting is a bit tricky. The different DirectDraw interface
266 * versions have individual refcounts, but the IDirect3D interfaces do not.
267 * All interfaces are from one object, that means calling QueryInterface on an
268 * IDirectDraw7 interface for an IDirectDraw4 interface does not create a new
271 * That means all AddRef and Release implementations of IDirectDrawX work
272 * with their own counter, and IDirect3DX::AddRef thunk to IDirectDraw (1),
273 * except of IDirect3D7 which thunks to IDirectDraw7
275 * Returns: The new refcount
277 *****************************************************************************/
278 static ULONG WINAPI
ddraw7_AddRef(IDirectDraw7
*iface
)
280 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
281 ULONG ref
= InterlockedIncrement(&This
->ref7
);
283 TRACE("%p increasing refcount to %u.\n", This
, ref
);
285 if(ref
== 1) InterlockedIncrement(&This
->numIfaces
);
290 static ULONG WINAPI
ddraw4_AddRef(IDirectDraw4
*iface
)
292 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
293 ULONG ref
= InterlockedIncrement(&This
->ref4
);
295 TRACE("%p increasing refcount to %u.\n", This
, ref
);
297 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
302 static ULONG WINAPI
ddraw2_AddRef(IDirectDraw2
*iface
)
304 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
305 ULONG ref
= InterlockedIncrement(&This
->ref2
);
307 TRACE("%p increasing refcount to %u.\n", This
, ref
);
309 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
314 static ULONG WINAPI
ddraw1_AddRef(IDirectDraw
*iface
)
316 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
317 ULONG ref
= InterlockedIncrement(&This
->ref1
);
319 TRACE("%p increasing refcount to %u.\n", This
, ref
);
321 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
326 static ULONG WINAPI
d3d7_AddRef(IDirect3D7
*iface
)
328 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
330 TRACE("iface %p.\n", iface
);
332 return ddraw7_AddRef(&This
->IDirectDraw7_iface
);
335 static ULONG WINAPI
d3d3_AddRef(IDirect3D3
*iface
)
337 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
339 TRACE("iface %p.\n", iface
);
341 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
344 static ULONG WINAPI
d3d2_AddRef(IDirect3D2
*iface
)
346 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
348 TRACE("iface %p.\n", iface
);
350 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
353 static ULONG WINAPI
d3d1_AddRef(IDirect3D
*iface
)
355 struct ddraw
*This
= impl_from_IDirect3D(iface
);
357 TRACE("iface %p.\n", iface
);
359 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
362 void ddraw_destroy_swapchain(struct ddraw
*ddraw
)
364 TRACE("Destroying the swapchain.\n");
366 wined3d_swapchain_decref(ddraw
->wined3d_swapchain
);
367 ddraw
->wined3d_swapchain
= NULL
;
369 if (!(ddraw
->flags
& DDRAW_NO3D
))
373 for (i
= 0; i
< ddraw
->numConvertedDecls
; ++i
)
375 wined3d_vertex_declaration_decref(ddraw
->decls
[i
].decl
);
377 HeapFree(GetProcessHeap(), 0, ddraw
->decls
);
378 ddraw
->numConvertedDecls
= 0;
380 if (FAILED(wined3d_device_uninit_3d(ddraw
->wined3d_device
)))
382 ERR("Failed to uninit 3D.\n");
386 /* Free the d3d window if one was created. */
387 if (ddraw
->d3d_window
&& ddraw
->d3d_window
!= ddraw
->dest_window
)
389 TRACE("Destroying the hidden render window %p.\n", ddraw
->d3d_window
);
390 DestroyWindow(ddraw
->d3d_window
);
391 ddraw
->d3d_window
= 0;
395 ddraw
->flags
&= ~DDRAW_D3D_INITIALIZED
;
399 wined3d_device_uninit_gdi(ddraw
->wined3d_device
);
402 ddraw_set_swapchain_window(ddraw
, NULL
);
404 TRACE("Swapchain destroyed.\n");
407 /*****************************************************************************
410 * Destroys a ddraw object if all refcounts are 0. This is to share code
411 * between the IDirectDrawX::Release functions
414 * This: DirectDraw object to destroy
416 *****************************************************************************/
417 static void ddraw_destroy(struct ddraw
*This
)
419 IDirectDraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, NULL
, DDSCL_NORMAL
);
420 IDirectDraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
422 /* Destroy the device window if we created one */
423 if(This
->devicewindow
!= 0)
425 TRACE(" (%p) Destroying the device window %p\n", This
, This
->devicewindow
);
426 DestroyWindow(This
->devicewindow
);
427 This
->devicewindow
= 0;
430 wined3d_mutex_lock();
431 list_remove(&This
->ddraw_list_entry
);
432 wined3d_mutex_unlock();
434 if (This
->wined3d_swapchain
)
435 ddraw_destroy_swapchain(This
);
436 wined3d_device_decref(This
->wined3d_device
);
437 wined3d_decref(This
->wined3d
);
440 This
->d3ddevice
->ddraw
= NULL
;
442 /* Now free the object */
443 HeapFree(GetProcessHeap(), 0, This
);
446 /*****************************************************************************
447 * IDirectDraw7::Release
449 * Decreases the refcount. If the refcount falls to 0, the object is destroyed
451 * Returns: The new refcount
452 *****************************************************************************/
453 static ULONG WINAPI
ddraw7_Release(IDirectDraw7
*iface
)
455 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
456 ULONG ref
= InterlockedDecrement(&This
->ref7
);
458 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
460 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
466 static ULONG WINAPI
ddraw4_Release(IDirectDraw4
*iface
)
468 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
469 ULONG ref
= InterlockedDecrement(&This
->ref4
);
471 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
473 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
479 static ULONG WINAPI
ddraw2_Release(IDirectDraw2
*iface
)
481 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
482 ULONG ref
= InterlockedDecrement(&This
->ref2
);
484 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
486 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
492 static ULONG WINAPI
ddraw1_Release(IDirectDraw
*iface
)
494 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
495 ULONG ref
= InterlockedDecrement(&This
->ref1
);
497 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
499 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
505 static ULONG WINAPI
d3d7_Release(IDirect3D7
*iface
)
507 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
509 TRACE("iface %p.\n", iface
);
511 return ddraw7_Release(&This
->IDirectDraw7_iface
);
514 static ULONG WINAPI
d3d3_Release(IDirect3D3
*iface
)
516 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
518 TRACE("iface %p.\n", iface
);
520 return ddraw1_Release(&This
->IDirectDraw_iface
);
523 static ULONG WINAPI
d3d2_Release(IDirect3D2
*iface
)
525 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
527 TRACE("iface %p.\n", iface
);
529 return ddraw1_Release(&This
->IDirectDraw_iface
);
532 static ULONG WINAPI
d3d1_Release(IDirect3D
*iface
)
534 struct ddraw
*This
= impl_from_IDirect3D(iface
);
536 TRACE("iface %p.\n", iface
);
538 return ddraw1_Release(&This
->IDirectDraw_iface
);
541 /*****************************************************************************
542 * IDirectDraw methods
543 *****************************************************************************/
545 static HRESULT
ddraw_set_focus_window(struct ddraw
*ddraw
, HWND window
)
547 /* FIXME: This looks wrong, exclusive mode should imply a destination
549 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) && ddraw
->dest_window
)
551 TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET.\n");
552 return DDERR_HWNDALREADYSET
;
555 ddraw
->focuswindow
= window
;
560 static HRESULT
ddraw_attach_d3d_device(struct ddraw
*ddraw
,
561 struct wined3d_swapchain_desc
*swapchain_desc
)
563 HWND window
= swapchain_desc
->device_window
;
566 TRACE("ddraw %p.\n", ddraw
);
568 if (!window
|| window
== GetDesktopWindow())
570 window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "Hidden D3D Window",
571 WS_DISABLED
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
572 NULL
, NULL
, NULL
, NULL
);
575 ERR("Failed to create window, last error %#x.\n", GetLastError());
579 ShowWindow(window
, SW_HIDE
); /* Just to be sure */
580 WARN("No window for the Direct3DDevice, created hidden window %p.\n", window
);
582 swapchain_desc
->device_window
= window
;
586 TRACE("Using existing window %p for Direct3D rendering.\n", window
);
588 ddraw
->d3d_window
= window
;
590 /* Set this NOW, otherwise creating the depth stencil surface will cause a
591 * recursive loop until ram or emulated video memory is full. */
592 ddraw
->flags
|= DDRAW_D3D_INITIALIZED
;
593 hr
= wined3d_device_init_3d(ddraw
->wined3d_device
, swapchain_desc
);
596 ddraw
->flags
&= ~DDRAW_D3D_INITIALIZED
;
600 ddraw
->declArraySize
= 2;
601 ddraw
->decls
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ddraw
->decls
) * ddraw
->declArraySize
);
604 ERR("Error allocating an array for the converted vertex decls.\n");
605 ddraw
->declArraySize
= 0;
606 hr
= wined3d_device_uninit_3d(ddraw
->wined3d_device
);
607 return E_OUTOFMEMORY
;
610 TRACE("Successfully initialized 3D.\n");
615 static HRESULT
ddraw_create_swapchain(struct ddraw
*ddraw
, HWND window
, BOOL windowed
)
617 struct wined3d_swapchain_desc swapchain_desc
;
618 struct wined3d_display_mode mode
;
619 HRESULT hr
= WINED3D_OK
;
621 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
623 ERR("Failed to get display mode.\n");
627 memset(&swapchain_desc
, 0, sizeof(swapchain_desc
));
628 swapchain_desc
.backbuffer_width
= mode
.width
;
629 swapchain_desc
.backbuffer_height
= mode
.height
;
630 swapchain_desc
.backbuffer_format
= mode
.format_id
;
631 swapchain_desc
.swap_effect
= WINED3D_SWAP_EFFECT_COPY
;
632 swapchain_desc
.device_window
= window
;
633 swapchain_desc
.windowed
= windowed
;
635 if (!(ddraw
->flags
& DDRAW_NO3D
))
636 hr
= ddraw_attach_d3d_device(ddraw
, &swapchain_desc
);
638 hr
= wined3d_device_init_gdi(ddraw
->wined3d_device
, &swapchain_desc
);
642 ERR("Failed to create swapchain, hr %#x.\n", hr
);
646 if (!(ddraw
->wined3d_swapchain
= wined3d_device_get_swapchain(ddraw
->wined3d_device
, 0)))
648 ERR("Failed to get swapchain.\n");
649 return DDERR_INVALIDPARAMS
;
652 wined3d_swapchain_incref(ddraw
->wined3d_swapchain
);
653 ddraw_set_swapchain_window(ddraw
, window
);
658 /*****************************************************************************
659 * IDirectDraw7::RestoreDisplayMode
661 * Restores the display mode to what it was at creation time. Basically.
665 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
667 *****************************************************************************/
668 static HRESULT WINAPI
ddraw7_RestoreDisplayMode(IDirectDraw7
*iface
)
670 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
673 TRACE("iface %p.\n", iface
);
675 wined3d_mutex_lock();
677 if (!(ddraw
->flags
& DDRAW_RESTORE_MODE
))
679 wined3d_mutex_unlock();
683 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
685 wined3d_mutex_unlock();
686 return DDERR_NOEXCLUSIVEMODE
;
689 if (SUCCEEDED(hr
= wined3d_set_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, NULL
)))
690 ddraw
->flags
&= ~DDRAW_RESTORE_MODE
;
692 wined3d_mutex_unlock();
697 static HRESULT WINAPI
ddraw4_RestoreDisplayMode(IDirectDraw4
*iface
)
699 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
701 TRACE("iface %p.\n", iface
);
703 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
706 static HRESULT WINAPI
ddraw2_RestoreDisplayMode(IDirectDraw2
*iface
)
708 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
710 TRACE("iface %p.\n", iface
);
712 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
715 static HRESULT WINAPI
ddraw1_RestoreDisplayMode(IDirectDraw
*iface
)
717 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
719 TRACE("iface %p.\n", iface
);
721 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
724 /*****************************************************************************
725 * IDirectDraw7::SetCooperativeLevel
727 * Sets the cooperative level for the DirectDraw object, and the window
728 * assigned to it. The cooperative level determines the general behavior
729 * of the DirectDraw application
731 * Warning: This is quite tricky, as it's not really documented which
732 * cooperative levels can be combined with each other. If a game fails
733 * after this function, try to check the cooperative levels passed on
734 * Windows, and if it returns something different.
736 * If you think that this function caused the failure because it writes a
737 * fixme, be sure to run again with a +ddraw trace.
739 * What is known about cooperative levels (See the ddraw modes test):
740 * DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN.
741 * DDSCL_NORMAL is not compatible with DDSCL_EXCLUSIVE.
742 * Unlike what msdn claims, DDSCL_NORMAL | DDSCL_FULLSCREEN is allowed.
743 * DDSCL_SETFOCUSWINDOW can be passed only in DDSCL_NORMAL mode, but after that
744 * DDSCL_EXCLUSIVE can be activated.
745 * DDSCL_SETFOCUSWINDOW may only be used with DDSCL_NOWINDOWCHANGES or
746 * DDSCL_CREATEDEVICEWINDOW.
748 * Handled flags: DDSCL_NORMAL, DDSCL_FULLSCREEN, DDSCL_EXCLUSIVE,
749 * DDSCL_CREATEDEVICEWINDOW, DDSCL_SETDEVICEWINDOW
750 * DDSCL_SETFOCUSWINDOW (partially),
751 * DDSCL_MULTITHREADED (work in progress)
752 * DDSCL_FPUPRESERVE (see device.c)
754 * Unsure about this: DDSCL_FPUSETUP
756 * These don't seem very important for wine:
757 * DDSCL_ALLOWREBOOT, DDSCL_NOWINDOWCHANGES, DDSCL_ALLOWMODEX
760 * DD_OK if the cooperative level was set successfully
761 * DDERR_INVALIDPARAMS if the passed cooperative level combination is invalid
762 * DDERR_HWNDALREADYSET if DDSCL_SETFOCUSWINDOW is passed in exclusive mode
763 * (Probably others too, have to investigate)
765 *****************************************************************************/
766 static HRESULT
ddraw_set_cooperative_level(struct ddraw
*ddraw
, HWND window
,
767 DWORD cooplevel
, BOOL restore_mode_on_normal
)
769 struct wined3d_rendertarget_view
*rtv
= NULL
, *dsv
= NULL
;
770 struct wined3d_stateblock
*stateblock
;
771 BOOL restore_state
= FALSE
;
774 TRACE("ddraw %p, window %p, flags %#x, restore_mode_on_normal %x.\n", ddraw
, window
, cooplevel
,
775 restore_mode_on_normal
);
776 DDRAW_dump_cooperativelevel(cooplevel
);
778 wined3d_mutex_lock();
780 if (ddraw
->flags
& DDRAW_SCL_RECURSIVE
)
782 WARN("Recursive call, returning DD_OK.\n");
786 ddraw
->flags
|= DDRAW_SCL_RECURSIVE
;
788 /* Tests suggest that we need one of them: */
789 if(!(cooplevel
& (DDSCL_SETFOCUSWINDOW
|
793 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
794 hr
= DDERR_INVALIDPARAMS
;
798 if ((cooplevel
& DDSCL_CREATEDEVICEWINDOW
) && !(cooplevel
& DDSCL_EXCLUSIVE
))
800 WARN("DDSCL_CREATEDEVICEWINDOW requires DDSCL_EXCLUSIVE.\n");
801 hr
= DDERR_INVALIDPARAMS
;
805 /* Handle those levels first which set various hwnds */
806 if ((cooplevel
& DDSCL_SETFOCUSWINDOW
) && !(cooplevel
& DDSCL_CREATEDEVICEWINDOW
))
808 /* This isn't compatible with a lot of flags */
809 if (cooplevel
& (DDSCL_MULTITHREADED
814 | DDSCL_SETDEVICEWINDOW
819 WARN("Called with incompatible flags, returning DDERR_INVALIDPARAMS.\n");
820 hr
= DDERR_INVALIDPARAMS
;
824 hr
= ddraw_set_focus_window(ddraw
, window
);
828 if (cooplevel
& DDSCL_EXCLUSIVE
)
830 if (!(cooplevel
& DDSCL_FULLSCREEN
) || !(window
|| (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)))
832 WARN("DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN and a window.\n");
833 hr
= DDERR_INVALIDPARAMS
;
837 if (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)
841 if (!ddraw
->focuswindow
&& !(cooplevel
& DDSCL_SETFOCUSWINDOW
))
843 WARN("No focus window set.\n");
844 hr
= DDERR_NOFOCUSWINDOW
;
848 device_window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "DirectDrawDeviceWnd",
849 WS_POPUP
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
850 NULL
, NULL
, NULL
, NULL
);
853 ERR("Failed to create window, last error %#x.\n", GetLastError());
858 ShowWindow(device_window
, SW_SHOW
);
859 TRACE("Created a device window %p.\n", device_window
);
861 /* Native apparently leaks the created device window if setting the
862 * focus window below fails. */
863 ddraw
->cooperative_level
|= DDSCL_CREATEDEVICEWINDOW
;
864 ddraw
->devicewindow
= device_window
;
866 if (cooplevel
& DDSCL_SETFOCUSWINDOW
)
874 if (FAILED(hr
= ddraw_set_focus_window(ddraw
, window
)))
878 window
= device_window
;
883 if (ddraw
->cooperative_level
& DDSCL_CREATEDEVICEWINDOW
)
884 DestroyWindow(ddraw
->devicewindow
);
885 ddraw
->devicewindow
= NULL
;
886 ddraw
->focuswindow
= NULL
;
889 if ((cooplevel
& DDSCL_FULLSCREEN
) != (ddraw
->cooperative_level
& DDSCL_FULLSCREEN
) || window
!= ddraw
->dest_window
)
891 if (ddraw
->cooperative_level
& DDSCL_FULLSCREEN
)
892 wined3d_device_restore_fullscreen_window(ddraw
->wined3d_device
, ddraw
->dest_window
);
894 if (cooplevel
& DDSCL_FULLSCREEN
)
896 struct wined3d_display_mode display_mode
;
898 wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &display_mode
, NULL
);
899 wined3d_device_setup_fullscreen_window(ddraw
->wined3d_device
, window
,
900 display_mode
.width
, display_mode
.height
);
904 if ((cooplevel
& DDSCL_EXCLUSIVE
) && exclusive_window
!= window
)
906 ddraw
->device_state
= DDRAW_DEVICE_STATE_NOT_RESTORED
;
907 exclusive_window
= window
;
910 if (cooplevel
& DDSCL_MULTITHREADED
&& !(ddraw
->cooperative_level
& DDSCL_MULTITHREADED
))
911 wined3d_device_set_multithreaded(ddraw
->wined3d_device
);
913 if (ddraw
->wined3d_swapchain
)
915 if (!(ddraw
->flags
& DDRAW_NO3D
))
917 restore_state
= TRUE
;
919 if (FAILED(hr
= wined3d_stateblock_create(ddraw
->wined3d_device
, WINED3D_SBT_ALL
, &stateblock
)))
921 ERR("Failed to create stateblock, hr %#x.\n", hr
);
925 wined3d_stateblock_capture(stateblock
);
926 rtv
= wined3d_device_get_rendertarget_view(ddraw
->wined3d_device
, 0);
927 /* Rendering to ddraw->wined3d_frontbuffer. */
928 if (rtv
&& !wined3d_rendertarget_view_get_sub_resource_parent(rtv
))
931 wined3d_rendertarget_view_incref(rtv
);
933 if ((dsv
= wined3d_device_get_depth_stencil_view(ddraw
->wined3d_device
)))
934 wined3d_rendertarget_view_incref(dsv
);
937 ddraw_destroy_swapchain(ddraw
);
940 if (FAILED(hr
= ddraw_create_swapchain(ddraw
, window
, !(cooplevel
& DDSCL_FULLSCREEN
))))
941 ERR("Failed to create swapchain, hr %#x.\n", hr
);
947 wined3d_device_set_depth_stencil_view(ddraw
->wined3d_device
, dsv
);
948 wined3d_rendertarget_view_decref(dsv
);
953 wined3d_device_set_rendertarget_view(ddraw
->wined3d_device
, 0, rtv
, FALSE
);
954 wined3d_rendertarget_view_decref(rtv
);
957 wined3d_stateblock_apply(stateblock
);
958 wined3d_stateblock_decref(stateblock
);
961 if (!(cooplevel
& DDSCL_EXCLUSIVE
) && (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
962 && restore_mode_on_normal
)
964 hr
= ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
966 ERR("RestoreDisplayMode failed\n");
969 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
970 && (window
!= ddraw
->dest_window
|| !(cooplevel
& DDSCL_EXCLUSIVE
)))
971 wined3d_device_release_focus_window(ddraw
->wined3d_device
);
973 if ((cooplevel
& DDSCL_EXCLUSIVE
)
974 && (window
!= ddraw
->dest_window
|| !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)))
976 hr
= wined3d_device_acquire_focus_window(ddraw
->wined3d_device
, window
);
979 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
984 /* Unhandled flags */
985 if (cooplevel
& DDSCL_ALLOWREBOOT
)
986 WARN("Unhandled flag DDSCL_ALLOWREBOOT, harmless\n");
987 if (cooplevel
& DDSCL_ALLOWMODEX
)
988 WARN("Unhandled flag DDSCL_ALLOWMODEX, harmless\n");
989 if (cooplevel
& DDSCL_FPUSETUP
)
990 WARN("Unhandled flag DDSCL_FPUSETUP, harmless\n");
992 if (cooplevel
& DDSCL_EXCLUSIVE
)
993 exclusive_ddraw
= ddraw
;
994 else if (exclusive_ddraw
== ddraw
)
995 exclusive_ddraw
= NULL
;
997 /* Store the cooperative_level */
998 ddraw
->cooperative_level
= cooplevel
;
999 ddraw
->dest_window
= window
;
1001 TRACE("SetCooperativeLevel returning DD_OK\n");
1004 ddraw
->flags
&= ~DDRAW_SCL_RECURSIVE
;
1005 wined3d_mutex_unlock();
1010 static HRESULT WINAPI
ddraw7_SetCooperativeLevel(IDirectDraw7
*iface
, HWND window
, DWORD flags
)
1012 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1014 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1016 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1019 static HRESULT WINAPI
ddraw4_SetCooperativeLevel(IDirectDraw4
*iface
, HWND window
, DWORD flags
)
1021 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1023 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1025 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1028 static HRESULT WINAPI
ddraw2_SetCooperativeLevel(IDirectDraw2
*iface
, HWND window
, DWORD flags
)
1030 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1032 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1034 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1037 static HRESULT WINAPI
ddraw1_SetCooperativeLevel(IDirectDraw
*iface
, HWND window
, DWORD flags
)
1039 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1042 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1044 hr
= ddraw_set_cooperative_level(ddraw
, window
, flags
, FALSE
);
1046 ddraw
->flags
|= DDRAW_SCL_DDRAW1
;
1050 /*****************************************************************************
1051 * IDirectDraw7::SetDisplayMode
1053 * Sets the display screen resolution, color depth and refresh frequency
1054 * when in fullscreen mode (in theory).
1055 * Possible return values listed in the SDK suggest that this method fails
1056 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
1057 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
1058 * It seems to be valid to pass 0 for With and Height, this has to be tested
1059 * It could mean that the current video mode should be left as-is. (But why
1063 * Height, Width: Screen dimension
1064 * BPP: Color depth in Bits per pixel
1065 * Refreshrate: Screen refresh rate
1066 * Flags: Other stuff
1071 *****************************************************************************/
1072 static HRESULT WINAPI
ddraw7_SetDisplayMode(IDirectDraw7
*iface
, DWORD width
, DWORD height
,
1073 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1075 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1076 struct wined3d_display_mode mode
;
1077 enum wined3d_format_id format
;
1080 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1081 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1083 if (force_refresh_rate
!= 0)
1085 TRACE("ForceRefreshRate overriding passed-in refresh rate (%u Hz) to %u Hz\n",
1086 refresh_rate
, force_refresh_rate
);
1087 refresh_rate
= force_refresh_rate
;
1090 wined3d_mutex_lock();
1092 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
1094 wined3d_mutex_unlock();
1095 return DDERR_NOEXCLUSIVEMODE
;
1098 if (!width
|| !height
)
1100 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here. */
1101 wined3d_mutex_unlock();
1107 case 8: format
= WINED3DFMT_P8_UINT
; break;
1108 case 15: format
= WINED3DFMT_B5G5R5X1_UNORM
; break;
1109 case 16: format
= WINED3DFMT_B5G6R5_UNORM
; break;
1110 case 24: format
= WINED3DFMT_B8G8R8_UNORM
; break;
1111 case 32: format
= WINED3DFMT_B8G8R8X8_UNORM
; break;
1112 default: format
= WINED3DFMT_UNKNOWN
; break;
1116 mode
.height
= height
;
1117 mode
.refresh_rate
= refresh_rate
;
1118 mode
.format_id
= format
;
1119 mode
.scanline_ordering
= WINED3D_SCANLINE_ORDERING_UNKNOWN
;
1121 /* TODO: The possible return values from msdn suggest that the screen mode
1122 * can't be changed if a surface is locked or some drawing is in progress. */
1123 if (SUCCEEDED(hr
= wined3d_set_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
)))
1124 ddraw
->flags
|= DDRAW_RESTORE_MODE
;
1126 wined3d_mutex_unlock();
1130 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1135 static HRESULT WINAPI
ddraw4_SetDisplayMode(IDirectDraw4
*iface
, DWORD width
, DWORD height
,
1136 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1138 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1140 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1141 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1143 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1146 static HRESULT WINAPI
ddraw2_SetDisplayMode(IDirectDraw2
*iface
,
1147 DWORD width
, DWORD height
, DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1149 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1151 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1152 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1154 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1157 static HRESULT WINAPI
ddraw1_SetDisplayMode(IDirectDraw
*iface
, DWORD width
, DWORD height
, DWORD bpp
)
1159 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1161 TRACE("iface %p, width %u, height %u, bpp %u.\n", iface
, width
, height
, bpp
);
1163 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, 0, 0);
1166 void ddraw_d3dcaps1_from_7(D3DDEVICEDESC
*caps1
, D3DDEVICEDESC7
*caps7
)
1168 memset(caps1
, 0, sizeof(*caps1
));
1169 caps1
->dwSize
= sizeof(*caps1
);
1170 caps1
->dwFlags
= D3DDD_COLORMODEL
1172 | D3DDD_TRANSFORMCAPS
1174 | D3DDD_LIGHTINGCAPS
1177 | D3DDD_DEVICERENDERBITDEPTH
1178 | D3DDD_DEVICEZBUFFERBITDEPTH
1179 | D3DDD_MAXBUFFERSIZE
1180 | D3DDD_MAXVERTEXCOUNT
;
1181 caps1
->dcmColorModel
= D3DCOLOR_RGB
;
1182 caps1
->dwDevCaps
= caps7
->dwDevCaps
;
1183 caps1
->dtcTransformCaps
.dwSize
= sizeof(caps1
->dtcTransformCaps
);
1184 caps1
->dtcTransformCaps
.dwCaps
= D3DTRANSFORMCAPS_CLIP
;
1185 caps1
->bClipping
= TRUE
;
1186 caps1
->dlcLightingCaps
.dwSize
= sizeof(caps1
->dlcLightingCaps
);
1187 caps1
->dlcLightingCaps
.dwCaps
= D3DLIGHTCAPS_DIRECTIONAL
1188 | D3DLIGHTCAPS_PARALLELPOINT
1189 | D3DLIGHTCAPS_POINT
1190 | D3DLIGHTCAPS_SPOT
;
1191 caps1
->dlcLightingCaps
.dwLightingModel
= D3DLIGHTINGMODEL_RGB
;
1192 caps1
->dlcLightingCaps
.dwNumLights
= caps7
->dwMaxActiveLights
;
1193 caps1
->dpcLineCaps
= caps7
->dpcLineCaps
;
1194 caps1
->dpcTriCaps
= caps7
->dpcTriCaps
;
1195 caps1
->dwDeviceRenderBitDepth
= caps7
->dwDeviceRenderBitDepth
;
1196 caps1
->dwDeviceZBufferBitDepth
= caps7
->dwDeviceZBufferBitDepth
;
1197 caps1
->dwMaxBufferSize
= 0;
1198 caps1
->dwMaxVertexCount
= 65536;
1199 caps1
->dwMinTextureWidth
= caps7
->dwMinTextureWidth
;
1200 caps1
->dwMinTextureHeight
= caps7
->dwMinTextureHeight
;
1201 caps1
->dwMaxTextureWidth
= caps7
->dwMaxTextureWidth
;
1202 caps1
->dwMaxTextureHeight
= caps7
->dwMaxTextureHeight
;
1203 caps1
->dwMinStippleWidth
= 1;
1204 caps1
->dwMinStippleHeight
= 1;
1205 caps1
->dwMaxStippleWidth
= 32;
1206 caps1
->dwMaxStippleHeight
= 32;
1207 caps1
->dwMaxTextureRepeat
= caps7
->dwMaxTextureRepeat
;
1208 caps1
->dwMaxTextureAspectRatio
= caps7
->dwMaxTextureAspectRatio
;
1209 caps1
->dwMaxAnisotropy
= caps7
->dwMaxAnisotropy
;
1210 caps1
->dvGuardBandLeft
= caps7
->dvGuardBandLeft
;
1211 caps1
->dvGuardBandTop
= caps7
->dvGuardBandTop
;
1212 caps1
->dvGuardBandRight
= caps7
->dvGuardBandRight
;
1213 caps1
->dvGuardBandBottom
= caps7
->dvGuardBandBottom
;
1214 caps1
->dvExtentsAdjust
= caps7
->dvExtentsAdjust
;
1215 caps1
->dwStencilCaps
= caps7
->dwStencilCaps
;
1216 caps1
->dwFVFCaps
= caps7
->dwFVFCaps
;
1217 caps1
->dwTextureOpCaps
= caps7
->dwTextureOpCaps
;
1218 caps1
->wMaxTextureBlendStages
= caps7
->wMaxTextureBlendStages
;
1219 caps1
->wMaxSimultaneousTextures
= caps7
->wMaxSimultaneousTextures
;
1222 HRESULT
ddraw_get_d3dcaps(const struct ddraw
*ddraw
, D3DDEVICEDESC7
*caps
)
1224 WINED3DCAPS wined3d_caps
;
1227 TRACE("ddraw %p, caps %p.\n", ddraw
, caps
);
1229 memset(&wined3d_caps
, 0, sizeof(wined3d_caps
));
1231 wined3d_mutex_lock();
1232 hr
= wined3d_get_device_caps(ddraw
->wined3d
, 0, WINED3D_DEVICE_TYPE_HAL
, &wined3d_caps
);
1233 wined3d_mutex_unlock();
1236 WARN("Failed to get device caps, hr %#x.\n", hr
);
1240 caps
->dwDevCaps
= wined3d_caps
.DevCaps
;
1241 caps
->dpcLineCaps
.dwMiscCaps
= wined3d_caps
.PrimitiveMiscCaps
;
1242 caps
->dpcLineCaps
.dwRasterCaps
= wined3d_caps
.RasterCaps
;
1243 caps
->dpcLineCaps
.dwZCmpCaps
= wined3d_caps
.ZCmpCaps
;
1244 caps
->dpcLineCaps
.dwSrcBlendCaps
= wined3d_caps
.SrcBlendCaps
;
1245 caps
->dpcLineCaps
.dwDestBlendCaps
= wined3d_caps
.DestBlendCaps
;
1246 caps
->dpcLineCaps
.dwAlphaCmpCaps
= wined3d_caps
.AlphaCmpCaps
;
1247 caps
->dpcLineCaps
.dwShadeCaps
= wined3d_caps
.ShadeCaps
;
1248 caps
->dpcLineCaps
.dwTextureCaps
= wined3d_caps
.TextureCaps
;
1249 caps
->dpcLineCaps
.dwTextureFilterCaps
= wined3d_caps
.TextureFilterCaps
;
1250 caps
->dpcLineCaps
.dwTextureAddressCaps
= wined3d_caps
.TextureAddressCaps
;
1252 caps
->dwMaxTextureWidth
= wined3d_caps
.MaxTextureWidth
;
1253 caps
->dwMaxTextureHeight
= wined3d_caps
.MaxTextureHeight
;
1255 caps
->dwMaxTextureRepeat
= wined3d_caps
.MaxTextureRepeat
;
1256 caps
->dwMaxTextureAspectRatio
= wined3d_caps
.MaxTextureAspectRatio
;
1257 caps
->dwMaxAnisotropy
= wined3d_caps
.MaxAnisotropy
;
1258 caps
->dvMaxVertexW
= wined3d_caps
.MaxVertexW
;
1260 caps
->dvGuardBandLeft
= wined3d_caps
.GuardBandLeft
;
1261 caps
->dvGuardBandTop
= wined3d_caps
.GuardBandTop
;
1262 caps
->dvGuardBandRight
= wined3d_caps
.GuardBandRight
;
1263 caps
->dvGuardBandBottom
= wined3d_caps
.GuardBandBottom
;
1265 caps
->dvExtentsAdjust
= wined3d_caps
.ExtentsAdjust
;
1266 caps
->dwStencilCaps
= wined3d_caps
.StencilCaps
;
1268 caps
->dwFVFCaps
= wined3d_caps
.FVFCaps
;
1269 caps
->dwTextureOpCaps
= wined3d_caps
.TextureOpCaps
;
1271 caps
->dwVertexProcessingCaps
= wined3d_caps
.VertexProcessingCaps
;
1272 caps
->dwMaxActiveLights
= wined3d_caps
.MaxActiveLights
;
1274 /* Remove all non-d3d7 caps */
1275 caps
->dwDevCaps
&= (
1276 D3DDEVCAPS_FLOATTLVERTEX
| D3DDEVCAPS_SORTINCREASINGZ
| D3DDEVCAPS_SORTDECREASINGZ
|
1277 D3DDEVCAPS_SORTEXACT
| D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
|
1278 D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
| D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
|
1279 D3DDEVCAPS_TEXTUREVIDEOMEMORY
| D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
|
1280 D3DDEVCAPS_TEXTURENONLOCALVIDMEM
| D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
1281 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
1282 D3DDEVCAPS_HWRASTERIZATION
);
1284 caps
->dwStencilCaps
&= (
1285 D3DSTENCILCAPS_KEEP
| D3DSTENCILCAPS_ZERO
| D3DSTENCILCAPS_REPLACE
|
1286 D3DSTENCILCAPS_INCRSAT
| D3DSTENCILCAPS_DECRSAT
| D3DSTENCILCAPS_INVERT
|
1287 D3DSTENCILCAPS_INCR
| D3DSTENCILCAPS_DECR
);
1291 caps
->dwTextureOpCaps
&= (
1292 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_SELECTARG2
|
1293 D3DTEXOPCAPS_MODULATE
| D3DTEXOPCAPS_MODULATE2X
| D3DTEXOPCAPS_MODULATE4X
|
1294 D3DTEXOPCAPS_ADD
| D3DTEXOPCAPS_ADDSIGNED
| D3DTEXOPCAPS_ADDSIGNED2X
|
1295 D3DTEXOPCAPS_SUBTRACT
| D3DTEXOPCAPS_ADDSMOOTH
| D3DTEXOPCAPS_BLENDTEXTUREALPHA
|
1296 D3DTEXOPCAPS_BLENDFACTORALPHA
| D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
| D3DTEXOPCAPS_BLENDCURRENTALPHA
|
1297 D3DTEXOPCAPS_PREMODULATE
| D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
|
1298 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
| D3DTEXOPCAPS_BUMPENVMAP
|
1299 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
| D3DTEXOPCAPS_DOTPRODUCT3
);
1301 caps
->dwVertexProcessingCaps
&= (
1302 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_VERTEXFOG
|
1303 D3DVTXPCAPS_DIRECTIONALLIGHTS
| D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
);
1305 caps
->dpcLineCaps
.dwMiscCaps
&= (
1306 D3DPMISCCAPS_MASKPLANES
| D3DPMISCCAPS_MASKZ
| D3DPMISCCAPS_LINEPATTERNREP
|
1307 D3DPMISCCAPS_CONFORMANT
| D3DPMISCCAPS_CULLNONE
| D3DPMISCCAPS_CULLCW
|
1308 D3DPMISCCAPS_CULLCCW
);
1310 caps
->dpcLineCaps
.dwRasterCaps
&= (
1311 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ROP2
| D3DPRASTERCAPS_XOR
|
1312 D3DPRASTERCAPS_PAT
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_SUBPIXEL
|
1313 D3DPRASTERCAPS_SUBPIXELX
| D3DPRASTERCAPS_FOGVERTEX
| D3DPRASTERCAPS_FOGTABLE
|
1314 D3DPRASTERCAPS_STIPPLE
| D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT
| D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT
|
1315 D3DPRASTERCAPS_ANTIALIASEDGES
| D3DPRASTERCAPS_MIPMAPLODBIAS
| D3DPRASTERCAPS_ZBIAS
|
1316 D3DPRASTERCAPS_ZBUFFERLESSHSR
| D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
|
1317 D3DPRASTERCAPS_WBUFFER
| D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT
| D3DPRASTERCAPS_WFOG
|
1318 D3DPRASTERCAPS_ZFOG
);
1320 caps
->dpcLineCaps
.dwZCmpCaps
&= (
1321 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
1322 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
1323 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
1325 caps
->dpcLineCaps
.dwSrcBlendCaps
&= (
1326 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
1327 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
1328 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
1329 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
1330 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
1332 caps
->dpcLineCaps
.dwDestBlendCaps
&= (
1333 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
1334 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
1335 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
1336 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
1337 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
1339 caps
->dpcLineCaps
.dwAlphaCmpCaps
&= (
1340 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
1341 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
1342 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
1344 caps
->dpcLineCaps
.dwShadeCaps
&= (
1345 D3DPSHADECAPS_COLORFLATMONO
| D3DPSHADECAPS_COLORFLATRGB
| D3DPSHADECAPS_COLORGOURAUDMONO
|
1346 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_COLORPHONGMONO
| D3DPSHADECAPS_COLORPHONGRGB
|
1347 D3DPSHADECAPS_SPECULARFLATMONO
| D3DPSHADECAPS_SPECULARFLATRGB
| D3DPSHADECAPS_SPECULARGOURAUDMONO
|
1348 D3DPSHADECAPS_SPECULARGOURAUDRGB
| D3DPSHADECAPS_SPECULARPHONGMONO
| D3DPSHADECAPS_SPECULARPHONGRGB
|
1349 D3DPSHADECAPS_ALPHAFLATBLEND
| D3DPSHADECAPS_ALPHAFLATSTIPPLED
| D3DPSHADECAPS_ALPHAGOURAUDBLEND
|
1350 D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED
| D3DPSHADECAPS_ALPHAPHONGBLEND
| D3DPSHADECAPS_ALPHAPHONGSTIPPLED
|
1351 D3DPSHADECAPS_FOGFLAT
| D3DPSHADECAPS_FOGGOURAUD
| D3DPSHADECAPS_FOGPHONG
);
1353 caps
->dpcLineCaps
.dwTextureCaps
&= (
1354 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
1355 D3DPTEXTURECAPS_TRANSPARENCY
| D3DPTEXTURECAPS_BORDER
| D3DPTEXTURECAPS_SQUAREONLY
|
1356 D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
| D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
1357 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_COLORKEYBLEND
);
1359 caps
->dpcLineCaps
.dwTextureFilterCaps
&= (
1360 D3DPTFILTERCAPS_NEAREST
| D3DPTFILTERCAPS_LINEAR
| D3DPTFILTERCAPS_MIPNEAREST
|
1361 D3DPTFILTERCAPS_MIPLINEAR
| D3DPTFILTERCAPS_LINEARMIPNEAREST
| D3DPTFILTERCAPS_LINEARMIPLINEAR
|
1362 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
1363 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
1364 D3DPTFILTERCAPS_MAGFLINEAR
| D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
|
1365 D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
);
1367 caps
->dpcLineCaps
.dwTextureAddressCaps
&= (
1368 D3DPTADDRESSCAPS_WRAP
| D3DPTADDRESSCAPS_MIRROR
| D3DPTADDRESSCAPS_CLAMP
|
1369 D3DPTADDRESSCAPS_BORDER
| D3DPTADDRESSCAPS_INDEPENDENTUV
);
1371 if (!(caps
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
))
1373 /* DirectX7 always has the np2 flag set, no matter what the card
1374 * supports. Some old games (Rollcage) check the caps incorrectly.
1375 * If wined3d supports nonpow2 textures it also has np2 conditional
1377 caps
->dpcLineCaps
.dwTextureCaps
|= D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
;
1380 /* Fill the missing members, and do some fixup */
1381 caps
->dpcLineCaps
.dwSize
= sizeof(caps
->dpcLineCaps
);
1382 caps
->dpcLineCaps
.dwTextureBlendCaps
= D3DPTBLENDCAPS_ADD
1383 | D3DPTBLENDCAPS_MODULATEMASK
1384 | D3DPTBLENDCAPS_COPY
1385 | D3DPTBLENDCAPS_DECAL
1386 | D3DPTBLENDCAPS_DECALALPHA
1387 | D3DPTBLENDCAPS_DECALMASK
1388 | D3DPTBLENDCAPS_MODULATE
1389 | D3DPTBLENDCAPS_MODULATEALPHA
;
1390 caps
->dpcLineCaps
.dwStippleWidth
= 32;
1391 caps
->dpcLineCaps
.dwStippleHeight
= 32;
1392 /* Use the same for the TriCaps */
1393 caps
->dpcTriCaps
= caps
->dpcLineCaps
;
1395 caps
->dwDeviceRenderBitDepth
= DDBD_16
| DDBD_24
| DDBD_32
;
1396 caps
->dwDeviceZBufferBitDepth
= DDBD_16
| DDBD_24
;
1397 caps
->dwMinTextureWidth
= 1;
1398 caps
->dwMinTextureHeight
= 1;
1400 /* Convert DWORDs safely to WORDs */
1401 if (wined3d_caps
.MaxTextureBlendStages
> 0xffff)
1402 caps
->wMaxTextureBlendStages
= 0xffff;
1404 caps
->wMaxTextureBlendStages
= (WORD
)wined3d_caps
.MaxTextureBlendStages
;
1405 if (wined3d_caps
.MaxSimultaneousTextures
> 0xffff)
1406 caps
->wMaxSimultaneousTextures
= 0xffff;
1408 caps
->wMaxSimultaneousTextures
= (WORD
)wined3d_caps
.MaxSimultaneousTextures
;
1410 if (wined3d_caps
.MaxUserClipPlanes
> 0xffff)
1411 caps
->wMaxUserClipPlanes
= 0xffff;
1413 caps
->wMaxUserClipPlanes
= (WORD
)wined3d_caps
.MaxUserClipPlanes
;
1414 if (wined3d_caps
.MaxVertexBlendMatrices
> 0xffff)
1415 caps
->wMaxVertexBlendMatrices
= 0xffff;
1417 caps
->wMaxVertexBlendMatrices
= (WORD
)wined3d_caps
.MaxVertexBlendMatrices
;
1419 caps
->deviceGUID
= IID_IDirect3DTnLHalDevice
;
1421 caps
->dwReserved1
= 0;
1422 caps
->dwReserved2
= 0;
1423 caps
->dwReserved3
= 0;
1424 caps
->dwReserved4
= 0;
1429 /*****************************************************************************
1430 * IDirectDraw7::GetCaps
1432 * Returns the drives capabilities
1434 * Used for version 1, 2, 4 and 7
1437 * DriverCaps: Structure to write the Hardware accelerated caps to
1438 * HelCaps: Structure to write the emulation caps to
1441 * This implementation returns DD_OK only
1443 *****************************************************************************/
1444 static HRESULT WINAPI
ddraw7_GetCaps(IDirectDraw7
*iface
, DDCAPS
*DriverCaps
, DDCAPS
*HELCaps
)
1446 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1448 WINED3DCAPS winecaps
;
1450 DDSCAPS2 ddscaps
= {0, 0, 0, {0}};
1452 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, DriverCaps
, HELCaps
);
1454 /* One structure must be != NULL */
1455 if (!DriverCaps
&& !HELCaps
)
1457 WARN("Invalid parameters.\n");
1458 return DDERR_INVALIDPARAMS
;
1461 memset(&caps
, 0, sizeof(caps
));
1462 memset(&winecaps
, 0, sizeof(winecaps
));
1463 caps
.dwSize
= sizeof(caps
);
1465 wined3d_mutex_lock();
1466 hr
= wined3d_device_get_device_caps(ddraw
->wined3d_device
, &winecaps
);
1469 WARN("IWineD3DDevice::GetDeviceCaps failed\n");
1470 wined3d_mutex_unlock();
1474 hr
= IDirectDraw7_GetAvailableVidMem(iface
, &ddscaps
, &caps
.dwVidMemTotal
, &caps
.dwVidMemFree
);
1477 WARN("IDirectDraw7::GetAvailableVidMem failed\n");
1478 wined3d_mutex_unlock();
1482 hr
= IDirectDraw7_GetFourCCCodes(iface
, &caps
.dwNumFourCCCodes
, NULL
);
1483 wined3d_mutex_unlock();
1486 WARN("IDirectDraw7::GetFourCCCodes failed\n");
1490 caps
.dwCaps
= winecaps
.ddraw_caps
.caps
;
1491 caps
.dwCaps2
= winecaps
.ddraw_caps
.caps2
;
1492 caps
.dwCKeyCaps
= winecaps
.ddraw_caps
.color_key_caps
;
1493 caps
.dwFXCaps
= winecaps
.ddraw_caps
.fx_caps
;
1494 caps
.dwPalCaps
= DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
;
1495 caps
.ddsCaps
.dwCaps
= winecaps
.ddraw_caps
.dds_caps
;
1496 caps
.dwSVBCaps
= winecaps
.ddraw_caps
.svb_caps
;
1497 caps
.dwSVBCKeyCaps
= winecaps
.ddraw_caps
.svb_color_key_caps
;
1498 caps
.dwSVBFXCaps
= winecaps
.ddraw_caps
.svb_fx_caps
;
1499 caps
.dwVSBCaps
= winecaps
.ddraw_caps
.vsb_caps
;
1500 caps
.dwVSBCKeyCaps
= winecaps
.ddraw_caps
.vsb_color_key_caps
;
1501 caps
.dwVSBFXCaps
= winecaps
.ddraw_caps
.vsb_fx_caps
;
1502 caps
.dwSSBCaps
= winecaps
.ddraw_caps
.ssb_caps
;
1503 caps
.dwSSBCKeyCaps
= winecaps
.ddraw_caps
.ssb_color_key_caps
;
1504 caps
.dwSSBFXCaps
= winecaps
.ddraw_caps
.ssb_fx_caps
;
1506 caps
.dwCaps
|= DDCAPS_ALIGNSTRIDE
;
1507 caps
.dwAlignStrideAlign
= DDRAW_STRIDE_ALIGNMENT
;
1511 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &caps
);
1512 if (TRACE_ON(ddraw
))
1514 TRACE("Driver Caps :\n");
1515 DDRAW_dump_DDCAPS(DriverCaps
);
1521 DD_STRUCT_COPY_BYSIZE(HELCaps
, &caps
);
1522 if (TRACE_ON(ddraw
))
1524 TRACE("HEL Caps :\n");
1525 DDRAW_dump_DDCAPS(HELCaps
);
1532 static HRESULT WINAPI
ddraw4_GetCaps(IDirectDraw4
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1534 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1536 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1538 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1541 static HRESULT WINAPI
ddraw2_GetCaps(IDirectDraw2
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1543 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1545 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1547 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1550 static HRESULT WINAPI
ddraw1_GetCaps(IDirectDraw
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1552 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1554 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1556 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1559 /*****************************************************************************
1560 * IDirectDraw7::Compact
1562 * No idea what it does, MSDN says it's not implemented.
1565 * DD_OK, but this is unchecked
1567 *****************************************************************************/
1568 static HRESULT WINAPI
ddraw7_Compact(IDirectDraw7
*iface
)
1570 TRACE("iface %p.\n", iface
);
1575 static HRESULT WINAPI
ddraw4_Compact(IDirectDraw4
*iface
)
1577 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1579 TRACE("iface %p.\n", iface
);
1581 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1584 static HRESULT WINAPI
ddraw2_Compact(IDirectDraw2
*iface
)
1586 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1588 TRACE("iface %p.\n", iface
);
1590 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1593 static HRESULT WINAPI
ddraw1_Compact(IDirectDraw
*iface
)
1595 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1597 TRACE("iface %p.\n", iface
);
1599 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1602 /*****************************************************************************
1603 * IDirectDraw7::GetDisplayMode
1605 * Returns information about the current display mode
1607 * Exists in Version 1, 2, 4 and 7
1610 * DDSD: Address of a surface description structure to write the info to
1615 *****************************************************************************/
1616 static HRESULT WINAPI
ddraw7_GetDisplayMode(IDirectDraw7
*iface
, DDSURFACEDESC2
*DDSD
)
1618 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1619 struct wined3d_display_mode mode
;
1623 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
1625 wined3d_mutex_lock();
1626 /* This seems sane */
1629 wined3d_mutex_unlock();
1630 return DDERR_INVALIDPARAMS
;
1633 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1635 ERR("Failed to get display mode, hr %#x.\n", hr
);
1636 wined3d_mutex_unlock();
1640 Size
= DDSD
->dwSize
;
1641 memset(DDSD
, 0, Size
);
1643 DDSD
->dwSize
= Size
;
1644 DDSD
->dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
1645 DDSD
->dwWidth
= mode
.width
;
1646 DDSD
->dwHeight
= mode
.height
;
1647 DDSD
->u2
.dwRefreshRate
= 60;
1648 DDSD
->ddsCaps
.dwCaps
= 0;
1649 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
1650 ddrawformat_from_wined3dformat(&DDSD
->u4
.ddpfPixelFormat
, mode
.format_id
);
1651 DDSD
->u1
.lPitch
= mode
.width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
1655 TRACE("Returning surface desc :\n");
1656 DDRAW_dump_surface_desc(DDSD
);
1659 wined3d_mutex_unlock();
1664 static HRESULT WINAPI
ddraw4_GetDisplayMode(IDirectDraw4
*iface
, DDSURFACEDESC2
*surface_desc
)
1666 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1668 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1670 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, surface_desc
);
1673 static HRESULT WINAPI
ddraw2_GetDisplayMode(IDirectDraw2
*iface
, DDSURFACEDESC
*surface_desc
)
1675 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1677 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1679 /* FIXME: Test sizes, properly convert surface_desc */
1680 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1683 static HRESULT WINAPI
ddraw1_GetDisplayMode(IDirectDraw
*iface
, DDSURFACEDESC
*surface_desc
)
1685 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1687 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1689 /* FIXME: Test sizes, properly convert surface_desc */
1690 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1693 /*****************************************************************************
1694 * IDirectDraw7::GetFourCCCodes
1696 * Returns an array of supported FourCC codes.
1698 * Exists in Version 1, 2, 4 and 7
1701 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
1702 * of enumerated codes
1703 * Codes: Pointer to an array of DWORDs where the supported codes are written
1707 * Always returns DD_OK, as it's a stub for now
1709 *****************************************************************************/
1710 static HRESULT WINAPI
ddraw7_GetFourCCCodes(IDirectDraw7
*iface
, DWORD
*NumCodes
, DWORD
*Codes
)
1712 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1713 static const enum wined3d_format_id formats
[] =
1715 WINED3DFMT_YUY2
, WINED3DFMT_UYVY
, WINED3DFMT_YV12
,
1716 WINED3DFMT_DXT1
, WINED3DFMT_DXT2
, WINED3DFMT_DXT3
, WINED3DFMT_DXT4
, WINED3DFMT_DXT5
,
1717 WINED3DFMT_ATI2N
, WINED3DFMT_NVHU
, WINED3DFMT_NVHS
1719 struct wined3d_display_mode mode
;
1720 DWORD count
= 0, i
, outsize
;
1723 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, NumCodes
, Codes
);
1725 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1727 ERR("Failed to get display mode, hr %#x.\n", hr
);
1731 outsize
= NumCodes
&& Codes
? *NumCodes
: 0;
1733 for (i
= 0; i
< (sizeof(formats
) / sizeof(formats
[0])); ++i
)
1735 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, WINED3D_DEVICE_TYPE_HAL
,
1736 mode
.format_id
, 0, WINED3D_RTYPE_SURFACE
, formats
[i
])))
1738 if (count
< outsize
)
1739 Codes
[count
] = formats
[i
];
1744 TRACE("Returning %u FourCC codes\n", count
);
1751 static HRESULT WINAPI
ddraw4_GetFourCCCodes(IDirectDraw4
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1753 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1755 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1757 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1760 static HRESULT WINAPI
ddraw2_GetFourCCCodes(IDirectDraw2
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1762 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1764 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1766 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1769 static HRESULT WINAPI
ddraw1_GetFourCCCodes(IDirectDraw
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1771 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1773 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1775 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1778 static HRESULT WINAPI
ddraw7_GetMonitorFrequency(IDirectDraw7
*iface
, DWORD
*frequency
)
1780 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1781 struct wined3d_display_mode mode
;
1784 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1786 wined3d_mutex_lock();
1787 hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
);
1788 wined3d_mutex_unlock();
1791 WARN("Failed to get display mode, hr %#x.\n", hr
);
1795 *frequency
= mode
.refresh_rate
;
1800 static HRESULT WINAPI
ddraw4_GetMonitorFrequency(IDirectDraw4
*iface
, DWORD
*frequency
)
1802 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1804 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1806 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1809 static HRESULT WINAPI
ddraw2_GetMonitorFrequency(IDirectDraw2
*iface
, DWORD
*frequency
)
1811 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1813 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1815 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1818 static HRESULT WINAPI
ddraw1_GetMonitorFrequency(IDirectDraw
*iface
, DWORD
*frequency
)
1820 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1822 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1824 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1827 static HRESULT WINAPI
ddraw7_GetVerticalBlankStatus(IDirectDraw7
*iface
, BOOL
*status
)
1829 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1830 struct wined3d_raster_status raster_status
;
1833 TRACE("iface %p, status %p.\n", iface
, status
);
1836 return DDERR_INVALIDPARAMS
;
1838 wined3d_mutex_lock();
1839 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
1840 wined3d_mutex_unlock();
1843 WARN("Failed to get raster status, hr %#x.\n", hr
);
1847 *status
= raster_status
.in_vblank
;
1852 static HRESULT WINAPI
ddraw4_GetVerticalBlankStatus(IDirectDraw4
*iface
, BOOL
*status
)
1854 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1856 TRACE("iface %p, status %p.\n", iface
, status
);
1858 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1861 static HRESULT WINAPI
ddraw2_GetVerticalBlankStatus(IDirectDraw2
*iface
, BOOL
*status
)
1863 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1865 TRACE("iface %p, status %p.\n", iface
, status
);
1867 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1870 static HRESULT WINAPI
ddraw1_GetVerticalBlankStatus(IDirectDraw
*iface
, BOOL
*status
)
1872 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1874 TRACE("iface %p, status %p.\n", iface
, status
);
1876 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1879 /*****************************************************************************
1880 * IDirectDraw7::GetAvailableVidMem
1882 * Returns the total and free video memory
1885 * Caps: Specifies the memory type asked for
1886 * total: Pointer to a DWORD to be filled with the total memory
1887 * free: Pointer to a DWORD to be filled with the free memory
1891 * DDERR_INVALIDPARAMS if free and total are NULL
1893 *****************************************************************************/
1894 static HRESULT WINAPI
ddraw7_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*Caps
, DWORD
*total
,
1897 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1900 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, Caps
, total
, free
);
1902 if (TRACE_ON(ddraw
))
1904 TRACE("Asked for memory with description: ");
1905 DDRAW_dump_DDSCAPS2(Caps
);
1907 wined3d_mutex_lock();
1909 /* Todo: System memory vs local video memory vs non-local video memory
1910 * The MSDN also mentions differences between texture memory and other
1911 * resources, but that's not important
1914 if( (!total
) && (!free
) )
1916 wined3d_mutex_unlock();
1917 return DDERR_INVALIDPARAMS
;
1921 *free
= wined3d_device_get_available_texture_mem(ddraw
->wined3d_device
);
1924 struct wined3d_adapter_identifier desc
= {0};
1926 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0, &desc
);
1927 *total
= min(UINT_MAX
, desc
.video_memory
);
1930 wined3d_mutex_unlock();
1935 static HRESULT WINAPI
ddraw4_GetAvailableVidMem(IDirectDraw4
*iface
,
1936 DDSCAPS2
*caps
, DWORD
*total
, DWORD
*free
)
1938 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1940 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1942 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, caps
, total
, free
);
1945 static HRESULT WINAPI
ddraw2_GetAvailableVidMem(IDirectDraw2
*iface
,
1946 DDSCAPS
*caps
, DWORD
*total
, DWORD
*free
)
1948 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1951 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1953 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
1954 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, &caps2
, total
, free
);
1957 /*****************************************************************************
1958 * IDirectDraw7::Initialize
1960 * Initializes a DirectDraw interface.
1963 * GUID: Interface identifier. Well, don't know what this is really good
1967 * Returns DD_OK on the first call,
1968 * DDERR_ALREADYINITIALIZED on repeated calls
1970 *****************************************************************************/
1971 static HRESULT WINAPI
ddraw7_Initialize(IDirectDraw7
*iface
, GUID
*guid
)
1973 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1975 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1977 if (ddraw
->flags
& DDRAW_INITIALIZED
)
1978 return DDERR_ALREADYINITIALIZED
;
1980 /* FIXME: To properly take the GUID into account we should call
1981 * ddraw_init() here instead of in DDRAW_Create(). */
1983 FIXME("Ignoring guid %s.\n", debugstr_guid(guid
));
1985 ddraw
->flags
|= DDRAW_INITIALIZED
;
1989 static HRESULT WINAPI
ddraw4_Initialize(IDirectDraw4
*iface
, GUID
*guid
)
1991 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1993 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1995 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
1998 static HRESULT WINAPI
ddraw2_Initialize(IDirectDraw2
*iface
, GUID
*guid
)
2000 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2002 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2004 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2007 static HRESULT WINAPI
ddraw1_Initialize(IDirectDraw
*iface
, GUID
*guid
)
2009 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2011 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2013 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2016 static HRESULT WINAPI
d3d1_Initialize(IDirect3D
*iface
, REFIID riid
)
2018 TRACE("iface %p, riid %s.\n", iface
, debugstr_guid(riid
));
2020 return DDERR_ALREADYINITIALIZED
;
2023 /*****************************************************************************
2024 * IDirectDraw7::FlipToGDISurface
2026 * "Makes the surface that the GDI writes to the primary surface"
2027 * Looks like some windows specific thing we don't have to care about.
2028 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
2029 * show error boxes ;)
2030 * Well, just return DD_OK.
2033 * Always returns DD_OK
2035 *****************************************************************************/
2036 static HRESULT WINAPI
ddraw7_FlipToGDISurface(IDirectDraw7
*iface
)
2038 FIXME("iface %p stub!\n", iface
);
2043 static HRESULT WINAPI
ddraw4_FlipToGDISurface(IDirectDraw4
*iface
)
2045 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2047 TRACE("iface %p.\n", iface
);
2049 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2052 static HRESULT WINAPI
ddraw2_FlipToGDISurface(IDirectDraw2
*iface
)
2054 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2056 TRACE("iface %p.\n", iface
);
2058 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2061 static HRESULT WINAPI
ddraw1_FlipToGDISurface(IDirectDraw
*iface
)
2063 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2065 TRACE("iface %p.\n", iface
);
2067 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2070 /*****************************************************************************
2071 * IDirectDraw7::WaitForVerticalBlank
2073 * This method allows applications to get in sync with the vertical blank
2075 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
2076 * redraw the screen, most likely because of this stub
2079 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
2080 * or DDWAITVB_BLOCKEND
2081 * h: Not used, according to MSDN
2084 * Always returns DD_OK
2086 *****************************************************************************/
2087 static HRESULT WINAPI
ddraw7_WaitForVerticalBlank(IDirectDraw7
*iface
, DWORD Flags
, HANDLE event
)
2091 TRACE("iface %p, flags %#x, event %p.\n", iface
, Flags
, event
);
2093 /* This function is called often, so print the fixme only once */
2096 FIXME("iface %p, flags %#x, event %p stub!\n", iface
, Flags
, event
);
2100 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
2101 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
2102 return DDERR_UNSUPPORTED
; /* unchecked */
2107 static HRESULT WINAPI
ddraw4_WaitForVerticalBlank(IDirectDraw4
*iface
, DWORD flags
, HANDLE event
)
2109 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2111 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2113 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2116 static HRESULT WINAPI
ddraw2_WaitForVerticalBlank(IDirectDraw2
*iface
, DWORD flags
, HANDLE event
)
2118 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2120 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2122 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2125 static HRESULT WINAPI
ddraw1_WaitForVerticalBlank(IDirectDraw
*iface
, DWORD flags
, HANDLE event
)
2127 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2129 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2131 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2134 static HRESULT WINAPI
ddraw7_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
2136 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2137 struct wined3d_raster_status raster_status
;
2140 TRACE("iface %p, line %p.\n", iface
, Scanline
);
2142 wined3d_mutex_lock();
2143 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
2144 wined3d_mutex_unlock();
2147 WARN("Failed to get raster status, hr %#x.\n", hr
);
2151 *Scanline
= raster_status
.scan_line
;
2153 if (raster_status
.in_vblank
)
2154 return DDERR_VERTICALBLANKINPROGRESS
;
2159 static HRESULT WINAPI
ddraw4_GetScanLine(IDirectDraw4
*iface
, DWORD
*line
)
2161 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2163 TRACE("iface %p, line %p.\n", iface
, line
);
2165 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2168 static HRESULT WINAPI
ddraw2_GetScanLine(IDirectDraw2
*iface
, DWORD
*line
)
2170 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2172 TRACE("iface %p, line %p.\n", iface
, line
);
2174 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2177 static HRESULT WINAPI
ddraw1_GetScanLine(IDirectDraw
*iface
, DWORD
*line
)
2179 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2181 TRACE("iface %p, line %p.\n", iface
, line
);
2183 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2186 static HRESULT WINAPI
ddraw7_TestCooperativeLevel(IDirectDraw7
*iface
)
2188 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2190 TRACE("iface %p.\n", iface
);
2192 return ddraw
->device_state
== DDRAW_DEVICE_STATE_LOST
? DDERR_NOEXCLUSIVEMODE
: DD_OK
;
2195 static HRESULT WINAPI
ddraw4_TestCooperativeLevel(IDirectDraw4
*iface
)
2197 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2199 TRACE("iface %p.\n", iface
);
2201 return ddraw7_TestCooperativeLevel(&ddraw
->IDirectDraw7_iface
);
2204 /*****************************************************************************
2205 * IDirectDraw7::GetGDISurface
2207 * Returns the surface that GDI is treating as the primary surface.
2208 * For Wine this is the front buffer
2211 * GDISurface: Address to write the surface pointer to
2214 * DD_OK if the surface was found
2215 * DDERR_NOTFOUND if the GDI surface wasn't found
2217 *****************************************************************************/
2218 static HRESULT WINAPI
ddraw7_GetGDISurface(IDirectDraw7
*iface
, IDirectDrawSurface7
**GDISurface
)
2220 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2222 TRACE("iface %p, surface %p.\n", iface
, GDISurface
);
2224 wined3d_mutex_lock();
2226 if (!(*GDISurface
= &ddraw
->primary
->IDirectDrawSurface7_iface
))
2228 WARN("Primary not created yet.\n");
2229 wined3d_mutex_unlock();
2230 return DDERR_NOTFOUND
;
2232 IDirectDrawSurface7_AddRef(*GDISurface
);
2234 wined3d_mutex_unlock();
2239 static HRESULT WINAPI
ddraw4_GetGDISurface(IDirectDraw4
*iface
, IDirectDrawSurface4
**surface
)
2241 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2242 struct ddraw_surface
*surface_impl
;
2243 IDirectDrawSurface7
*surface7
;
2246 TRACE("iface %p, surface %p.\n", iface
, surface
);
2248 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2254 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2255 *surface
= &surface_impl
->IDirectDrawSurface4_iface
;
2256 IDirectDrawSurface4_AddRef(*surface
);
2257 IDirectDrawSurface7_Release(surface7
);
2262 static HRESULT WINAPI
ddraw2_GetGDISurface(IDirectDraw2
*iface
, IDirectDrawSurface
**surface
)
2264 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2265 struct ddraw_surface
*surface_impl
;
2266 IDirectDrawSurface7
*surface7
;
2269 TRACE("iface %p, surface %p.\n", iface
, surface
);
2271 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2277 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2278 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2279 IDirectDrawSurface_AddRef(*surface
);
2280 IDirectDrawSurface7_Release(surface7
);
2285 static HRESULT WINAPI
ddraw1_GetGDISurface(IDirectDraw
*iface
, IDirectDrawSurface
**surface
)
2287 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2288 struct ddraw_surface
*surface_impl
;
2289 IDirectDrawSurface7
*surface7
;
2292 TRACE("iface %p, surface %p.\n", iface
, surface
);
2294 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2300 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2301 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2302 IDirectDrawSurface_AddRef(*surface
);
2303 IDirectDrawSurface7_Release(surface7
);
2308 struct displaymodescallback_context
2310 LPDDENUMMODESCALLBACK func
;
2314 static HRESULT CALLBACK
EnumDisplayModesCallbackThunk(DDSURFACEDESC2
*surface_desc
, void *context
)
2316 struct displaymodescallback_context
*cbcontext
= context
;
2319 DDSD2_to_DDSD(surface_desc
, &desc
);
2320 return cbcontext
->func(&desc
, cbcontext
->context
);
2323 /*****************************************************************************
2324 * IDirectDraw7::EnumDisplayModes
2326 * Enumerates the supported Display modes. The modes can be filtered with
2327 * the DDSD parameter.
2330 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES. For old ddraw
2331 * versions (3 and older?) this is reserved and must be 0.
2332 * DDSD: Surface description to filter the modes
2333 * Context: Pointer passed back to the callback function
2334 * cb: Application-provided callback function
2338 * DDERR_INVALIDPARAMS if the callback wasn't set
2340 *****************************************************************************/
2341 static HRESULT WINAPI
ddraw7_EnumDisplayModes(IDirectDraw7
*iface
, DWORD Flags
,
2342 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMMODESCALLBACK2 cb
)
2344 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2345 struct wined3d_display_mode
*enum_modes
= NULL
;
2346 struct wined3d_display_mode mode
;
2347 unsigned int modenum
, fmt
;
2348 DDSURFACEDESC2 callback_sd
;
2349 unsigned enum_mode_count
= 0, enum_mode_array_size
= 16;
2350 DDPIXELFORMAT pixelformat
;
2352 static const enum wined3d_format_id checkFormatList
[] =
2354 WINED3DFMT_B8G8R8X8_UNORM
,
2355 WINED3DFMT_B5G6R5_UNORM
,
2359 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2360 iface
, Flags
, DDSD
, Context
, cb
);
2363 return DDERR_INVALIDPARAMS
;
2365 enum_modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(*enum_modes
) * enum_mode_array_size
);
2366 if (!enum_modes
) return DDERR_OUTOFMEMORY
;
2368 wined3d_mutex_lock();
2370 pixelformat
.dwSize
= sizeof(pixelformat
);
2371 for(fmt
= 0; fmt
< (sizeof(checkFormatList
) / sizeof(checkFormatList
[0])); fmt
++)
2374 while (wined3d_enum_adapter_modes(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, checkFormatList
[fmt
],
2375 WINED3D_SCANLINE_ORDERING_UNKNOWN
, modenum
++, &mode
) == WINED3D_OK
)
2380 ddrawformat_from_wined3dformat(&pixelformat
, mode
.format_id
);
2383 if (DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.width
!= DDSD
->dwWidth
)
2385 if (DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.height
!= DDSD
->dwHeight
)
2387 if (DDSD
->dwFlags
& DDSD_REFRESHRATE
&& mode
.refresh_rate
!= DDSD
->u2
.dwRefreshRate
)
2389 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
2390 && pixelformat
.u1
.dwRGBBitCount
!= DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
)
2394 /* DX docs state EnumDisplayMode should return only unique modes */
2395 for (i
= 0; i
< enum_mode_count
; i
++)
2397 if (enum_modes
[i
].width
== mode
.width
&& enum_modes
[i
].height
== mode
.height
2398 && enum_modes
[i
].format_id
== mode
.format_id
2399 && (enum_modes
[i
].refresh_rate
== mode
.refresh_rate
|| !(Flags
& DDEDM_REFRESHRATES
)))
2407 memset(&callback_sd
, 0, sizeof(callback_sd
));
2408 callback_sd
.dwSize
= sizeof(callback_sd
);
2409 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2411 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
|DDSD_REFRESHRATE
;
2412 if (Flags
& DDEDM_REFRESHRATES
)
2413 callback_sd
.u2
.dwRefreshRate
= mode
.refresh_rate
;
2415 callback_sd
.dwWidth
= mode
.width
;
2416 callback_sd
.dwHeight
= mode
.height
;
2418 callback_sd
.u4
.ddpfPixelFormat
=pixelformat
;
2420 /* Calc pitch and DWORD align like MSDN says */
2421 callback_sd
.u1
.lPitch
= (callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8) * mode
.width
;
2422 callback_sd
.u1
.lPitch
= (callback_sd
.u1
.lPitch
+ 3) & ~3;
2424 TRACE("Enumerating %dx%dx%d @%d\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
,
2425 callback_sd
.u2
.dwRefreshRate
);
2427 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
2429 TRACE("Application asked to terminate the enumeration\n");
2430 HeapFree(GetProcessHeap(), 0, enum_modes
);
2431 wined3d_mutex_unlock();
2435 if (enum_mode_count
== enum_mode_array_size
)
2437 struct wined3d_display_mode
*new_enum_modes
;
2439 enum_mode_array_size
*= 2;
2440 new_enum_modes
= HeapReAlloc(GetProcessHeap(), 0, enum_modes
,
2441 sizeof(*new_enum_modes
) * enum_mode_array_size
);
2442 if (!new_enum_modes
)
2444 HeapFree(GetProcessHeap(), 0, enum_modes
);
2445 wined3d_mutex_unlock();
2446 return DDERR_OUTOFMEMORY
;
2449 enum_modes
= new_enum_modes
;
2451 enum_modes
[enum_mode_count
++] = mode
;
2455 TRACE("End of enumeration\n");
2456 HeapFree(GetProcessHeap(), 0, enum_modes
);
2457 wined3d_mutex_unlock();
2462 static HRESULT WINAPI
ddraw4_EnumDisplayModes(IDirectDraw4
*iface
, DWORD flags
,
2463 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK2 callback
)
2465 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2467 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2468 iface
, flags
, surface_desc
, context
, callback
);
2470 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
, context
, callback
);
2473 static HRESULT WINAPI
ddraw2_EnumDisplayModes(IDirectDraw2
*iface
, DWORD flags
,
2474 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2476 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2477 struct displaymodescallback_context cbcontext
;
2478 DDSURFACEDESC2 surface_desc2
;
2480 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2481 iface
, flags
, surface_desc
, context
, callback
);
2483 cbcontext
.func
= callback
;
2484 cbcontext
.context
= context
;
2486 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2487 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2488 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2491 static HRESULT WINAPI
ddraw1_EnumDisplayModes(IDirectDraw
*iface
, DWORD flags
,
2492 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2494 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2495 struct displaymodescallback_context cbcontext
;
2496 DDSURFACEDESC2 surface_desc2
;
2498 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2499 iface
, flags
, surface_desc
, context
, callback
);
2501 cbcontext
.func
= callback
;
2502 cbcontext
.context
= context
;
2504 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2505 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2506 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2509 /*****************************************************************************
2510 * IDirectDraw7::EvaluateMode
2512 * Used with IDirectDraw7::StartModeTest to test video modes.
2513 * EvaluateMode is used to pass or fail a mode, and continue with the next
2517 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
2518 * Timeout: Returns the amount of seconds left before the mode would have
2519 * been failed automatically
2522 * This implementation always DD_OK, because it's a stub
2524 *****************************************************************************/
2525 static HRESULT WINAPI
ddraw7_EvaluateMode(IDirectDraw7
*iface
, DWORD Flags
, DWORD
*Timeout
)
2527 FIXME("iface %p, flags %#x, timeout %p stub!\n", iface
, Flags
, Timeout
);
2529 /* When implementing this, implement it in WineD3D */
2534 /*****************************************************************************
2535 * IDirectDraw7::GetDeviceIdentifier
2537 * Returns the device identifier, which gives information about the driver
2538 * Our device identifier is defined at the beginning of this file.
2541 * DDDI: Address for the returned structure
2542 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
2545 * On success it returns DD_OK
2546 * DDERR_INVALIDPARAMS if DDDI is NULL
2548 *****************************************************************************/
2549 static HRESULT WINAPI
ddraw7_GetDeviceIdentifier(IDirectDraw7
*iface
,
2550 DDDEVICEIDENTIFIER2
*DDDI
, DWORD Flags
)
2552 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2553 struct wined3d_adapter_identifier adapter_id
;
2556 TRACE("iface %p, device_identifier %p, flags %#x.\n", iface
, DDDI
, Flags
);
2559 return DDERR_INVALIDPARAMS
;
2561 if (Flags
& DDGDI_GETHOSTIDENTIFIER
)
2563 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
2564 * host adapter, if there's a secondary 3D adapter. This doesn't apply
2565 * to any modern hardware, nor is it interesting for Wine, so ignore it.
2566 * Size of DDDEVICEIDENTIFIER2 may be aligned to 8 bytes and thus 4
2567 * bytes too long. So only copy the relevant part of the structure
2570 memcpy(DDDI
, &deviceidentifier
, FIELD_OFFSET(DDDEVICEIDENTIFIER2
, dwWHQLLevel
) + sizeof(DWORD
));
2574 /* Drakan: Order of the Flame expects accurate D3D device information from ddraw */
2575 adapter_id
.driver
= DDDI
->szDriver
;
2576 adapter_id
.driver_size
= sizeof(DDDI
->szDriver
);
2577 adapter_id
.description
= DDDI
->szDescription
;
2578 adapter_id
.description_size
= sizeof(DDDI
->szDescription
);
2579 adapter_id
.device_name_size
= 0;
2580 wined3d_mutex_lock();
2581 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0x0, &adapter_id
);
2582 wined3d_mutex_unlock();
2583 if (FAILED(hr
)) return hr
;
2585 DDDI
->liDriverVersion
= adapter_id
.driver_version
;
2586 DDDI
->dwVendorId
= adapter_id
.vendor_id
;
2587 DDDI
->dwDeviceId
= adapter_id
.device_id
;
2588 DDDI
->dwSubSysId
= adapter_id
.subsystem_id
;
2589 DDDI
->dwRevision
= adapter_id
.revision
;
2590 DDDI
->guidDeviceIdentifier
= adapter_id
.device_identifier
;
2591 DDDI
->dwWHQLLevel
= adapter_id
.whql_level
;
2595 static HRESULT WINAPI
ddraw4_GetDeviceIdentifier(IDirectDraw4
*iface
,
2596 DDDEVICEIDENTIFIER
*identifier
, DWORD flags
)
2598 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2599 DDDEVICEIDENTIFIER2 identifier2
;
2602 TRACE("iface %p, identifier %p, flags %#x.\n", iface
, identifier
, flags
);
2604 hr
= ddraw7_GetDeviceIdentifier(&ddraw
->IDirectDraw7_iface
, &identifier2
, flags
);
2605 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&identifier2
, identifier
);
2610 /*****************************************************************************
2611 * IDirectDraw7::GetSurfaceFromDC
2613 * Returns the Surface for a GDI device context handle.
2614 * Is this related to IDirectDrawSurface::GetDC ???
2617 * hdc: hdc to return the surface for
2618 * Surface: Address to write the surface pointer to
2621 * Always returns DD_OK because it's a stub
2623 *****************************************************************************/
2624 static HRESULT WINAPI
ddraw7_GetSurfaceFromDC(IDirectDraw7
*iface
, HDC hdc
,
2625 IDirectDrawSurface7
**Surface
)
2627 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2628 struct wined3d_surface
*wined3d_surface
;
2629 struct ddraw_surface
*surface_impl
;
2631 TRACE("iface %p, dc %p, surface %p.\n", iface
, hdc
, Surface
);
2633 if (!Surface
) return E_INVALIDARG
;
2635 if (!(wined3d_surface
= wined3d_device_get_surface_from_dc(ddraw
->wined3d_device
, hdc
)))
2637 TRACE("No surface found for dc %p.\n", hdc
);
2639 return DDERR_NOTFOUND
;
2642 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
2643 *Surface
= &surface_impl
->IDirectDrawSurface7_iface
;
2644 IDirectDrawSurface7_AddRef(*Surface
);
2645 TRACE("Returning surface %p.\n", Surface
);
2649 static HRESULT WINAPI
ddraw4_GetSurfaceFromDC(IDirectDraw4
*iface
, HDC dc
,
2650 IDirectDrawSurface4
**surface
)
2652 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2653 struct ddraw_surface
*surface_impl
;
2654 IDirectDrawSurface7
*surface7
;
2657 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2659 if (!surface
) return E_INVALIDARG
;
2661 hr
= ddraw7_GetSurfaceFromDC(&ddraw
->IDirectDraw7_iface
, dc
, &surface7
);
2667 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2668 /* Tests say this is true */
2669 *surface
= (IDirectDrawSurface4
*)&surface_impl
->IDirectDrawSurface_iface
;
2670 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2671 IDirectDrawSurface7_Release(surface7
);
2676 static HRESULT CALLBACK
restore_callback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
2678 IDirectDrawSurface_Restore(surface
);
2679 IDirectDrawSurface_Release(surface
);
2681 return DDENUMRET_OK
;
2684 static HRESULT WINAPI
ddraw7_RestoreAllSurfaces(IDirectDraw7
*iface
)
2686 TRACE("iface %p.\n", iface
);
2688 return IDirectDraw7_EnumSurfaces(iface
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
2689 NULL
, NULL
, restore_callback
);
2692 static HRESULT WINAPI
ddraw4_RestoreAllSurfaces(IDirectDraw4
*iface
)
2694 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2696 TRACE("iface %p.\n", iface
);
2698 return ddraw7_RestoreAllSurfaces(&ddraw
->IDirectDraw7_iface
);
2701 /*****************************************************************************
2702 * IDirectDraw7::StartModeTest
2704 * Tests the specified video modes to update the system registry with
2705 * refresh rate information. StartModeTest starts the mode test,
2706 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
2707 * isn't called within 15 seconds, the mode is failed automatically
2709 * As refresh rates are handled by the X server, I don't think this
2710 * Method is important
2713 * Modes: An array of mode specifications
2714 * NumModes: The number of modes in Modes
2715 * Flags: Some flags...
2718 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
2719 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
2722 *****************************************************************************/
2723 static HRESULT WINAPI
ddraw7_StartModeTest(IDirectDraw7
*iface
, SIZE
*Modes
, DWORD NumModes
, DWORD Flags
)
2725 FIXME("iface %p, modes %p, mode_count %u, flags %#x partial stub!\n",
2726 iface
, Modes
, NumModes
, Flags
);
2728 /* This looks sane */
2729 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
2731 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
2732 * As it is not, DDERR_TESTFINISHED is returned
2733 * (hopefully that's correct
2735 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
2736 * well, that value doesn't (yet) exist in the wine headers, so ignore it
2742 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
, DDSURFACEDESC2
*surface_desc
,
2743 IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
2745 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2746 struct ddraw_surface
*impl
;
2749 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2750 iface
, surface_desc
, surface
, outer_unknown
);
2752 wined3d_mutex_lock();
2754 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2756 WARN("Cooperative level not set.\n");
2757 wined3d_mutex_unlock();
2758 return DDERR_NOCOOPERATIVELEVELSET
;
2761 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2763 WARN("Application supplied invalid surface descriptor\n");
2764 wined3d_mutex_unlock();
2765 return DDERR_INVALIDPARAMS
;
2768 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2770 if (TRACE_ON(ddraw
))
2772 TRACE(" (%p) Requesting surface desc :\n", iface
);
2773 DDRAW_dump_surface_desc(surface_desc
);
2776 WARN("Application tried to create an explicit front or back buffer\n");
2777 wined3d_mutex_unlock();
2778 return DDERR_INVALIDCAPS
;
2781 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 7);
2782 wined3d_mutex_unlock();
2789 *surface
= &impl
->IDirectDrawSurface7_iface
;
2790 IDirectDraw7_AddRef(iface
);
2791 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2796 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
2797 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
2799 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2800 struct ddraw_surface
*impl
;
2803 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2804 iface
, surface_desc
, surface
, outer_unknown
);
2806 wined3d_mutex_lock();
2808 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2810 WARN("Cooperative level not set.\n");
2811 wined3d_mutex_unlock();
2812 return DDERR_NOCOOPERATIVELEVELSET
;
2815 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2817 WARN("Application supplied invalid surface descriptor\n");
2818 wined3d_mutex_unlock();
2819 return DDERR_INVALIDPARAMS
;
2822 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2824 if (TRACE_ON(ddraw
))
2826 TRACE(" (%p) Requesting surface desc :\n", iface
);
2827 DDRAW_dump_surface_desc(surface_desc
);
2830 WARN("Application tried to create an explicit front or back buffer\n");
2831 wined3d_mutex_unlock();
2832 return DDERR_INVALIDCAPS
;
2835 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 4);
2836 wined3d_mutex_unlock();
2843 *surface
= &impl
->IDirectDrawSurface4_iface
;
2844 IDirectDraw4_AddRef(iface
);
2845 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2850 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
2851 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2853 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2854 struct ddraw_surface
*impl
;
2856 DDSURFACEDESC2 surface_desc2
;
2858 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2859 iface
, surface_desc
, surface
, outer_unknown
);
2861 wined3d_mutex_lock();
2863 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2865 WARN("Cooperative level not set.\n");
2866 wined3d_mutex_unlock();
2867 return DDERR_NOCOOPERATIVELEVELSET
;
2870 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2872 WARN("Application supplied invalid surface descriptor\n");
2873 wined3d_mutex_unlock();
2874 return DDERR_INVALIDPARAMS
;
2877 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2878 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2880 if (TRACE_ON(ddraw
))
2882 TRACE(" (%p) Requesting surface desc :\n", iface
);
2883 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
2886 WARN("Application tried to create an explicit front or back buffer\n");
2887 wined3d_mutex_unlock();
2888 return DDERR_INVALIDCAPS
;
2891 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 2);
2892 wined3d_mutex_unlock();
2899 *surface
= &impl
->IDirectDrawSurface_iface
;
2900 impl
->ifaceToRelease
= NULL
;
2905 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
2906 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2908 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2909 struct ddraw_surface
*impl
;
2911 DDSURFACEDESC2 surface_desc2
;
2913 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2914 iface
, surface_desc
, surface
, outer_unknown
);
2916 wined3d_mutex_lock();
2918 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2920 WARN("Cooperative level not set.\n");
2921 wined3d_mutex_unlock();
2922 return DDERR_NOCOOPERATIVELEVELSET
;
2925 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2927 WARN("Application supplied invalid surface descriptor\n");
2928 wined3d_mutex_unlock();
2929 return DDERR_INVALIDPARAMS
;
2932 if ((surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
))
2933 == (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
)
2934 || (surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
))
2935 == ((DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
)))
2937 WARN("Application tried to create an explicit front or back buffer.\n");
2938 wined3d_mutex_unlock();
2939 return DDERR_INVALIDCAPS
;
2942 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2943 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 1);
2944 wined3d_mutex_unlock();
2951 *surface
= &impl
->IDirectDrawSurface_iface
;
2952 impl
->ifaceToRelease
= NULL
;
2957 #define DDENUMSURFACES_SEARCHTYPE (DDENUMSURFACES_CANBECREATED|DDENUMSURFACES_DOESEXIST)
2958 #define DDENUMSURFACES_MATCHTYPE (DDENUMSURFACES_ALL|DDENUMSURFACES_MATCH|DDENUMSURFACES_NOMATCH)
2961 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
2962 const DDPIXELFORMAT
*provided
)
2964 /* Some flags must be present in both or neither for a match. */
2965 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
2966 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
2967 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
2969 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
2972 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
2975 if (requested
->dwFlags
& DDPF_FOURCC
)
2976 if (requested
->dwFourCC
!= provided
->dwFourCC
)
2979 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
2980 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
2981 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
2984 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
2985 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
2986 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
2989 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
2990 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
2993 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
2994 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
2996 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
2999 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
3000 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
3006 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3015 #define CMP(FLAG, FIELD) \
3016 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3017 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3019 static const struct compare_info compare
[] =
3021 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3022 CMP(BACKBUFFERCOUNT
, u5
.dwBackBufferCount
),
3024 CMP(CKDESTBLT
, ddckCKDestBlt
),
3025 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3026 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3027 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3028 CMP(HEIGHT
, dwHeight
),
3029 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3030 CMP(LPSURFACE
, lpSurface
),
3031 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3032 CMP(PITCH
, u1
/* lPitch */),
3033 /* PIXELFORMAT: manual */
3034 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3035 CMP(TEXTURESTAGE
, dwTextureStage
),
3036 CMP(WIDTH
, dwWidth
),
3037 /* ZBUFFERBITDEPTH: "obsolete" */
3044 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3047 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
3049 if (requested
->dwFlags
& compare
[i
].flag
3050 && memcmp((const char *)provided
+ compare
[i
].offset
,
3051 (const char *)requested
+ compare
[i
].offset
,
3052 compare
[i
].size
) != 0)
3056 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3058 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3059 &provided
->u4
.ddpfPixelFormat
))
3066 #undef DDENUMSURFACES_SEARCHTYPE
3067 #undef DDENUMSURFACES_MATCHTYPE
3069 struct surfacescallback2_context
3071 LPDDENUMSURFACESCALLBACK2 func
;
3075 struct surfacescallback_context
3077 LPDDENUMSURFACESCALLBACK func
;
3081 static HRESULT CALLBACK
EnumSurfacesCallback2Thunk(IDirectDrawSurface7
*surface
,
3082 DDSURFACEDESC2
*surface_desc
, void *context
)
3084 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3085 struct surfacescallback2_context
*cbcontext
= context
;
3087 IDirectDrawSurface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
3088 IDirectDrawSurface7_Release(surface
);
3090 return cbcontext
->func(&surface_impl
->IDirectDrawSurface4_iface
,
3091 surface_desc
, cbcontext
->context
);
3094 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3095 DDSURFACEDESC2
*surface_desc
, void *context
)
3097 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3098 struct surfacescallback_context
*cbcontext
= context
;
3100 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
3101 IDirectDrawSurface7_Release(surface
);
3103 return cbcontext
->func(&surface_impl
->IDirectDrawSurface_iface
,
3104 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3107 /*****************************************************************************
3108 * IDirectDraw7::EnumSurfaces
3110 * Loops through all surfaces attached to this device and calls the
3111 * application callback. This can't be relayed to WineD3DDevice,
3112 * because some WineD3DSurfaces' parents are IParent objects
3115 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3116 * DDSD: Description to filter for
3117 * Context: Application-provided pointer, it's passed unmodified to the
3119 * Callback: Address to call for each surface
3122 * DDERR_INVALIDPARAMS if the callback is NULL
3125 *****************************************************************************/
3126 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD Flags
,
3127 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMSURFACESCALLBACK7 Callback
)
3129 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3130 struct ddraw_surface
*surf
;
3132 DDSURFACEDESC2 desc
;
3133 struct list
*entry
, *entry2
;
3135 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3136 iface
, Flags
, DDSD
, Context
, Callback
);
3138 all
= Flags
& DDENUMSURFACES_ALL
;
3139 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
3142 return DDERR_INVALIDPARAMS
;
3144 wined3d_mutex_lock();
3146 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
3147 LIST_FOR_EACH_SAFE(entry
, entry2
, &ddraw
->surface_list
)
3149 surf
= LIST_ENTRY(entry
, struct ddraw_surface
, surface_list_entry
);
3151 if (!surf
->iface_count
)
3153 WARN("Not enumerating surface %p because it doesn't have any references.\n", surf
);
3157 if (all
|| (nomatch
!= ddraw_match_surface_desc(DDSD
, &surf
->surface_desc
)))
3159 TRACE("Enumerating surface %p.\n", surf
);
3160 desc
= surf
->surface_desc
;
3161 IDirectDrawSurface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
3162 if (Callback(&surf
->IDirectDrawSurface7_iface
, &desc
, Context
) != DDENUMRET_OK
)
3164 wined3d_mutex_unlock();
3170 wined3d_mutex_unlock();
3175 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3176 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3178 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3179 struct surfacescallback2_context cbcontext
;
3181 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3182 iface
, flags
, surface_desc
, context
, callback
);
3184 cbcontext
.func
= callback
;
3185 cbcontext
.context
= context
;
3187 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
,
3188 &cbcontext
, EnumSurfacesCallback2Thunk
);
3191 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3192 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3194 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3195 struct surfacescallback_context cbcontext
;
3196 DDSURFACEDESC2 surface_desc2
;
3198 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3199 iface
, flags
, surface_desc
, context
, callback
);
3201 cbcontext
.func
= callback
;
3202 cbcontext
.context
= context
;
3204 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3205 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3206 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3209 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3210 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3212 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3213 struct surfacescallback_context cbcontext
;
3214 DDSURFACEDESC2 surface_desc2
;
3216 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3217 iface
, flags
, surface_desc
, context
, callback
);
3219 cbcontext
.func
= callback
;
3220 cbcontext
.context
= context
;
3222 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3223 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3224 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3227 /*****************************************************************************
3228 * DirectDrawCreateClipper (DDRAW.@)
3230 * Creates a new IDirectDrawClipper object.
3233 * Clipper: Address to write the interface pointer to
3234 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3238 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3239 * E_OUTOFMEMORY if allocating the object failed
3241 *****************************************************************************/
3242 HRESULT WINAPI
DirectDrawCreateClipper(DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3244 struct ddraw_clipper
*object
;
3247 TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
3248 flags
, clipper
, outer_unknown
);
3251 return CLASS_E_NOAGGREGATION
;
3253 wined3d_mutex_lock();
3255 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3258 wined3d_mutex_unlock();
3259 return E_OUTOFMEMORY
;
3262 hr
= ddraw_clipper_init(object
);
3265 WARN("Failed to initialize clipper, hr %#x.\n", hr
);
3266 HeapFree(GetProcessHeap(), 0, object
);
3267 wined3d_mutex_unlock();
3271 TRACE("Created clipper %p.\n", object
);
3272 *clipper
= &object
->IDirectDrawClipper_iface
;
3273 wined3d_mutex_unlock();
3278 /*****************************************************************************
3279 * IDirectDraw7::CreateClipper
3281 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3283 *****************************************************************************/
3284 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3285 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3287 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3288 iface
, Flags
, Clipper
, UnkOuter
);
3290 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3293 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
, DWORD flags
,
3294 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3296 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3298 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3299 iface
, flags
, clipper
, outer_unknown
);
3301 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3304 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
3305 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3307 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3309 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3310 iface
, flags
, clipper
, outer_unknown
);
3312 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3315 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
3316 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3318 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3320 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3321 iface
, flags
, clipper
, outer_unknown
);
3323 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3326 /*****************************************************************************
3327 * IDirectDraw7::CreatePalette
3329 * Creates a new IDirectDrawPalette object
3332 * Flags: The flags for the new clipper
3333 * ColorTable: Color table to assign to the new clipper
3334 * Palette: Address to write the interface pointer to
3335 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3339 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3340 * E_OUTOFMEMORY if allocating the object failed
3342 *****************************************************************************/
3343 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
3344 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
3346 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3347 struct ddraw_palette
*object
;
3350 TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
3351 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3354 return CLASS_E_NOAGGREGATION
;
3356 wined3d_mutex_lock();
3358 /* The refcount test shows that a cooplevel is required for this */
3359 if (!ddraw
->cooperative_level
)
3361 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3362 wined3d_mutex_unlock();
3363 return DDERR_NOCOOPERATIVELEVELSET
;
3366 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(*object
));
3369 ERR("Out of memory when allocating memory for a palette implementation\n");
3370 wined3d_mutex_unlock();
3371 return E_OUTOFMEMORY
;
3374 hr
= ddraw_palette_init(object
, ddraw
, Flags
, ColorTable
);
3377 WARN("Failed to initialize palette, hr %#x.\n", hr
);
3378 HeapFree(GetProcessHeap(), 0, object
);
3379 wined3d_mutex_unlock();
3383 TRACE("Created palette %p.\n", object
);
3384 *Palette
= &object
->IDirectDrawPalette_iface
;
3385 wined3d_mutex_unlock();
3390 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
, PALETTEENTRY
*entries
,
3391 IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3393 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3396 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3397 iface
, flags
, entries
, palette
, outer_unknown
);
3399 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3400 if (SUCCEEDED(hr
) && *palette
)
3402 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3403 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3404 IDirectDraw4_AddRef(iface
);
3405 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3410 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
3411 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3413 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3416 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3417 iface
, flags
, entries
, palette
, outer_unknown
);
3419 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3420 if (SUCCEEDED(hr
) && *palette
)
3422 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3423 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3424 impl
->ifaceToRelease
= NULL
;
3430 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
3431 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3433 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3436 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3437 iface
, flags
, entries
, palette
, outer_unknown
);
3439 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3440 if (SUCCEEDED(hr
) && *palette
)
3442 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3443 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3444 impl
->ifaceToRelease
= NULL
;
3450 /*****************************************************************************
3451 * IDirectDraw7::DuplicateSurface
3453 * Duplicates a surface. The surface memory points to the same memory as
3454 * the original surface, and it's released when the last surface referencing
3455 * it is released. I guess that's beyond Wine's surface management right now
3456 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3457 * test application to implement this)
3460 * Src: Address of the source surface
3461 * Dest: Address to write the new surface pointer to
3464 * See IDirectDraw7::CreateSurface
3466 *****************************************************************************/
3467 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
3468 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
3470 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(Src
);
3472 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
3474 /* For now, simply create a new, independent surface */
3475 return IDirectDraw7_CreateSurface(iface
, &src_surface
->surface_desc
, Dest
, NULL
);
3478 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
, IDirectDrawSurface4
*src
,
3479 IDirectDrawSurface4
**dst
)
3481 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
3482 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3483 struct ddraw_surface
*dst_impl
;
3484 IDirectDrawSurface7
*dst7
;
3487 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3489 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3490 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3496 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3497 *dst
= &dst_impl
->IDirectDrawSurface4_iface
;
3498 IDirectDrawSurface4_AddRef(*dst
);
3499 IDirectDrawSurface7_Release(dst7
);
3504 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
3505 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
3507 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3508 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3509 struct ddraw_surface
*dst_impl
;
3510 IDirectDrawSurface7
*dst7
;
3513 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3515 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3516 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3519 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3520 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3521 IDirectDrawSurface_AddRef(*dst
);
3522 IDirectDrawSurface7_Release(dst7
);
3527 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
, IDirectDrawSurface
*src
,
3528 IDirectDrawSurface
**dst
)
3530 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3531 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3532 struct ddraw_surface
*dst_impl
;
3533 IDirectDrawSurface7
*dst7
;
3536 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3538 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3539 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3542 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3543 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3544 IDirectDrawSurface_AddRef(*dst
);
3545 IDirectDrawSurface7_Release(dst7
);
3550 /*****************************************************************************
3551 * IDirect3D7::EnumDevices
3553 * The EnumDevices method for IDirect3D7. It enumerates all supported
3554 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
3557 * callback: Function to call for each enumerated device
3558 * context: Pointer to pass back to the app
3561 * D3D_OK, or the return value of the GetCaps call
3563 *****************************************************************************/
3564 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
3566 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
3567 D3DDEVICEDESC7 device_desc7
;
3571 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3574 return DDERR_INVALIDPARAMS
;
3576 wined3d_mutex_lock();
3578 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3580 wined3d_mutex_unlock();
3584 for (i
= 0; i
< sizeof(device_list7
)/sizeof(device_list7
[0]); i
++)
3588 device_desc7
.deviceGUID
= *device_list7
[i
].device_guid
;
3589 ret
= callback(device_list7
[i
].interface_name
, device_list7
[i
].device_name
, &device_desc7
, context
);
3590 if (ret
!= DDENUMRET_OK
)
3592 TRACE("Application cancelled the enumeration.\n");
3593 wined3d_mutex_unlock();
3598 TRACE("End of enumeration.\n");
3600 wined3d_mutex_unlock();
3605 /*****************************************************************************
3606 * IDirect3D3::EnumDevices
3608 * Enumerates all supported Direct3DDevice interfaces. This is the
3609 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
3611 * Version 1, 2 and 3
3614 * callback: Application-provided routine to call for each enumerated device
3615 * Context: Pointer to pass to the callback
3618 * D3D_OK on success,
3619 * The result of IDirect3DImpl_GetCaps if it failed
3621 *****************************************************************************/
3622 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3624 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
3626 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3627 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
3628 D3DDEVICEDESC7 device_desc7
;
3631 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
3632 * name string. Let's put the string in a sufficiently sized array in
3633 * writable memory. */
3634 char device_name
[50];
3635 strcpy(device_name
,"Direct3D HEL");
3637 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3640 return DDERR_INVALIDPARAMS
;
3642 wined3d_mutex_lock();
3644 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3646 wined3d_mutex_unlock();
3649 ddraw_d3dcaps1_from_7(&device_desc1
, &device_desc7
);
3651 /* Do I have to enumerate the reference id? Note from old d3d7:
3652 * "It seems that enumerating the reference IID on Direct3D 1 games
3653 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
3655 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
3656 * EnumReference which enables / disables enumerating the reference
3657 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
3658 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
3659 * demo directory suggest this.
3661 * Some games(GTA 2) seem to use the second enumerated device, so I have
3662 * to enumerate at least 2 devices. So enumerate the reference device to
3665 * Other games (Rollcage) tell emulation and hal device apart by certain
3666 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
3667 * limitation flag), and it refuses all devices that have the perspective
3668 * flag set. This way it refuses the emulation device, and HAL devices
3669 * never have POW2 unset in d3d7 on windows. */
3670 if (ddraw
->d3dversion
!= 1)
3672 static CHAR reference_description
[] = "RGB Direct3D emulation";
3674 TRACE("Enumerating WineD3D D3DDevice interface.\n");
3675 hal_desc
= device_desc1
;
3676 hel_desc
= device_desc1
;
3677 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
3678 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3679 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3680 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3681 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3682 /* RGB, RAMP and MMX devices have a HAL dcmColorModel of 0 */
3683 hal_desc
.dcmColorModel
= 0;
3684 /* RGB, RAMP and MMX devices cannot report HAL hardware flags */
3685 hal_desc
.dwFlags
= 0;
3687 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
3688 device_name
, &hal_desc
, &hel_desc
, context
);
3689 if (hr
!= D3DENUMRET_OK
)
3691 TRACE("Application cancelled the enumeration.\n");
3692 wined3d_mutex_unlock();
3697 strcpy(device_name
,"Direct3D HAL");
3699 TRACE("Enumerating HAL Direct3D device.\n");
3700 hal_desc
= device_desc1
;
3701 hel_desc
= device_desc1
;
3703 /* The hal device does not have the pow2 flag set in hel, but in hal. */
3704 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3705 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3706 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3707 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3708 /* HAL devices have a HEL dcmColorModel of 0 */
3709 hel_desc
.dcmColorModel
= 0;
3711 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
3712 device_name
, &hal_desc
, &hel_desc
, context
);
3713 if (hr
!= D3DENUMRET_OK
)
3715 TRACE("Application cancelled the enumeration.\n");
3716 wined3d_mutex_unlock();
3720 TRACE("End of enumeration.\n");
3722 wined3d_mutex_unlock();
3727 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3729 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3731 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3733 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3736 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3738 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3740 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3742 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3745 /*****************************************************************************
3746 * IDirect3D3::CreateLight
3748 * Creates an IDirect3DLight interface. This interface is used in
3749 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
3750 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
3751 * uses the IDirect3DDevice7 interface with D3D7 lights.
3753 * Version 1, 2 and 3
3756 * light: Address to store the new interface pointer
3757 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3762 * DDERR_OUTOFMEMORY if memory allocation failed
3763 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3765 *****************************************************************************/
3766 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
,
3767 IUnknown
*outer_unknown
)
3769 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3770 struct d3d_light
*object
;
3772 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3774 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3776 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3779 ERR("Failed to allocate light memory.\n");
3780 return DDERR_OUTOFMEMORY
;
3783 d3d_light_init(object
, ddraw
);
3785 TRACE("Created light %p.\n", object
);
3786 *light
= &object
->IDirect3DLight_iface
;
3791 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3793 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3795 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3797 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3800 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3802 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3804 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3806 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3809 /*****************************************************************************
3810 * IDirect3D3::CreateMaterial
3812 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
3813 * and older versions. The IDirect3DMaterial implementation wraps its
3814 * functionality to IDirect3DDevice7::SetMaterial and friends.
3816 * Version 1, 2 and 3
3819 * material: Address to store the new interface's pointer to
3820 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3825 * DDERR_OUTOFMEMORY if memory allocation failed
3826 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3828 *****************************************************************************/
3829 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
,
3830 IUnknown
*outer_unknown
)
3832 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3833 struct d3d_material
*object
;
3835 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3837 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3839 object
= d3d_material_create(ddraw
);
3842 ERR("Failed to allocate material memory.\n");
3843 return DDERR_OUTOFMEMORY
;
3846 TRACE("Created material %p.\n", object
);
3847 *material
= &object
->IDirect3DMaterial3_iface
;
3852 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
,
3853 IUnknown
*outer_unknown
)
3855 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3856 struct d3d_material
*object
;
3858 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3860 object
= d3d_material_create(ddraw
);
3863 ERR("Failed to allocate material memory.\n");
3864 return DDERR_OUTOFMEMORY
;
3867 TRACE("Created material %p.\n", object
);
3868 *material
= &object
->IDirect3DMaterial2_iface
;
3873 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
,
3874 IUnknown
*outer_unknown
)
3876 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3877 struct d3d_material
*object
;
3879 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3881 object
= d3d_material_create(ddraw
);
3884 ERR("Failed to allocate material memory.\n");
3885 return DDERR_OUTOFMEMORY
;
3888 TRACE("Created material %p.\n", object
);
3889 *material
= &object
->IDirect3DMaterial_iface
;
3894 /*****************************************************************************
3895 * IDirect3D3::CreateViewport
3897 * Creates an IDirect3DViewport interface. This interface is used
3898 * by Direct3D and earlier versions for Viewport management. In Direct3D7
3899 * it has been replaced by a viewport structure and
3900 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
3901 * uses the IDirect3DDevice7 methods for its functionality
3904 * Viewport: Address to store the new interface pointer
3905 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3910 * DDERR_OUTOFMEMORY if memory allocation failed
3911 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3913 *****************************************************************************/
3914 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
,
3915 IUnknown
*outer_unknown
)
3917 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3918 struct d3d_viewport
*object
;
3920 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
3922 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3924 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3927 ERR("Failed to allocate viewport memory.\n");
3928 return DDERR_OUTOFMEMORY
;
3931 d3d_viewport_init(object
, ddraw
);
3933 TRACE("Created viewport %p.\n", object
);
3934 *viewport
= &object
->IDirect3DViewport3_iface
;
3939 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
3941 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3943 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
3945 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
3949 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
3951 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3953 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
3955 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
3959 /*****************************************************************************
3960 * IDirect3D3::FindDevice
3962 * This method finds a device with the requested properties and returns a
3963 * device description
3967 * fds: Describes the requested device characteristics
3968 * fdr: Returns the device description
3972 * DDERR_INVALIDPARAMS if no device was found
3974 *****************************************************************************/
3975 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
3977 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3978 D3DDEVICEDESC7 desc7
;
3979 D3DDEVICEDESC desc1
;
3982 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
3984 if (!fds
|| !fdr
) return DDERR_INVALIDPARAMS
;
3986 if (fds
->dwSize
!= sizeof(D3DFINDDEVICESEARCH
)
3987 || fdr
->dwSize
!= sizeof(D3DFINDDEVICERESULT
))
3988 return DDERR_INVALIDPARAMS
;
3990 if ((fds
->dwFlags
& D3DFDS_COLORMODEL
)
3991 && fds
->dcmColorModel
!= D3DCOLOR_RGB
)
3993 WARN("Trying to request a non-RGB D3D color model. Not supported.\n");
3994 return DDERR_INVALIDPARAMS
; /* No real idea what to return here :-) */
3997 if (fds
->dwFlags
& D3DFDS_GUID
)
3999 TRACE("Trying to match guid %s.\n", debugstr_guid(&(fds
->guid
)));
4000 if (!IsEqualGUID(&IID_D3DDEVICE_WineD3D
, &fds
->guid
)
4001 && !IsEqualGUID(&IID_IDirect3DHALDevice
, &fds
->guid
)
4002 && !IsEqualGUID(&IID_IDirect3DRGBDevice
, &fds
->guid
))
4004 WARN("No match for this GUID.\n");
4005 return DDERR_NOTFOUND
;
4010 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &desc7
)))
4013 /* Now return our own GUID */
4014 ddraw_d3dcaps1_from_7(&desc1
, &desc7
);
4015 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4016 fdr
->ddHwDesc
= desc1
;
4017 fdr
->ddSwDesc
= desc1
;
4019 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4024 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4026 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4028 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4030 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4033 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4035 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4037 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4039 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4042 /*****************************************************************************
4043 * IDirect3D7::CreateDevice
4045 * Creates an IDirect3DDevice7 interface.
4047 * Version 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4048 * DirectDraw surfaces and are created with
4049 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4050 * create the device object and QueryInterfaces for IDirect3DDevice
4053 * refiid: IID of the device to create
4054 * Surface: Initial rendertarget
4055 * Device: Address to return the interface pointer
4059 * DDERR_OUTOFMEMORY if memory allocation failed
4060 * DDERR_INVALIDPARAMS if a device exists already
4062 *****************************************************************************/
4063 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4064 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4066 struct ddraw_surface
*target
= unsafe_impl_from_IDirectDrawSurface7(surface
);
4067 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4068 struct d3d_device
*object
;
4071 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4073 wined3d_mutex_lock();
4074 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, target
, (IUnknown
*)surface
, 7, &object
, NULL
)))
4076 *device
= &object
->IDirect3DDevice7_iface
;
4080 WARN("Failed to create device, hr %#x.\n", hr
);
4083 wined3d_mutex_unlock();
4088 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4089 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4091 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface4(surface
);
4092 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4093 struct d3d_device
*device_impl
;
4096 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4097 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4100 return CLASS_E_NOAGGREGATION
;
4102 wined3d_mutex_lock();
4103 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 3, &device_impl
, NULL
)))
4105 *device
= &device_impl
->IDirect3DDevice3_iface
;
4109 WARN("Failed to create device, hr %#x.\n", hr
);
4112 wined3d_mutex_unlock();
4117 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4118 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4120 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface(surface
);
4121 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4122 struct d3d_device
*device_impl
;
4125 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4126 iface
, debugstr_guid(riid
), surface
, device
);
4128 wined3d_mutex_lock();
4129 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 2, &device_impl
, NULL
)))
4131 *device
= &device_impl
->IDirect3DDevice2_iface
;
4135 WARN("Failed to create device, hr %#x.\n", hr
);
4138 wined3d_mutex_unlock();
4143 /*****************************************************************************
4144 * IDirect3D7::CreateVertexBuffer
4146 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4152 * desc: Requested Vertex buffer properties
4153 * vertex_buffer: Address to return the interface pointer at
4154 * flags: Some flags, should be 0
4158 * DDERR_OUTOFMEMORY if memory allocation failed
4159 * The return value of IWineD3DDevice::CreateVertexBuffer if this call fails
4160 * DDERR_INVALIDPARAMS if desc or vertex_buffer is NULL
4162 *****************************************************************************/
4163 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4164 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4166 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4167 struct d3d_vertex_buffer
*object
;
4170 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
4171 iface
, desc
, vertex_buffer
, flags
);
4173 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4175 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4178 TRACE("Created vertex buffer %p.\n", object
);
4179 *vertex_buffer
= &object
->IDirect3DVertexBuffer7_iface
;
4182 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4187 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4188 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4190 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4191 struct d3d_vertex_buffer
*object
;
4194 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n",
4195 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4198 return CLASS_E_NOAGGREGATION
;
4199 if (!vertex_buffer
|| !desc
)
4200 return DDERR_INVALIDPARAMS
;
4202 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4205 TRACE("Created vertex buffer %p.\n", object
);
4206 *vertex_buffer
= &object
->IDirect3DVertexBuffer_iface
;
4209 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4214 /*****************************************************************************
4215 * IDirect3D7::EnumZBufferFormats
4217 * Enumerates all supported Z buffer pixel formats
4223 * callback: callback to call for each pixel format
4224 * context: Pointer to pass back to the callback
4228 * DDERR_INVALIDPARAMS if callback is NULL
4229 * For details, see IWineD3DDevice::EnumZBufferFormats
4231 *****************************************************************************/
4232 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4233 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4235 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4236 struct wined3d_display_mode mode
;
4237 enum wined3d_device_type type
;
4241 /* Order matters. Specifically, BattleZone II (full version) expects the
4242 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4243 static const enum wined3d_format_id formats
[] =
4245 WINED3DFMT_S1_UINT_D15_UNORM
,
4246 WINED3DFMT_D16_UNORM
,
4247 WINED3DFMT_X8D24_UNORM
,
4248 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4249 WINED3DFMT_D24_UNORM_S8_UINT
,
4250 WINED3DFMT_D32_UNORM
,
4253 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4254 iface
, debugstr_guid(device_iid
), callback
, context
);
4256 if (!callback
) return DDERR_INVALIDPARAMS
;
4258 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4259 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4260 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4262 TRACE("Asked for HAL device.\n");
4263 type
= WINED3D_DEVICE_TYPE_HAL
;
4265 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4266 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4268 TRACE("Asked for SW device.\n");
4269 type
= WINED3D_DEVICE_TYPE_SW
;
4271 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4273 TRACE("Asked for REF device.\n");
4274 type
= WINED3D_DEVICE_TYPE_REF
;
4276 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4278 TRACE("Asked for NULLREF device.\n");
4279 type
= WINED3D_DEVICE_TYPE_NULLREF
;
4283 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4284 type
= WINED3D_DEVICE_TYPE_HAL
;
4287 wined3d_mutex_lock();
4288 /* We need an adapter format from somewhere to please wined3d and WGL.
4289 * Use the current display mode. So far all cards offer the same depth
4290 * stencil format for all modes, but if some do not and applications do
4291 * not like that we'll have to find some workaround, like iterating over
4292 * all imaginable formats and collecting all the depth stencil formats we
4294 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
4296 ERR("Failed to get display mode, hr %#x.\n", hr
);
4297 wined3d_mutex_unlock();
4301 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
4303 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4304 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_SURFACE
, formats
[i
])))
4306 DDPIXELFORMAT pformat
;
4308 memset(&pformat
, 0, sizeof(pformat
));
4309 pformat
.dwSize
= sizeof(pformat
);
4310 ddrawformat_from_wined3dformat(&pformat
, formats
[i
]);
4312 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
4313 hr
= callback(&pformat
, context
);
4314 if (hr
!= DDENUMRET_OK
)
4316 TRACE("Format enumeration cancelled by application.\n");
4317 wined3d_mutex_unlock();
4323 /* Historically some windows drivers used dwZBufferBitDepth=24 for WINED3DFMT_X8D24_UNORM,
4324 * while others used dwZBufferBitDepth=32. In either case the pitch matches a 32 bits per
4325 * pixel format, so we use dwZBufferBitDepth=32. Some games expect 24. Windows Vista and
4326 * newer enumerate both versions, so we do the same(bug 22434) */
4327 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4328 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_SURFACE
, WINED3DFMT_X8D24_UNORM
)))
4330 DDPIXELFORMAT x8d24
=
4332 sizeof(x8d24
), DDPF_ZBUFFER
, 0,
4333 {24}, {0x00000000}, {0x00ffffff}, {0x00000000}
4335 TRACE("Enumerating WINED3DFMT_X8D24_UNORM, dwZBufferBitDepth=24 version\n");
4336 callback(&x8d24
, context
);
4339 TRACE("End of enumeration.\n");
4341 wined3d_mutex_unlock();
4346 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
4347 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4349 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4351 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4352 iface
, debugstr_guid(device_iid
), callback
, context
);
4354 return d3d7_EnumZBufferFormats(&ddraw
->IDirect3D7_iface
, device_iid
, callback
, context
);
4357 /*****************************************************************************
4358 * IDirect3D7::EvictManagedTextures
4360 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
4361 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
4366 * D3D_OK, because it's a stub
4368 *****************************************************************************/
4369 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
4371 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4373 TRACE("iface %p!\n", iface
);
4375 wined3d_mutex_lock();
4376 if (ddraw
->flags
& DDRAW_D3D_INITIALIZED
)
4377 wined3d_device_evict_managed_resources(ddraw
->wined3d_device
);
4378 wined3d_mutex_unlock();
4383 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
4385 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4387 TRACE("iface %p.\n", iface
);
4389 return d3d7_EvictManagedTextures(&ddraw
->IDirect3D7_iface
);
4392 /*****************************************************************************
4393 * IDirectDraw7 VTable
4394 *****************************************************************************/
4395 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
4398 ddraw7_QueryInterface
,
4403 ddraw7_CreateClipper
,
4404 ddraw7_CreatePalette
,
4405 ddraw7_CreateSurface
,
4406 ddraw7_DuplicateSurface
,
4407 ddraw7_EnumDisplayModes
,
4408 ddraw7_EnumSurfaces
,
4409 ddraw7_FlipToGDISurface
,
4411 ddraw7_GetDisplayMode
,
4412 ddraw7_GetFourCCCodes
,
4413 ddraw7_GetGDISurface
,
4414 ddraw7_GetMonitorFrequency
,
4416 ddraw7_GetVerticalBlankStatus
,
4418 ddraw7_RestoreDisplayMode
,
4419 ddraw7_SetCooperativeLevel
,
4420 ddraw7_SetDisplayMode
,
4421 ddraw7_WaitForVerticalBlank
,
4423 ddraw7_GetAvailableVidMem
,
4425 ddraw7_GetSurfaceFromDC
,
4427 ddraw7_RestoreAllSurfaces
,
4428 ddraw7_TestCooperativeLevel
,
4429 ddraw7_GetDeviceIdentifier
,
4431 ddraw7_StartModeTest
,
4435 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
4438 ddraw4_QueryInterface
,
4443 ddraw4_CreateClipper
,
4444 ddraw4_CreatePalette
,
4445 ddraw4_CreateSurface
,
4446 ddraw4_DuplicateSurface
,
4447 ddraw4_EnumDisplayModes
,
4448 ddraw4_EnumSurfaces
,
4449 ddraw4_FlipToGDISurface
,
4451 ddraw4_GetDisplayMode
,
4452 ddraw4_GetFourCCCodes
,
4453 ddraw4_GetGDISurface
,
4454 ddraw4_GetMonitorFrequency
,
4456 ddraw4_GetVerticalBlankStatus
,
4458 ddraw4_RestoreDisplayMode
,
4459 ddraw4_SetCooperativeLevel
,
4460 ddraw4_SetDisplayMode
,
4461 ddraw4_WaitForVerticalBlank
,
4463 ddraw4_GetAvailableVidMem
,
4465 ddraw4_GetSurfaceFromDC
,
4467 ddraw4_RestoreAllSurfaces
,
4468 ddraw4_TestCooperativeLevel
,
4469 ddraw4_GetDeviceIdentifier
,
4472 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
4475 ddraw2_QueryInterface
,
4480 ddraw2_CreateClipper
,
4481 ddraw2_CreatePalette
,
4482 ddraw2_CreateSurface
,
4483 ddraw2_DuplicateSurface
,
4484 ddraw2_EnumDisplayModes
,
4485 ddraw2_EnumSurfaces
,
4486 ddraw2_FlipToGDISurface
,
4488 ddraw2_GetDisplayMode
,
4489 ddraw2_GetFourCCCodes
,
4490 ddraw2_GetGDISurface
,
4491 ddraw2_GetMonitorFrequency
,
4493 ddraw2_GetVerticalBlankStatus
,
4495 ddraw2_RestoreDisplayMode
,
4496 ddraw2_SetCooperativeLevel
,
4497 ddraw2_SetDisplayMode
,
4498 ddraw2_WaitForVerticalBlank
,
4500 ddraw2_GetAvailableVidMem
,
4503 static const struct IDirectDrawVtbl ddraw1_vtbl
=
4506 ddraw1_QueryInterface
,
4511 ddraw1_CreateClipper
,
4512 ddraw1_CreatePalette
,
4513 ddraw1_CreateSurface
,
4514 ddraw1_DuplicateSurface
,
4515 ddraw1_EnumDisplayModes
,
4516 ddraw1_EnumSurfaces
,
4517 ddraw1_FlipToGDISurface
,
4519 ddraw1_GetDisplayMode
,
4520 ddraw1_GetFourCCCodes
,
4521 ddraw1_GetGDISurface
,
4522 ddraw1_GetMonitorFrequency
,
4524 ddraw1_GetVerticalBlankStatus
,
4526 ddraw1_RestoreDisplayMode
,
4527 ddraw1_SetCooperativeLevel
,
4528 ddraw1_SetDisplayMode
,
4529 ddraw1_WaitForVerticalBlank
,
4532 static const struct IDirect3D7Vtbl d3d7_vtbl
=
4534 /* IUnknown methods */
4535 d3d7_QueryInterface
,
4538 /* IDirect3D7 methods */
4541 d3d7_CreateVertexBuffer
,
4542 d3d7_EnumZBufferFormats
,
4543 d3d7_EvictManagedTextures
4546 static const struct IDirect3D3Vtbl d3d3_vtbl
=
4548 /* IUnknown methods */
4549 d3d3_QueryInterface
,
4552 /* IDirect3D3 methods */
4555 d3d3_CreateMaterial
,
4556 d3d3_CreateViewport
,
4559 d3d3_CreateVertexBuffer
,
4560 d3d3_EnumZBufferFormats
,
4561 d3d3_EvictManagedTextures
4564 static const struct IDirect3D2Vtbl d3d2_vtbl
=
4566 /* IUnknown methods */
4567 d3d2_QueryInterface
,
4570 /* IDirect3D2 methods */
4573 d3d2_CreateMaterial
,
4574 d3d2_CreateViewport
,
4579 static const struct IDirect3DVtbl d3d1_vtbl
=
4581 /* IUnknown methods */
4582 d3d1_QueryInterface
,
4585 /* IDirect3D methods */
4589 d3d1_CreateMaterial
,
4590 d3d1_CreateViewport
,
4594 /*****************************************************************************
4597 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
4598 * if none was found.
4600 * This function is in ddraw.c and the DDraw object space because D3D7
4601 * vertex buffers are created using the IDirect3D interface to the ddraw
4602 * object, so they can be valid across D3D devices(theoretically. The ddraw
4603 * object also owns the wined3d device
4607 * fvf: Fvf to find the decl for
4610 * NULL in case of an error, the vertex declaration for the FVF otherwise.
4612 *****************************************************************************/
4613 struct wined3d_vertex_declaration
*ddraw_find_decl(struct ddraw
*This
, DWORD fvf
)
4615 struct wined3d_vertex_declaration
*pDecl
= NULL
;
4617 int p
, low
, high
; /* deliberately signed */
4618 struct FvfToDecl
*convertedDecls
= This
->decls
;
4620 TRACE("Searching for declaration for fvf %08x... ", fvf
);
4623 high
= This
->numConvertedDecls
- 1;
4624 while(low
<= high
) {
4625 p
= (low
+ high
) >> 1;
4627 if(convertedDecls
[p
].fvf
== fvf
) {
4628 TRACE("found %p\n", convertedDecls
[p
].decl
);
4629 return convertedDecls
[p
].decl
;
4630 } else if(convertedDecls
[p
].fvf
< fvf
) {
4636 TRACE("not found. Creating and inserting at position %d.\n", low
);
4638 hr
= wined3d_vertex_declaration_create_from_fvf(This
->wined3d_device
,
4639 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
4640 if (hr
!= S_OK
) return NULL
;
4642 if(This
->declArraySize
== This
->numConvertedDecls
) {
4643 int grow
= max(This
->declArraySize
/ 2, 8);
4644 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
4645 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
4646 if (!convertedDecls
)
4648 wined3d_vertex_declaration_decref(pDecl
);
4651 This
->decls
= convertedDecls
;
4652 This
->declArraySize
+= grow
;
4655 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
4656 convertedDecls
[low
].decl
= pDecl
;
4657 convertedDecls
[low
].fvf
= fvf
;
4658 This
->numConvertedDecls
++;
4660 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
4664 static inline struct ddraw
*ddraw_from_device_parent(struct wined3d_device_parent
*device_parent
)
4666 return CONTAINING_RECORD(device_parent
, struct ddraw
, device_parent
);
4669 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
4670 struct wined3d_device
*device
)
4672 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
4675 /* This is run from device_process_message() in wined3d, we can't take the
4677 /* FIXME: We only get mode change notifications in exclusive mode, but we
4678 * should mark surfaces as lost on mode changes in DDSCL_NORMAL mode as well. */
4679 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
4681 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4682 MONITORINFO monitor_info
;
4686 TRACE("device_parent %p.\n", device_parent
);
4688 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) || !ddraw
->swapchain_window
)
4690 TRACE("Nothing to resize.\n");
4694 monitor
= MonitorFromWindow(ddraw
->swapchain_window
, MONITOR_DEFAULTTOPRIMARY
);
4695 monitor_info
.cbSize
= sizeof(monitor_info
);
4696 if (!GetMonitorInfoW(monitor
, &monitor_info
))
4698 ERR("Failed to get monitor info.\n");
4702 r
= &monitor_info
.rcMonitor
;
4703 TRACE("Resizing window %p to %s.\n", ddraw
->swapchain_window
, wine_dbgstr_rect(r
));
4705 if (!SetWindowPos(ddraw
->swapchain_window
, HWND_TOP
, r
->left
, r
->top
,
4706 r
->right
- r
->left
, r
->bottom
- r
->top
, SWP_SHOWWINDOW
| SWP_NOACTIVATE
))
4707 ERR("Failed to resize window.\n");
4709 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_OK
);
4712 static void CDECL
device_parent_activate(struct wined3d_device_parent
*device_parent
, BOOL activate
)
4714 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4716 TRACE("device_parent %p, activate %#x.\n", device_parent
, activate
);
4720 ddraw
->device_state
= DDRAW_DEVICE_STATE_LOST
;
4721 exclusive_window
= NULL
;
4725 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_LOST
);
4729 void ddraw_update_lost_surfaces(struct ddraw
*ddraw
)
4731 struct ddraw_surface
*surface
;
4733 if (ddraw
->device_state
!= DDRAW_DEVICE_STATE_NOT_RESTORED
)
4736 LIST_FOR_EACH_ENTRY(surface
, &ddraw
->surface_list
, struct ddraw_surface
, surface_list_entry
)
4738 surface
->is_lost
= TRUE
;
4740 ddraw
->device_state
= DDRAW_DEVICE_STATE_OK
;
4743 static HRESULT CDECL
device_parent_surface_created(struct wined3d_device_parent
*device_parent
,
4744 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
, struct wined3d_surface
*surface
,
4745 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
4747 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4748 struct ddraw_surface
*ddraw_surface
;
4750 TRACE("device_parent %p, wined3d_texture %p, sub_resource_idx %u, surface %p, parent %p, parent_ops %p.\n",
4751 device_parent
, wined3d_texture
, sub_resource_idx
, surface
, parent
, parent_ops
);
4753 /* We have a swapchain or wined3d internal texture. */
4754 if (!wined3d_texture_get_parent(wined3d_texture
) || wined3d_texture_get_parent(wined3d_texture
) == ddraw
)
4757 *parent_ops
= &ddraw_null_wined3d_parent_ops
;
4762 if (!(ddraw_surface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ddraw_surface
))))
4764 ERR("Failed to allocate surface memory.\n");
4765 return DDERR_OUTOFVIDEOMEMORY
;
4768 ddraw_surface_init(ddraw_surface
, ddraw
, wined3d_texture_get_parent(wined3d_texture
), surface
, parent_ops
);
4769 *parent
= ddraw_surface
;
4771 ddraw_update_lost_surfaces(ddraw
);
4772 list_add_head(&ddraw
->surface_list
, &ddraw_surface
->surface_list_entry
);
4774 TRACE("Created ddraw surface %p.\n", ddraw_surface
);
4779 static HRESULT CDECL
device_parent_volume_created(struct wined3d_device_parent
*device_parent
,
4780 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
4781 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
4783 TRACE("device_parent %p, texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
4784 device_parent
, wined3d_texture
, sub_resource_idx
, parent
, parent_ops
);
4787 *parent_ops
= &ddraw_null_wined3d_parent_ops
;
4792 static void STDMETHODCALLTYPE
ddraw_frontbuffer_destroyed(void *parent
)
4794 struct ddraw
*ddraw
= parent
;
4795 ddraw
->wined3d_frontbuffer
= NULL
;
4798 static const struct wined3d_parent_ops ddraw_frontbuffer_parent_ops
=
4800 ddraw_frontbuffer_destroyed
,
4803 static HRESULT CDECL
device_parent_create_swapchain_texture(struct wined3d_device_parent
*device_parent
,
4804 void *container_parent
, const struct wined3d_resource_desc
*desc
, struct wined3d_texture
**texture
)
4806 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4809 TRACE("device_parent %p, container_parent %p, desc %p, texture %p.\n",
4810 device_parent
, container_parent
, desc
, texture
);
4812 if (ddraw
->wined3d_frontbuffer
)
4814 ERR("Frontbuffer already created.\n");
4818 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, desc
, 1,
4819 WINED3D_SURFACE_MAPPABLE
, NULL
, ddraw
, &ddraw_frontbuffer_parent_ops
, texture
)))
4821 WARN("Failed to create texture, hr %#x.\n", hr
);
4825 ddraw
->wined3d_frontbuffer
= wined3d_surface_from_resource(wined3d_texture_get_sub_resource(*texture
, 0));
4830 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
4831 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
4833 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4836 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent
, desc
, swapchain
);
4838 if (ddraw
->wined3d_swapchain
)
4840 ERR("Swapchain already created.\n");
4844 if (FAILED(hr
= wined3d_swapchain_create(ddraw
->wined3d_device
, desc
, NULL
,
4845 &ddraw_null_wined3d_parent_ops
, swapchain
)))
4846 WARN("Failed to create swapchain, hr %#x.\n", hr
);
4851 static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops
=
4853 device_parent_wined3d_device_created
,
4854 device_parent_mode_changed
,
4855 device_parent_activate
,
4856 device_parent_surface_created
,
4857 device_parent_volume_created
,
4858 device_parent_create_swapchain_texture
,
4859 device_parent_create_swapchain
,
4862 HRESULT
ddraw_init(struct ddraw
*ddraw
, DWORD flags
, enum wined3d_device_type device_type
)
4867 ddraw
->IDirectDraw7_iface
.lpVtbl
= &ddraw7_vtbl
;
4868 ddraw
->IDirectDraw_iface
.lpVtbl
= &ddraw1_vtbl
;
4869 ddraw
->IDirectDraw2_iface
.lpVtbl
= &ddraw2_vtbl
;
4870 ddraw
->IDirectDraw4_iface
.lpVtbl
= &ddraw4_vtbl
;
4871 ddraw
->IDirect3D_iface
.lpVtbl
= &d3d1_vtbl
;
4872 ddraw
->IDirect3D2_iface
.lpVtbl
= &d3d2_vtbl
;
4873 ddraw
->IDirect3D3_iface
.lpVtbl
= &d3d3_vtbl
;
4874 ddraw
->IDirect3D7_iface
.lpVtbl
= &d3d7_vtbl
;
4875 ddraw
->device_parent
.ops
= &ddraw_wined3d_device_parent_ops
;
4876 ddraw
->numIfaces
= 1;
4879 flags
|= DDRAW_WINED3D_FLAGS
;
4880 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
4882 flags
|= WINED3D_NO3D
;
4883 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
4885 WARN("Failed to create a wined3d object.\n");
4890 if (FAILED(hr
= wined3d_get_device_caps(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
, &caps
)))
4892 ERR("Failed to get device caps, hr %#x.\n", hr
);
4893 wined3d_decref(ddraw
->wined3d
);
4897 if (!(caps
.ddraw_caps
.caps
& WINEDDCAPS_3D
))
4899 WARN("Created a wined3d object without 3D support.\n");
4900 ddraw
->flags
|= DDRAW_NO3D
;
4903 if (FAILED(hr
= wined3d_device_create(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
,
4904 NULL
, 0, DDRAW_STRIDE_ALIGNMENT
, &ddraw
->device_parent
, &ddraw
->wined3d_device
)))
4906 WARN("Failed to create a wined3d device, hr %#x.\n", hr
);
4907 wined3d_decref(ddraw
->wined3d
);
4911 list_init(&ddraw
->surface_list
);