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"
31 #include "wine/exception.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
35 static const struct ddraw
*exclusive_ddraw
;
36 static HWND exclusive_window
;
38 /* Device identifier. Don't relay it to WineD3D */
39 static const DDDEVICEIDENTIFIER2 deviceidentifier
=
41 "vga.dll", /* default 2D driver */
43 { { 0x00010001, 0x00010001 } },
45 /* a8373c10-7ac4-4deb-849a-009844d08b2d */
46 {0xa8373c10,0x7ac4,0x4deb, {0x84,0x9a,0x00,0x98,0x44,0xd0,0x8b,0x2d}},
50 static struct enum_device_entry
52 char interface_name
[100];
53 char device_name
[100];
54 const GUID
*device_guid
;
59 "WINE Direct3D7 Hardware Transform and Lighting acceleration using WineD3D",
61 &IID_IDirect3DTnLHalDevice
,
66 "WINE Direct3D7 Hardware acceleration using WineD3D",
68 &IID_IDirect3DHALDevice
,
73 "WINE Direct3D7 RGB Software Emulation using WineD3D",
75 &IID_IDirect3DRGBDevice
,
79 static void STDMETHODCALLTYPE
ddraw_null_wined3d_object_destroyed(void *parent
) {}
81 const struct wined3d_parent_ops ddraw_null_wined3d_parent_ops
=
83 ddraw_null_wined3d_object_destroyed
,
86 static inline struct ddraw
*impl_from_IDirectDraw(IDirectDraw
*iface
)
88 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw_iface
);
91 static inline struct ddraw
*impl_from_IDirectDraw2(IDirectDraw2
*iface
)
93 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw2_iface
);
96 static inline struct ddraw
*impl_from_IDirectDraw4(IDirectDraw4
*iface
)
98 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw4_iface
);
101 static inline struct ddraw
*impl_from_IDirectDraw7(IDirectDraw7
*iface
)
103 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw7_iface
);
106 static inline struct ddraw
*impl_from_IDirect3D(IDirect3D
*iface
)
108 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D_iface
);
111 static inline struct ddraw
*impl_from_IDirect3D2(IDirect3D2
*iface
)
113 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D2_iface
);
116 static inline struct ddraw
*impl_from_IDirect3D3(IDirect3D3
*iface
)
118 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D3_iface
);
121 static inline struct ddraw
*impl_from_IDirect3D7(IDirect3D7
*iface
)
123 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D7_iface
);
126 static HRESULT WINAPI
ddraw7_QueryInterface(IDirectDraw7
*iface
, REFIID riid
, void **out
)
128 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
130 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
135 return DDERR_INVALIDPARAMS
;
138 /* The refcount unit test revealed that an IDirect3D7 interface can only
139 * be queried from a DirectDraw object that was created as an IDirectDraw7
140 * interface. The older interfaces can query any IDirect3D version except
141 * 7, because they are all initially created as IDirectDraw. This isn't
142 * really crucial behavior, and messy to implement with the common
143 * creation function, so it has been left out here. */
144 if (IsEqualGUID(&IID_IDirectDraw7
, riid
)
145 || IsEqualGUID(&IID_IUnknown
, riid
))
147 *out
= &ddraw
->IDirectDraw7_iface
;
148 TRACE("Returning IDirectDraw7 interface %p.\n", *out
);
150 else if (IsEqualGUID(&IID_IDirectDraw4
, riid
))
152 *out
= &ddraw
->IDirectDraw4_iface
;
153 TRACE("Returning IDirectDraw4 interface %p.\n", *out
);
155 else if (IsEqualGUID(&IID_IDirectDraw2
, riid
))
157 *out
= &ddraw
->IDirectDraw2_iface
;
158 TRACE("Returning IDirectDraw2 interface %p.\n", *out
);
160 else if (IsEqualGUID(&IID_IDirectDraw
, riid
))
162 *out
= &ddraw
->IDirectDraw_iface
;
163 TRACE("Returning IDirectDraw interface %p.\n", *out
);
165 else if (IsEqualGUID(&IID_IDirect3D7
, riid
))
167 ddraw
->d3dversion
= 7;
168 *out
= &ddraw
->IDirect3D7_iface
;
169 TRACE("Returning Direct3D7 interface %p.\n", *out
);
171 else if (IsEqualGUID(&IID_IDirect3D3
, riid
))
173 ddraw
->d3dversion
= 3;
174 *out
= &ddraw
->IDirect3D3_iface
;
175 TRACE("Returning Direct3D3 interface %p.\n", *out
);
177 else if (IsEqualGUID(&IID_IDirect3D2
, riid
))
179 ddraw
->d3dversion
= 2;
180 *out
= &ddraw
->IDirect3D2_iface
;
181 TRACE("Returning Direct3D2 interface %p.\n", *out
);
183 else if (IsEqualGUID(&IID_IDirect3D
, riid
))
185 ddraw
->d3dversion
= 1;
186 *out
= &ddraw
->IDirect3D_iface
;
187 TRACE("Returning Direct3D interface %p.\n", *out
);
189 /* Unknown interface */
192 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
194 return E_NOINTERFACE
;
197 IUnknown_AddRef((IUnknown
*)*out
);
201 static HRESULT WINAPI
ddraw4_QueryInterface(IDirectDraw4
*iface
, REFIID riid
, void **object
)
203 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
205 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
207 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
210 static HRESULT WINAPI
ddraw2_QueryInterface(IDirectDraw2
*iface
, REFIID riid
, void **object
)
212 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
214 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
216 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
219 static HRESULT WINAPI
ddraw1_QueryInterface(IDirectDraw
*iface
, REFIID riid
, void **object
)
221 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
223 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
225 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
228 static HRESULT WINAPI
d3d7_QueryInterface(IDirect3D7
*iface
, REFIID riid
, void **object
)
230 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
232 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
234 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
237 static HRESULT WINAPI
d3d3_QueryInterface(IDirect3D3
*iface
, REFIID riid
, void **object
)
239 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
241 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
243 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
246 static HRESULT WINAPI
d3d2_QueryInterface(IDirect3D2
*iface
, REFIID riid
, void **object
)
248 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
250 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
252 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
255 static HRESULT WINAPI
d3d1_QueryInterface(IDirect3D
*iface
, REFIID riid
, void **object
)
257 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
259 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
261 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
264 /*****************************************************************************
265 * IDirectDraw7::AddRef
267 * Increases the interfaces refcount, basically
269 * DDraw refcounting is a bit tricky. The different DirectDraw interface
270 * versions have individual refcounts, but the IDirect3D interfaces do not.
271 * All interfaces are from one object, that means calling QueryInterface on an
272 * IDirectDraw7 interface for an IDirectDraw4 interface does not create a new
275 * That means all AddRef and Release implementations of IDirectDrawX work
276 * with their own counter, and IDirect3DX::AddRef thunk to IDirectDraw (1),
277 * except of IDirect3D7 which thunks to IDirectDraw7
279 * Returns: The new refcount
281 *****************************************************************************/
282 static ULONG WINAPI
ddraw7_AddRef(IDirectDraw7
*iface
)
284 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
285 ULONG ref
= InterlockedIncrement(&This
->ref7
);
287 TRACE("%p increasing refcount to %u.\n", This
, ref
);
289 if(ref
== 1) InterlockedIncrement(&This
->numIfaces
);
294 static ULONG WINAPI
ddraw4_AddRef(IDirectDraw4
*iface
)
296 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
297 ULONG ref
= InterlockedIncrement(&This
->ref4
);
299 TRACE("%p increasing refcount to %u.\n", This
, ref
);
301 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
306 static ULONG WINAPI
ddraw2_AddRef(IDirectDraw2
*iface
)
308 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
309 ULONG ref
= InterlockedIncrement(&This
->ref2
);
311 TRACE("%p increasing refcount to %u.\n", This
, ref
);
313 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
318 static ULONG WINAPI
ddraw1_AddRef(IDirectDraw
*iface
)
320 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
321 ULONG ref
= InterlockedIncrement(&This
->ref1
);
323 TRACE("%p increasing refcount to %u.\n", This
, ref
);
325 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
330 static ULONG WINAPI
d3d7_AddRef(IDirect3D7
*iface
)
332 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
334 TRACE("iface %p.\n", iface
);
336 return ddraw7_AddRef(&This
->IDirectDraw7_iface
);
339 static ULONG WINAPI
d3d3_AddRef(IDirect3D3
*iface
)
341 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
343 TRACE("iface %p.\n", iface
);
345 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
348 static ULONG WINAPI
d3d2_AddRef(IDirect3D2
*iface
)
350 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
352 TRACE("iface %p.\n", iface
);
354 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
357 static ULONG WINAPI
d3d1_AddRef(IDirect3D
*iface
)
359 struct ddraw
*This
= impl_from_IDirect3D(iface
);
361 TRACE("iface %p.\n", iface
);
363 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
366 static void ddraw_destroy_swapchain(struct ddraw
*ddraw
)
368 TRACE("Destroying the swapchain.\n");
370 wined3d_swapchain_decref(ddraw
->wined3d_swapchain
);
371 ddraw
->wined3d_swapchain
= NULL
;
373 if (!(ddraw
->flags
& DDRAW_NO3D
))
377 for (i
= 0; i
< ddraw
->numConvertedDecls
; ++i
)
379 wined3d_vertex_declaration_decref(ddraw
->decls
[i
].decl
);
381 heap_free(ddraw
->decls
);
382 ddraw
->numConvertedDecls
= 0;
384 if (FAILED(wined3d_device_uninit_3d(ddraw
->wined3d_device
)))
386 ERR("Failed to uninit 3D.\n");
390 /* Free the d3d window if one was created. */
391 if (ddraw
->d3d_window
&& ddraw
->d3d_window
!= ddraw
->dest_window
)
393 TRACE("Destroying the hidden render window %p.\n", ddraw
->d3d_window
);
394 DestroyWindow(ddraw
->d3d_window
);
395 ddraw
->d3d_window
= 0;
399 ddraw
->flags
&= ~DDRAW_D3D_INITIALIZED
;
403 wined3d_device_uninit_gdi(ddraw
->wined3d_device
);
406 ddraw_set_swapchain_window(ddraw
, NULL
);
408 TRACE("Swapchain destroyed.\n");
411 /*****************************************************************************
414 * Destroys a ddraw object if all refcounts are 0. This is to share code
415 * between the IDirectDrawX::Release functions
418 * This: DirectDraw object to destroy
420 *****************************************************************************/
421 static void ddraw_destroy(struct ddraw
*This
)
423 IDirectDraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, NULL
, DDSCL_NORMAL
);
424 IDirectDraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
426 /* Destroy the device window if we created one */
427 if(This
->devicewindow
!= 0)
429 TRACE(" (%p) Destroying the device window %p\n", This
, This
->devicewindow
);
430 DestroyWindow(This
->devicewindow
);
431 This
->devicewindow
= 0;
434 wined3d_mutex_lock();
435 list_remove(&This
->ddraw_list_entry
);
436 wined3d_mutex_unlock();
438 if (This
->wined3d_swapchain
)
439 ddraw_destroy_swapchain(This
);
440 wined3d_device_decref(This
->wined3d_device
);
441 wined3d_decref(This
->wined3d
);
444 This
->d3ddevice
->ddraw
= NULL
;
446 /* Now free the object */
450 /*****************************************************************************
451 * IDirectDraw7::Release
453 * Decreases the refcount. If the refcount falls to 0, the object is destroyed
455 * Returns: The new refcount
456 *****************************************************************************/
457 static ULONG WINAPI
ddraw7_Release(IDirectDraw7
*iface
)
459 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
460 ULONG ref
= InterlockedDecrement(&This
->ref7
);
462 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
464 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
470 static ULONG WINAPI
ddraw4_Release(IDirectDraw4
*iface
)
472 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
473 ULONG ref
= InterlockedDecrement(&This
->ref4
);
475 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
477 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
483 static ULONG WINAPI
ddraw2_Release(IDirectDraw2
*iface
)
485 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
486 ULONG ref
= InterlockedDecrement(&This
->ref2
);
488 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
490 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
496 static ULONG WINAPI
ddraw1_Release(IDirectDraw
*iface
)
498 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
499 ULONG ref
= InterlockedDecrement(&This
->ref1
);
501 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
503 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
509 static ULONG WINAPI
d3d7_Release(IDirect3D7
*iface
)
511 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
513 TRACE("iface %p.\n", iface
);
515 return ddraw7_Release(&This
->IDirectDraw7_iface
);
518 static ULONG WINAPI
d3d3_Release(IDirect3D3
*iface
)
520 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
522 TRACE("iface %p.\n", iface
);
524 return ddraw1_Release(&This
->IDirectDraw_iface
);
527 static ULONG WINAPI
d3d2_Release(IDirect3D2
*iface
)
529 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
531 TRACE("iface %p.\n", iface
);
533 return ddraw1_Release(&This
->IDirectDraw_iface
);
536 static ULONG WINAPI
d3d1_Release(IDirect3D
*iface
)
538 struct ddraw
*This
= impl_from_IDirect3D(iface
);
540 TRACE("iface %p.\n", iface
);
542 return ddraw1_Release(&This
->IDirectDraw_iface
);
545 /*****************************************************************************
546 * IDirectDraw methods
547 *****************************************************************************/
549 static HRESULT
ddraw_set_focus_window(struct ddraw
*ddraw
, HWND window
)
551 /* FIXME: This looks wrong, exclusive mode should imply a destination
553 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) && ddraw
->dest_window
)
555 TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET.\n");
556 return DDERR_HWNDALREADYSET
;
559 ddraw
->focuswindow
= window
;
564 static HRESULT
ddraw_attach_d3d_device(struct ddraw
*ddraw
,
565 struct wined3d_swapchain_desc
*swapchain_desc
)
567 HWND window
= swapchain_desc
->device_window
;
570 TRACE("ddraw %p.\n", ddraw
);
572 if (!window
|| window
== GetDesktopWindow())
574 window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "Hidden D3D Window",
575 WS_DISABLED
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
576 NULL
, NULL
, NULL
, NULL
);
579 ERR("Failed to create window, last error %#x.\n", GetLastError());
583 ShowWindow(window
, SW_HIDE
); /* Just to be sure */
584 WARN("No window for the Direct3DDevice, created hidden window %p.\n", window
);
586 swapchain_desc
->device_window
= window
;
590 TRACE("Using existing window %p for Direct3D rendering.\n", window
);
592 ddraw
->d3d_window
= window
;
594 /* Set this NOW, otherwise creating the depth stencil surface will cause a
595 * recursive loop until ram or emulated video memory is full. */
596 ddraw
->flags
|= DDRAW_D3D_INITIALIZED
;
597 hr
= wined3d_device_init_3d(ddraw
->wined3d_device
, swapchain_desc
);
600 ddraw
->flags
&= ~DDRAW_D3D_INITIALIZED
;
604 ddraw
->declArraySize
= 2;
605 if (!(ddraw
->decls
= heap_alloc_zero(ddraw
->declArraySize
* sizeof(*ddraw
->decls
))))
607 ERR("Error allocating an array for the converted vertex decls.\n");
608 ddraw
->declArraySize
= 0;
609 hr
= wined3d_device_uninit_3d(ddraw
->wined3d_device
);
610 return E_OUTOFMEMORY
;
613 TRACE("Successfully initialized 3D.\n");
618 static HRESULT
ddraw_create_swapchain(struct ddraw
*ddraw
, HWND window
, BOOL windowed
)
620 struct wined3d_swapchain_desc swapchain_desc
;
621 struct wined3d_display_mode mode
;
622 HRESULT hr
= WINED3D_OK
;
624 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
626 ERR("Failed to get display mode.\n");
630 memset(&swapchain_desc
, 0, sizeof(swapchain_desc
));
631 swapchain_desc
.backbuffer_width
= mode
.width
;
632 swapchain_desc
.backbuffer_height
= mode
.height
;
633 swapchain_desc
.backbuffer_format
= mode
.format_id
;
634 swapchain_desc
.backbuffer_bind_flags
= 0;
635 swapchain_desc
.backbuffer_count
= 1;
636 swapchain_desc
.swap_effect
= WINED3D_SWAP_EFFECT_DISCARD
;
637 swapchain_desc
.device_window
= window
;
638 swapchain_desc
.windowed
= windowed
;
639 swapchain_desc
.flags
= WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH
;
641 if (!(ddraw
->flags
& DDRAW_NO3D
))
642 hr
= ddraw_attach_d3d_device(ddraw
, &swapchain_desc
);
644 hr
= wined3d_device_init_gdi(ddraw
->wined3d_device
, &swapchain_desc
);
648 ERR("Failed to create swapchain, hr %#x.\n", hr
);
652 if (!(ddraw
->wined3d_swapchain
= wined3d_device_get_swapchain(ddraw
->wined3d_device
, 0)))
654 ERR("Failed to get swapchain.\n");
655 return DDERR_INVALIDPARAMS
;
658 wined3d_swapchain_incref(ddraw
->wined3d_swapchain
);
659 ddraw_set_swapchain_window(ddraw
, window
);
661 if (ddraw
->primary
&& ddraw
->primary
->palette
)
662 wined3d_swapchain_set_palette(ddraw
->wined3d_swapchain
, ddraw
->primary
->palette
->wined3d_palette
);
667 /*****************************************************************************
668 * IDirectDraw7::RestoreDisplayMode
670 * Restores the display mode to what it was at creation time. Basically.
674 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
676 *****************************************************************************/
677 static HRESULT WINAPI
ddraw7_RestoreDisplayMode(IDirectDraw7
*iface
)
679 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
682 TRACE("iface %p.\n", iface
);
684 wined3d_mutex_lock();
686 if (!(ddraw
->flags
& DDRAW_RESTORE_MODE
))
688 wined3d_mutex_unlock();
692 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
694 wined3d_mutex_unlock();
695 return DDERR_NOEXCLUSIVEMODE
;
698 if (SUCCEEDED(hr
= wined3d_set_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, NULL
)))
699 ddraw
->flags
&= ~DDRAW_RESTORE_MODE
;
701 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_OK
);
703 wined3d_mutex_unlock();
708 static HRESULT WINAPI
ddraw4_RestoreDisplayMode(IDirectDraw4
*iface
)
710 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
712 TRACE("iface %p.\n", iface
);
714 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
717 static HRESULT WINAPI
ddraw2_RestoreDisplayMode(IDirectDraw2
*iface
)
719 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
721 TRACE("iface %p.\n", iface
);
723 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
726 static HRESULT WINAPI
ddraw1_RestoreDisplayMode(IDirectDraw
*iface
)
728 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
730 TRACE("iface %p.\n", iface
);
732 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
735 /*****************************************************************************
736 * IDirectDraw7::SetCooperativeLevel
738 * Sets the cooperative level for the DirectDraw object, and the window
739 * assigned to it. The cooperative level determines the general behavior
740 * of the DirectDraw application
742 * Warning: This is quite tricky, as it's not really documented which
743 * cooperative levels can be combined with each other. If a game fails
744 * after this function, try to check the cooperative levels passed on
745 * Windows, and if it returns something different.
747 * If you think that this function caused the failure because it writes a
748 * fixme, be sure to run again with a +ddraw trace.
750 * What is known about cooperative levels (See the ddraw modes test):
751 * DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN.
752 * DDSCL_NORMAL is not compatible with DDSCL_EXCLUSIVE.
753 * Unlike what msdn claims, DDSCL_NORMAL | DDSCL_FULLSCREEN is allowed.
754 * DDSCL_SETFOCUSWINDOW can be passed only in DDSCL_NORMAL mode, but after that
755 * DDSCL_EXCLUSIVE can be activated.
756 * DDSCL_SETFOCUSWINDOW may only be used with DDSCL_NOWINDOWCHANGES or
757 * DDSCL_CREATEDEVICEWINDOW.
759 * Handled flags: DDSCL_NORMAL, DDSCL_FULLSCREEN, DDSCL_EXCLUSIVE,
760 * DDSCL_CREATEDEVICEWINDOW, DDSCL_SETDEVICEWINDOW
761 * DDSCL_SETFOCUSWINDOW (partially),
762 * DDSCL_MULTITHREADED (work in progress)
763 * DDSCL_FPUPRESERVE (see device.c)
765 * Unsure about this: DDSCL_FPUSETUP
767 * These don't seem very important for wine:
768 * DDSCL_ALLOWREBOOT, DDSCL_NOWINDOWCHANGES, DDSCL_ALLOWMODEX
771 * DD_OK if the cooperative level was set successfully
772 * DDERR_INVALIDPARAMS if the passed cooperative level combination is invalid
773 * DDERR_HWNDALREADYSET if DDSCL_SETFOCUSWINDOW is passed in exclusive mode
774 * (Probably others too, have to investigate)
776 *****************************************************************************/
777 static HRESULT
ddraw_set_cooperative_level(struct ddraw
*ddraw
, HWND window
,
778 DWORD cooplevel
, BOOL restore_mode_on_normal
)
780 struct wined3d_rendertarget_view
*rtv
= NULL
, *dsv
= NULL
;
781 struct wined3d_stateblock
*stateblock
;
782 BOOL restore_state
= FALSE
;
785 TRACE("ddraw %p, window %p, flags %#x, restore_mode_on_normal %x.\n", ddraw
, window
, cooplevel
,
786 restore_mode_on_normal
);
787 DDRAW_dump_cooperativelevel(cooplevel
);
789 wined3d_mutex_lock();
791 if (ddraw
->flags
& DDRAW_SCL_RECURSIVE
)
793 WARN("Recursive call, returning DD_OK.\n");
797 ddraw
->flags
|= DDRAW_SCL_RECURSIVE
;
799 /* Tests suggest that we need one of them: */
800 if(!(cooplevel
& (DDSCL_SETFOCUSWINDOW
|
804 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
805 hr
= DDERR_INVALIDPARAMS
;
809 if ((cooplevel
& DDSCL_CREATEDEVICEWINDOW
) && !(cooplevel
& DDSCL_EXCLUSIVE
))
811 WARN("DDSCL_CREATEDEVICEWINDOW requires DDSCL_EXCLUSIVE.\n");
812 hr
= DDERR_INVALIDPARAMS
;
816 /* Handle those levels first which set various hwnds */
817 if ((cooplevel
& DDSCL_SETFOCUSWINDOW
) && !(cooplevel
& DDSCL_CREATEDEVICEWINDOW
))
819 /* This isn't compatible with a lot of flags */
820 if (cooplevel
& (DDSCL_MULTITHREADED
825 | DDSCL_SETDEVICEWINDOW
830 WARN("Called with incompatible flags, returning DDERR_INVALIDPARAMS.\n");
831 hr
= DDERR_INVALIDPARAMS
;
835 hr
= ddraw_set_focus_window(ddraw
, window
);
839 if (cooplevel
& DDSCL_EXCLUSIVE
)
841 if (!(cooplevel
& DDSCL_FULLSCREEN
) || !(window
|| (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)))
843 WARN("DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN and a window.\n");
844 hr
= DDERR_INVALIDPARAMS
;
848 if (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)
852 if (!ddraw
->focuswindow
&& !(cooplevel
& DDSCL_SETFOCUSWINDOW
))
854 WARN("No focus window set.\n");
855 hr
= DDERR_NOFOCUSWINDOW
;
859 device_window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "DirectDrawDeviceWnd",
860 WS_POPUP
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
861 NULL
, NULL
, NULL
, NULL
);
864 ERR("Failed to create window, last error %#x.\n", GetLastError());
869 ShowWindow(device_window
, SW_SHOW
);
870 TRACE("Created a device window %p.\n", device_window
);
872 /* Native apparently leaks the created device window if setting the
873 * focus window below fails. */
874 ddraw
->cooperative_level
|= DDSCL_CREATEDEVICEWINDOW
;
875 ddraw
->devicewindow
= device_window
;
877 if (cooplevel
& DDSCL_SETFOCUSWINDOW
)
885 if (FAILED(hr
= ddraw_set_focus_window(ddraw
, window
)))
889 window
= device_window
;
894 if (ddraw
->cooperative_level
& DDSCL_CREATEDEVICEWINDOW
)
895 DestroyWindow(ddraw
->devicewindow
);
896 ddraw
->devicewindow
= NULL
;
897 ddraw
->focuswindow
= NULL
;
900 if ((cooplevel
& DDSCL_FULLSCREEN
) != (ddraw
->cooperative_level
& DDSCL_FULLSCREEN
) || window
!= ddraw
->dest_window
)
902 if (ddraw
->cooperative_level
& DDSCL_FULLSCREEN
)
903 wined3d_device_restore_fullscreen_window(ddraw
->wined3d_device
, ddraw
->dest_window
, NULL
);
905 if (cooplevel
& DDSCL_FULLSCREEN
)
907 struct wined3d_display_mode display_mode
;
909 wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &display_mode
, NULL
);
910 wined3d_device_setup_fullscreen_window(ddraw
->wined3d_device
, window
,
911 display_mode
.width
, display_mode
.height
);
915 if ((cooplevel
& DDSCL_EXCLUSIVE
) && exclusive_window
!= window
)
917 ddraw
->device_state
= DDRAW_DEVICE_STATE_NOT_RESTORED
;
918 exclusive_window
= window
;
921 if (cooplevel
& DDSCL_MULTITHREADED
&& !(ddraw
->cooperative_level
& DDSCL_MULTITHREADED
))
922 wined3d_device_set_multithreaded(ddraw
->wined3d_device
);
924 if (ddraw
->wined3d_swapchain
)
926 if (!(ddraw
->flags
& DDRAW_NO3D
))
928 restore_state
= TRUE
;
930 if (FAILED(hr
= wined3d_stateblock_create(ddraw
->wined3d_device
, WINED3D_SBT_ALL
, &stateblock
)))
932 ERR("Failed to create stateblock, hr %#x.\n", hr
);
936 rtv
= wined3d_device_get_rendertarget_view(ddraw
->wined3d_device
, 0);
937 /* Rendering to ddraw->wined3d_frontbuffer. */
938 if (rtv
&& !wined3d_rendertarget_view_get_sub_resource_parent(rtv
))
941 wined3d_rendertarget_view_incref(rtv
);
943 if ((dsv
= wined3d_device_get_depth_stencil_view(ddraw
->wined3d_device
)))
944 wined3d_rendertarget_view_incref(dsv
);
947 ddraw_destroy_swapchain(ddraw
);
950 if (FAILED(hr
= ddraw_create_swapchain(ddraw
, window
, !(cooplevel
& DDSCL_FULLSCREEN
))))
951 ERR("Failed to create swapchain, hr %#x.\n", hr
);
957 wined3d_device_set_depth_stencil_view(ddraw
->wined3d_device
, dsv
);
958 wined3d_rendertarget_view_decref(dsv
);
963 wined3d_device_set_rendertarget_view(ddraw
->wined3d_device
, 0, rtv
, FALSE
);
964 wined3d_rendertarget_view_decref(rtv
);
967 wined3d_stateblock_apply(stateblock
);
968 wined3d_stateblock_decref(stateblock
);
971 if (!(cooplevel
& DDSCL_EXCLUSIVE
) && (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
972 && restore_mode_on_normal
)
974 hr
= ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
976 ERR("RestoreDisplayMode failed\n");
979 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
980 && (window
!= ddraw
->dest_window
|| !(cooplevel
& DDSCL_EXCLUSIVE
)))
981 wined3d_device_release_focus_window(ddraw
->wined3d_device
);
983 if ((cooplevel
& DDSCL_EXCLUSIVE
)
984 && (window
!= ddraw
->dest_window
|| !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)))
986 hr
= wined3d_device_acquire_focus_window(ddraw
->wined3d_device
, window
);
989 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
994 /* Unhandled flags */
995 if (cooplevel
& DDSCL_ALLOWREBOOT
)
996 WARN("Unhandled flag DDSCL_ALLOWREBOOT, harmless\n");
997 if (cooplevel
& DDSCL_ALLOWMODEX
)
998 WARN("Unhandled flag DDSCL_ALLOWMODEX, harmless\n");
999 if (cooplevel
& DDSCL_FPUSETUP
)
1000 WARN("Unhandled flag DDSCL_FPUSETUP, harmless\n");
1002 if (cooplevel
& DDSCL_EXCLUSIVE
)
1003 exclusive_ddraw
= ddraw
;
1004 else if (exclusive_ddraw
== ddraw
)
1005 exclusive_ddraw
= NULL
;
1007 /* Store the cooperative_level */
1008 ddraw
->cooperative_level
= cooplevel
;
1009 ddraw
->dest_window
= window
;
1011 TRACE("SetCooperativeLevel returning DD_OK\n");
1014 ddraw
->flags
&= ~DDRAW_SCL_RECURSIVE
;
1015 wined3d_mutex_unlock();
1020 static HRESULT WINAPI
ddraw7_SetCooperativeLevel(IDirectDraw7
*iface
, HWND window
, DWORD flags
)
1022 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1024 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1026 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1029 static HRESULT WINAPI
ddraw4_SetCooperativeLevel(IDirectDraw4
*iface
, HWND window
, DWORD flags
)
1031 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1033 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1035 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1038 static HRESULT WINAPI
ddraw2_SetCooperativeLevel(IDirectDraw2
*iface
, HWND window
, DWORD flags
)
1040 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1042 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1044 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1047 static HRESULT WINAPI
ddraw1_SetCooperativeLevel(IDirectDraw
*iface
, HWND window
, DWORD flags
)
1049 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1052 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1054 hr
= ddraw_set_cooperative_level(ddraw
, window
, flags
, FALSE
);
1056 ddraw
->flags
|= DDRAW_SCL_DDRAW1
;
1060 /*****************************************************************************
1061 * IDirectDraw7::SetDisplayMode
1063 * Sets the display screen resolution, color depth and refresh frequency
1064 * when in fullscreen mode (in theory).
1065 * Possible return values listed in the SDK suggest that this method fails
1066 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
1067 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
1068 * It seems to be valid to pass 0 for With and Height, this has to be tested
1069 * It could mean that the current video mode should be left as-is. (But why
1073 * Height, Width: Screen dimension
1074 * BPP: Color depth in Bits per pixel
1075 * Refreshrate: Screen refresh rate
1076 * Flags: Other stuff
1081 *****************************************************************************/
1082 static HRESULT WINAPI
ddraw7_SetDisplayMode(IDirectDraw7
*iface
, DWORD width
, DWORD height
,
1083 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1085 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1086 struct wined3d_display_mode mode
;
1087 enum wined3d_format_id format
;
1090 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1091 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1093 if (force_refresh_rate
!= 0)
1095 TRACE("ForceRefreshRate overriding passed-in refresh rate (%u Hz) to %u Hz\n",
1096 refresh_rate
, force_refresh_rate
);
1097 refresh_rate
= force_refresh_rate
;
1100 wined3d_mutex_lock();
1102 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
1104 wined3d_mutex_unlock();
1105 return DDERR_NOEXCLUSIVEMODE
;
1108 if (!width
|| !height
)
1110 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here. */
1111 wined3d_mutex_unlock();
1117 case 8: format
= WINED3DFMT_P8_UINT
; break;
1118 case 15: format
= WINED3DFMT_B5G5R5X1_UNORM
; break;
1119 case 16: format
= WINED3DFMT_B5G6R5_UNORM
; break;
1120 case 24: format
= WINED3DFMT_B8G8R8_UNORM
; break;
1121 case 32: format
= WINED3DFMT_B8G8R8X8_UNORM
; break;
1122 default: format
= WINED3DFMT_UNKNOWN
; break;
1126 mode
.height
= height
;
1127 mode
.refresh_rate
= refresh_rate
;
1128 mode
.format_id
= format
;
1129 mode
.scanline_ordering
= WINED3D_SCANLINE_ORDERING_UNKNOWN
;
1131 /* TODO: The possible return values from msdn suggest that the screen mode
1132 * can't be changed if a surface is locked or some drawing is in progress. */
1133 if (SUCCEEDED(hr
= wined3d_set_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
)))
1137 DDSURFACEDESC2
*surface_desc
= &ddraw
->primary
->surface_desc
;
1139 if (FAILED(hr
= wined3d_swapchain_resize_buffers(ddraw
->wined3d_swapchain
, 0,
1140 surface_desc
->dwWidth
, surface_desc
->dwHeight
, mode
.format_id
, WINED3D_MULTISAMPLE_NONE
, 0)))
1141 ERR("Failed to resize buffers, hr %#x.\n", hr
);
1143 ddrawformat_from_wined3dformat(&ddraw
->primary
->surface_desc
.u4
.ddpfPixelFormat
, mode
.format_id
);
1145 ddraw
->flags
|= DDRAW_RESTORE_MODE
;
1148 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_OK
);
1150 wined3d_mutex_unlock();
1154 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1159 static HRESULT WINAPI
ddraw4_SetDisplayMode(IDirectDraw4
*iface
, DWORD width
, DWORD height
,
1160 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1162 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1164 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1165 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1167 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1170 static HRESULT WINAPI
ddraw2_SetDisplayMode(IDirectDraw2
*iface
,
1171 DWORD width
, DWORD height
, DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1173 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1175 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1176 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1178 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1181 static HRESULT WINAPI
ddraw1_SetDisplayMode(IDirectDraw
*iface
, DWORD width
, DWORD height
, DWORD bpp
)
1183 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1185 TRACE("iface %p, width %u, height %u, bpp %u.\n", iface
, width
, height
, bpp
);
1187 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, 0, 0);
1190 void ddraw_d3dcaps1_from_7(D3DDEVICEDESC
*caps1
, D3DDEVICEDESC7
*caps7
)
1192 memset(caps1
, 0, sizeof(*caps1
));
1193 caps1
->dwSize
= sizeof(*caps1
);
1194 caps1
->dwFlags
= D3DDD_COLORMODEL
1196 | D3DDD_TRANSFORMCAPS
1198 | D3DDD_LIGHTINGCAPS
1201 | D3DDD_DEVICERENDERBITDEPTH
1202 | D3DDD_DEVICEZBUFFERBITDEPTH
1203 | D3DDD_MAXBUFFERSIZE
1204 | D3DDD_MAXVERTEXCOUNT
;
1205 caps1
->dcmColorModel
= D3DCOLOR_RGB
;
1206 caps1
->dwDevCaps
= caps7
->dwDevCaps
;
1207 caps1
->dtcTransformCaps
.dwSize
= sizeof(caps1
->dtcTransformCaps
);
1208 caps1
->dtcTransformCaps
.dwCaps
= D3DTRANSFORMCAPS_CLIP
;
1209 caps1
->bClipping
= TRUE
;
1210 caps1
->dlcLightingCaps
.dwSize
= sizeof(caps1
->dlcLightingCaps
);
1211 caps1
->dlcLightingCaps
.dwCaps
= D3DLIGHTCAPS_DIRECTIONAL
1212 | D3DLIGHTCAPS_PARALLELPOINT
1213 | D3DLIGHTCAPS_POINT
1214 | D3DLIGHTCAPS_SPOT
;
1215 caps1
->dlcLightingCaps
.dwLightingModel
= D3DLIGHTINGMODEL_RGB
;
1216 caps1
->dlcLightingCaps
.dwNumLights
= caps7
->dwMaxActiveLights
;
1217 caps1
->dpcLineCaps
= caps7
->dpcLineCaps
;
1218 caps1
->dpcTriCaps
= caps7
->dpcTriCaps
;
1219 caps1
->dwDeviceRenderBitDepth
= caps7
->dwDeviceRenderBitDepth
;
1220 caps1
->dwDeviceZBufferBitDepth
= caps7
->dwDeviceZBufferBitDepth
;
1221 caps1
->dwMaxBufferSize
= 0;
1222 caps1
->dwMaxVertexCount
= 65536;
1223 caps1
->dwMinTextureWidth
= caps7
->dwMinTextureWidth
;
1224 caps1
->dwMinTextureHeight
= caps7
->dwMinTextureHeight
;
1225 caps1
->dwMaxTextureWidth
= caps7
->dwMaxTextureWidth
;
1226 caps1
->dwMaxTextureHeight
= caps7
->dwMaxTextureHeight
;
1227 caps1
->dwMinStippleWidth
= 1;
1228 caps1
->dwMinStippleHeight
= 1;
1229 caps1
->dwMaxStippleWidth
= 32;
1230 caps1
->dwMaxStippleHeight
= 32;
1231 caps1
->dwMaxTextureRepeat
= caps7
->dwMaxTextureRepeat
;
1232 caps1
->dwMaxTextureAspectRatio
= caps7
->dwMaxTextureAspectRatio
;
1233 caps1
->dwMaxAnisotropy
= caps7
->dwMaxAnisotropy
;
1234 caps1
->dvGuardBandLeft
= caps7
->dvGuardBandLeft
;
1235 caps1
->dvGuardBandTop
= caps7
->dvGuardBandTop
;
1236 caps1
->dvGuardBandRight
= caps7
->dvGuardBandRight
;
1237 caps1
->dvGuardBandBottom
= caps7
->dvGuardBandBottom
;
1238 caps1
->dvExtentsAdjust
= caps7
->dvExtentsAdjust
;
1239 caps1
->dwStencilCaps
= caps7
->dwStencilCaps
;
1240 caps1
->dwFVFCaps
= caps7
->dwFVFCaps
;
1241 caps1
->dwTextureOpCaps
= caps7
->dwTextureOpCaps
;
1242 caps1
->wMaxTextureBlendStages
= caps7
->wMaxTextureBlendStages
;
1243 caps1
->wMaxSimultaneousTextures
= caps7
->wMaxSimultaneousTextures
;
1246 HRESULT
ddraw_get_d3dcaps(const struct ddraw
*ddraw
, D3DDEVICEDESC7
*caps
)
1248 struct wined3d_caps wined3d_caps
;
1251 TRACE("ddraw %p, caps %p.\n", ddraw
, caps
);
1253 memset(&wined3d_caps
, 0, sizeof(wined3d_caps
));
1255 wined3d_mutex_lock();
1256 hr
= wined3d_get_device_caps(ddraw
->wined3d
, 0, WINED3D_DEVICE_TYPE_HAL
, &wined3d_caps
);
1257 wined3d_mutex_unlock();
1260 WARN("Failed to get device caps, hr %#x.\n", hr
);
1264 caps
->dwDevCaps
= wined3d_caps
.DevCaps
;
1265 caps
->dpcLineCaps
.dwMiscCaps
= wined3d_caps
.PrimitiveMiscCaps
;
1266 caps
->dpcLineCaps
.dwRasterCaps
= wined3d_caps
.RasterCaps
;
1267 caps
->dpcLineCaps
.dwZCmpCaps
= wined3d_caps
.ZCmpCaps
;
1268 caps
->dpcLineCaps
.dwSrcBlendCaps
= wined3d_caps
.SrcBlendCaps
;
1269 caps
->dpcLineCaps
.dwDestBlendCaps
= wined3d_caps
.DestBlendCaps
;
1270 caps
->dpcLineCaps
.dwAlphaCmpCaps
= wined3d_caps
.AlphaCmpCaps
;
1271 caps
->dpcLineCaps
.dwShadeCaps
= wined3d_caps
.ShadeCaps
;
1272 caps
->dpcLineCaps
.dwTextureCaps
= wined3d_caps
.TextureCaps
;
1273 caps
->dpcLineCaps
.dwTextureFilterCaps
= wined3d_caps
.TextureFilterCaps
;
1274 caps
->dpcLineCaps
.dwTextureAddressCaps
= wined3d_caps
.TextureAddressCaps
;
1276 caps
->dwMaxTextureWidth
= wined3d_caps
.MaxTextureWidth
;
1277 caps
->dwMaxTextureHeight
= wined3d_caps
.MaxTextureHeight
;
1279 caps
->dwMaxTextureRepeat
= wined3d_caps
.MaxTextureRepeat
;
1280 caps
->dwMaxTextureAspectRatio
= wined3d_caps
.MaxTextureAspectRatio
;
1281 caps
->dwMaxAnisotropy
= wined3d_caps
.MaxAnisotropy
;
1282 caps
->dvMaxVertexW
= wined3d_caps
.MaxVertexW
;
1284 caps
->dvGuardBandLeft
= wined3d_caps
.GuardBandLeft
;
1285 caps
->dvGuardBandTop
= wined3d_caps
.GuardBandTop
;
1286 caps
->dvGuardBandRight
= wined3d_caps
.GuardBandRight
;
1287 caps
->dvGuardBandBottom
= wined3d_caps
.GuardBandBottom
;
1289 caps
->dvExtentsAdjust
= wined3d_caps
.ExtentsAdjust
;
1290 caps
->dwStencilCaps
= wined3d_caps
.StencilCaps
;
1292 caps
->dwFVFCaps
= wined3d_caps
.FVFCaps
;
1293 caps
->dwTextureOpCaps
= wined3d_caps
.TextureOpCaps
;
1295 caps
->dwVertexProcessingCaps
= wined3d_caps
.VertexProcessingCaps
;
1296 caps
->dwMaxActiveLights
= wined3d_caps
.MaxActiveLights
;
1298 /* Remove all non-d3d7 caps */
1299 caps
->dwDevCaps
&= (
1300 D3DDEVCAPS_FLOATTLVERTEX
| D3DDEVCAPS_SORTINCREASINGZ
| D3DDEVCAPS_SORTDECREASINGZ
|
1301 D3DDEVCAPS_SORTEXACT
| D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
|
1302 D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
| D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
|
1303 D3DDEVCAPS_TEXTUREVIDEOMEMORY
| D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
|
1304 D3DDEVCAPS_TEXTURENONLOCALVIDMEM
| D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
1305 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
1306 D3DDEVCAPS_HWRASTERIZATION
);
1308 caps
->dwStencilCaps
&= (
1309 D3DSTENCILCAPS_KEEP
| D3DSTENCILCAPS_ZERO
| D3DSTENCILCAPS_REPLACE
|
1310 D3DSTENCILCAPS_INCRSAT
| D3DSTENCILCAPS_DECRSAT
| D3DSTENCILCAPS_INVERT
|
1311 D3DSTENCILCAPS_INCR
| D3DSTENCILCAPS_DECR
);
1315 caps
->dwTextureOpCaps
&= (
1316 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_SELECTARG2
|
1317 D3DTEXOPCAPS_MODULATE
| D3DTEXOPCAPS_MODULATE2X
| D3DTEXOPCAPS_MODULATE4X
|
1318 D3DTEXOPCAPS_ADD
| D3DTEXOPCAPS_ADDSIGNED
| D3DTEXOPCAPS_ADDSIGNED2X
|
1319 D3DTEXOPCAPS_SUBTRACT
| D3DTEXOPCAPS_ADDSMOOTH
| D3DTEXOPCAPS_BLENDTEXTUREALPHA
|
1320 D3DTEXOPCAPS_BLENDFACTORALPHA
| D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
| D3DTEXOPCAPS_BLENDCURRENTALPHA
|
1321 D3DTEXOPCAPS_PREMODULATE
| D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
|
1322 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
| D3DTEXOPCAPS_BUMPENVMAP
|
1323 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
| D3DTEXOPCAPS_DOTPRODUCT3
);
1325 caps
->dwVertexProcessingCaps
&= (
1326 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_VERTEXFOG
|
1327 D3DVTXPCAPS_DIRECTIONALLIGHTS
| D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
);
1329 caps
->dpcLineCaps
.dwMiscCaps
&= (
1330 D3DPMISCCAPS_MASKPLANES
| D3DPMISCCAPS_MASKZ
| D3DPMISCCAPS_LINEPATTERNREP
|
1331 D3DPMISCCAPS_CONFORMANT
| D3DPMISCCAPS_CULLNONE
| D3DPMISCCAPS_CULLCW
|
1332 D3DPMISCCAPS_CULLCCW
);
1334 caps
->dpcLineCaps
.dwRasterCaps
&= (
1335 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ROP2
| D3DPRASTERCAPS_XOR
|
1336 D3DPRASTERCAPS_PAT
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_SUBPIXEL
|
1337 D3DPRASTERCAPS_SUBPIXELX
| D3DPRASTERCAPS_FOGVERTEX
| D3DPRASTERCAPS_FOGTABLE
|
1338 D3DPRASTERCAPS_STIPPLE
| D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT
| D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT
|
1339 D3DPRASTERCAPS_ANTIALIASEDGES
| D3DPRASTERCAPS_MIPMAPLODBIAS
| D3DPRASTERCAPS_ZBIAS
|
1340 D3DPRASTERCAPS_ZBUFFERLESSHSR
| D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
|
1341 D3DPRASTERCAPS_WBUFFER
| D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT
| D3DPRASTERCAPS_WFOG
|
1342 D3DPRASTERCAPS_ZFOG
);
1344 caps
->dpcLineCaps
.dwZCmpCaps
&= (
1345 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
1346 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
1347 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
1349 caps
->dpcLineCaps
.dwSrcBlendCaps
&= (
1350 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
1351 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
1352 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
1353 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
1354 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
1356 caps
->dpcLineCaps
.dwDestBlendCaps
&= (
1357 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
1358 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
1359 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
1360 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
1361 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
1363 caps
->dpcLineCaps
.dwAlphaCmpCaps
&= (
1364 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
1365 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
1366 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
1368 caps
->dpcLineCaps
.dwShadeCaps
&= (
1369 D3DPSHADECAPS_COLORFLATMONO
| D3DPSHADECAPS_COLORFLATRGB
| D3DPSHADECAPS_COLORGOURAUDMONO
|
1370 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_COLORPHONGMONO
| D3DPSHADECAPS_COLORPHONGRGB
|
1371 D3DPSHADECAPS_SPECULARFLATMONO
| D3DPSHADECAPS_SPECULARFLATRGB
| D3DPSHADECAPS_SPECULARGOURAUDMONO
|
1372 D3DPSHADECAPS_SPECULARGOURAUDRGB
| D3DPSHADECAPS_SPECULARPHONGMONO
| D3DPSHADECAPS_SPECULARPHONGRGB
|
1373 D3DPSHADECAPS_ALPHAFLATBLEND
| D3DPSHADECAPS_ALPHAFLATSTIPPLED
| D3DPSHADECAPS_ALPHAGOURAUDBLEND
|
1374 D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED
| D3DPSHADECAPS_ALPHAPHONGBLEND
| D3DPSHADECAPS_ALPHAPHONGSTIPPLED
|
1375 D3DPSHADECAPS_FOGFLAT
| D3DPSHADECAPS_FOGGOURAUD
| D3DPSHADECAPS_FOGPHONG
);
1377 caps
->dpcLineCaps
.dwTextureCaps
&= (
1378 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
1379 D3DPTEXTURECAPS_TRANSPARENCY
| D3DPTEXTURECAPS_BORDER
| D3DPTEXTURECAPS_SQUAREONLY
|
1380 D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
| D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
1381 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_COLORKEYBLEND
);
1383 caps
->dpcLineCaps
.dwTextureFilterCaps
&= (
1384 D3DPTFILTERCAPS_NEAREST
| D3DPTFILTERCAPS_LINEAR
| D3DPTFILTERCAPS_MIPNEAREST
|
1385 D3DPTFILTERCAPS_MIPLINEAR
| D3DPTFILTERCAPS_LINEARMIPNEAREST
| D3DPTFILTERCAPS_LINEARMIPLINEAR
|
1386 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
1387 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
1388 D3DPTFILTERCAPS_MAGFLINEAR
| D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
|
1389 D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
);
1391 caps
->dpcLineCaps
.dwTextureAddressCaps
&= (
1392 D3DPTADDRESSCAPS_WRAP
| D3DPTADDRESSCAPS_MIRROR
| D3DPTADDRESSCAPS_CLAMP
|
1393 D3DPTADDRESSCAPS_BORDER
| D3DPTADDRESSCAPS_INDEPENDENTUV
);
1395 if (!(caps
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
))
1397 /* DirectX7 always has the np2 flag set, no matter what the card
1398 * supports. Some old games (Rollcage) check the caps incorrectly.
1399 * If wined3d supports nonpow2 textures it also has np2 conditional
1401 caps
->dpcLineCaps
.dwTextureCaps
|= D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
;
1404 /* Fill the missing members, and do some fixup */
1405 caps
->dpcLineCaps
.dwSize
= sizeof(caps
->dpcLineCaps
);
1406 caps
->dpcLineCaps
.dwTextureBlendCaps
= D3DPTBLENDCAPS_ADD
1407 | D3DPTBLENDCAPS_MODULATEMASK
1408 | D3DPTBLENDCAPS_COPY
1409 | D3DPTBLENDCAPS_DECAL
1410 | D3DPTBLENDCAPS_DECALALPHA
1411 | D3DPTBLENDCAPS_DECALMASK
1412 | D3DPTBLENDCAPS_MODULATE
1413 | D3DPTBLENDCAPS_MODULATEALPHA
;
1414 caps
->dpcLineCaps
.dwStippleWidth
= 32;
1415 caps
->dpcLineCaps
.dwStippleHeight
= 32;
1416 /* Use the same for the TriCaps */
1417 caps
->dpcTriCaps
= caps
->dpcLineCaps
;
1419 caps
->dwDeviceRenderBitDepth
= DDBD_16
| DDBD_24
| DDBD_32
;
1420 caps
->dwDeviceZBufferBitDepth
= DDBD_16
| DDBD_24
;
1421 caps
->dwMinTextureWidth
= 1;
1422 caps
->dwMinTextureHeight
= 1;
1424 /* Convert DWORDs safely to WORDs */
1425 caps
->wMaxTextureBlendStages
= min(wined3d_caps
.MaxTextureBlendStages
, 0xffff);
1426 caps
->wMaxSimultaneousTextures
= min(wined3d_caps
.MaxSimultaneousTextures
, 0xffff);
1427 caps
->wMaxUserClipPlanes
= min(wined3d_caps
.MaxUserClipPlanes
, D3DMAXUSERCLIPPLANES
);
1428 caps
->wMaxVertexBlendMatrices
= min(wined3d_caps
.MaxVertexBlendMatrices
, 0xffff);
1430 caps
->deviceGUID
= IID_IDirect3DTnLHalDevice
;
1432 caps
->dwReserved1
= 0;
1433 caps
->dwReserved2
= 0;
1434 caps
->dwReserved3
= 0;
1435 caps
->dwReserved4
= 0;
1440 /*****************************************************************************
1441 * IDirectDraw7::GetCaps
1443 * Returns the drives capabilities
1445 * Used for version 1, 2, 4 and 7
1448 * DriverCaps: Structure to write the Hardware accelerated caps to
1449 * HelCaps: Structure to write the emulation caps to
1452 * This implementation returns DD_OK only
1454 *****************************************************************************/
1455 static HRESULT WINAPI
ddraw7_GetCaps(IDirectDraw7
*iface
, DDCAPS
*DriverCaps
, DDCAPS
*HELCaps
)
1457 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1458 DDSCAPS2 ddscaps
= {0, 0, 0, {0}};
1459 struct wined3d_caps winecaps
;
1463 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, DriverCaps
, HELCaps
);
1465 /* One structure must be != NULL */
1466 if (!DriverCaps
&& !HELCaps
)
1468 WARN("Invalid parameters.\n");
1469 return DDERR_INVALIDPARAMS
;
1472 memset(&caps
, 0, sizeof(caps
));
1473 memset(&winecaps
, 0, sizeof(winecaps
));
1474 caps
.dwSize
= sizeof(caps
);
1476 wined3d_mutex_lock();
1477 hr
= wined3d_device_get_device_caps(ddraw
->wined3d_device
, &winecaps
);
1480 WARN("Failed to get device caps, %#x.\n", hr
);
1481 wined3d_mutex_unlock();
1485 hr
= IDirectDraw7_GetAvailableVidMem(iface
, &ddscaps
, &caps
.dwVidMemTotal
, &caps
.dwVidMemFree
);
1488 WARN("IDirectDraw7::GetAvailableVidMem failed\n");
1489 wined3d_mutex_unlock();
1493 hr
= IDirectDraw7_GetFourCCCodes(iface
, &caps
.dwNumFourCCCodes
, NULL
);
1494 wined3d_mutex_unlock();
1497 WARN("IDirectDraw7::GetFourCCCodes failed\n");
1501 caps
.dwCaps
= winecaps
.ddraw_caps
.caps
;
1502 caps
.dwCaps2
= winecaps
.ddraw_caps
.caps2
;
1503 caps
.dwCKeyCaps
= winecaps
.ddraw_caps
.color_key_caps
;
1504 caps
.dwFXCaps
= winecaps
.ddraw_caps
.fx_caps
;
1505 caps
.dwPalCaps
= DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
;
1506 caps
.ddsCaps
.dwCaps
= winecaps
.ddraw_caps
.dds_caps
;
1507 caps
.dwSVBCaps
= winecaps
.ddraw_caps
.svb_caps
;
1508 caps
.dwSVBCKeyCaps
= winecaps
.ddraw_caps
.svb_color_key_caps
;
1509 caps
.dwSVBFXCaps
= winecaps
.ddraw_caps
.svb_fx_caps
;
1510 caps
.dwVSBCaps
= winecaps
.ddraw_caps
.vsb_caps
;
1511 caps
.dwVSBCKeyCaps
= winecaps
.ddraw_caps
.vsb_color_key_caps
;
1512 caps
.dwVSBFXCaps
= winecaps
.ddraw_caps
.vsb_fx_caps
;
1513 caps
.dwSSBCaps
= winecaps
.ddraw_caps
.ssb_caps
;
1514 caps
.dwSSBCKeyCaps
= winecaps
.ddraw_caps
.ssb_color_key_caps
;
1515 caps
.dwSSBFXCaps
= winecaps
.ddraw_caps
.ssb_fx_caps
;
1517 caps
.dwCaps
|= DDCAPS_ALIGNSTRIDE
;
1518 caps
.dwAlignStrideAlign
= DDRAW_STRIDE_ALIGNMENT
;
1522 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &caps
);
1523 if (TRACE_ON(ddraw
))
1525 TRACE("Driver Caps :\n");
1526 DDRAW_dump_DDCAPS(DriverCaps
);
1532 DD_STRUCT_COPY_BYSIZE(HELCaps
, &caps
);
1533 if (TRACE_ON(ddraw
))
1535 TRACE("HEL Caps :\n");
1536 DDRAW_dump_DDCAPS(HELCaps
);
1543 static HRESULT WINAPI
ddraw4_GetCaps(IDirectDraw4
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1545 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1547 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1549 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1552 static HRESULT WINAPI
ddraw2_GetCaps(IDirectDraw2
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1554 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1556 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1558 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1561 static HRESULT WINAPI
ddraw1_GetCaps(IDirectDraw
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1563 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1565 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1567 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1570 /*****************************************************************************
1571 * IDirectDraw7::Compact
1573 * No idea what it does, MSDN says it's not implemented.
1576 * DD_OK, but this is unchecked
1578 *****************************************************************************/
1579 static HRESULT WINAPI
ddraw7_Compact(IDirectDraw7
*iface
)
1581 TRACE("iface %p.\n", iface
);
1586 static HRESULT WINAPI
ddraw4_Compact(IDirectDraw4
*iface
)
1588 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1590 TRACE("iface %p.\n", iface
);
1592 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1595 static HRESULT WINAPI
ddraw2_Compact(IDirectDraw2
*iface
)
1597 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1599 TRACE("iface %p.\n", iface
);
1601 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1604 static HRESULT WINAPI
ddraw1_Compact(IDirectDraw
*iface
)
1606 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1608 TRACE("iface %p.\n", iface
);
1610 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1613 /*****************************************************************************
1614 * IDirectDraw7::GetDisplayMode
1616 * Returns information about the current display mode
1618 * Exists in versions 1, 2, 4 and 7
1621 * DDSD: Address of a surface description structure to write the info to
1626 *****************************************************************************/
1627 static HRESULT WINAPI
ddraw7_GetDisplayMode(IDirectDraw7
*iface
, DDSURFACEDESC2
*DDSD
)
1629 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1630 struct wined3d_display_mode mode
;
1633 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
1635 /* This seems sane */
1636 if (!DDSD
|| (DDSD
->dwSize
!= sizeof(DDSURFACEDESC
) && DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
)))
1637 return DDERR_INVALIDPARAMS
;
1639 wined3d_mutex_lock();
1641 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1643 ERR("Failed to get display mode, hr %#x.\n", hr
);
1644 wined3d_mutex_unlock();
1648 memset(DDSD
, 0, DDSD
->dwSize
);
1649 DDSD
->dwSize
= sizeof(*DDSD
);
1650 DDSD
->dwFlags
= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
1651 DDSD
->dwWidth
= mode
.width
;
1652 DDSD
->dwHeight
= mode
.height
;
1653 DDSD
->u2
.dwRefreshRate
= 60;
1654 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
1655 ddrawformat_from_wined3dformat(&DDSD
->u4
.ddpfPixelFormat
, mode
.format_id
);
1656 DDSD
->u1
.lPitch
= mode
.width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
1660 TRACE("Returning surface desc :\n");
1661 DDRAW_dump_surface_desc(DDSD
);
1664 wined3d_mutex_unlock();
1669 static HRESULT WINAPI
ddraw4_GetDisplayMode(IDirectDraw4
*iface
, DDSURFACEDESC2
*surface_desc
)
1671 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1673 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1675 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, surface_desc
);
1678 static HRESULT WINAPI
ddraw2_GetDisplayMode(IDirectDraw2
*iface
, DDSURFACEDESC
*surface_desc
)
1680 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1683 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1685 hr
= ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1686 if (SUCCEEDED(hr
)) surface_desc
->dwSize
= sizeof(*surface_desc
);
1690 static HRESULT WINAPI
ddraw1_GetDisplayMode(IDirectDraw
*iface
, DDSURFACEDESC
*surface_desc
)
1692 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1695 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1697 hr
= ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1698 if (SUCCEEDED(hr
)) surface_desc
->dwSize
= sizeof(*surface_desc
);
1702 /*****************************************************************************
1703 * IDirectDraw7::GetFourCCCodes
1705 * Returns an array of supported FourCC codes.
1707 * Exists in versions 1, 2, 4 and 7
1710 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
1711 * of enumerated codes
1712 * Codes: Pointer to an array of DWORDs where the supported codes are written
1716 * Always returns DD_OK, as it's a stub for now
1718 *****************************************************************************/
1719 static HRESULT WINAPI
ddraw7_GetFourCCCodes(IDirectDraw7
*iface
, DWORD
*NumCodes
, DWORD
*Codes
)
1721 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1722 static const enum wined3d_format_id formats
[] =
1724 WINED3DFMT_YUY2
, WINED3DFMT_UYVY
, WINED3DFMT_YV12
,
1725 WINED3DFMT_DXT1
, WINED3DFMT_DXT2
, WINED3DFMT_DXT3
, WINED3DFMT_DXT4
, WINED3DFMT_DXT5
,
1726 WINED3DFMT_ATI2N
, WINED3DFMT_NVHU
, WINED3DFMT_NVHS
1728 struct wined3d_display_mode mode
;
1729 DWORD count
= 0, i
, outsize
;
1732 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, NumCodes
, Codes
);
1734 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1736 ERR("Failed to get display mode, hr %#x.\n", hr
);
1740 outsize
= NumCodes
&& Codes
? *NumCodes
: 0;
1742 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
)
1744 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, WINED3D_DEVICE_TYPE_HAL
,
1745 mode
.format_id
, 0, 0, WINED3D_RTYPE_TEXTURE_2D
, formats
[i
])))
1747 if (count
< outsize
)
1748 Codes
[count
] = formats
[i
];
1753 TRACE("Returning %u FourCC codes\n", count
);
1760 static HRESULT WINAPI
ddraw4_GetFourCCCodes(IDirectDraw4
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1762 struct ddraw
*ddraw
= impl_from_IDirectDraw4(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
ddraw2_GetFourCCCodes(IDirectDraw2
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1771 struct ddraw
*ddraw
= impl_from_IDirectDraw2(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
ddraw1_GetFourCCCodes(IDirectDraw
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1780 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1782 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1784 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1787 static HRESULT WINAPI
ddraw7_GetMonitorFrequency(IDirectDraw7
*iface
, DWORD
*frequency
)
1789 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1790 struct wined3d_display_mode mode
;
1793 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1795 wined3d_mutex_lock();
1796 hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
);
1797 wined3d_mutex_unlock();
1800 WARN("Failed to get display mode, hr %#x.\n", hr
);
1804 *frequency
= mode
.refresh_rate
;
1809 static HRESULT WINAPI
ddraw4_GetMonitorFrequency(IDirectDraw4
*iface
, DWORD
*frequency
)
1811 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1813 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1815 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1818 static HRESULT WINAPI
ddraw2_GetMonitorFrequency(IDirectDraw2
*iface
, DWORD
*frequency
)
1820 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1822 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1824 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1827 static HRESULT WINAPI
ddraw1_GetMonitorFrequency(IDirectDraw
*iface
, DWORD
*frequency
)
1829 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1831 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1833 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1836 static HRESULT WINAPI
ddraw7_GetVerticalBlankStatus(IDirectDraw7
*iface
, BOOL
*status
)
1838 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1839 struct wined3d_raster_status raster_status
;
1842 TRACE("iface %p, status %p.\n", iface
, status
);
1845 return DDERR_INVALIDPARAMS
;
1847 wined3d_mutex_lock();
1848 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
1849 wined3d_mutex_unlock();
1852 WARN("Failed to get raster status, hr %#x.\n", hr
);
1856 *status
= raster_status
.in_vblank
;
1861 static HRESULT WINAPI
ddraw4_GetVerticalBlankStatus(IDirectDraw4
*iface
, BOOL
*status
)
1863 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1865 TRACE("iface %p, status %p.\n", iface
, status
);
1867 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1870 static HRESULT WINAPI
ddraw2_GetVerticalBlankStatus(IDirectDraw2
*iface
, BOOL
*status
)
1872 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1874 TRACE("iface %p, status %p.\n", iface
, status
);
1876 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1879 static HRESULT WINAPI
ddraw1_GetVerticalBlankStatus(IDirectDraw
*iface
, BOOL
*status
)
1881 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1883 TRACE("iface %p, status %p.\n", iface
, status
);
1885 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1888 /*****************************************************************************
1889 * IDirectDraw7::GetAvailableVidMem
1891 * Returns the total and free video memory
1894 * caps: Specifies the memory type asked for
1895 * total: Pointer to a DWORD to be filled with the total memory
1896 * free: Pointer to a DWORD to be filled with the free memory
1900 * DDERR_INVALIDPARAMS if free and total are NULL
1902 *****************************************************************************/
1903 static HRESULT WINAPI
ddraw7_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*caps
, DWORD
*total
,
1906 unsigned int framebuffer_size
, total_vidmem
, free_vidmem
;
1907 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1908 struct wined3d_display_mode mode
;
1911 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1913 if (!total
&& !free
)
1914 return DDERR_INVALIDPARAMS
;
1916 if (TRACE_ON(ddraw
))
1918 TRACE("Asked for memory with description: ");
1919 DDRAW_dump_DDSCAPS2(caps
);
1921 wined3d_mutex_lock();
1923 /* Todo: System memory vs local video memory vs non-local video memory
1924 * The MSDN also mentions differences between texture memory and other
1925 * resources, but that's not important
1928 /* Some applications (e.g. 3DMark 2000) assume that the reported amount of
1929 * video memory doesn't include the memory used by the default framebuffer.
1931 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1933 WARN("Failed to get display mode, hr %#x.\n", hr
);
1934 wined3d_mutex_unlock();
1937 framebuffer_size
= wined3d_calculate_format_pitch(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
1938 mode
.format_id
, mode
.width
);
1939 framebuffer_size
*= mode
.height
;
1943 free_vidmem
= wined3d_device_get_available_texture_mem(ddraw
->wined3d_device
);
1944 *free
= framebuffer_size
> free_vidmem
? 0 : free_vidmem
- framebuffer_size
;
1945 TRACE("Free video memory %#x.\n", *free
);
1950 struct wined3d_adapter_identifier desc
= {0};
1952 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0, &desc
);
1953 total_vidmem
= min(UINT_MAX
, desc
.video_memory
);
1954 *total
= framebuffer_size
> total_vidmem
? 0 : total_vidmem
- framebuffer_size
;
1955 TRACE("Total video memory %#x.\n", *total
);
1958 wined3d_mutex_unlock();
1963 static HRESULT WINAPI
ddraw4_GetAvailableVidMem(IDirectDraw4
*iface
,
1964 DDSCAPS2
*caps
, DWORD
*total
, DWORD
*free
)
1966 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1968 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1970 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, caps
, total
, free
);
1973 static HRESULT WINAPI
ddraw2_GetAvailableVidMem(IDirectDraw2
*iface
,
1974 DDSCAPS
*caps
, DWORD
*total
, DWORD
*free
)
1976 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1979 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1981 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
1982 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, &caps2
, total
, free
);
1985 /*****************************************************************************
1986 * IDirectDraw7::Initialize
1988 * Initializes a DirectDraw interface.
1991 * GUID: Interface identifier. Well, don't know what this is really good
1995 * Returns DD_OK on the first call,
1996 * DDERR_ALREADYINITIALIZED on repeated calls
1998 *****************************************************************************/
1999 static HRESULT WINAPI
ddraw7_Initialize(IDirectDraw7
*iface
, GUID
*guid
)
2001 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2003 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2005 if (ddraw
->flags
& DDRAW_INITIALIZED
)
2006 return DDERR_ALREADYINITIALIZED
;
2008 /* FIXME: To properly take the GUID into account we should call
2009 * ddraw_init() here instead of in DDRAW_Create(). */
2011 FIXME("Ignoring guid %s.\n", debugstr_guid(guid
));
2013 ddraw
->flags
|= DDRAW_INITIALIZED
;
2017 static HRESULT WINAPI
ddraw4_Initialize(IDirectDraw4
*iface
, GUID
*guid
)
2019 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2021 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2023 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2026 static HRESULT WINAPI
ddraw2_Initialize(IDirectDraw2
*iface
, GUID
*guid
)
2028 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2030 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2032 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2035 static HRESULT WINAPI
ddraw1_Initialize(IDirectDraw
*iface
, GUID
*guid
)
2037 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2039 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2041 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2044 static HRESULT WINAPI
d3d1_Initialize(IDirect3D
*iface
, REFIID riid
)
2046 TRACE("iface %p, riid %s.\n", iface
, debugstr_guid(riid
));
2048 return DDERR_ALREADYINITIALIZED
;
2051 /*****************************************************************************
2052 * IDirectDraw7::FlipToGDISurface
2054 * "Makes the surface that the GDI writes to the primary surface"
2055 * Looks like some windows specific thing we don't have to care about.
2056 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
2057 * show error boxes ;)
2058 * Well, just return DD_OK.
2061 * Always returns DD_OK
2063 *****************************************************************************/
2064 static HRESULT WINAPI
ddraw7_FlipToGDISurface(IDirectDraw7
*iface
)
2066 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2067 IDirectDrawSurface7
*gdi_surface
;
2068 struct ddraw_surface
*gdi_impl
;
2071 TRACE("iface %p.\n", iface
);
2073 wined3d_mutex_lock();
2075 if (FAILED(hr
= IDirectDraw7_GetGDISurface(iface
, &gdi_surface
)))
2077 WARN("Failed to retrieve GDI surface, hr %#x.\n", hr
);
2078 wined3d_mutex_unlock();
2082 gdi_impl
= impl_from_IDirectDrawSurface7(gdi_surface
);
2083 if (gdi_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
2086 hr
= IDirectDrawSurface7_Flip(&ddraw
->primary
->IDirectDrawSurface7_iface
, gdi_surface
, DDFLIP_WAIT
);
2087 IDirectDrawSurface7_Release(gdi_surface
);
2089 wined3d_mutex_unlock();
2094 static HRESULT WINAPI
ddraw4_FlipToGDISurface(IDirectDraw4
*iface
)
2096 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2098 TRACE("iface %p.\n", iface
);
2100 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2103 static HRESULT WINAPI
ddraw2_FlipToGDISurface(IDirectDraw2
*iface
)
2105 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2107 TRACE("iface %p.\n", iface
);
2109 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2112 static HRESULT WINAPI
ddraw1_FlipToGDISurface(IDirectDraw
*iface
)
2114 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2116 TRACE("iface %p.\n", iface
);
2118 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2121 /*****************************************************************************
2122 * IDirectDraw7::WaitForVerticalBlank
2124 * This method allows applications to get in sync with the vertical blank
2126 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
2127 * redraw the screen, most likely because of this stub
2130 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
2131 * or DDWAITVB_BLOCKEND
2132 * h: Not used, according to MSDN
2135 * Always returns DD_OK
2137 *****************************************************************************/
2138 static HRESULT WINAPI
ddraw7_WaitForVerticalBlank(IDirectDraw7
*iface
, DWORD Flags
, HANDLE event
)
2142 TRACE("iface %p, flags %#x, event %p.\n", iface
, Flags
, event
);
2144 /* This function is called often, so print the fixme only once */
2147 FIXME("iface %p, flags %#x, event %p stub!\n", iface
, Flags
, event
);
2151 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
2152 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
2153 return DDERR_UNSUPPORTED
; /* unchecked */
2158 static HRESULT WINAPI
ddraw4_WaitForVerticalBlank(IDirectDraw4
*iface
, DWORD flags
, HANDLE event
)
2160 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2162 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2164 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2167 static HRESULT WINAPI
ddraw2_WaitForVerticalBlank(IDirectDraw2
*iface
, DWORD flags
, HANDLE event
)
2169 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2171 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2173 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2176 static HRESULT WINAPI
ddraw1_WaitForVerticalBlank(IDirectDraw
*iface
, DWORD flags
, HANDLE event
)
2178 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2180 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2182 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2185 static HRESULT WINAPI
ddraw7_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
2187 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2188 struct wined3d_raster_status raster_status
;
2191 TRACE("iface %p, line %p.\n", iface
, Scanline
);
2193 wined3d_mutex_lock();
2194 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
2195 wined3d_mutex_unlock();
2198 WARN("Failed to get raster status, hr %#x.\n", hr
);
2202 *Scanline
= raster_status
.scan_line
;
2204 if (raster_status
.in_vblank
)
2205 return DDERR_VERTICALBLANKINPROGRESS
;
2210 static HRESULT WINAPI
ddraw4_GetScanLine(IDirectDraw4
*iface
, DWORD
*line
)
2212 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2214 TRACE("iface %p, line %p.\n", iface
, line
);
2216 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2219 static HRESULT WINAPI
ddraw2_GetScanLine(IDirectDraw2
*iface
, DWORD
*line
)
2221 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2223 TRACE("iface %p, line %p.\n", iface
, line
);
2225 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2228 static HRESULT WINAPI
ddraw1_GetScanLine(IDirectDraw
*iface
, DWORD
*line
)
2230 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2232 TRACE("iface %p, line %p.\n", iface
, line
);
2234 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2237 static HRESULT WINAPI
ddraw7_TestCooperativeLevel(IDirectDraw7
*iface
)
2239 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2241 TRACE("iface %p.\n", iface
);
2243 return ddraw
->device_state
== DDRAW_DEVICE_STATE_LOST
? DDERR_NOEXCLUSIVEMODE
: DD_OK
;
2246 static HRESULT WINAPI
ddraw4_TestCooperativeLevel(IDirectDraw4
*iface
)
2248 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2250 TRACE("iface %p.\n", iface
);
2252 return ddraw7_TestCooperativeLevel(&ddraw
->IDirectDraw7_iface
);
2255 /*****************************************************************************
2256 * IDirectDraw7::GetGDISurface
2258 * Returns the surface that GDI is treating as the primary surface.
2259 * For Wine this is the front buffer
2262 * GDISurface: Address to write the surface pointer to
2265 * DD_OK if the surface was found
2266 * DDERR_NOTFOUND if the GDI surface wasn't found
2268 *****************************************************************************/
2269 static HRESULT WINAPI
ddraw7_GetGDISurface(IDirectDraw7
*iface
, IDirectDrawSurface7
**surface
)
2271 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2272 struct ddraw_surface
*ddraw_surface
;
2274 TRACE("iface %p, surface %p.\n", iface
, surface
);
2276 wined3d_mutex_lock();
2278 if (!ddraw
->gdi_surface
|| !(ddraw_surface
= wined3d_texture_get_sub_resource_parent(ddraw
->gdi_surface
, 0)))
2280 WARN("GDI surface not available.\n");
2282 wined3d_mutex_unlock();
2283 return DDERR_NOTFOUND
;
2285 *surface
= &ddraw_surface
->IDirectDrawSurface7_iface
;
2286 IDirectDrawSurface7_AddRef(*surface
);
2288 wined3d_mutex_unlock();
2293 static HRESULT WINAPI
ddraw4_GetGDISurface(IDirectDraw4
*iface
, IDirectDrawSurface4
**surface
)
2295 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2296 struct ddraw_surface
*surface_impl
;
2297 IDirectDrawSurface7
*surface7
;
2300 TRACE("iface %p, surface %p.\n", iface
, surface
);
2302 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2308 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2309 *surface
= &surface_impl
->IDirectDrawSurface4_iface
;
2310 IDirectDrawSurface4_AddRef(*surface
);
2311 IDirectDrawSurface7_Release(surface7
);
2316 static HRESULT WINAPI
ddraw2_GetGDISurface(IDirectDraw2
*iface
, IDirectDrawSurface
**surface
)
2318 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2319 struct ddraw_surface
*surface_impl
;
2320 IDirectDrawSurface7
*surface7
;
2323 TRACE("iface %p, surface %p.\n", iface
, surface
);
2325 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2331 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2332 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2333 IDirectDrawSurface_AddRef(*surface
);
2334 IDirectDrawSurface7_Release(surface7
);
2339 static HRESULT WINAPI
ddraw1_GetGDISurface(IDirectDraw
*iface
, IDirectDrawSurface
**surface
)
2341 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2342 struct ddraw_surface
*surface_impl
;
2343 IDirectDrawSurface7
*surface7
;
2346 TRACE("iface %p, surface %p.\n", iface
, surface
);
2348 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2354 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2355 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2356 IDirectDrawSurface_AddRef(*surface
);
2357 IDirectDrawSurface7_Release(surface7
);
2362 struct displaymodescallback_context
2364 LPDDENUMMODESCALLBACK func
;
2368 static HRESULT CALLBACK
EnumDisplayModesCallbackThunk(DDSURFACEDESC2
*surface_desc
, void *context
)
2370 struct displaymodescallback_context
*cbcontext
= context
;
2373 DDSD2_to_DDSD(surface_desc
, &desc
);
2374 return cbcontext
->func(&desc
, cbcontext
->context
);
2377 /*****************************************************************************
2378 * IDirectDraw7::EnumDisplayModes
2380 * Enumerates the supported Display modes. The modes can be filtered with
2381 * the DDSD parameter.
2384 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES. For old ddraw
2385 * versions (3 and older?) this is reserved and must be 0.
2386 * DDSD: Surface description to filter the modes
2387 * Context: Pointer passed back to the callback function
2388 * cb: Application-provided callback function
2392 * DDERR_INVALIDPARAMS if the callback wasn't set
2394 *****************************************************************************/
2395 static HRESULT WINAPI
ddraw7_EnumDisplayModes(IDirectDraw7
*iface
, DWORD Flags
,
2396 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMMODESCALLBACK2 cb
)
2398 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2399 struct wined3d_display_mode
*enum_modes
= NULL
;
2400 struct wined3d_display_mode mode
;
2401 unsigned int modenum
, fmt
;
2402 DDSURFACEDESC2 callback_sd
;
2403 unsigned enum_mode_count
= 0, enum_mode_array_size
= 16;
2404 DDPIXELFORMAT pixelformat
;
2406 static const enum wined3d_format_id checkFormatList
[] =
2408 WINED3DFMT_B8G8R8X8_UNORM
,
2409 WINED3DFMT_B5G6R5_UNORM
,
2413 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2414 iface
, Flags
, DDSD
, Context
, cb
);
2417 return DDERR_INVALIDPARAMS
;
2419 if (!(enum_modes
= heap_alloc(enum_mode_array_size
* sizeof(*enum_modes
))))
2420 return DDERR_OUTOFMEMORY
;
2422 wined3d_mutex_lock();
2424 pixelformat
.dwSize
= sizeof(pixelformat
);
2425 for(fmt
= 0; fmt
< ARRAY_SIZE(checkFormatList
); fmt
++)
2428 while (wined3d_enum_adapter_modes(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, checkFormatList
[fmt
],
2429 WINED3D_SCANLINE_ORDERING_UNKNOWN
, modenum
++, &mode
) == WINED3D_OK
)
2434 ddrawformat_from_wined3dformat(&pixelformat
, mode
.format_id
);
2437 if (DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.width
!= DDSD
->dwWidth
)
2439 if (DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.height
!= DDSD
->dwHeight
)
2441 if (DDSD
->dwFlags
& DDSD_REFRESHRATE
&& mode
.refresh_rate
!= DDSD
->u2
.dwRefreshRate
)
2443 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
2444 && pixelformat
.u1
.dwRGBBitCount
!= DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
)
2448 /* DX docs state EnumDisplayMode should return only unique modes */
2449 for (i
= 0; i
< enum_mode_count
; i
++)
2451 if (enum_modes
[i
].width
== mode
.width
&& enum_modes
[i
].height
== mode
.height
2452 && enum_modes
[i
].format_id
== mode
.format_id
2453 && (enum_modes
[i
].refresh_rate
== mode
.refresh_rate
|| !(Flags
& DDEDM_REFRESHRATES
)))
2461 memset(&callback_sd
, 0, sizeof(callback_sd
));
2462 callback_sd
.dwSize
= sizeof(callback_sd
);
2463 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2465 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
|DDSD_REFRESHRATE
;
2466 if (Flags
& DDEDM_REFRESHRATES
)
2467 callback_sd
.u2
.dwRefreshRate
= mode
.refresh_rate
;
2469 callback_sd
.dwWidth
= mode
.width
;
2470 callback_sd
.dwHeight
= mode
.height
;
2472 callback_sd
.u4
.ddpfPixelFormat
=pixelformat
;
2474 /* Calc pitch and DWORD align like MSDN says */
2475 callback_sd
.u1
.lPitch
= (callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8) * mode
.width
;
2476 callback_sd
.u1
.lPitch
= (callback_sd
.u1
.lPitch
+ 3) & ~3;
2478 TRACE("Enumerating %dx%dx%d @%d\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
,
2479 callback_sd
.u2
.dwRefreshRate
);
2481 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
2483 TRACE("Application asked to terminate the enumeration\n");
2484 heap_free(enum_modes
);
2485 wined3d_mutex_unlock();
2489 if (enum_mode_count
== enum_mode_array_size
)
2491 struct wined3d_display_mode
*new_enum_modes
;
2493 enum_mode_array_size
*= 2;
2494 if (!(new_enum_modes
= heap_realloc(enum_modes
, enum_mode_array_size
* sizeof(*new_enum_modes
))))
2496 heap_free(enum_modes
);
2497 wined3d_mutex_unlock();
2498 return DDERR_OUTOFMEMORY
;
2501 enum_modes
= new_enum_modes
;
2503 enum_modes
[enum_mode_count
++] = mode
;
2507 TRACE("End of enumeration\n");
2508 heap_free(enum_modes
);
2509 wined3d_mutex_unlock();
2514 static HRESULT WINAPI
ddraw4_EnumDisplayModes(IDirectDraw4
*iface
, DWORD flags
,
2515 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK2 callback
)
2517 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2519 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2520 iface
, flags
, surface_desc
, context
, callback
);
2522 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
, context
, callback
);
2525 static HRESULT WINAPI
ddraw2_EnumDisplayModes(IDirectDraw2
*iface
, DWORD flags
,
2526 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2528 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2529 struct displaymodescallback_context cbcontext
;
2530 DDSURFACEDESC2 surface_desc2
;
2532 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2533 iface
, flags
, surface_desc
, context
, callback
);
2535 cbcontext
.func
= callback
;
2536 cbcontext
.context
= context
;
2538 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2539 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2540 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2543 static HRESULT WINAPI
ddraw1_EnumDisplayModes(IDirectDraw
*iface
, DWORD flags
,
2544 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2546 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2547 struct displaymodescallback_context cbcontext
;
2548 DDSURFACEDESC2 surface_desc2
;
2550 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2551 iface
, flags
, surface_desc
, context
, callback
);
2553 cbcontext
.func
= callback
;
2554 cbcontext
.context
= context
;
2556 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2557 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2558 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2561 /*****************************************************************************
2562 * IDirectDraw7::EvaluateMode
2564 * Used with IDirectDraw7::StartModeTest to test video modes.
2565 * EvaluateMode is used to pass or fail a mode, and continue with the next
2569 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
2570 * Timeout: Returns the amount of seconds left before the mode would have
2571 * been failed automatically
2574 * This implementation always DD_OK, because it's a stub
2576 *****************************************************************************/
2577 static HRESULT WINAPI
ddraw7_EvaluateMode(IDirectDraw7
*iface
, DWORD Flags
, DWORD
*Timeout
)
2579 FIXME("iface %p, flags %#x, timeout %p stub!\n", iface
, Flags
, Timeout
);
2581 /* When implementing this, implement it in WineD3D */
2586 /*****************************************************************************
2587 * IDirectDraw7::GetDeviceIdentifier
2589 * Returns the device identifier, which gives information about the driver
2590 * Our device identifier is defined at the beginning of this file.
2593 * DDDI: Address for the returned structure
2594 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
2597 * On success it returns DD_OK
2598 * DDERR_INVALIDPARAMS if DDDI is NULL
2600 *****************************************************************************/
2601 static HRESULT WINAPI
ddraw7_GetDeviceIdentifier(IDirectDraw7
*iface
,
2602 DDDEVICEIDENTIFIER2
*DDDI
, DWORD Flags
)
2604 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2605 struct wined3d_adapter_identifier adapter_id
;
2608 TRACE("iface %p, device_identifier %p, flags %#x.\n", iface
, DDDI
, Flags
);
2611 return DDERR_INVALIDPARAMS
;
2613 if (Flags
& DDGDI_GETHOSTIDENTIFIER
)
2615 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
2616 * host adapter, if there's a secondary 3D adapter. This doesn't apply
2617 * to any modern hardware, nor is it interesting for Wine, so ignore it.
2618 * Size of DDDEVICEIDENTIFIER2 may be aligned to 8 bytes and thus 4
2619 * bytes too long. So only copy the relevant part of the structure
2622 memcpy(DDDI
, &deviceidentifier
, FIELD_OFFSET(DDDEVICEIDENTIFIER2
, dwWHQLLevel
) + sizeof(DWORD
));
2626 /* Drakan: Order of the Flame expects accurate D3D device information from ddraw */
2627 adapter_id
.driver
= DDDI
->szDriver
;
2628 adapter_id
.driver_size
= sizeof(DDDI
->szDriver
);
2629 adapter_id
.description
= DDDI
->szDescription
;
2630 adapter_id
.description_size
= sizeof(DDDI
->szDescription
);
2631 adapter_id
.device_name_size
= 0;
2632 wined3d_mutex_lock();
2633 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0x0, &adapter_id
);
2634 wined3d_mutex_unlock();
2635 if (FAILED(hr
)) return hr
;
2637 DDDI
->liDriverVersion
= adapter_id
.driver_version
;
2638 DDDI
->dwVendorId
= adapter_id
.vendor_id
;
2639 DDDI
->dwDeviceId
= adapter_id
.device_id
;
2640 DDDI
->dwSubSysId
= adapter_id
.subsystem_id
;
2641 DDDI
->dwRevision
= adapter_id
.revision
;
2642 DDDI
->guidDeviceIdentifier
= adapter_id
.device_identifier
;
2643 DDDI
->dwWHQLLevel
= adapter_id
.whql_level
;
2647 static HRESULT WINAPI
ddraw4_GetDeviceIdentifier(IDirectDraw4
*iface
,
2648 DDDEVICEIDENTIFIER
*identifier
, DWORD flags
)
2650 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2651 DDDEVICEIDENTIFIER2 identifier2
;
2654 TRACE("iface %p, identifier %p, flags %#x.\n", iface
, identifier
, flags
);
2656 hr
= ddraw7_GetDeviceIdentifier(&ddraw
->IDirectDraw7_iface
, &identifier2
, flags
);
2657 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&identifier2
, identifier
);
2662 /*****************************************************************************
2663 * IDirectDraw7::GetSurfaceFromDC
2665 * Returns the Surface for a GDI device context handle.
2666 * Is this related to IDirectDrawSurface::GetDC ???
2669 * hdc: hdc to return the surface for
2670 * Surface: Address to write the surface pointer to
2673 * Always returns DD_OK because it's a stub
2675 *****************************************************************************/
2676 static HRESULT WINAPI
ddraw7_GetSurfaceFromDC(IDirectDraw7
*iface
,
2677 HDC dc
, IDirectDrawSurface7
**surface
)
2679 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2680 struct ddraw_surface
*surface_impl
;
2682 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2685 return E_INVALIDARG
;
2690 wined3d_mutex_lock();
2691 LIST_FOR_EACH_ENTRY(surface_impl
, &ddraw
->surface_list
, struct ddraw_surface
, surface_list_entry
)
2693 if (surface_impl
->dc
!= dc
)
2696 TRACE("Found surface %p for dc %p.\n", surface_impl
, dc
);
2697 *surface
= &surface_impl
->IDirectDrawSurface7_iface
;
2698 IDirectDrawSurface7_AddRef(*surface
);
2699 wined3d_mutex_unlock();
2702 wined3d_mutex_unlock();
2705 TRACE("No surface found for dc %p.\n", dc
);
2707 return DDERR_NOTFOUND
;
2710 static HRESULT WINAPI
ddraw4_GetSurfaceFromDC(IDirectDraw4
*iface
, HDC dc
,
2711 IDirectDrawSurface4
**surface
)
2713 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2714 struct ddraw_surface
*surface_impl
;
2715 IDirectDrawSurface7
*surface7
;
2718 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2720 if (!surface
) return E_INVALIDARG
;
2722 hr
= ddraw7_GetSurfaceFromDC(&ddraw
->IDirectDraw7_iface
, dc
, &surface7
);
2728 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2729 /* Tests say this is true */
2730 *surface
= (IDirectDrawSurface4
*)&surface_impl
->IDirectDrawSurface_iface
;
2731 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2732 IDirectDrawSurface7_Release(surface7
);
2737 static HRESULT CALLBACK
restore_callback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
2739 IDirectDrawSurface_Restore(surface
);
2740 IDirectDrawSurface_Release(surface
);
2742 return DDENUMRET_OK
;
2745 static HRESULT WINAPI
ddraw7_RestoreAllSurfaces(IDirectDraw7
*iface
)
2747 TRACE("iface %p.\n", iface
);
2749 return IDirectDraw7_EnumSurfaces(iface
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
2750 NULL
, NULL
, restore_callback
);
2753 static HRESULT WINAPI
ddraw4_RestoreAllSurfaces(IDirectDraw4
*iface
)
2755 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2757 TRACE("iface %p.\n", iface
);
2759 return ddraw7_RestoreAllSurfaces(&ddraw
->IDirectDraw7_iface
);
2762 /*****************************************************************************
2763 * IDirectDraw7::StartModeTest
2765 * Tests the specified video modes to update the system registry with
2766 * refresh rate information. StartModeTest starts the mode test,
2767 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
2768 * isn't called within 15 seconds, the mode is failed automatically
2770 * As refresh rates are handled by the X server, I don't think this
2771 * Method is important
2774 * Modes: An array of mode specifications
2775 * NumModes: The number of modes in Modes
2776 * Flags: Some flags...
2779 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
2780 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
2783 *****************************************************************************/
2784 static HRESULT WINAPI
ddraw7_StartModeTest(IDirectDraw7
*iface
, SIZE
*Modes
, DWORD NumModes
, DWORD Flags
)
2786 FIXME("iface %p, modes %p, mode_count %u, flags %#x partial stub!\n",
2787 iface
, Modes
, NumModes
, Flags
);
2789 /* This looks sane */
2790 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
2792 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
2793 * As it is not, DDERR_TESTFINISHED is returned
2794 * (hopefully that's correct
2796 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
2797 * well, that value doesn't (yet) exist in the wine headers, so ignore it
2803 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
, DDSURFACEDESC2
*surface_desc
,
2804 IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
2806 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2807 struct ddraw_surface
*impl
;
2810 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2811 iface
, surface_desc
, surface
, outer_unknown
);
2813 wined3d_mutex_lock();
2815 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2817 WARN("Cooperative level not set.\n");
2818 wined3d_mutex_unlock();
2819 return DDERR_NOCOOPERATIVELEVELSET
;
2822 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2824 WARN("Application supplied invalid surface descriptor\n");
2825 wined3d_mutex_unlock();
2826 return DDERR_INVALIDPARAMS
;
2835 WARN("Surface pointer %p is invalid.\n", surface
);
2836 wined3d_mutex_unlock();
2837 return DDERR_INVALIDPARAMS
;
2841 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2843 if (TRACE_ON(ddraw
))
2845 TRACE(" (%p) Requesting surface desc :\n", iface
);
2846 DDRAW_dump_surface_desc(surface_desc
);
2849 WARN("Application tried to create an explicit front or back buffer\n");
2850 wined3d_mutex_unlock();
2851 return DDERR_INVALIDCAPS
;
2854 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 7);
2855 wined3d_mutex_unlock();
2859 *surface
= &impl
->IDirectDrawSurface7_iface
;
2860 IDirectDraw7_AddRef(iface
);
2861 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2866 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
2867 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
2869 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2870 struct ddraw_surface
*impl
;
2873 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2874 iface
, surface_desc
, surface
, outer_unknown
);
2876 wined3d_mutex_lock();
2878 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2880 WARN("Cooperative level not set.\n");
2881 wined3d_mutex_unlock();
2882 return DDERR_NOCOOPERATIVELEVELSET
;
2885 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2887 WARN("Application supplied invalid surface descriptor\n");
2888 wined3d_mutex_unlock();
2889 return DDERR_INVALIDPARAMS
;
2898 WARN("Surface pointer %p is invalid.\n", surface
);
2899 wined3d_mutex_unlock();
2900 return DDERR_INVALIDPARAMS
;
2904 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2906 if (TRACE_ON(ddraw
))
2908 TRACE(" (%p) Requesting surface desc :\n", iface
);
2909 DDRAW_dump_surface_desc(surface_desc
);
2912 WARN("Application tried to create an explicit front or back buffer\n");
2913 wined3d_mutex_unlock();
2914 return DDERR_INVALIDCAPS
;
2917 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 4);
2918 wined3d_mutex_unlock();
2922 *surface
= &impl
->IDirectDrawSurface4_iface
;
2923 IDirectDraw4_AddRef(iface
);
2924 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2929 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
2930 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2932 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2933 struct ddraw_surface
*impl
;
2935 DDSURFACEDESC2 surface_desc2
;
2937 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2938 iface
, surface_desc
, surface
, outer_unknown
);
2940 wined3d_mutex_lock();
2942 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2944 WARN("Cooperative level not set.\n");
2945 wined3d_mutex_unlock();
2946 return DDERR_NOCOOPERATIVELEVELSET
;
2949 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2951 WARN("Application supplied invalid surface descriptor\n");
2952 wined3d_mutex_unlock();
2953 return DDERR_INVALIDPARAMS
;
2962 WARN("Surface pointer %p is invalid.\n", surface
);
2963 wined3d_mutex_unlock();
2964 return DDERR_INVALIDPARAMS
;
2968 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2969 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2971 if (TRACE_ON(ddraw
))
2973 TRACE(" (%p) Requesting surface desc :\n", iface
);
2974 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
2977 WARN("Application tried to create an explicit front or back buffer\n");
2978 wined3d_mutex_unlock();
2979 return DDERR_INVALIDCAPS
;
2982 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 2);
2983 wined3d_mutex_unlock();
2987 *surface
= &impl
->IDirectDrawSurface_iface
;
2988 impl
->ifaceToRelease
= NULL
;
2993 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
2994 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2996 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2997 struct ddraw_surface
*impl
;
2999 DDSURFACEDESC2 surface_desc2
;
3001 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3002 iface
, surface_desc
, surface
, outer_unknown
);
3004 wined3d_mutex_lock();
3006 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
3008 WARN("Cooperative level not set.\n");
3009 wined3d_mutex_unlock();
3010 return DDERR_NOCOOPERATIVELEVELSET
;
3013 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3015 WARN("Application supplied invalid surface descriptor\n");
3016 wined3d_mutex_unlock();
3017 return DDERR_INVALIDPARAMS
;
3026 WARN("Surface pointer %p is invalid.\n", surface
);
3027 wined3d_mutex_unlock();
3028 return DDERR_INVALIDPARAMS
;
3032 if ((surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
))
3033 == (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
)
3034 || (surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
))
3035 == ((DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
)))
3037 WARN("Application tried to create an explicit front or back buffer.\n");
3038 wined3d_mutex_unlock();
3039 return DDERR_INVALIDCAPS
;
3042 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3043 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 1);
3044 wined3d_mutex_unlock();
3048 *surface
= &impl
->IDirectDrawSurface_iface
;
3049 impl
->ifaceToRelease
= NULL
;
3055 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
3056 const DDPIXELFORMAT
*provided
)
3058 /* Some flags must be present in both or neither for a match. */
3059 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
3060 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
3061 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
3063 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3066 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
3069 if (requested
->dwFlags
& DDPF_FOURCC
)
3070 if (requested
->dwFourCC
!= provided
->dwFourCC
)
3073 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
3074 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3075 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
3078 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3079 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3080 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
3083 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
3084 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
3087 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
3088 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3090 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
3093 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
3094 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
3100 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3109 #define CMP(FLAG, FIELD) \
3110 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3111 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3113 static const struct compare_info compare
[] =
3115 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3116 CMP(BACKBUFFERCOUNT
, u5
.dwBackBufferCount
),
3118 CMP(CKDESTBLT
, ddckCKDestBlt
),
3119 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3120 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3121 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3122 CMP(HEIGHT
, dwHeight
),
3123 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3124 CMP(LPSURFACE
, lpSurface
),
3125 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3126 CMP(PITCH
, u1
/* lPitch */),
3127 /* PIXELFORMAT: manual */
3128 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3129 CMP(TEXTURESTAGE
, dwTextureStage
),
3130 CMP(WIDTH
, dwWidth
),
3131 /* ZBUFFERBITDEPTH: "obsolete" */
3138 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3141 for (i
=0; i
< ARRAY_SIZE(compare
); i
++)
3143 if (requested
->dwFlags
& compare
[i
].flag
3144 && memcmp((const char *)provided
+ compare
[i
].offset
,
3145 (const char *)requested
+ compare
[i
].offset
,
3146 compare
[i
].size
) != 0)
3150 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3152 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3153 &provided
->u4
.ddpfPixelFormat
))
3160 struct surfacescallback2_context
3162 LPDDENUMSURFACESCALLBACK2 func
;
3166 struct surfacescallback_context
3168 LPDDENUMSURFACESCALLBACK func
;
3172 static HRESULT CALLBACK
EnumSurfacesCallback2Thunk(IDirectDrawSurface7
*surface
,
3173 DDSURFACEDESC2
*surface_desc
, void *context
)
3175 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3176 struct surfacescallback2_context
*cbcontext
= context
;
3178 IDirectDrawSurface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
3179 IDirectDrawSurface7_Release(surface
);
3181 return cbcontext
->func(&surface_impl
->IDirectDrawSurface4_iface
,
3182 surface_desc
, cbcontext
->context
);
3185 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3186 DDSURFACEDESC2
*surface_desc
, void *context
)
3188 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3189 struct surfacescallback_context
*cbcontext
= context
;
3191 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
3192 IDirectDrawSurface7_Release(surface
);
3194 return cbcontext
->func(&surface_impl
->IDirectDrawSurface_iface
,
3195 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3198 /*****************************************************************************
3199 * IDirectDraw7::EnumSurfaces
3201 * Loops through all surfaces attached to this device and calls the
3202 * application callback. This can't be relayed to WineD3DDevice,
3203 * because some WineD3DSurfaces' parents are IParent objects
3206 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3207 * DDSD: Description to filter for
3208 * Context: Application-provided pointer, it's passed unmodified to the
3210 * Callback: Address to call for each surface
3213 * DDERR_INVALIDPARAMS if the callback is NULL
3216 *****************************************************************************/
3217 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD Flags
,
3218 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMSURFACESCALLBACK7 Callback
)
3220 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3221 struct ddraw_surface
*surf
;
3223 DDSURFACEDESC2 desc
;
3224 struct list
*entry
, *entry2
;
3226 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3227 iface
, Flags
, DDSD
, Context
, Callback
);
3229 all
= Flags
& DDENUMSURFACES_ALL
;
3230 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
3233 return DDERR_INVALIDPARAMS
;
3235 wined3d_mutex_lock();
3237 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
3238 LIST_FOR_EACH_SAFE(entry
, entry2
, &ddraw
->surface_list
)
3240 surf
= LIST_ENTRY(entry
, struct ddraw_surface
, surface_list_entry
);
3242 if (!surf
->iface_count
)
3244 WARN("Not enumerating surface %p because it doesn't have any references.\n", surf
);
3248 if (all
|| (nomatch
!= ddraw_match_surface_desc(DDSD
, &surf
->surface_desc
)))
3250 TRACE("Enumerating surface %p.\n", surf
);
3251 desc
= surf
->surface_desc
;
3252 IDirectDrawSurface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
3253 if (Callback(&surf
->IDirectDrawSurface7_iface
, &desc
, Context
) != DDENUMRET_OK
)
3255 wined3d_mutex_unlock();
3261 wined3d_mutex_unlock();
3266 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3267 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3269 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3270 struct surfacescallback2_context cbcontext
;
3272 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3273 iface
, flags
, surface_desc
, context
, callback
);
3275 cbcontext
.func
= callback
;
3276 cbcontext
.context
= context
;
3278 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
,
3279 &cbcontext
, EnumSurfacesCallback2Thunk
);
3282 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3283 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3285 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3286 struct surfacescallback_context cbcontext
;
3287 DDSURFACEDESC2 surface_desc2
;
3289 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3290 iface
, flags
, surface_desc
, context
, callback
);
3292 cbcontext
.func
= callback
;
3293 cbcontext
.context
= context
;
3295 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3296 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3297 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3300 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3301 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3303 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3304 struct surfacescallback_context cbcontext
;
3305 DDSURFACEDESC2 surface_desc2
;
3307 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3308 iface
, flags
, surface_desc
, context
, callback
);
3310 cbcontext
.func
= callback
;
3311 cbcontext
.context
= context
;
3313 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3314 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3315 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3318 /*****************************************************************************
3319 * DirectDrawCreateClipper (DDRAW.@)
3321 * Creates a new IDirectDrawClipper object.
3324 * Clipper: Address to write the interface pointer to
3325 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3329 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3330 * E_OUTOFMEMORY if allocating the object failed
3332 *****************************************************************************/
3333 HRESULT WINAPI
DirectDrawCreateClipper(DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3335 struct ddraw_clipper
*object
;
3338 TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
3339 flags
, clipper
, outer_unknown
);
3342 return CLASS_E_NOAGGREGATION
;
3344 wined3d_mutex_lock();
3346 if (!(object
= heap_alloc_zero(sizeof(*object
))))
3348 wined3d_mutex_unlock();
3349 return E_OUTOFMEMORY
;
3352 hr
= ddraw_clipper_init(object
);
3355 WARN("Failed to initialize clipper, hr %#x.\n", hr
);
3357 wined3d_mutex_unlock();
3361 TRACE("Created clipper %p.\n", object
);
3362 *clipper
= &object
->IDirectDrawClipper_iface
;
3363 wined3d_mutex_unlock();
3368 /*****************************************************************************
3369 * IDirectDraw7::CreateClipper
3371 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3373 *****************************************************************************/
3374 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3375 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3377 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3378 iface
, Flags
, Clipper
, UnkOuter
);
3380 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3383 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
, DWORD flags
,
3384 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3386 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3388 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3389 iface
, flags
, clipper
, outer_unknown
);
3391 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3394 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
3395 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3397 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3399 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3400 iface
, flags
, clipper
, outer_unknown
);
3402 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3405 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
3406 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3408 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3410 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3411 iface
, flags
, clipper
, outer_unknown
);
3413 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3416 /*****************************************************************************
3417 * IDirectDraw7::CreatePalette
3419 * Creates a new IDirectDrawPalette object
3422 * Flags: The flags for the new clipper
3423 * ColorTable: Color table to assign to the new clipper
3424 * Palette: Address to write the interface pointer to
3425 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3429 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3430 * E_OUTOFMEMORY if allocating the object failed
3432 *****************************************************************************/
3433 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
3434 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
3436 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3437 struct ddraw_palette
*object
;
3440 TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
3441 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3444 return CLASS_E_NOAGGREGATION
;
3446 wined3d_mutex_lock();
3448 /* The refcount test shows that a cooplevel is required for this */
3449 if (!ddraw
->cooperative_level
)
3451 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3452 wined3d_mutex_unlock();
3453 return DDERR_NOCOOPERATIVELEVELSET
;
3456 if (!(object
= heap_alloc(sizeof(*object
))))
3458 ERR("Out of memory when allocating memory for a palette implementation\n");
3459 wined3d_mutex_unlock();
3460 return E_OUTOFMEMORY
;
3463 hr
= ddraw_palette_init(object
, ddraw
, Flags
, ColorTable
);
3466 WARN("Failed to initialize palette, hr %#x.\n", hr
);
3468 wined3d_mutex_unlock();
3472 TRACE("Created palette %p.\n", object
);
3473 *Palette
= &object
->IDirectDrawPalette_iface
;
3474 wined3d_mutex_unlock();
3479 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
, PALETTEENTRY
*entries
,
3480 IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3482 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3485 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3486 iface
, flags
, entries
, palette
, outer_unknown
);
3488 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3489 if (SUCCEEDED(hr
) && *palette
)
3491 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3492 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3493 IDirectDraw4_AddRef(iface
);
3494 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3499 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
3500 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3502 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3505 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3506 iface
, flags
, entries
, palette
, outer_unknown
);
3508 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3509 if (SUCCEEDED(hr
) && *palette
)
3511 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3512 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3513 impl
->ifaceToRelease
= NULL
;
3519 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
3520 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3522 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3525 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3526 iface
, flags
, entries
, palette
, outer_unknown
);
3528 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3529 if (SUCCEEDED(hr
) && *palette
)
3531 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3532 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3533 impl
->ifaceToRelease
= NULL
;
3539 /*****************************************************************************
3540 * IDirectDraw7::DuplicateSurface
3542 * Duplicates a surface. The surface memory points to the same memory as
3543 * the original surface, and it's released when the last surface referencing
3544 * it is released. I guess that's beyond Wine's surface management right now
3545 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3546 * test application to implement this)
3549 * Src: Address of the source surface
3550 * Dest: Address to write the new surface pointer to
3553 * See IDirectDraw7::CreateSurface
3555 *****************************************************************************/
3556 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
3557 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
3559 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(Src
);
3561 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
3563 /* For now, simply create a new, independent surface */
3564 return IDirectDraw7_CreateSurface(iface
, &src_surface
->surface_desc
, Dest
, NULL
);
3567 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
, IDirectDrawSurface4
*src
,
3568 IDirectDrawSurface4
**dst
)
3570 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
3571 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3572 struct ddraw_surface
*dst_impl
;
3573 IDirectDrawSurface7
*dst7
;
3576 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3578 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3579 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3585 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3586 *dst
= &dst_impl
->IDirectDrawSurface4_iface
;
3587 IDirectDrawSurface4_AddRef(*dst
);
3588 IDirectDrawSurface7_Release(dst7
);
3593 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
3594 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
3596 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3597 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3598 struct ddraw_surface
*dst_impl
;
3599 IDirectDrawSurface7
*dst7
;
3602 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3604 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3605 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3608 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3609 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3610 IDirectDrawSurface_AddRef(*dst
);
3611 IDirectDrawSurface7_Release(dst7
);
3616 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
, IDirectDrawSurface
*src
,
3617 IDirectDrawSurface
**dst
)
3619 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3620 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3621 struct ddraw_surface
*dst_impl
;
3622 IDirectDrawSurface7
*dst7
;
3625 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3627 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3628 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3631 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3632 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3633 IDirectDrawSurface_AddRef(*dst
);
3634 IDirectDrawSurface7_Release(dst7
);
3639 /*****************************************************************************
3640 * IDirect3D7::EnumDevices
3642 * The EnumDevices method for IDirect3D7. It enumerates all supported
3643 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
3646 * callback: Function to call for each enumerated device
3647 * context: Pointer to pass back to the app
3650 * D3D_OK, or the return value of the GetCaps call
3652 *****************************************************************************/
3653 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
3655 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
3656 D3DDEVICEDESC7 device_desc7
;
3660 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3663 return DDERR_INVALIDPARAMS
;
3665 wined3d_mutex_lock();
3667 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3669 wined3d_mutex_unlock();
3673 for (i
= 0; i
< ARRAY_SIZE(device_list7
); i
++)
3677 device_desc7
.deviceGUID
= *device_list7
[i
].device_guid
;
3678 ret
= callback(device_list7
[i
].interface_name
, device_list7
[i
].device_name
, &device_desc7
, context
);
3679 if (ret
!= DDENUMRET_OK
)
3681 TRACE("Application cancelled the enumeration.\n");
3682 wined3d_mutex_unlock();
3687 TRACE("End of enumeration.\n");
3689 wined3d_mutex_unlock();
3694 /*****************************************************************************
3695 * IDirect3D3::EnumDevices
3697 * Enumerates all supported Direct3DDevice interfaces. This is the
3698 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
3700 * Versions 1, 2 and 3
3703 * callback: Application-provided routine to call for each enumerated device
3704 * Context: Pointer to pass to the callback
3707 * D3D_OK on success,
3708 * The result of IDirect3DImpl_GetCaps if it failed
3710 *****************************************************************************/
3711 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3713 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
3715 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3716 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
3717 D3DDEVICEDESC7 device_desc7
;
3720 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
3721 * name string. Let's put the string in a sufficiently sized array in
3722 * writable memory. */
3723 char device_name
[50];
3724 strcpy(device_name
,"Direct3D HEL");
3726 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3729 return DDERR_INVALIDPARAMS
;
3731 wined3d_mutex_lock();
3733 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3735 wined3d_mutex_unlock();
3738 ddraw_d3dcaps1_from_7(&device_desc1
, &device_desc7
);
3740 /* Do I have to enumerate the reference id? Note from old d3d7:
3741 * "It seems that enumerating the reference IID on Direct3D 1 games
3742 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
3744 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
3745 * EnumReference which enables / disables enumerating the reference
3746 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
3747 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
3748 * demo directory suggest this.
3750 * Some games(GTA 2) seem to use the second enumerated device, so I have
3751 * to enumerate at least 2 devices. So enumerate the reference device to
3754 * Other games (Rollcage) tell emulation and hal device apart by certain
3755 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
3756 * limitation flag), and it refuses all devices that have the perspective
3757 * flag set. This way it refuses the emulation device, and HAL devices
3758 * never have POW2 unset in d3d7 on windows. */
3759 if (ddraw
->d3dversion
!= 1)
3761 static CHAR reference_description
[] = "RGB Direct3D emulation";
3763 TRACE("Enumerating WineD3D D3DDevice interface.\n");
3764 hal_desc
= device_desc1
;
3765 hel_desc
= device_desc1
;
3766 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
3767 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3768 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3769 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3770 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3771 /* RGB, RAMP and MMX devices have a HAL dcmColorModel of 0 */
3772 hal_desc
.dcmColorModel
= 0;
3773 /* RGB, RAMP and MMX devices cannot report HAL hardware flags */
3774 hal_desc
.dwFlags
= 0;
3776 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
3777 device_name
, &hal_desc
, &hel_desc
, context
);
3778 if (hr
!= D3DENUMRET_OK
)
3780 TRACE("Application cancelled the enumeration.\n");
3781 wined3d_mutex_unlock();
3786 strcpy(device_name
,"Direct3D HAL");
3788 TRACE("Enumerating HAL Direct3D device.\n");
3789 hal_desc
= device_desc1
;
3790 hel_desc
= device_desc1
;
3792 /* The hal device does not have the pow2 flag set in hel, but in hal. */
3793 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3794 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3795 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3796 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3797 /* HAL devices have a HEL dcmColorModel of 0 */
3798 hel_desc
.dcmColorModel
= 0;
3800 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
3801 device_name
, &hal_desc
, &hel_desc
, context
);
3802 if (hr
!= D3DENUMRET_OK
)
3804 TRACE("Application cancelled the enumeration.\n");
3805 wined3d_mutex_unlock();
3809 TRACE("End of enumeration.\n");
3811 wined3d_mutex_unlock();
3816 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3818 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3820 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3822 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3825 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3827 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3829 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3831 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3834 /*****************************************************************************
3835 * IDirect3D3::CreateLight
3837 * Creates an IDirect3DLight interface. This interface is used in
3838 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
3839 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
3840 * uses the IDirect3DDevice7 interface with D3D7 lights.
3842 * Versions 1, 2 and 3
3845 * light: Address to store the new interface pointer
3846 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3851 * DDERR_OUTOFMEMORY if memory allocation failed
3852 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3854 *****************************************************************************/
3855 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
,
3856 IUnknown
*outer_unknown
)
3858 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3859 struct d3d_light
*object
;
3861 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3864 return CLASS_E_NOAGGREGATION
;
3866 if (!(object
= heap_alloc_zero(sizeof(*object
))))
3868 ERR("Failed to allocate light memory.\n");
3869 return DDERR_OUTOFMEMORY
;
3872 d3d_light_init(object
, ddraw
);
3874 TRACE("Created light %p.\n", object
);
3875 *light
= &object
->IDirect3DLight_iface
;
3880 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3882 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3884 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3886 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3889 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3891 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3893 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3895 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3898 /*****************************************************************************
3899 * IDirect3D3::CreateMaterial
3901 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
3902 * and older versions. The IDirect3DMaterial implementation wraps its
3903 * functionality to IDirect3DDevice7::SetMaterial and friends.
3905 * Versions 1, 2 and 3
3908 * material: Address to store the new interface's pointer to
3909 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3914 * DDERR_OUTOFMEMORY if memory allocation failed
3915 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3917 *****************************************************************************/
3918 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
,
3919 IUnknown
*outer_unknown
)
3921 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3922 struct d3d_material
*object
;
3924 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3926 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3928 object
= d3d_material_create(ddraw
);
3931 ERR("Failed to allocate material memory.\n");
3932 return DDERR_OUTOFMEMORY
;
3935 TRACE("Created material %p.\n", object
);
3936 *material
= &object
->IDirect3DMaterial3_iface
;
3941 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
,
3942 IUnknown
*outer_unknown
)
3944 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3945 struct d3d_material
*object
;
3947 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3949 object
= d3d_material_create(ddraw
);
3952 ERR("Failed to allocate material memory.\n");
3953 return DDERR_OUTOFMEMORY
;
3956 TRACE("Created material %p.\n", object
);
3957 *material
= &object
->IDirect3DMaterial2_iface
;
3962 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
,
3963 IUnknown
*outer_unknown
)
3965 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3966 struct d3d_material
*object
;
3968 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3970 object
= d3d_material_create(ddraw
);
3973 ERR("Failed to allocate material memory.\n");
3974 return DDERR_OUTOFMEMORY
;
3977 TRACE("Created material %p.\n", object
);
3978 *material
= &object
->IDirect3DMaterial_iface
;
3983 /*****************************************************************************
3984 * IDirect3D3::CreateViewport
3986 * Creates an IDirect3DViewport interface. This interface is used
3987 * by Direct3D and earlier versions for Viewport management. In Direct3D7
3988 * it has been replaced by a viewport structure and
3989 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
3990 * uses the IDirect3DDevice7 methods for its functionality
3993 * Viewport: Address to store the new interface pointer
3994 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3999 * DDERR_OUTOFMEMORY if memory allocation failed
4000 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4002 *****************************************************************************/
4003 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
,
4004 IUnknown
*outer_unknown
)
4006 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4007 struct d3d_viewport
*object
;
4009 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4011 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4013 if (!(object
= heap_alloc_zero(sizeof(*object
))))
4015 ERR("Failed to allocate viewport memory.\n");
4016 return DDERR_OUTOFMEMORY
;
4019 d3d_viewport_init(object
, ddraw
);
4021 TRACE("Created viewport %p.\n", object
);
4022 *viewport
= &object
->IDirect3DViewport3_iface
;
4027 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
4029 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4031 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4033 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4037 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
4039 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4041 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4043 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4047 static HRESULT
ddraw_find_device(struct ddraw
*ddraw
, const D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
,
4048 unsigned int guid_count
, const GUID
* const *guids
, DWORD device_desc_size
)
4050 struct ddraw_find_device_result_v1
4054 D3DDEVICEDESC_V1 hw_desc
;
4055 D3DDEVICEDESC_V1 sw_desc
;
4057 struct ddraw_find_device_result_v2
4061 D3DDEVICEDESC_V2 hw_desc
;
4062 D3DDEVICEDESC_V2 sw_desc
;
4064 D3DDEVICEDESC7 desc7
;
4065 D3DDEVICEDESC desc1
;
4069 TRACE("ddraw %p, fds %p, fdr %p, guid_count %u, guids %p, device_desc_size %u.\n",
4070 ddraw
, fds
, fdr
, guid_count
, guids
, device_desc_size
);
4073 return DDERR_INVALIDPARAMS
;
4075 if (fds
->dwSize
!= sizeof(*fds
))
4077 WARN("Got invalid search structure size %u.\n", fds
->dwSize
);
4078 return DDERR_INVALIDPARAMS
;
4081 if (fdr
->dwSize
!= sizeof(*fdr
) && fdr
->dwSize
!= sizeof(*fdr2
) && fdr
->dwSize
!= sizeof(*fdr1
))
4083 WARN("Got invalid result structure size %u.\n", fdr
->dwSize
);
4084 return DDERR_INVALIDPARAMS
;
4087 if (fds
->dwFlags
& D3DFDS_COLORMODEL
)
4088 WARN("Ignoring colour model %#x.\n", fds
->dcmColorModel
);
4090 if (fds
->dwFlags
& D3DFDS_GUID
)
4094 TRACE("Trying to match GUID %s.\n", debugstr_guid(&fds
->guid
));
4096 if ((ddraw
->flags
& DDRAW_NO3D
) && IsEqualGUID(&fds
->guid
, &IID_IDirect3DHALDevice
))
4098 WARN("HAL device not available without 3D support.\n");
4099 return DDERR_NOTFOUND
;
4102 for (i
= 0; i
< guid_count
; ++i
)
4104 if (IsEqualGUID(guids
[i
], &fds
->guid
))
4113 WARN("Failed to match GUID %s.\n", debugstr_guid(&fds
->guid
));
4114 return DDERR_NOTFOUND
;
4119 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &desc7
)))
4122 /* Now return our own GUID */
4123 ddraw_d3dcaps1_from_7(&desc1
, &desc7
);
4124 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4126 /* Note that "device_desc_size" doesn't necessarily have any relation to
4127 * the actual structure size. However, this matches the behaviour of
4128 * Windows since at least Windows 2000. */
4129 if (fdr
->dwSize
== sizeof(*fdr1
))
4131 fdr1
= (struct ddraw_find_device_result_v1
*)fdr
;
4132 memcpy(&fdr1
->hw_desc
, &desc1
, sizeof(fdr1
->hw_desc
));
4133 fdr1
->hw_desc
.dwSize
= device_desc_size
;
4134 memcpy(&fdr1
->sw_desc
, &desc1
, sizeof(fdr1
->sw_desc
));
4135 fdr1
->sw_desc
.dwSize
= device_desc_size
;
4137 else if (fdr
->dwSize
== sizeof(*fdr2
))
4139 fdr2
= (struct ddraw_find_device_result_v2
*)fdr
;
4140 memcpy(&fdr2
->hw_desc
, &desc1
, sizeof(fdr2
->hw_desc
));
4141 fdr2
->hw_desc
.dwSize
= device_desc_size
;
4142 memcpy(&fdr2
->sw_desc
, &desc1
, sizeof(fdr2
->sw_desc
));
4143 fdr2
->sw_desc
.dwSize
= device_desc_size
;
4147 fdr
->ddHwDesc
= desc1
;
4148 fdr
->ddHwDesc
.dwSize
= device_desc_size
;
4149 fdr
->ddSwDesc
= desc1
;
4150 fdr
->ddSwDesc
.dwSize
= device_desc_size
;
4153 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4158 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4160 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4161 static const GUID
* const guids
[] =
4163 &IID_D3DDEVICE_WineD3D
,
4164 &IID_IDirect3DHALDevice
,
4165 &IID_IDirect3DRGBDevice
,
4168 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4170 return ddraw_find_device(ddraw
, fds
, fdr
, ARRAY_SIZE(guids
), guids
, sizeof(D3DDEVICEDESC_V3
));
4173 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4175 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4176 static const GUID
* const guids
[] =
4178 &IID_D3DDEVICE_WineD3D
,
4179 &IID_IDirect3DHALDevice
,
4180 &IID_IDirect3DMMXDevice
,
4181 &IID_IDirect3DRGBDevice
,
4182 &IID_IDirect3DRampDevice
,
4185 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4187 return ddraw_find_device(ddraw
, fds
, fdr
, ARRAY_SIZE(guids
), guids
, sizeof(D3DDEVICEDESC_V2
));
4190 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4192 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4193 static const GUID
* const guids
[] =
4195 &IID_D3DDEVICE_WineD3D
,
4196 &IID_IDirect3DHALDevice
,
4197 &IID_IDirect3DRGBDevice
,
4198 &IID_IDirect3DRampDevice
,
4201 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4203 return ddraw_find_device(ddraw
, fds
, fdr
, ARRAY_SIZE(guids
), guids
, sizeof(D3DDEVICEDESC_V1
));
4206 /*****************************************************************************
4207 * IDirect3D7::CreateDevice
4209 * Creates an IDirect3DDevice7 interface.
4211 * Versions 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4212 * DirectDraw surfaces and are created with
4213 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4214 * create the device object and QueryInterfaces for IDirect3DDevice
4217 * refiid: IID of the device to create
4218 * Surface: Initial rendertarget
4219 * Device: Address to return the interface pointer
4223 * DDERR_OUTOFMEMORY if memory allocation failed
4224 * DDERR_INVALIDPARAMS if a device exists already
4226 *****************************************************************************/
4227 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4228 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4230 struct ddraw_surface
*target
= unsafe_impl_from_IDirectDrawSurface7(surface
);
4231 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4232 struct d3d_device
*object
;
4235 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4237 wined3d_mutex_lock();
4238 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, target
, (IUnknown
*)surface
, 7, &object
, NULL
)))
4240 *device
= &object
->IDirect3DDevice7_iface
;
4244 WARN("Failed to create device, hr %#x.\n", hr
);
4247 wined3d_mutex_unlock();
4252 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4253 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4255 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface4(surface
);
4256 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4257 struct d3d_device
*device_impl
;
4260 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4261 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4264 return CLASS_E_NOAGGREGATION
;
4266 wined3d_mutex_lock();
4267 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 3, &device_impl
, NULL
)))
4269 *device
= &device_impl
->IDirect3DDevice3_iface
;
4273 WARN("Failed to create device, hr %#x.\n", hr
);
4276 wined3d_mutex_unlock();
4281 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4282 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4284 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface(surface
);
4285 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4286 struct d3d_device
*device_impl
;
4289 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4290 iface
, debugstr_guid(riid
), surface
, device
);
4292 wined3d_mutex_lock();
4293 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 2, &device_impl
, NULL
)))
4295 *device
= &device_impl
->IDirect3DDevice2_iface
;
4299 WARN("Failed to create device, hr %#x.\n", hr
);
4302 wined3d_mutex_unlock();
4307 /*****************************************************************************
4308 * IDirect3D7::CreateVertexBuffer
4310 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4316 * desc: Requested Vertex buffer properties
4317 * vertex_buffer: Address to return the interface pointer at
4318 * flags: Some flags, should be 0
4322 * DDERR_OUTOFMEMORY if memory allocation failed
4323 * DDERR_INVALIDPARAMS if desc or vertex_buffer is NULL
4325 *****************************************************************************/
4326 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4327 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4329 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4330 struct d3d_vertex_buffer
*object
;
4333 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
4334 iface
, desc
, vertex_buffer
, flags
);
4336 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4338 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4341 TRACE("Created vertex buffer %p.\n", object
);
4342 *vertex_buffer
= &object
->IDirect3DVertexBuffer7_iface
;
4345 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4350 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4351 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4353 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4354 struct d3d_vertex_buffer
*object
;
4357 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n",
4358 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4361 return CLASS_E_NOAGGREGATION
;
4362 if (!vertex_buffer
|| !desc
)
4363 return DDERR_INVALIDPARAMS
;
4365 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4368 TRACE("Created vertex buffer %p.\n", object
);
4369 *vertex_buffer
= (IDirect3DVertexBuffer
*)&object
->IDirect3DVertexBuffer7_iface
;
4372 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4377 /*****************************************************************************
4378 * IDirect3D7::EnumZBufferFormats
4380 * Enumerates all supported Z buffer pixel formats
4386 * callback: callback to call for each pixel format
4387 * context: Pointer to pass back to the callback
4391 * DDERR_INVALIDPARAMS if callback is NULL
4393 *****************************************************************************/
4394 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4395 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4397 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4398 struct wined3d_display_mode mode
;
4399 enum wined3d_device_type type
;
4403 /* Order matters. Specifically, BattleZone II (full version) expects the
4404 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4405 static const enum wined3d_format_id formats
[] =
4407 WINED3DFMT_S1_UINT_D15_UNORM
,
4408 WINED3DFMT_D16_UNORM
,
4409 WINED3DFMT_X8D24_UNORM
,
4410 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4411 WINED3DFMT_D24_UNORM_S8_UINT
,
4412 WINED3DFMT_D32_UNORM
,
4415 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4416 iface
, debugstr_guid(device_iid
), callback
, context
);
4418 if (!callback
) return DDERR_INVALIDPARAMS
;
4420 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4421 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4422 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4424 TRACE("Asked for HAL device.\n");
4425 type
= WINED3D_DEVICE_TYPE_HAL
;
4427 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4428 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4430 TRACE("Asked for SW device.\n");
4431 type
= WINED3D_DEVICE_TYPE_SW
;
4433 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4435 TRACE("Asked for REF device.\n");
4436 type
= WINED3D_DEVICE_TYPE_REF
;
4438 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4440 TRACE("Asked for NULLREF device.\n");
4441 type
= WINED3D_DEVICE_TYPE_NULLREF
;
4445 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4446 type
= WINED3D_DEVICE_TYPE_HAL
;
4449 wined3d_mutex_lock();
4450 /* We need an adapter format from somewhere to please wined3d and WGL.
4451 * Use the current display mode. So far all cards offer the same depth
4452 * stencil format for all modes, but if some do not and applications do
4453 * not like that we'll have to find some workaround, like iterating over
4454 * all imaginable formats and collecting all the depth stencil formats we
4456 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
4458 ERR("Failed to get display mode, hr %#x.\n", hr
);
4459 wined3d_mutex_unlock();
4463 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
)
4465 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
,
4466 mode
.format_id
, 0, WINED3D_BIND_DEPTH_STENCIL
, WINED3D_RTYPE_TEXTURE_2D
, formats
[i
])))
4468 DDPIXELFORMAT pformat
;
4470 memset(&pformat
, 0, sizeof(pformat
));
4471 pformat
.dwSize
= sizeof(pformat
);
4472 ddrawformat_from_wined3dformat(&pformat
, formats
[i
]);
4474 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
4475 hr
= callback(&pformat
, context
);
4476 if (hr
!= DDENUMRET_OK
)
4478 TRACE("Format enumeration cancelled by application.\n");
4479 wined3d_mutex_unlock();
4485 /* Historically some windows drivers used dwZBufferBitDepth=24 for WINED3DFMT_X8D24_UNORM,
4486 * while others used dwZBufferBitDepth=32. In either case the pitch matches a 32 bits per
4487 * pixel format, so we use dwZBufferBitDepth=32. Some games expect 24. Windows Vista and
4488 * newer enumerate both versions, so we do the same(bug 22434) */
4489 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4490 0, WINED3D_BIND_DEPTH_STENCIL
, WINED3D_RTYPE_TEXTURE_2D
, WINED3DFMT_X8D24_UNORM
)))
4492 DDPIXELFORMAT x8d24
=
4494 sizeof(x8d24
), DDPF_ZBUFFER
, 0,
4495 {24}, {0x00000000}, {0x00ffffff}, {0x00000000}
4497 TRACE("Enumerating WINED3DFMT_X8D24_UNORM, dwZBufferBitDepth=24 version\n");
4498 callback(&x8d24
, context
);
4501 TRACE("End of enumeration.\n");
4503 wined3d_mutex_unlock();
4508 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
4509 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4511 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4513 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4514 iface
, debugstr_guid(device_iid
), callback
, context
);
4516 return d3d7_EnumZBufferFormats(&ddraw
->IDirect3D7_iface
, device_iid
, callback
, context
);
4519 /*****************************************************************************
4520 * IDirect3D7::EvictManagedTextures
4522 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
4523 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
4528 * D3D_OK, because it's a stub
4530 *****************************************************************************/
4531 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
4533 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4535 TRACE("iface %p!\n", iface
);
4537 wined3d_mutex_lock();
4538 if (ddraw
->flags
& DDRAW_D3D_INITIALIZED
)
4539 wined3d_device_evict_managed_resources(ddraw
->wined3d_device
);
4540 wined3d_mutex_unlock();
4545 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
4547 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4549 TRACE("iface %p.\n", iface
);
4551 return d3d7_EvictManagedTextures(&ddraw
->IDirect3D7_iface
);
4554 /*****************************************************************************
4555 * IDirectDraw7 VTable
4556 *****************************************************************************/
4557 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
4560 ddraw7_QueryInterface
,
4565 ddraw7_CreateClipper
,
4566 ddraw7_CreatePalette
,
4567 ddraw7_CreateSurface
,
4568 ddraw7_DuplicateSurface
,
4569 ddraw7_EnumDisplayModes
,
4570 ddraw7_EnumSurfaces
,
4571 ddraw7_FlipToGDISurface
,
4573 ddraw7_GetDisplayMode
,
4574 ddraw7_GetFourCCCodes
,
4575 ddraw7_GetGDISurface
,
4576 ddraw7_GetMonitorFrequency
,
4578 ddraw7_GetVerticalBlankStatus
,
4580 ddraw7_RestoreDisplayMode
,
4581 ddraw7_SetCooperativeLevel
,
4582 ddraw7_SetDisplayMode
,
4583 ddraw7_WaitForVerticalBlank
,
4585 ddraw7_GetAvailableVidMem
,
4587 ddraw7_GetSurfaceFromDC
,
4589 ddraw7_RestoreAllSurfaces
,
4590 ddraw7_TestCooperativeLevel
,
4591 ddraw7_GetDeviceIdentifier
,
4593 ddraw7_StartModeTest
,
4597 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
4600 ddraw4_QueryInterface
,
4605 ddraw4_CreateClipper
,
4606 ddraw4_CreatePalette
,
4607 ddraw4_CreateSurface
,
4608 ddraw4_DuplicateSurface
,
4609 ddraw4_EnumDisplayModes
,
4610 ddraw4_EnumSurfaces
,
4611 ddraw4_FlipToGDISurface
,
4613 ddraw4_GetDisplayMode
,
4614 ddraw4_GetFourCCCodes
,
4615 ddraw4_GetGDISurface
,
4616 ddraw4_GetMonitorFrequency
,
4618 ddraw4_GetVerticalBlankStatus
,
4620 ddraw4_RestoreDisplayMode
,
4621 ddraw4_SetCooperativeLevel
,
4622 ddraw4_SetDisplayMode
,
4623 ddraw4_WaitForVerticalBlank
,
4625 ddraw4_GetAvailableVidMem
,
4627 ddraw4_GetSurfaceFromDC
,
4629 ddraw4_RestoreAllSurfaces
,
4630 ddraw4_TestCooperativeLevel
,
4631 ddraw4_GetDeviceIdentifier
,
4634 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
4637 ddraw2_QueryInterface
,
4642 ddraw2_CreateClipper
,
4643 ddraw2_CreatePalette
,
4644 ddraw2_CreateSurface
,
4645 ddraw2_DuplicateSurface
,
4646 ddraw2_EnumDisplayModes
,
4647 ddraw2_EnumSurfaces
,
4648 ddraw2_FlipToGDISurface
,
4650 ddraw2_GetDisplayMode
,
4651 ddraw2_GetFourCCCodes
,
4652 ddraw2_GetGDISurface
,
4653 ddraw2_GetMonitorFrequency
,
4655 ddraw2_GetVerticalBlankStatus
,
4657 ddraw2_RestoreDisplayMode
,
4658 ddraw2_SetCooperativeLevel
,
4659 ddraw2_SetDisplayMode
,
4660 ddraw2_WaitForVerticalBlank
,
4662 ddraw2_GetAvailableVidMem
,
4665 static const struct IDirectDrawVtbl ddraw1_vtbl
=
4668 ddraw1_QueryInterface
,
4673 ddraw1_CreateClipper
,
4674 ddraw1_CreatePalette
,
4675 ddraw1_CreateSurface
,
4676 ddraw1_DuplicateSurface
,
4677 ddraw1_EnumDisplayModes
,
4678 ddraw1_EnumSurfaces
,
4679 ddraw1_FlipToGDISurface
,
4681 ddraw1_GetDisplayMode
,
4682 ddraw1_GetFourCCCodes
,
4683 ddraw1_GetGDISurface
,
4684 ddraw1_GetMonitorFrequency
,
4686 ddraw1_GetVerticalBlankStatus
,
4688 ddraw1_RestoreDisplayMode
,
4689 ddraw1_SetCooperativeLevel
,
4690 ddraw1_SetDisplayMode
,
4691 ddraw1_WaitForVerticalBlank
,
4694 static const struct IDirect3D7Vtbl d3d7_vtbl
=
4696 /* IUnknown methods */
4697 d3d7_QueryInterface
,
4700 /* IDirect3D7 methods */
4703 d3d7_CreateVertexBuffer
,
4704 d3d7_EnumZBufferFormats
,
4705 d3d7_EvictManagedTextures
4708 static const struct IDirect3D3Vtbl d3d3_vtbl
=
4710 /* IUnknown methods */
4711 d3d3_QueryInterface
,
4714 /* IDirect3D3 methods */
4717 d3d3_CreateMaterial
,
4718 d3d3_CreateViewport
,
4721 d3d3_CreateVertexBuffer
,
4722 d3d3_EnumZBufferFormats
,
4723 d3d3_EvictManagedTextures
4726 static const struct IDirect3D2Vtbl d3d2_vtbl
=
4728 /* IUnknown methods */
4729 d3d2_QueryInterface
,
4732 /* IDirect3D2 methods */
4735 d3d2_CreateMaterial
,
4736 d3d2_CreateViewport
,
4741 static const struct IDirect3DVtbl d3d1_vtbl
=
4743 /* IUnknown methods */
4744 d3d1_QueryInterface
,
4747 /* IDirect3D methods */
4751 d3d1_CreateMaterial
,
4752 d3d1_CreateViewport
,
4756 /*****************************************************************************
4759 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
4760 * if none was found.
4762 * This function is in ddraw.c and the DDraw object space because D3D7
4763 * vertex buffers are created using the IDirect3D interface to the ddraw
4764 * object, so they can be valid across D3D devices(theoretically. The ddraw
4765 * object also owns the wined3d device
4769 * fvf: Fvf to find the decl for
4772 * NULL in case of an error, the vertex declaration for the FVF otherwise.
4774 *****************************************************************************/
4775 struct wined3d_vertex_declaration
*ddraw_find_decl(struct ddraw
*This
, DWORD fvf
)
4777 struct wined3d_vertex_declaration
*pDecl
= NULL
;
4779 int p
, low
, high
; /* deliberately signed */
4780 struct FvfToDecl
*convertedDecls
= This
->decls
;
4782 TRACE("Searching for declaration for fvf %08x... ", fvf
);
4785 high
= This
->numConvertedDecls
- 1;
4786 while(low
<= high
) {
4787 p
= (low
+ high
) >> 1;
4789 if(convertedDecls
[p
].fvf
== fvf
) {
4790 TRACE("found %p\n", convertedDecls
[p
].decl
);
4791 return convertedDecls
[p
].decl
;
4792 } else if(convertedDecls
[p
].fvf
< fvf
) {
4798 TRACE("not found. Creating and inserting at position %d.\n", low
);
4800 hr
= wined3d_vertex_declaration_create_from_fvf(This
->wined3d_device
,
4801 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
4802 if (hr
!= S_OK
) return NULL
;
4804 if (This
->declArraySize
== This
->numConvertedDecls
)
4806 unsigned int grow
= max(This
->declArraySize
/ 2, 8);
4808 if (!(convertedDecls
= heap_realloc(convertedDecls
,
4809 (This
->numConvertedDecls
+ grow
) * sizeof(*convertedDecls
))))
4811 wined3d_vertex_declaration_decref(pDecl
);
4814 This
->decls
= convertedDecls
;
4815 This
->declArraySize
+= grow
;
4818 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
4819 convertedDecls
[low
].decl
= pDecl
;
4820 convertedDecls
[low
].fvf
= fvf
;
4821 This
->numConvertedDecls
++;
4823 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
4827 static inline struct ddraw
*ddraw_from_device_parent(struct wined3d_device_parent
*device_parent
)
4829 return CONTAINING_RECORD(device_parent
, struct ddraw
, device_parent
);
4832 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
4833 struct wined3d_device
*device
)
4835 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
4838 /* This is run from device_process_message() in wined3d, we can't take the
4840 /* FIXME: We only get mode change notifications in exclusive mode, but we
4841 * should mark surfaces as lost on mode changes in DDSCL_NORMAL mode as well. */
4842 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
4844 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4845 MONITORINFO monitor_info
;
4849 TRACE("device_parent %p.\n", device_parent
);
4851 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) || !ddraw
->swapchain_window
)
4853 TRACE("Nothing to resize.\n");
4857 monitor
= MonitorFromWindow(ddraw
->swapchain_window
, MONITOR_DEFAULTTOPRIMARY
);
4858 monitor_info
.cbSize
= sizeof(monitor_info
);
4859 if (!GetMonitorInfoW(monitor
, &monitor_info
))
4861 ERR("Failed to get monitor info.\n");
4865 r
= &monitor_info
.rcMonitor
;
4866 TRACE("Resizing window %p to %s.\n", ddraw
->swapchain_window
, wine_dbgstr_rect(r
));
4868 if (!SetWindowPos(ddraw
->swapchain_window
, HWND_TOP
, r
->left
, r
->top
,
4869 r
->right
- r
->left
, r
->bottom
- r
->top
, SWP_SHOWWINDOW
| SWP_NOACTIVATE
))
4870 ERR("Failed to resize window.\n");
4872 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_OK
);
4875 static void CDECL
device_parent_activate(struct wined3d_device_parent
*device_parent
, BOOL activate
)
4877 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4879 TRACE("device_parent %p, activate %#x.\n", device_parent
, activate
);
4883 ddraw
->device_state
= DDRAW_DEVICE_STATE_LOST
;
4884 exclusive_window
= NULL
;
4888 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_LOST
);
4892 void ddraw_update_lost_surfaces(struct ddraw
*ddraw
)
4894 struct ddraw_surface
*surface
;
4896 if (ddraw
->device_state
!= DDRAW_DEVICE_STATE_NOT_RESTORED
)
4899 LIST_FOR_EACH_ENTRY(surface
, &ddraw
->surface_list
, struct ddraw_surface
, surface_list_entry
)
4901 surface
->is_lost
= TRUE
;
4903 ddraw
->device_state
= DDRAW_DEVICE_STATE_OK
;
4906 static HRESULT CDECL
device_parent_texture_sub_resource_created(struct wined3d_device_parent
*device_parent
,
4907 enum wined3d_resource_type type
, struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
4908 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
4910 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4911 struct ddraw_surface
*ddraw_surface
;
4913 TRACE("device_parent %p, type %#x, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
4914 device_parent
, type
, wined3d_texture
, sub_resource_idx
, parent
, parent_ops
);
4916 /* We have a swapchain or wined3d internal texture. */
4917 if (type
!= WINED3D_RTYPE_TEXTURE_2D
|| !wined3d_texture_get_parent(wined3d_texture
)
4918 || wined3d_texture_get_parent(wined3d_texture
) == ddraw
)
4921 *parent_ops
= &ddraw_null_wined3d_parent_ops
;
4926 if (!(ddraw_surface
= heap_alloc_zero(sizeof(*ddraw_surface
))))
4928 ERR("Failed to allocate surface memory.\n");
4929 return DDERR_OUTOFVIDEOMEMORY
;
4932 ddraw_surface_init(ddraw_surface
, ddraw
, wined3d_texture
, sub_resource_idx
, parent_ops
);
4933 *parent
= ddraw_surface
;
4935 ddraw_update_lost_surfaces(ddraw
);
4936 list_add_head(&ddraw
->surface_list
, &ddraw_surface
->surface_list_entry
);
4938 TRACE("Created ddraw surface %p.\n", ddraw_surface
);
4943 static void STDMETHODCALLTYPE
ddraw_frontbuffer_destroyed(void *parent
)
4945 struct ddraw
*ddraw
= parent
;
4946 ddraw
->wined3d_frontbuffer
= NULL
;
4949 static const struct wined3d_parent_ops ddraw_frontbuffer_parent_ops
=
4951 ddraw_frontbuffer_destroyed
,
4954 static HRESULT CDECL
device_parent_create_swapchain_texture(struct wined3d_device_parent
*device_parent
,
4955 void *container_parent
, const struct wined3d_resource_desc
*desc
, DWORD texture_flags
,
4956 struct wined3d_texture
**texture
)
4958 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4959 const struct wined3d_parent_ops
*parent_ops
;
4962 TRACE("device_parent %p, container_parent %p, desc %p, texture flags %#x, texture %p.\n",
4963 device_parent
, container_parent
, desc
, texture_flags
, texture
);
4965 if (!ddraw
->wined3d_frontbuffer
)
4966 parent_ops
= &ddraw_frontbuffer_parent_ops
;
4968 parent_ops
= &ddraw_null_wined3d_parent_ops
;
4970 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, desc
, 1, 1,
4971 texture_flags
, NULL
, ddraw
, parent_ops
, texture
)))
4973 WARN("Failed to create texture, hr %#x.\n", hr
);
4977 if (!ddraw
->wined3d_frontbuffer
)
4978 ddraw
->wined3d_frontbuffer
= *texture
;
4983 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
4984 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
4986 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4989 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent
, desc
, swapchain
);
4991 if (ddraw
->wined3d_swapchain
)
4993 ERR("Swapchain already created.\n");
4997 if (FAILED(hr
= wined3d_swapchain_create(ddraw
->wined3d_device
, desc
, NULL
,
4998 &ddraw_null_wined3d_parent_ops
, swapchain
)))
4999 WARN("Failed to create swapchain, hr %#x.\n", hr
);
5004 static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops
=
5006 device_parent_wined3d_device_created
,
5007 device_parent_mode_changed
,
5008 device_parent_activate
,
5009 device_parent_texture_sub_resource_created
,
5010 device_parent_create_swapchain_texture
,
5011 device_parent_create_swapchain
,
5014 HRESULT
ddraw_init(struct ddraw
*ddraw
, DWORD flags
, enum wined3d_device_type device_type
)
5016 struct wined3d_caps caps
;
5019 static const enum wined3d_feature_level feature_levels
[] =
5021 WINED3D_FEATURE_LEVEL_7
,
5022 WINED3D_FEATURE_LEVEL_6
,
5023 WINED3D_FEATURE_LEVEL_5
,
5026 ddraw
->IDirectDraw7_iface
.lpVtbl
= &ddraw7_vtbl
;
5027 ddraw
->IDirectDraw_iface
.lpVtbl
= &ddraw1_vtbl
;
5028 ddraw
->IDirectDraw2_iface
.lpVtbl
= &ddraw2_vtbl
;
5029 ddraw
->IDirectDraw4_iface
.lpVtbl
= &ddraw4_vtbl
;
5030 ddraw
->IDirect3D_iface
.lpVtbl
= &d3d1_vtbl
;
5031 ddraw
->IDirect3D2_iface
.lpVtbl
= &d3d2_vtbl
;
5032 ddraw
->IDirect3D3_iface
.lpVtbl
= &d3d3_vtbl
;
5033 ddraw
->IDirect3D7_iface
.lpVtbl
= &d3d7_vtbl
;
5034 ddraw
->device_parent
.ops
= &ddraw_wined3d_device_parent_ops
;
5035 ddraw
->numIfaces
= 1;
5038 flags
|= DDRAW_WINED3D_FLAGS
;
5039 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
5041 flags
|= WINED3D_NO3D
;
5042 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
5044 WARN("Failed to create a wined3d object.\n");
5049 if (FAILED(hr
= wined3d_get_device_caps(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
, &caps
)))
5051 ERR("Failed to get device caps, hr %#x.\n", hr
);
5052 wined3d_decref(ddraw
->wined3d
);
5056 if (!(caps
.ddraw_caps
.caps
& WINEDDCAPS_3D
))
5058 WARN("Created a wined3d object without 3D support.\n");
5059 ddraw
->flags
|= DDRAW_NO3D
;
5062 if (FAILED(hr
= wined3d_device_create(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
,
5063 NULL
, 0, DDRAW_STRIDE_ALIGNMENT
, feature_levels
, ARRAY_SIZE(feature_levels
),
5064 &ddraw
->device_parent
, &ddraw
->wined3d_device
)))
5066 WARN("Failed to create a wined3d device, hr %#x.\n", hr
);
5067 wined3d_decref(ddraw
->wined3d
);
5071 list_init(&ddraw
->surface_list
);