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
,
2625 HDC dc
, IDirectDrawSurface7
**surface
)
2627 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2628 struct ddraw_surface
*surface_impl
;
2630 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2633 return E_INVALIDARG
;
2638 wined3d_mutex_lock();
2639 LIST_FOR_EACH_ENTRY(surface_impl
, &ddraw
->surface_list
, struct ddraw_surface
, surface_list_entry
)
2641 if (surface_impl
->dc
!= dc
)
2644 TRACE("Found surface %p for dc %p.\n", surface_impl
, dc
);
2645 *surface
= &surface_impl
->IDirectDrawSurface7_iface
;
2646 IDirectDrawSurface7_AddRef(*surface
);
2647 wined3d_mutex_unlock();
2650 wined3d_mutex_unlock();
2653 TRACE("No surface found for dc %p.\n", dc
);
2655 return DDERR_NOTFOUND
;
2658 static HRESULT WINAPI
ddraw4_GetSurfaceFromDC(IDirectDraw4
*iface
, HDC dc
,
2659 IDirectDrawSurface4
**surface
)
2661 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2662 struct ddraw_surface
*surface_impl
;
2663 IDirectDrawSurface7
*surface7
;
2666 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2668 if (!surface
) return E_INVALIDARG
;
2670 hr
= ddraw7_GetSurfaceFromDC(&ddraw
->IDirectDraw7_iface
, dc
, &surface7
);
2676 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2677 /* Tests say this is true */
2678 *surface
= (IDirectDrawSurface4
*)&surface_impl
->IDirectDrawSurface_iface
;
2679 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2680 IDirectDrawSurface7_Release(surface7
);
2685 static HRESULT CALLBACK
restore_callback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
2687 IDirectDrawSurface_Restore(surface
);
2688 IDirectDrawSurface_Release(surface
);
2690 return DDENUMRET_OK
;
2693 static HRESULT WINAPI
ddraw7_RestoreAllSurfaces(IDirectDraw7
*iface
)
2695 TRACE("iface %p.\n", iface
);
2697 return IDirectDraw7_EnumSurfaces(iface
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
2698 NULL
, NULL
, restore_callback
);
2701 static HRESULT WINAPI
ddraw4_RestoreAllSurfaces(IDirectDraw4
*iface
)
2703 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2705 TRACE("iface %p.\n", iface
);
2707 return ddraw7_RestoreAllSurfaces(&ddraw
->IDirectDraw7_iface
);
2710 /*****************************************************************************
2711 * IDirectDraw7::StartModeTest
2713 * Tests the specified video modes to update the system registry with
2714 * refresh rate information. StartModeTest starts the mode test,
2715 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
2716 * isn't called within 15 seconds, the mode is failed automatically
2718 * As refresh rates are handled by the X server, I don't think this
2719 * Method is important
2722 * Modes: An array of mode specifications
2723 * NumModes: The number of modes in Modes
2724 * Flags: Some flags...
2727 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
2728 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
2731 *****************************************************************************/
2732 static HRESULT WINAPI
ddraw7_StartModeTest(IDirectDraw7
*iface
, SIZE
*Modes
, DWORD NumModes
, DWORD Flags
)
2734 FIXME("iface %p, modes %p, mode_count %u, flags %#x partial stub!\n",
2735 iface
, Modes
, NumModes
, Flags
);
2737 /* This looks sane */
2738 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
2740 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
2741 * As it is not, DDERR_TESTFINISHED is returned
2742 * (hopefully that's correct
2744 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
2745 * well, that value doesn't (yet) exist in the wine headers, so ignore it
2751 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
, DDSURFACEDESC2
*surface_desc
,
2752 IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
2754 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2755 struct ddraw_surface
*impl
;
2758 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2759 iface
, surface_desc
, surface
, outer_unknown
);
2761 wined3d_mutex_lock();
2763 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2765 WARN("Cooperative level not set.\n");
2766 wined3d_mutex_unlock();
2767 return DDERR_NOCOOPERATIVELEVELSET
;
2770 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2772 WARN("Application supplied invalid surface descriptor\n");
2773 wined3d_mutex_unlock();
2774 return DDERR_INVALIDPARAMS
;
2777 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2779 if (TRACE_ON(ddraw
))
2781 TRACE(" (%p) Requesting surface desc :\n", iface
);
2782 DDRAW_dump_surface_desc(surface_desc
);
2785 WARN("Application tried to create an explicit front or back buffer\n");
2786 wined3d_mutex_unlock();
2787 return DDERR_INVALIDCAPS
;
2790 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 7);
2791 wined3d_mutex_unlock();
2798 *surface
= &impl
->IDirectDrawSurface7_iface
;
2799 IDirectDraw7_AddRef(iface
);
2800 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2805 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
2806 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
2808 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2809 struct ddraw_surface
*impl
;
2812 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2813 iface
, surface_desc
, surface
, outer_unknown
);
2815 wined3d_mutex_lock();
2817 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2819 WARN("Cooperative level not set.\n");
2820 wined3d_mutex_unlock();
2821 return DDERR_NOCOOPERATIVELEVELSET
;
2824 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2826 WARN("Application supplied invalid surface descriptor\n");
2827 wined3d_mutex_unlock();
2828 return DDERR_INVALIDPARAMS
;
2831 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2833 if (TRACE_ON(ddraw
))
2835 TRACE(" (%p) Requesting surface desc :\n", iface
);
2836 DDRAW_dump_surface_desc(surface_desc
);
2839 WARN("Application tried to create an explicit front or back buffer\n");
2840 wined3d_mutex_unlock();
2841 return DDERR_INVALIDCAPS
;
2844 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 4);
2845 wined3d_mutex_unlock();
2852 *surface
= &impl
->IDirectDrawSurface4_iface
;
2853 IDirectDraw4_AddRef(iface
);
2854 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2859 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
2860 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2862 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2863 struct ddraw_surface
*impl
;
2865 DDSURFACEDESC2 surface_desc2
;
2867 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2868 iface
, surface_desc
, surface
, outer_unknown
);
2870 wined3d_mutex_lock();
2872 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2874 WARN("Cooperative level not set.\n");
2875 wined3d_mutex_unlock();
2876 return DDERR_NOCOOPERATIVELEVELSET
;
2879 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2881 WARN("Application supplied invalid surface descriptor\n");
2882 wined3d_mutex_unlock();
2883 return DDERR_INVALIDPARAMS
;
2886 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2887 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2889 if (TRACE_ON(ddraw
))
2891 TRACE(" (%p) Requesting surface desc :\n", iface
);
2892 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
2895 WARN("Application tried to create an explicit front or back buffer\n");
2896 wined3d_mutex_unlock();
2897 return DDERR_INVALIDCAPS
;
2900 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 2);
2901 wined3d_mutex_unlock();
2908 *surface
= &impl
->IDirectDrawSurface_iface
;
2909 impl
->ifaceToRelease
= NULL
;
2914 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
2915 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2917 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2918 struct ddraw_surface
*impl
;
2920 DDSURFACEDESC2 surface_desc2
;
2922 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2923 iface
, surface_desc
, surface
, outer_unknown
);
2925 wined3d_mutex_lock();
2927 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2929 WARN("Cooperative level not set.\n");
2930 wined3d_mutex_unlock();
2931 return DDERR_NOCOOPERATIVELEVELSET
;
2934 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2936 WARN("Application supplied invalid surface descriptor\n");
2937 wined3d_mutex_unlock();
2938 return DDERR_INVALIDPARAMS
;
2941 if ((surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
))
2942 == (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
)
2943 || (surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
))
2944 == ((DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
)))
2946 WARN("Application tried to create an explicit front or back buffer.\n");
2947 wined3d_mutex_unlock();
2948 return DDERR_INVALIDCAPS
;
2951 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2952 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 1);
2953 wined3d_mutex_unlock();
2960 *surface
= &impl
->IDirectDrawSurface_iface
;
2961 impl
->ifaceToRelease
= NULL
;
2966 #define DDENUMSURFACES_SEARCHTYPE (DDENUMSURFACES_CANBECREATED|DDENUMSURFACES_DOESEXIST)
2967 #define DDENUMSURFACES_MATCHTYPE (DDENUMSURFACES_ALL|DDENUMSURFACES_MATCH|DDENUMSURFACES_NOMATCH)
2970 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
2971 const DDPIXELFORMAT
*provided
)
2973 /* Some flags must be present in both or neither for a match. */
2974 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
2975 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
2976 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
2978 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
2981 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
2984 if (requested
->dwFlags
& DDPF_FOURCC
)
2985 if (requested
->dwFourCC
!= provided
->dwFourCC
)
2988 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
2989 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
2990 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
2993 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
2994 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
2995 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
2998 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
2999 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
3002 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
3003 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3005 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
3008 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
3009 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
3015 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3024 #define CMP(FLAG, FIELD) \
3025 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3026 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3028 static const struct compare_info compare
[] =
3030 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3031 CMP(BACKBUFFERCOUNT
, u5
.dwBackBufferCount
),
3033 CMP(CKDESTBLT
, ddckCKDestBlt
),
3034 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3035 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3036 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3037 CMP(HEIGHT
, dwHeight
),
3038 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3039 CMP(LPSURFACE
, lpSurface
),
3040 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3041 CMP(PITCH
, u1
/* lPitch */),
3042 /* PIXELFORMAT: manual */
3043 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3044 CMP(TEXTURESTAGE
, dwTextureStage
),
3045 CMP(WIDTH
, dwWidth
),
3046 /* ZBUFFERBITDEPTH: "obsolete" */
3053 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3056 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
3058 if (requested
->dwFlags
& compare
[i
].flag
3059 && memcmp((const char *)provided
+ compare
[i
].offset
,
3060 (const char *)requested
+ compare
[i
].offset
,
3061 compare
[i
].size
) != 0)
3065 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3067 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3068 &provided
->u4
.ddpfPixelFormat
))
3075 #undef DDENUMSURFACES_SEARCHTYPE
3076 #undef DDENUMSURFACES_MATCHTYPE
3078 struct surfacescallback2_context
3080 LPDDENUMSURFACESCALLBACK2 func
;
3084 struct surfacescallback_context
3086 LPDDENUMSURFACESCALLBACK func
;
3090 static HRESULT CALLBACK
EnumSurfacesCallback2Thunk(IDirectDrawSurface7
*surface
,
3091 DDSURFACEDESC2
*surface_desc
, void *context
)
3093 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3094 struct surfacescallback2_context
*cbcontext
= context
;
3096 IDirectDrawSurface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
3097 IDirectDrawSurface7_Release(surface
);
3099 return cbcontext
->func(&surface_impl
->IDirectDrawSurface4_iface
,
3100 surface_desc
, cbcontext
->context
);
3103 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3104 DDSURFACEDESC2
*surface_desc
, void *context
)
3106 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3107 struct surfacescallback_context
*cbcontext
= context
;
3109 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
3110 IDirectDrawSurface7_Release(surface
);
3112 return cbcontext
->func(&surface_impl
->IDirectDrawSurface_iface
,
3113 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3116 /*****************************************************************************
3117 * IDirectDraw7::EnumSurfaces
3119 * Loops through all surfaces attached to this device and calls the
3120 * application callback. This can't be relayed to WineD3DDevice,
3121 * because some WineD3DSurfaces' parents are IParent objects
3124 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3125 * DDSD: Description to filter for
3126 * Context: Application-provided pointer, it's passed unmodified to the
3128 * Callback: Address to call for each surface
3131 * DDERR_INVALIDPARAMS if the callback is NULL
3134 *****************************************************************************/
3135 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD Flags
,
3136 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMSURFACESCALLBACK7 Callback
)
3138 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3139 struct ddraw_surface
*surf
;
3141 DDSURFACEDESC2 desc
;
3142 struct list
*entry
, *entry2
;
3144 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3145 iface
, Flags
, DDSD
, Context
, Callback
);
3147 all
= Flags
& DDENUMSURFACES_ALL
;
3148 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
3151 return DDERR_INVALIDPARAMS
;
3153 wined3d_mutex_lock();
3155 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
3156 LIST_FOR_EACH_SAFE(entry
, entry2
, &ddraw
->surface_list
)
3158 surf
= LIST_ENTRY(entry
, struct ddraw_surface
, surface_list_entry
);
3160 if (!surf
->iface_count
)
3162 WARN("Not enumerating surface %p because it doesn't have any references.\n", surf
);
3166 if (all
|| (nomatch
!= ddraw_match_surface_desc(DDSD
, &surf
->surface_desc
)))
3168 TRACE("Enumerating surface %p.\n", surf
);
3169 desc
= surf
->surface_desc
;
3170 IDirectDrawSurface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
3171 if (Callback(&surf
->IDirectDrawSurface7_iface
, &desc
, Context
) != DDENUMRET_OK
)
3173 wined3d_mutex_unlock();
3179 wined3d_mutex_unlock();
3184 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3185 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3187 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3188 struct surfacescallback2_context cbcontext
;
3190 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3191 iface
, flags
, surface_desc
, context
, callback
);
3193 cbcontext
.func
= callback
;
3194 cbcontext
.context
= context
;
3196 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
,
3197 &cbcontext
, EnumSurfacesCallback2Thunk
);
3200 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3201 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3203 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3204 struct surfacescallback_context cbcontext
;
3205 DDSURFACEDESC2 surface_desc2
;
3207 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3208 iface
, flags
, surface_desc
, context
, callback
);
3210 cbcontext
.func
= callback
;
3211 cbcontext
.context
= context
;
3213 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3214 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3215 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3218 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3219 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3221 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3222 struct surfacescallback_context cbcontext
;
3223 DDSURFACEDESC2 surface_desc2
;
3225 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3226 iface
, flags
, surface_desc
, context
, callback
);
3228 cbcontext
.func
= callback
;
3229 cbcontext
.context
= context
;
3231 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3232 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3233 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3236 /*****************************************************************************
3237 * DirectDrawCreateClipper (DDRAW.@)
3239 * Creates a new IDirectDrawClipper object.
3242 * Clipper: Address to write the interface pointer to
3243 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3247 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3248 * E_OUTOFMEMORY if allocating the object failed
3250 *****************************************************************************/
3251 HRESULT WINAPI
DirectDrawCreateClipper(DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3253 struct ddraw_clipper
*object
;
3256 TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
3257 flags
, clipper
, outer_unknown
);
3260 return CLASS_E_NOAGGREGATION
;
3262 wined3d_mutex_lock();
3264 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3267 wined3d_mutex_unlock();
3268 return E_OUTOFMEMORY
;
3271 hr
= ddraw_clipper_init(object
);
3274 WARN("Failed to initialize clipper, hr %#x.\n", hr
);
3275 HeapFree(GetProcessHeap(), 0, object
);
3276 wined3d_mutex_unlock();
3280 TRACE("Created clipper %p.\n", object
);
3281 *clipper
= &object
->IDirectDrawClipper_iface
;
3282 wined3d_mutex_unlock();
3287 /*****************************************************************************
3288 * IDirectDraw7::CreateClipper
3290 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3292 *****************************************************************************/
3293 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3294 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3296 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3297 iface
, Flags
, Clipper
, UnkOuter
);
3299 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3302 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
, DWORD flags
,
3303 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3305 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3307 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3308 iface
, flags
, clipper
, outer_unknown
);
3310 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3313 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
3314 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3316 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3318 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3319 iface
, flags
, clipper
, outer_unknown
);
3321 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3324 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
3325 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3327 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3329 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3330 iface
, flags
, clipper
, outer_unknown
);
3332 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3335 /*****************************************************************************
3336 * IDirectDraw7::CreatePalette
3338 * Creates a new IDirectDrawPalette object
3341 * Flags: The flags for the new clipper
3342 * ColorTable: Color table to assign to the new clipper
3343 * Palette: Address to write the interface pointer to
3344 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3348 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3349 * E_OUTOFMEMORY if allocating the object failed
3351 *****************************************************************************/
3352 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
3353 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
3355 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3356 struct ddraw_palette
*object
;
3359 TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
3360 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3363 return CLASS_E_NOAGGREGATION
;
3365 wined3d_mutex_lock();
3367 /* The refcount test shows that a cooplevel is required for this */
3368 if (!ddraw
->cooperative_level
)
3370 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3371 wined3d_mutex_unlock();
3372 return DDERR_NOCOOPERATIVELEVELSET
;
3375 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(*object
));
3378 ERR("Out of memory when allocating memory for a palette implementation\n");
3379 wined3d_mutex_unlock();
3380 return E_OUTOFMEMORY
;
3383 hr
= ddraw_palette_init(object
, ddraw
, Flags
, ColorTable
);
3386 WARN("Failed to initialize palette, hr %#x.\n", hr
);
3387 HeapFree(GetProcessHeap(), 0, object
);
3388 wined3d_mutex_unlock();
3392 TRACE("Created palette %p.\n", object
);
3393 *Palette
= &object
->IDirectDrawPalette_iface
;
3394 wined3d_mutex_unlock();
3399 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
, PALETTEENTRY
*entries
,
3400 IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3402 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3405 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3406 iface
, flags
, entries
, palette
, outer_unknown
);
3408 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3409 if (SUCCEEDED(hr
) && *palette
)
3411 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3412 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3413 IDirectDraw4_AddRef(iface
);
3414 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3419 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
3420 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3422 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3425 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3426 iface
, flags
, entries
, palette
, outer_unknown
);
3428 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3429 if (SUCCEEDED(hr
) && *palette
)
3431 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3432 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3433 impl
->ifaceToRelease
= NULL
;
3439 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
3440 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3442 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3445 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3446 iface
, flags
, entries
, palette
, outer_unknown
);
3448 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3449 if (SUCCEEDED(hr
) && *palette
)
3451 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3452 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3453 impl
->ifaceToRelease
= NULL
;
3459 /*****************************************************************************
3460 * IDirectDraw7::DuplicateSurface
3462 * Duplicates a surface. The surface memory points to the same memory as
3463 * the original surface, and it's released when the last surface referencing
3464 * it is released. I guess that's beyond Wine's surface management right now
3465 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3466 * test application to implement this)
3469 * Src: Address of the source surface
3470 * Dest: Address to write the new surface pointer to
3473 * See IDirectDraw7::CreateSurface
3475 *****************************************************************************/
3476 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
3477 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
3479 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(Src
);
3481 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
3483 /* For now, simply create a new, independent surface */
3484 return IDirectDraw7_CreateSurface(iface
, &src_surface
->surface_desc
, Dest
, NULL
);
3487 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
, IDirectDrawSurface4
*src
,
3488 IDirectDrawSurface4
**dst
)
3490 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
3491 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3492 struct ddraw_surface
*dst_impl
;
3493 IDirectDrawSurface7
*dst7
;
3496 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3498 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3499 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3505 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3506 *dst
= &dst_impl
->IDirectDrawSurface4_iface
;
3507 IDirectDrawSurface4_AddRef(*dst
);
3508 IDirectDrawSurface7_Release(dst7
);
3513 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
3514 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
3516 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3517 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3518 struct ddraw_surface
*dst_impl
;
3519 IDirectDrawSurface7
*dst7
;
3522 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3524 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3525 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3528 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3529 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3530 IDirectDrawSurface_AddRef(*dst
);
3531 IDirectDrawSurface7_Release(dst7
);
3536 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
, IDirectDrawSurface
*src
,
3537 IDirectDrawSurface
**dst
)
3539 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3540 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3541 struct ddraw_surface
*dst_impl
;
3542 IDirectDrawSurface7
*dst7
;
3545 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3547 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3548 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3551 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3552 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3553 IDirectDrawSurface_AddRef(*dst
);
3554 IDirectDrawSurface7_Release(dst7
);
3559 /*****************************************************************************
3560 * IDirect3D7::EnumDevices
3562 * The EnumDevices method for IDirect3D7. It enumerates all supported
3563 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
3566 * callback: Function to call for each enumerated device
3567 * context: Pointer to pass back to the app
3570 * D3D_OK, or the return value of the GetCaps call
3572 *****************************************************************************/
3573 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
3575 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
3576 D3DDEVICEDESC7 device_desc7
;
3580 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3583 return DDERR_INVALIDPARAMS
;
3585 wined3d_mutex_lock();
3587 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3589 wined3d_mutex_unlock();
3593 for (i
= 0; i
< sizeof(device_list7
)/sizeof(device_list7
[0]); i
++)
3597 device_desc7
.deviceGUID
= *device_list7
[i
].device_guid
;
3598 ret
= callback(device_list7
[i
].interface_name
, device_list7
[i
].device_name
, &device_desc7
, context
);
3599 if (ret
!= DDENUMRET_OK
)
3601 TRACE("Application cancelled the enumeration.\n");
3602 wined3d_mutex_unlock();
3607 TRACE("End of enumeration.\n");
3609 wined3d_mutex_unlock();
3614 /*****************************************************************************
3615 * IDirect3D3::EnumDevices
3617 * Enumerates all supported Direct3DDevice interfaces. This is the
3618 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
3620 * Version 1, 2 and 3
3623 * callback: Application-provided routine to call for each enumerated device
3624 * Context: Pointer to pass to the callback
3627 * D3D_OK on success,
3628 * The result of IDirect3DImpl_GetCaps if it failed
3630 *****************************************************************************/
3631 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3633 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
3635 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3636 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
3637 D3DDEVICEDESC7 device_desc7
;
3640 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
3641 * name string. Let's put the string in a sufficiently sized array in
3642 * writable memory. */
3643 char device_name
[50];
3644 strcpy(device_name
,"Direct3D HEL");
3646 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3649 return DDERR_INVALIDPARAMS
;
3651 wined3d_mutex_lock();
3653 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3655 wined3d_mutex_unlock();
3658 ddraw_d3dcaps1_from_7(&device_desc1
, &device_desc7
);
3660 /* Do I have to enumerate the reference id? Note from old d3d7:
3661 * "It seems that enumerating the reference IID on Direct3D 1 games
3662 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
3664 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
3665 * EnumReference which enables / disables enumerating the reference
3666 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
3667 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
3668 * demo directory suggest this.
3670 * Some games(GTA 2) seem to use the second enumerated device, so I have
3671 * to enumerate at least 2 devices. So enumerate the reference device to
3674 * Other games (Rollcage) tell emulation and hal device apart by certain
3675 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
3676 * limitation flag), and it refuses all devices that have the perspective
3677 * flag set. This way it refuses the emulation device, and HAL devices
3678 * never have POW2 unset in d3d7 on windows. */
3679 if (ddraw
->d3dversion
!= 1)
3681 static CHAR reference_description
[] = "RGB Direct3D emulation";
3683 TRACE("Enumerating WineD3D D3DDevice interface.\n");
3684 hal_desc
= device_desc1
;
3685 hel_desc
= device_desc1
;
3686 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
3687 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3688 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3689 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3690 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3691 /* RGB, RAMP and MMX devices have a HAL dcmColorModel of 0 */
3692 hal_desc
.dcmColorModel
= 0;
3693 /* RGB, RAMP and MMX devices cannot report HAL hardware flags */
3694 hal_desc
.dwFlags
= 0;
3696 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
3697 device_name
, &hal_desc
, &hel_desc
, context
);
3698 if (hr
!= D3DENUMRET_OK
)
3700 TRACE("Application cancelled the enumeration.\n");
3701 wined3d_mutex_unlock();
3706 strcpy(device_name
,"Direct3D HAL");
3708 TRACE("Enumerating HAL Direct3D device.\n");
3709 hal_desc
= device_desc1
;
3710 hel_desc
= device_desc1
;
3712 /* The hal device does not have the pow2 flag set in hel, but in hal. */
3713 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3714 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3715 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3716 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3717 /* HAL devices have a HEL dcmColorModel of 0 */
3718 hel_desc
.dcmColorModel
= 0;
3720 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
3721 device_name
, &hal_desc
, &hel_desc
, context
);
3722 if (hr
!= D3DENUMRET_OK
)
3724 TRACE("Application cancelled the enumeration.\n");
3725 wined3d_mutex_unlock();
3729 TRACE("End of enumeration.\n");
3731 wined3d_mutex_unlock();
3736 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3738 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3740 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3742 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3745 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3747 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3749 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3751 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3754 /*****************************************************************************
3755 * IDirect3D3::CreateLight
3757 * Creates an IDirect3DLight interface. This interface is used in
3758 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
3759 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
3760 * uses the IDirect3DDevice7 interface with D3D7 lights.
3762 * Version 1, 2 and 3
3765 * light: Address to store the new interface pointer
3766 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3771 * DDERR_OUTOFMEMORY if memory allocation failed
3772 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3774 *****************************************************************************/
3775 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
,
3776 IUnknown
*outer_unknown
)
3778 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3779 struct d3d_light
*object
;
3781 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3783 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3785 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3788 ERR("Failed to allocate light memory.\n");
3789 return DDERR_OUTOFMEMORY
;
3792 d3d_light_init(object
, ddraw
);
3794 TRACE("Created light %p.\n", object
);
3795 *light
= &object
->IDirect3DLight_iface
;
3800 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3802 struct ddraw
*ddraw
= impl_from_IDirect3D2(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 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3811 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3813 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3815 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3818 /*****************************************************************************
3819 * IDirect3D3::CreateMaterial
3821 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
3822 * and older versions. The IDirect3DMaterial implementation wraps its
3823 * functionality to IDirect3DDevice7::SetMaterial and friends.
3825 * Version 1, 2 and 3
3828 * material: Address to store the new interface's pointer to
3829 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3834 * DDERR_OUTOFMEMORY if memory allocation failed
3835 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3837 *****************************************************************************/
3838 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
,
3839 IUnknown
*outer_unknown
)
3841 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3842 struct d3d_material
*object
;
3844 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3846 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3848 object
= d3d_material_create(ddraw
);
3851 ERR("Failed to allocate material memory.\n");
3852 return DDERR_OUTOFMEMORY
;
3855 TRACE("Created material %p.\n", object
);
3856 *material
= &object
->IDirect3DMaterial3_iface
;
3861 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
,
3862 IUnknown
*outer_unknown
)
3864 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3865 struct d3d_material
*object
;
3867 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3869 object
= d3d_material_create(ddraw
);
3872 ERR("Failed to allocate material memory.\n");
3873 return DDERR_OUTOFMEMORY
;
3876 TRACE("Created material %p.\n", object
);
3877 *material
= &object
->IDirect3DMaterial2_iface
;
3882 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
,
3883 IUnknown
*outer_unknown
)
3885 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3886 struct d3d_material
*object
;
3888 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3890 object
= d3d_material_create(ddraw
);
3893 ERR("Failed to allocate material memory.\n");
3894 return DDERR_OUTOFMEMORY
;
3897 TRACE("Created material %p.\n", object
);
3898 *material
= &object
->IDirect3DMaterial_iface
;
3903 /*****************************************************************************
3904 * IDirect3D3::CreateViewport
3906 * Creates an IDirect3DViewport interface. This interface is used
3907 * by Direct3D and earlier versions for Viewport management. In Direct3D7
3908 * it has been replaced by a viewport structure and
3909 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
3910 * uses the IDirect3DDevice7 methods for its functionality
3913 * Viewport: Address to store the new interface pointer
3914 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3919 * DDERR_OUTOFMEMORY if memory allocation failed
3920 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3922 *****************************************************************************/
3923 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
,
3924 IUnknown
*outer_unknown
)
3926 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3927 struct d3d_viewport
*object
;
3929 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
3931 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3933 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3936 ERR("Failed to allocate viewport memory.\n");
3937 return DDERR_OUTOFMEMORY
;
3940 d3d_viewport_init(object
, ddraw
);
3942 TRACE("Created viewport %p.\n", object
);
3943 *viewport
= &object
->IDirect3DViewport3_iface
;
3948 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
3950 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3952 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
3954 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
3958 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
3960 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3962 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
3964 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
3968 /*****************************************************************************
3969 * IDirect3D3::FindDevice
3971 * This method finds a device with the requested properties and returns a
3972 * device description
3976 * fds: Describes the requested device characteristics
3977 * fdr: Returns the device description
3981 * DDERR_INVALIDPARAMS if no device was found
3983 *****************************************************************************/
3984 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
3986 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3987 D3DDEVICEDESC7 desc7
;
3988 D3DDEVICEDESC desc1
;
3991 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
3993 if (!fds
|| !fdr
) return DDERR_INVALIDPARAMS
;
3995 if (fds
->dwSize
!= sizeof(D3DFINDDEVICESEARCH
)
3996 || fdr
->dwSize
!= sizeof(D3DFINDDEVICERESULT
))
3997 return DDERR_INVALIDPARAMS
;
3999 if ((fds
->dwFlags
& D3DFDS_COLORMODEL
)
4000 && fds
->dcmColorModel
!= D3DCOLOR_RGB
)
4002 WARN("Trying to request a non-RGB D3D color model. Not supported.\n");
4003 return DDERR_INVALIDPARAMS
; /* No real idea what to return here :-) */
4006 if (fds
->dwFlags
& D3DFDS_GUID
)
4008 TRACE("Trying to match guid %s.\n", debugstr_guid(&(fds
->guid
)));
4009 if (!IsEqualGUID(&IID_D3DDEVICE_WineD3D
, &fds
->guid
)
4010 && !IsEqualGUID(&IID_IDirect3DHALDevice
, &fds
->guid
)
4011 && !IsEqualGUID(&IID_IDirect3DRGBDevice
, &fds
->guid
))
4013 WARN("No match for this GUID.\n");
4014 return DDERR_NOTFOUND
;
4019 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &desc7
)))
4022 /* Now return our own GUID */
4023 ddraw_d3dcaps1_from_7(&desc1
, &desc7
);
4024 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4025 fdr
->ddHwDesc
= desc1
;
4026 fdr
->ddSwDesc
= desc1
;
4028 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4033 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4035 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4037 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4039 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4042 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4044 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4046 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4048 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4051 /*****************************************************************************
4052 * IDirect3D7::CreateDevice
4054 * Creates an IDirect3DDevice7 interface.
4056 * Version 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4057 * DirectDraw surfaces and are created with
4058 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4059 * create the device object and QueryInterfaces for IDirect3DDevice
4062 * refiid: IID of the device to create
4063 * Surface: Initial rendertarget
4064 * Device: Address to return the interface pointer
4068 * DDERR_OUTOFMEMORY if memory allocation failed
4069 * DDERR_INVALIDPARAMS if a device exists already
4071 *****************************************************************************/
4072 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4073 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4075 struct ddraw_surface
*target
= unsafe_impl_from_IDirectDrawSurface7(surface
);
4076 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4077 struct d3d_device
*object
;
4080 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4082 wined3d_mutex_lock();
4083 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, target
, (IUnknown
*)surface
, 7, &object
, NULL
)))
4085 *device
= &object
->IDirect3DDevice7_iface
;
4089 WARN("Failed to create device, hr %#x.\n", hr
);
4092 wined3d_mutex_unlock();
4097 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4098 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4100 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface4(surface
);
4101 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4102 struct d3d_device
*device_impl
;
4105 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4106 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4109 return CLASS_E_NOAGGREGATION
;
4111 wined3d_mutex_lock();
4112 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 3, &device_impl
, NULL
)))
4114 *device
= &device_impl
->IDirect3DDevice3_iface
;
4118 WARN("Failed to create device, hr %#x.\n", hr
);
4121 wined3d_mutex_unlock();
4126 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4127 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4129 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface(surface
);
4130 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4131 struct d3d_device
*device_impl
;
4134 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4135 iface
, debugstr_guid(riid
), surface
, device
);
4137 wined3d_mutex_lock();
4138 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 2, &device_impl
, NULL
)))
4140 *device
= &device_impl
->IDirect3DDevice2_iface
;
4144 WARN("Failed to create device, hr %#x.\n", hr
);
4147 wined3d_mutex_unlock();
4152 /*****************************************************************************
4153 * IDirect3D7::CreateVertexBuffer
4155 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4161 * desc: Requested Vertex buffer properties
4162 * vertex_buffer: Address to return the interface pointer at
4163 * flags: Some flags, should be 0
4167 * DDERR_OUTOFMEMORY if memory allocation failed
4168 * The return value of IWineD3DDevice::CreateVertexBuffer if this call fails
4169 * DDERR_INVALIDPARAMS if desc or vertex_buffer is NULL
4171 *****************************************************************************/
4172 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4173 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4175 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4176 struct d3d_vertex_buffer
*object
;
4179 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
4180 iface
, desc
, vertex_buffer
, flags
);
4182 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4184 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4187 TRACE("Created vertex buffer %p.\n", object
);
4188 *vertex_buffer
= &object
->IDirect3DVertexBuffer7_iface
;
4191 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4196 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4197 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4199 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4200 struct d3d_vertex_buffer
*object
;
4203 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n",
4204 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4207 return CLASS_E_NOAGGREGATION
;
4208 if (!vertex_buffer
|| !desc
)
4209 return DDERR_INVALIDPARAMS
;
4211 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4214 TRACE("Created vertex buffer %p.\n", object
);
4215 *vertex_buffer
= &object
->IDirect3DVertexBuffer_iface
;
4218 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4223 /*****************************************************************************
4224 * IDirect3D7::EnumZBufferFormats
4226 * Enumerates all supported Z buffer pixel formats
4232 * callback: callback to call for each pixel format
4233 * context: Pointer to pass back to the callback
4237 * DDERR_INVALIDPARAMS if callback is NULL
4238 * For details, see IWineD3DDevice::EnumZBufferFormats
4240 *****************************************************************************/
4241 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4242 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4244 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4245 struct wined3d_display_mode mode
;
4246 enum wined3d_device_type type
;
4250 /* Order matters. Specifically, BattleZone II (full version) expects the
4251 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4252 static const enum wined3d_format_id formats
[] =
4254 WINED3DFMT_S1_UINT_D15_UNORM
,
4255 WINED3DFMT_D16_UNORM
,
4256 WINED3DFMT_X8D24_UNORM
,
4257 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4258 WINED3DFMT_D24_UNORM_S8_UINT
,
4259 WINED3DFMT_D32_UNORM
,
4262 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4263 iface
, debugstr_guid(device_iid
), callback
, context
);
4265 if (!callback
) return DDERR_INVALIDPARAMS
;
4267 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4268 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4269 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4271 TRACE("Asked for HAL device.\n");
4272 type
= WINED3D_DEVICE_TYPE_HAL
;
4274 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4275 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4277 TRACE("Asked for SW device.\n");
4278 type
= WINED3D_DEVICE_TYPE_SW
;
4280 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4282 TRACE("Asked for REF device.\n");
4283 type
= WINED3D_DEVICE_TYPE_REF
;
4285 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4287 TRACE("Asked for NULLREF device.\n");
4288 type
= WINED3D_DEVICE_TYPE_NULLREF
;
4292 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4293 type
= WINED3D_DEVICE_TYPE_HAL
;
4296 wined3d_mutex_lock();
4297 /* We need an adapter format from somewhere to please wined3d and WGL.
4298 * Use the current display mode. So far all cards offer the same depth
4299 * stencil format for all modes, but if some do not and applications do
4300 * not like that we'll have to find some workaround, like iterating over
4301 * all imaginable formats and collecting all the depth stencil formats we
4303 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
4305 ERR("Failed to get display mode, hr %#x.\n", hr
);
4306 wined3d_mutex_unlock();
4310 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
4312 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4313 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_SURFACE
, formats
[i
])))
4315 DDPIXELFORMAT pformat
;
4317 memset(&pformat
, 0, sizeof(pformat
));
4318 pformat
.dwSize
= sizeof(pformat
);
4319 ddrawformat_from_wined3dformat(&pformat
, formats
[i
]);
4321 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
4322 hr
= callback(&pformat
, context
);
4323 if (hr
!= DDENUMRET_OK
)
4325 TRACE("Format enumeration cancelled by application.\n");
4326 wined3d_mutex_unlock();
4332 /* Historically some windows drivers used dwZBufferBitDepth=24 for WINED3DFMT_X8D24_UNORM,
4333 * while others used dwZBufferBitDepth=32. In either case the pitch matches a 32 bits per
4334 * pixel format, so we use dwZBufferBitDepth=32. Some games expect 24. Windows Vista and
4335 * newer enumerate both versions, so we do the same(bug 22434) */
4336 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4337 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_SURFACE
, WINED3DFMT_X8D24_UNORM
)))
4339 DDPIXELFORMAT x8d24
=
4341 sizeof(x8d24
), DDPF_ZBUFFER
, 0,
4342 {24}, {0x00000000}, {0x00ffffff}, {0x00000000}
4344 TRACE("Enumerating WINED3DFMT_X8D24_UNORM, dwZBufferBitDepth=24 version\n");
4345 callback(&x8d24
, context
);
4348 TRACE("End of enumeration.\n");
4350 wined3d_mutex_unlock();
4355 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
4356 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4358 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4360 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4361 iface
, debugstr_guid(device_iid
), callback
, context
);
4363 return d3d7_EnumZBufferFormats(&ddraw
->IDirect3D7_iface
, device_iid
, callback
, context
);
4366 /*****************************************************************************
4367 * IDirect3D7::EvictManagedTextures
4369 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
4370 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
4375 * D3D_OK, because it's a stub
4377 *****************************************************************************/
4378 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
4380 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4382 TRACE("iface %p!\n", iface
);
4384 wined3d_mutex_lock();
4385 if (ddraw
->flags
& DDRAW_D3D_INITIALIZED
)
4386 wined3d_device_evict_managed_resources(ddraw
->wined3d_device
);
4387 wined3d_mutex_unlock();
4392 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
4394 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4396 TRACE("iface %p.\n", iface
);
4398 return d3d7_EvictManagedTextures(&ddraw
->IDirect3D7_iface
);
4401 /*****************************************************************************
4402 * IDirectDraw7 VTable
4403 *****************************************************************************/
4404 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
4407 ddraw7_QueryInterface
,
4412 ddraw7_CreateClipper
,
4413 ddraw7_CreatePalette
,
4414 ddraw7_CreateSurface
,
4415 ddraw7_DuplicateSurface
,
4416 ddraw7_EnumDisplayModes
,
4417 ddraw7_EnumSurfaces
,
4418 ddraw7_FlipToGDISurface
,
4420 ddraw7_GetDisplayMode
,
4421 ddraw7_GetFourCCCodes
,
4422 ddraw7_GetGDISurface
,
4423 ddraw7_GetMonitorFrequency
,
4425 ddraw7_GetVerticalBlankStatus
,
4427 ddraw7_RestoreDisplayMode
,
4428 ddraw7_SetCooperativeLevel
,
4429 ddraw7_SetDisplayMode
,
4430 ddraw7_WaitForVerticalBlank
,
4432 ddraw7_GetAvailableVidMem
,
4434 ddraw7_GetSurfaceFromDC
,
4436 ddraw7_RestoreAllSurfaces
,
4437 ddraw7_TestCooperativeLevel
,
4438 ddraw7_GetDeviceIdentifier
,
4440 ddraw7_StartModeTest
,
4444 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
4447 ddraw4_QueryInterface
,
4452 ddraw4_CreateClipper
,
4453 ddraw4_CreatePalette
,
4454 ddraw4_CreateSurface
,
4455 ddraw4_DuplicateSurface
,
4456 ddraw4_EnumDisplayModes
,
4457 ddraw4_EnumSurfaces
,
4458 ddraw4_FlipToGDISurface
,
4460 ddraw4_GetDisplayMode
,
4461 ddraw4_GetFourCCCodes
,
4462 ddraw4_GetGDISurface
,
4463 ddraw4_GetMonitorFrequency
,
4465 ddraw4_GetVerticalBlankStatus
,
4467 ddraw4_RestoreDisplayMode
,
4468 ddraw4_SetCooperativeLevel
,
4469 ddraw4_SetDisplayMode
,
4470 ddraw4_WaitForVerticalBlank
,
4472 ddraw4_GetAvailableVidMem
,
4474 ddraw4_GetSurfaceFromDC
,
4476 ddraw4_RestoreAllSurfaces
,
4477 ddraw4_TestCooperativeLevel
,
4478 ddraw4_GetDeviceIdentifier
,
4481 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
4484 ddraw2_QueryInterface
,
4489 ddraw2_CreateClipper
,
4490 ddraw2_CreatePalette
,
4491 ddraw2_CreateSurface
,
4492 ddraw2_DuplicateSurface
,
4493 ddraw2_EnumDisplayModes
,
4494 ddraw2_EnumSurfaces
,
4495 ddraw2_FlipToGDISurface
,
4497 ddraw2_GetDisplayMode
,
4498 ddraw2_GetFourCCCodes
,
4499 ddraw2_GetGDISurface
,
4500 ddraw2_GetMonitorFrequency
,
4502 ddraw2_GetVerticalBlankStatus
,
4504 ddraw2_RestoreDisplayMode
,
4505 ddraw2_SetCooperativeLevel
,
4506 ddraw2_SetDisplayMode
,
4507 ddraw2_WaitForVerticalBlank
,
4509 ddraw2_GetAvailableVidMem
,
4512 static const struct IDirectDrawVtbl ddraw1_vtbl
=
4515 ddraw1_QueryInterface
,
4520 ddraw1_CreateClipper
,
4521 ddraw1_CreatePalette
,
4522 ddraw1_CreateSurface
,
4523 ddraw1_DuplicateSurface
,
4524 ddraw1_EnumDisplayModes
,
4525 ddraw1_EnumSurfaces
,
4526 ddraw1_FlipToGDISurface
,
4528 ddraw1_GetDisplayMode
,
4529 ddraw1_GetFourCCCodes
,
4530 ddraw1_GetGDISurface
,
4531 ddraw1_GetMonitorFrequency
,
4533 ddraw1_GetVerticalBlankStatus
,
4535 ddraw1_RestoreDisplayMode
,
4536 ddraw1_SetCooperativeLevel
,
4537 ddraw1_SetDisplayMode
,
4538 ddraw1_WaitForVerticalBlank
,
4541 static const struct IDirect3D7Vtbl d3d7_vtbl
=
4543 /* IUnknown methods */
4544 d3d7_QueryInterface
,
4547 /* IDirect3D7 methods */
4550 d3d7_CreateVertexBuffer
,
4551 d3d7_EnumZBufferFormats
,
4552 d3d7_EvictManagedTextures
4555 static const struct IDirect3D3Vtbl d3d3_vtbl
=
4557 /* IUnknown methods */
4558 d3d3_QueryInterface
,
4561 /* IDirect3D3 methods */
4564 d3d3_CreateMaterial
,
4565 d3d3_CreateViewport
,
4568 d3d3_CreateVertexBuffer
,
4569 d3d3_EnumZBufferFormats
,
4570 d3d3_EvictManagedTextures
4573 static const struct IDirect3D2Vtbl d3d2_vtbl
=
4575 /* IUnknown methods */
4576 d3d2_QueryInterface
,
4579 /* IDirect3D2 methods */
4582 d3d2_CreateMaterial
,
4583 d3d2_CreateViewport
,
4588 static const struct IDirect3DVtbl d3d1_vtbl
=
4590 /* IUnknown methods */
4591 d3d1_QueryInterface
,
4594 /* IDirect3D methods */
4598 d3d1_CreateMaterial
,
4599 d3d1_CreateViewport
,
4603 /*****************************************************************************
4606 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
4607 * if none was found.
4609 * This function is in ddraw.c and the DDraw object space because D3D7
4610 * vertex buffers are created using the IDirect3D interface to the ddraw
4611 * object, so they can be valid across D3D devices(theoretically. The ddraw
4612 * object also owns the wined3d device
4616 * fvf: Fvf to find the decl for
4619 * NULL in case of an error, the vertex declaration for the FVF otherwise.
4621 *****************************************************************************/
4622 struct wined3d_vertex_declaration
*ddraw_find_decl(struct ddraw
*This
, DWORD fvf
)
4624 struct wined3d_vertex_declaration
*pDecl
= NULL
;
4626 int p
, low
, high
; /* deliberately signed */
4627 struct FvfToDecl
*convertedDecls
= This
->decls
;
4629 TRACE("Searching for declaration for fvf %08x... ", fvf
);
4632 high
= This
->numConvertedDecls
- 1;
4633 while(low
<= high
) {
4634 p
= (low
+ high
) >> 1;
4636 if(convertedDecls
[p
].fvf
== fvf
) {
4637 TRACE("found %p\n", convertedDecls
[p
].decl
);
4638 return convertedDecls
[p
].decl
;
4639 } else if(convertedDecls
[p
].fvf
< fvf
) {
4645 TRACE("not found. Creating and inserting at position %d.\n", low
);
4647 hr
= wined3d_vertex_declaration_create_from_fvf(This
->wined3d_device
,
4648 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
4649 if (hr
!= S_OK
) return NULL
;
4651 if(This
->declArraySize
== This
->numConvertedDecls
) {
4652 int grow
= max(This
->declArraySize
/ 2, 8);
4653 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
4654 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
4655 if (!convertedDecls
)
4657 wined3d_vertex_declaration_decref(pDecl
);
4660 This
->decls
= convertedDecls
;
4661 This
->declArraySize
+= grow
;
4664 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
4665 convertedDecls
[low
].decl
= pDecl
;
4666 convertedDecls
[low
].fvf
= fvf
;
4667 This
->numConvertedDecls
++;
4669 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
4673 static inline struct ddraw
*ddraw_from_device_parent(struct wined3d_device_parent
*device_parent
)
4675 return CONTAINING_RECORD(device_parent
, struct ddraw
, device_parent
);
4678 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
4679 struct wined3d_device
*device
)
4681 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
4684 /* This is run from device_process_message() in wined3d, we can't take the
4686 /* FIXME: We only get mode change notifications in exclusive mode, but we
4687 * should mark surfaces as lost on mode changes in DDSCL_NORMAL mode as well. */
4688 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
4690 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4691 MONITORINFO monitor_info
;
4695 TRACE("device_parent %p.\n", device_parent
);
4697 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) || !ddraw
->swapchain_window
)
4699 TRACE("Nothing to resize.\n");
4703 monitor
= MonitorFromWindow(ddraw
->swapchain_window
, MONITOR_DEFAULTTOPRIMARY
);
4704 monitor_info
.cbSize
= sizeof(monitor_info
);
4705 if (!GetMonitorInfoW(monitor
, &monitor_info
))
4707 ERR("Failed to get monitor info.\n");
4711 r
= &monitor_info
.rcMonitor
;
4712 TRACE("Resizing window %p to %s.\n", ddraw
->swapchain_window
, wine_dbgstr_rect(r
));
4714 if (!SetWindowPos(ddraw
->swapchain_window
, HWND_TOP
, r
->left
, r
->top
,
4715 r
->right
- r
->left
, r
->bottom
- r
->top
, SWP_SHOWWINDOW
| SWP_NOACTIVATE
))
4716 ERR("Failed to resize window.\n");
4718 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_OK
);
4721 static void CDECL
device_parent_activate(struct wined3d_device_parent
*device_parent
, BOOL activate
)
4723 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4725 TRACE("device_parent %p, activate %#x.\n", device_parent
, activate
);
4729 ddraw
->device_state
= DDRAW_DEVICE_STATE_LOST
;
4730 exclusive_window
= NULL
;
4734 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_LOST
);
4738 void ddraw_update_lost_surfaces(struct ddraw
*ddraw
)
4740 struct ddraw_surface
*surface
;
4742 if (ddraw
->device_state
!= DDRAW_DEVICE_STATE_NOT_RESTORED
)
4745 LIST_FOR_EACH_ENTRY(surface
, &ddraw
->surface_list
, struct ddraw_surface
, surface_list_entry
)
4747 surface
->is_lost
= TRUE
;
4749 ddraw
->device_state
= DDRAW_DEVICE_STATE_OK
;
4752 static HRESULT CDECL
device_parent_surface_created(struct wined3d_device_parent
*device_parent
,
4753 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
4754 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
4756 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4757 struct ddraw_surface
*ddraw_surface
;
4759 TRACE("device_parent %p, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
4760 device_parent
, wined3d_texture
, sub_resource_idx
, parent
, parent_ops
);
4762 /* We have a swapchain or wined3d internal texture. */
4763 if (!wined3d_texture_get_parent(wined3d_texture
) || wined3d_texture_get_parent(wined3d_texture
) == ddraw
)
4766 *parent_ops
= &ddraw_null_wined3d_parent_ops
;
4771 if (!(ddraw_surface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ddraw_surface
))))
4773 ERR("Failed to allocate surface memory.\n");
4774 return DDERR_OUTOFVIDEOMEMORY
;
4777 ddraw_surface_init(ddraw_surface
, ddraw
, wined3d_texture
, sub_resource_idx
, parent_ops
);
4778 *parent
= ddraw_surface
;
4780 ddraw_update_lost_surfaces(ddraw
);
4781 list_add_head(&ddraw
->surface_list
, &ddraw_surface
->surface_list_entry
);
4783 TRACE("Created ddraw surface %p.\n", ddraw_surface
);
4788 static HRESULT CDECL
device_parent_volume_created(struct wined3d_device_parent
*device_parent
,
4789 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
4790 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
4792 TRACE("device_parent %p, texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
4793 device_parent
, wined3d_texture
, sub_resource_idx
, parent
, parent_ops
);
4796 *parent_ops
= &ddraw_null_wined3d_parent_ops
;
4801 static void STDMETHODCALLTYPE
ddraw_frontbuffer_destroyed(void *parent
)
4803 struct ddraw
*ddraw
= parent
;
4804 ddraw
->wined3d_frontbuffer
= NULL
;
4807 static const struct wined3d_parent_ops ddraw_frontbuffer_parent_ops
=
4809 ddraw_frontbuffer_destroyed
,
4812 static HRESULT CDECL
device_parent_create_swapchain_texture(struct wined3d_device_parent
*device_parent
,
4813 void *container_parent
, const struct wined3d_resource_desc
*desc
, struct wined3d_texture
**texture
)
4815 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4818 TRACE("device_parent %p, container_parent %p, desc %p, texture %p.\n",
4819 device_parent
, container_parent
, desc
, texture
);
4821 if (ddraw
->wined3d_frontbuffer
)
4823 ERR("Frontbuffer already created.\n");
4827 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, desc
, 1,
4828 WINED3D_TEXTURE_CREATE_MAPPABLE
, NULL
, ddraw
, &ddraw_frontbuffer_parent_ops
, texture
)))
4830 WARN("Failed to create texture, hr %#x.\n", hr
);
4834 ddraw
->wined3d_frontbuffer
= *texture
;
4839 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
4840 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
4842 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4845 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent
, desc
, swapchain
);
4847 if (ddraw
->wined3d_swapchain
)
4849 ERR("Swapchain already created.\n");
4853 if (FAILED(hr
= wined3d_swapchain_create(ddraw
->wined3d_device
, desc
, NULL
,
4854 &ddraw_null_wined3d_parent_ops
, swapchain
)))
4855 WARN("Failed to create swapchain, hr %#x.\n", hr
);
4860 static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops
=
4862 device_parent_wined3d_device_created
,
4863 device_parent_mode_changed
,
4864 device_parent_activate
,
4865 device_parent_surface_created
,
4866 device_parent_volume_created
,
4867 device_parent_create_swapchain_texture
,
4868 device_parent_create_swapchain
,
4871 HRESULT
ddraw_init(struct ddraw
*ddraw
, DWORD flags
, enum wined3d_device_type device_type
)
4876 ddraw
->IDirectDraw7_iface
.lpVtbl
= &ddraw7_vtbl
;
4877 ddraw
->IDirectDraw_iface
.lpVtbl
= &ddraw1_vtbl
;
4878 ddraw
->IDirectDraw2_iface
.lpVtbl
= &ddraw2_vtbl
;
4879 ddraw
->IDirectDraw4_iface
.lpVtbl
= &ddraw4_vtbl
;
4880 ddraw
->IDirect3D_iface
.lpVtbl
= &d3d1_vtbl
;
4881 ddraw
->IDirect3D2_iface
.lpVtbl
= &d3d2_vtbl
;
4882 ddraw
->IDirect3D3_iface
.lpVtbl
= &d3d3_vtbl
;
4883 ddraw
->IDirect3D7_iface
.lpVtbl
= &d3d7_vtbl
;
4884 ddraw
->device_parent
.ops
= &ddraw_wined3d_device_parent_ops
;
4885 ddraw
->numIfaces
= 1;
4888 flags
|= DDRAW_WINED3D_FLAGS
;
4889 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
4891 flags
|= WINED3D_NO3D
;
4892 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
4894 WARN("Failed to create a wined3d object.\n");
4899 if (FAILED(hr
= wined3d_get_device_caps(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
, &caps
)))
4901 ERR("Failed to get device caps, hr %#x.\n", hr
);
4902 wined3d_decref(ddraw
->wined3d
);
4906 if (!(caps
.ddraw_caps
.caps
& WINEDDCAPS_3D
))
4908 WARN("Created a wined3d object without 3D support.\n");
4909 ddraw
->flags
|= DDRAW_NO3D
;
4912 if (FAILED(hr
= wined3d_device_create(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
,
4913 NULL
, 0, DDRAW_STRIDE_ALIGNMENT
, &ddraw
->device_parent
, &ddraw
->wined3d_device
)))
4915 WARN("Failed to create a wined3d device, hr %#x.\n", hr
);
4916 wined3d_decref(ddraw
->wined3d
);
4920 list_init(&ddraw
->surface_list
);