2 * Copyright 1997-2000 Marcus Meissner
3 * Copyright 1998-2000 Lionel Ulmer
4 * Copyright 2000-2001 TransGaming Technologies Inc.
5 * Copyright 2006 Stefan Dösinger
6 * Copyright 2008 Denver Gingerich
7 * Copyright 2007-2008, 2011, 2013 Stefan Dösinger for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/port.h"
27 #include "ddraw_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
31 static const struct ddraw
*exclusive_ddraw
;
33 /* Device identifier. Don't relay it to WineD3D */
34 static const DDDEVICEIDENTIFIER2 deviceidentifier
=
36 "vga.dll", /* default 2D driver */
38 { { 0x00010001, 0x00010001 } },
40 /* a8373c10-7ac4-4deb-849a-009844d08b2d */
41 {0xa8373c10,0x7ac4,0x4deb, {0x84,0x9a,0x00,0x98,0x44,0xd0,0x8b,0x2d}},
45 static struct enum_device_entry
47 char interface_name
[100];
48 char device_name
[100];
49 const GUID
*device_guid
;
54 "WINE Direct3D7 Hardware Transform and Lighting acceleration using WineD3D",
56 &IID_IDirect3DTnLHalDevice
,
61 "WINE Direct3D7 Hardware acceleration using WineD3D",
63 &IID_IDirect3DHALDevice
,
68 "WINE Direct3D7 RGB Software Emulation using WineD3D",
70 &IID_IDirect3DRGBDevice
,
74 static void STDMETHODCALLTYPE
ddraw_null_wined3d_object_destroyed(void *parent
) {}
76 const struct wined3d_parent_ops ddraw_null_wined3d_parent_ops
=
78 ddraw_null_wined3d_object_destroyed
,
81 static inline struct ddraw
*impl_from_IDirectDraw(IDirectDraw
*iface
)
83 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw_iface
);
86 static inline struct ddraw
*impl_from_IDirectDraw2(IDirectDraw2
*iface
)
88 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw2_iface
);
91 static inline struct ddraw
*impl_from_IDirectDraw4(IDirectDraw4
*iface
)
93 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw4_iface
);
96 static inline struct ddraw
*impl_from_IDirectDraw7(IDirectDraw7
*iface
)
98 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw7_iface
);
101 static inline struct ddraw
*impl_from_IDirect3D(IDirect3D
*iface
)
103 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D_iface
);
106 static inline struct ddraw
*impl_from_IDirect3D2(IDirect3D2
*iface
)
108 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D2_iface
);
111 static inline struct ddraw
*impl_from_IDirect3D3(IDirect3D3
*iface
)
113 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D3_iface
);
116 static inline struct ddraw
*impl_from_IDirect3D7(IDirect3D7
*iface
)
118 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D7_iface
);
121 static HRESULT WINAPI
ddraw7_QueryInterface(IDirectDraw7
*iface
, REFIID riid
, void **out
)
123 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
125 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
130 return DDERR_INVALIDPARAMS
;
133 /* The refcount unit test revealed that an IDirect3D7 interface can only
134 * be queried from a DirectDraw object that was created as an IDirectDraw7
135 * interface. The older interfaces can query any IDirect3D version except
136 * 7, because they are all initially created as IDirectDraw. This isn't
137 * really crucial behavior, and messy to implement with the common
138 * creation function, so it has been left out here. */
139 if (IsEqualGUID(&IID_IDirectDraw7
, riid
)
140 || IsEqualGUID(&IID_IUnknown
, riid
))
142 *out
= &ddraw
->IDirectDraw7_iface
;
143 TRACE("Returning IDirectDraw7 interface %p.\n", *out
);
145 else if (IsEqualGUID(&IID_IDirectDraw4
, riid
))
147 *out
= &ddraw
->IDirectDraw4_iface
;
148 TRACE("Returning IDirectDraw4 interface %p.\n", *out
);
150 else if (IsEqualGUID(&IID_IDirectDraw2
, riid
))
152 *out
= &ddraw
->IDirectDraw2_iface
;
153 TRACE("Returning IDirectDraw2 interface %p.\n", *out
);
155 else if (IsEqualGUID(&IID_IDirectDraw
, riid
))
157 *out
= &ddraw
->IDirectDraw_iface
;
158 TRACE("Returning IDirectDraw interface %p.\n", *out
);
160 else if (IsEqualGUID(&IID_IDirect3D7
, riid
))
162 ddraw
->d3dversion
= 7;
163 *out
= &ddraw
->IDirect3D7_iface
;
164 TRACE("Returning Direct3D7 interface %p.\n", *out
);
166 else if (IsEqualGUID(&IID_IDirect3D3
, riid
))
168 ddraw
->d3dversion
= 3;
169 *out
= &ddraw
->IDirect3D3_iface
;
170 TRACE("Returning Direct3D3 interface %p.\n", *out
);
172 else if (IsEqualGUID(&IID_IDirect3D2
, riid
))
174 ddraw
->d3dversion
= 2;
175 *out
= &ddraw
->IDirect3D2_iface
;
176 TRACE("Returning Direct3D2 interface %p.\n", *out
);
178 else if (IsEqualGUID(&IID_IDirect3D
, riid
))
180 ddraw
->d3dversion
= 1;
181 *out
= &ddraw
->IDirect3D_iface
;
182 TRACE("Returning Direct3D interface %p.\n", *out
);
184 /* Unknown interface */
187 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
189 return E_NOINTERFACE
;
192 IUnknown_AddRef((IUnknown
*)*out
);
196 static HRESULT WINAPI
ddraw4_QueryInterface(IDirectDraw4
*iface
, REFIID riid
, void **object
)
198 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
200 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
202 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
205 static HRESULT WINAPI
ddraw2_QueryInterface(IDirectDraw2
*iface
, REFIID riid
, void **object
)
207 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
209 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
211 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
214 static HRESULT WINAPI
ddraw1_QueryInterface(IDirectDraw
*iface
, REFIID riid
, void **object
)
216 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
218 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
220 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
223 static HRESULT WINAPI
d3d7_QueryInterface(IDirect3D7
*iface
, REFIID riid
, void **object
)
225 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
227 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
229 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
232 static HRESULT WINAPI
d3d3_QueryInterface(IDirect3D3
*iface
, REFIID riid
, void **object
)
234 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
236 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
238 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
241 static HRESULT WINAPI
d3d2_QueryInterface(IDirect3D2
*iface
, REFIID riid
, void **object
)
243 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
245 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
247 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
250 static HRESULT WINAPI
d3d1_QueryInterface(IDirect3D
*iface
, REFIID riid
, void **object
)
252 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
254 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
256 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
259 /*****************************************************************************
260 * IDirectDraw7::AddRef
262 * Increases the interfaces refcount, basically
264 * DDraw refcounting is a bit tricky. The different DirectDraw interface
265 * versions have individual refcounts, but the IDirect3D interfaces do not.
266 * All interfaces are from one object, that means calling QueryInterface on an
267 * IDirectDraw7 interface for an IDirectDraw4 interface does not create a new
270 * That means all AddRef and Release implementations of IDirectDrawX work
271 * with their own counter, and IDirect3DX::AddRef thunk to IDirectDraw (1),
272 * except of IDirect3D7 which thunks to IDirectDraw7
274 * Returns: The new refcount
276 *****************************************************************************/
277 static ULONG WINAPI
ddraw7_AddRef(IDirectDraw7
*iface
)
279 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
280 ULONG ref
= InterlockedIncrement(&This
->ref7
);
282 TRACE("%p increasing refcount to %u.\n", This
, ref
);
284 if(ref
== 1) InterlockedIncrement(&This
->numIfaces
);
289 static ULONG WINAPI
ddraw4_AddRef(IDirectDraw4
*iface
)
291 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
292 ULONG ref
= InterlockedIncrement(&This
->ref4
);
294 TRACE("%p increasing refcount to %u.\n", This
, ref
);
296 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
301 static ULONG WINAPI
ddraw2_AddRef(IDirectDraw2
*iface
)
303 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
304 ULONG ref
= InterlockedIncrement(&This
->ref2
);
306 TRACE("%p increasing refcount to %u.\n", This
, ref
);
308 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
313 static ULONG WINAPI
ddraw1_AddRef(IDirectDraw
*iface
)
315 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
316 ULONG ref
= InterlockedIncrement(&This
->ref1
);
318 TRACE("%p increasing refcount to %u.\n", This
, ref
);
320 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
325 static ULONG WINAPI
d3d7_AddRef(IDirect3D7
*iface
)
327 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
329 TRACE("iface %p.\n", iface
);
331 return ddraw7_AddRef(&This
->IDirectDraw7_iface
);
334 static ULONG WINAPI
d3d3_AddRef(IDirect3D3
*iface
)
336 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
338 TRACE("iface %p.\n", iface
);
340 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
343 static ULONG WINAPI
d3d2_AddRef(IDirect3D2
*iface
)
345 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
347 TRACE("iface %p.\n", iface
);
349 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
352 static ULONG WINAPI
d3d1_AddRef(IDirect3D
*iface
)
354 struct ddraw
*This
= impl_from_IDirect3D(iface
);
356 TRACE("iface %p.\n", iface
);
358 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
361 void ddraw_destroy_swapchain(struct ddraw
*ddraw
)
363 TRACE("Destroying the swapchain.\n");
365 wined3d_swapchain_decref(ddraw
->wined3d_swapchain
);
366 ddraw
->wined3d_swapchain
= NULL
;
368 if (!(ddraw
->flags
& DDRAW_NO3D
))
372 for (i
= 0; i
< ddraw
->numConvertedDecls
; ++i
)
374 wined3d_vertex_declaration_decref(ddraw
->decls
[i
].decl
);
376 HeapFree(GetProcessHeap(), 0, ddraw
->decls
);
377 ddraw
->numConvertedDecls
= 0;
379 if (FAILED(wined3d_device_uninit_3d(ddraw
->wined3d_device
)))
381 ERR("Failed to uninit 3D.\n");
385 /* Free the d3d window if one was created. */
386 if (ddraw
->d3d_window
&& ddraw
->d3d_window
!= ddraw
->dest_window
)
388 TRACE("Destroying the hidden render window %p.\n", ddraw
->d3d_window
);
389 DestroyWindow(ddraw
->d3d_window
);
390 ddraw
->d3d_window
= 0;
394 ddraw
->flags
&= ~DDRAW_D3D_INITIALIZED
;
398 wined3d_device_uninit_gdi(ddraw
->wined3d_device
);
401 ddraw_set_swapchain_window(ddraw
, NULL
);
403 TRACE("Swapchain destroyed.\n");
406 /*****************************************************************************
409 * Destroys a ddraw object if all refcounts are 0. This is to share code
410 * between the IDirectDrawX::Release functions
413 * This: DirectDraw object to destroy
415 *****************************************************************************/
416 static void ddraw_destroy(struct ddraw
*This
)
418 IDirectDraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, NULL
, DDSCL_NORMAL
);
419 IDirectDraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
421 /* Destroy the device window if we created one */
422 if(This
->devicewindow
!= 0)
424 TRACE(" (%p) Destroying the device window %p\n", This
, This
->devicewindow
);
425 DestroyWindow(This
->devicewindow
);
426 This
->devicewindow
= 0;
429 wined3d_mutex_lock();
430 list_remove(&This
->ddraw_list_entry
);
431 wined3d_mutex_unlock();
433 if (This
->wined3d_swapchain
)
434 ddraw_destroy_swapchain(This
);
435 wined3d_device_decref(This
->wined3d_device
);
436 wined3d_decref(This
->wined3d
);
439 This
->d3ddevice
->ddraw
= NULL
;
441 /* Now free the object */
442 HeapFree(GetProcessHeap(), 0, This
);
445 /*****************************************************************************
446 * IDirectDraw7::Release
448 * Decreases the refcount. If the refcount falls to 0, the object is destroyed
450 * Returns: The new refcount
451 *****************************************************************************/
452 static ULONG WINAPI
ddraw7_Release(IDirectDraw7
*iface
)
454 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
455 ULONG ref
= InterlockedDecrement(&This
->ref7
);
457 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
459 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
465 static ULONG WINAPI
ddraw4_Release(IDirectDraw4
*iface
)
467 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
468 ULONG ref
= InterlockedDecrement(&This
->ref4
);
470 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
472 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
478 static ULONG WINAPI
ddraw2_Release(IDirectDraw2
*iface
)
480 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
481 ULONG ref
= InterlockedDecrement(&This
->ref2
);
483 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
485 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
491 static ULONG WINAPI
ddraw1_Release(IDirectDraw
*iface
)
493 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
494 ULONG ref
= InterlockedDecrement(&This
->ref1
);
496 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
498 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
504 static ULONG WINAPI
d3d7_Release(IDirect3D7
*iface
)
506 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
508 TRACE("iface %p.\n", iface
);
510 return ddraw7_Release(&This
->IDirectDraw7_iface
);
513 static ULONG WINAPI
d3d3_Release(IDirect3D3
*iface
)
515 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
517 TRACE("iface %p.\n", iface
);
519 return ddraw1_Release(&This
->IDirectDraw_iface
);
522 static ULONG WINAPI
d3d2_Release(IDirect3D2
*iface
)
524 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
526 TRACE("iface %p.\n", iface
);
528 return ddraw1_Release(&This
->IDirectDraw_iface
);
531 static ULONG WINAPI
d3d1_Release(IDirect3D
*iface
)
533 struct ddraw
*This
= impl_from_IDirect3D(iface
);
535 TRACE("iface %p.\n", iface
);
537 return ddraw1_Release(&This
->IDirectDraw_iface
);
540 /*****************************************************************************
541 * IDirectDraw methods
542 *****************************************************************************/
544 static HRESULT
ddraw_set_focus_window(struct ddraw
*ddraw
, HWND window
)
546 /* FIXME: This looks wrong, exclusive mode should imply a destination
548 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) && ddraw
->dest_window
)
550 TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET.\n");
551 return DDERR_HWNDALREADYSET
;
554 ddraw
->focuswindow
= window
;
559 static HRESULT
ddraw_attach_d3d_device(struct ddraw
*ddraw
,
560 struct wined3d_swapchain_desc
*swapchain_desc
)
562 HWND window
= swapchain_desc
->device_window
;
565 TRACE("ddraw %p.\n", ddraw
);
567 if (!window
|| window
== GetDesktopWindow())
569 window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "Hidden D3D Window",
570 WS_DISABLED
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
571 NULL
, NULL
, NULL
, NULL
);
574 ERR("Failed to create window, last error %#x.\n", GetLastError());
578 ShowWindow(window
, SW_HIDE
); /* Just to be sure */
579 WARN("No window for the Direct3DDevice, created hidden window %p.\n", window
);
581 swapchain_desc
->device_window
= window
;
585 TRACE("Using existing window %p for Direct3D rendering.\n", window
);
587 ddraw
->d3d_window
= window
;
589 /* Set this NOW, otherwise creating the depth stencil surface will cause a
590 * recursive loop until ram or emulated video memory is full. */
591 ddraw
->flags
|= DDRAW_D3D_INITIALIZED
;
592 hr
= wined3d_device_init_3d(ddraw
->wined3d_device
, swapchain_desc
);
595 ddraw
->flags
&= ~DDRAW_D3D_INITIALIZED
;
599 ddraw
->declArraySize
= 2;
600 ddraw
->decls
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ddraw
->decls
) * ddraw
->declArraySize
);
603 ERR("Error allocating an array for the converted vertex decls.\n");
604 ddraw
->declArraySize
= 0;
605 hr
= wined3d_device_uninit_3d(ddraw
->wined3d_device
);
606 return E_OUTOFMEMORY
;
609 TRACE("Successfully initialized 3D.\n");
614 static HRESULT
ddraw_create_swapchain(struct ddraw
*ddraw
, HWND window
, BOOL windowed
)
616 struct wined3d_swapchain_desc swapchain_desc
;
617 struct wined3d_display_mode mode
;
618 HRESULT hr
= WINED3D_OK
;
620 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
622 ERR("Failed to get display mode.\n");
626 memset(&swapchain_desc
, 0, sizeof(swapchain_desc
));
627 swapchain_desc
.backbuffer_width
= mode
.width
;
628 swapchain_desc
.backbuffer_height
= mode
.height
;
629 swapchain_desc
.backbuffer_format
= mode
.format_id
;
630 swapchain_desc
.swap_effect
= WINED3D_SWAP_EFFECT_COPY
;
631 swapchain_desc
.device_window
= window
;
632 swapchain_desc
.windowed
= windowed
;
634 if (!(ddraw
->flags
& DDRAW_NO3D
))
635 hr
= ddraw_attach_d3d_device(ddraw
, &swapchain_desc
);
637 hr
= wined3d_device_init_gdi(ddraw
->wined3d_device
, &swapchain_desc
);
641 ERR("Failed to create swapchain, hr %#x.\n", hr
);
645 if (!(ddraw
->wined3d_swapchain
= wined3d_device_get_swapchain(ddraw
->wined3d_device
, 0)))
647 ERR("Failed to get swapchain.\n");
648 return DDERR_INVALIDPARAMS
;
651 wined3d_swapchain_incref(ddraw
->wined3d_swapchain
);
652 ddraw_set_swapchain_window(ddraw
, window
);
657 /*****************************************************************************
658 * IDirectDraw7::RestoreDisplayMode
660 * Restores the display mode to what it was at creation time. Basically.
664 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
666 *****************************************************************************/
667 static HRESULT WINAPI
ddraw7_RestoreDisplayMode(IDirectDraw7
*iface
)
669 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
672 TRACE("iface %p.\n", iface
);
674 wined3d_mutex_lock();
676 if (!(ddraw
->flags
& DDRAW_RESTORE_MODE
))
678 wined3d_mutex_unlock();
682 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
684 wined3d_mutex_unlock();
685 return DDERR_NOEXCLUSIVEMODE
;
688 if (SUCCEEDED(hr
= wined3d_set_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, NULL
)))
689 ddraw
->flags
&= ~DDRAW_RESTORE_MODE
;
691 wined3d_mutex_unlock();
696 static HRESULT WINAPI
ddraw4_RestoreDisplayMode(IDirectDraw4
*iface
)
698 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
700 TRACE("iface %p.\n", iface
);
702 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
705 static HRESULT WINAPI
ddraw2_RestoreDisplayMode(IDirectDraw2
*iface
)
707 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
709 TRACE("iface %p.\n", iface
);
711 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
714 static HRESULT WINAPI
ddraw1_RestoreDisplayMode(IDirectDraw
*iface
)
716 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
718 TRACE("iface %p.\n", iface
);
720 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
723 /*****************************************************************************
724 * IDirectDraw7::SetCooperativeLevel
726 * Sets the cooperative level for the DirectDraw object, and the window
727 * assigned to it. The cooperative level determines the general behavior
728 * of the DirectDraw application
730 * Warning: This is quite tricky, as it's not really documented which
731 * cooperative levels can be combined with each other. If a game fails
732 * after this function, try to check the cooperative levels passed on
733 * Windows, and if it returns something different.
735 * If you think that this function caused the failure because it writes a
736 * fixme, be sure to run again with a +ddraw trace.
738 * What is known about cooperative levels (See the ddraw modes test):
739 * DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN.
740 * DDSCL_NORMAL is not compatible with DDSCL_EXCLUSIVE.
741 * Unlike what msdn claims, DDSCL_NORMAL | DDSCL_FULLSCREEN is allowed.
742 * DDSCL_SETFOCUSWINDOW can be passed only in DDSCL_NORMAL mode, but after that
743 * DDSCL_EXCLUSIVE can be activated.
744 * DDSCL_SETFOCUSWINDOW may only be used with DDSCL_NOWINDOWCHANGES or
745 * DDSCL_CREATEDEVICEWINDOW.
747 * Handled flags: DDSCL_NORMAL, DDSCL_FULLSCREEN, DDSCL_EXCLUSIVE,
748 * DDSCL_CREATEDEVICEWINDOW, DDSCL_SETDEVICEWINDOW
749 * DDSCL_SETFOCUSWINDOW (partially),
750 * DDSCL_MULTITHREADED (work in progress)
751 * DDSCL_FPUPRESERVE (see device.c)
753 * Unsure about this: DDSCL_FPUSETUP
755 * These don't seem very important for wine:
756 * DDSCL_ALLOWREBOOT, DDSCL_NOWINDOWCHANGES, DDSCL_ALLOWMODEX
759 * DD_OK if the cooperative level was set successfully
760 * DDERR_INVALIDPARAMS if the passed cooperative level combination is invalid
761 * DDERR_HWNDALREADYSET if DDSCL_SETFOCUSWINDOW is passed in exclusive mode
762 * (Probably others too, have to investigate)
764 *****************************************************************************/
765 static HRESULT
ddraw_set_cooperative_level(struct ddraw
*ddraw
, HWND window
,
766 DWORD cooplevel
, BOOL restore_mode_on_normal
)
768 struct wined3d_rendertarget_view
*rtv
= NULL
, *dsv
= NULL
;
769 struct wined3d_stateblock
*stateblock
;
770 BOOL restore_state
= FALSE
;
773 TRACE("ddraw %p, window %p, flags %#x, restore_mode_on_normal %x.\n", ddraw
, window
, cooplevel
,
774 restore_mode_on_normal
);
775 DDRAW_dump_cooperativelevel(cooplevel
);
777 wined3d_mutex_lock();
779 if (ddraw
->flags
& DDRAW_SCL_RECURSIVE
)
781 WARN("Recursive call, returning DD_OK.\n");
785 ddraw
->flags
|= DDRAW_SCL_RECURSIVE
;
787 /* Tests suggest that we need one of them: */
788 if(!(cooplevel
& (DDSCL_SETFOCUSWINDOW
|
792 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
793 hr
= DDERR_INVALIDPARAMS
;
797 if ((cooplevel
& DDSCL_CREATEDEVICEWINDOW
) && !(cooplevel
& DDSCL_EXCLUSIVE
))
799 WARN("DDSCL_CREATEDEVICEWINDOW requires DDSCL_EXCLUSIVE.\n");
800 hr
= DDERR_INVALIDPARAMS
;
804 /* Handle those levels first which set various hwnds */
805 if ((cooplevel
& DDSCL_SETFOCUSWINDOW
) && !(cooplevel
& DDSCL_CREATEDEVICEWINDOW
))
807 /* This isn't compatible with a lot of flags */
808 if (cooplevel
& (DDSCL_MULTITHREADED
813 | DDSCL_SETDEVICEWINDOW
818 WARN("Called with incompatible flags, returning DDERR_INVALIDPARAMS.\n");
819 hr
= DDERR_INVALIDPARAMS
;
823 hr
= ddraw_set_focus_window(ddraw
, window
);
827 if (cooplevel
& DDSCL_EXCLUSIVE
)
829 if (!(cooplevel
& DDSCL_FULLSCREEN
) || !(window
|| (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)))
831 WARN("DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN and a window.\n");
832 hr
= DDERR_INVALIDPARAMS
;
836 if (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)
840 if (!ddraw
->focuswindow
&& !(cooplevel
& DDSCL_SETFOCUSWINDOW
))
842 WARN("No focus window set.\n");
843 hr
= DDERR_NOFOCUSWINDOW
;
847 device_window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "DirectDrawDeviceWnd",
848 WS_POPUP
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
849 NULL
, NULL
, NULL
, NULL
);
852 ERR("Failed to create window, last error %#x.\n", GetLastError());
857 ShowWindow(device_window
, SW_SHOW
);
858 TRACE("Created a device window %p.\n", device_window
);
860 /* Native apparently leaks the created device window if setting the
861 * focus window below fails. */
862 ddraw
->cooperative_level
|= DDSCL_CREATEDEVICEWINDOW
;
863 ddraw
->devicewindow
= device_window
;
865 if (cooplevel
& DDSCL_SETFOCUSWINDOW
)
873 if (FAILED(hr
= ddraw_set_focus_window(ddraw
, window
)))
877 window
= device_window
;
882 if (ddraw
->cooperative_level
& DDSCL_CREATEDEVICEWINDOW
)
883 DestroyWindow(ddraw
->devicewindow
);
884 ddraw
->devicewindow
= NULL
;
885 ddraw
->focuswindow
= NULL
;
888 if ((cooplevel
& DDSCL_FULLSCREEN
) != (ddraw
->cooperative_level
& DDSCL_FULLSCREEN
) || window
!= ddraw
->dest_window
)
890 if (ddraw
->cooperative_level
& DDSCL_FULLSCREEN
)
891 wined3d_device_restore_fullscreen_window(ddraw
->wined3d_device
, ddraw
->dest_window
);
893 if (cooplevel
& DDSCL_FULLSCREEN
)
895 struct wined3d_display_mode display_mode
;
897 wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &display_mode
, NULL
);
898 wined3d_device_setup_fullscreen_window(ddraw
->wined3d_device
, window
,
899 display_mode
.width
, display_mode
.height
);
903 if (cooplevel
& DDSCL_MULTITHREADED
&& !(ddraw
->cooperative_level
& DDSCL_MULTITHREADED
))
904 wined3d_device_set_multithreaded(ddraw
->wined3d_device
);
906 if (ddraw
->wined3d_swapchain
)
908 if (!(ddraw
->flags
& DDRAW_NO3D
))
910 restore_state
= TRUE
;
912 if (FAILED(hr
= wined3d_stateblock_create(ddraw
->wined3d_device
, WINED3D_SBT_ALL
, &stateblock
)))
914 ERR("Failed to create stateblock, hr %#x.\n", hr
);
918 wined3d_stateblock_capture(stateblock
);
919 rtv
= wined3d_device_get_rendertarget_view(ddraw
->wined3d_device
, 0);
920 /* Rendering to ddraw->wined3d_frontbuffer. */
921 if (rtv
&& !wined3d_rendertarget_view_get_sub_resource_parent(rtv
))
924 wined3d_rendertarget_view_incref(rtv
);
926 if ((dsv
= wined3d_device_get_depth_stencil_view(ddraw
->wined3d_device
)))
927 wined3d_rendertarget_view_incref(dsv
);
930 ddraw_destroy_swapchain(ddraw
);
933 if (FAILED(hr
= ddraw_create_swapchain(ddraw
, window
, !(cooplevel
& DDSCL_FULLSCREEN
))))
934 ERR("Failed to create swapchain, hr %#x.\n", hr
);
940 wined3d_device_set_depth_stencil_view(ddraw
->wined3d_device
, dsv
);
941 wined3d_rendertarget_view_decref(dsv
);
946 wined3d_device_set_rendertarget_view(ddraw
->wined3d_device
, 0, rtv
, FALSE
);
947 wined3d_rendertarget_view_decref(rtv
);
950 wined3d_stateblock_apply(stateblock
);
951 wined3d_stateblock_decref(stateblock
);
954 if (!(cooplevel
& DDSCL_EXCLUSIVE
) && (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
955 && restore_mode_on_normal
)
957 hr
= ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
959 ERR("RestoreDisplayMode failed\n");
962 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
963 && (window
!= ddraw
->dest_window
|| !(cooplevel
& DDSCL_EXCLUSIVE
)))
964 wined3d_device_release_focus_window(ddraw
->wined3d_device
);
966 if ((cooplevel
& DDSCL_EXCLUSIVE
)
967 && (window
!= ddraw
->dest_window
|| !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)))
969 hr
= wined3d_device_acquire_focus_window(ddraw
->wined3d_device
, window
);
972 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
977 /* Unhandled flags */
978 if (cooplevel
& DDSCL_ALLOWREBOOT
)
979 WARN("Unhandled flag DDSCL_ALLOWREBOOT, harmless\n");
980 if (cooplevel
& DDSCL_ALLOWMODEX
)
981 WARN("Unhandled flag DDSCL_ALLOWMODEX, harmless\n");
982 if (cooplevel
& DDSCL_FPUSETUP
)
983 WARN("Unhandled flag DDSCL_FPUSETUP, harmless\n");
985 if (cooplevel
& DDSCL_EXCLUSIVE
)
986 exclusive_ddraw
= ddraw
;
987 else if (exclusive_ddraw
== ddraw
)
988 exclusive_ddraw
= NULL
;
990 /* Store the cooperative_level */
991 ddraw
->cooperative_level
= cooplevel
;
992 ddraw
->dest_window
= window
;
994 TRACE("SetCooperativeLevel retuning DD_OK\n");
997 ddraw
->flags
&= ~DDRAW_SCL_RECURSIVE
;
998 wined3d_mutex_unlock();
1003 static HRESULT WINAPI
ddraw7_SetCooperativeLevel(IDirectDraw7
*iface
, HWND window
, DWORD flags
)
1005 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1007 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1009 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1012 static HRESULT WINAPI
ddraw4_SetCooperativeLevel(IDirectDraw4
*iface
, HWND window
, DWORD flags
)
1014 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1016 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1018 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1021 static HRESULT WINAPI
ddraw2_SetCooperativeLevel(IDirectDraw2
*iface
, HWND window
, DWORD flags
)
1023 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1025 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1027 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1030 static HRESULT WINAPI
ddraw1_SetCooperativeLevel(IDirectDraw
*iface
, HWND window
, DWORD flags
)
1032 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1035 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1037 hr
= ddraw_set_cooperative_level(ddraw
, window
, flags
, FALSE
);
1039 ddraw
->flags
|= DDRAW_SCL_DDRAW1
;
1043 /*****************************************************************************
1044 * IDirectDraw7::SetDisplayMode
1046 * Sets the display screen resolution, color depth and refresh frequency
1047 * when in fullscreen mode (in theory).
1048 * Possible return values listed in the SDK suggest that this method fails
1049 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
1050 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
1051 * It seems to be valid to pass 0 for With and Height, this has to be tested
1052 * It could mean that the current video mode should be left as-is. (But why
1056 * Height, Width: Screen dimension
1057 * BPP: Color depth in Bits per pixel
1058 * Refreshrate: Screen refresh rate
1059 * Flags: Other stuff
1064 *****************************************************************************/
1065 static HRESULT WINAPI
ddraw7_SetDisplayMode(IDirectDraw7
*iface
, DWORD width
, DWORD height
,
1066 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1068 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1069 struct wined3d_display_mode mode
;
1070 enum wined3d_format_id format
;
1073 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1074 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1076 if (force_refresh_rate
!= 0)
1078 TRACE("ForceRefreshRate overriding passed-in refresh rate (%u Hz) to %u Hz\n",
1079 refresh_rate
, force_refresh_rate
);
1080 refresh_rate
= force_refresh_rate
;
1083 wined3d_mutex_lock();
1085 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
1087 wined3d_mutex_unlock();
1088 return DDERR_NOEXCLUSIVEMODE
;
1091 if (!width
|| !height
)
1093 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here. */
1094 wined3d_mutex_unlock();
1100 case 8: format
= WINED3DFMT_P8_UINT
; break;
1101 case 15: format
= WINED3DFMT_B5G5R5X1_UNORM
; break;
1102 case 16: format
= WINED3DFMT_B5G6R5_UNORM
; break;
1103 case 24: format
= WINED3DFMT_B8G8R8_UNORM
; break;
1104 case 32: format
= WINED3DFMT_B8G8R8X8_UNORM
; break;
1105 default: format
= WINED3DFMT_UNKNOWN
; break;
1109 mode
.height
= height
;
1110 mode
.refresh_rate
= refresh_rate
;
1111 mode
.format_id
= format
;
1112 mode
.scanline_ordering
= WINED3D_SCANLINE_ORDERING_UNKNOWN
;
1114 /* TODO: The possible return values from msdn suggest that the screen mode
1115 * can't be changed if a surface is locked or some drawing is in progress. */
1116 /* TODO: Lose the primary surface. */
1117 if (SUCCEEDED(hr
= wined3d_set_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
)))
1118 ddraw
->flags
|= DDRAW_RESTORE_MODE
;
1120 wined3d_mutex_unlock();
1124 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1129 static HRESULT WINAPI
ddraw4_SetDisplayMode(IDirectDraw4
*iface
, DWORD width
, DWORD height
,
1130 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1132 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1134 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1135 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1137 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1140 static HRESULT WINAPI
ddraw2_SetDisplayMode(IDirectDraw2
*iface
,
1141 DWORD width
, DWORD height
, DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1143 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1145 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1146 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1148 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1151 static HRESULT WINAPI
ddraw1_SetDisplayMode(IDirectDraw
*iface
, DWORD width
, DWORD height
, DWORD bpp
)
1153 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1155 TRACE("iface %p, width %u, height %u, bpp %u.\n", iface
, width
, height
, bpp
);
1157 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, 0, 0);
1160 void ddraw_d3dcaps1_from_7(D3DDEVICEDESC
*caps1
, D3DDEVICEDESC7
*caps7
)
1162 memset(caps1
, 0, sizeof(*caps1
));
1163 caps1
->dwSize
= sizeof(*caps1
);
1164 caps1
->dwFlags
= D3DDD_COLORMODEL
1166 | D3DDD_TRANSFORMCAPS
1168 | D3DDD_LIGHTINGCAPS
1171 | D3DDD_DEVICERENDERBITDEPTH
1172 | D3DDD_DEVICEZBUFFERBITDEPTH
1173 | D3DDD_MAXBUFFERSIZE
1174 | D3DDD_MAXVERTEXCOUNT
;
1175 caps1
->dcmColorModel
= D3DCOLOR_RGB
;
1176 caps1
->dwDevCaps
= caps7
->dwDevCaps
;
1177 caps1
->dtcTransformCaps
.dwSize
= sizeof(caps1
->dtcTransformCaps
);
1178 caps1
->dtcTransformCaps
.dwCaps
= D3DTRANSFORMCAPS_CLIP
;
1179 caps1
->bClipping
= TRUE
;
1180 caps1
->dlcLightingCaps
.dwSize
= sizeof(caps1
->dlcLightingCaps
);
1181 caps1
->dlcLightingCaps
.dwCaps
= D3DLIGHTCAPS_DIRECTIONAL
1182 | D3DLIGHTCAPS_PARALLELPOINT
1183 | D3DLIGHTCAPS_POINT
1184 | D3DLIGHTCAPS_SPOT
;
1185 caps1
->dlcLightingCaps
.dwLightingModel
= D3DLIGHTINGMODEL_RGB
;
1186 caps1
->dlcLightingCaps
.dwNumLights
= caps7
->dwMaxActiveLights
;
1187 caps1
->dpcLineCaps
= caps7
->dpcLineCaps
;
1188 caps1
->dpcTriCaps
= caps7
->dpcTriCaps
;
1189 caps1
->dwDeviceRenderBitDepth
= caps7
->dwDeviceRenderBitDepth
;
1190 caps1
->dwDeviceZBufferBitDepth
= caps7
->dwDeviceZBufferBitDepth
;
1191 caps1
->dwMaxBufferSize
= 0;
1192 caps1
->dwMaxVertexCount
= 65536;
1193 caps1
->dwMinTextureWidth
= caps7
->dwMinTextureWidth
;
1194 caps1
->dwMinTextureHeight
= caps7
->dwMinTextureHeight
;
1195 caps1
->dwMaxTextureWidth
= caps7
->dwMaxTextureWidth
;
1196 caps1
->dwMaxTextureHeight
= caps7
->dwMaxTextureHeight
;
1197 caps1
->dwMinStippleWidth
= 1;
1198 caps1
->dwMinStippleHeight
= 1;
1199 caps1
->dwMaxStippleWidth
= 32;
1200 caps1
->dwMaxStippleHeight
= 32;
1201 caps1
->dwMaxTextureRepeat
= caps7
->dwMaxTextureRepeat
;
1202 caps1
->dwMaxTextureAspectRatio
= caps7
->dwMaxTextureAspectRatio
;
1203 caps1
->dwMaxAnisotropy
= caps7
->dwMaxAnisotropy
;
1204 caps1
->dvGuardBandLeft
= caps7
->dvGuardBandLeft
;
1205 caps1
->dvGuardBandTop
= caps7
->dvGuardBandTop
;
1206 caps1
->dvGuardBandRight
= caps7
->dvGuardBandRight
;
1207 caps1
->dvGuardBandBottom
= caps7
->dvGuardBandBottom
;
1208 caps1
->dvExtentsAdjust
= caps7
->dvExtentsAdjust
;
1209 caps1
->dwStencilCaps
= caps7
->dwStencilCaps
;
1210 caps1
->dwFVFCaps
= caps7
->dwFVFCaps
;
1211 caps1
->dwTextureOpCaps
= caps7
->dwTextureOpCaps
;
1212 caps1
->wMaxTextureBlendStages
= caps7
->wMaxTextureBlendStages
;
1213 caps1
->wMaxSimultaneousTextures
= caps7
->wMaxSimultaneousTextures
;
1216 HRESULT
ddraw_get_d3dcaps(const struct ddraw
*ddraw
, D3DDEVICEDESC7
*caps
)
1218 WINED3DCAPS wined3d_caps
;
1221 TRACE("ddraw %p, caps %p.\n", ddraw
, caps
);
1223 memset(&wined3d_caps
, 0, sizeof(wined3d_caps
));
1225 wined3d_mutex_lock();
1226 hr
= wined3d_get_device_caps(ddraw
->wined3d
, 0, WINED3D_DEVICE_TYPE_HAL
, &wined3d_caps
);
1227 wined3d_mutex_unlock();
1230 WARN("Failed to get device caps, hr %#x.\n", hr
);
1234 caps
->dwDevCaps
= wined3d_caps
.DevCaps
;
1235 caps
->dpcLineCaps
.dwMiscCaps
= wined3d_caps
.PrimitiveMiscCaps
;
1236 caps
->dpcLineCaps
.dwRasterCaps
= wined3d_caps
.RasterCaps
;
1237 caps
->dpcLineCaps
.dwZCmpCaps
= wined3d_caps
.ZCmpCaps
;
1238 caps
->dpcLineCaps
.dwSrcBlendCaps
= wined3d_caps
.SrcBlendCaps
;
1239 caps
->dpcLineCaps
.dwDestBlendCaps
= wined3d_caps
.DestBlendCaps
;
1240 caps
->dpcLineCaps
.dwAlphaCmpCaps
= wined3d_caps
.AlphaCmpCaps
;
1241 caps
->dpcLineCaps
.dwShadeCaps
= wined3d_caps
.ShadeCaps
;
1242 caps
->dpcLineCaps
.dwTextureCaps
= wined3d_caps
.TextureCaps
;
1243 caps
->dpcLineCaps
.dwTextureFilterCaps
= wined3d_caps
.TextureFilterCaps
;
1244 caps
->dpcLineCaps
.dwTextureAddressCaps
= wined3d_caps
.TextureAddressCaps
;
1246 caps
->dwMaxTextureWidth
= wined3d_caps
.MaxTextureWidth
;
1247 caps
->dwMaxTextureHeight
= wined3d_caps
.MaxTextureHeight
;
1249 caps
->dwMaxTextureRepeat
= wined3d_caps
.MaxTextureRepeat
;
1250 caps
->dwMaxTextureAspectRatio
= wined3d_caps
.MaxTextureAspectRatio
;
1251 caps
->dwMaxAnisotropy
= wined3d_caps
.MaxAnisotropy
;
1252 caps
->dvMaxVertexW
= wined3d_caps
.MaxVertexW
;
1254 caps
->dvGuardBandLeft
= wined3d_caps
.GuardBandLeft
;
1255 caps
->dvGuardBandTop
= wined3d_caps
.GuardBandTop
;
1256 caps
->dvGuardBandRight
= wined3d_caps
.GuardBandRight
;
1257 caps
->dvGuardBandBottom
= wined3d_caps
.GuardBandBottom
;
1259 caps
->dvExtentsAdjust
= wined3d_caps
.ExtentsAdjust
;
1260 caps
->dwStencilCaps
= wined3d_caps
.StencilCaps
;
1262 caps
->dwFVFCaps
= wined3d_caps
.FVFCaps
;
1263 caps
->dwTextureOpCaps
= wined3d_caps
.TextureOpCaps
;
1265 caps
->dwVertexProcessingCaps
= wined3d_caps
.VertexProcessingCaps
;
1266 caps
->dwMaxActiveLights
= wined3d_caps
.MaxActiveLights
;
1268 /* Remove all non-d3d7 caps */
1269 caps
->dwDevCaps
&= (
1270 D3DDEVCAPS_FLOATTLVERTEX
| D3DDEVCAPS_SORTINCREASINGZ
| D3DDEVCAPS_SORTDECREASINGZ
|
1271 D3DDEVCAPS_SORTEXACT
| D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
|
1272 D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
| D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
|
1273 D3DDEVCAPS_TEXTUREVIDEOMEMORY
| D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
|
1274 D3DDEVCAPS_TEXTURENONLOCALVIDMEM
| D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
1275 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
1276 D3DDEVCAPS_HWRASTERIZATION
);
1278 caps
->dwStencilCaps
&= (
1279 D3DSTENCILCAPS_KEEP
| D3DSTENCILCAPS_ZERO
| D3DSTENCILCAPS_REPLACE
|
1280 D3DSTENCILCAPS_INCRSAT
| D3DSTENCILCAPS_DECRSAT
| D3DSTENCILCAPS_INVERT
|
1281 D3DSTENCILCAPS_INCR
| D3DSTENCILCAPS_DECR
);
1285 caps
->dwTextureOpCaps
&= (
1286 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_SELECTARG2
|
1287 D3DTEXOPCAPS_MODULATE
| D3DTEXOPCAPS_MODULATE2X
| D3DTEXOPCAPS_MODULATE4X
|
1288 D3DTEXOPCAPS_ADD
| D3DTEXOPCAPS_ADDSIGNED
| D3DTEXOPCAPS_ADDSIGNED2X
|
1289 D3DTEXOPCAPS_SUBTRACT
| D3DTEXOPCAPS_ADDSMOOTH
| D3DTEXOPCAPS_BLENDTEXTUREALPHA
|
1290 D3DTEXOPCAPS_BLENDFACTORALPHA
| D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
| D3DTEXOPCAPS_BLENDCURRENTALPHA
|
1291 D3DTEXOPCAPS_PREMODULATE
| D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
|
1292 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
| D3DTEXOPCAPS_BUMPENVMAP
|
1293 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
| D3DTEXOPCAPS_DOTPRODUCT3
);
1295 caps
->dwVertexProcessingCaps
&= (
1296 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_VERTEXFOG
|
1297 D3DVTXPCAPS_DIRECTIONALLIGHTS
| D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
);
1299 caps
->dpcLineCaps
.dwMiscCaps
&= (
1300 D3DPMISCCAPS_MASKPLANES
| D3DPMISCCAPS_MASKZ
| D3DPMISCCAPS_LINEPATTERNREP
|
1301 D3DPMISCCAPS_CONFORMANT
| D3DPMISCCAPS_CULLNONE
| D3DPMISCCAPS_CULLCW
|
1302 D3DPMISCCAPS_CULLCCW
);
1304 caps
->dpcLineCaps
.dwRasterCaps
&= (
1305 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ROP2
| D3DPRASTERCAPS_XOR
|
1306 D3DPRASTERCAPS_PAT
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_SUBPIXEL
|
1307 D3DPRASTERCAPS_SUBPIXELX
| D3DPRASTERCAPS_FOGVERTEX
| D3DPRASTERCAPS_FOGTABLE
|
1308 D3DPRASTERCAPS_STIPPLE
| D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT
| D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT
|
1309 D3DPRASTERCAPS_ANTIALIASEDGES
| D3DPRASTERCAPS_MIPMAPLODBIAS
| D3DPRASTERCAPS_ZBIAS
|
1310 D3DPRASTERCAPS_ZBUFFERLESSHSR
| D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
|
1311 D3DPRASTERCAPS_WBUFFER
| D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT
| D3DPRASTERCAPS_WFOG
|
1312 D3DPRASTERCAPS_ZFOG
);
1314 caps
->dpcLineCaps
.dwZCmpCaps
&= (
1315 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
1316 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
1317 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
1319 caps
->dpcLineCaps
.dwSrcBlendCaps
&= (
1320 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
1321 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
1322 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
1323 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
1324 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
1326 caps
->dpcLineCaps
.dwDestBlendCaps
&= (
1327 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
1328 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
1329 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
1330 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
1331 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
1333 caps
->dpcLineCaps
.dwAlphaCmpCaps
&= (
1334 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
1335 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
1336 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
1338 caps
->dpcLineCaps
.dwShadeCaps
&= (
1339 D3DPSHADECAPS_COLORFLATMONO
| D3DPSHADECAPS_COLORFLATRGB
| D3DPSHADECAPS_COLORGOURAUDMONO
|
1340 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_COLORPHONGMONO
| D3DPSHADECAPS_COLORPHONGRGB
|
1341 D3DPSHADECAPS_SPECULARFLATMONO
| D3DPSHADECAPS_SPECULARFLATRGB
| D3DPSHADECAPS_SPECULARGOURAUDMONO
|
1342 D3DPSHADECAPS_SPECULARGOURAUDRGB
| D3DPSHADECAPS_SPECULARPHONGMONO
| D3DPSHADECAPS_SPECULARPHONGRGB
|
1343 D3DPSHADECAPS_ALPHAFLATBLEND
| D3DPSHADECAPS_ALPHAFLATSTIPPLED
| D3DPSHADECAPS_ALPHAGOURAUDBLEND
|
1344 D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED
| D3DPSHADECAPS_ALPHAPHONGBLEND
| D3DPSHADECAPS_ALPHAPHONGSTIPPLED
|
1345 D3DPSHADECAPS_FOGFLAT
| D3DPSHADECAPS_FOGGOURAUD
| D3DPSHADECAPS_FOGPHONG
);
1347 caps
->dpcLineCaps
.dwTextureCaps
&= (
1348 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
1349 D3DPTEXTURECAPS_TRANSPARENCY
| D3DPTEXTURECAPS_BORDER
| D3DPTEXTURECAPS_SQUAREONLY
|
1350 D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
| D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
1351 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_COLORKEYBLEND
);
1353 caps
->dpcLineCaps
.dwTextureFilterCaps
&= (
1354 D3DPTFILTERCAPS_NEAREST
| D3DPTFILTERCAPS_LINEAR
| D3DPTFILTERCAPS_MIPNEAREST
|
1355 D3DPTFILTERCAPS_MIPLINEAR
| D3DPTFILTERCAPS_LINEARMIPNEAREST
| D3DPTFILTERCAPS_LINEARMIPLINEAR
|
1356 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
1357 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
1358 D3DPTFILTERCAPS_MAGFLINEAR
| D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
|
1359 D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
);
1361 caps
->dpcLineCaps
.dwTextureAddressCaps
&= (
1362 D3DPTADDRESSCAPS_WRAP
| D3DPTADDRESSCAPS_MIRROR
| D3DPTADDRESSCAPS_CLAMP
|
1363 D3DPTADDRESSCAPS_BORDER
| D3DPTADDRESSCAPS_INDEPENDENTUV
);
1365 if (!(caps
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
))
1367 /* DirectX7 always has the np2 flag set, no matter what the card
1368 * supports. Some old games (Rollcage) check the caps incorrectly.
1369 * If wined3d supports nonpow2 textures it also has np2 conditional
1371 caps
->dpcLineCaps
.dwTextureCaps
|= D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
;
1374 /* Fill the missing members, and do some fixup */
1375 caps
->dpcLineCaps
.dwSize
= sizeof(caps
->dpcLineCaps
);
1376 caps
->dpcLineCaps
.dwTextureBlendCaps
= D3DPTBLENDCAPS_ADD
1377 | D3DPTBLENDCAPS_MODULATEMASK
1378 | D3DPTBLENDCAPS_COPY
1379 | D3DPTBLENDCAPS_DECAL
1380 | D3DPTBLENDCAPS_DECALALPHA
1381 | D3DPTBLENDCAPS_DECALMASK
1382 | D3DPTBLENDCAPS_MODULATE
1383 | D3DPTBLENDCAPS_MODULATEALPHA
;
1384 caps
->dpcLineCaps
.dwStippleWidth
= 32;
1385 caps
->dpcLineCaps
.dwStippleHeight
= 32;
1386 /* Use the same for the TriCaps */
1387 caps
->dpcTriCaps
= caps
->dpcLineCaps
;
1389 caps
->dwDeviceRenderBitDepth
= DDBD_16
| DDBD_24
| DDBD_32
;
1390 caps
->dwDeviceZBufferBitDepth
= DDBD_16
| DDBD_24
;
1391 caps
->dwMinTextureWidth
= 1;
1392 caps
->dwMinTextureHeight
= 1;
1394 /* Convert DWORDs safely to WORDs */
1395 if (wined3d_caps
.MaxTextureBlendStages
> 0xffff)
1396 caps
->wMaxTextureBlendStages
= 0xffff;
1398 caps
->wMaxTextureBlendStages
= (WORD
)wined3d_caps
.MaxTextureBlendStages
;
1399 if (wined3d_caps
.MaxSimultaneousTextures
> 0xffff)
1400 caps
->wMaxSimultaneousTextures
= 0xffff;
1402 caps
->wMaxSimultaneousTextures
= (WORD
)wined3d_caps
.MaxSimultaneousTextures
;
1404 if (wined3d_caps
.MaxUserClipPlanes
> 0xffff)
1405 caps
->wMaxUserClipPlanes
= 0xffff;
1407 caps
->wMaxUserClipPlanes
= (WORD
)wined3d_caps
.MaxUserClipPlanes
;
1408 if (wined3d_caps
.MaxVertexBlendMatrices
> 0xffff)
1409 caps
->wMaxVertexBlendMatrices
= 0xffff;
1411 caps
->wMaxVertexBlendMatrices
= (WORD
)wined3d_caps
.MaxVertexBlendMatrices
;
1413 caps
->deviceGUID
= IID_IDirect3DTnLHalDevice
;
1415 caps
->dwReserved1
= 0;
1416 caps
->dwReserved2
= 0;
1417 caps
->dwReserved3
= 0;
1418 caps
->dwReserved4
= 0;
1423 /*****************************************************************************
1424 * IDirectDraw7::GetCaps
1426 * Returns the drives capabilities
1428 * Used for version 1, 2, 4 and 7
1431 * DriverCaps: Structure to write the Hardware accelerated caps to
1432 * HelCaps: Structure to write the emulation caps to
1435 * This implementation returns DD_OK only
1437 *****************************************************************************/
1438 static HRESULT WINAPI
ddraw7_GetCaps(IDirectDraw7
*iface
, DDCAPS
*DriverCaps
, DDCAPS
*HELCaps
)
1440 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1442 WINED3DCAPS winecaps
;
1444 DDSCAPS2 ddscaps
= {0, 0, 0, {0}};
1446 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, DriverCaps
, HELCaps
);
1448 /* One structure must be != NULL */
1449 if (!DriverCaps
&& !HELCaps
)
1451 WARN("Invalid parameters.\n");
1452 return DDERR_INVALIDPARAMS
;
1455 memset(&caps
, 0, sizeof(caps
));
1456 memset(&winecaps
, 0, sizeof(winecaps
));
1457 caps
.dwSize
= sizeof(caps
);
1459 wined3d_mutex_lock();
1460 hr
= wined3d_device_get_device_caps(ddraw
->wined3d_device
, &winecaps
);
1463 WARN("IWineD3DDevice::GetDeviceCaps failed\n");
1464 wined3d_mutex_unlock();
1468 hr
= IDirectDraw7_GetAvailableVidMem(iface
, &ddscaps
, &caps
.dwVidMemTotal
, &caps
.dwVidMemFree
);
1471 WARN("IDirectDraw7::GetAvailableVidMem failed\n");
1472 wined3d_mutex_unlock();
1476 hr
= IDirectDraw7_GetFourCCCodes(iface
, &caps
.dwNumFourCCCodes
, NULL
);
1477 wined3d_mutex_unlock();
1480 WARN("IDirectDraw7::GetFourCCCodes failed\n");
1484 caps
.dwCaps
= winecaps
.ddraw_caps
.caps
;
1485 caps
.dwCaps2
= winecaps
.ddraw_caps
.caps2
;
1486 caps
.dwCKeyCaps
= winecaps
.ddraw_caps
.color_key_caps
;
1487 caps
.dwFXCaps
= winecaps
.ddraw_caps
.fx_caps
;
1488 caps
.dwPalCaps
= DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
;
1489 caps
.ddsCaps
.dwCaps
= winecaps
.ddraw_caps
.dds_caps
;
1490 caps
.dwSVBCaps
= winecaps
.ddraw_caps
.svb_caps
;
1491 caps
.dwSVBCKeyCaps
= winecaps
.ddraw_caps
.svb_color_key_caps
;
1492 caps
.dwSVBFXCaps
= winecaps
.ddraw_caps
.svb_fx_caps
;
1493 caps
.dwVSBCaps
= winecaps
.ddraw_caps
.vsb_caps
;
1494 caps
.dwVSBCKeyCaps
= winecaps
.ddraw_caps
.vsb_color_key_caps
;
1495 caps
.dwVSBFXCaps
= winecaps
.ddraw_caps
.vsb_fx_caps
;
1496 caps
.dwSSBCaps
= winecaps
.ddraw_caps
.ssb_caps
;
1497 caps
.dwSSBCKeyCaps
= winecaps
.ddraw_caps
.ssb_color_key_caps
;
1498 caps
.dwSSBFXCaps
= winecaps
.ddraw_caps
.ssb_fx_caps
;
1500 caps
.dwCaps
|= DDCAPS_ALIGNSTRIDE
;
1501 caps
.dwAlignStrideAlign
= DDRAW_STRIDE_ALIGNMENT
;
1505 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &caps
);
1506 if (TRACE_ON(ddraw
))
1508 TRACE("Driver Caps :\n");
1509 DDRAW_dump_DDCAPS(DriverCaps
);
1515 DD_STRUCT_COPY_BYSIZE(HELCaps
, &caps
);
1516 if (TRACE_ON(ddraw
))
1518 TRACE("HEL Caps :\n");
1519 DDRAW_dump_DDCAPS(HELCaps
);
1526 static HRESULT WINAPI
ddraw4_GetCaps(IDirectDraw4
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1528 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1530 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1532 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1535 static HRESULT WINAPI
ddraw2_GetCaps(IDirectDraw2
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1537 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1539 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1541 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1544 static HRESULT WINAPI
ddraw1_GetCaps(IDirectDraw
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1546 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1548 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1550 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1553 /*****************************************************************************
1554 * IDirectDraw7::Compact
1556 * No idea what it does, MSDN says it's not implemented.
1559 * DD_OK, but this is unchecked
1561 *****************************************************************************/
1562 static HRESULT WINAPI
ddraw7_Compact(IDirectDraw7
*iface
)
1564 TRACE("iface %p.\n", iface
);
1569 static HRESULT WINAPI
ddraw4_Compact(IDirectDraw4
*iface
)
1571 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1573 TRACE("iface %p.\n", iface
);
1575 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1578 static HRESULT WINAPI
ddraw2_Compact(IDirectDraw2
*iface
)
1580 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1582 TRACE("iface %p.\n", iface
);
1584 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1587 static HRESULT WINAPI
ddraw1_Compact(IDirectDraw
*iface
)
1589 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1591 TRACE("iface %p.\n", iface
);
1593 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1596 /*****************************************************************************
1597 * IDirectDraw7::GetDisplayMode
1599 * Returns information about the current display mode
1601 * Exists in Version 1, 2, 4 and 7
1604 * DDSD: Address of a surface description structure to write the info to
1609 *****************************************************************************/
1610 static HRESULT WINAPI
ddraw7_GetDisplayMode(IDirectDraw7
*iface
, DDSURFACEDESC2
*DDSD
)
1612 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1613 struct wined3d_display_mode mode
;
1617 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
1619 wined3d_mutex_lock();
1620 /* This seems sane */
1623 wined3d_mutex_unlock();
1624 return DDERR_INVALIDPARAMS
;
1627 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1629 ERR("Failed to get display mode, hr %#x.\n", hr
);
1630 wined3d_mutex_unlock();
1634 Size
= DDSD
->dwSize
;
1635 memset(DDSD
, 0, Size
);
1637 DDSD
->dwSize
= Size
;
1638 DDSD
->dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
1639 DDSD
->dwWidth
= mode
.width
;
1640 DDSD
->dwHeight
= mode
.height
;
1641 DDSD
->u2
.dwRefreshRate
= 60;
1642 DDSD
->ddsCaps
.dwCaps
= 0;
1643 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
1644 ddrawformat_from_wined3dformat(&DDSD
->u4
.ddpfPixelFormat
, mode
.format_id
);
1645 DDSD
->u1
.lPitch
= mode
.width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
1649 TRACE("Returning surface desc :\n");
1650 DDRAW_dump_surface_desc(DDSD
);
1653 wined3d_mutex_unlock();
1658 static HRESULT WINAPI
ddraw4_GetDisplayMode(IDirectDraw4
*iface
, DDSURFACEDESC2
*surface_desc
)
1660 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1662 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1664 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, surface_desc
);
1667 static HRESULT WINAPI
ddraw2_GetDisplayMode(IDirectDraw2
*iface
, DDSURFACEDESC
*surface_desc
)
1669 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1671 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1673 /* FIXME: Test sizes, properly convert surface_desc */
1674 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1677 static HRESULT WINAPI
ddraw1_GetDisplayMode(IDirectDraw
*iface
, DDSURFACEDESC
*surface_desc
)
1679 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1681 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1683 /* FIXME: Test sizes, properly convert surface_desc */
1684 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1687 /*****************************************************************************
1688 * IDirectDraw7::GetFourCCCodes
1690 * Returns an array of supported FourCC codes.
1692 * Exists in Version 1, 2, 4 and 7
1695 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
1696 * of enumerated codes
1697 * Codes: Pointer to an array of DWORDs where the supported codes are written
1701 * Always returns DD_OK, as it's a stub for now
1703 *****************************************************************************/
1704 static HRESULT WINAPI
ddraw7_GetFourCCCodes(IDirectDraw7
*iface
, DWORD
*NumCodes
, DWORD
*Codes
)
1706 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1707 static const enum wined3d_format_id formats
[] =
1709 WINED3DFMT_YUY2
, WINED3DFMT_UYVY
, WINED3DFMT_YV12
,
1710 WINED3DFMT_DXT1
, WINED3DFMT_DXT2
, WINED3DFMT_DXT3
, WINED3DFMT_DXT4
, WINED3DFMT_DXT5
,
1711 WINED3DFMT_ATI2N
, WINED3DFMT_NVHU
, WINED3DFMT_NVHS
1713 struct wined3d_display_mode mode
;
1714 DWORD count
= 0, i
, outsize
;
1717 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, NumCodes
, Codes
);
1719 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1721 ERR("Failed to get display mode, hr %#x.\n", hr
);
1725 outsize
= NumCodes
&& Codes
? *NumCodes
: 0;
1727 for (i
= 0; i
< (sizeof(formats
) / sizeof(formats
[0])); ++i
)
1729 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, WINED3D_DEVICE_TYPE_HAL
,
1730 mode
.format_id
, 0, WINED3D_RTYPE_SURFACE
, formats
[i
])))
1732 if (count
< outsize
)
1733 Codes
[count
] = formats
[i
];
1738 TRACE("Returning %u FourCC codes\n", count
);
1745 static HRESULT WINAPI
ddraw4_GetFourCCCodes(IDirectDraw4
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1747 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1749 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1751 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1754 static HRESULT WINAPI
ddraw2_GetFourCCCodes(IDirectDraw2
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1756 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1758 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1760 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1763 static HRESULT WINAPI
ddraw1_GetFourCCCodes(IDirectDraw
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1765 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1767 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1769 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1772 static HRESULT WINAPI
ddraw7_GetMonitorFrequency(IDirectDraw7
*iface
, DWORD
*frequency
)
1774 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1775 struct wined3d_display_mode mode
;
1778 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1780 wined3d_mutex_lock();
1781 hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
);
1782 wined3d_mutex_unlock();
1785 WARN("Failed to get display mode, hr %#x.\n", hr
);
1789 *frequency
= mode
.refresh_rate
;
1794 static HRESULT WINAPI
ddraw4_GetMonitorFrequency(IDirectDraw4
*iface
, DWORD
*frequency
)
1796 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1798 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1800 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1803 static HRESULT WINAPI
ddraw2_GetMonitorFrequency(IDirectDraw2
*iface
, DWORD
*frequency
)
1805 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1807 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1809 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1812 static HRESULT WINAPI
ddraw1_GetMonitorFrequency(IDirectDraw
*iface
, DWORD
*frequency
)
1814 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1816 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1818 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1821 static HRESULT WINAPI
ddraw7_GetVerticalBlankStatus(IDirectDraw7
*iface
, BOOL
*status
)
1823 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1824 struct wined3d_raster_status raster_status
;
1827 TRACE("iface %p, status %p.\n", iface
, status
);
1830 return DDERR_INVALIDPARAMS
;
1832 wined3d_mutex_lock();
1833 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
1834 wined3d_mutex_unlock();
1837 WARN("Failed to get raster status, hr %#x.\n", hr
);
1841 *status
= raster_status
.in_vblank
;
1846 static HRESULT WINAPI
ddraw4_GetVerticalBlankStatus(IDirectDraw4
*iface
, BOOL
*status
)
1848 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1850 TRACE("iface %p, status %p.\n", iface
, status
);
1852 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1855 static HRESULT WINAPI
ddraw2_GetVerticalBlankStatus(IDirectDraw2
*iface
, BOOL
*status
)
1857 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1859 TRACE("iface %p, status %p.\n", iface
, status
);
1861 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1864 static HRESULT WINAPI
ddraw1_GetVerticalBlankStatus(IDirectDraw
*iface
, BOOL
*status
)
1866 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1868 TRACE("iface %p, status %p.\n", iface
, status
);
1870 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1873 /*****************************************************************************
1874 * IDirectDraw7::GetAvailableVidMem
1876 * Returns the total and free video memory
1879 * Caps: Specifies the memory type asked for
1880 * total: Pointer to a DWORD to be filled with the total memory
1881 * free: Pointer to a DWORD to be filled with the free memory
1885 * DDERR_INVALIDPARAMS if free and total are NULL
1887 *****************************************************************************/
1888 static HRESULT WINAPI
ddraw7_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*Caps
, DWORD
*total
,
1891 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1894 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, Caps
, total
, free
);
1896 if (TRACE_ON(ddraw
))
1898 TRACE("Asked for memory with description: ");
1899 DDRAW_dump_DDSCAPS2(Caps
);
1901 wined3d_mutex_lock();
1903 /* Todo: System memory vs local video memory vs non-local video memory
1904 * The MSDN also mentions differences between texture memory and other
1905 * resources, but that's not important
1908 if( (!total
) && (!free
) )
1910 wined3d_mutex_unlock();
1911 return DDERR_INVALIDPARAMS
;
1915 *free
= wined3d_device_get_available_texture_mem(ddraw
->wined3d_device
);
1918 struct wined3d_adapter_identifier desc
= {0};
1920 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0, &desc
);
1921 *total
= min(UINT_MAX
, desc
.video_memory
);
1924 wined3d_mutex_unlock();
1929 static HRESULT WINAPI
ddraw4_GetAvailableVidMem(IDirectDraw4
*iface
,
1930 DDSCAPS2
*caps
, DWORD
*total
, DWORD
*free
)
1932 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1934 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1936 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, caps
, total
, free
);
1939 static HRESULT WINAPI
ddraw2_GetAvailableVidMem(IDirectDraw2
*iface
,
1940 DDSCAPS
*caps
, DWORD
*total
, DWORD
*free
)
1942 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1945 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1947 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
1948 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, &caps2
, total
, free
);
1951 /*****************************************************************************
1952 * IDirectDraw7::Initialize
1954 * Initializes a DirectDraw interface.
1957 * GUID: Interface identifier. Well, don't know what this is really good
1961 * Returns DD_OK on the first call,
1962 * DDERR_ALREADYINITIALIZED on repeated calls
1964 *****************************************************************************/
1965 static HRESULT WINAPI
ddraw7_Initialize(IDirectDraw7
*iface
, GUID
*guid
)
1967 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1969 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1971 if (ddraw
->flags
& DDRAW_INITIALIZED
)
1972 return DDERR_ALREADYINITIALIZED
;
1974 /* FIXME: To properly take the GUID into account we should call
1975 * ddraw_init() here instead of in DDRAW_Create(). */
1977 FIXME("Ignoring guid %s.\n", debugstr_guid(guid
));
1979 ddraw
->flags
|= DDRAW_INITIALIZED
;
1983 static HRESULT WINAPI
ddraw4_Initialize(IDirectDraw4
*iface
, GUID
*guid
)
1985 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1987 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1989 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
1992 static HRESULT WINAPI
ddraw2_Initialize(IDirectDraw2
*iface
, GUID
*guid
)
1994 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1996 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1998 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2001 static HRESULT WINAPI
ddraw1_Initialize(IDirectDraw
*iface
, GUID
*guid
)
2003 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2005 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2007 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2010 static HRESULT WINAPI
d3d1_Initialize(IDirect3D
*iface
, REFIID riid
)
2012 TRACE("iface %p, riid %s.\n", iface
, debugstr_guid(riid
));
2014 return DDERR_ALREADYINITIALIZED
;
2017 /*****************************************************************************
2018 * IDirectDraw7::FlipToGDISurface
2020 * "Makes the surface that the GDI writes to the primary surface"
2021 * Looks like some windows specific thing we don't have to care about.
2022 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
2023 * show error boxes ;)
2024 * Well, just return DD_OK.
2027 * Always returns DD_OK
2029 *****************************************************************************/
2030 static HRESULT WINAPI
ddraw7_FlipToGDISurface(IDirectDraw7
*iface
)
2032 FIXME("iface %p stub!\n", iface
);
2037 static HRESULT WINAPI
ddraw4_FlipToGDISurface(IDirectDraw4
*iface
)
2039 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2041 TRACE("iface %p.\n", iface
);
2043 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2046 static HRESULT WINAPI
ddraw2_FlipToGDISurface(IDirectDraw2
*iface
)
2048 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2050 TRACE("iface %p.\n", iface
);
2052 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2055 static HRESULT WINAPI
ddraw1_FlipToGDISurface(IDirectDraw
*iface
)
2057 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2059 TRACE("iface %p.\n", iface
);
2061 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2064 /*****************************************************************************
2065 * IDirectDraw7::WaitForVerticalBlank
2067 * This method allows applications to get in sync with the vertical blank
2069 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
2070 * redraw the screen, most likely because of this stub
2073 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
2074 * or DDWAITVB_BLOCKEND
2075 * h: Not used, according to MSDN
2078 * Always returns DD_OK
2080 *****************************************************************************/
2081 static HRESULT WINAPI
ddraw7_WaitForVerticalBlank(IDirectDraw7
*iface
, DWORD Flags
, HANDLE event
)
2085 TRACE("iface %p, flags %#x, event %p.\n", iface
, Flags
, event
);
2087 /* This function is called often, so print the fixme only once */
2090 FIXME("iface %p, flags %#x, event %p stub!\n", iface
, Flags
, event
);
2094 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
2095 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
2096 return DDERR_UNSUPPORTED
; /* unchecked */
2101 static HRESULT WINAPI
ddraw4_WaitForVerticalBlank(IDirectDraw4
*iface
, DWORD flags
, HANDLE event
)
2103 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2105 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2107 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2110 static HRESULT WINAPI
ddraw2_WaitForVerticalBlank(IDirectDraw2
*iface
, DWORD flags
, HANDLE event
)
2112 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2114 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2116 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2119 static HRESULT WINAPI
ddraw1_WaitForVerticalBlank(IDirectDraw
*iface
, DWORD flags
, HANDLE event
)
2121 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2123 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2125 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2128 static HRESULT WINAPI
ddraw7_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
2130 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2131 struct wined3d_raster_status raster_status
;
2134 TRACE("iface %p, line %p.\n", iface
, Scanline
);
2136 wined3d_mutex_lock();
2137 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
2138 wined3d_mutex_unlock();
2141 WARN("Failed to get raster status, hr %#x.\n", hr
);
2145 *Scanline
= raster_status
.scan_line
;
2147 if (raster_status
.in_vblank
)
2148 return DDERR_VERTICALBLANKINPROGRESS
;
2153 static HRESULT WINAPI
ddraw4_GetScanLine(IDirectDraw4
*iface
, DWORD
*line
)
2155 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2157 TRACE("iface %p, line %p.\n", iface
, line
);
2159 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2162 static HRESULT WINAPI
ddraw2_GetScanLine(IDirectDraw2
*iface
, DWORD
*line
)
2164 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2166 TRACE("iface %p, line %p.\n", iface
, line
);
2168 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2171 static HRESULT WINAPI
ddraw1_GetScanLine(IDirectDraw
*iface
, DWORD
*line
)
2173 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2175 TRACE("iface %p, line %p.\n", iface
, line
);
2177 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2180 static HRESULT WINAPI
ddraw7_TestCooperativeLevel(IDirectDraw7
*iface
)
2182 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2184 TRACE("iface %p.\n", iface
);
2186 return ddraw
->device_state
== DDRAW_DEVICE_STATE_OK
? DD_OK
: DDERR_NOEXCLUSIVEMODE
;
2189 static HRESULT WINAPI
ddraw4_TestCooperativeLevel(IDirectDraw4
*iface
)
2191 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2193 TRACE("iface %p.\n", iface
);
2195 return ddraw7_TestCooperativeLevel(&ddraw
->IDirectDraw7_iface
);
2198 /*****************************************************************************
2199 * IDirectDraw7::GetGDISurface
2201 * Returns the surface that GDI is treating as the primary surface.
2202 * For Wine this is the front buffer
2205 * GDISurface: Address to write the surface pointer to
2208 * DD_OK if the surface was found
2209 * DDERR_NOTFOUND if the GDI surface wasn't found
2211 *****************************************************************************/
2212 static HRESULT WINAPI
ddraw7_GetGDISurface(IDirectDraw7
*iface
, IDirectDrawSurface7
**GDISurface
)
2214 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2216 TRACE("iface %p, surface %p.\n", iface
, GDISurface
);
2218 wined3d_mutex_lock();
2220 if (!(*GDISurface
= &ddraw
->primary
->IDirectDrawSurface7_iface
))
2222 WARN("Primary not created yet.\n");
2223 wined3d_mutex_unlock();
2224 return DDERR_NOTFOUND
;
2226 IDirectDrawSurface7_AddRef(*GDISurface
);
2228 wined3d_mutex_unlock();
2233 static HRESULT WINAPI
ddraw4_GetGDISurface(IDirectDraw4
*iface
, IDirectDrawSurface4
**surface
)
2235 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2236 struct ddraw_surface
*surface_impl
;
2237 IDirectDrawSurface7
*surface7
;
2240 TRACE("iface %p, surface %p.\n", iface
, surface
);
2242 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2248 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2249 *surface
= &surface_impl
->IDirectDrawSurface4_iface
;
2250 IDirectDrawSurface4_AddRef(*surface
);
2251 IDirectDrawSurface7_Release(surface7
);
2256 static HRESULT WINAPI
ddraw2_GetGDISurface(IDirectDraw2
*iface
, IDirectDrawSurface
**surface
)
2258 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2259 struct ddraw_surface
*surface_impl
;
2260 IDirectDrawSurface7
*surface7
;
2263 TRACE("iface %p, surface %p.\n", iface
, surface
);
2265 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2271 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2272 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2273 IDirectDrawSurface_AddRef(*surface
);
2274 IDirectDrawSurface7_Release(surface7
);
2279 static HRESULT WINAPI
ddraw1_GetGDISurface(IDirectDraw
*iface
, IDirectDrawSurface
**surface
)
2281 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2282 struct ddraw_surface
*surface_impl
;
2283 IDirectDrawSurface7
*surface7
;
2286 TRACE("iface %p, surface %p.\n", iface
, surface
);
2288 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2294 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2295 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2296 IDirectDrawSurface_AddRef(*surface
);
2297 IDirectDrawSurface7_Release(surface7
);
2302 struct displaymodescallback_context
2304 LPDDENUMMODESCALLBACK func
;
2308 static HRESULT CALLBACK
EnumDisplayModesCallbackThunk(DDSURFACEDESC2
*surface_desc
, void *context
)
2310 struct displaymodescallback_context
*cbcontext
= context
;
2313 DDSD2_to_DDSD(surface_desc
, &desc
);
2314 return cbcontext
->func(&desc
, cbcontext
->context
);
2317 /*****************************************************************************
2318 * IDirectDraw7::EnumDisplayModes
2320 * Enumerates the supported Display modes. The modes can be filtered with
2321 * the DDSD parameter.
2324 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES. For old ddraw
2325 * versions (3 and older?) this is reserved and must be 0.
2326 * DDSD: Surface description to filter the modes
2327 * Context: Pointer passed back to the callback function
2328 * cb: Application-provided callback function
2332 * DDERR_INVALIDPARAMS if the callback wasn't set
2334 *****************************************************************************/
2335 static HRESULT WINAPI
ddraw7_EnumDisplayModes(IDirectDraw7
*iface
, DWORD Flags
,
2336 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMMODESCALLBACK2 cb
)
2338 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2339 struct wined3d_display_mode
*enum_modes
= NULL
;
2340 struct wined3d_display_mode mode
;
2341 unsigned int modenum
, fmt
;
2342 DDSURFACEDESC2 callback_sd
;
2343 unsigned enum_mode_count
= 0, enum_mode_array_size
= 16;
2344 DDPIXELFORMAT pixelformat
;
2346 static const enum wined3d_format_id checkFormatList
[] =
2348 WINED3DFMT_B8G8R8X8_UNORM
,
2349 WINED3DFMT_B5G6R5_UNORM
,
2353 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2354 iface
, Flags
, DDSD
, Context
, cb
);
2357 return DDERR_INVALIDPARAMS
;
2359 enum_modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(*enum_modes
) * enum_mode_array_size
);
2360 if (!enum_modes
) return DDERR_OUTOFMEMORY
;
2362 wined3d_mutex_lock();
2364 pixelformat
.dwSize
= sizeof(pixelformat
);
2365 for(fmt
= 0; fmt
< (sizeof(checkFormatList
) / sizeof(checkFormatList
[0])); fmt
++)
2368 while (wined3d_enum_adapter_modes(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, checkFormatList
[fmt
],
2369 WINED3D_SCANLINE_ORDERING_UNKNOWN
, modenum
++, &mode
) == WINED3D_OK
)
2374 ddrawformat_from_wined3dformat(&pixelformat
, mode
.format_id
);
2377 if (DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.width
!= DDSD
->dwWidth
)
2379 if (DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.height
!= DDSD
->dwHeight
)
2381 if (DDSD
->dwFlags
& DDSD_REFRESHRATE
&& mode
.refresh_rate
!= DDSD
->u2
.dwRefreshRate
)
2383 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
2384 && pixelformat
.u1
.dwRGBBitCount
!= DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
)
2388 /* DX docs state EnumDisplayMode should return only unique modes */
2389 for (i
= 0; i
< enum_mode_count
; i
++)
2391 if (enum_modes
[i
].width
== mode
.width
&& enum_modes
[i
].height
== mode
.height
2392 && enum_modes
[i
].format_id
== mode
.format_id
2393 && (enum_modes
[i
].refresh_rate
== mode
.refresh_rate
|| !(Flags
& DDEDM_REFRESHRATES
)))
2401 memset(&callback_sd
, 0, sizeof(callback_sd
));
2402 callback_sd
.dwSize
= sizeof(callback_sd
);
2403 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2405 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
|DDSD_REFRESHRATE
;
2406 if (Flags
& DDEDM_REFRESHRATES
)
2407 callback_sd
.u2
.dwRefreshRate
= mode
.refresh_rate
;
2409 callback_sd
.dwWidth
= mode
.width
;
2410 callback_sd
.dwHeight
= mode
.height
;
2412 callback_sd
.u4
.ddpfPixelFormat
=pixelformat
;
2414 /* Calc pitch and DWORD align like MSDN says */
2415 callback_sd
.u1
.lPitch
= (callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8) * mode
.width
;
2416 callback_sd
.u1
.lPitch
= (callback_sd
.u1
.lPitch
+ 3) & ~3;
2418 TRACE("Enumerating %dx%dx%d @%d\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
,
2419 callback_sd
.u2
.dwRefreshRate
);
2421 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
2423 TRACE("Application asked to terminate the enumeration\n");
2424 HeapFree(GetProcessHeap(), 0, enum_modes
);
2425 wined3d_mutex_unlock();
2429 if (enum_mode_count
== enum_mode_array_size
)
2431 struct wined3d_display_mode
*new_enum_modes
;
2433 enum_mode_array_size
*= 2;
2434 new_enum_modes
= HeapReAlloc(GetProcessHeap(), 0, enum_modes
,
2435 sizeof(*new_enum_modes
) * enum_mode_array_size
);
2436 if (!new_enum_modes
)
2438 HeapFree(GetProcessHeap(), 0, enum_modes
);
2439 wined3d_mutex_unlock();
2440 return DDERR_OUTOFMEMORY
;
2443 enum_modes
= new_enum_modes
;
2445 enum_modes
[enum_mode_count
++] = mode
;
2449 TRACE("End of enumeration\n");
2450 HeapFree(GetProcessHeap(), 0, enum_modes
);
2451 wined3d_mutex_unlock();
2456 static HRESULT WINAPI
ddraw4_EnumDisplayModes(IDirectDraw4
*iface
, DWORD flags
,
2457 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK2 callback
)
2459 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2461 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2462 iface
, flags
, surface_desc
, context
, callback
);
2464 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
, context
, callback
);
2467 static HRESULT WINAPI
ddraw2_EnumDisplayModes(IDirectDraw2
*iface
, DWORD flags
,
2468 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2470 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2471 struct displaymodescallback_context cbcontext
;
2472 DDSURFACEDESC2 surface_desc2
;
2474 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2475 iface
, flags
, surface_desc
, context
, callback
);
2477 cbcontext
.func
= callback
;
2478 cbcontext
.context
= context
;
2480 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2481 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2482 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2485 static HRESULT WINAPI
ddraw1_EnumDisplayModes(IDirectDraw
*iface
, DWORD flags
,
2486 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2488 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2489 struct displaymodescallback_context cbcontext
;
2490 DDSURFACEDESC2 surface_desc2
;
2492 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2493 iface
, flags
, surface_desc
, context
, callback
);
2495 cbcontext
.func
= callback
;
2496 cbcontext
.context
= context
;
2498 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2499 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2500 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2503 /*****************************************************************************
2504 * IDirectDraw7::EvaluateMode
2506 * Used with IDirectDraw7::StartModeTest to test video modes.
2507 * EvaluateMode is used to pass or fail a mode, and continue with the next
2511 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
2512 * Timeout: Returns the amount of seconds left before the mode would have
2513 * been failed automatically
2516 * This implementation always DD_OK, because it's a stub
2518 *****************************************************************************/
2519 static HRESULT WINAPI
ddraw7_EvaluateMode(IDirectDraw7
*iface
, DWORD Flags
, DWORD
*Timeout
)
2521 FIXME("iface %p, flags %#x, timeout %p stub!\n", iface
, Flags
, Timeout
);
2523 /* When implementing this, implement it in WineD3D */
2528 /*****************************************************************************
2529 * IDirectDraw7::GetDeviceIdentifier
2531 * Returns the device identifier, which gives information about the driver
2532 * Our device identifier is defined at the beginning of this file.
2535 * DDDI: Address for the returned structure
2536 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
2539 * On success it returns DD_OK
2540 * DDERR_INVALIDPARAMS if DDDI is NULL
2542 *****************************************************************************/
2543 static HRESULT WINAPI
ddraw7_GetDeviceIdentifier(IDirectDraw7
*iface
,
2544 DDDEVICEIDENTIFIER2
*DDDI
, DWORD Flags
)
2546 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2547 struct wined3d_adapter_identifier adapter_id
;
2550 TRACE("iface %p, device_identifier %p, flags %#x.\n", iface
, DDDI
, Flags
);
2553 return DDERR_INVALIDPARAMS
;
2555 if (Flags
& DDGDI_GETHOSTIDENTIFIER
)
2557 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
2558 * host adapter, if there's a secondary 3D adapter. This doesn't apply
2559 * to any modern hardware, nor is it interesting for Wine, so ignore it.
2560 * Size of DDDEVICEIDENTIFIER2 may be aligned to 8 bytes and thus 4
2561 * bytes too long. So only copy the relevant part of the structure
2564 memcpy(DDDI
, &deviceidentifier
, FIELD_OFFSET(DDDEVICEIDENTIFIER2
, dwWHQLLevel
) + sizeof(DWORD
));
2568 /* Drakan: Order of the Flame expects accurate D3D device information from ddraw */
2569 adapter_id
.driver
= DDDI
->szDriver
;
2570 adapter_id
.driver_size
= sizeof(DDDI
->szDriver
);
2571 adapter_id
.description
= DDDI
->szDescription
;
2572 adapter_id
.description_size
= sizeof(DDDI
->szDescription
);
2573 adapter_id
.device_name_size
= 0;
2574 wined3d_mutex_lock();
2575 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0x0, &adapter_id
);
2576 wined3d_mutex_unlock();
2577 if (FAILED(hr
)) return hr
;
2579 DDDI
->liDriverVersion
= adapter_id
.driver_version
;
2580 DDDI
->dwVendorId
= adapter_id
.vendor_id
;
2581 DDDI
->dwDeviceId
= adapter_id
.device_id
;
2582 DDDI
->dwSubSysId
= adapter_id
.subsystem_id
;
2583 DDDI
->dwRevision
= adapter_id
.revision
;
2584 DDDI
->guidDeviceIdentifier
= adapter_id
.device_identifier
;
2585 DDDI
->dwWHQLLevel
= adapter_id
.whql_level
;
2589 static HRESULT WINAPI
ddraw4_GetDeviceIdentifier(IDirectDraw4
*iface
,
2590 DDDEVICEIDENTIFIER
*identifier
, DWORD flags
)
2592 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2593 DDDEVICEIDENTIFIER2 identifier2
;
2596 TRACE("iface %p, identifier %p, flags %#x.\n", iface
, identifier
, flags
);
2598 hr
= ddraw7_GetDeviceIdentifier(&ddraw
->IDirectDraw7_iface
, &identifier2
, flags
);
2599 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&identifier2
, identifier
);
2604 /*****************************************************************************
2605 * IDirectDraw7::GetSurfaceFromDC
2607 * Returns the Surface for a GDI device context handle.
2608 * Is this related to IDirectDrawSurface::GetDC ???
2611 * hdc: hdc to return the surface for
2612 * Surface: Address to write the surface pointer to
2615 * Always returns DD_OK because it's a stub
2617 *****************************************************************************/
2618 static HRESULT WINAPI
ddraw7_GetSurfaceFromDC(IDirectDraw7
*iface
, HDC hdc
,
2619 IDirectDrawSurface7
**Surface
)
2621 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2622 struct wined3d_surface
*wined3d_surface
;
2623 struct ddraw_surface
*surface_impl
;
2625 TRACE("iface %p, dc %p, surface %p.\n", iface
, hdc
, Surface
);
2627 if (!Surface
) return E_INVALIDARG
;
2629 if (!(wined3d_surface
= wined3d_device_get_surface_from_dc(ddraw
->wined3d_device
, hdc
)))
2631 TRACE("No surface found for dc %p.\n", hdc
);
2633 return DDERR_NOTFOUND
;
2636 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
2637 *Surface
= &surface_impl
->IDirectDrawSurface7_iface
;
2638 IDirectDrawSurface7_AddRef(*Surface
);
2639 TRACE("Returning surface %p.\n", Surface
);
2643 static HRESULT WINAPI
ddraw4_GetSurfaceFromDC(IDirectDraw4
*iface
, HDC dc
,
2644 IDirectDrawSurface4
**surface
)
2646 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2647 struct ddraw_surface
*surface_impl
;
2648 IDirectDrawSurface7
*surface7
;
2651 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2653 if (!surface
) return E_INVALIDARG
;
2655 hr
= ddraw7_GetSurfaceFromDC(&ddraw
->IDirectDraw7_iface
, dc
, &surface7
);
2661 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2662 /* Tests say this is true */
2663 *surface
= (IDirectDrawSurface4
*)&surface_impl
->IDirectDrawSurface_iface
;
2664 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2665 IDirectDrawSurface7_Release(surface7
);
2670 static HRESULT CALLBACK
restore_callback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
2672 IDirectDrawSurface_Restore(surface
);
2673 IDirectDrawSurface_Release(surface
);
2675 return DDENUMRET_OK
;
2678 static HRESULT WINAPI
ddraw7_RestoreAllSurfaces(IDirectDraw7
*iface
)
2680 TRACE("iface %p.\n", iface
);
2682 return IDirectDraw7_EnumSurfaces(iface
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
2683 NULL
, NULL
, restore_callback
);
2686 static HRESULT WINAPI
ddraw4_RestoreAllSurfaces(IDirectDraw4
*iface
)
2688 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2690 TRACE("iface %p.\n", iface
);
2692 return ddraw7_RestoreAllSurfaces(&ddraw
->IDirectDraw7_iface
);
2695 /*****************************************************************************
2696 * IDirectDraw7::StartModeTest
2698 * Tests the specified video modes to update the system registry with
2699 * refresh rate information. StartModeTest starts the mode test,
2700 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
2701 * isn't called within 15 seconds, the mode is failed automatically
2703 * As refresh rates are handled by the X server, I don't think this
2704 * Method is important
2707 * Modes: An array of mode specifications
2708 * NumModes: The number of modes in Modes
2709 * Flags: Some flags...
2712 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
2713 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
2716 *****************************************************************************/
2717 static HRESULT WINAPI
ddraw7_StartModeTest(IDirectDraw7
*iface
, SIZE
*Modes
, DWORD NumModes
, DWORD Flags
)
2719 FIXME("iface %p, modes %p, mode_count %u, flags %#x partial stub!\n",
2720 iface
, Modes
, NumModes
, Flags
);
2722 /* This looks sane */
2723 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
2725 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
2726 * As it is not, DDERR_TESTFINISHED is returned
2727 * (hopefully that's correct
2729 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
2730 * well, that value doesn't (yet) exist in the wine headers, so ignore it
2736 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
, DDSURFACEDESC2
*surface_desc
,
2737 IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
2739 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2740 struct ddraw_surface
*impl
;
2743 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2744 iface
, surface_desc
, surface
, outer_unknown
);
2746 wined3d_mutex_lock();
2748 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2750 WARN("Cooperative level not set.\n");
2751 wined3d_mutex_unlock();
2752 return DDERR_NOCOOPERATIVELEVELSET
;
2755 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2757 WARN("Application supplied invalid surface descriptor\n");
2758 wined3d_mutex_unlock();
2759 return DDERR_INVALIDPARAMS
;
2762 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2764 if (TRACE_ON(ddraw
))
2766 TRACE(" (%p) Requesting surface desc :\n", iface
);
2767 DDRAW_dump_surface_desc(surface_desc
);
2770 WARN("Application tried to create an explicit front or back buffer\n");
2771 wined3d_mutex_unlock();
2772 return DDERR_INVALIDCAPS
;
2775 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 7);
2776 wined3d_mutex_unlock();
2783 *surface
= &impl
->IDirectDrawSurface7_iface
;
2784 IDirectDraw7_AddRef(iface
);
2785 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2790 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
2791 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
2793 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2794 struct ddraw_surface
*impl
;
2797 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2798 iface
, surface_desc
, surface
, outer_unknown
);
2800 wined3d_mutex_lock();
2802 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2804 WARN("Cooperative level not set.\n");
2805 wined3d_mutex_unlock();
2806 return DDERR_NOCOOPERATIVELEVELSET
;
2809 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2811 WARN("Application supplied invalid surface descriptor\n");
2812 wined3d_mutex_unlock();
2813 return DDERR_INVALIDPARAMS
;
2816 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2818 if (TRACE_ON(ddraw
))
2820 TRACE(" (%p) Requesting surface desc :\n", iface
);
2821 DDRAW_dump_surface_desc(surface_desc
);
2824 WARN("Application tried to create an explicit front or back buffer\n");
2825 wined3d_mutex_unlock();
2826 return DDERR_INVALIDCAPS
;
2829 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 4);
2830 wined3d_mutex_unlock();
2837 *surface
= &impl
->IDirectDrawSurface4_iface
;
2838 IDirectDraw4_AddRef(iface
);
2839 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2844 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
2845 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2847 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2848 struct ddraw_surface
*impl
;
2850 DDSURFACEDESC2 surface_desc2
;
2852 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2853 iface
, surface_desc
, surface
, outer_unknown
);
2855 wined3d_mutex_lock();
2857 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2859 WARN("Cooperative level not set.\n");
2860 wined3d_mutex_unlock();
2861 return DDERR_NOCOOPERATIVELEVELSET
;
2864 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2866 WARN("Application supplied invalid surface descriptor\n");
2867 wined3d_mutex_unlock();
2868 return DDERR_INVALIDPARAMS
;
2871 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2872 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2874 if (TRACE_ON(ddraw
))
2876 TRACE(" (%p) Requesting surface desc :\n", iface
);
2877 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
2880 WARN("Application tried to create an explicit front or back buffer\n");
2881 wined3d_mutex_unlock();
2882 return DDERR_INVALIDCAPS
;
2885 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 2);
2886 wined3d_mutex_unlock();
2893 *surface
= &impl
->IDirectDrawSurface_iface
;
2894 impl
->ifaceToRelease
= NULL
;
2899 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
2900 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2902 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2903 struct ddraw_surface
*impl
;
2905 DDSURFACEDESC2 surface_desc2
;
2907 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2908 iface
, surface_desc
, surface
, outer_unknown
);
2910 wined3d_mutex_lock();
2912 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2914 WARN("Cooperative level not set.\n");
2915 wined3d_mutex_unlock();
2916 return DDERR_NOCOOPERATIVELEVELSET
;
2919 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2921 WARN("Application supplied invalid surface descriptor\n");
2922 wined3d_mutex_unlock();
2923 return DDERR_INVALIDPARAMS
;
2926 if ((surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
))
2927 == (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
)
2928 || (surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
))
2929 == ((DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
)))
2931 WARN("Application tried to create an explicit front or back buffer.\n");
2932 wined3d_mutex_unlock();
2933 return DDERR_INVALIDCAPS
;
2936 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2937 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 1);
2938 wined3d_mutex_unlock();
2945 *surface
= &impl
->IDirectDrawSurface_iface
;
2946 impl
->ifaceToRelease
= NULL
;
2951 #define DDENUMSURFACES_SEARCHTYPE (DDENUMSURFACES_CANBECREATED|DDENUMSURFACES_DOESEXIST)
2952 #define DDENUMSURFACES_MATCHTYPE (DDENUMSURFACES_ALL|DDENUMSURFACES_MATCH|DDENUMSURFACES_NOMATCH)
2955 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
2956 const DDPIXELFORMAT
*provided
)
2958 /* Some flags must be present in both or neither for a match. */
2959 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
2960 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
2961 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
2963 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
2966 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
2969 if (requested
->dwFlags
& DDPF_FOURCC
)
2970 if (requested
->dwFourCC
!= provided
->dwFourCC
)
2973 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
2974 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
2975 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
2978 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
2979 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
2980 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
2983 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
2984 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
2987 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
2988 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
2990 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
2993 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
2994 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
3000 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3009 #define CMP(FLAG, FIELD) \
3010 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3011 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3013 static const struct compare_info compare
[] =
3015 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3016 CMP(BACKBUFFERCOUNT
, u5
.dwBackBufferCount
),
3018 CMP(CKDESTBLT
, ddckCKDestBlt
),
3019 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3020 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3021 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3022 CMP(HEIGHT
, dwHeight
),
3023 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3024 CMP(LPSURFACE
, lpSurface
),
3025 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3026 CMP(PITCH
, u1
/* lPitch */),
3027 /* PIXELFORMAT: manual */
3028 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3029 CMP(TEXTURESTAGE
, dwTextureStage
),
3030 CMP(WIDTH
, dwWidth
),
3031 /* ZBUFFERBITDEPTH: "obsolete" */
3038 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3041 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
3043 if (requested
->dwFlags
& compare
[i
].flag
3044 && memcmp((const char *)provided
+ compare
[i
].offset
,
3045 (const char *)requested
+ compare
[i
].offset
,
3046 compare
[i
].size
) != 0)
3050 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3052 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3053 &provided
->u4
.ddpfPixelFormat
))
3060 #undef DDENUMSURFACES_SEARCHTYPE
3061 #undef DDENUMSURFACES_MATCHTYPE
3063 struct surfacescallback2_context
3065 LPDDENUMSURFACESCALLBACK2 func
;
3069 struct surfacescallback_context
3071 LPDDENUMSURFACESCALLBACK func
;
3075 static HRESULT CALLBACK
EnumSurfacesCallback2Thunk(IDirectDrawSurface7
*surface
,
3076 DDSURFACEDESC2
*surface_desc
, void *context
)
3078 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3079 struct surfacescallback2_context
*cbcontext
= context
;
3081 IDirectDrawSurface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
3082 IDirectDrawSurface7_Release(surface
);
3084 return cbcontext
->func(&surface_impl
->IDirectDrawSurface4_iface
,
3085 surface_desc
, cbcontext
->context
);
3088 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3089 DDSURFACEDESC2
*surface_desc
, void *context
)
3091 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3092 struct surfacescallback_context
*cbcontext
= context
;
3094 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
3095 IDirectDrawSurface7_Release(surface
);
3097 return cbcontext
->func(&surface_impl
->IDirectDrawSurface_iface
,
3098 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3101 /*****************************************************************************
3102 * IDirectDraw7::EnumSurfaces
3104 * Loops through all surfaces attached to this device and calls the
3105 * application callback. This can't be relayed to WineD3DDevice,
3106 * because some WineD3DSurfaces' parents are IParent objects
3109 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3110 * DDSD: Description to filter for
3111 * Context: Application-provided pointer, it's passed unmodified to the
3113 * Callback: Address to call for each surface
3116 * DDERR_INVALIDPARAMS if the callback is NULL
3119 *****************************************************************************/
3120 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD Flags
,
3121 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMSURFACESCALLBACK7 Callback
)
3123 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3124 struct ddraw_surface
*surf
;
3126 DDSURFACEDESC2 desc
;
3127 struct list
*entry
, *entry2
;
3129 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3130 iface
, Flags
, DDSD
, Context
, Callback
);
3132 all
= Flags
& DDENUMSURFACES_ALL
;
3133 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
3136 return DDERR_INVALIDPARAMS
;
3138 wined3d_mutex_lock();
3140 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
3141 LIST_FOR_EACH_SAFE(entry
, entry2
, &ddraw
->surface_list
)
3143 surf
= LIST_ENTRY(entry
, struct ddraw_surface
, surface_list_entry
);
3145 if (!surf
->iface_count
)
3147 WARN("Not enumerating surface %p because it doesn't have any references.\n", surf
);
3151 if (all
|| (nomatch
!= ddraw_match_surface_desc(DDSD
, &surf
->surface_desc
)))
3153 TRACE("Enumerating surface %p.\n", surf
);
3154 desc
= surf
->surface_desc
;
3155 IDirectDrawSurface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
3156 if (Callback(&surf
->IDirectDrawSurface7_iface
, &desc
, Context
) != DDENUMRET_OK
)
3158 wined3d_mutex_unlock();
3164 wined3d_mutex_unlock();
3169 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3170 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3172 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3173 struct surfacescallback2_context cbcontext
;
3175 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3176 iface
, flags
, surface_desc
, context
, callback
);
3178 cbcontext
.func
= callback
;
3179 cbcontext
.context
= context
;
3181 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
,
3182 &cbcontext
, EnumSurfacesCallback2Thunk
);
3185 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3186 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3188 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3189 struct surfacescallback_context cbcontext
;
3190 DDSURFACEDESC2 surface_desc2
;
3192 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3193 iface
, flags
, surface_desc
, context
, callback
);
3195 cbcontext
.func
= callback
;
3196 cbcontext
.context
= context
;
3198 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3199 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3200 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3203 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3204 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3206 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3207 struct surfacescallback_context cbcontext
;
3208 DDSURFACEDESC2 surface_desc2
;
3210 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3211 iface
, flags
, surface_desc
, context
, callback
);
3213 cbcontext
.func
= callback
;
3214 cbcontext
.context
= context
;
3216 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3217 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3218 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3221 /*****************************************************************************
3222 * DirectDrawCreateClipper (DDRAW.@)
3224 * Creates a new IDirectDrawClipper object.
3227 * Clipper: Address to write the interface pointer to
3228 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3232 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3233 * E_OUTOFMEMORY if allocating the object failed
3235 *****************************************************************************/
3236 HRESULT WINAPI
DirectDrawCreateClipper(DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3238 struct ddraw_clipper
*object
;
3241 TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
3242 flags
, clipper
, outer_unknown
);
3245 return CLASS_E_NOAGGREGATION
;
3247 wined3d_mutex_lock();
3249 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3252 wined3d_mutex_unlock();
3253 return E_OUTOFMEMORY
;
3256 hr
= ddraw_clipper_init(object
);
3259 WARN("Failed to initialize clipper, hr %#x.\n", hr
);
3260 HeapFree(GetProcessHeap(), 0, object
);
3261 wined3d_mutex_unlock();
3265 TRACE("Created clipper %p.\n", object
);
3266 *clipper
= &object
->IDirectDrawClipper_iface
;
3267 wined3d_mutex_unlock();
3272 /*****************************************************************************
3273 * IDirectDraw7::CreateClipper
3275 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3277 *****************************************************************************/
3278 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3279 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3281 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3282 iface
, Flags
, Clipper
, UnkOuter
);
3284 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3287 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
, DWORD flags
,
3288 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3290 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3292 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3293 iface
, flags
, clipper
, outer_unknown
);
3295 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3298 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
3299 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3301 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3303 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3304 iface
, flags
, clipper
, outer_unknown
);
3306 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3309 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
3310 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3312 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3314 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3315 iface
, flags
, clipper
, outer_unknown
);
3317 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3320 /*****************************************************************************
3321 * IDirectDraw7::CreatePalette
3323 * Creates a new IDirectDrawPalette object
3326 * Flags: The flags for the new clipper
3327 * ColorTable: Color table to assign to the new clipper
3328 * Palette: Address to write the interface pointer to
3329 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3333 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3334 * E_OUTOFMEMORY if allocating the object failed
3336 *****************************************************************************/
3337 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
3338 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
3340 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3341 struct ddraw_palette
*object
;
3344 TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
3345 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3348 return CLASS_E_NOAGGREGATION
;
3350 wined3d_mutex_lock();
3352 /* The refcount test shows that a cooplevel is required for this */
3353 if (!ddraw
->cooperative_level
)
3355 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3356 wined3d_mutex_unlock();
3357 return DDERR_NOCOOPERATIVELEVELSET
;
3360 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(*object
));
3363 ERR("Out of memory when allocating memory for a palette implementation\n");
3364 wined3d_mutex_unlock();
3365 return E_OUTOFMEMORY
;
3368 hr
= ddraw_palette_init(object
, ddraw
, Flags
, ColorTable
);
3371 WARN("Failed to initialize palette, hr %#x.\n", hr
);
3372 HeapFree(GetProcessHeap(), 0, object
);
3373 wined3d_mutex_unlock();
3377 TRACE("Created palette %p.\n", object
);
3378 *Palette
= &object
->IDirectDrawPalette_iface
;
3379 wined3d_mutex_unlock();
3384 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
, PALETTEENTRY
*entries
,
3385 IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3387 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3390 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3391 iface
, flags
, entries
, palette
, outer_unknown
);
3393 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3394 if (SUCCEEDED(hr
) && *palette
)
3396 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3397 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3398 IDirectDraw4_AddRef(iface
);
3399 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3404 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
3405 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3407 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3410 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3411 iface
, flags
, entries
, palette
, outer_unknown
);
3413 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3414 if (SUCCEEDED(hr
) && *palette
)
3416 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3417 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3418 impl
->ifaceToRelease
= NULL
;
3424 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
3425 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3427 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3430 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3431 iface
, flags
, entries
, palette
, outer_unknown
);
3433 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3434 if (SUCCEEDED(hr
) && *palette
)
3436 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3437 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3438 impl
->ifaceToRelease
= NULL
;
3444 /*****************************************************************************
3445 * IDirectDraw7::DuplicateSurface
3447 * Duplicates a surface. The surface memory points to the same memory as
3448 * the original surface, and it's released when the last surface referencing
3449 * it is released. I guess that's beyond Wine's surface management right now
3450 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3451 * test application to implement this)
3454 * Src: Address of the source surface
3455 * Dest: Address to write the new surface pointer to
3458 * See IDirectDraw7::CreateSurface
3460 *****************************************************************************/
3461 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
3462 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
3464 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(Src
);
3466 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
3468 /* For now, simply create a new, independent surface */
3469 return IDirectDraw7_CreateSurface(iface
, &src_surface
->surface_desc
, Dest
, NULL
);
3472 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
, IDirectDrawSurface4
*src
,
3473 IDirectDrawSurface4
**dst
)
3475 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
3476 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3477 struct ddraw_surface
*dst_impl
;
3478 IDirectDrawSurface7
*dst7
;
3481 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3483 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3484 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3490 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3491 *dst
= &dst_impl
->IDirectDrawSurface4_iface
;
3492 IDirectDrawSurface4_AddRef(*dst
);
3493 IDirectDrawSurface7_Release(dst7
);
3498 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
3499 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
3501 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3502 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3503 struct ddraw_surface
*dst_impl
;
3504 IDirectDrawSurface7
*dst7
;
3507 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3509 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3510 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3513 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3514 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3515 IDirectDrawSurface_AddRef(*dst
);
3516 IDirectDrawSurface7_Release(dst7
);
3521 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
, IDirectDrawSurface
*src
,
3522 IDirectDrawSurface
**dst
)
3524 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3525 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3526 struct ddraw_surface
*dst_impl
;
3527 IDirectDrawSurface7
*dst7
;
3530 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3532 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3533 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3536 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3537 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3538 IDirectDrawSurface_AddRef(*dst
);
3539 IDirectDrawSurface7_Release(dst7
);
3544 /*****************************************************************************
3545 * IDirect3D7::EnumDevices
3547 * The EnumDevices method for IDirect3D7. It enumerates all supported
3548 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
3551 * callback: Function to call for each enumerated device
3552 * context: Pointer to pass back to the app
3555 * D3D_OK, or the return value of the GetCaps call
3557 *****************************************************************************/
3558 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
3560 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
3561 D3DDEVICEDESC7 device_desc7
;
3565 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3568 return DDERR_INVALIDPARAMS
;
3570 wined3d_mutex_lock();
3572 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3574 wined3d_mutex_unlock();
3578 for (i
= 0; i
< sizeof(device_list7
)/sizeof(device_list7
[0]); i
++)
3582 device_desc7
.deviceGUID
= *device_list7
[i
].device_guid
;
3583 ret
= callback(device_list7
[i
].interface_name
, device_list7
[i
].device_name
, &device_desc7
, context
);
3584 if (ret
!= DDENUMRET_OK
)
3586 TRACE("Application cancelled the enumeration.\n");
3587 wined3d_mutex_unlock();
3592 TRACE("End of enumeration.\n");
3594 wined3d_mutex_unlock();
3599 /*****************************************************************************
3600 * IDirect3D3::EnumDevices
3602 * Enumerates all supported Direct3DDevice interfaces. This is the
3603 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
3605 * Version 1, 2 and 3
3608 * callback: Application-provided routine to call for each enumerated device
3609 * Context: Pointer to pass to the callback
3612 * D3D_OK on success,
3613 * The result of IDirect3DImpl_GetCaps if it failed
3615 *****************************************************************************/
3616 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3618 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
3620 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3621 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
3622 D3DDEVICEDESC7 device_desc7
;
3625 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
3626 * name string. Let's put the string in a sufficiently sized array in
3627 * writable memory. */
3628 char device_name
[50];
3629 strcpy(device_name
,"Direct3D HEL");
3631 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3634 return DDERR_INVALIDPARAMS
;
3636 wined3d_mutex_lock();
3638 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3640 wined3d_mutex_unlock();
3643 ddraw_d3dcaps1_from_7(&device_desc1
, &device_desc7
);
3645 /* Do I have to enumerate the reference id? Note from old d3d7:
3646 * "It seems that enumerating the reference IID on Direct3D 1 games
3647 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
3649 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
3650 * EnumReference which enables / disables enumerating the reference
3651 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
3652 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
3653 * demo directory suggest this.
3655 * Some games(GTA 2) seem to use the second enumerated device, so I have
3656 * to enumerate at least 2 devices. So enumerate the reference device to
3659 * Other games (Rollcage) tell emulation and hal device apart by certain
3660 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
3661 * limitation flag), and it refuses all devices that have the perspective
3662 * flag set. This way it refuses the emulation device, and HAL devices
3663 * never have POW2 unset in d3d7 on windows. */
3664 if (ddraw
->d3dversion
!= 1)
3666 static CHAR reference_description
[] = "RGB Direct3D emulation";
3668 TRACE("Enumerating WineD3D D3DDevice interface.\n");
3669 hal_desc
= device_desc1
;
3670 hel_desc
= device_desc1
;
3671 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
3672 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3673 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3674 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3675 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3676 /* RGB, RAMP and MMX devices have a HAL dcmColorModel of 0 */
3677 hal_desc
.dcmColorModel
= 0;
3678 /* RGB, RAMP and MMX devices cannot report HAL hardware flags */
3679 hal_desc
.dwFlags
= 0;
3681 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
3682 device_name
, &hal_desc
, &hel_desc
, context
);
3683 if (hr
!= D3DENUMRET_OK
)
3685 TRACE("Application cancelled the enumeration.\n");
3686 wined3d_mutex_unlock();
3691 strcpy(device_name
,"Direct3D HAL");
3693 TRACE("Enumerating HAL Direct3D device.\n");
3694 hal_desc
= device_desc1
;
3695 hel_desc
= device_desc1
;
3697 /* The hal device does not have the pow2 flag set in hel, but in hal. */
3698 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3699 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3700 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3701 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3702 /* HAL devices have a HEL dcmColorModel of 0 */
3703 hel_desc
.dcmColorModel
= 0;
3705 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
3706 device_name
, &hal_desc
, &hel_desc
, context
);
3707 if (hr
!= D3DENUMRET_OK
)
3709 TRACE("Application cancelled the enumeration.\n");
3710 wined3d_mutex_unlock();
3714 TRACE("End of enumeration.\n");
3716 wined3d_mutex_unlock();
3721 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3723 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3725 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3727 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3730 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3732 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3734 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3736 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3739 /*****************************************************************************
3740 * IDirect3D3::CreateLight
3742 * Creates an IDirect3DLight interface. This interface is used in
3743 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
3744 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
3745 * uses the IDirect3DDevice7 interface with D3D7 lights.
3747 * Version 1, 2 and 3
3750 * light: Address to store the new interface pointer
3751 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3756 * DDERR_OUTOFMEMORY if memory allocation failed
3757 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3759 *****************************************************************************/
3760 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
,
3761 IUnknown
*outer_unknown
)
3763 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3764 struct d3d_light
*object
;
3766 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3768 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3770 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3773 ERR("Failed to allocate light memory.\n");
3774 return DDERR_OUTOFMEMORY
;
3777 d3d_light_init(object
, ddraw
);
3779 TRACE("Created light %p.\n", object
);
3780 *light
= &object
->IDirect3DLight_iface
;
3785 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3787 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3789 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3791 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3794 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3796 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3798 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3800 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3803 /*****************************************************************************
3804 * IDirect3D3::CreateMaterial
3806 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
3807 * and older versions. The IDirect3DMaterial implementation wraps its
3808 * functionality to IDirect3DDevice7::SetMaterial and friends.
3810 * Version 1, 2 and 3
3813 * material: Address to store the new interface's pointer to
3814 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3819 * DDERR_OUTOFMEMORY if memory allocation failed
3820 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3822 *****************************************************************************/
3823 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
,
3824 IUnknown
*outer_unknown
)
3826 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3827 struct d3d_material
*object
;
3829 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3831 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3833 object
= d3d_material_create(ddraw
);
3836 ERR("Failed to allocate material memory.\n");
3837 return DDERR_OUTOFMEMORY
;
3840 TRACE("Created material %p.\n", object
);
3841 *material
= &object
->IDirect3DMaterial3_iface
;
3846 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
,
3847 IUnknown
*outer_unknown
)
3849 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3850 struct d3d_material
*object
;
3852 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3854 object
= d3d_material_create(ddraw
);
3857 ERR("Failed to allocate material memory.\n");
3858 return DDERR_OUTOFMEMORY
;
3861 TRACE("Created material %p.\n", object
);
3862 *material
= &object
->IDirect3DMaterial2_iface
;
3867 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
,
3868 IUnknown
*outer_unknown
)
3870 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3871 struct d3d_material
*object
;
3873 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3875 object
= d3d_material_create(ddraw
);
3878 ERR("Failed to allocate material memory.\n");
3879 return DDERR_OUTOFMEMORY
;
3882 TRACE("Created material %p.\n", object
);
3883 *material
= &object
->IDirect3DMaterial_iface
;
3888 /*****************************************************************************
3889 * IDirect3D3::CreateViewport
3891 * Creates an IDirect3DViewport interface. This interface is used
3892 * by Direct3D and earlier versions for Viewport management. In Direct3D7
3893 * it has been replaced by a viewport structure and
3894 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
3895 * uses the IDirect3DDevice7 methods for its functionality
3898 * Viewport: Address to store the new interface pointer
3899 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3904 * DDERR_OUTOFMEMORY if memory allocation failed
3905 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3907 *****************************************************************************/
3908 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
,
3909 IUnknown
*outer_unknown
)
3911 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3912 struct d3d_viewport
*object
;
3914 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
3916 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3918 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3921 ERR("Failed to allocate viewport memory.\n");
3922 return DDERR_OUTOFMEMORY
;
3925 d3d_viewport_init(object
, ddraw
);
3927 TRACE("Created viewport %p.\n", object
);
3928 *viewport
= &object
->IDirect3DViewport3_iface
;
3933 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
3935 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3937 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
3939 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
3943 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
3945 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3947 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
3949 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
3953 /*****************************************************************************
3954 * IDirect3D3::FindDevice
3956 * This method finds a device with the requested properties and returns a
3957 * device description
3961 * fds: Describes the requested device characteristics
3962 * fdr: Returns the device description
3966 * DDERR_INVALIDPARAMS if no device was found
3968 *****************************************************************************/
3969 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
3971 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3972 D3DDEVICEDESC7 desc7
;
3973 D3DDEVICEDESC desc1
;
3976 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
3978 if (!fds
|| !fdr
) return DDERR_INVALIDPARAMS
;
3980 if (fds
->dwSize
!= sizeof(D3DFINDDEVICESEARCH
)
3981 || fdr
->dwSize
!= sizeof(D3DFINDDEVICERESULT
))
3982 return DDERR_INVALIDPARAMS
;
3984 if ((fds
->dwFlags
& D3DFDS_COLORMODEL
)
3985 && fds
->dcmColorModel
!= D3DCOLOR_RGB
)
3987 WARN("Trying to request a non-RGB D3D color model. Not supported.\n");
3988 return DDERR_INVALIDPARAMS
; /* No real idea what to return here :-) */
3991 if (fds
->dwFlags
& D3DFDS_GUID
)
3993 TRACE("Trying to match guid %s.\n", debugstr_guid(&(fds
->guid
)));
3994 if (!IsEqualGUID(&IID_D3DDEVICE_WineD3D
, &fds
->guid
)
3995 && !IsEqualGUID(&IID_IDirect3DHALDevice
, &fds
->guid
)
3996 && !IsEqualGUID(&IID_IDirect3DRGBDevice
, &fds
->guid
))
3998 WARN("No match for this GUID.\n");
3999 return DDERR_NOTFOUND
;
4004 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &desc7
)))
4007 /* Now return our own GUID */
4008 ddraw_d3dcaps1_from_7(&desc1
, &desc7
);
4009 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4010 fdr
->ddHwDesc
= desc1
;
4011 fdr
->ddSwDesc
= desc1
;
4013 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4018 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4020 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4022 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4024 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4027 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4029 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4031 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4033 return d3d3_FindDevice(&ddraw
->IDirect3D3_iface
, fds
, fdr
);
4036 /*****************************************************************************
4037 * IDirect3D7::CreateDevice
4039 * Creates an IDirect3DDevice7 interface.
4041 * Version 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4042 * DirectDraw surfaces and are created with
4043 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4044 * create the device object and QueryInterfaces for IDirect3DDevice
4047 * refiid: IID of the device to create
4048 * Surface: Initial rendertarget
4049 * Device: Address to return the interface pointer
4053 * DDERR_OUTOFMEMORY if memory allocation failed
4054 * DDERR_INVALIDPARAMS if a device exists already
4056 *****************************************************************************/
4057 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4058 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4060 struct ddraw_surface
*target
= unsafe_impl_from_IDirectDrawSurface7(surface
);
4061 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4062 struct d3d_device
*object
;
4065 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4067 wined3d_mutex_lock();
4068 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, target
, (IUnknown
*)surface
, 7, &object
, NULL
)))
4070 *device
= &object
->IDirect3DDevice7_iface
;
4074 WARN("Failed to create device, hr %#x.\n", hr
);
4077 wined3d_mutex_unlock();
4082 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4083 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4085 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface4(surface
);
4086 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4087 struct d3d_device
*device_impl
;
4090 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4091 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4094 return CLASS_E_NOAGGREGATION
;
4096 wined3d_mutex_lock();
4097 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 3, &device_impl
, NULL
)))
4099 *device
= &device_impl
->IDirect3DDevice3_iface
;
4103 WARN("Failed to create device, hr %#x.\n", hr
);
4106 wined3d_mutex_unlock();
4111 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4112 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4114 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface(surface
);
4115 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4116 struct d3d_device
*device_impl
;
4119 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4120 iface
, debugstr_guid(riid
), surface
, device
);
4122 wined3d_mutex_lock();
4123 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 2, &device_impl
, NULL
)))
4125 *device
= &device_impl
->IDirect3DDevice2_iface
;
4129 WARN("Failed to create device, hr %#x.\n", hr
);
4132 wined3d_mutex_unlock();
4137 /*****************************************************************************
4138 * IDirect3D7::CreateVertexBuffer
4140 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4146 * desc: Requested Vertex buffer properties
4147 * vertex_buffer: Address to return the interface pointer at
4148 * flags: Some flags, should be 0
4152 * DDERR_OUTOFMEMORY if memory allocation failed
4153 * The return value of IWineD3DDevice::CreateVertexBuffer if this call fails
4154 * DDERR_INVALIDPARAMS if desc or vertex_buffer is NULL
4156 *****************************************************************************/
4157 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4158 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4160 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4161 struct d3d_vertex_buffer
*object
;
4164 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
4165 iface
, desc
, vertex_buffer
, flags
);
4167 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4169 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4172 TRACE("Created vertex buffer %p.\n", object
);
4173 *vertex_buffer
= &object
->IDirect3DVertexBuffer7_iface
;
4176 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4181 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4182 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4184 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4185 struct d3d_vertex_buffer
*object
;
4188 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n",
4189 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4192 return CLASS_E_NOAGGREGATION
;
4193 if (!vertex_buffer
|| !desc
)
4194 return DDERR_INVALIDPARAMS
;
4196 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4199 TRACE("Created vertex buffer %p.\n", object
);
4200 *vertex_buffer
= &object
->IDirect3DVertexBuffer_iface
;
4203 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4208 /*****************************************************************************
4209 * IDirect3D7::EnumZBufferFormats
4211 * Enumerates all supported Z buffer pixel formats
4217 * callback: callback to call for each pixel format
4218 * context: Pointer to pass back to the callback
4222 * DDERR_INVALIDPARAMS if callback is NULL
4223 * For details, see IWineD3DDevice::EnumZBufferFormats
4225 *****************************************************************************/
4226 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4227 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4229 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4230 struct wined3d_display_mode mode
;
4231 enum wined3d_device_type type
;
4235 /* Order matters. Specifically, BattleZone II (full version) expects the
4236 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4237 static const enum wined3d_format_id formats
[] =
4239 WINED3DFMT_S1_UINT_D15_UNORM
,
4240 WINED3DFMT_D16_UNORM
,
4241 WINED3DFMT_X8D24_UNORM
,
4242 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4243 WINED3DFMT_D24_UNORM_S8_UINT
,
4244 WINED3DFMT_D32_UNORM
,
4247 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4248 iface
, debugstr_guid(device_iid
), callback
, context
);
4250 if (!callback
) return DDERR_INVALIDPARAMS
;
4252 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4253 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4254 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4256 TRACE("Asked for HAL device.\n");
4257 type
= WINED3D_DEVICE_TYPE_HAL
;
4259 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4260 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4262 TRACE("Asked for SW device.\n");
4263 type
= WINED3D_DEVICE_TYPE_SW
;
4265 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4267 TRACE("Asked for REF device.\n");
4268 type
= WINED3D_DEVICE_TYPE_REF
;
4270 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4272 TRACE("Asked for NULLREF device.\n");
4273 type
= WINED3D_DEVICE_TYPE_NULLREF
;
4277 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4278 type
= WINED3D_DEVICE_TYPE_HAL
;
4281 wined3d_mutex_lock();
4282 /* We need an adapter format from somewhere to please wined3d and WGL.
4283 * Use the current display mode. So far all cards offer the same depth
4284 * stencil format for all modes, but if some do not and applications do
4285 * not like that we'll have to find some workaround, like iterating over
4286 * all imaginable formats and collecting all the depth stencil formats we
4288 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
4290 ERR("Failed to get display mode, hr %#x.\n", hr
);
4291 wined3d_mutex_unlock();
4295 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
4297 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4298 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_SURFACE
, formats
[i
])))
4300 DDPIXELFORMAT pformat
;
4302 memset(&pformat
, 0, sizeof(pformat
));
4303 pformat
.dwSize
= sizeof(pformat
);
4304 ddrawformat_from_wined3dformat(&pformat
, formats
[i
]);
4306 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
4307 hr
= callback(&pformat
, context
);
4308 if (hr
!= DDENUMRET_OK
)
4310 TRACE("Format enumeration cancelled by application.\n");
4311 wined3d_mutex_unlock();
4317 /* Historically some windows drivers used dwZBufferBitDepth=24 for WINED3DFMT_X8D24_UNORM,
4318 * while others used dwZBufferBitDepth=32. In either case the pitch matches a 32 bits per
4319 * pixel format, so we use dwZBufferBitDepth=32. Some games expect 24. Windows Vista and
4320 * newer enumerate both versions, so we do the same(bug 22434) */
4321 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4322 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_SURFACE
, WINED3DFMT_X8D24_UNORM
)))
4324 DDPIXELFORMAT x8d24
=
4326 sizeof(x8d24
), DDPF_ZBUFFER
, 0,
4327 {24}, {0x00000000}, {0x00ffffff}, {0x00000000}
4329 TRACE("Enumerating WINED3DFMT_X8D24_UNORM, dwZBufferBitDepth=24 version\n");
4330 callback(&x8d24
, context
);
4333 TRACE("End of enumeration.\n");
4335 wined3d_mutex_unlock();
4340 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
4341 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4343 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4345 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4346 iface
, debugstr_guid(device_iid
), callback
, context
);
4348 return d3d7_EnumZBufferFormats(&ddraw
->IDirect3D7_iface
, device_iid
, callback
, context
);
4351 /*****************************************************************************
4352 * IDirect3D7::EvictManagedTextures
4354 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
4355 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
4360 * D3D_OK, because it's a stub
4362 *****************************************************************************/
4363 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
4365 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4367 TRACE("iface %p!\n", iface
);
4369 wined3d_mutex_lock();
4370 if (ddraw
->flags
& DDRAW_D3D_INITIALIZED
)
4371 wined3d_device_evict_managed_resources(ddraw
->wined3d_device
);
4372 wined3d_mutex_unlock();
4377 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
4379 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4381 TRACE("iface %p.\n", iface
);
4383 return d3d7_EvictManagedTextures(&ddraw
->IDirect3D7_iface
);
4386 /*****************************************************************************
4387 * IDirectDraw7 VTable
4388 *****************************************************************************/
4389 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
4392 ddraw7_QueryInterface
,
4397 ddraw7_CreateClipper
,
4398 ddraw7_CreatePalette
,
4399 ddraw7_CreateSurface
,
4400 ddraw7_DuplicateSurface
,
4401 ddraw7_EnumDisplayModes
,
4402 ddraw7_EnumSurfaces
,
4403 ddraw7_FlipToGDISurface
,
4405 ddraw7_GetDisplayMode
,
4406 ddraw7_GetFourCCCodes
,
4407 ddraw7_GetGDISurface
,
4408 ddraw7_GetMonitorFrequency
,
4410 ddraw7_GetVerticalBlankStatus
,
4412 ddraw7_RestoreDisplayMode
,
4413 ddraw7_SetCooperativeLevel
,
4414 ddraw7_SetDisplayMode
,
4415 ddraw7_WaitForVerticalBlank
,
4417 ddraw7_GetAvailableVidMem
,
4419 ddraw7_GetSurfaceFromDC
,
4421 ddraw7_RestoreAllSurfaces
,
4422 ddraw7_TestCooperativeLevel
,
4423 ddraw7_GetDeviceIdentifier
,
4425 ddraw7_StartModeTest
,
4429 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
4432 ddraw4_QueryInterface
,
4437 ddraw4_CreateClipper
,
4438 ddraw4_CreatePalette
,
4439 ddraw4_CreateSurface
,
4440 ddraw4_DuplicateSurface
,
4441 ddraw4_EnumDisplayModes
,
4442 ddraw4_EnumSurfaces
,
4443 ddraw4_FlipToGDISurface
,
4445 ddraw4_GetDisplayMode
,
4446 ddraw4_GetFourCCCodes
,
4447 ddraw4_GetGDISurface
,
4448 ddraw4_GetMonitorFrequency
,
4450 ddraw4_GetVerticalBlankStatus
,
4452 ddraw4_RestoreDisplayMode
,
4453 ddraw4_SetCooperativeLevel
,
4454 ddraw4_SetDisplayMode
,
4455 ddraw4_WaitForVerticalBlank
,
4457 ddraw4_GetAvailableVidMem
,
4459 ddraw4_GetSurfaceFromDC
,
4461 ddraw4_RestoreAllSurfaces
,
4462 ddraw4_TestCooperativeLevel
,
4463 ddraw4_GetDeviceIdentifier
,
4466 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
4469 ddraw2_QueryInterface
,
4474 ddraw2_CreateClipper
,
4475 ddraw2_CreatePalette
,
4476 ddraw2_CreateSurface
,
4477 ddraw2_DuplicateSurface
,
4478 ddraw2_EnumDisplayModes
,
4479 ddraw2_EnumSurfaces
,
4480 ddraw2_FlipToGDISurface
,
4482 ddraw2_GetDisplayMode
,
4483 ddraw2_GetFourCCCodes
,
4484 ddraw2_GetGDISurface
,
4485 ddraw2_GetMonitorFrequency
,
4487 ddraw2_GetVerticalBlankStatus
,
4489 ddraw2_RestoreDisplayMode
,
4490 ddraw2_SetCooperativeLevel
,
4491 ddraw2_SetDisplayMode
,
4492 ddraw2_WaitForVerticalBlank
,
4494 ddraw2_GetAvailableVidMem
,
4497 static const struct IDirectDrawVtbl ddraw1_vtbl
=
4500 ddraw1_QueryInterface
,
4505 ddraw1_CreateClipper
,
4506 ddraw1_CreatePalette
,
4507 ddraw1_CreateSurface
,
4508 ddraw1_DuplicateSurface
,
4509 ddraw1_EnumDisplayModes
,
4510 ddraw1_EnumSurfaces
,
4511 ddraw1_FlipToGDISurface
,
4513 ddraw1_GetDisplayMode
,
4514 ddraw1_GetFourCCCodes
,
4515 ddraw1_GetGDISurface
,
4516 ddraw1_GetMonitorFrequency
,
4518 ddraw1_GetVerticalBlankStatus
,
4520 ddraw1_RestoreDisplayMode
,
4521 ddraw1_SetCooperativeLevel
,
4522 ddraw1_SetDisplayMode
,
4523 ddraw1_WaitForVerticalBlank
,
4526 static const struct IDirect3D7Vtbl d3d7_vtbl
=
4528 /* IUnknown methods */
4529 d3d7_QueryInterface
,
4532 /* IDirect3D7 methods */
4535 d3d7_CreateVertexBuffer
,
4536 d3d7_EnumZBufferFormats
,
4537 d3d7_EvictManagedTextures
4540 static const struct IDirect3D3Vtbl d3d3_vtbl
=
4542 /* IUnknown methods */
4543 d3d3_QueryInterface
,
4546 /* IDirect3D3 methods */
4549 d3d3_CreateMaterial
,
4550 d3d3_CreateViewport
,
4553 d3d3_CreateVertexBuffer
,
4554 d3d3_EnumZBufferFormats
,
4555 d3d3_EvictManagedTextures
4558 static const struct IDirect3D2Vtbl d3d2_vtbl
=
4560 /* IUnknown methods */
4561 d3d2_QueryInterface
,
4564 /* IDirect3D2 methods */
4567 d3d2_CreateMaterial
,
4568 d3d2_CreateViewport
,
4573 static const struct IDirect3DVtbl d3d1_vtbl
=
4575 /* IUnknown methods */
4576 d3d1_QueryInterface
,
4579 /* IDirect3D methods */
4583 d3d1_CreateMaterial
,
4584 d3d1_CreateViewport
,
4588 /*****************************************************************************
4591 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
4592 * if none was found.
4594 * This function is in ddraw.c and the DDraw object space because D3D7
4595 * vertex buffers are created using the IDirect3D interface to the ddraw
4596 * object, so they can be valid across D3D devices(theoretically. The ddraw
4597 * object also owns the wined3d device
4601 * fvf: Fvf to find the decl for
4604 * NULL in case of an error, the vertex declaration for the FVF otherwise.
4606 *****************************************************************************/
4607 struct wined3d_vertex_declaration
*ddraw_find_decl(struct ddraw
*This
, DWORD fvf
)
4609 struct wined3d_vertex_declaration
*pDecl
= NULL
;
4611 int p
, low
, high
; /* deliberately signed */
4612 struct FvfToDecl
*convertedDecls
= This
->decls
;
4614 TRACE("Searching for declaration for fvf %08x... ", fvf
);
4617 high
= This
->numConvertedDecls
- 1;
4618 while(low
<= high
) {
4619 p
= (low
+ high
) >> 1;
4621 if(convertedDecls
[p
].fvf
== fvf
) {
4622 TRACE("found %p\n", convertedDecls
[p
].decl
);
4623 return convertedDecls
[p
].decl
;
4624 } else if(convertedDecls
[p
].fvf
< fvf
) {
4630 TRACE("not found. Creating and inserting at position %d.\n", low
);
4632 hr
= wined3d_vertex_declaration_create_from_fvf(This
->wined3d_device
,
4633 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
4634 if (hr
!= S_OK
) return NULL
;
4636 if(This
->declArraySize
== This
->numConvertedDecls
) {
4637 int grow
= max(This
->declArraySize
/ 2, 8);
4638 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
4639 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
4640 if (!convertedDecls
)
4642 wined3d_vertex_declaration_decref(pDecl
);
4645 This
->decls
= convertedDecls
;
4646 This
->declArraySize
+= grow
;
4649 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
4650 convertedDecls
[low
].decl
= pDecl
;
4651 convertedDecls
[low
].fvf
= fvf
;
4652 This
->numConvertedDecls
++;
4654 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
4658 static inline struct ddraw
*ddraw_from_device_parent(struct wined3d_device_parent
*device_parent
)
4660 return CONTAINING_RECORD(device_parent
, struct ddraw
, device_parent
);
4663 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
4664 struct wined3d_device
*device
)
4666 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
4669 /* This is run from device_process_message() in wined3d, we can't take the
4671 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
4673 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4674 MONITORINFO monitor_info
;
4678 TRACE("device_parent %p.\n", device_parent
);
4680 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) || !ddraw
->swapchain_window
)
4682 TRACE("Nothing to resize.\n");
4686 monitor
= MonitorFromWindow(ddraw
->swapchain_window
, MONITOR_DEFAULTTOPRIMARY
);
4687 monitor_info
.cbSize
= sizeof(monitor_info
);
4688 if (!GetMonitorInfoW(monitor
, &monitor_info
))
4690 ERR("Failed to get monitor info.\n");
4694 r
= &monitor_info
.rcMonitor
;
4695 TRACE("Resizing window %p to %s.\n", ddraw
->swapchain_window
, wine_dbgstr_rect(r
));
4697 if (!SetWindowPos(ddraw
->swapchain_window
, HWND_TOP
, r
->left
, r
->top
,
4698 r
->right
- r
->left
, r
->bottom
- r
->top
, SWP_SHOWWINDOW
| SWP_NOACTIVATE
))
4699 ERR("Failed to resize window.\n");
4702 static void CDECL
device_parent_activate(struct wined3d_device_parent
*device_parent
, BOOL activate
)
4704 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4706 TRACE("device_parent %p, activate %#x.\n", device_parent
, activate
);
4709 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_LOST
, DDRAW_DEVICE_STATE_OK
);
4711 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_OK
, DDRAW_DEVICE_STATE_LOST
);
4714 static HRESULT CDECL
device_parent_surface_created(struct wined3d_device_parent
*device_parent
,
4715 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
, struct wined3d_surface
*surface
,
4716 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
4718 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4719 struct ddraw_surface
*ddraw_surface
;
4721 TRACE("device_parent %p, wined3d_texture %p, sub_resource_idx %u, surface %p, parent %p, parent_ops %p.\n",
4722 device_parent
, wined3d_texture
, sub_resource_idx
, surface
, parent
, parent_ops
);
4724 /* We have a swapchain or wined3d internal texture. */
4725 if (!wined3d_texture_get_parent(wined3d_texture
) || wined3d_texture_get_parent(wined3d_texture
) == ddraw
)
4728 *parent_ops
= &ddraw_null_wined3d_parent_ops
;
4733 if (!(ddraw_surface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ddraw_surface
))))
4735 ERR("Failed to allocate surface memory.\n");
4736 return DDERR_OUTOFVIDEOMEMORY
;
4739 ddraw_surface_init(ddraw_surface
, ddraw
, wined3d_texture_get_parent(wined3d_texture
), surface
, parent_ops
);
4740 *parent
= ddraw_surface
;
4741 list_add_head(&ddraw
->surface_list
, &ddraw_surface
->surface_list_entry
);
4743 TRACE("Created ddraw surface %p.\n", ddraw_surface
);
4748 static HRESULT CDECL
device_parent_volume_created(struct wined3d_device_parent
*device_parent
,
4749 struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
4750 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
4752 TRACE("device_parent %p, texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
4753 device_parent
, wined3d_texture
, sub_resource_idx
, parent
, parent_ops
);
4756 *parent_ops
= &ddraw_null_wined3d_parent_ops
;
4761 static void STDMETHODCALLTYPE
ddraw_frontbuffer_destroyed(void *parent
)
4763 struct ddraw
*ddraw
= parent
;
4764 ddraw
->wined3d_frontbuffer
= NULL
;
4767 static const struct wined3d_parent_ops ddraw_frontbuffer_parent_ops
=
4769 ddraw_frontbuffer_destroyed
,
4772 static HRESULT CDECL
device_parent_create_swapchain_texture(struct wined3d_device_parent
*device_parent
,
4773 void *container_parent
, const struct wined3d_resource_desc
*desc
, struct wined3d_texture
**texture
)
4775 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4778 TRACE("device_parent %p, container_parent %p, desc %p, texture %p.\n",
4779 device_parent
, container_parent
, desc
, texture
);
4781 if (ddraw
->wined3d_frontbuffer
)
4783 ERR("Frontbuffer already created.\n");
4787 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, desc
, 1,
4788 WINED3D_SURFACE_MAPPABLE
, NULL
, ddraw
, &ddraw_frontbuffer_parent_ops
, texture
)))
4790 WARN("Failed to create texture, hr %#x.\n", hr
);
4794 ddraw
->wined3d_frontbuffer
= wined3d_surface_from_resource(wined3d_texture_get_sub_resource(*texture
, 0));
4799 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
4800 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
4802 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4805 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent
, desc
, swapchain
);
4807 if (ddraw
->wined3d_swapchain
)
4809 ERR("Swapchain already created.\n");
4813 if (FAILED(hr
= wined3d_swapchain_create(ddraw
->wined3d_device
, desc
, NULL
,
4814 &ddraw_null_wined3d_parent_ops
, swapchain
)))
4815 WARN("Failed to create swapchain, hr %#x.\n", hr
);
4820 static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops
=
4822 device_parent_wined3d_device_created
,
4823 device_parent_mode_changed
,
4824 device_parent_activate
,
4825 device_parent_surface_created
,
4826 device_parent_volume_created
,
4827 device_parent_create_swapchain_texture
,
4828 device_parent_create_swapchain
,
4831 HRESULT
ddraw_init(struct ddraw
*ddraw
, DWORD flags
, enum wined3d_device_type device_type
)
4836 ddraw
->IDirectDraw7_iface
.lpVtbl
= &ddraw7_vtbl
;
4837 ddraw
->IDirectDraw_iface
.lpVtbl
= &ddraw1_vtbl
;
4838 ddraw
->IDirectDraw2_iface
.lpVtbl
= &ddraw2_vtbl
;
4839 ddraw
->IDirectDraw4_iface
.lpVtbl
= &ddraw4_vtbl
;
4840 ddraw
->IDirect3D_iface
.lpVtbl
= &d3d1_vtbl
;
4841 ddraw
->IDirect3D2_iface
.lpVtbl
= &d3d2_vtbl
;
4842 ddraw
->IDirect3D3_iface
.lpVtbl
= &d3d3_vtbl
;
4843 ddraw
->IDirect3D7_iface
.lpVtbl
= &d3d7_vtbl
;
4844 ddraw
->device_parent
.ops
= &ddraw_wined3d_device_parent_ops
;
4845 ddraw
->numIfaces
= 1;
4848 flags
|= DDRAW_WINED3D_FLAGS
;
4849 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
4851 flags
|= WINED3D_NO3D
;
4852 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
4854 WARN("Failed to create a wined3d object.\n");
4859 if (FAILED(hr
= wined3d_get_device_caps(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
, &caps
)))
4861 ERR("Failed to get device caps, hr %#x.\n", hr
);
4862 wined3d_decref(ddraw
->wined3d
);
4866 if (!(caps
.ddraw_caps
.caps
& WINEDDCAPS_3D
))
4868 WARN("Created a wined3d object without 3D support.\n");
4869 ddraw
->flags
|= DDRAW_NO3D
;
4872 if (FAILED(hr
= wined3d_device_create(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
,
4873 NULL
, 0, DDRAW_STRIDE_ALIGNMENT
, &ddraw
->device_parent
, &ddraw
->wined3d_device
)))
4875 WARN("Failed to create a wined3d device, hr %#x.\n", hr
);
4876 wined3d_decref(ddraw
->wined3d
);
4880 list_init(&ddraw
->surface_list
);