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
24 #include "ddraw_private.h"
28 #include "wine/exception.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
32 static const struct ddraw
*exclusive_ddraw
;
33 static HWND exclusive_window
;
35 /* Device identifier. Don't relay it to WineD3D */
36 static const DDDEVICEIDENTIFIER2 deviceidentifier
=
38 "vga.dll", /* default 2D driver */
40 { { 0x00010001, 0x00010001 } },
42 /* a8373c10-7ac4-4deb-849a-009844d08b2d */
43 {0xa8373c10,0x7ac4,0x4deb, {0x84,0x9a,0x00,0x98,0x44,0xd0,0x8b,0x2d}},
47 static struct enum_device_entry
49 char interface_name
[100];
50 char device_name
[100];
51 const GUID
*device_guid
;
56 "WINE Direct3D7 Hardware Transform and Lighting acceleration using WineD3D",
58 &IID_IDirect3DTnLHalDevice
,
63 "WINE Direct3D7 Hardware acceleration using WineD3D",
65 &IID_IDirect3DHALDevice
,
70 "WINE Direct3D7 RGB Software Emulation using WineD3D",
72 &IID_IDirect3DRGBDevice
,
76 static void STDMETHODCALLTYPE
ddraw_null_wined3d_object_destroyed(void *parent
) {}
78 const struct wined3d_parent_ops ddraw_null_wined3d_parent_ops
=
80 ddraw_null_wined3d_object_destroyed
,
83 static inline struct ddraw
*impl_from_IDirectDraw(IDirectDraw
*iface
)
85 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw_iface
);
88 static inline struct ddraw
*impl_from_IDirectDraw2(IDirectDraw2
*iface
)
90 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw2_iface
);
93 static inline struct ddraw
*impl_from_IDirectDraw4(IDirectDraw4
*iface
)
95 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw4_iface
);
98 static inline struct ddraw
*impl_from_IDirectDraw7(IDirectDraw7
*iface
)
100 return CONTAINING_RECORD(iface
, struct ddraw
, IDirectDraw7_iface
);
103 static inline struct ddraw
*impl_from_IDirect3D(IDirect3D
*iface
)
105 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D_iface
);
108 static inline struct ddraw
*impl_from_IDirect3D2(IDirect3D2
*iface
)
110 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D2_iface
);
113 static inline struct ddraw
*impl_from_IDirect3D3(IDirect3D3
*iface
)
115 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D3_iface
);
118 static inline struct ddraw
*impl_from_IDirect3D7(IDirect3D7
*iface
)
120 return CONTAINING_RECORD(iface
, struct ddraw
, IDirect3D7_iface
);
123 static HRESULT WINAPI
ddraw7_QueryInterface(IDirectDraw7
*iface
, REFIID riid
, void **out
)
125 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
127 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
132 return DDERR_INVALIDPARAMS
;
135 /* The refcount unit test revealed that an IDirect3D7 interface can only
136 * be queried from a DirectDraw object that was created as an IDirectDraw7
137 * interface. The older interfaces can query any IDirect3D version except
138 * 7, because they are all initially created as IDirectDraw. This isn't
139 * really crucial behavior, and messy to implement with the common
140 * creation function, so it has been left out here. */
141 if (IsEqualGUID(&IID_IDirectDraw7
, riid
)
142 || IsEqualGUID(&IID_IUnknown
, riid
))
144 *out
= &ddraw
->IDirectDraw7_iface
;
145 TRACE("Returning IDirectDraw7 interface %p.\n", *out
);
147 else if (IsEqualGUID(&IID_IDirectDraw4
, riid
))
149 *out
= &ddraw
->IDirectDraw4_iface
;
150 TRACE("Returning IDirectDraw4 interface %p.\n", *out
);
152 else if (IsEqualGUID(&IID_IDirectDraw2
, riid
))
154 *out
= &ddraw
->IDirectDraw2_iface
;
155 TRACE("Returning IDirectDraw2 interface %p.\n", *out
);
157 else if (IsEqualGUID(&IID_IDirectDraw
, riid
))
159 *out
= &ddraw
->IDirectDraw_iface
;
160 TRACE("Returning IDirectDraw interface %p.\n", *out
);
162 else if (IsEqualGUID(&IID_IDirect3D7
, riid
))
164 ddraw
->d3dversion
= 7;
165 *out
= &ddraw
->IDirect3D7_iface
;
166 TRACE("Returning Direct3D7 interface %p.\n", *out
);
168 else if (IsEqualGUID(&IID_IDirect3D3
, riid
))
170 ddraw
->d3dversion
= 3;
171 *out
= &ddraw
->IDirect3D3_iface
;
172 TRACE("Returning Direct3D3 interface %p.\n", *out
);
174 else if (IsEqualGUID(&IID_IDirect3D2
, riid
))
176 ddraw
->d3dversion
= 2;
177 *out
= &ddraw
->IDirect3D2_iface
;
178 TRACE("Returning Direct3D2 interface %p.\n", *out
);
180 else if (IsEqualGUID(&IID_IDirect3D
, riid
))
182 ddraw
->d3dversion
= 1;
183 *out
= &ddraw
->IDirect3D_iface
;
184 TRACE("Returning Direct3D interface %p.\n", *out
);
186 /* Unknown interface */
189 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
191 return E_NOINTERFACE
;
194 IUnknown_AddRef((IUnknown
*)*out
);
198 static HRESULT WINAPI
ddraw4_QueryInterface(IDirectDraw4
*iface
, REFIID riid
, void **object
)
200 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
202 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
204 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
207 static HRESULT WINAPI
ddraw2_QueryInterface(IDirectDraw2
*iface
, REFIID riid
, void **object
)
209 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
211 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
213 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
216 static HRESULT WINAPI
ddraw1_QueryInterface(IDirectDraw
*iface
, REFIID riid
, void **object
)
218 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
220 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
222 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
225 static HRESULT WINAPI
d3d7_QueryInterface(IDirect3D7
*iface
, REFIID riid
, void **object
)
227 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
229 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
231 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
234 static HRESULT WINAPI
d3d3_QueryInterface(IDirect3D3
*iface
, REFIID riid
, void **object
)
236 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
238 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
240 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
243 static HRESULT WINAPI
d3d2_QueryInterface(IDirect3D2
*iface
, REFIID riid
, void **object
)
245 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
247 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
249 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
252 static HRESULT WINAPI
d3d1_QueryInterface(IDirect3D
*iface
, REFIID riid
, void **object
)
254 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
256 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
258 return ddraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, riid
, object
);
261 /*****************************************************************************
262 * IDirectDraw7::AddRef
264 * Increases the interfaces refcount, basically
266 * DDraw refcounting is a bit tricky. The different DirectDraw interface
267 * versions have individual refcounts, but the IDirect3D interfaces do not.
268 * All interfaces are from one object, that means calling QueryInterface on an
269 * IDirectDraw7 interface for an IDirectDraw4 interface does not create a new
272 * That means all AddRef and Release implementations of IDirectDrawX work
273 * with their own counter, and IDirect3DX::AddRef thunk to IDirectDraw (1),
274 * except of IDirect3D7 which thunks to IDirectDraw7
276 * Returns: The new refcount
278 *****************************************************************************/
279 static ULONG WINAPI
ddraw7_AddRef(IDirectDraw7
*iface
)
281 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
282 ULONG ref
= InterlockedIncrement(&This
->ref7
);
284 TRACE("%p increasing refcount to %u.\n", This
, ref
);
286 if(ref
== 1) InterlockedIncrement(&This
->numIfaces
);
291 static ULONG WINAPI
ddraw4_AddRef(IDirectDraw4
*iface
)
293 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
294 ULONG ref
= InterlockedIncrement(&This
->ref4
);
296 TRACE("%p increasing refcount to %u.\n", This
, ref
);
298 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
303 static ULONG WINAPI
ddraw2_AddRef(IDirectDraw2
*iface
)
305 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
306 ULONG ref
= InterlockedIncrement(&This
->ref2
);
308 TRACE("%p increasing refcount to %u.\n", This
, ref
);
310 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
315 static ULONG WINAPI
ddraw1_AddRef(IDirectDraw
*iface
)
317 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
318 ULONG ref
= InterlockedIncrement(&This
->ref1
);
320 TRACE("%p increasing refcount to %u.\n", This
, ref
);
322 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
327 static ULONG WINAPI
d3d7_AddRef(IDirect3D7
*iface
)
329 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
331 TRACE("iface %p.\n", iface
);
333 return ddraw7_AddRef(&This
->IDirectDraw7_iface
);
336 static ULONG WINAPI
d3d3_AddRef(IDirect3D3
*iface
)
338 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
340 TRACE("iface %p.\n", iface
);
342 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
345 static ULONG WINAPI
d3d2_AddRef(IDirect3D2
*iface
)
347 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
349 TRACE("iface %p.\n", iface
);
351 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
354 static ULONG WINAPI
d3d1_AddRef(IDirect3D
*iface
)
356 struct ddraw
*This
= impl_from_IDirect3D(iface
);
358 TRACE("iface %p.\n", iface
);
360 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
363 static void ddraw_destroy_swapchain(struct ddraw
*ddraw
)
367 TRACE("Destroying the swapchain.\n");
369 wined3d_swapchain_decref(ddraw
->wined3d_swapchain
);
371 for (i
= 0; i
< ddraw
->numConvertedDecls
; ++i
)
373 wined3d_vertex_declaration_decref(ddraw
->decls
[i
].decl
);
375 heap_free(ddraw
->decls
);
376 ddraw
->numConvertedDecls
= 0;
378 wined3d_swapchain_decref(ddraw
->wined3d_swapchain
);
379 ddraw
->wined3d_swapchain
= NULL
;
381 /* Free the d3d window if one was created. */
382 if (ddraw
->d3d_window
&& ddraw
->d3d_window
!= ddraw
->dest_window
)
384 TRACE("Destroying the hidden render window %p.\n", ddraw
->d3d_window
);
385 DestroyWindow(ddraw
->d3d_window
);
386 ddraw
->d3d_window
= 0;
389 ddraw
->flags
&= ~DDRAW_D3D_INITIALIZED
;
391 ddraw_set_swapchain_window(ddraw
, NULL
);
393 TRACE("Swapchain destroyed.\n");
396 /*****************************************************************************
399 * Destroys a ddraw object if all refcounts are 0. This is to share code
400 * between the IDirectDrawX::Release functions
403 * This: DirectDraw object to destroy
405 *****************************************************************************/
406 static void ddraw_destroy(struct ddraw
*This
)
408 IDirectDraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, NULL
, DDSCL_NORMAL
);
409 IDirectDraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
411 /* Destroy the device window if we created one */
412 if(This
->devicewindow
!= 0)
414 TRACE(" (%p) Destroying the device window %p\n", This
, This
->devicewindow
);
415 DestroyWindow(This
->devicewindow
);
416 This
->devicewindow
= 0;
419 wined3d_mutex_lock();
420 list_remove(&This
->ddraw_list_entry
);
421 wined3d_mutex_unlock();
423 if (This
->wined3d_swapchain
)
424 ddraw_destroy_swapchain(This
);
425 wined3d_stateblock_decref(This
->state
);
426 wined3d_device_decref(This
->wined3d_device
);
427 wined3d_decref(This
->wined3d
);
430 This
->d3ddevice
->ddraw
= NULL
;
432 /* Now free the object */
436 /*****************************************************************************
437 * IDirectDraw7::Release
439 * Decreases the refcount. If the refcount falls to 0, the object is destroyed
441 * Returns: The new refcount
442 *****************************************************************************/
443 static ULONG WINAPI
ddraw7_Release(IDirectDraw7
*iface
)
445 struct ddraw
*This
= impl_from_IDirectDraw7(iface
);
446 ULONG ref
= InterlockedDecrement(&This
->ref7
);
448 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
450 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
456 static ULONG WINAPI
ddraw4_Release(IDirectDraw4
*iface
)
458 struct ddraw
*This
= impl_from_IDirectDraw4(iface
);
459 ULONG ref
= InterlockedDecrement(&This
->ref4
);
461 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
463 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
469 static ULONG WINAPI
ddraw2_Release(IDirectDraw2
*iface
)
471 struct ddraw
*This
= impl_from_IDirectDraw2(iface
);
472 ULONG ref
= InterlockedDecrement(&This
->ref2
);
474 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
476 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
482 static ULONG WINAPI
ddraw1_Release(IDirectDraw
*iface
)
484 struct ddraw
*This
= impl_from_IDirectDraw(iface
);
485 ULONG ref
= InterlockedDecrement(&This
->ref1
);
487 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
489 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
495 static ULONG WINAPI
d3d7_Release(IDirect3D7
*iface
)
497 struct ddraw
*This
= impl_from_IDirect3D7(iface
);
499 TRACE("iface %p.\n", iface
);
501 return ddraw7_Release(&This
->IDirectDraw7_iface
);
504 static ULONG WINAPI
d3d3_Release(IDirect3D3
*iface
)
506 struct ddraw
*This
= impl_from_IDirect3D3(iface
);
508 TRACE("iface %p.\n", iface
);
510 return ddraw1_Release(&This
->IDirectDraw_iface
);
513 static ULONG WINAPI
d3d2_Release(IDirect3D2
*iface
)
515 struct ddraw
*This
= impl_from_IDirect3D2(iface
);
517 TRACE("iface %p.\n", iface
);
519 return ddraw1_Release(&This
->IDirectDraw_iface
);
522 static ULONG WINAPI
d3d1_Release(IDirect3D
*iface
)
524 struct ddraw
*This
= impl_from_IDirect3D(iface
);
526 TRACE("iface %p.\n", iface
);
528 return ddraw1_Release(&This
->IDirectDraw_iface
);
531 /*****************************************************************************
532 * IDirectDraw methods
533 *****************************************************************************/
535 static HRESULT
ddraw_set_focus_window(struct ddraw
*ddraw
, HWND window
)
537 /* FIXME: This looks wrong, exclusive mode should imply a destination
539 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) && ddraw
->dest_window
)
541 TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET.\n");
542 return DDERR_HWNDALREADYSET
;
545 ddraw
->focuswindow
= window
;
550 static HRESULT
ddraw_attach_d3d_device(struct ddraw
*ddraw
, HWND window
,
551 BOOL windowed
, struct wined3d_swapchain
**wined3d_swapchain
)
553 struct wined3d_swapchain_desc swapchain_desc
;
554 struct wined3d_display_mode mode
;
557 TRACE("ddraw %p.\n", ddraw
);
559 if (FAILED(hr
= wined3d_output_get_display_mode(ddraw
->wined3d_output
, &mode
, NULL
)))
561 ERR("Failed to get display mode.\n");
565 memset(&swapchain_desc
, 0, sizeof(swapchain_desc
));
566 swapchain_desc
.output
= ddraw
->wined3d_output
;
567 swapchain_desc
.backbuffer_width
= mode
.width
;
568 swapchain_desc
.backbuffer_height
= mode
.height
;
569 swapchain_desc
.backbuffer_format
= mode
.format_id
;
570 swapchain_desc
.backbuffer_bind_flags
= 0;
571 swapchain_desc
.backbuffer_count
= 1;
572 swapchain_desc
.swap_effect
= WINED3D_SWAP_EFFECT_DISCARD
;
573 swapchain_desc
.device_window
= window
;
574 swapchain_desc
.windowed
= windowed
;
575 swapchain_desc
.flags
= WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH
576 | WINED3D_SWAPCHAIN_IMPLICIT
| WINED3D_SWAPCHAIN_NO_WINDOW_CHANGES
;
578 if (ddraw
->flags
& DDRAW_NO3D
)
579 return wined3d_swapchain_create(ddraw
->wined3d_device
, &swapchain_desc
,
580 NULL
, &ddraw_null_wined3d_parent_ops
, wined3d_swapchain
);
582 if (!window
|| window
== GetDesktopWindow())
584 window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "Hidden D3D Window",
585 WS_DISABLED
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
586 NULL
, NULL
, NULL
, NULL
);
589 ERR("Failed to create window, last error %#x.\n", GetLastError());
593 ShowWindow(window
, SW_HIDE
); /* Just to be sure */
594 WARN("No window for the Direct3DDevice, created hidden window %p.\n", window
);
596 swapchain_desc
.device_window
= window
;
600 TRACE("Using existing window %p for Direct3D rendering.\n", window
);
602 ddraw
->d3d_window
= window
;
604 /* Set this NOW, otherwise creating the depth stencil surface will cause a
605 * recursive loop until ram or emulated video memory is full. */
606 ddraw
->flags
|= DDRAW_D3D_INITIALIZED
;
607 if (FAILED(hr
= wined3d_swapchain_create(ddraw
->wined3d_device
, &swapchain_desc
,
608 NULL
, &ddraw_null_wined3d_parent_ops
, wined3d_swapchain
)))
610 ddraw
->flags
&= ~DDRAW_D3D_INITIALIZED
;
611 DestroyWindow(window
);
612 ddraw
->d3d_window
= NULL
;
616 ddraw
->declArraySize
= 2;
617 if (!(ddraw
->decls
= heap_alloc_zero(ddraw
->declArraySize
* sizeof(*ddraw
->decls
))))
619 ERR("Error allocating an array for the converted vertex decls.\n");
620 ddraw
->declArraySize
= 0;
621 wined3d_swapchain_decref(*wined3d_swapchain
);
622 DestroyWindow(window
);
623 ddraw
->d3d_window
= NULL
;
624 return E_OUTOFMEMORY
;
627 TRACE("Successfully initialized 3D.\n");
632 static HRESULT
ddraw_create_swapchain(struct ddraw
*ddraw
, HWND window
, BOOL windowed
)
636 if (ddraw
->wined3d_swapchain
)
638 ERR("Swapchain already created.\n");
642 if (FAILED(hr
= ddraw_attach_d3d_device(ddraw
, window
, windowed
, &ddraw
->wined3d_swapchain
)))
644 ERR("Failed to create swapchain, hr %#x.\n", hr
);
647 wined3d_swapchain_incref(ddraw
->wined3d_swapchain
);
649 ddraw_set_swapchain_window(ddraw
, window
);
651 if (ddraw
->primary
&& ddraw
->primary
->palette
)
652 wined3d_swapchain_set_palette(ddraw
->wined3d_swapchain
, ddraw
->primary
->palette
->wined3d_palette
);
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
);
670 struct wined3d_display_mode mode
;
674 TRACE("iface %p.\n", iface
);
676 wined3d_mutex_lock();
678 if (!(ddraw
->flags
& DDRAW_RESTORE_MODE
))
680 wined3d_mutex_unlock();
684 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
686 wined3d_mutex_unlock();
687 return DDERR_NOEXCLUSIVEMODE
;
690 if (SUCCEEDED(hr
= wined3d_output_set_display_mode(ddraw
->wined3d_output
, NULL
)))
692 ddraw
->flags
&= ~DDRAW_RESTORE_MODE
;
693 if (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
&&
694 SUCCEEDED(hr
= wined3d_output_get_display_mode(ddraw
->wined3d_output
, &mode
, NULL
)))
696 SetRect(&clip_rect
, 0, 0, mode
.width
, mode
.height
);
697 ClipCursor(&clip_rect
);
701 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_OK
);
703 wined3d_mutex_unlock();
708 static HRESULT WINAPI
ddraw4_RestoreDisplayMode(IDirectDraw4
*iface
)
710 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
712 TRACE("iface %p.\n", iface
);
714 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
717 static HRESULT WINAPI
ddraw2_RestoreDisplayMode(IDirectDraw2
*iface
)
719 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
721 TRACE("iface %p.\n", iface
);
723 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
726 static HRESULT WINAPI
ddraw1_RestoreDisplayMode(IDirectDraw
*iface
)
728 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
730 TRACE("iface %p.\n", iface
);
732 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
735 /*****************************************************************************
736 * IDirectDraw7::SetCooperativeLevel
738 * Sets the cooperative level for the DirectDraw object, and the window
739 * assigned to it. The cooperative level determines the general behavior
740 * of the DirectDraw application
742 * Warning: This is quite tricky, as it's not really documented which
743 * cooperative levels can be combined with each other. If a game fails
744 * after this function, try to check the cooperative levels passed on
745 * Windows, and if it returns something different.
747 * If you think that this function caused the failure because it writes a
748 * fixme, be sure to run again with a +ddraw trace.
750 * What is known about cooperative levels (See the ddraw modes test):
751 * DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN.
752 * DDSCL_NORMAL is not compatible with DDSCL_EXCLUSIVE.
753 * Unlike what msdn claims, DDSCL_NORMAL | DDSCL_FULLSCREEN is allowed.
754 * DDSCL_SETFOCUSWINDOW can be passed only in DDSCL_NORMAL mode, but after that
755 * DDSCL_EXCLUSIVE can be activated.
756 * DDSCL_SETFOCUSWINDOW may only be used with DDSCL_NOWINDOWCHANGES or
757 * DDSCL_CREATEDEVICEWINDOW.
759 * Handled flags: DDSCL_NORMAL, DDSCL_FULLSCREEN, DDSCL_EXCLUSIVE,
760 * DDSCL_CREATEDEVICEWINDOW, DDSCL_SETDEVICEWINDOW
761 * DDSCL_SETFOCUSWINDOW (partially),
762 * DDSCL_MULTITHREADED (work in progress)
763 * DDSCL_FPUPRESERVE (see device.c)
765 * Unsure about this: DDSCL_FPUSETUP
767 * These don't seem very important for wine:
768 * DDSCL_ALLOWREBOOT, DDSCL_NOWINDOWCHANGES, DDSCL_ALLOWMODEX
771 * DD_OK if the cooperative level was set successfully
772 * DDERR_INVALIDPARAMS if the passed cooperative level combination is invalid
773 * DDERR_HWNDALREADYSET if DDSCL_SETFOCUSWINDOW is passed in exclusive mode
774 * (Probably others too, have to investigate)
776 *****************************************************************************/
777 static HRESULT
ddraw_set_cooperative_level(struct ddraw
*ddraw
, HWND window
,
778 DWORD cooplevel
, BOOL restore_mode_on_normal
)
780 struct wined3d_rendertarget_view
*rtv
= NULL
, *dsv
= NULL
;
781 struct wined3d_stateblock
*stateblock
;
782 BOOL restore_state
= FALSE
;
786 TRACE("ddraw %p, window %p, flags %#x, restore_mode_on_normal %x.\n", ddraw
, window
, cooplevel
,
787 restore_mode_on_normal
);
788 DDRAW_dump_cooperativelevel(cooplevel
);
790 wined3d_mutex_lock();
792 if (ddraw
->flags
& DDRAW_SCL_RECURSIVE
)
794 WARN("Recursive call, returning DD_OK.\n");
798 ddraw
->flags
|= DDRAW_SCL_RECURSIVE
;
800 /* Tests suggest that we need one of them: */
801 if(!(cooplevel
& (DDSCL_SETFOCUSWINDOW
|
805 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
806 hr
= DDERR_INVALIDPARAMS
;
810 if ((cooplevel
& DDSCL_CREATEDEVICEWINDOW
) && !(cooplevel
& DDSCL_EXCLUSIVE
))
812 WARN("DDSCL_CREATEDEVICEWINDOW requires DDSCL_EXCLUSIVE.\n");
813 hr
= DDERR_INVALIDPARAMS
;
817 /* Handle those levels first which set various hwnds */
818 if ((cooplevel
& DDSCL_SETFOCUSWINDOW
) && !(cooplevel
& DDSCL_CREATEDEVICEWINDOW
))
820 /* This isn't compatible with a lot of flags */
821 if (cooplevel
& (DDSCL_MULTITHREADED
826 | DDSCL_SETDEVICEWINDOW
831 WARN("Called with incompatible flags, returning DDERR_INVALIDPARAMS.\n");
832 hr
= DDERR_INVALIDPARAMS
;
836 hr
= ddraw_set_focus_window(ddraw
, window
);
840 if (cooplevel
& DDSCL_EXCLUSIVE
)
842 if (!(cooplevel
& DDSCL_FULLSCREEN
) || !(window
|| (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)))
844 WARN("DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN and a window.\n");
845 hr
= DDERR_INVALIDPARAMS
;
849 if (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)
853 if (!ddraw
->focuswindow
&& !(cooplevel
& DDSCL_SETFOCUSWINDOW
))
855 WARN("No focus window set.\n");
856 hr
= DDERR_NOFOCUSWINDOW
;
860 device_window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "DirectDrawDeviceWnd",
861 WS_POPUP
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
862 NULL
, NULL
, NULL
, NULL
);
865 ERR("Failed to create window, last error %#x.\n", GetLastError());
870 ShowWindow(device_window
, SW_SHOW
);
871 TRACE("Created a device window %p.\n", device_window
);
873 /* Native apparently leaks the created device window if setting the
874 * focus window below fails. */
875 ddraw
->cooperative_level
|= DDSCL_CREATEDEVICEWINDOW
;
876 ddraw
->devicewindow
= device_window
;
878 if (cooplevel
& DDSCL_SETFOCUSWINDOW
)
886 if (FAILED(hr
= ddraw_set_focus_window(ddraw
, window
)))
890 window
= device_window
;
895 if (ddraw
->cooperative_level
& DDSCL_CREATEDEVICEWINDOW
)
896 DestroyWindow(ddraw
->devicewindow
);
897 ddraw
->devicewindow
= NULL
;
898 ddraw
->focuswindow
= NULL
;
901 if ((cooplevel
& DDSCL_EXCLUSIVE
) && exclusive_window
!= window
)
903 ddraw
->device_state
= DDRAW_DEVICE_STATE_NOT_RESTORED
;
904 exclusive_window
= window
;
907 if (cooplevel
& DDSCL_MULTITHREADED
&& !(ddraw
->cooperative_level
& DDSCL_MULTITHREADED
))
908 wined3d_device_set_multithreaded(ddraw
->wined3d_device
);
910 if (ddraw
->wined3d_swapchain
)
912 if (!(ddraw
->flags
& DDRAW_NO3D
))
914 restore_state
= TRUE
;
916 if (FAILED(hr
= wined3d_stateblock_create(ddraw
->wined3d_device
,
917 ddraw
->state
, WINED3D_SBT_ALL
, &stateblock
)))
919 ERR("Failed to create stateblock, hr %#x.\n", hr
);
923 rtv
= wined3d_device_get_rendertarget_view(ddraw
->wined3d_device
, 0);
924 /* Rendering to ddraw->wined3d_frontbuffer. */
925 if (rtv
&& !wined3d_rendertarget_view_get_sub_resource_parent(rtv
))
928 wined3d_rendertarget_view_incref(rtv
);
930 if ((dsv
= wined3d_device_get_depth_stencil_view(ddraw
->wined3d_device
)))
931 wined3d_rendertarget_view_incref(dsv
);
934 ddraw_destroy_swapchain(ddraw
);
937 if (FAILED(hr
= ddraw_create_swapchain(ddraw
, window
, !(cooplevel
& DDSCL_FULLSCREEN
))))
938 ERR("Failed to create swapchain, hr %#x.\n", hr
);
944 wined3d_device_set_depth_stencil_view(ddraw
->wined3d_device
, dsv
);
945 wined3d_rendertarget_view_decref(dsv
);
950 wined3d_device_set_rendertarget_view(ddraw
->wined3d_device
, 0, rtv
, FALSE
);
951 wined3d_rendertarget_view_decref(rtv
);
954 wined3d_stateblock_apply(stateblock
, ddraw
->state
);
955 wined3d_stateblock_decref(stateblock
);
958 if (!(cooplevel
& DDSCL_EXCLUSIVE
) && (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
960 if (restore_mode_on_normal
&& FAILED(ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
)))
961 ERR("RestoreDisplayMode failed\n");
965 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
966 && (window
!= ddraw
->dest_window
|| !(cooplevel
& DDSCL_EXCLUSIVE
)))
967 wined3d_device_release_focus_window(ddraw
->wined3d_device
);
969 if ((cooplevel
& DDSCL_EXCLUSIVE
)
970 && (window
!= ddraw
->dest_window
|| !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)))
972 hr
= wined3d_device_acquire_focus_window(ddraw
->wined3d_device
, window
);
975 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
980 if (cooplevel
& DDSCL_EXCLUSIVE
)
982 SetRect(&clip_rect
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
));
983 ClipCursor(&clip_rect
);
986 /* Unhandled flags */
987 if (cooplevel
& DDSCL_ALLOWREBOOT
)
988 WARN("Unhandled flag DDSCL_ALLOWREBOOT, harmless\n");
989 if (cooplevel
& DDSCL_ALLOWMODEX
)
990 WARN("Unhandled flag DDSCL_ALLOWMODEX, harmless\n");
991 if (cooplevel
& DDSCL_FPUSETUP
)
992 WARN("Unhandled flag DDSCL_FPUSETUP, harmless\n");
994 if (cooplevel
& DDSCL_EXCLUSIVE
)
995 exclusive_ddraw
= ddraw
;
996 else if (exclusive_ddraw
== ddraw
)
997 exclusive_ddraw
= NULL
;
999 /* Store the cooperative_level */
1000 ddraw
->cooperative_level
= cooplevel
;
1001 ddraw
->dest_window
= window
;
1003 TRACE("SetCooperativeLevel returning DD_OK\n");
1006 ddraw
->flags
&= ~DDRAW_SCL_RECURSIVE
;
1007 wined3d_mutex_unlock();
1012 static HRESULT WINAPI
ddraw7_SetCooperativeLevel(IDirectDraw7
*iface
, HWND window
, DWORD flags
)
1014 struct ddraw
*ddraw
= impl_from_IDirectDraw7(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
ddraw4_SetCooperativeLevel(IDirectDraw4
*iface
, HWND window
, DWORD flags
)
1023 struct ddraw
*ddraw
= impl_from_IDirectDraw4(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
ddraw2_SetCooperativeLevel(IDirectDraw2
*iface
, HWND window
, DWORD flags
)
1032 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1034 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1036 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1039 static HRESULT WINAPI
ddraw1_SetCooperativeLevel(IDirectDraw
*iface
, HWND window
, DWORD flags
)
1041 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1044 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1046 hr
= ddraw_set_cooperative_level(ddraw
, window
, flags
, FALSE
);
1048 ddraw
->flags
|= DDRAW_SCL_DDRAW1
;
1052 /*****************************************************************************
1053 * IDirectDraw7::SetDisplayMode
1055 * Sets the display screen resolution, color depth and refresh frequency
1056 * when in fullscreen mode (in theory).
1057 * Possible return values listed in the SDK suggest that this method fails
1058 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
1059 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
1060 * It seems to be valid to pass 0 for With and Height, this has to be tested
1061 * It could mean that the current video mode should be left as-is. (But why
1065 * Height, Width: Screen dimension
1066 * BPP: Color depth in Bits per pixel
1067 * Refreshrate: Screen refresh rate
1068 * Flags: Other stuff
1073 *****************************************************************************/
1074 static HRESULT WINAPI
ddraw7_SetDisplayMode(IDirectDraw7
*iface
, DWORD width
, DWORD height
,
1075 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1077 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1078 struct wined3d_display_mode mode
;
1079 enum wined3d_format_id format
;
1083 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1084 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1086 if (force_refresh_rate
!= 0)
1088 TRACE("ForceRefreshRate overriding passed-in refresh rate (%u Hz) to %u Hz\n",
1089 refresh_rate
, force_refresh_rate
);
1090 refresh_rate
= force_refresh_rate
;
1093 wined3d_mutex_lock();
1095 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
1097 wined3d_mutex_unlock();
1098 return DDERR_NOEXCLUSIVEMODE
;
1101 if (!width
|| !height
)
1103 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here. */
1104 wined3d_mutex_unlock();
1110 case 8: format
= WINED3DFMT_P8_UINT
; break;
1111 case 15: format
= WINED3DFMT_B5G5R5X1_UNORM
; break;
1112 case 16: format
= WINED3DFMT_B5G6R5_UNORM
; break;
1113 case 24: format
= WINED3DFMT_B8G8R8_UNORM
; break;
1114 case 32: format
= WINED3DFMT_B8G8R8X8_UNORM
; break;
1115 default: format
= WINED3DFMT_UNKNOWN
; break;
1119 mode
.height
= height
;
1120 mode
.refresh_rate
= refresh_rate
;
1121 mode
.format_id
= format
;
1122 mode
.scanline_ordering
= WINED3D_SCANLINE_ORDERING_UNKNOWN
;
1124 /* TODO: The possible return values from msdn suggest that the screen mode
1125 * can't be changed if a surface is locked or some drawing is in progress. */
1126 if (SUCCEEDED(hr
= wined3d_output_set_display_mode(ddraw
->wined3d_output
, &mode
)))
1130 DDSURFACEDESC2
*surface_desc
= &ddraw
->primary
->surface_desc
;
1132 if (FAILED(hr
= wined3d_swapchain_resize_buffers(ddraw
->wined3d_swapchain
, 0,
1133 surface_desc
->dwWidth
, surface_desc
->dwHeight
, mode
.format_id
, WINED3D_MULTISAMPLE_NONE
, 0)))
1134 ERR("Failed to resize buffers, hr %#x.\n", hr
);
1136 ddrawformat_from_wined3dformat(&ddraw
->primary
->surface_desc
.u4
.ddpfPixelFormat
, mode
.format_id
);
1138 ddraw
->flags
|= DDRAW_RESTORE_MODE
;
1140 if (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
1142 SetRect(&clip_rect
, 0, 0, width
, height
);
1143 ClipCursor(&clip_rect
);
1147 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_OK
);
1149 wined3d_mutex_unlock();
1151 return hr_ddraw_from_wined3d(hr
);
1154 static HRESULT WINAPI
ddraw4_SetDisplayMode(IDirectDraw4
*iface
, DWORD width
, DWORD height
,
1155 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1157 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1159 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1160 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1162 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1165 static HRESULT WINAPI
ddraw2_SetDisplayMode(IDirectDraw2
*iface
,
1166 DWORD width
, DWORD height
, DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1168 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1170 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1171 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1173 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1176 static HRESULT WINAPI
ddraw1_SetDisplayMode(IDirectDraw
*iface
, DWORD width
, DWORD height
, DWORD bpp
)
1178 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1180 TRACE("iface %p, width %u, height %u, bpp %u.\n", iface
, width
, height
, bpp
);
1182 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, 0, 0);
1185 void ddraw_d3dcaps1_from_7(D3DDEVICEDESC
*caps1
, D3DDEVICEDESC7
*caps7
)
1187 memset(caps1
, 0, sizeof(*caps1
));
1188 caps1
->dwSize
= sizeof(*caps1
);
1189 caps1
->dwFlags
= D3DDD_COLORMODEL
1191 | D3DDD_TRANSFORMCAPS
1193 | D3DDD_LIGHTINGCAPS
1196 | D3DDD_DEVICERENDERBITDEPTH
1197 | D3DDD_DEVICEZBUFFERBITDEPTH
1198 | D3DDD_MAXBUFFERSIZE
1199 | D3DDD_MAXVERTEXCOUNT
;
1200 caps1
->dcmColorModel
= D3DCOLOR_RGB
;
1201 caps1
->dwDevCaps
= caps7
->dwDevCaps
;
1202 caps1
->dtcTransformCaps
.dwSize
= sizeof(caps1
->dtcTransformCaps
);
1203 caps1
->dtcTransformCaps
.dwCaps
= D3DTRANSFORMCAPS_CLIP
;
1204 caps1
->bClipping
= TRUE
;
1205 caps1
->dlcLightingCaps
.dwSize
= sizeof(caps1
->dlcLightingCaps
);
1206 caps1
->dlcLightingCaps
.dwCaps
= D3DLIGHTCAPS_DIRECTIONAL
1207 | D3DLIGHTCAPS_PARALLELPOINT
1208 | D3DLIGHTCAPS_POINT
1209 | D3DLIGHTCAPS_SPOT
;
1210 caps1
->dlcLightingCaps
.dwLightingModel
= D3DLIGHTINGMODEL_RGB
;
1211 caps1
->dlcLightingCaps
.dwNumLights
= caps7
->dwMaxActiveLights
;
1212 caps1
->dpcLineCaps
= caps7
->dpcLineCaps
;
1213 caps1
->dpcTriCaps
= caps7
->dpcTriCaps
;
1214 caps1
->dwDeviceRenderBitDepth
= caps7
->dwDeviceRenderBitDepth
;
1215 caps1
->dwDeviceZBufferBitDepth
= caps7
->dwDeviceZBufferBitDepth
;
1216 caps1
->dwMaxBufferSize
= 0;
1217 caps1
->dwMaxVertexCount
= 65536;
1218 caps1
->dwMinTextureWidth
= caps7
->dwMinTextureWidth
;
1219 caps1
->dwMinTextureHeight
= caps7
->dwMinTextureHeight
;
1220 caps1
->dwMaxTextureWidth
= caps7
->dwMaxTextureWidth
;
1221 caps1
->dwMaxTextureHeight
= caps7
->dwMaxTextureHeight
;
1222 caps1
->dwMinStippleWidth
= 1;
1223 caps1
->dwMinStippleHeight
= 1;
1224 caps1
->dwMaxStippleWidth
= 32;
1225 caps1
->dwMaxStippleHeight
= 32;
1226 caps1
->dwMaxTextureRepeat
= caps7
->dwMaxTextureRepeat
;
1227 caps1
->dwMaxTextureAspectRatio
= caps7
->dwMaxTextureAspectRatio
;
1228 caps1
->dwMaxAnisotropy
= caps7
->dwMaxAnisotropy
;
1229 caps1
->dvGuardBandLeft
= caps7
->dvGuardBandLeft
;
1230 caps1
->dvGuardBandTop
= caps7
->dvGuardBandTop
;
1231 caps1
->dvGuardBandRight
= caps7
->dvGuardBandRight
;
1232 caps1
->dvGuardBandBottom
= caps7
->dvGuardBandBottom
;
1233 caps1
->dvExtentsAdjust
= caps7
->dvExtentsAdjust
;
1234 caps1
->dwStencilCaps
= caps7
->dwStencilCaps
;
1235 caps1
->dwFVFCaps
= caps7
->dwFVFCaps
;
1236 caps1
->dwTextureOpCaps
= caps7
->dwTextureOpCaps
;
1237 caps1
->wMaxTextureBlendStages
= caps7
->wMaxTextureBlendStages
;
1238 caps1
->wMaxSimultaneousTextures
= caps7
->wMaxSimultaneousTextures
;
1241 HRESULT
ddraw_get_d3dcaps(const struct ddraw
*ddraw
, D3DDEVICEDESC7
*caps
)
1243 struct wined3d_caps wined3d_caps
;
1246 TRACE("ddraw %p, caps %p.\n", ddraw
, caps
);
1248 memset(&wined3d_caps
, 0, sizeof(wined3d_caps
));
1250 wined3d_mutex_lock();
1251 hr
= wined3d_get_device_caps(ddraw
->wined3d_adapter
, WINED3D_DEVICE_TYPE_HAL
, &wined3d_caps
);
1252 wined3d_mutex_unlock();
1255 WARN("Failed to get device caps, hr %#x.\n", hr
);
1259 caps
->dwDevCaps
= wined3d_caps
.DevCaps
;
1260 caps
->dpcLineCaps
.dwMiscCaps
= wined3d_caps
.PrimitiveMiscCaps
;
1261 caps
->dpcLineCaps
.dwRasterCaps
= wined3d_caps
.RasterCaps
;
1262 caps
->dpcLineCaps
.dwZCmpCaps
= wined3d_caps
.ZCmpCaps
;
1263 caps
->dpcLineCaps
.dwSrcBlendCaps
= wined3d_caps
.SrcBlendCaps
;
1264 caps
->dpcLineCaps
.dwDestBlendCaps
= wined3d_caps
.DestBlendCaps
;
1265 caps
->dpcLineCaps
.dwAlphaCmpCaps
= wined3d_caps
.AlphaCmpCaps
;
1266 caps
->dpcLineCaps
.dwShadeCaps
= wined3d_caps
.ShadeCaps
;
1267 caps
->dpcLineCaps
.dwTextureCaps
= wined3d_caps
.TextureCaps
;
1268 caps
->dpcLineCaps
.dwTextureFilterCaps
= wined3d_caps
.TextureFilterCaps
;
1269 caps
->dpcLineCaps
.dwTextureAddressCaps
= wined3d_caps
.TextureAddressCaps
;
1271 caps
->dwMaxTextureWidth
= wined3d_caps
.MaxTextureWidth
;
1272 caps
->dwMaxTextureHeight
= wined3d_caps
.MaxTextureHeight
;
1274 caps
->dwMaxTextureRepeat
= wined3d_caps
.MaxTextureRepeat
;
1275 caps
->dwMaxTextureAspectRatio
= wined3d_caps
.MaxTextureAspectRatio
;
1276 caps
->dwMaxAnisotropy
= wined3d_caps
.MaxAnisotropy
;
1277 caps
->dvMaxVertexW
= wined3d_caps
.MaxVertexW
;
1279 caps
->dvGuardBandLeft
= wined3d_caps
.GuardBandLeft
;
1280 caps
->dvGuardBandTop
= wined3d_caps
.GuardBandTop
;
1281 caps
->dvGuardBandRight
= wined3d_caps
.GuardBandRight
;
1282 caps
->dvGuardBandBottom
= wined3d_caps
.GuardBandBottom
;
1284 caps
->dvExtentsAdjust
= wined3d_caps
.ExtentsAdjust
;
1285 caps
->dwStencilCaps
= wined3d_caps
.StencilCaps
;
1287 caps
->dwFVFCaps
= wined3d_caps
.FVFCaps
;
1288 caps
->dwTextureOpCaps
= wined3d_caps
.TextureOpCaps
;
1290 caps
->dwVertexProcessingCaps
= wined3d_caps
.VertexProcessingCaps
;
1291 caps
->dwMaxActiveLights
= wined3d_caps
.MaxActiveLights
;
1293 /* Remove all non-d3d7 caps */
1294 caps
->dwDevCaps
&= (
1295 D3DDEVCAPS_FLOATTLVERTEX
| D3DDEVCAPS_SORTINCREASINGZ
| D3DDEVCAPS_SORTDECREASINGZ
|
1296 D3DDEVCAPS_SORTEXACT
| D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
|
1297 D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
| D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
|
1298 D3DDEVCAPS_TEXTUREVIDEOMEMORY
| D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
|
1299 D3DDEVCAPS_TEXTURENONLOCALVIDMEM
| D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
1300 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
1301 D3DDEVCAPS_HWRASTERIZATION
);
1303 caps
->dwStencilCaps
&= (
1304 D3DSTENCILCAPS_KEEP
| D3DSTENCILCAPS_ZERO
| D3DSTENCILCAPS_REPLACE
|
1305 D3DSTENCILCAPS_INCRSAT
| D3DSTENCILCAPS_DECRSAT
| D3DSTENCILCAPS_INVERT
|
1306 D3DSTENCILCAPS_INCR
| D3DSTENCILCAPS_DECR
);
1310 caps
->dwTextureOpCaps
&= (
1311 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_SELECTARG2
|
1312 D3DTEXOPCAPS_MODULATE
| D3DTEXOPCAPS_MODULATE2X
| D3DTEXOPCAPS_MODULATE4X
|
1313 D3DTEXOPCAPS_ADD
| D3DTEXOPCAPS_ADDSIGNED
| D3DTEXOPCAPS_ADDSIGNED2X
|
1314 D3DTEXOPCAPS_SUBTRACT
| D3DTEXOPCAPS_ADDSMOOTH
| D3DTEXOPCAPS_BLENDTEXTUREALPHA
|
1315 D3DTEXOPCAPS_BLENDFACTORALPHA
| D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
| D3DTEXOPCAPS_BLENDCURRENTALPHA
|
1316 D3DTEXOPCAPS_PREMODULATE
| D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
|
1317 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
| D3DTEXOPCAPS_BUMPENVMAP
|
1318 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
| D3DTEXOPCAPS_DOTPRODUCT3
);
1320 caps
->dwVertexProcessingCaps
&= (
1321 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_VERTEXFOG
|
1322 D3DVTXPCAPS_DIRECTIONALLIGHTS
| D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
);
1324 caps
->dpcLineCaps
.dwMiscCaps
&= (
1325 D3DPMISCCAPS_MASKPLANES
| D3DPMISCCAPS_MASKZ
| D3DPMISCCAPS_LINEPATTERNREP
|
1326 D3DPMISCCAPS_CONFORMANT
| D3DPMISCCAPS_CULLNONE
| D3DPMISCCAPS_CULLCW
|
1327 D3DPMISCCAPS_CULLCCW
);
1329 caps
->dpcLineCaps
.dwRasterCaps
&= (
1330 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ROP2
| D3DPRASTERCAPS_XOR
|
1331 D3DPRASTERCAPS_PAT
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_SUBPIXEL
|
1332 D3DPRASTERCAPS_SUBPIXELX
| D3DPRASTERCAPS_FOGVERTEX
| D3DPRASTERCAPS_FOGTABLE
|
1333 D3DPRASTERCAPS_STIPPLE
| D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT
| D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT
|
1334 D3DPRASTERCAPS_ANTIALIASEDGES
| D3DPRASTERCAPS_MIPMAPLODBIAS
|
1335 D3DPRASTERCAPS_ZBUFFERLESSHSR
| D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
|
1336 D3DPRASTERCAPS_WBUFFER
| D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT
| D3DPRASTERCAPS_WFOG
|
1337 D3DPRASTERCAPS_ZFOG
| WINED3DPRASTERCAPS_DEPTHBIAS
);
1338 if (caps
->dpcLineCaps
.dwRasterCaps
& WINED3DPRASTERCAPS_DEPTHBIAS
)
1339 caps
->dpcLineCaps
.dwRasterCaps
= (caps
->dpcLineCaps
.dwRasterCaps
| D3DPRASTERCAPS_ZBIAS
)
1340 & ~WINED3DPRASTERCAPS_DEPTHBIAS
;
1341 if (wined3d_caps
.LineCaps
& WINED3DLINECAPS_ANTIALIAS
)
1342 caps
->dpcLineCaps
.dwRasterCaps
|= D3DPRASTERCAPS_ANTIALIASEDGES
;
1344 caps
->dpcLineCaps
.dwZCmpCaps
&= (
1345 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
1346 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
1347 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
1349 caps
->dpcLineCaps
.dwSrcBlendCaps
&= (
1350 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
1351 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
1352 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
1353 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
1354 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
1356 caps
->dpcLineCaps
.dwDestBlendCaps
&= (
1357 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
1358 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
1359 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
1360 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
1361 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
1363 caps
->dpcLineCaps
.dwAlphaCmpCaps
&= (
1364 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
1365 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
1366 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
1368 caps
->dpcLineCaps
.dwShadeCaps
&= (
1369 D3DPSHADECAPS_COLORFLATMONO
| D3DPSHADECAPS_COLORFLATRGB
| D3DPSHADECAPS_COLORGOURAUDMONO
|
1370 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_COLORPHONGMONO
| D3DPSHADECAPS_COLORPHONGRGB
|
1371 D3DPSHADECAPS_SPECULARFLATMONO
| D3DPSHADECAPS_SPECULARFLATRGB
| D3DPSHADECAPS_SPECULARGOURAUDMONO
|
1372 D3DPSHADECAPS_SPECULARGOURAUDRGB
| D3DPSHADECAPS_SPECULARPHONGMONO
| D3DPSHADECAPS_SPECULARPHONGRGB
|
1373 D3DPSHADECAPS_ALPHAFLATBLEND
| D3DPSHADECAPS_ALPHAFLATSTIPPLED
| D3DPSHADECAPS_ALPHAGOURAUDBLEND
|
1374 D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED
| D3DPSHADECAPS_ALPHAPHONGBLEND
| D3DPSHADECAPS_ALPHAPHONGSTIPPLED
|
1375 D3DPSHADECAPS_FOGFLAT
| D3DPSHADECAPS_FOGGOURAUD
| D3DPSHADECAPS_FOGPHONG
);
1377 caps
->dpcLineCaps
.dwTextureCaps
&= (
1378 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
1379 D3DPTEXTURECAPS_TRANSPARENCY
| D3DPTEXTURECAPS_BORDER
| D3DPTEXTURECAPS_SQUAREONLY
|
1380 D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
| D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
1381 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_COLORKEYBLEND
);
1383 caps
->dpcLineCaps
.dwTextureFilterCaps
&= (
1384 D3DPTFILTERCAPS_NEAREST
| D3DPTFILTERCAPS_LINEAR
| D3DPTFILTERCAPS_MIPNEAREST
|
1385 D3DPTFILTERCAPS_MIPLINEAR
| D3DPTFILTERCAPS_LINEARMIPNEAREST
| D3DPTFILTERCAPS_LINEARMIPLINEAR
|
1386 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
1387 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
1388 D3DPTFILTERCAPS_MAGFLINEAR
| D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
|
1389 D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
);
1391 caps
->dpcLineCaps
.dwTextureAddressCaps
&= (
1392 D3DPTADDRESSCAPS_WRAP
| D3DPTADDRESSCAPS_MIRROR
| D3DPTADDRESSCAPS_CLAMP
|
1393 D3DPTADDRESSCAPS_BORDER
| D3DPTADDRESSCAPS_INDEPENDENTUV
);
1395 if (!(caps
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
))
1397 /* DirectX7 always has the np2 flag set, no matter what the card
1398 * supports. Some old games (Rollcage) check the caps incorrectly.
1399 * If wined3d supports nonpow2 textures it also has np2 conditional
1401 caps
->dpcLineCaps
.dwTextureCaps
|= D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
;
1404 /* Fill the missing members, and do some fixup */
1405 caps
->dpcLineCaps
.dwSize
= sizeof(caps
->dpcLineCaps
);
1406 caps
->dpcLineCaps
.dwTextureBlendCaps
= D3DPTBLENDCAPS_ADD
1407 | D3DPTBLENDCAPS_MODULATEMASK
1408 | D3DPTBLENDCAPS_COPY
1409 | D3DPTBLENDCAPS_DECAL
1410 | D3DPTBLENDCAPS_DECALALPHA
1411 | D3DPTBLENDCAPS_DECALMASK
1412 | D3DPTBLENDCAPS_MODULATE
1413 | D3DPTBLENDCAPS_MODULATEALPHA
;
1414 caps
->dpcLineCaps
.dwStippleWidth
= 32;
1415 caps
->dpcLineCaps
.dwStippleHeight
= 32;
1416 /* Use the same for the TriCaps */
1417 caps
->dpcTriCaps
= caps
->dpcLineCaps
;
1419 caps
->dwDeviceRenderBitDepth
= DDBD_16
| DDBD_24
| DDBD_32
;
1420 caps
->dwDeviceZBufferBitDepth
= DDBD_16
| DDBD_24
;
1421 caps
->dwMinTextureWidth
= 1;
1422 caps
->dwMinTextureHeight
= 1;
1424 /* Convert DWORDs safely to WORDs */
1425 caps
->wMaxTextureBlendStages
= min(wined3d_caps
.MaxTextureBlendStages
, 0xffff);
1426 caps
->wMaxSimultaneousTextures
= min(wined3d_caps
.MaxSimultaneousTextures
, 0xffff);
1427 caps
->wMaxUserClipPlanes
= min(wined3d_caps
.MaxUserClipPlanes
, D3DMAXUSERCLIPPLANES
);
1428 caps
->wMaxVertexBlendMatrices
= min(wined3d_caps
.MaxVertexBlendMatrices
, 0xffff);
1430 caps
->deviceGUID
= IID_IDirect3DTnLHalDevice
;
1432 caps
->dwReserved1
= 0;
1433 caps
->dwReserved2
= 0;
1434 caps
->dwReserved3
= 0;
1435 caps
->dwReserved4
= 0;
1440 /*****************************************************************************
1441 * IDirectDraw7::GetCaps
1443 * Returns the drives capabilities
1445 * Used for version 1, 2, 4 and 7
1448 * DriverCaps: Structure to write the Hardware accelerated caps to
1449 * HelCaps: Structure to write the emulation caps to
1452 * This implementation returns DD_OK only
1454 *****************************************************************************/
1455 static HRESULT WINAPI
ddraw7_GetCaps(IDirectDraw7
*iface
, DDCAPS
*DriverCaps
, DDCAPS
*HELCaps
)
1457 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1458 DDSCAPS2 ddscaps
= {0, 0, 0, {0}};
1459 struct wined3d_caps winecaps
;
1463 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, DriverCaps
, HELCaps
);
1465 /* One structure must be != NULL */
1466 if (!DriverCaps
&& !HELCaps
)
1468 WARN("Invalid parameters.\n");
1469 return DDERR_INVALIDPARAMS
;
1472 memset(&caps
, 0, sizeof(caps
));
1473 memset(&winecaps
, 0, sizeof(winecaps
));
1474 caps
.dwSize
= sizeof(caps
);
1476 wined3d_mutex_lock();
1477 hr
= wined3d_device_get_device_caps(ddraw
->wined3d_device
, &winecaps
);
1480 WARN("Failed to get device caps, %#x.\n", hr
);
1481 wined3d_mutex_unlock();
1485 hr
= IDirectDraw7_GetAvailableVidMem(iface
, &ddscaps
, &caps
.dwVidMemTotal
, &caps
.dwVidMemFree
);
1488 WARN("IDirectDraw7::GetAvailableVidMem failed\n");
1489 wined3d_mutex_unlock();
1493 hr
= IDirectDraw7_GetFourCCCodes(iface
, &caps
.dwNumFourCCCodes
, NULL
);
1494 wined3d_mutex_unlock();
1497 WARN("IDirectDraw7::GetFourCCCodes failed\n");
1501 caps
.dwCaps
= winecaps
.ddraw_caps
.caps
;
1502 caps
.dwCaps2
= winecaps
.ddraw_caps
.caps2
;
1503 caps
.dwCKeyCaps
= winecaps
.ddraw_caps
.color_key_caps
;
1504 caps
.dwFXCaps
= winecaps
.ddraw_caps
.fx_caps
;
1505 caps
.dwPalCaps
= DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
;
1506 caps
.ddsCaps
.dwCaps
= winecaps
.ddraw_caps
.dds_caps
;
1507 caps
.dwSVBCaps
= winecaps
.ddraw_caps
.svb_caps
;
1508 caps
.dwSVBCKeyCaps
= winecaps
.ddraw_caps
.svb_color_key_caps
;
1509 caps
.dwSVBFXCaps
= winecaps
.ddraw_caps
.svb_fx_caps
;
1510 caps
.dwVSBCaps
= winecaps
.ddraw_caps
.vsb_caps
;
1511 caps
.dwVSBCKeyCaps
= winecaps
.ddraw_caps
.vsb_color_key_caps
;
1512 caps
.dwVSBFXCaps
= winecaps
.ddraw_caps
.vsb_fx_caps
;
1513 caps
.dwSSBCaps
= winecaps
.ddraw_caps
.ssb_caps
;
1514 caps
.dwSSBCKeyCaps
= winecaps
.ddraw_caps
.ssb_color_key_caps
;
1515 caps
.dwSSBFXCaps
= winecaps
.ddraw_caps
.ssb_fx_caps
;
1517 caps
.dwCaps
|= DDCAPS_ALIGNSTRIDE
;
1518 caps
.dwAlignStrideAlign
= DDRAW_STRIDE_ALIGNMENT
;
1520 caps
.ddsOldCaps
.dwCaps
= caps
.ddsCaps
.dwCaps
;
1524 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &caps
);
1525 if (TRACE_ON(ddraw
))
1527 TRACE("Driver Caps :\n");
1528 DDRAW_dump_DDCAPS(DriverCaps
);
1534 DD_STRUCT_COPY_BYSIZE(HELCaps
, &caps
);
1535 if (TRACE_ON(ddraw
))
1537 TRACE("HEL Caps :\n");
1538 DDRAW_dump_DDCAPS(HELCaps
);
1545 static HRESULT WINAPI
ddraw4_GetCaps(IDirectDraw4
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1547 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1549 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1551 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1554 static HRESULT WINAPI
ddraw2_GetCaps(IDirectDraw2
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1556 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1558 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1560 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1563 static HRESULT WINAPI
ddraw1_GetCaps(IDirectDraw
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1565 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1567 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1569 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1572 /*****************************************************************************
1573 * IDirectDraw7::Compact
1575 * No idea what it does, MSDN says it's not implemented.
1578 * DD_OK, but this is unchecked
1580 *****************************************************************************/
1581 static HRESULT WINAPI
ddraw7_Compact(IDirectDraw7
*iface
)
1583 TRACE("iface %p.\n", iface
);
1588 static HRESULT WINAPI
ddraw4_Compact(IDirectDraw4
*iface
)
1590 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1592 TRACE("iface %p.\n", iface
);
1594 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1597 static HRESULT WINAPI
ddraw2_Compact(IDirectDraw2
*iface
)
1599 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1601 TRACE("iface %p.\n", iface
);
1603 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1606 static HRESULT WINAPI
ddraw1_Compact(IDirectDraw
*iface
)
1608 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1610 TRACE("iface %p.\n", iface
);
1612 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1615 /*****************************************************************************
1616 * IDirectDraw7::GetDisplayMode
1618 * Returns information about the current display mode
1620 * Exists in versions 1, 2, 4 and 7
1623 * DDSD: Address of a surface description structure to write the info to
1628 *****************************************************************************/
1629 static HRESULT WINAPI
ddraw7_GetDisplayMode(IDirectDraw7
*iface
, DDSURFACEDESC2
*DDSD
)
1631 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1632 struct wined3d_display_mode mode
;
1635 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
1637 /* This seems sane */
1638 if (!DDSD
|| (DDSD
->dwSize
!= sizeof(DDSURFACEDESC
) && DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
)))
1639 return DDERR_INVALIDPARAMS
;
1641 wined3d_mutex_lock();
1643 if (FAILED(hr
= wined3d_output_get_display_mode(ddraw
->wined3d_output
, &mode
, NULL
)))
1645 ERR("Failed to get display mode, hr %#x.\n", hr
);
1646 wined3d_mutex_unlock();
1650 memset(DDSD
, 0, DDSD
->dwSize
);
1651 DDSD
->dwSize
= sizeof(*DDSD
);
1652 DDSD
->dwFlags
= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
1653 DDSD
->dwWidth
= mode
.width
;
1654 DDSD
->dwHeight
= mode
.height
;
1655 DDSD
->u2
.dwRefreshRate
= mode
.refresh_rate
;
1656 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
1657 ddrawformat_from_wined3dformat(&DDSD
->u4
.ddpfPixelFormat
, mode
.format_id
);
1658 DDSD
->u1
.lPitch
= mode
.width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
1662 TRACE("Returning surface desc :\n");
1663 DDRAW_dump_surface_desc(DDSD
);
1666 wined3d_mutex_unlock();
1671 static HRESULT WINAPI
ddraw4_GetDisplayMode(IDirectDraw4
*iface
, DDSURFACEDESC2
*surface_desc
)
1673 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1675 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1677 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, surface_desc
);
1680 static HRESULT WINAPI
ddraw2_GetDisplayMode(IDirectDraw2
*iface
, DDSURFACEDESC
*surface_desc
)
1682 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1685 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1687 hr
= ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1688 if (SUCCEEDED(hr
)) surface_desc
->dwSize
= sizeof(*surface_desc
);
1692 static HRESULT WINAPI
ddraw1_GetDisplayMode(IDirectDraw
*iface
, DDSURFACEDESC
*surface_desc
)
1694 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1697 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1699 hr
= ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1700 if (SUCCEEDED(hr
)) surface_desc
->dwSize
= sizeof(*surface_desc
);
1704 /*****************************************************************************
1705 * IDirectDraw7::GetFourCCCodes
1707 * Returns an array of supported FourCC codes.
1709 * Exists in versions 1, 2, 4 and 7
1712 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
1713 * of enumerated codes
1714 * Codes: Pointer to an array of DWORDs where the supported codes are written
1718 * Always returns DD_OK, as it's a stub for now
1720 *****************************************************************************/
1721 static HRESULT WINAPI
ddraw7_GetFourCCCodes(IDirectDraw7
*iface
, DWORD
*NumCodes
, DWORD
*Codes
)
1723 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1724 static const enum wined3d_format_id formats
[] =
1726 WINED3DFMT_YUY2
, WINED3DFMT_UYVY
, WINED3DFMT_YV12
,
1727 WINED3DFMT_DXT1
, WINED3DFMT_DXT2
, WINED3DFMT_DXT3
, WINED3DFMT_DXT4
, WINED3DFMT_DXT5
,
1728 WINED3DFMT_ATI2N
, WINED3DFMT_NVHU
, WINED3DFMT_NVHS
1730 struct wined3d_display_mode mode
;
1731 DWORD count
= 0, i
, outsize
;
1734 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, NumCodes
, Codes
);
1736 if (FAILED(hr
= wined3d_output_get_display_mode(ddraw
->wined3d_output
, &mode
, NULL
)))
1738 ERR("Failed to get display mode, hr %#x.\n", hr
);
1742 outsize
= NumCodes
&& Codes
? *NumCodes
: 0;
1744 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
)
1746 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, ddraw
->wined3d_adapter
, WINED3D_DEVICE_TYPE_HAL
,
1747 mode
.format_id
, 0, 0, WINED3D_RTYPE_TEXTURE_2D
, formats
[i
])))
1749 if (count
< outsize
)
1750 Codes
[count
] = formats
[i
];
1755 TRACE("Returning %u FourCC codes\n", count
);
1762 static HRESULT WINAPI
ddraw4_GetFourCCCodes(IDirectDraw4
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1764 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1766 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1768 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1771 static HRESULT WINAPI
ddraw2_GetFourCCCodes(IDirectDraw2
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1773 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1775 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1777 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1780 static HRESULT WINAPI
ddraw1_GetFourCCCodes(IDirectDraw
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1782 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1784 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1786 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1789 static HRESULT WINAPI
ddraw7_GetMonitorFrequency(IDirectDraw7
*iface
, DWORD
*frequency
)
1791 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1792 struct wined3d_display_mode mode
;
1795 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1797 wined3d_mutex_lock();
1798 hr
= wined3d_output_get_display_mode(ddraw
->wined3d_output
, &mode
, NULL
);
1799 wined3d_mutex_unlock();
1802 WARN("Failed to get display mode, hr %#x.\n", hr
);
1806 *frequency
= mode
.refresh_rate
;
1811 static HRESULT WINAPI
ddraw4_GetMonitorFrequency(IDirectDraw4
*iface
, DWORD
*frequency
)
1813 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1815 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1817 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1820 static HRESULT WINAPI
ddraw2_GetMonitorFrequency(IDirectDraw2
*iface
, DWORD
*frequency
)
1822 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1824 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1826 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1829 static HRESULT WINAPI
ddraw1_GetMonitorFrequency(IDirectDraw
*iface
, DWORD
*frequency
)
1831 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1833 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1835 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1838 static HRESULT WINAPI
ddraw7_GetVerticalBlankStatus(IDirectDraw7
*iface
, BOOL
*status
)
1840 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1841 struct wined3d_raster_status raster_status
;
1844 TRACE("iface %p, status %p.\n", iface
, status
);
1847 return DDERR_INVALIDPARAMS
;
1849 wined3d_mutex_lock();
1850 hr
= wined3d_output_get_raster_status(ddraw
->wined3d_output
, &raster_status
);
1851 wined3d_mutex_unlock();
1854 WARN("Failed to get raster status, hr %#x.\n", hr
);
1858 *status
= raster_status
.in_vblank
;
1863 static HRESULT WINAPI
ddraw4_GetVerticalBlankStatus(IDirectDraw4
*iface
, BOOL
*status
)
1865 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1867 TRACE("iface %p, status %p.\n", iface
, status
);
1869 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1872 static HRESULT WINAPI
ddraw2_GetVerticalBlankStatus(IDirectDraw2
*iface
, BOOL
*status
)
1874 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1876 TRACE("iface %p, status %p.\n", iface
, status
);
1878 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1881 static HRESULT WINAPI
ddraw1_GetVerticalBlankStatus(IDirectDraw
*iface
, BOOL
*status
)
1883 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1885 TRACE("iface %p, status %p.\n", iface
, status
);
1887 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1890 /*****************************************************************************
1891 * IDirectDraw7::GetAvailableVidMem
1893 * Returns the total and free video memory
1896 * caps: Specifies the memory type asked for
1897 * total: Pointer to a DWORD to be filled with the total memory
1898 * free: Pointer to a DWORD to be filled with the free memory
1902 * DDERR_INVALIDPARAMS if free and total are NULL
1904 *****************************************************************************/
1905 static HRESULT WINAPI
ddraw7_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*caps
, DWORD
*total
,
1908 unsigned int framebuffer_size
, total_vidmem
, free_vidmem
;
1909 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1910 struct wined3d_display_mode mode
;
1913 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1915 if (!total
&& !free
)
1916 return DDERR_INVALIDPARAMS
;
1918 if (TRACE_ON(ddraw
))
1920 TRACE("Asked for memory with description: ");
1921 DDRAW_dump_DDSCAPS2(caps
);
1923 wined3d_mutex_lock();
1925 /* Todo: System memory vs local video memory vs non-local video memory
1926 * The MSDN also mentions differences between texture memory and other
1927 * resources, but that's not important
1930 /* Some applications (e.g. 3DMark 2000) assume that the reported amount of
1931 * video memory doesn't include the memory used by the default framebuffer.
1933 if (FAILED(hr
= wined3d_output_get_display_mode(ddraw
->wined3d_output
, &mode
, NULL
)))
1935 WARN("Failed to get display mode, hr %#x.\n", hr
);
1936 wined3d_mutex_unlock();
1939 framebuffer_size
= wined3d_calculate_format_pitch(ddraw
->wined3d_adapter
,
1940 mode
.format_id
, mode
.width
);
1941 framebuffer_size
*= mode
.height
;
1945 free_vidmem
= wined3d_device_get_available_texture_mem(ddraw
->wined3d_device
);
1946 *free
= framebuffer_size
> free_vidmem
? 0 : free_vidmem
- framebuffer_size
;
1947 TRACE("Free video memory %#x.\n", *free
);
1952 struct wined3d_adapter_identifier desc
= {0};
1954 hr
= wined3d_adapter_get_identifier(ddraw
->wined3d_adapter
, 0, &desc
);
1955 total_vidmem
= min(UINT_MAX
, desc
.video_memory
);
1956 *total
= framebuffer_size
> total_vidmem
? 0 : total_vidmem
- framebuffer_size
;
1957 TRACE("Total video memory %#x.\n", *total
);
1960 wined3d_mutex_unlock();
1965 static HRESULT WINAPI
ddraw4_GetAvailableVidMem(IDirectDraw4
*iface
,
1966 DDSCAPS2
*caps
, DWORD
*total
, DWORD
*free
)
1968 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1970 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1972 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, caps
, total
, free
);
1975 static HRESULT WINAPI
ddraw2_GetAvailableVidMem(IDirectDraw2
*iface
,
1976 DDSCAPS
*caps
, DWORD
*total
, DWORD
*free
)
1978 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1981 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1983 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
1984 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, &caps2
, total
, free
);
1987 /*****************************************************************************
1988 * IDirectDraw7::Initialize
1990 * Initializes a DirectDraw interface.
1993 * GUID: Interface identifier. Well, don't know what this is really good
1997 * Returns DD_OK on the first call,
1998 * DDERR_ALREADYINITIALIZED on repeated calls
2000 *****************************************************************************/
2001 static HRESULT WINAPI
ddraw7_Initialize(IDirectDraw7
*iface
, GUID
*guid
)
2003 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2005 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2007 if (ddraw
->flags
& DDRAW_INITIALIZED
)
2008 return DDERR_ALREADYINITIALIZED
;
2010 /* FIXME: To properly take the GUID into account we should call
2011 * ddraw_init() here instead of in DDRAW_Create(). */
2013 FIXME("Ignoring guid %s.\n", debugstr_guid(guid
));
2015 ddraw
->flags
|= DDRAW_INITIALIZED
;
2019 static HRESULT WINAPI
ddraw4_Initialize(IDirectDraw4
*iface
, GUID
*guid
)
2021 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2023 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2025 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2028 static HRESULT WINAPI
ddraw2_Initialize(IDirectDraw2
*iface
, GUID
*guid
)
2030 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2032 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2034 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2037 static HRESULT WINAPI
ddraw1_Initialize(IDirectDraw
*iface
, GUID
*guid
)
2039 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2041 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2043 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2046 static HRESULT WINAPI
d3d1_Initialize(IDirect3D
*iface
, REFIID riid
)
2048 TRACE("iface %p, riid %s.\n", iface
, debugstr_guid(riid
));
2050 return DDERR_ALREADYINITIALIZED
;
2053 /*****************************************************************************
2054 * IDirectDraw7::FlipToGDISurface
2056 * "Makes the surface that the GDI writes to the primary surface"
2057 * Looks like some windows specific thing we don't have to care about.
2058 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
2059 * show error boxes ;)
2060 * Well, just return DD_OK.
2063 * Always returns DD_OK
2065 *****************************************************************************/
2066 static HRESULT WINAPI
ddraw7_FlipToGDISurface(IDirectDraw7
*iface
)
2068 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2069 IDirectDrawSurface7
*gdi_surface
;
2070 struct ddraw_surface
*gdi_impl
;
2073 TRACE("iface %p.\n", iface
);
2075 wined3d_mutex_lock();
2077 if (FAILED(hr
= IDirectDraw7_GetGDISurface(iface
, &gdi_surface
)))
2079 WARN("Failed to retrieve GDI surface, hr %#x.\n", hr
);
2080 wined3d_mutex_unlock();
2084 gdi_impl
= impl_from_IDirectDrawSurface7(gdi_surface
);
2085 if (gdi_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
2088 hr
= IDirectDrawSurface7_Flip(&ddraw
->primary
->IDirectDrawSurface7_iface
, gdi_surface
, DDFLIP_WAIT
);
2089 IDirectDrawSurface7_Release(gdi_surface
);
2091 wined3d_mutex_unlock();
2096 static HRESULT WINAPI
ddraw4_FlipToGDISurface(IDirectDraw4
*iface
)
2098 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2100 TRACE("iface %p.\n", iface
);
2102 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2105 static HRESULT WINAPI
ddraw2_FlipToGDISurface(IDirectDraw2
*iface
)
2107 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2109 TRACE("iface %p.\n", iface
);
2111 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2114 static HRESULT WINAPI
ddraw1_FlipToGDISurface(IDirectDraw
*iface
)
2116 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2118 TRACE("iface %p.\n", iface
);
2120 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2123 /*****************************************************************************
2124 * IDirectDraw7::WaitForVerticalBlank
2126 * This method allows applications to get in sync with the vertical blank
2128 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
2129 * redraw the screen, most likely because of this stub
2132 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
2133 * or DDWAITVB_BLOCKEND
2134 * h: Not used, according to MSDN
2137 * Always returns DD_OK
2139 *****************************************************************************/
2140 static HRESULT WINAPI
ddraw7_WaitForVerticalBlank(IDirectDraw7
*iface
, DWORD Flags
, HANDLE event
)
2144 TRACE("iface %p, flags %#x, event %p.\n", iface
, Flags
, event
);
2146 /* This function is called often, so print the fixme only once */
2149 FIXME("iface %p, flags %#x, event %p stub!\n", iface
, Flags
, event
);
2153 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
2154 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
2155 return DDERR_UNSUPPORTED
; /* unchecked */
2160 static HRESULT WINAPI
ddraw4_WaitForVerticalBlank(IDirectDraw4
*iface
, DWORD flags
, HANDLE event
)
2162 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2164 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2166 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2169 static HRESULT WINAPI
ddraw2_WaitForVerticalBlank(IDirectDraw2
*iface
, DWORD flags
, HANDLE event
)
2171 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2173 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2175 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2178 static HRESULT WINAPI
ddraw1_WaitForVerticalBlank(IDirectDraw
*iface
, DWORD flags
, HANDLE event
)
2180 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2182 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2184 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2187 static HRESULT WINAPI
ddraw7_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
2189 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2190 struct wined3d_raster_status raster_status
;
2193 TRACE("iface %p, line %p.\n", iface
, Scanline
);
2195 wined3d_mutex_lock();
2196 hr
= wined3d_output_get_raster_status(ddraw
->wined3d_output
, &raster_status
);
2197 wined3d_mutex_unlock();
2200 WARN("Failed to get raster status, hr %#x.\n", hr
);
2204 *Scanline
= raster_status
.scan_line
;
2206 if (raster_status
.in_vblank
)
2207 return DDERR_VERTICALBLANKINPROGRESS
;
2212 static HRESULT WINAPI
ddraw4_GetScanLine(IDirectDraw4
*iface
, DWORD
*line
)
2214 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2216 TRACE("iface %p, line %p.\n", iface
, line
);
2218 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2221 static HRESULT WINAPI
ddraw2_GetScanLine(IDirectDraw2
*iface
, DWORD
*line
)
2223 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2225 TRACE("iface %p, line %p.\n", iface
, line
);
2227 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2230 static HRESULT WINAPI
ddraw1_GetScanLine(IDirectDraw
*iface
, DWORD
*line
)
2232 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2234 TRACE("iface %p, line %p.\n", iface
, line
);
2236 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2239 static HRESULT WINAPI
ddraw7_TestCooperativeLevel(IDirectDraw7
*iface
)
2241 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2243 TRACE("iface %p.\n", iface
);
2245 return ddraw
->device_state
== DDRAW_DEVICE_STATE_LOST
? DDERR_NOEXCLUSIVEMODE
: DD_OK
;
2248 static HRESULT WINAPI
ddraw4_TestCooperativeLevel(IDirectDraw4
*iface
)
2250 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2252 TRACE("iface %p.\n", iface
);
2254 return ddraw7_TestCooperativeLevel(&ddraw
->IDirectDraw7_iface
);
2257 /*****************************************************************************
2258 * IDirectDraw7::GetGDISurface
2260 * Returns the surface that GDI is treating as the primary surface.
2261 * For Wine this is the front buffer
2264 * GDISurface: Address to write the surface pointer to
2267 * DD_OK if the surface was found
2268 * DDERR_NOTFOUND if the GDI surface wasn't found
2270 *****************************************************************************/
2271 static HRESULT WINAPI
ddraw7_GetGDISurface(IDirectDraw7
*iface
, IDirectDrawSurface7
**surface
)
2273 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2274 struct ddraw_surface
*ddraw_surface
;
2276 TRACE("iface %p, surface %p.\n", iface
, surface
);
2278 wined3d_mutex_lock();
2280 if (!ddraw
->gdi_surface
|| !(ddraw_surface
= wined3d_texture_get_sub_resource_parent(ddraw
->gdi_surface
, 0)))
2282 WARN("GDI surface not available.\n");
2284 wined3d_mutex_unlock();
2285 return DDERR_NOTFOUND
;
2287 *surface
= &ddraw_surface
->IDirectDrawSurface7_iface
;
2288 IDirectDrawSurface7_AddRef(*surface
);
2290 wined3d_mutex_unlock();
2295 static HRESULT WINAPI
ddraw4_GetGDISurface(IDirectDraw4
*iface
, IDirectDrawSurface4
**surface
)
2297 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2298 struct ddraw_surface
*surface_impl
;
2299 IDirectDrawSurface7
*surface7
;
2302 TRACE("iface %p, surface %p.\n", iface
, surface
);
2304 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2310 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2311 *surface
= &surface_impl
->IDirectDrawSurface4_iface
;
2312 IDirectDrawSurface4_AddRef(*surface
);
2313 IDirectDrawSurface7_Release(surface7
);
2318 static HRESULT WINAPI
ddraw2_GetGDISurface(IDirectDraw2
*iface
, IDirectDrawSurface
**surface
)
2320 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2321 struct ddraw_surface
*surface_impl
;
2322 IDirectDrawSurface7
*surface7
;
2325 TRACE("iface %p, surface %p.\n", iface
, surface
);
2327 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2333 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2334 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2335 IDirectDrawSurface_AddRef(*surface
);
2336 IDirectDrawSurface7_Release(surface7
);
2341 static HRESULT WINAPI
ddraw1_GetGDISurface(IDirectDraw
*iface
, IDirectDrawSurface
**surface
)
2343 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2344 struct ddraw_surface
*surface_impl
;
2345 IDirectDrawSurface7
*surface7
;
2348 TRACE("iface %p, surface %p.\n", iface
, surface
);
2350 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2356 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2357 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2358 IDirectDrawSurface_AddRef(*surface
);
2359 IDirectDrawSurface7_Release(surface7
);
2364 struct displaymodescallback_context
2366 LPDDENUMMODESCALLBACK func
;
2370 static HRESULT CALLBACK
EnumDisplayModesCallbackThunk(DDSURFACEDESC2
*surface_desc
, void *context
)
2372 struct displaymodescallback_context
*cbcontext
= context
;
2375 DDSD2_to_DDSD(surface_desc
, &desc
);
2376 return cbcontext
->func(&desc
, cbcontext
->context
);
2379 /*****************************************************************************
2380 * IDirectDraw7::EnumDisplayModes
2382 * Enumerates the supported Display modes. The modes can be filtered with
2383 * the DDSD parameter.
2386 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES. For old ddraw
2387 * versions (3 and older?) this is reserved and must be 0.
2388 * DDSD: Surface description to filter the modes
2389 * Context: Pointer passed back to the callback function
2390 * cb: Application-provided callback function
2394 * DDERR_INVALIDPARAMS if the callback wasn't set
2396 *****************************************************************************/
2397 static HRESULT WINAPI
ddraw7_EnumDisplayModes(IDirectDraw7
*iface
, DWORD Flags
,
2398 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMMODESCALLBACK2 cb
)
2400 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2401 struct wined3d_display_mode
*enum_modes
= NULL
;
2402 struct wined3d_display_mode mode
;
2403 unsigned int modenum
, fmt
;
2404 DDSURFACEDESC2 callback_sd
;
2405 unsigned enum_mode_count
= 0, enum_mode_array_size
= 16;
2406 DDPIXELFORMAT pixelformat
;
2408 static const enum wined3d_format_id checkFormatList
[] =
2410 WINED3DFMT_B8G8R8X8_UNORM
,
2411 WINED3DFMT_B5G6R5_UNORM
,
2415 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2416 iface
, Flags
, DDSD
, Context
, cb
);
2419 return DDERR_INVALIDPARAMS
;
2421 if (!(enum_modes
= heap_alloc(enum_mode_array_size
* sizeof(*enum_modes
))))
2422 return DDERR_OUTOFMEMORY
;
2424 wined3d_mutex_lock();
2426 pixelformat
.dwSize
= sizeof(pixelformat
);
2427 for(fmt
= 0; fmt
< ARRAY_SIZE(checkFormatList
); fmt
++)
2430 while (wined3d_output_get_mode(ddraw
->wined3d_output
, checkFormatList
[fmt
],
2431 WINED3D_SCANLINE_ORDERING_UNKNOWN
, modenum
++, &mode
) == WINED3D_OK
)
2436 ddrawformat_from_wined3dformat(&pixelformat
, mode
.format_id
);
2439 if (DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.width
!= DDSD
->dwWidth
)
2441 if (DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.height
!= DDSD
->dwHeight
)
2443 if (DDSD
->dwFlags
& DDSD_REFRESHRATE
&& mode
.refresh_rate
!= DDSD
->u2
.dwRefreshRate
)
2445 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
2446 && pixelformat
.u1
.dwRGBBitCount
!= DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
)
2450 /* DX docs state EnumDisplayMode should return only unique modes */
2451 for (i
= 0; i
< enum_mode_count
; i
++)
2453 if (enum_modes
[i
].width
== mode
.width
&& enum_modes
[i
].height
== mode
.height
2454 && enum_modes
[i
].format_id
== mode
.format_id
2455 && (enum_modes
[i
].refresh_rate
== mode
.refresh_rate
|| !(Flags
& DDEDM_REFRESHRATES
)))
2463 memset(&callback_sd
, 0, sizeof(callback_sd
));
2464 callback_sd
.dwSize
= sizeof(callback_sd
);
2465 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2467 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
|DDSD_REFRESHRATE
;
2468 if (Flags
& DDEDM_REFRESHRATES
)
2469 callback_sd
.u2
.dwRefreshRate
= mode
.refresh_rate
;
2471 callback_sd
.dwWidth
= mode
.width
;
2472 callback_sd
.dwHeight
= mode
.height
;
2474 callback_sd
.u4
.ddpfPixelFormat
=pixelformat
;
2476 /* Calc pitch and DWORD align like MSDN says */
2477 callback_sd
.u1
.lPitch
= (callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8) * mode
.width
;
2478 callback_sd
.u1
.lPitch
= (callback_sd
.u1
.lPitch
+ 3) & ~3;
2480 TRACE("Enumerating %dx%dx%d @%d\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
,
2481 callback_sd
.u2
.dwRefreshRate
);
2483 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
2485 TRACE("Application asked to terminate the enumeration\n");
2486 heap_free(enum_modes
);
2487 wined3d_mutex_unlock();
2491 if (enum_mode_count
== enum_mode_array_size
)
2493 struct wined3d_display_mode
*new_enum_modes
;
2495 enum_mode_array_size
*= 2;
2496 if (!(new_enum_modes
= heap_realloc(enum_modes
, enum_mode_array_size
* sizeof(*new_enum_modes
))))
2498 heap_free(enum_modes
);
2499 wined3d_mutex_unlock();
2500 return DDERR_OUTOFMEMORY
;
2503 enum_modes
= new_enum_modes
;
2505 enum_modes
[enum_mode_count
++] = mode
;
2509 TRACE("End of enumeration\n");
2510 heap_free(enum_modes
);
2511 wined3d_mutex_unlock();
2516 static HRESULT WINAPI
ddraw4_EnumDisplayModes(IDirectDraw4
*iface
, DWORD flags
,
2517 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK2 callback
)
2519 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2521 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2522 iface
, flags
, surface_desc
, context
, callback
);
2524 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
, context
, callback
);
2527 static HRESULT WINAPI
ddraw2_EnumDisplayModes(IDirectDraw2
*iface
, DWORD flags
,
2528 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2530 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2531 struct displaymodescallback_context cbcontext
;
2532 DDSURFACEDESC2 surface_desc2
;
2534 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2535 iface
, flags
, surface_desc
, context
, callback
);
2537 cbcontext
.func
= callback
;
2538 cbcontext
.context
= context
;
2540 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2541 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2542 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2545 static HRESULT WINAPI
ddraw1_EnumDisplayModes(IDirectDraw
*iface
, DWORD flags
,
2546 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2548 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2549 struct displaymodescallback_context cbcontext
;
2550 DDSURFACEDESC2 surface_desc2
;
2552 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2553 iface
, flags
, surface_desc
, context
, callback
);
2555 cbcontext
.func
= callback
;
2556 cbcontext
.context
= context
;
2558 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2559 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2560 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2563 /*****************************************************************************
2564 * IDirectDraw7::EvaluateMode
2566 * Used with IDirectDraw7::StartModeTest to test video modes.
2567 * EvaluateMode is used to pass or fail a mode, and continue with the next
2571 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
2572 * Timeout: Returns the amount of seconds left before the mode would have
2573 * been failed automatically
2576 * This implementation always DD_OK, because it's a stub
2578 *****************************************************************************/
2579 static HRESULT WINAPI
ddraw7_EvaluateMode(IDirectDraw7
*iface
, DWORD Flags
, DWORD
*Timeout
)
2581 FIXME("iface %p, flags %#x, timeout %p stub!\n", iface
, Flags
, Timeout
);
2583 /* When implementing this, implement it in WineD3D */
2588 /*****************************************************************************
2589 * IDirectDraw7::GetDeviceIdentifier
2591 * Returns the device identifier, which gives information about the driver
2592 * Our device identifier is defined at the beginning of this file.
2595 * DDDI: Address for the returned structure
2596 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
2599 * On success it returns DD_OK
2600 * DDERR_INVALIDPARAMS if DDDI is NULL
2602 *****************************************************************************/
2603 static HRESULT WINAPI
ddraw7_GetDeviceIdentifier(IDirectDraw7
*iface
,
2604 DDDEVICEIDENTIFIER2
*DDDI
, DWORD Flags
)
2606 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2607 struct wined3d_adapter_identifier adapter_id
;
2610 TRACE("iface %p, device_identifier %p, flags %#x.\n", iface
, DDDI
, Flags
);
2613 return DDERR_INVALIDPARAMS
;
2615 if (Flags
& DDGDI_GETHOSTIDENTIFIER
)
2617 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
2618 * host adapter, if there's a secondary 3D adapter. This doesn't apply
2619 * to any modern hardware, nor is it interesting for Wine, so ignore it.
2620 * Size of DDDEVICEIDENTIFIER2 may be aligned to 8 bytes and thus 4
2621 * bytes too long. So only copy the relevant part of the structure
2624 memcpy(DDDI
, &deviceidentifier
, FIELD_OFFSET(DDDEVICEIDENTIFIER2
, dwWHQLLevel
) + sizeof(DWORD
));
2628 /* Drakan: Order of the Flame expects accurate D3D device information from ddraw */
2629 adapter_id
.driver
= DDDI
->szDriver
;
2630 adapter_id
.driver_size
= sizeof(DDDI
->szDriver
);
2631 adapter_id
.description
= DDDI
->szDescription
;
2632 adapter_id
.description_size
= sizeof(DDDI
->szDescription
);
2633 wined3d_mutex_lock();
2634 hr
= wined3d_adapter_get_identifier(ddraw
->wined3d_adapter
, 0x0, &adapter_id
);
2635 wined3d_mutex_unlock();
2636 if (FAILED(hr
)) return hr
;
2638 DDDI
->liDriverVersion
= adapter_id
.driver_version
;
2639 DDDI
->dwVendorId
= adapter_id
.vendor_id
;
2640 DDDI
->dwDeviceId
= adapter_id
.device_id
;
2641 DDDI
->dwSubSysId
= adapter_id
.subsystem_id
;
2642 DDDI
->dwRevision
= adapter_id
.revision
;
2643 DDDI
->guidDeviceIdentifier
= adapter_id
.device_identifier
;
2644 DDDI
->dwWHQLLevel
= adapter_id
.whql_level
;
2648 static HRESULT WINAPI
ddraw4_GetDeviceIdentifier(IDirectDraw4
*iface
,
2649 DDDEVICEIDENTIFIER
*identifier
, DWORD flags
)
2651 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2652 DDDEVICEIDENTIFIER2 identifier2
;
2655 TRACE("iface %p, identifier %p, flags %#x.\n", iface
, identifier
, flags
);
2657 hr
= ddraw7_GetDeviceIdentifier(&ddraw
->IDirectDraw7_iface
, &identifier2
, flags
);
2658 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&identifier2
, identifier
);
2663 /*****************************************************************************
2664 * IDirectDraw7::GetSurfaceFromDC
2666 * Returns the Surface for a GDI device context handle.
2667 * Is this related to IDirectDrawSurface::GetDC ???
2670 * hdc: hdc to return the surface for
2671 * Surface: Address to write the surface pointer to
2674 * Always returns DD_OK because it's a stub
2676 *****************************************************************************/
2677 static HRESULT WINAPI
ddraw7_GetSurfaceFromDC(IDirectDraw7
*iface
,
2678 HDC dc
, IDirectDrawSurface7
**surface
)
2680 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2681 struct ddraw_surface
*surface_impl
;
2683 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2686 return E_INVALIDARG
;
2691 wined3d_mutex_lock();
2692 LIST_FOR_EACH_ENTRY(surface_impl
, &ddraw
->surface_list
, struct ddraw_surface
, surface_list_entry
)
2694 if (surface_impl
->dc
!= dc
)
2697 TRACE("Found surface %p for dc %p.\n", surface_impl
, dc
);
2698 *surface
= &surface_impl
->IDirectDrawSurface7_iface
;
2699 IDirectDrawSurface7_AddRef(*surface
);
2700 wined3d_mutex_unlock();
2703 wined3d_mutex_unlock();
2706 TRACE("No surface found for dc %p.\n", dc
);
2708 return DDERR_NOTFOUND
;
2711 static HRESULT WINAPI
ddraw4_GetSurfaceFromDC(IDirectDraw4
*iface
, HDC dc
,
2712 IDirectDrawSurface4
**surface
)
2714 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2715 struct ddraw_surface
*surface_impl
;
2716 IDirectDrawSurface7
*surface7
;
2719 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2721 if (!surface
) return E_INVALIDARG
;
2723 hr
= ddraw7_GetSurfaceFromDC(&ddraw
->IDirectDraw7_iface
, dc
, &surface7
);
2729 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2730 /* Tests say this is true */
2731 *surface
= (IDirectDrawSurface4
*)&surface_impl
->IDirectDrawSurface_iface
;
2732 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2733 IDirectDrawSurface7_Release(surface7
);
2738 static HRESULT CALLBACK
restore_callback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
2740 IDirectDrawSurface_Restore(surface
);
2741 IDirectDrawSurface_Release(surface
);
2743 return DDENUMRET_OK
;
2746 static HRESULT WINAPI
ddraw7_RestoreAllSurfaces(IDirectDraw7
*iface
)
2748 TRACE("iface %p.\n", iface
);
2750 return IDirectDraw7_EnumSurfaces(iface
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
2751 NULL
, NULL
, restore_callback
);
2754 static HRESULT WINAPI
ddraw4_RestoreAllSurfaces(IDirectDraw4
*iface
)
2756 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2758 TRACE("iface %p.\n", iface
);
2760 return ddraw7_RestoreAllSurfaces(&ddraw
->IDirectDraw7_iface
);
2763 /*****************************************************************************
2764 * IDirectDraw7::StartModeTest
2766 * Tests the specified video modes to update the system registry with
2767 * refresh rate information. StartModeTest starts the mode test,
2768 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
2769 * isn't called within 15 seconds, the mode is failed automatically
2771 * As refresh rates are handled by the X server, I don't think this
2772 * Method is important
2775 * Modes: An array of mode specifications
2776 * NumModes: The number of modes in Modes
2777 * Flags: Some flags...
2780 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
2781 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
2784 *****************************************************************************/
2785 static HRESULT WINAPI
ddraw7_StartModeTest(IDirectDraw7
*iface
, SIZE
*Modes
, DWORD NumModes
, DWORD Flags
)
2787 FIXME("iface %p, modes %p, mode_count %u, flags %#x partial stub!\n",
2788 iface
, Modes
, NumModes
, Flags
);
2790 /* This looks sane */
2791 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
2793 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
2794 * As it is not, DDERR_TESTFINISHED is returned
2795 * (hopefully that's correct
2797 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
2798 * well, that value doesn't (yet) exist in the wine headers, so ignore it
2804 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
, DDSURFACEDESC2
*surface_desc
,
2805 IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
2807 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2808 struct ddraw_surface
*impl
;
2811 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2812 iface
, surface_desc
, surface
, outer_unknown
);
2814 wined3d_mutex_lock();
2816 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2818 WARN("Cooperative level not set.\n");
2819 wined3d_mutex_unlock();
2820 return DDERR_NOCOOPERATIVELEVELSET
;
2823 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2825 WARN("Application supplied invalid surface descriptor\n");
2826 wined3d_mutex_unlock();
2827 return DDERR_INVALIDPARAMS
;
2836 WARN("Surface pointer %p is invalid.\n", surface
);
2837 wined3d_mutex_unlock();
2838 return DDERR_INVALIDPARAMS
;
2842 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2844 if (TRACE_ON(ddraw
))
2846 TRACE(" (%p) Requesting surface desc :\n", iface
);
2847 DDRAW_dump_surface_desc(surface_desc
);
2850 WARN("Application tried to create an explicit front or back buffer\n");
2851 wined3d_mutex_unlock();
2852 return DDERR_INVALIDCAPS
;
2855 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 7);
2856 wined3d_mutex_unlock();
2860 *surface
= &impl
->IDirectDrawSurface7_iface
;
2861 IDirectDraw7_AddRef(iface
);
2862 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2867 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
2868 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
2870 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2871 struct ddraw_surface
*impl
;
2874 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2875 iface
, surface_desc
, surface
, outer_unknown
);
2877 wined3d_mutex_lock();
2879 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2881 WARN("Cooperative level not set.\n");
2882 wined3d_mutex_unlock();
2883 return DDERR_NOCOOPERATIVELEVELSET
;
2886 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2888 WARN("Application supplied invalid surface descriptor\n");
2889 wined3d_mutex_unlock();
2890 return DDERR_INVALIDPARAMS
;
2899 WARN("Surface pointer %p is invalid.\n", surface
);
2900 wined3d_mutex_unlock();
2901 return DDERR_INVALIDPARAMS
;
2905 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2907 if (TRACE_ON(ddraw
))
2909 TRACE(" (%p) Requesting surface desc :\n", iface
);
2910 DDRAW_dump_surface_desc(surface_desc
);
2913 WARN("Application tried to create an explicit front or back buffer\n");
2914 wined3d_mutex_unlock();
2915 return DDERR_INVALIDCAPS
;
2918 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 4);
2919 wined3d_mutex_unlock();
2923 *surface
= &impl
->IDirectDrawSurface4_iface
;
2924 IDirectDraw4_AddRef(iface
);
2925 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2930 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
2931 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2933 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2934 struct ddraw_surface
*impl
;
2936 DDSURFACEDESC2 surface_desc2
;
2938 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2939 iface
, surface_desc
, surface
, outer_unknown
);
2941 wined3d_mutex_lock();
2943 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2945 WARN("Cooperative level not set.\n");
2946 wined3d_mutex_unlock();
2947 return DDERR_NOCOOPERATIVELEVELSET
;
2950 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2952 WARN("Application supplied invalid surface descriptor\n");
2953 wined3d_mutex_unlock();
2954 return DDERR_INVALIDPARAMS
;
2963 WARN("Surface pointer %p is invalid.\n", surface
);
2964 wined3d_mutex_unlock();
2965 return DDERR_INVALIDPARAMS
;
2969 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2970 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2972 if (TRACE_ON(ddraw
))
2974 TRACE(" (%p) Requesting surface desc :\n", iface
);
2975 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
2978 WARN("Application tried to create an explicit front or back buffer\n");
2979 wined3d_mutex_unlock();
2980 return DDERR_INVALIDCAPS
;
2983 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 2);
2984 wined3d_mutex_unlock();
2988 *surface
= &impl
->IDirectDrawSurface_iface
;
2989 impl
->ifaceToRelease
= NULL
;
2994 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
2995 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2997 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2998 struct ddraw_surface
*impl
;
3000 DDSURFACEDESC2 surface_desc2
;
3002 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3003 iface
, surface_desc
, surface
, outer_unknown
);
3005 wined3d_mutex_lock();
3007 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
3009 WARN("Cooperative level not set.\n");
3010 wined3d_mutex_unlock();
3011 return DDERR_NOCOOPERATIVELEVELSET
;
3014 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3016 WARN("Application supplied invalid surface descriptor\n");
3017 wined3d_mutex_unlock();
3018 return DDERR_INVALIDPARAMS
;
3027 WARN("Surface pointer %p is invalid.\n", surface
);
3028 wined3d_mutex_unlock();
3029 return DDERR_INVALIDPARAMS
;
3033 if ((surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
))
3034 == (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
)
3035 || (surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
))
3036 == ((DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
)))
3038 WARN("Application tried to create an explicit front or back buffer.\n");
3039 wined3d_mutex_unlock();
3040 return DDERR_INVALIDCAPS
;
3043 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3044 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 1);
3045 wined3d_mutex_unlock();
3049 *surface
= &impl
->IDirectDrawSurface_iface
;
3050 impl
->ifaceToRelease
= NULL
;
3056 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
3057 const DDPIXELFORMAT
*provided
)
3059 /* Some flags must be present in both or neither for a match. */
3060 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
3061 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
3062 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
3064 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3067 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
3070 if (requested
->dwFlags
& DDPF_FOURCC
)
3071 if (requested
->dwFourCC
!= provided
->dwFourCC
)
3074 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
3075 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3076 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
3079 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3080 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3081 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
3084 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
3085 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
3088 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
3089 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3091 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
3094 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
3095 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
3101 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3110 #define CMP(FLAG, FIELD) \
3111 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3112 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3114 static const struct compare_info compare
[] =
3116 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3117 CMP(BACKBUFFERCOUNT
, u5
.dwBackBufferCount
),
3119 CMP(CKDESTBLT
, ddckCKDestBlt
),
3120 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3121 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3122 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3123 CMP(HEIGHT
, dwHeight
),
3124 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3125 CMP(LPSURFACE
, lpSurface
),
3126 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3127 CMP(PITCH
, u1
/* lPitch */),
3128 /* PIXELFORMAT: manual */
3129 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3130 CMP(TEXTURESTAGE
, dwTextureStage
),
3131 CMP(WIDTH
, dwWidth
),
3132 /* ZBUFFERBITDEPTH: "obsolete" */
3139 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3142 for (i
=0; i
< ARRAY_SIZE(compare
); i
++)
3144 if (requested
->dwFlags
& compare
[i
].flag
3145 && memcmp((const char *)provided
+ compare
[i
].offset
,
3146 (const char *)requested
+ compare
[i
].offset
,
3147 compare
[i
].size
) != 0)
3151 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3153 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3154 &provided
->u4
.ddpfPixelFormat
))
3161 struct surfacescallback2_context
3163 LPDDENUMSURFACESCALLBACK2 func
;
3167 struct surfacescallback_context
3169 LPDDENUMSURFACESCALLBACK func
;
3173 static HRESULT CALLBACK
EnumSurfacesCallback2Thunk(IDirectDrawSurface7
*surface
,
3174 DDSURFACEDESC2
*surface_desc
, void *context
)
3176 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3177 struct surfacescallback2_context
*cbcontext
= context
;
3180 return cbcontext
->func(NULL
, surface_desc
, cbcontext
->context
);
3182 IDirectDrawSurface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
3183 IDirectDrawSurface7_Release(surface
);
3185 return cbcontext
->func(&surface_impl
->IDirectDrawSurface4_iface
,
3186 surface_desc
, cbcontext
->context
);
3189 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3190 DDSURFACEDESC2
*surface_desc
, void *context
)
3192 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3193 struct surfacescallback_context
*cbcontext
= context
;
3196 return cbcontext
->func(NULL
, (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3198 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
3199 IDirectDrawSurface7_Release(surface
);
3201 return cbcontext
->func(&surface_impl
->IDirectDrawSurface_iface
,
3202 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3205 struct enum_surface_mode_params
3207 IDirectDraw7
*ddraw
;
3208 const DDSURFACEDESC2
*desc
;
3209 LPDDENUMSURFACESCALLBACK7 callback
;
3213 static HRESULT CALLBACK
enum_surface_mode_callback(DDSURFACEDESC2
*surface_desc
, void *context
)
3215 const struct enum_surface_mode_params
*params
= context
;
3216 DDSURFACEDESC2 desc
= *params
->desc
;
3217 IDirectDrawSurface7
*surface
;
3219 desc
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PITCH
| DDSD_PIXELFORMAT
;
3220 desc
.dwWidth
= surface_desc
->dwWidth
;
3221 desc
.dwHeight
= surface_desc
->dwHeight
;
3222 desc
.u1
.lPitch
= surface_desc
->u1
.lPitch
;
3223 desc
.u4
.ddpfPixelFormat
= surface_desc
->u4
.ddpfPixelFormat
;
3225 if (SUCCEEDED(ddraw7_CreateSurface(params
->ddraw
, &desc
, &surface
, NULL
)))
3227 IDirectDrawSurface7_Release(surface
);
3228 return params
->callback(NULL
, &desc
, params
->context
);
3230 return DDENUMRET_OK
;
3233 /*****************************************************************************
3234 * IDirectDraw7::EnumSurfaces
3236 * Loops through all surfaces attached to this device and calls the
3237 * application callback. This can't be relayed to WineD3DDevice,
3238 * because some WineD3DSurfaces' parents are IParent objects
3241 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3242 * DDSD: Description to filter for
3243 * Context: Application-provided pointer, it's passed unmodified to the
3245 * Callback: Address to call for each surface
3248 * DDERR_INVALIDPARAMS if the callback is NULL
3251 *****************************************************************************/
3252 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD flags
,
3253 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK7 callback
)
3255 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3258 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3259 iface
, flags
, surface_desc
, context
, callback
);
3262 return DDERR_INVALIDPARAMS
;
3264 if (flags
& DDENUMSURFACES_CANBECREATED
)
3266 IDirectDrawSurface7
*surface
;
3268 if ((flags
& (DDENUMSURFACES_ALL
| DDENUMSURFACES_MATCH
| DDENUMSURFACES_NOMATCH
)) != DDENUMSURFACES_MATCH
)
3269 return DDERR_INVALIDPARAMS
;
3271 wined3d_mutex_lock();
3273 if (surface_desc
->dwFlags
& (DDSD_WIDTH
| DDSD_HEIGHT
))
3275 if (SUCCEEDED(ddraw7_CreateSurface(iface
, surface_desc
, &surface
, NULL
)))
3277 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3278 callback(NULL
, &surface_impl
->surface_desc
, context
);
3279 IDirectDrawSurface7_Release(surface
);
3284 DDSURFACEDESC2 desc
=
3286 .dwSize
= sizeof(desc
),
3287 .dwFlags
= DDSD_PIXELFORMAT
,
3288 .u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
),
3290 struct enum_surface_mode_params params
=
3293 .desc
= surface_desc
,
3294 .callback
= callback
,
3297 struct wined3d_display_mode mode
;
3299 if (FAILED(hr
= wined3d_output_get_display_mode(ddraw
->wined3d_output
, &mode
, NULL
)))
3301 ERR("Failed to get display mode, hr %#x.\n", hr
);
3302 wined3d_mutex_unlock();
3303 return hr_ddraw_from_wined3d(hr
);
3306 ddrawformat_from_wined3dformat(&desc
.u4
.ddpfPixelFormat
, mode
.format_id
);
3307 hr
= ddraw7_EnumDisplayModes(iface
, 0, &desc
, ¶ms
, enum_surface_mode_callback
);
3310 wined3d_mutex_unlock();
3312 else if (flags
& DDENUMSURFACES_DOESEXIST
)
3314 struct ddraw_surface
*surface
, *cursor
;
3315 BOOL nomatch
= !!(flags
& DDENUMSURFACES_NOMATCH
);
3317 wined3d_mutex_lock();
3319 /* Use the safe enumeration, as the callback may destroy surfaces. */
3320 LIST_FOR_EACH_ENTRY_SAFE(surface
, cursor
, &ddraw
->surface_list
, struct ddraw_surface
, surface_list_entry
)
3322 if (!surface
->iface_count
)
3324 WARN("Not enumerating surface %p because it doesn't have any references.\n", surface
);
3328 if ((flags
& DDENUMSURFACES_ALL
)
3329 || nomatch
!= ddraw_match_surface_desc(surface_desc
, &surface
->surface_desc
))
3331 DDSURFACEDESC2 desc
= surface
->surface_desc
;
3333 TRACE("Enumerating surface %p.\n", surface
);
3334 IDirectDrawSurface7_AddRef(&surface
->IDirectDrawSurface7_iface
);
3335 if (callback(&surface
->IDirectDrawSurface7_iface
, &desc
, context
) != DDENUMRET_OK
)
3340 wined3d_mutex_unlock();
3344 return DDERR_INVALIDPARAMS
;
3350 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3351 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3353 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3354 struct surfacescallback2_context cbcontext
;
3356 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3357 iface
, flags
, surface_desc
, context
, callback
);
3359 cbcontext
.func
= callback
;
3360 cbcontext
.context
= context
;
3362 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
,
3363 &cbcontext
, EnumSurfacesCallback2Thunk
);
3366 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3367 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3369 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3370 struct surfacescallback_context cbcontext
;
3371 DDSURFACEDESC2 surface_desc2
;
3373 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3374 iface
, flags
, surface_desc
, context
, callback
);
3376 cbcontext
.func
= callback
;
3377 cbcontext
.context
= context
;
3379 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3380 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3381 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3384 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3385 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3387 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3388 struct surfacescallback_context cbcontext
;
3389 DDSURFACEDESC2 surface_desc2
;
3391 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3392 iface
, flags
, surface_desc
, context
, callback
);
3394 cbcontext
.func
= callback
;
3395 cbcontext
.context
= context
;
3397 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3398 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3399 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3402 /*****************************************************************************
3403 * DirectDrawCreateClipper (DDRAW.@)
3405 * Creates a new IDirectDrawClipper object.
3408 * Clipper: Address to write the interface pointer to
3409 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3413 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3414 * E_OUTOFMEMORY if allocating the object failed
3416 *****************************************************************************/
3417 HRESULT WINAPI
DirectDrawCreateClipper(DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3419 struct ddraw_clipper
*object
;
3422 TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
3423 flags
, clipper
, outer_unknown
);
3426 return CLASS_E_NOAGGREGATION
;
3428 wined3d_mutex_lock();
3430 if (!(object
= heap_alloc_zero(sizeof(*object
))))
3432 wined3d_mutex_unlock();
3433 return E_OUTOFMEMORY
;
3436 hr
= ddraw_clipper_init(object
);
3439 WARN("Failed to initialize clipper, hr %#x.\n", hr
);
3441 wined3d_mutex_unlock();
3445 TRACE("Created clipper %p.\n", object
);
3446 *clipper
= &object
->IDirectDrawClipper_iface
;
3447 wined3d_mutex_unlock();
3452 /*****************************************************************************
3453 * IDirectDraw7::CreateClipper
3455 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3457 *****************************************************************************/
3458 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3459 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3461 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3462 iface
, Flags
, Clipper
, UnkOuter
);
3464 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3467 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
, DWORD flags
,
3468 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3470 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3472 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3473 iface
, flags
, clipper
, outer_unknown
);
3475 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3478 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
3479 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3481 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3483 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3484 iface
, flags
, clipper
, outer_unknown
);
3486 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3489 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
3490 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3492 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3494 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3495 iface
, flags
, clipper
, outer_unknown
);
3497 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3500 /*****************************************************************************
3501 * IDirectDraw7::CreatePalette
3503 * Creates a new IDirectDrawPalette object
3506 * Flags: The flags for the new clipper
3507 * ColorTable: Color table to assign to the new clipper
3508 * Palette: Address to write the interface pointer to
3509 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3513 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3514 * E_OUTOFMEMORY if allocating the object failed
3516 *****************************************************************************/
3517 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
3518 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
3520 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3521 struct ddraw_palette
*object
;
3524 TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
3525 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3528 return CLASS_E_NOAGGREGATION
;
3530 wined3d_mutex_lock();
3532 /* The refcount test shows that a cooplevel is required for this */
3533 if (!ddraw
->cooperative_level
)
3535 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3536 wined3d_mutex_unlock();
3537 return DDERR_NOCOOPERATIVELEVELSET
;
3540 if (!(object
= heap_alloc(sizeof(*object
))))
3542 ERR("Out of memory when allocating memory for a palette implementation\n");
3543 wined3d_mutex_unlock();
3544 return E_OUTOFMEMORY
;
3547 hr
= ddraw_palette_init(object
, ddraw
, Flags
, ColorTable
);
3550 WARN("Failed to initialize palette, hr %#x.\n", hr
);
3552 wined3d_mutex_unlock();
3556 TRACE("Created palette %p.\n", object
);
3557 *Palette
= &object
->IDirectDrawPalette_iface
;
3558 wined3d_mutex_unlock();
3563 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
, PALETTEENTRY
*entries
,
3564 IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3566 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3569 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3570 iface
, flags
, entries
, palette
, outer_unknown
);
3572 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3573 if (SUCCEEDED(hr
) && *palette
)
3575 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3576 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3577 IDirectDraw4_AddRef(iface
);
3578 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3583 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
3584 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3586 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3589 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3590 iface
, flags
, entries
, palette
, outer_unknown
);
3592 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3593 if (SUCCEEDED(hr
) && *palette
)
3595 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3596 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3597 impl
->ifaceToRelease
= NULL
;
3603 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
3604 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3606 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3609 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3610 iface
, flags
, entries
, palette
, outer_unknown
);
3612 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3613 if (SUCCEEDED(hr
) && *palette
)
3615 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3616 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3617 impl
->ifaceToRelease
= NULL
;
3623 /*****************************************************************************
3624 * IDirectDraw7::DuplicateSurface
3626 * Duplicates a surface. The surface memory points to the same memory as
3627 * the original surface, and it's released when the last surface referencing
3628 * it is released. I guess that's beyond Wine's surface management right now
3629 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3630 * test application to implement this)
3633 * Src: Address of the source surface
3634 * Dest: Address to write the new surface pointer to
3637 * See IDirectDraw7::CreateSurface
3639 *****************************************************************************/
3640 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
3641 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
3643 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(Src
);
3645 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
3647 /* For now, simply create a new, independent surface */
3648 return IDirectDraw7_CreateSurface(iface
, &src_surface
->surface_desc
, Dest
, NULL
);
3651 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
, IDirectDrawSurface4
*src
,
3652 IDirectDrawSurface4
**dst
)
3654 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
3655 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3656 struct ddraw_surface
*dst_impl
;
3657 IDirectDrawSurface7
*dst7
;
3660 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3662 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3663 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3669 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3670 *dst
= &dst_impl
->IDirectDrawSurface4_iface
;
3671 IDirectDrawSurface4_AddRef(*dst
);
3672 IDirectDrawSurface7_Release(dst7
);
3677 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
3678 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
3680 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3681 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3682 struct ddraw_surface
*dst_impl
;
3683 IDirectDrawSurface7
*dst7
;
3686 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3688 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3689 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3692 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3693 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3694 IDirectDrawSurface_AddRef(*dst
);
3695 IDirectDrawSurface7_Release(dst7
);
3700 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
, IDirectDrawSurface
*src
,
3701 IDirectDrawSurface
**dst
)
3703 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3704 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3705 struct ddraw_surface
*dst_impl
;
3706 IDirectDrawSurface7
*dst7
;
3709 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3711 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3712 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3715 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3716 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3717 IDirectDrawSurface_AddRef(*dst
);
3718 IDirectDrawSurface7_Release(dst7
);
3723 /*****************************************************************************
3724 * IDirect3D7::EnumDevices
3726 * The EnumDevices method for IDirect3D7. It enumerates all supported
3727 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
3730 * callback: Function to call for each enumerated device
3731 * context: Pointer to pass back to the app
3734 * D3D_OK, or the return value of the GetCaps call
3736 *****************************************************************************/
3737 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
3739 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
3740 D3DDEVICEDESC7 device_desc7
;
3744 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3747 return DDERR_INVALIDPARAMS
;
3749 wined3d_mutex_lock();
3751 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3753 wined3d_mutex_unlock();
3757 for (i
= 0; i
< ARRAY_SIZE(device_list7
); i
++)
3761 device_desc7
.deviceGUID
= *device_list7
[i
].device_guid
;
3762 ret
= callback(device_list7
[i
].interface_name
, device_list7
[i
].device_name
, &device_desc7
, context
);
3763 if (ret
!= DDENUMRET_OK
)
3765 TRACE("Application cancelled the enumeration.\n");
3766 wined3d_mutex_unlock();
3771 TRACE("End of enumeration.\n");
3773 wined3d_mutex_unlock();
3778 /*****************************************************************************
3779 * IDirect3D3::EnumDevices
3781 * Enumerates all supported Direct3DDevice interfaces. This is the
3782 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
3784 * Versions 1, 2 and 3
3787 * callback: Application-provided routine to call for each enumerated device
3788 * Context: Pointer to pass to the callback
3791 * D3D_OK on success,
3792 * The result of IDirect3DImpl_GetCaps if it failed
3794 *****************************************************************************/
3795 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3797 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
3799 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3800 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
3801 D3DDEVICEDESC7 device_desc7
;
3804 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
3805 * name string. Let's put the string in a sufficiently sized array in
3806 * writable memory. */
3807 char device_name
[50];
3808 strcpy(device_name
,"Direct3D HEL");
3810 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3813 return DDERR_INVALIDPARAMS
;
3815 wined3d_mutex_lock();
3817 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3819 wined3d_mutex_unlock();
3822 ddraw_d3dcaps1_from_7(&device_desc1
, &device_desc7
);
3824 /* Do I have to enumerate the reference id? Note from old d3d7:
3825 * "It seems that enumerating the reference IID on Direct3D 1 games
3826 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
3828 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
3829 * EnumReference which enables / disables enumerating the reference
3830 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
3831 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
3832 * demo directory suggest this.
3834 * Some games(GTA 2) seem to use the second enumerated device, so I have
3835 * to enumerate at least 2 devices. So enumerate the reference device to
3838 * Other games (Rollcage) tell emulation and hal device apart by certain
3839 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
3840 * limitation flag), and it refuses all devices that have the perspective
3841 * flag set. This way it refuses the emulation device, and HAL devices
3842 * never have POW2 unset in d3d7 on windows. */
3843 if (ddraw
->d3dversion
!= 1)
3845 static CHAR reference_description
[] = "RGB Direct3D emulation";
3847 TRACE("Enumerating WineD3D D3DDevice interface.\n");
3848 hal_desc
= device_desc1
;
3849 hel_desc
= device_desc1
;
3850 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
3851 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3852 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3853 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3854 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3855 /* RGB, RAMP and MMX devices have a HAL dcmColorModel of 0 */
3856 hal_desc
.dcmColorModel
= 0;
3857 /* RGB, RAMP and MMX devices cannot report HAL hardware flags */
3858 hal_desc
.dwFlags
= 0;
3860 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
3861 device_name
, &hal_desc
, &hel_desc
, context
);
3862 if (hr
!= D3DENUMRET_OK
)
3864 TRACE("Application cancelled the enumeration.\n");
3865 wined3d_mutex_unlock();
3870 strcpy(device_name
,"Direct3D HAL");
3872 TRACE("Enumerating HAL Direct3D device.\n");
3873 hal_desc
= device_desc1
;
3874 hel_desc
= device_desc1
;
3876 /* The hal device does not have the pow2 flag set in hel, but in hal. */
3877 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3878 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3879 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3880 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3881 /* HAL devices have a HEL dcmColorModel of 0 */
3882 hel_desc
.dcmColorModel
= 0;
3884 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
3885 device_name
, &hal_desc
, &hel_desc
, context
);
3886 if (hr
!= D3DENUMRET_OK
)
3888 TRACE("Application cancelled the enumeration.\n");
3889 wined3d_mutex_unlock();
3893 TRACE("End of enumeration.\n");
3895 wined3d_mutex_unlock();
3900 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3902 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3904 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3906 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3909 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3911 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3913 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3915 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3918 /*****************************************************************************
3919 * IDirect3D3::CreateLight
3921 * Creates an IDirect3DLight interface. This interface is used in
3922 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
3923 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
3924 * uses the IDirect3DDevice7 interface with D3D7 lights.
3926 * Versions 1, 2 and 3
3929 * light: Address to store the new interface pointer
3930 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3935 * DDERR_OUTOFMEMORY if memory allocation failed
3936 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3938 *****************************************************************************/
3939 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
,
3940 IUnknown
*outer_unknown
)
3942 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3943 struct d3d_light
*object
;
3945 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3948 return CLASS_E_NOAGGREGATION
;
3950 if (!(object
= heap_alloc_zero(sizeof(*object
))))
3952 ERR("Failed to allocate light memory.\n");
3953 return DDERR_OUTOFMEMORY
;
3956 d3d_light_init(object
, ddraw
);
3958 TRACE("Created light %p.\n", object
);
3959 *light
= &object
->IDirect3DLight_iface
;
3964 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3966 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3968 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3970 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3973 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3975 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3977 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3979 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3982 /*****************************************************************************
3983 * IDirect3D3::CreateMaterial
3985 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
3986 * and older versions. The IDirect3DMaterial implementation wraps its
3987 * functionality to IDirect3DDevice7::SetMaterial and friends.
3989 * Versions 1, 2 and 3
3992 * material: Address to store the new interface's pointer to
3993 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3998 * DDERR_OUTOFMEMORY if memory allocation failed
3999 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4001 *****************************************************************************/
4002 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
,
4003 IUnknown
*outer_unknown
)
4005 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4006 struct d3d_material
*object
;
4008 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4010 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4012 object
= d3d_material_create(ddraw
);
4015 ERR("Failed to allocate material memory.\n");
4016 return DDERR_OUTOFMEMORY
;
4019 TRACE("Created material %p.\n", object
);
4020 *material
= &object
->IDirect3DMaterial3_iface
;
4025 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
,
4026 IUnknown
*outer_unknown
)
4028 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4029 struct d3d_material
*object
;
4031 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4033 object
= d3d_material_create(ddraw
);
4036 ERR("Failed to allocate material memory.\n");
4037 return DDERR_OUTOFMEMORY
;
4040 TRACE("Created material %p.\n", object
);
4041 *material
= &object
->IDirect3DMaterial2_iface
;
4046 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
,
4047 IUnknown
*outer_unknown
)
4049 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4050 struct d3d_material
*object
;
4052 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4054 object
= d3d_material_create(ddraw
);
4057 ERR("Failed to allocate material memory.\n");
4058 return DDERR_OUTOFMEMORY
;
4061 TRACE("Created material %p.\n", object
);
4062 *material
= &object
->IDirect3DMaterial_iface
;
4067 /*****************************************************************************
4068 * IDirect3D3::CreateViewport
4070 * Creates an IDirect3DViewport interface. This interface is used
4071 * by Direct3D and earlier versions for Viewport management. In Direct3D7
4072 * it has been replaced by a viewport structure and
4073 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
4074 * uses the IDirect3DDevice7 methods for its functionality
4077 * Viewport: Address to store the new interface pointer
4078 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4083 * DDERR_OUTOFMEMORY if memory allocation failed
4084 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4086 *****************************************************************************/
4087 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
,
4088 IUnknown
*outer_unknown
)
4090 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4091 struct d3d_viewport
*object
;
4093 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4095 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4097 if (!(object
= heap_alloc_zero(sizeof(*object
))))
4099 ERR("Failed to allocate viewport memory.\n");
4100 return DDERR_OUTOFMEMORY
;
4103 d3d_viewport_init(object
, ddraw
);
4105 TRACE("Created viewport %p.\n", object
);
4106 *viewport
= &object
->IDirect3DViewport3_iface
;
4111 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
4113 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4115 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4117 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4121 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
4123 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4125 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4127 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4131 static HRESULT
ddraw_find_device(struct ddraw
*ddraw
, const D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
,
4132 unsigned int guid_count
, const GUID
* const *guids
, DWORD device_desc_size
)
4134 struct ddraw_find_device_result_v1
4138 D3DDEVICEDESC_V1 hw_desc
;
4139 D3DDEVICEDESC_V1 sw_desc
;
4141 struct ddraw_find_device_result_v2
4145 D3DDEVICEDESC_V2 hw_desc
;
4146 D3DDEVICEDESC_V2 sw_desc
;
4148 D3DDEVICEDESC7 desc7
;
4149 D3DDEVICEDESC desc1
;
4153 TRACE("ddraw %p, fds %p, fdr %p, guid_count %u, guids %p, device_desc_size %u.\n",
4154 ddraw
, fds
, fdr
, guid_count
, guids
, device_desc_size
);
4157 return DDERR_INVALIDPARAMS
;
4159 if (fds
->dwSize
!= sizeof(*fds
))
4161 WARN("Got invalid search structure size %u.\n", fds
->dwSize
);
4162 return DDERR_INVALIDPARAMS
;
4165 if (fdr
->dwSize
!= sizeof(*fdr
) && fdr
->dwSize
!= sizeof(*fdr2
) && fdr
->dwSize
!= sizeof(*fdr1
))
4167 WARN("Got invalid result structure size %u.\n", fdr
->dwSize
);
4168 return DDERR_INVALIDPARAMS
;
4171 if (fds
->dwFlags
& D3DFDS_COLORMODEL
)
4172 WARN("Ignoring colour model %#x.\n", fds
->dcmColorModel
);
4174 if (fds
->dwFlags
& D3DFDS_GUID
)
4178 TRACE("Trying to match GUID %s.\n", debugstr_guid(&fds
->guid
));
4180 if ((ddraw
->flags
& DDRAW_NO3D
) && IsEqualGUID(&fds
->guid
, &IID_IDirect3DHALDevice
))
4182 WARN("HAL device not available without 3D support.\n");
4183 return DDERR_NOTFOUND
;
4186 for (i
= 0; i
< guid_count
; ++i
)
4188 if (IsEqualGUID(guids
[i
], &fds
->guid
))
4197 WARN("Failed to match GUID %s.\n", debugstr_guid(&fds
->guid
));
4198 return DDERR_NOTFOUND
;
4203 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &desc7
)))
4206 /* Now return our own GUID */
4207 ddraw_d3dcaps1_from_7(&desc1
, &desc7
);
4208 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4210 /* Note that "device_desc_size" doesn't necessarily have any relation to
4211 * the actual structure size. However, this matches the behaviour of
4212 * Windows since at least Windows 2000. */
4213 if (fdr
->dwSize
== sizeof(*fdr1
))
4215 fdr1
= (struct ddraw_find_device_result_v1
*)fdr
;
4216 memcpy(&fdr1
->hw_desc
, &desc1
, sizeof(fdr1
->hw_desc
));
4217 fdr1
->hw_desc
.dwSize
= device_desc_size
;
4218 memcpy(&fdr1
->sw_desc
, &desc1
, sizeof(fdr1
->sw_desc
));
4219 fdr1
->sw_desc
.dwSize
= device_desc_size
;
4221 else if (fdr
->dwSize
== sizeof(*fdr2
))
4223 fdr2
= (struct ddraw_find_device_result_v2
*)fdr
;
4224 memcpy(&fdr2
->hw_desc
, &desc1
, sizeof(fdr2
->hw_desc
));
4225 fdr2
->hw_desc
.dwSize
= device_desc_size
;
4226 memcpy(&fdr2
->sw_desc
, &desc1
, sizeof(fdr2
->sw_desc
));
4227 fdr2
->sw_desc
.dwSize
= device_desc_size
;
4231 fdr
->ddHwDesc
= desc1
;
4232 fdr
->ddHwDesc
.dwSize
= device_desc_size
;
4233 fdr
->ddSwDesc
= desc1
;
4234 fdr
->ddSwDesc
.dwSize
= device_desc_size
;
4237 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4242 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4244 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4245 static const GUID
* const guids
[] =
4247 &IID_D3DDEVICE_WineD3D
,
4248 &IID_IDirect3DHALDevice
,
4249 &IID_IDirect3DRGBDevice
,
4252 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4254 return ddraw_find_device(ddraw
, fds
, fdr
, ARRAY_SIZE(guids
), guids
, sizeof(D3DDEVICEDESC_V3
));
4257 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4259 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4260 static const GUID
* const guids
[] =
4262 &IID_D3DDEVICE_WineD3D
,
4263 &IID_IDirect3DHALDevice
,
4264 &IID_IDirect3DMMXDevice
,
4265 &IID_IDirect3DRGBDevice
,
4266 &IID_IDirect3DRampDevice
,
4269 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4271 return ddraw_find_device(ddraw
, fds
, fdr
, ARRAY_SIZE(guids
), guids
, sizeof(D3DDEVICEDESC_V2
));
4274 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4276 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4277 static const GUID
* const guids
[] =
4279 &IID_D3DDEVICE_WineD3D
,
4280 &IID_IDirect3DHALDevice
,
4281 &IID_IDirect3DRGBDevice
,
4282 &IID_IDirect3DRampDevice
,
4285 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4287 return ddraw_find_device(ddraw
, fds
, fdr
, ARRAY_SIZE(guids
), guids
, sizeof(D3DDEVICEDESC_V1
));
4290 /*****************************************************************************
4291 * IDirect3D7::CreateDevice
4293 * Creates an IDirect3DDevice7 interface.
4295 * Versions 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4296 * DirectDraw surfaces and are created with
4297 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4298 * create the device object and QueryInterfaces for IDirect3DDevice
4301 * refiid: IID of the device to create
4302 * Surface: Initial rendertarget
4303 * Device: Address to return the interface pointer
4307 * DDERR_OUTOFMEMORY if memory allocation failed
4308 * DDERR_INVALIDPARAMS if a device exists already
4310 *****************************************************************************/
4311 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4312 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4314 struct ddraw_surface
*target
= unsafe_impl_from_IDirectDrawSurface7(surface
);
4315 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4316 struct d3d_device
*object
;
4319 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4321 wined3d_mutex_lock();
4322 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, target
, (IUnknown
*)surface
, 7, &object
, NULL
)))
4324 *device
= &object
->IDirect3DDevice7_iface
;
4328 WARN("Failed to create device, hr %#x.\n", hr
);
4331 wined3d_mutex_unlock();
4336 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4337 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4339 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface4(surface
);
4340 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4341 struct d3d_device
*device_impl
;
4344 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4345 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4348 return CLASS_E_NOAGGREGATION
;
4350 wined3d_mutex_lock();
4351 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 3, &device_impl
, NULL
)))
4353 *device
= &device_impl
->IDirect3DDevice3_iface
;
4357 WARN("Failed to create device, hr %#x.\n", hr
);
4360 wined3d_mutex_unlock();
4365 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4366 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4368 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface(surface
);
4369 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4370 struct d3d_device
*device_impl
;
4373 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4374 iface
, debugstr_guid(riid
), surface
, device
);
4376 wined3d_mutex_lock();
4377 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 2, &device_impl
, NULL
)))
4379 *device
= &device_impl
->IDirect3DDevice2_iface
;
4383 WARN("Failed to create device, hr %#x.\n", hr
);
4386 wined3d_mutex_unlock();
4391 /*****************************************************************************
4392 * IDirect3D7::CreateVertexBuffer
4394 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4400 * desc: Requested Vertex buffer properties
4401 * vertex_buffer: Address to return the interface pointer at
4402 * flags: Some flags, should be 0
4406 * DDERR_OUTOFMEMORY if memory allocation failed
4407 * DDERR_INVALIDPARAMS if desc or vertex_buffer is NULL
4409 *****************************************************************************/
4410 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4411 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4413 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4414 struct d3d_vertex_buffer
*object
;
4417 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
4418 iface
, desc
, vertex_buffer
, flags
);
4420 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4422 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4425 TRACE("Created vertex buffer %p.\n", object
);
4426 *vertex_buffer
= &object
->IDirect3DVertexBuffer7_iface
;
4429 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4434 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4435 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4437 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4438 struct d3d_vertex_buffer
*object
;
4441 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n",
4442 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4445 return CLASS_E_NOAGGREGATION
;
4446 if (!vertex_buffer
|| !desc
)
4447 return DDERR_INVALIDPARAMS
;
4449 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4452 TRACE("Created vertex buffer %p.\n", object
);
4453 *vertex_buffer
= (IDirect3DVertexBuffer
*)&object
->IDirect3DVertexBuffer7_iface
;
4456 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4461 /*****************************************************************************
4462 * IDirect3D7::EnumZBufferFormats
4464 * Enumerates all supported Z buffer pixel formats
4470 * callback: callback to call for each pixel format
4471 * context: Pointer to pass back to the callback
4475 * DDERR_INVALIDPARAMS if callback is NULL
4477 *****************************************************************************/
4478 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4479 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4481 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4482 struct wined3d_display_mode mode
;
4483 enum wined3d_device_type type
;
4487 /* Order matters. Specifically, BattleZone II (full version) expects the
4488 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4489 static const enum wined3d_format_id formats
[] =
4491 WINED3DFMT_S1_UINT_D15_UNORM
,
4492 WINED3DFMT_D16_UNORM
,
4493 WINED3DFMT_X8D24_UNORM
,
4494 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4495 WINED3DFMT_D24_UNORM_S8_UINT
,
4496 WINED3DFMT_D32_UNORM
,
4499 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4500 iface
, debugstr_guid(device_iid
), callback
, context
);
4502 if (!callback
) return DDERR_INVALIDPARAMS
;
4504 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4505 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4506 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4508 TRACE("Asked for HAL device.\n");
4509 type
= WINED3D_DEVICE_TYPE_HAL
;
4511 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4512 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4514 TRACE("Asked for SW device.\n");
4515 type
= WINED3D_DEVICE_TYPE_SW
;
4517 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4519 TRACE("Asked for REF device.\n");
4520 type
= WINED3D_DEVICE_TYPE_REF
;
4522 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4524 TRACE("Asked for NULLREF device.\n");
4525 type
= WINED3D_DEVICE_TYPE_NULLREF
;
4529 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4530 type
= WINED3D_DEVICE_TYPE_HAL
;
4533 wined3d_mutex_lock();
4534 /* We need an adapter format from somewhere to please wined3d and WGL.
4535 * Use the current display mode. So far all cards offer the same depth
4536 * stencil format for all modes, but if some do not and applications do
4537 * not like that we'll have to find some workaround, like iterating over
4538 * all imaginable formats and collecting all the depth stencil formats we
4540 if (FAILED(hr
= wined3d_output_get_display_mode(ddraw
->wined3d_output
, &mode
, NULL
)))
4542 ERR("Failed to get display mode, hr %#x.\n", hr
);
4543 wined3d_mutex_unlock();
4547 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
)
4549 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, ddraw
->wined3d_adapter
, type
,
4550 mode
.format_id
, 0, WINED3D_BIND_DEPTH_STENCIL
, WINED3D_RTYPE_TEXTURE_2D
, formats
[i
])))
4552 DDPIXELFORMAT pformat
;
4554 memset(&pformat
, 0, sizeof(pformat
));
4555 pformat
.dwSize
= sizeof(pformat
);
4556 ddrawformat_from_wined3dformat(&pformat
, formats
[i
]);
4558 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
4559 hr
= callback(&pformat
, context
);
4560 if (hr
!= DDENUMRET_OK
)
4562 TRACE("Format enumeration cancelled by application.\n");
4563 wined3d_mutex_unlock();
4569 /* Historically some windows drivers used dwZBufferBitDepth=24 for WINED3DFMT_X8D24_UNORM,
4570 * while others used dwZBufferBitDepth=32. In either case the pitch matches a 32 bits per
4571 * pixel format, so we use dwZBufferBitDepth=32. Some games expect 24. Windows Vista and
4572 * newer enumerate both versions, so we do the same(bug 22434) */
4573 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, ddraw
->wined3d_adapter
, type
, mode
.format_id
,
4574 0, WINED3D_BIND_DEPTH_STENCIL
, WINED3D_RTYPE_TEXTURE_2D
, WINED3DFMT_X8D24_UNORM
)))
4576 DDPIXELFORMAT x8d24
=
4578 sizeof(x8d24
), DDPF_ZBUFFER
, 0,
4579 {24}, {0x00000000}, {0x00ffffff}, {0x00000000}
4581 TRACE("Enumerating WINED3DFMT_X8D24_UNORM, dwZBufferBitDepth=24 version\n");
4582 callback(&x8d24
, context
);
4585 TRACE("End of enumeration.\n");
4587 wined3d_mutex_unlock();
4592 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
4593 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4595 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4597 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4598 iface
, debugstr_guid(device_iid
), callback
, context
);
4600 return d3d7_EnumZBufferFormats(&ddraw
->IDirect3D7_iface
, device_iid
, callback
, context
);
4603 /*****************************************************************************
4604 * IDirect3D7::EvictManagedTextures
4606 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
4607 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
4612 * D3D_OK, because it's a stub
4614 *****************************************************************************/
4615 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
4617 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4619 TRACE("iface %p!\n", iface
);
4621 wined3d_mutex_lock();
4622 if (ddraw
->flags
& DDRAW_D3D_INITIALIZED
)
4623 wined3d_device_evict_managed_resources(ddraw
->wined3d_device
);
4624 wined3d_mutex_unlock();
4629 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
4631 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4633 TRACE("iface %p.\n", iface
);
4635 return d3d7_EvictManagedTextures(&ddraw
->IDirect3D7_iface
);
4638 /*****************************************************************************
4639 * IDirectDraw7 VTable
4640 *****************************************************************************/
4641 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
4644 ddraw7_QueryInterface
,
4649 ddraw7_CreateClipper
,
4650 ddraw7_CreatePalette
,
4651 ddraw7_CreateSurface
,
4652 ddraw7_DuplicateSurface
,
4653 ddraw7_EnumDisplayModes
,
4654 ddraw7_EnumSurfaces
,
4655 ddraw7_FlipToGDISurface
,
4657 ddraw7_GetDisplayMode
,
4658 ddraw7_GetFourCCCodes
,
4659 ddraw7_GetGDISurface
,
4660 ddraw7_GetMonitorFrequency
,
4662 ddraw7_GetVerticalBlankStatus
,
4664 ddraw7_RestoreDisplayMode
,
4665 ddraw7_SetCooperativeLevel
,
4666 ddraw7_SetDisplayMode
,
4667 ddraw7_WaitForVerticalBlank
,
4669 ddraw7_GetAvailableVidMem
,
4671 ddraw7_GetSurfaceFromDC
,
4673 ddraw7_RestoreAllSurfaces
,
4674 ddraw7_TestCooperativeLevel
,
4675 ddraw7_GetDeviceIdentifier
,
4677 ddraw7_StartModeTest
,
4681 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
4684 ddraw4_QueryInterface
,
4689 ddraw4_CreateClipper
,
4690 ddraw4_CreatePalette
,
4691 ddraw4_CreateSurface
,
4692 ddraw4_DuplicateSurface
,
4693 ddraw4_EnumDisplayModes
,
4694 ddraw4_EnumSurfaces
,
4695 ddraw4_FlipToGDISurface
,
4697 ddraw4_GetDisplayMode
,
4698 ddraw4_GetFourCCCodes
,
4699 ddraw4_GetGDISurface
,
4700 ddraw4_GetMonitorFrequency
,
4702 ddraw4_GetVerticalBlankStatus
,
4704 ddraw4_RestoreDisplayMode
,
4705 ddraw4_SetCooperativeLevel
,
4706 ddraw4_SetDisplayMode
,
4707 ddraw4_WaitForVerticalBlank
,
4709 ddraw4_GetAvailableVidMem
,
4711 ddraw4_GetSurfaceFromDC
,
4713 ddraw4_RestoreAllSurfaces
,
4714 ddraw4_TestCooperativeLevel
,
4715 ddraw4_GetDeviceIdentifier
,
4718 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
4721 ddraw2_QueryInterface
,
4726 ddraw2_CreateClipper
,
4727 ddraw2_CreatePalette
,
4728 ddraw2_CreateSurface
,
4729 ddraw2_DuplicateSurface
,
4730 ddraw2_EnumDisplayModes
,
4731 ddraw2_EnumSurfaces
,
4732 ddraw2_FlipToGDISurface
,
4734 ddraw2_GetDisplayMode
,
4735 ddraw2_GetFourCCCodes
,
4736 ddraw2_GetGDISurface
,
4737 ddraw2_GetMonitorFrequency
,
4739 ddraw2_GetVerticalBlankStatus
,
4741 ddraw2_RestoreDisplayMode
,
4742 ddraw2_SetCooperativeLevel
,
4743 ddraw2_SetDisplayMode
,
4744 ddraw2_WaitForVerticalBlank
,
4746 ddraw2_GetAvailableVidMem
,
4749 /* Bad Mojo Redux expects this vtbl to be writable. */
4750 static struct IDirectDrawVtbl ddraw1_vtbl
=
4753 ddraw1_QueryInterface
,
4758 ddraw1_CreateClipper
,
4759 ddraw1_CreatePalette
,
4760 ddraw1_CreateSurface
,
4761 ddraw1_DuplicateSurface
,
4762 ddraw1_EnumDisplayModes
,
4763 ddraw1_EnumSurfaces
,
4764 ddraw1_FlipToGDISurface
,
4766 ddraw1_GetDisplayMode
,
4767 ddraw1_GetFourCCCodes
,
4768 ddraw1_GetGDISurface
,
4769 ddraw1_GetMonitorFrequency
,
4771 ddraw1_GetVerticalBlankStatus
,
4773 ddraw1_RestoreDisplayMode
,
4774 ddraw1_SetCooperativeLevel
,
4775 ddraw1_SetDisplayMode
,
4776 ddraw1_WaitForVerticalBlank
,
4779 static const struct IDirect3D7Vtbl d3d7_vtbl
=
4781 /* IUnknown methods */
4782 d3d7_QueryInterface
,
4785 /* IDirect3D7 methods */
4788 d3d7_CreateVertexBuffer
,
4789 d3d7_EnumZBufferFormats
,
4790 d3d7_EvictManagedTextures
4793 static const struct IDirect3D3Vtbl d3d3_vtbl
=
4795 /* IUnknown methods */
4796 d3d3_QueryInterface
,
4799 /* IDirect3D3 methods */
4802 d3d3_CreateMaterial
,
4803 d3d3_CreateViewport
,
4806 d3d3_CreateVertexBuffer
,
4807 d3d3_EnumZBufferFormats
,
4808 d3d3_EvictManagedTextures
4811 static const struct IDirect3D2Vtbl d3d2_vtbl
=
4813 /* IUnknown methods */
4814 d3d2_QueryInterface
,
4817 /* IDirect3D2 methods */
4820 d3d2_CreateMaterial
,
4821 d3d2_CreateViewport
,
4826 static const struct IDirect3DVtbl d3d1_vtbl
=
4828 /* IUnknown methods */
4829 d3d1_QueryInterface
,
4832 /* IDirect3D methods */
4836 d3d1_CreateMaterial
,
4837 d3d1_CreateViewport
,
4841 /*****************************************************************************
4844 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
4845 * if none was found.
4847 * This function is in ddraw.c and the DDraw object space because D3D7
4848 * vertex buffers are created using the IDirect3D interface to the ddraw
4849 * object, so they can be valid across D3D devices(theoretically. The ddraw
4850 * object also owns the wined3d device
4854 * fvf: Fvf to find the decl for
4857 * NULL in case of an error, the vertex declaration for the FVF otherwise.
4859 *****************************************************************************/
4860 struct wined3d_vertex_declaration
*ddraw_find_decl(struct ddraw
*This
, DWORD fvf
)
4862 struct wined3d_vertex_declaration
*pDecl
= NULL
;
4864 int p
, low
, high
; /* deliberately signed */
4865 struct FvfToDecl
*convertedDecls
= This
->decls
;
4867 TRACE("Searching for declaration for fvf %08x... ", fvf
);
4870 high
= This
->numConvertedDecls
- 1;
4871 while(low
<= high
) {
4872 p
= (low
+ high
) >> 1;
4874 if(convertedDecls
[p
].fvf
== fvf
) {
4875 TRACE("found %p\n", convertedDecls
[p
].decl
);
4876 return convertedDecls
[p
].decl
;
4877 } else if(convertedDecls
[p
].fvf
< fvf
) {
4883 TRACE("not found. Creating and inserting at position %d.\n", low
);
4885 hr
= wined3d_vertex_declaration_create_from_fvf(This
->wined3d_device
,
4886 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
4887 if (hr
!= S_OK
) return NULL
;
4889 if (This
->declArraySize
== This
->numConvertedDecls
)
4891 unsigned int grow
= max(This
->declArraySize
/ 2, 8);
4893 if (!(convertedDecls
= heap_realloc(convertedDecls
,
4894 (This
->numConvertedDecls
+ grow
) * sizeof(*convertedDecls
))))
4896 wined3d_vertex_declaration_decref(pDecl
);
4899 This
->decls
= convertedDecls
;
4900 This
->declArraySize
+= grow
;
4903 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
4904 convertedDecls
[low
].decl
= pDecl
;
4905 convertedDecls
[low
].fvf
= fvf
;
4906 This
->numConvertedDecls
++;
4908 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
4912 static inline struct ddraw
*ddraw_from_device_parent(struct wined3d_device_parent
*device_parent
)
4914 return CONTAINING_RECORD(device_parent
, struct ddraw
, device_parent
);
4917 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
4918 struct wined3d_device
*device
)
4920 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
4923 /* This is run from device_process_message() in wined3d, we can't take the
4925 /* FIXME: We only get mode change notifications in exclusive mode, but we
4926 * should mark surfaces as lost on mode changes in DDSCL_NORMAL mode as well. */
4927 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
4929 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4930 struct wined3d_output_desc output_desc
;
4933 TRACE("device_parent %p.\n", device_parent
);
4935 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) || !ddraw
->swapchain_window
)
4937 TRACE("Nothing to resize.\n");
4941 if (FAILED(wined3d_output_get_desc(ddraw
->wined3d_output
, &output_desc
)))
4943 ERR("Failed to get output description.\n");
4947 r
= &output_desc
.desktop_rect
;
4948 TRACE("Resizing window %p to %s.\n", ddraw
->swapchain_window
, wine_dbgstr_rect(r
));
4950 if (!SetWindowPos(ddraw
->swapchain_window
, HWND_TOP
, r
->left
, r
->top
,
4951 r
->right
- r
->left
, r
->bottom
- r
->top
, SWP_SHOWWINDOW
| SWP_NOACTIVATE
))
4952 ERR("Failed to resize window.\n");
4954 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_OK
);
4957 static void CDECL
device_parent_activate(struct wined3d_device_parent
*device_parent
, BOOL activate
)
4959 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4961 TRACE("device_parent %p, activate %#x.\n", device_parent
, activate
);
4965 ddraw
->device_state
= DDRAW_DEVICE_STATE_LOST
;
4966 exclusive_window
= NULL
;
4970 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_LOST
);
4974 void ddraw_update_lost_surfaces(struct ddraw
*ddraw
)
4976 struct ddraw_surface
*surface
;
4978 /* Railroad Tycoon 2 tries to restore surfaces from within a
4979 * WM_QUERYNEWPALETTE message handler and expects it to succeed. We
4980 * haven't received the WM_ACTIVATEAPP message by that point, so the
4981 * device state is still DDRAW_DEVICE_STATE_LOST, even though we are in
4982 * the foreground. */
4983 if (ddraw
->device_state
== DDRAW_DEVICE_STATE_LOST
)
4985 HWND window
= ddraw
->focuswindow
? ddraw
->focuswindow
: ddraw
->dest_window
;
4987 if (window
&& GetForegroundWindow() == window
)
4988 ddraw
->device_state
= DDRAW_DEVICE_STATE_NOT_RESTORED
;
4991 if (ddraw
->device_state
!= DDRAW_DEVICE_STATE_NOT_RESTORED
)
4994 LIST_FOR_EACH_ENTRY(surface
, &ddraw
->surface_list
, struct ddraw_surface
, surface_list_entry
)
4996 surface
->is_lost
= ddraw_surface_can_be_lost(surface
);
4998 ddraw
->device_state
= DDRAW_DEVICE_STATE_OK
;
5001 static HRESULT CDECL
device_parent_texture_sub_resource_created(struct wined3d_device_parent
*device_parent
,
5002 enum wined3d_resource_type type
, struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
5003 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
5005 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
5006 struct ddraw_surface
*ddraw_surface
;
5008 TRACE("device_parent %p, type %#x, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
5009 device_parent
, type
, wined3d_texture
, sub_resource_idx
, parent
, parent_ops
);
5011 /* We have a swapchain or wined3d internal texture. */
5012 if (type
!= WINED3D_RTYPE_TEXTURE_2D
|| !wined3d_texture_get_parent(wined3d_texture
)
5013 || wined3d_texture_get_parent(wined3d_texture
) == ddraw
)
5016 *parent_ops
= &ddraw_null_wined3d_parent_ops
;
5021 if (!(ddraw_surface
= heap_alloc_zero(sizeof(*ddraw_surface
))))
5023 ERR("Failed to allocate surface memory.\n");
5024 return DDERR_OUTOFVIDEOMEMORY
;
5027 ddraw_surface_init(ddraw_surface
, ddraw
, wined3d_texture
, sub_resource_idx
, parent_ops
);
5028 *parent
= ddraw_surface
;
5030 ddraw_update_lost_surfaces(ddraw
);
5031 list_add_head(&ddraw
->surface_list
, &ddraw_surface
->surface_list_entry
);
5033 TRACE("Created ddraw surface %p.\n", ddraw_surface
);
5038 static void STDMETHODCALLTYPE
ddraw_frontbuffer_destroyed(void *parent
)
5040 struct ddraw
*ddraw
= parent
;
5041 ddraw
->wined3d_frontbuffer
= NULL
;
5044 static const struct wined3d_parent_ops ddraw_frontbuffer_parent_ops
=
5046 ddraw_frontbuffer_destroyed
,
5049 static HRESULT CDECL
device_parent_create_swapchain_texture(struct wined3d_device_parent
*device_parent
,
5050 void *container_parent
, const struct wined3d_resource_desc
*desc
, DWORD texture_flags
,
5051 struct wined3d_texture
**texture
)
5053 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
5054 const struct wined3d_parent_ops
*parent_ops
;
5057 TRACE("device_parent %p, container_parent %p, desc %p, texture flags %#x, texture %p.\n",
5058 device_parent
, container_parent
, desc
, texture_flags
, texture
);
5060 if (!ddraw
->wined3d_frontbuffer
)
5061 parent_ops
= &ddraw_frontbuffer_parent_ops
;
5063 parent_ops
= &ddraw_null_wined3d_parent_ops
;
5065 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, desc
, 1, 1,
5066 texture_flags
, NULL
, ddraw
, parent_ops
, texture
)))
5068 WARN("Failed to create texture, hr %#x.\n", hr
);
5072 if (!ddraw
->wined3d_frontbuffer
)
5073 ddraw
->wined3d_frontbuffer
= *texture
;
5078 static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops
=
5080 device_parent_wined3d_device_created
,
5081 device_parent_mode_changed
,
5082 device_parent_activate
,
5083 device_parent_texture_sub_resource_created
,
5084 device_parent_create_swapchain_texture
,
5087 HRESULT
ddraw_init(struct ddraw
*ddraw
, DWORD flags
, enum wined3d_device_type device_type
)
5089 struct wined3d_caps caps
;
5092 static const enum wined3d_feature_level feature_levels
[] =
5094 WINED3D_FEATURE_LEVEL_7
,
5095 WINED3D_FEATURE_LEVEL_6
,
5096 WINED3D_FEATURE_LEVEL_5
,
5099 ddraw
->IDirectDraw7_iface
.lpVtbl
= &ddraw7_vtbl
;
5100 ddraw
->IDirectDraw_iface
.lpVtbl
= &ddraw1_vtbl
;
5101 ddraw
->IDirectDraw2_iface
.lpVtbl
= &ddraw2_vtbl
;
5102 ddraw
->IDirectDraw4_iface
.lpVtbl
= &ddraw4_vtbl
;
5103 ddraw
->IDirect3D_iface
.lpVtbl
= &d3d1_vtbl
;
5104 ddraw
->IDirect3D2_iface
.lpVtbl
= &d3d2_vtbl
;
5105 ddraw
->IDirect3D3_iface
.lpVtbl
= &d3d3_vtbl
;
5106 ddraw
->IDirect3D7_iface
.lpVtbl
= &d3d7_vtbl
;
5107 ddraw
->device_parent
.ops
= &ddraw_wined3d_device_parent_ops
;
5108 ddraw
->numIfaces
= 1;
5111 flags
|= DDRAW_WINED3D_FLAGS
;
5112 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
5114 flags
|= WINED3D_NO3D
;
5115 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
5117 WARN("Failed to create a wined3d object.\n");
5122 if (!(ddraw
->wined3d_adapter
= wined3d_get_adapter(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
)))
5124 WARN("Failed to get the default wined3d adapter.\n");
5125 wined3d_decref(ddraw
->wined3d
);
5129 if (!(ddraw
->wined3d_output
= wined3d_adapter_get_output(ddraw
->wined3d_adapter
, 0)))
5131 WARN("Failed to get the default wined3d output.\n");
5132 wined3d_decref(ddraw
->wined3d
);
5136 if (FAILED(hr
= wined3d_get_device_caps(ddraw
->wined3d_adapter
, device_type
, &caps
)))
5138 ERR("Failed to get device caps, hr %#x.\n", hr
);
5139 wined3d_decref(ddraw
->wined3d
);
5143 if (!(caps
.ddraw_caps
.caps
& WINEDDCAPS_3D
))
5145 WARN("Created a wined3d object without 3D support.\n");
5146 ddraw
->flags
|= DDRAW_NO3D
;
5149 if (FAILED(hr
= wined3d_device_create(ddraw
->wined3d
, ddraw
->wined3d_adapter
, device_type
,
5150 NULL
, 0, DDRAW_STRIDE_ALIGNMENT
, feature_levels
, ARRAY_SIZE(feature_levels
),
5151 &ddraw
->device_parent
, &ddraw
->wined3d_device
)))
5153 WARN("Failed to create a wined3d device, hr %#x.\n", hr
);
5154 wined3d_decref(ddraw
->wined3d
);
5158 list_init(&ddraw
->surface_list
);
5160 if (FAILED(hr
= wined3d_stateblock_create(ddraw
->wined3d_device
, NULL
, WINED3D_SBT_PRIMARY
, &ddraw
->state
)))
5162 ERR("Failed to create the primary stateblock, hr %#x.\n", hr
);
5163 wined3d_device_decref(ddraw
->wined3d_device
);
5164 wined3d_decref(ddraw
->wined3d
);
5167 ddraw
->stateblock_state
= wined3d_stateblock_get_state(ddraw
->state
);