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_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
561 ERR("Failed to get display mode.\n");
565 memset(&swapchain_desc
, 0, sizeof(swapchain_desc
));
566 swapchain_desc
.backbuffer_width
= mode
.width
;
567 swapchain_desc
.backbuffer_height
= mode
.height
;
568 swapchain_desc
.backbuffer_format
= mode
.format_id
;
569 swapchain_desc
.backbuffer_bind_flags
= 0;
570 swapchain_desc
.backbuffer_count
= 1;
571 swapchain_desc
.swap_effect
= WINED3D_SWAP_EFFECT_DISCARD
;
572 swapchain_desc
.device_window
= window
;
573 swapchain_desc
.windowed
= windowed
;
574 swapchain_desc
.flags
= WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH
| WINED3D_SWAPCHAIN_IMPLICIT
;
576 if (ddraw
->flags
& DDRAW_NO3D
)
577 return wined3d_swapchain_create(ddraw
->wined3d_device
, &swapchain_desc
,
578 NULL
, &ddraw_null_wined3d_parent_ops
, wined3d_swapchain
);
580 if (!window
|| window
== GetDesktopWindow())
582 window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "Hidden D3D Window",
583 WS_DISABLED
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
584 NULL
, NULL
, NULL
, NULL
);
587 ERR("Failed to create window, last error %#x.\n", GetLastError());
591 ShowWindow(window
, SW_HIDE
); /* Just to be sure */
592 WARN("No window for the Direct3DDevice, created hidden window %p.\n", window
);
594 swapchain_desc
.device_window
= window
;
598 TRACE("Using existing window %p for Direct3D rendering.\n", window
);
600 ddraw
->d3d_window
= window
;
602 /* Set this NOW, otherwise creating the depth stencil surface will cause a
603 * recursive loop until ram or emulated video memory is full. */
604 ddraw
->flags
|= DDRAW_D3D_INITIALIZED
;
605 if (FAILED(hr
= wined3d_swapchain_create(ddraw
->wined3d_device
, &swapchain_desc
,
606 NULL
, &ddraw_null_wined3d_parent_ops
, wined3d_swapchain
)))
608 ddraw
->flags
&= ~DDRAW_D3D_INITIALIZED
;
609 DestroyWindow(window
);
610 ddraw
->d3d_window
= NULL
;
614 ddraw
->declArraySize
= 2;
615 if (!(ddraw
->decls
= heap_alloc_zero(ddraw
->declArraySize
* sizeof(*ddraw
->decls
))))
617 ERR("Error allocating an array for the converted vertex decls.\n");
618 ddraw
->declArraySize
= 0;
619 wined3d_swapchain_decref(*wined3d_swapchain
);
620 DestroyWindow(window
);
621 ddraw
->d3d_window
= NULL
;
622 return E_OUTOFMEMORY
;
625 TRACE("Successfully initialized 3D.\n");
630 static HRESULT
ddraw_create_swapchain(struct ddraw
*ddraw
, HWND window
, BOOL windowed
)
634 if (ddraw
->wined3d_swapchain
)
636 ERR("Swapchain already created.\n");
640 if (FAILED(hr
= ddraw_attach_d3d_device(ddraw
, window
, windowed
, &ddraw
->wined3d_swapchain
)))
642 ERR("Failed to create swapchain, hr %#x.\n", hr
);
645 wined3d_swapchain_incref(ddraw
->wined3d_swapchain
);
647 ddraw_set_swapchain_window(ddraw
, window
);
649 if (ddraw
->primary
&& ddraw
->primary
->palette
)
650 wined3d_swapchain_set_palette(ddraw
->wined3d_swapchain
, ddraw
->primary
->palette
->wined3d_palette
);
655 /*****************************************************************************
656 * IDirectDraw7::RestoreDisplayMode
658 * Restores the display mode to what it was at creation time. Basically.
662 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
664 *****************************************************************************/
665 static HRESULT WINAPI
ddraw7_RestoreDisplayMode(IDirectDraw7
*iface
)
667 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
670 TRACE("iface %p.\n", iface
);
672 wined3d_mutex_lock();
674 if (!(ddraw
->flags
& DDRAW_RESTORE_MODE
))
676 wined3d_mutex_unlock();
680 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
682 wined3d_mutex_unlock();
683 return DDERR_NOEXCLUSIVEMODE
;
686 if (SUCCEEDED(hr
= wined3d_output_set_display_mode(ddraw
->wined3d_output
, NULL
)))
687 ddraw
->flags
&= ~DDRAW_RESTORE_MODE
;
689 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_OK
);
691 wined3d_mutex_unlock();
696 static HRESULT WINAPI
ddraw4_RestoreDisplayMode(IDirectDraw4
*iface
)
698 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
700 TRACE("iface %p.\n", iface
);
702 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
705 static HRESULT WINAPI
ddraw2_RestoreDisplayMode(IDirectDraw2
*iface
)
707 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
709 TRACE("iface %p.\n", iface
);
711 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
714 static HRESULT WINAPI
ddraw1_RestoreDisplayMode(IDirectDraw
*iface
)
716 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
718 TRACE("iface %p.\n", iface
);
720 return ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
723 /*****************************************************************************
724 * IDirectDraw7::SetCooperativeLevel
726 * Sets the cooperative level for the DirectDraw object, and the window
727 * assigned to it. The cooperative level determines the general behavior
728 * of the DirectDraw application
730 * Warning: This is quite tricky, as it's not really documented which
731 * cooperative levels can be combined with each other. If a game fails
732 * after this function, try to check the cooperative levels passed on
733 * Windows, and if it returns something different.
735 * If you think that this function caused the failure because it writes a
736 * fixme, be sure to run again with a +ddraw trace.
738 * What is known about cooperative levels (See the ddraw modes test):
739 * DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN.
740 * DDSCL_NORMAL is not compatible with DDSCL_EXCLUSIVE.
741 * Unlike what msdn claims, DDSCL_NORMAL | DDSCL_FULLSCREEN is allowed.
742 * DDSCL_SETFOCUSWINDOW can be passed only in DDSCL_NORMAL mode, but after that
743 * DDSCL_EXCLUSIVE can be activated.
744 * DDSCL_SETFOCUSWINDOW may only be used with DDSCL_NOWINDOWCHANGES or
745 * DDSCL_CREATEDEVICEWINDOW.
747 * Handled flags: DDSCL_NORMAL, DDSCL_FULLSCREEN, DDSCL_EXCLUSIVE,
748 * DDSCL_CREATEDEVICEWINDOW, DDSCL_SETDEVICEWINDOW
749 * DDSCL_SETFOCUSWINDOW (partially),
750 * DDSCL_MULTITHREADED (work in progress)
751 * DDSCL_FPUPRESERVE (see device.c)
753 * Unsure about this: DDSCL_FPUSETUP
755 * These don't seem very important for wine:
756 * DDSCL_ALLOWREBOOT, DDSCL_NOWINDOWCHANGES, DDSCL_ALLOWMODEX
759 * DD_OK if the cooperative level was set successfully
760 * DDERR_INVALIDPARAMS if the passed cooperative level combination is invalid
761 * DDERR_HWNDALREADYSET if DDSCL_SETFOCUSWINDOW is passed in exclusive mode
762 * (Probably others too, have to investigate)
764 *****************************************************************************/
765 static HRESULT
ddraw_set_cooperative_level(struct ddraw
*ddraw
, HWND window
,
766 DWORD cooplevel
, BOOL restore_mode_on_normal
)
768 struct wined3d_rendertarget_view
*rtv
= NULL
, *dsv
= NULL
;
769 struct wined3d_stateblock
*stateblock
;
770 BOOL restore_state
= FALSE
;
773 TRACE("ddraw %p, window %p, flags %#x, restore_mode_on_normal %x.\n", ddraw
, window
, cooplevel
,
774 restore_mode_on_normal
);
775 DDRAW_dump_cooperativelevel(cooplevel
);
777 wined3d_mutex_lock();
779 if (ddraw
->flags
& DDRAW_SCL_RECURSIVE
)
781 WARN("Recursive call, returning DD_OK.\n");
785 ddraw
->flags
|= DDRAW_SCL_RECURSIVE
;
787 /* Tests suggest that we need one of them: */
788 if(!(cooplevel
& (DDSCL_SETFOCUSWINDOW
|
792 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
793 hr
= DDERR_INVALIDPARAMS
;
797 if ((cooplevel
& DDSCL_CREATEDEVICEWINDOW
) && !(cooplevel
& DDSCL_EXCLUSIVE
))
799 WARN("DDSCL_CREATEDEVICEWINDOW requires DDSCL_EXCLUSIVE.\n");
800 hr
= DDERR_INVALIDPARAMS
;
804 /* Handle those levels first which set various hwnds */
805 if ((cooplevel
& DDSCL_SETFOCUSWINDOW
) && !(cooplevel
& DDSCL_CREATEDEVICEWINDOW
))
807 /* This isn't compatible with a lot of flags */
808 if (cooplevel
& (DDSCL_MULTITHREADED
813 | DDSCL_SETDEVICEWINDOW
818 WARN("Called with incompatible flags, returning DDERR_INVALIDPARAMS.\n");
819 hr
= DDERR_INVALIDPARAMS
;
823 hr
= ddraw_set_focus_window(ddraw
, window
);
827 if (cooplevel
& DDSCL_EXCLUSIVE
)
829 if (!(cooplevel
& DDSCL_FULLSCREEN
) || !(window
|| (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)))
831 WARN("DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN and a window.\n");
832 hr
= DDERR_INVALIDPARAMS
;
836 if (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)
840 if (!ddraw
->focuswindow
&& !(cooplevel
& DDSCL_SETFOCUSWINDOW
))
842 WARN("No focus window set.\n");
843 hr
= DDERR_NOFOCUSWINDOW
;
847 device_window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "DirectDrawDeviceWnd",
848 WS_POPUP
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
849 NULL
, NULL
, NULL
, NULL
);
852 ERR("Failed to create window, last error %#x.\n", GetLastError());
857 ShowWindow(device_window
, SW_SHOW
);
858 TRACE("Created a device window %p.\n", device_window
);
860 /* Native apparently leaks the created device window if setting the
861 * focus window below fails. */
862 ddraw
->cooperative_level
|= DDSCL_CREATEDEVICEWINDOW
;
863 ddraw
->devicewindow
= device_window
;
865 if (cooplevel
& DDSCL_SETFOCUSWINDOW
)
873 if (FAILED(hr
= ddraw_set_focus_window(ddraw
, window
)))
877 window
= device_window
;
882 if (ddraw
->cooperative_level
& DDSCL_CREATEDEVICEWINDOW
)
883 DestroyWindow(ddraw
->devicewindow
);
884 ddraw
->devicewindow
= NULL
;
885 ddraw
->focuswindow
= NULL
;
888 if ((cooplevel
& DDSCL_EXCLUSIVE
) && exclusive_window
!= window
)
890 ddraw
->device_state
= DDRAW_DEVICE_STATE_NOT_RESTORED
;
891 exclusive_window
= window
;
894 if (cooplevel
& DDSCL_MULTITHREADED
&& !(ddraw
->cooperative_level
& DDSCL_MULTITHREADED
))
895 wined3d_device_set_multithreaded(ddraw
->wined3d_device
);
897 if (ddraw
->wined3d_swapchain
)
899 if (!(ddraw
->flags
& DDRAW_NO3D
))
901 restore_state
= TRUE
;
903 if (FAILED(hr
= wined3d_stateblock_create(ddraw
->wined3d_device
,
904 ddraw
->state
, WINED3D_SBT_ALL
, &stateblock
)))
906 ERR("Failed to create stateblock, hr %#x.\n", hr
);
910 rtv
= wined3d_device_get_rendertarget_view(ddraw
->wined3d_device
, 0);
911 /* Rendering to ddraw->wined3d_frontbuffer. */
912 if (rtv
&& !wined3d_rendertarget_view_get_sub_resource_parent(rtv
))
915 wined3d_rendertarget_view_incref(rtv
);
917 if ((dsv
= wined3d_device_get_depth_stencil_view(ddraw
->wined3d_device
)))
918 wined3d_rendertarget_view_incref(dsv
);
921 ddraw_destroy_swapchain(ddraw
);
924 if (FAILED(hr
= ddraw_create_swapchain(ddraw
, window
, !(cooplevel
& DDSCL_FULLSCREEN
))))
925 ERR("Failed to create swapchain, hr %#x.\n", hr
);
931 wined3d_device_set_depth_stencil_view(ddraw
->wined3d_device
, dsv
);
932 wined3d_rendertarget_view_decref(dsv
);
937 wined3d_device_set_rendertarget_view(ddraw
->wined3d_device
, 0, rtv
, FALSE
);
938 wined3d_rendertarget_view_decref(rtv
);
941 wined3d_stateblock_apply(stateblock
, ddraw
->state
);
942 wined3d_stateblock_decref(stateblock
);
945 if (!(cooplevel
& DDSCL_EXCLUSIVE
) && (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
946 && restore_mode_on_normal
)
948 hr
= ddraw7_RestoreDisplayMode(&ddraw
->IDirectDraw7_iface
);
950 ERR("RestoreDisplayMode failed\n");
953 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
954 && (window
!= ddraw
->dest_window
|| !(cooplevel
& DDSCL_EXCLUSIVE
)))
955 wined3d_device_release_focus_window(ddraw
->wined3d_device
);
957 if ((cooplevel
& DDSCL_EXCLUSIVE
)
958 && (window
!= ddraw
->dest_window
|| !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)))
960 hr
= wined3d_device_acquire_focus_window(ddraw
->wined3d_device
, window
);
963 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
968 /* Unhandled flags */
969 if (cooplevel
& DDSCL_ALLOWREBOOT
)
970 WARN("Unhandled flag DDSCL_ALLOWREBOOT, harmless\n");
971 if (cooplevel
& DDSCL_ALLOWMODEX
)
972 WARN("Unhandled flag DDSCL_ALLOWMODEX, harmless\n");
973 if (cooplevel
& DDSCL_FPUSETUP
)
974 WARN("Unhandled flag DDSCL_FPUSETUP, harmless\n");
976 if (cooplevel
& DDSCL_EXCLUSIVE
)
977 exclusive_ddraw
= ddraw
;
978 else if (exclusive_ddraw
== ddraw
)
979 exclusive_ddraw
= NULL
;
981 /* Store the cooperative_level */
982 ddraw
->cooperative_level
= cooplevel
;
983 ddraw
->dest_window
= window
;
985 TRACE("SetCooperativeLevel returning DD_OK\n");
988 ddraw
->flags
&= ~DDRAW_SCL_RECURSIVE
;
989 wined3d_mutex_unlock();
994 static HRESULT WINAPI
ddraw7_SetCooperativeLevel(IDirectDraw7
*iface
, HWND window
, DWORD flags
)
996 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
998 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1000 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1003 static HRESULT WINAPI
ddraw4_SetCooperativeLevel(IDirectDraw4
*iface
, HWND window
, DWORD flags
)
1005 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1007 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1009 return ddraw_set_cooperative_level(ddraw
, window
, flags
, !(ddraw
->flags
& DDRAW_SCL_DDRAW1
));
1012 static HRESULT WINAPI
ddraw2_SetCooperativeLevel(IDirectDraw2
*iface
, HWND window
, DWORD flags
)
1014 struct ddraw
*ddraw
= impl_from_IDirectDraw2(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
ddraw1_SetCooperativeLevel(IDirectDraw
*iface
, HWND window
, DWORD flags
)
1023 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1026 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1028 hr
= ddraw_set_cooperative_level(ddraw
, window
, flags
, FALSE
);
1030 ddraw
->flags
|= DDRAW_SCL_DDRAW1
;
1034 /*****************************************************************************
1035 * IDirectDraw7::SetDisplayMode
1037 * Sets the display screen resolution, color depth and refresh frequency
1038 * when in fullscreen mode (in theory).
1039 * Possible return values listed in the SDK suggest that this method fails
1040 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
1041 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
1042 * It seems to be valid to pass 0 for With and Height, this has to be tested
1043 * It could mean that the current video mode should be left as-is. (But why
1047 * Height, Width: Screen dimension
1048 * BPP: Color depth in Bits per pixel
1049 * Refreshrate: Screen refresh rate
1050 * Flags: Other stuff
1055 *****************************************************************************/
1056 static HRESULT WINAPI
ddraw7_SetDisplayMode(IDirectDraw7
*iface
, DWORD width
, DWORD height
,
1057 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1059 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1060 struct wined3d_display_mode mode
;
1061 enum wined3d_format_id format
;
1064 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1065 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1067 if (force_refresh_rate
!= 0)
1069 TRACE("ForceRefreshRate overriding passed-in refresh rate (%u Hz) to %u Hz\n",
1070 refresh_rate
, force_refresh_rate
);
1071 refresh_rate
= force_refresh_rate
;
1074 wined3d_mutex_lock();
1076 if (exclusive_ddraw
&& exclusive_ddraw
!= ddraw
)
1078 wined3d_mutex_unlock();
1079 return DDERR_NOEXCLUSIVEMODE
;
1082 if (!width
|| !height
)
1084 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here. */
1085 wined3d_mutex_unlock();
1091 case 8: format
= WINED3DFMT_P8_UINT
; break;
1092 case 15: format
= WINED3DFMT_B5G5R5X1_UNORM
; break;
1093 case 16: format
= WINED3DFMT_B5G6R5_UNORM
; break;
1094 case 24: format
= WINED3DFMT_B8G8R8_UNORM
; break;
1095 case 32: format
= WINED3DFMT_B8G8R8X8_UNORM
; break;
1096 default: format
= WINED3DFMT_UNKNOWN
; break;
1100 mode
.height
= height
;
1101 mode
.refresh_rate
= refresh_rate
;
1102 mode
.format_id
= format
;
1103 mode
.scanline_ordering
= WINED3D_SCANLINE_ORDERING_UNKNOWN
;
1105 /* TODO: The possible return values from msdn suggest that the screen mode
1106 * can't be changed if a surface is locked or some drawing is in progress. */
1107 if (SUCCEEDED(hr
= wined3d_output_set_display_mode(ddraw
->wined3d_output
, &mode
)))
1111 DDSURFACEDESC2
*surface_desc
= &ddraw
->primary
->surface_desc
;
1113 if (FAILED(hr
= wined3d_swapchain_resize_buffers(ddraw
->wined3d_swapchain
, 0,
1114 surface_desc
->dwWidth
, surface_desc
->dwHeight
, mode
.format_id
, WINED3D_MULTISAMPLE_NONE
, 0)))
1115 ERR("Failed to resize buffers, hr %#x.\n", hr
);
1117 ddrawformat_from_wined3dformat(&ddraw
->primary
->surface_desc
.u4
.ddpfPixelFormat
, mode
.format_id
);
1119 ddraw
->flags
|= DDRAW_RESTORE_MODE
;
1122 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_OK
);
1124 wined3d_mutex_unlock();
1128 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1133 static HRESULT WINAPI
ddraw4_SetDisplayMode(IDirectDraw4
*iface
, DWORD width
, DWORD height
,
1134 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1136 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1138 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1139 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1141 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1144 static HRESULT WINAPI
ddraw2_SetDisplayMode(IDirectDraw2
*iface
,
1145 DWORD width
, DWORD height
, DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1147 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1149 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1150 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1152 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1155 static HRESULT WINAPI
ddraw1_SetDisplayMode(IDirectDraw
*iface
, DWORD width
, DWORD height
, DWORD bpp
)
1157 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1159 TRACE("iface %p, width %u, height %u, bpp %u.\n", iface
, width
, height
, bpp
);
1161 return ddraw7_SetDisplayMode(&ddraw
->IDirectDraw7_iface
, width
, height
, bpp
, 0, 0);
1164 void ddraw_d3dcaps1_from_7(D3DDEVICEDESC
*caps1
, D3DDEVICEDESC7
*caps7
)
1166 memset(caps1
, 0, sizeof(*caps1
));
1167 caps1
->dwSize
= sizeof(*caps1
);
1168 caps1
->dwFlags
= D3DDD_COLORMODEL
1170 | D3DDD_TRANSFORMCAPS
1172 | D3DDD_LIGHTINGCAPS
1175 | D3DDD_DEVICERENDERBITDEPTH
1176 | D3DDD_DEVICEZBUFFERBITDEPTH
1177 | D3DDD_MAXBUFFERSIZE
1178 | D3DDD_MAXVERTEXCOUNT
;
1179 caps1
->dcmColorModel
= D3DCOLOR_RGB
;
1180 caps1
->dwDevCaps
= caps7
->dwDevCaps
;
1181 caps1
->dtcTransformCaps
.dwSize
= sizeof(caps1
->dtcTransformCaps
);
1182 caps1
->dtcTransformCaps
.dwCaps
= D3DTRANSFORMCAPS_CLIP
;
1183 caps1
->bClipping
= TRUE
;
1184 caps1
->dlcLightingCaps
.dwSize
= sizeof(caps1
->dlcLightingCaps
);
1185 caps1
->dlcLightingCaps
.dwCaps
= D3DLIGHTCAPS_DIRECTIONAL
1186 | D3DLIGHTCAPS_PARALLELPOINT
1187 | D3DLIGHTCAPS_POINT
1188 | D3DLIGHTCAPS_SPOT
;
1189 caps1
->dlcLightingCaps
.dwLightingModel
= D3DLIGHTINGMODEL_RGB
;
1190 caps1
->dlcLightingCaps
.dwNumLights
= caps7
->dwMaxActiveLights
;
1191 caps1
->dpcLineCaps
= caps7
->dpcLineCaps
;
1192 caps1
->dpcTriCaps
= caps7
->dpcTriCaps
;
1193 caps1
->dwDeviceRenderBitDepth
= caps7
->dwDeviceRenderBitDepth
;
1194 caps1
->dwDeviceZBufferBitDepth
= caps7
->dwDeviceZBufferBitDepth
;
1195 caps1
->dwMaxBufferSize
= 0;
1196 caps1
->dwMaxVertexCount
= 65536;
1197 caps1
->dwMinTextureWidth
= caps7
->dwMinTextureWidth
;
1198 caps1
->dwMinTextureHeight
= caps7
->dwMinTextureHeight
;
1199 caps1
->dwMaxTextureWidth
= caps7
->dwMaxTextureWidth
;
1200 caps1
->dwMaxTextureHeight
= caps7
->dwMaxTextureHeight
;
1201 caps1
->dwMinStippleWidth
= 1;
1202 caps1
->dwMinStippleHeight
= 1;
1203 caps1
->dwMaxStippleWidth
= 32;
1204 caps1
->dwMaxStippleHeight
= 32;
1205 caps1
->dwMaxTextureRepeat
= caps7
->dwMaxTextureRepeat
;
1206 caps1
->dwMaxTextureAspectRatio
= caps7
->dwMaxTextureAspectRatio
;
1207 caps1
->dwMaxAnisotropy
= caps7
->dwMaxAnisotropy
;
1208 caps1
->dvGuardBandLeft
= caps7
->dvGuardBandLeft
;
1209 caps1
->dvGuardBandTop
= caps7
->dvGuardBandTop
;
1210 caps1
->dvGuardBandRight
= caps7
->dvGuardBandRight
;
1211 caps1
->dvGuardBandBottom
= caps7
->dvGuardBandBottom
;
1212 caps1
->dvExtentsAdjust
= caps7
->dvExtentsAdjust
;
1213 caps1
->dwStencilCaps
= caps7
->dwStencilCaps
;
1214 caps1
->dwFVFCaps
= caps7
->dwFVFCaps
;
1215 caps1
->dwTextureOpCaps
= caps7
->dwTextureOpCaps
;
1216 caps1
->wMaxTextureBlendStages
= caps7
->wMaxTextureBlendStages
;
1217 caps1
->wMaxSimultaneousTextures
= caps7
->wMaxSimultaneousTextures
;
1220 HRESULT
ddraw_get_d3dcaps(const struct ddraw
*ddraw
, D3DDEVICEDESC7
*caps
)
1222 struct wined3d_caps wined3d_caps
;
1225 TRACE("ddraw %p, caps %p.\n", ddraw
, caps
);
1227 memset(&wined3d_caps
, 0, sizeof(wined3d_caps
));
1229 wined3d_mutex_lock();
1230 hr
= wined3d_get_device_caps(ddraw
->wined3d
, 0, WINED3D_DEVICE_TYPE_HAL
, &wined3d_caps
);
1231 wined3d_mutex_unlock();
1234 WARN("Failed to get device caps, hr %#x.\n", hr
);
1238 caps
->dwDevCaps
= wined3d_caps
.DevCaps
;
1239 caps
->dpcLineCaps
.dwMiscCaps
= wined3d_caps
.PrimitiveMiscCaps
;
1240 caps
->dpcLineCaps
.dwRasterCaps
= wined3d_caps
.RasterCaps
;
1241 caps
->dpcLineCaps
.dwZCmpCaps
= wined3d_caps
.ZCmpCaps
;
1242 caps
->dpcLineCaps
.dwSrcBlendCaps
= wined3d_caps
.SrcBlendCaps
;
1243 caps
->dpcLineCaps
.dwDestBlendCaps
= wined3d_caps
.DestBlendCaps
;
1244 caps
->dpcLineCaps
.dwAlphaCmpCaps
= wined3d_caps
.AlphaCmpCaps
;
1245 caps
->dpcLineCaps
.dwShadeCaps
= wined3d_caps
.ShadeCaps
;
1246 caps
->dpcLineCaps
.dwTextureCaps
= wined3d_caps
.TextureCaps
;
1247 caps
->dpcLineCaps
.dwTextureFilterCaps
= wined3d_caps
.TextureFilterCaps
;
1248 caps
->dpcLineCaps
.dwTextureAddressCaps
= wined3d_caps
.TextureAddressCaps
;
1250 caps
->dwMaxTextureWidth
= wined3d_caps
.MaxTextureWidth
;
1251 caps
->dwMaxTextureHeight
= wined3d_caps
.MaxTextureHeight
;
1253 caps
->dwMaxTextureRepeat
= wined3d_caps
.MaxTextureRepeat
;
1254 caps
->dwMaxTextureAspectRatio
= wined3d_caps
.MaxTextureAspectRatio
;
1255 caps
->dwMaxAnisotropy
= wined3d_caps
.MaxAnisotropy
;
1256 caps
->dvMaxVertexW
= wined3d_caps
.MaxVertexW
;
1258 caps
->dvGuardBandLeft
= wined3d_caps
.GuardBandLeft
;
1259 caps
->dvGuardBandTop
= wined3d_caps
.GuardBandTop
;
1260 caps
->dvGuardBandRight
= wined3d_caps
.GuardBandRight
;
1261 caps
->dvGuardBandBottom
= wined3d_caps
.GuardBandBottom
;
1263 caps
->dvExtentsAdjust
= wined3d_caps
.ExtentsAdjust
;
1264 caps
->dwStencilCaps
= wined3d_caps
.StencilCaps
;
1266 caps
->dwFVFCaps
= wined3d_caps
.FVFCaps
;
1267 caps
->dwTextureOpCaps
= wined3d_caps
.TextureOpCaps
;
1269 caps
->dwVertexProcessingCaps
= wined3d_caps
.VertexProcessingCaps
;
1270 caps
->dwMaxActiveLights
= wined3d_caps
.MaxActiveLights
;
1272 /* Remove all non-d3d7 caps */
1273 caps
->dwDevCaps
&= (
1274 D3DDEVCAPS_FLOATTLVERTEX
| D3DDEVCAPS_SORTINCREASINGZ
| D3DDEVCAPS_SORTDECREASINGZ
|
1275 D3DDEVCAPS_SORTEXACT
| D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
|
1276 D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
| D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
|
1277 D3DDEVCAPS_TEXTUREVIDEOMEMORY
| D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
|
1278 D3DDEVCAPS_TEXTURENONLOCALVIDMEM
| D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
1279 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
1280 D3DDEVCAPS_HWRASTERIZATION
);
1282 caps
->dwStencilCaps
&= (
1283 D3DSTENCILCAPS_KEEP
| D3DSTENCILCAPS_ZERO
| D3DSTENCILCAPS_REPLACE
|
1284 D3DSTENCILCAPS_INCRSAT
| D3DSTENCILCAPS_DECRSAT
| D3DSTENCILCAPS_INVERT
|
1285 D3DSTENCILCAPS_INCR
| D3DSTENCILCAPS_DECR
);
1289 caps
->dwTextureOpCaps
&= (
1290 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_SELECTARG2
|
1291 D3DTEXOPCAPS_MODULATE
| D3DTEXOPCAPS_MODULATE2X
| D3DTEXOPCAPS_MODULATE4X
|
1292 D3DTEXOPCAPS_ADD
| D3DTEXOPCAPS_ADDSIGNED
| D3DTEXOPCAPS_ADDSIGNED2X
|
1293 D3DTEXOPCAPS_SUBTRACT
| D3DTEXOPCAPS_ADDSMOOTH
| D3DTEXOPCAPS_BLENDTEXTUREALPHA
|
1294 D3DTEXOPCAPS_BLENDFACTORALPHA
| D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
| D3DTEXOPCAPS_BLENDCURRENTALPHA
|
1295 D3DTEXOPCAPS_PREMODULATE
| D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
|
1296 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
| D3DTEXOPCAPS_BUMPENVMAP
|
1297 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
| D3DTEXOPCAPS_DOTPRODUCT3
);
1299 caps
->dwVertexProcessingCaps
&= (
1300 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_VERTEXFOG
|
1301 D3DVTXPCAPS_DIRECTIONALLIGHTS
| D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
);
1303 caps
->dpcLineCaps
.dwMiscCaps
&= (
1304 D3DPMISCCAPS_MASKPLANES
| D3DPMISCCAPS_MASKZ
| D3DPMISCCAPS_LINEPATTERNREP
|
1305 D3DPMISCCAPS_CONFORMANT
| D3DPMISCCAPS_CULLNONE
| D3DPMISCCAPS_CULLCW
|
1306 D3DPMISCCAPS_CULLCCW
);
1308 caps
->dpcLineCaps
.dwRasterCaps
&= (
1309 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ROP2
| D3DPRASTERCAPS_XOR
|
1310 D3DPRASTERCAPS_PAT
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_SUBPIXEL
|
1311 D3DPRASTERCAPS_SUBPIXELX
| D3DPRASTERCAPS_FOGVERTEX
| D3DPRASTERCAPS_FOGTABLE
|
1312 D3DPRASTERCAPS_STIPPLE
| D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT
| D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT
|
1313 D3DPRASTERCAPS_ANTIALIASEDGES
| D3DPRASTERCAPS_MIPMAPLODBIAS
|
1314 D3DPRASTERCAPS_ZBUFFERLESSHSR
| D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
|
1315 D3DPRASTERCAPS_WBUFFER
| D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT
| D3DPRASTERCAPS_WFOG
|
1316 D3DPRASTERCAPS_ZFOG
| WINED3DPRASTERCAPS_DEPTHBIAS
);
1317 if (caps
->dpcLineCaps
.dwRasterCaps
& WINED3DPRASTERCAPS_DEPTHBIAS
)
1318 caps
->dpcLineCaps
.dwRasterCaps
= (caps
->dpcLineCaps
.dwRasterCaps
| D3DPRASTERCAPS_ZBIAS
)
1319 & ~WINED3DPRASTERCAPS_DEPTHBIAS
;
1321 caps
->dpcLineCaps
.dwZCmpCaps
&= (
1322 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
1323 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
1324 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
1326 caps
->dpcLineCaps
.dwSrcBlendCaps
&= (
1327 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
1328 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
1329 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
1330 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
1331 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
1333 caps
->dpcLineCaps
.dwDestBlendCaps
&= (
1334 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
1335 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
1336 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
1337 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
1338 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
1340 caps
->dpcLineCaps
.dwAlphaCmpCaps
&= (
1341 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
1342 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
1343 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
1345 caps
->dpcLineCaps
.dwShadeCaps
&= (
1346 D3DPSHADECAPS_COLORFLATMONO
| D3DPSHADECAPS_COLORFLATRGB
| D3DPSHADECAPS_COLORGOURAUDMONO
|
1347 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_COLORPHONGMONO
| D3DPSHADECAPS_COLORPHONGRGB
|
1348 D3DPSHADECAPS_SPECULARFLATMONO
| D3DPSHADECAPS_SPECULARFLATRGB
| D3DPSHADECAPS_SPECULARGOURAUDMONO
|
1349 D3DPSHADECAPS_SPECULARGOURAUDRGB
| D3DPSHADECAPS_SPECULARPHONGMONO
| D3DPSHADECAPS_SPECULARPHONGRGB
|
1350 D3DPSHADECAPS_ALPHAFLATBLEND
| D3DPSHADECAPS_ALPHAFLATSTIPPLED
| D3DPSHADECAPS_ALPHAGOURAUDBLEND
|
1351 D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED
| D3DPSHADECAPS_ALPHAPHONGBLEND
| D3DPSHADECAPS_ALPHAPHONGSTIPPLED
|
1352 D3DPSHADECAPS_FOGFLAT
| D3DPSHADECAPS_FOGGOURAUD
| D3DPSHADECAPS_FOGPHONG
);
1354 caps
->dpcLineCaps
.dwTextureCaps
&= (
1355 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
1356 D3DPTEXTURECAPS_TRANSPARENCY
| D3DPTEXTURECAPS_BORDER
| D3DPTEXTURECAPS_SQUAREONLY
|
1357 D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
| D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
1358 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_COLORKEYBLEND
);
1360 caps
->dpcLineCaps
.dwTextureFilterCaps
&= (
1361 D3DPTFILTERCAPS_NEAREST
| D3DPTFILTERCAPS_LINEAR
| D3DPTFILTERCAPS_MIPNEAREST
|
1362 D3DPTFILTERCAPS_MIPLINEAR
| D3DPTFILTERCAPS_LINEARMIPNEAREST
| D3DPTFILTERCAPS_LINEARMIPLINEAR
|
1363 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
1364 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
1365 D3DPTFILTERCAPS_MAGFLINEAR
| D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
|
1366 D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
);
1368 caps
->dpcLineCaps
.dwTextureAddressCaps
&= (
1369 D3DPTADDRESSCAPS_WRAP
| D3DPTADDRESSCAPS_MIRROR
| D3DPTADDRESSCAPS_CLAMP
|
1370 D3DPTADDRESSCAPS_BORDER
| D3DPTADDRESSCAPS_INDEPENDENTUV
);
1372 if (!(caps
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
))
1374 /* DirectX7 always has the np2 flag set, no matter what the card
1375 * supports. Some old games (Rollcage) check the caps incorrectly.
1376 * If wined3d supports nonpow2 textures it also has np2 conditional
1378 caps
->dpcLineCaps
.dwTextureCaps
|= D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
;
1381 /* Fill the missing members, and do some fixup */
1382 caps
->dpcLineCaps
.dwSize
= sizeof(caps
->dpcLineCaps
);
1383 caps
->dpcLineCaps
.dwTextureBlendCaps
= D3DPTBLENDCAPS_ADD
1384 | D3DPTBLENDCAPS_MODULATEMASK
1385 | D3DPTBLENDCAPS_COPY
1386 | D3DPTBLENDCAPS_DECAL
1387 | D3DPTBLENDCAPS_DECALALPHA
1388 | D3DPTBLENDCAPS_DECALMASK
1389 | D3DPTBLENDCAPS_MODULATE
1390 | D3DPTBLENDCAPS_MODULATEALPHA
;
1391 caps
->dpcLineCaps
.dwStippleWidth
= 32;
1392 caps
->dpcLineCaps
.dwStippleHeight
= 32;
1393 /* Use the same for the TriCaps */
1394 caps
->dpcTriCaps
= caps
->dpcLineCaps
;
1396 caps
->dwDeviceRenderBitDepth
= DDBD_16
| DDBD_24
| DDBD_32
;
1397 caps
->dwDeviceZBufferBitDepth
= DDBD_16
| DDBD_24
;
1398 caps
->dwMinTextureWidth
= 1;
1399 caps
->dwMinTextureHeight
= 1;
1401 /* Convert DWORDs safely to WORDs */
1402 caps
->wMaxTextureBlendStages
= min(wined3d_caps
.MaxTextureBlendStages
, 0xffff);
1403 caps
->wMaxSimultaneousTextures
= min(wined3d_caps
.MaxSimultaneousTextures
, 0xffff);
1404 caps
->wMaxUserClipPlanes
= min(wined3d_caps
.MaxUserClipPlanes
, D3DMAXUSERCLIPPLANES
);
1405 caps
->wMaxVertexBlendMatrices
= min(wined3d_caps
.MaxVertexBlendMatrices
, 0xffff);
1407 caps
->deviceGUID
= IID_IDirect3DTnLHalDevice
;
1409 caps
->dwReserved1
= 0;
1410 caps
->dwReserved2
= 0;
1411 caps
->dwReserved3
= 0;
1412 caps
->dwReserved4
= 0;
1417 /*****************************************************************************
1418 * IDirectDraw7::GetCaps
1420 * Returns the drives capabilities
1422 * Used for version 1, 2, 4 and 7
1425 * DriverCaps: Structure to write the Hardware accelerated caps to
1426 * HelCaps: Structure to write the emulation caps to
1429 * This implementation returns DD_OK only
1431 *****************************************************************************/
1432 static HRESULT WINAPI
ddraw7_GetCaps(IDirectDraw7
*iface
, DDCAPS
*DriverCaps
, DDCAPS
*HELCaps
)
1434 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1435 DDSCAPS2 ddscaps
= {0, 0, 0, {0}};
1436 struct wined3d_caps winecaps
;
1440 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, DriverCaps
, HELCaps
);
1442 /* One structure must be != NULL */
1443 if (!DriverCaps
&& !HELCaps
)
1445 WARN("Invalid parameters.\n");
1446 return DDERR_INVALIDPARAMS
;
1449 memset(&caps
, 0, sizeof(caps
));
1450 memset(&winecaps
, 0, sizeof(winecaps
));
1451 caps
.dwSize
= sizeof(caps
);
1453 wined3d_mutex_lock();
1454 hr
= wined3d_device_get_device_caps(ddraw
->wined3d_device
, &winecaps
);
1457 WARN("Failed to get device caps, %#x.\n", hr
);
1458 wined3d_mutex_unlock();
1462 hr
= IDirectDraw7_GetAvailableVidMem(iface
, &ddscaps
, &caps
.dwVidMemTotal
, &caps
.dwVidMemFree
);
1465 WARN("IDirectDraw7::GetAvailableVidMem failed\n");
1466 wined3d_mutex_unlock();
1470 hr
= IDirectDraw7_GetFourCCCodes(iface
, &caps
.dwNumFourCCCodes
, NULL
);
1471 wined3d_mutex_unlock();
1474 WARN("IDirectDraw7::GetFourCCCodes failed\n");
1478 caps
.dwCaps
= winecaps
.ddraw_caps
.caps
;
1479 caps
.dwCaps2
= winecaps
.ddraw_caps
.caps2
;
1480 caps
.dwCKeyCaps
= winecaps
.ddraw_caps
.color_key_caps
;
1481 caps
.dwFXCaps
= winecaps
.ddraw_caps
.fx_caps
;
1482 caps
.dwPalCaps
= DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
;
1483 caps
.ddsCaps
.dwCaps
= winecaps
.ddraw_caps
.dds_caps
;
1484 caps
.dwSVBCaps
= winecaps
.ddraw_caps
.svb_caps
;
1485 caps
.dwSVBCKeyCaps
= winecaps
.ddraw_caps
.svb_color_key_caps
;
1486 caps
.dwSVBFXCaps
= winecaps
.ddraw_caps
.svb_fx_caps
;
1487 caps
.dwVSBCaps
= winecaps
.ddraw_caps
.vsb_caps
;
1488 caps
.dwVSBCKeyCaps
= winecaps
.ddraw_caps
.vsb_color_key_caps
;
1489 caps
.dwVSBFXCaps
= winecaps
.ddraw_caps
.vsb_fx_caps
;
1490 caps
.dwSSBCaps
= winecaps
.ddraw_caps
.ssb_caps
;
1491 caps
.dwSSBCKeyCaps
= winecaps
.ddraw_caps
.ssb_color_key_caps
;
1492 caps
.dwSSBFXCaps
= winecaps
.ddraw_caps
.ssb_fx_caps
;
1494 caps
.dwCaps
|= DDCAPS_ALIGNSTRIDE
;
1495 caps
.dwAlignStrideAlign
= DDRAW_STRIDE_ALIGNMENT
;
1497 caps
.ddsOldCaps
.dwCaps
= caps
.ddsCaps
.dwCaps
;
1501 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &caps
);
1502 if (TRACE_ON(ddraw
))
1504 TRACE("Driver Caps :\n");
1505 DDRAW_dump_DDCAPS(DriverCaps
);
1511 DD_STRUCT_COPY_BYSIZE(HELCaps
, &caps
);
1512 if (TRACE_ON(ddraw
))
1514 TRACE("HEL Caps :\n");
1515 DDRAW_dump_DDCAPS(HELCaps
);
1522 static HRESULT WINAPI
ddraw4_GetCaps(IDirectDraw4
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1524 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1526 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1528 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1531 static HRESULT WINAPI
ddraw2_GetCaps(IDirectDraw2
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1533 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1535 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1537 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1540 static HRESULT WINAPI
ddraw1_GetCaps(IDirectDraw
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1542 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1544 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1546 return ddraw7_GetCaps(&ddraw
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1549 /*****************************************************************************
1550 * IDirectDraw7::Compact
1552 * No idea what it does, MSDN says it's not implemented.
1555 * DD_OK, but this is unchecked
1557 *****************************************************************************/
1558 static HRESULT WINAPI
ddraw7_Compact(IDirectDraw7
*iface
)
1560 TRACE("iface %p.\n", iface
);
1565 static HRESULT WINAPI
ddraw4_Compact(IDirectDraw4
*iface
)
1567 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1569 TRACE("iface %p.\n", iface
);
1571 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1574 static HRESULT WINAPI
ddraw2_Compact(IDirectDraw2
*iface
)
1576 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1578 TRACE("iface %p.\n", iface
);
1580 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1583 static HRESULT WINAPI
ddraw1_Compact(IDirectDraw
*iface
)
1585 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1587 TRACE("iface %p.\n", iface
);
1589 return ddraw7_Compact(&ddraw
->IDirectDraw7_iface
);
1592 /*****************************************************************************
1593 * IDirectDraw7::GetDisplayMode
1595 * Returns information about the current display mode
1597 * Exists in versions 1, 2, 4 and 7
1600 * DDSD: Address of a surface description structure to write the info to
1605 *****************************************************************************/
1606 static HRESULT WINAPI
ddraw7_GetDisplayMode(IDirectDraw7
*iface
, DDSURFACEDESC2
*DDSD
)
1608 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1609 struct wined3d_display_mode mode
;
1612 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
1614 /* This seems sane */
1615 if (!DDSD
|| (DDSD
->dwSize
!= sizeof(DDSURFACEDESC
) && DDSD
->dwSize
!= sizeof(DDSURFACEDESC2
)))
1616 return DDERR_INVALIDPARAMS
;
1618 wined3d_mutex_lock();
1620 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1622 ERR("Failed to get display mode, hr %#x.\n", hr
);
1623 wined3d_mutex_unlock();
1627 memset(DDSD
, 0, DDSD
->dwSize
);
1628 DDSD
->dwSize
= sizeof(*DDSD
);
1629 DDSD
->dwFlags
= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
1630 DDSD
->dwWidth
= mode
.width
;
1631 DDSD
->dwHeight
= mode
.height
;
1632 DDSD
->u2
.dwRefreshRate
= 60;
1633 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
1634 ddrawformat_from_wined3dformat(&DDSD
->u4
.ddpfPixelFormat
, mode
.format_id
);
1635 DDSD
->u1
.lPitch
= mode
.width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
1639 TRACE("Returning surface desc :\n");
1640 DDRAW_dump_surface_desc(DDSD
);
1643 wined3d_mutex_unlock();
1648 static HRESULT WINAPI
ddraw4_GetDisplayMode(IDirectDraw4
*iface
, DDSURFACEDESC2
*surface_desc
)
1650 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1652 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1654 return ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, surface_desc
);
1657 static HRESULT WINAPI
ddraw2_GetDisplayMode(IDirectDraw2
*iface
, DDSURFACEDESC
*surface_desc
)
1659 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1662 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1664 hr
= ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1665 if (SUCCEEDED(hr
)) surface_desc
->dwSize
= sizeof(*surface_desc
);
1669 static HRESULT WINAPI
ddraw1_GetDisplayMode(IDirectDraw
*iface
, DDSURFACEDESC
*surface_desc
)
1671 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1674 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1676 hr
= ddraw7_GetDisplayMode(&ddraw
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1677 if (SUCCEEDED(hr
)) surface_desc
->dwSize
= sizeof(*surface_desc
);
1681 /*****************************************************************************
1682 * IDirectDraw7::GetFourCCCodes
1684 * Returns an array of supported FourCC codes.
1686 * Exists in versions 1, 2, 4 and 7
1689 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
1690 * of enumerated codes
1691 * Codes: Pointer to an array of DWORDs where the supported codes are written
1695 * Always returns DD_OK, as it's a stub for now
1697 *****************************************************************************/
1698 static HRESULT WINAPI
ddraw7_GetFourCCCodes(IDirectDraw7
*iface
, DWORD
*NumCodes
, DWORD
*Codes
)
1700 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1701 static const enum wined3d_format_id formats
[] =
1703 WINED3DFMT_YUY2
, WINED3DFMT_UYVY
, WINED3DFMT_YV12
,
1704 WINED3DFMT_DXT1
, WINED3DFMT_DXT2
, WINED3DFMT_DXT3
, WINED3DFMT_DXT4
, WINED3DFMT_DXT5
,
1705 WINED3DFMT_ATI2N
, WINED3DFMT_NVHU
, WINED3DFMT_NVHS
1707 struct wined3d_display_mode mode
;
1708 DWORD count
= 0, i
, outsize
;
1711 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, NumCodes
, Codes
);
1713 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1715 ERR("Failed to get display mode, hr %#x.\n", hr
);
1719 outsize
= NumCodes
&& Codes
? *NumCodes
: 0;
1721 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
)
1723 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, WINED3D_DEVICE_TYPE_HAL
,
1724 mode
.format_id
, 0, 0, WINED3D_RTYPE_TEXTURE_2D
, formats
[i
])))
1726 if (count
< outsize
)
1727 Codes
[count
] = formats
[i
];
1732 TRACE("Returning %u FourCC codes\n", count
);
1739 static HRESULT WINAPI
ddraw4_GetFourCCCodes(IDirectDraw4
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1741 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1743 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1745 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1748 static HRESULT WINAPI
ddraw2_GetFourCCCodes(IDirectDraw2
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1750 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1752 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1754 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1757 static HRESULT WINAPI
ddraw1_GetFourCCCodes(IDirectDraw
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1759 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1761 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1763 return ddraw7_GetFourCCCodes(&ddraw
->IDirectDraw7_iface
, codes_count
, codes
);
1766 static HRESULT WINAPI
ddraw7_GetMonitorFrequency(IDirectDraw7
*iface
, DWORD
*frequency
)
1768 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1769 struct wined3d_display_mode mode
;
1772 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1774 wined3d_mutex_lock();
1775 hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
);
1776 wined3d_mutex_unlock();
1779 WARN("Failed to get display mode, hr %#x.\n", hr
);
1783 *frequency
= mode
.refresh_rate
;
1788 static HRESULT WINAPI
ddraw4_GetMonitorFrequency(IDirectDraw4
*iface
, DWORD
*frequency
)
1790 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1792 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1794 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1797 static HRESULT WINAPI
ddraw2_GetMonitorFrequency(IDirectDraw2
*iface
, DWORD
*frequency
)
1799 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1801 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1803 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1806 static HRESULT WINAPI
ddraw1_GetMonitorFrequency(IDirectDraw
*iface
, DWORD
*frequency
)
1808 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1810 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1812 return ddraw7_GetMonitorFrequency(&ddraw
->IDirectDraw7_iface
, frequency
);
1815 static HRESULT WINAPI
ddraw7_GetVerticalBlankStatus(IDirectDraw7
*iface
, BOOL
*status
)
1817 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1818 struct wined3d_raster_status raster_status
;
1821 TRACE("iface %p, status %p.\n", iface
, status
);
1824 return DDERR_INVALIDPARAMS
;
1826 wined3d_mutex_lock();
1827 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
1828 wined3d_mutex_unlock();
1831 WARN("Failed to get raster status, hr %#x.\n", hr
);
1835 *status
= raster_status
.in_vblank
;
1840 static HRESULT WINAPI
ddraw4_GetVerticalBlankStatus(IDirectDraw4
*iface
, BOOL
*status
)
1842 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1844 TRACE("iface %p, status %p.\n", iface
, status
);
1846 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1849 static HRESULT WINAPI
ddraw2_GetVerticalBlankStatus(IDirectDraw2
*iface
, BOOL
*status
)
1851 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1853 TRACE("iface %p, status %p.\n", iface
, status
);
1855 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1858 static HRESULT WINAPI
ddraw1_GetVerticalBlankStatus(IDirectDraw
*iface
, BOOL
*status
)
1860 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
1862 TRACE("iface %p, status %p.\n", iface
, status
);
1864 return ddraw7_GetVerticalBlankStatus(&ddraw
->IDirectDraw7_iface
, status
);
1867 /*****************************************************************************
1868 * IDirectDraw7::GetAvailableVidMem
1870 * Returns the total and free video memory
1873 * caps: Specifies the memory type asked for
1874 * total: Pointer to a DWORD to be filled with the total memory
1875 * free: Pointer to a DWORD to be filled with the free memory
1879 * DDERR_INVALIDPARAMS if free and total are NULL
1881 *****************************************************************************/
1882 static HRESULT WINAPI
ddraw7_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*caps
, DWORD
*total
,
1885 unsigned int framebuffer_size
, total_vidmem
, free_vidmem
;
1886 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1887 struct wined3d_display_mode mode
;
1890 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1892 if (!total
&& !free
)
1893 return DDERR_INVALIDPARAMS
;
1895 if (TRACE_ON(ddraw
))
1897 TRACE("Asked for memory with description: ");
1898 DDRAW_dump_DDSCAPS2(caps
);
1900 wined3d_mutex_lock();
1902 /* Todo: System memory vs local video memory vs non-local video memory
1903 * The MSDN also mentions differences between texture memory and other
1904 * resources, but that's not important
1907 /* Some applications (e.g. 3DMark 2000) assume that the reported amount of
1908 * video memory doesn't include the memory used by the default framebuffer.
1910 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
1912 WARN("Failed to get display mode, hr %#x.\n", hr
);
1913 wined3d_mutex_unlock();
1916 framebuffer_size
= wined3d_calculate_format_pitch(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
,
1917 mode
.format_id
, mode
.width
);
1918 framebuffer_size
*= mode
.height
;
1922 free_vidmem
= wined3d_device_get_available_texture_mem(ddraw
->wined3d_device
);
1923 *free
= framebuffer_size
> free_vidmem
? 0 : free_vidmem
- framebuffer_size
;
1924 TRACE("Free video memory %#x.\n", *free
);
1929 struct wined3d_adapter_identifier desc
= {0};
1931 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0, &desc
);
1932 total_vidmem
= min(UINT_MAX
, desc
.video_memory
);
1933 *total
= framebuffer_size
> total_vidmem
? 0 : total_vidmem
- framebuffer_size
;
1934 TRACE("Total video memory %#x.\n", *total
);
1937 wined3d_mutex_unlock();
1942 static HRESULT WINAPI
ddraw4_GetAvailableVidMem(IDirectDraw4
*iface
,
1943 DDSCAPS2
*caps
, DWORD
*total
, DWORD
*free
)
1945 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
1947 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1949 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, caps
, total
, free
);
1952 static HRESULT WINAPI
ddraw2_GetAvailableVidMem(IDirectDraw2
*iface
,
1953 DDSCAPS
*caps
, DWORD
*total
, DWORD
*free
)
1955 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
1958 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1960 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
1961 return ddraw7_GetAvailableVidMem(&ddraw
->IDirectDraw7_iface
, &caps2
, total
, free
);
1964 /*****************************************************************************
1965 * IDirectDraw7::Initialize
1967 * Initializes a DirectDraw interface.
1970 * GUID: Interface identifier. Well, don't know what this is really good
1974 * Returns DD_OK on the first call,
1975 * DDERR_ALREADYINITIALIZED on repeated calls
1977 *****************************************************************************/
1978 static HRESULT WINAPI
ddraw7_Initialize(IDirectDraw7
*iface
, GUID
*guid
)
1980 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
1982 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1984 if (ddraw
->flags
& DDRAW_INITIALIZED
)
1985 return DDERR_ALREADYINITIALIZED
;
1987 /* FIXME: To properly take the GUID into account we should call
1988 * ddraw_init() here instead of in DDRAW_Create(). */
1990 FIXME("Ignoring guid %s.\n", debugstr_guid(guid
));
1992 ddraw
->flags
|= DDRAW_INITIALIZED
;
1996 static HRESULT WINAPI
ddraw4_Initialize(IDirectDraw4
*iface
, GUID
*guid
)
1998 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2000 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2002 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2005 static HRESULT WINAPI
ddraw2_Initialize(IDirectDraw2
*iface
, GUID
*guid
)
2007 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2009 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2011 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2014 static HRESULT WINAPI
ddraw1_Initialize(IDirectDraw
*iface
, GUID
*guid
)
2016 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2018 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
2020 return ddraw7_Initialize(&ddraw
->IDirectDraw7_iface
, guid
);
2023 static HRESULT WINAPI
d3d1_Initialize(IDirect3D
*iface
, REFIID riid
)
2025 TRACE("iface %p, riid %s.\n", iface
, debugstr_guid(riid
));
2027 return DDERR_ALREADYINITIALIZED
;
2030 /*****************************************************************************
2031 * IDirectDraw7::FlipToGDISurface
2033 * "Makes the surface that the GDI writes to the primary surface"
2034 * Looks like some windows specific thing we don't have to care about.
2035 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
2036 * show error boxes ;)
2037 * Well, just return DD_OK.
2040 * Always returns DD_OK
2042 *****************************************************************************/
2043 static HRESULT WINAPI
ddraw7_FlipToGDISurface(IDirectDraw7
*iface
)
2045 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2046 IDirectDrawSurface7
*gdi_surface
;
2047 struct ddraw_surface
*gdi_impl
;
2050 TRACE("iface %p.\n", iface
);
2052 wined3d_mutex_lock();
2054 if (FAILED(hr
= IDirectDraw7_GetGDISurface(iface
, &gdi_surface
)))
2056 WARN("Failed to retrieve GDI surface, hr %#x.\n", hr
);
2057 wined3d_mutex_unlock();
2061 gdi_impl
= impl_from_IDirectDrawSurface7(gdi_surface
);
2062 if (gdi_impl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_FRONTBUFFER
)
2065 hr
= IDirectDrawSurface7_Flip(&ddraw
->primary
->IDirectDrawSurface7_iface
, gdi_surface
, DDFLIP_WAIT
);
2066 IDirectDrawSurface7_Release(gdi_surface
);
2068 wined3d_mutex_unlock();
2073 static HRESULT WINAPI
ddraw4_FlipToGDISurface(IDirectDraw4
*iface
)
2075 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2077 TRACE("iface %p.\n", iface
);
2079 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2082 static HRESULT WINAPI
ddraw2_FlipToGDISurface(IDirectDraw2
*iface
)
2084 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2086 TRACE("iface %p.\n", iface
);
2088 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2091 static HRESULT WINAPI
ddraw1_FlipToGDISurface(IDirectDraw
*iface
)
2093 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2095 TRACE("iface %p.\n", iface
);
2097 return ddraw7_FlipToGDISurface(&ddraw
->IDirectDraw7_iface
);
2100 /*****************************************************************************
2101 * IDirectDraw7::WaitForVerticalBlank
2103 * This method allows applications to get in sync with the vertical blank
2105 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
2106 * redraw the screen, most likely because of this stub
2109 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
2110 * or DDWAITVB_BLOCKEND
2111 * h: Not used, according to MSDN
2114 * Always returns DD_OK
2116 *****************************************************************************/
2117 static HRESULT WINAPI
ddraw7_WaitForVerticalBlank(IDirectDraw7
*iface
, DWORD Flags
, HANDLE event
)
2121 TRACE("iface %p, flags %#x, event %p.\n", iface
, Flags
, event
);
2123 /* This function is called often, so print the fixme only once */
2126 FIXME("iface %p, flags %#x, event %p stub!\n", iface
, Flags
, event
);
2130 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
2131 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
2132 return DDERR_UNSUPPORTED
; /* unchecked */
2137 static HRESULT WINAPI
ddraw4_WaitForVerticalBlank(IDirectDraw4
*iface
, DWORD flags
, HANDLE event
)
2139 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2141 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2143 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2146 static HRESULT WINAPI
ddraw2_WaitForVerticalBlank(IDirectDraw2
*iface
, DWORD flags
, HANDLE event
)
2148 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2150 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2152 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2155 static HRESULT WINAPI
ddraw1_WaitForVerticalBlank(IDirectDraw
*iface
, DWORD flags
, HANDLE event
)
2157 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2159 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
2161 return ddraw7_WaitForVerticalBlank(&ddraw
->IDirectDraw7_iface
, flags
, event
);
2164 static HRESULT WINAPI
ddraw7_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
2166 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2167 struct wined3d_raster_status raster_status
;
2170 TRACE("iface %p, line %p.\n", iface
, Scanline
);
2172 wined3d_mutex_lock();
2173 hr
= wined3d_get_adapter_raster_status(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &raster_status
);
2174 wined3d_mutex_unlock();
2177 WARN("Failed to get raster status, hr %#x.\n", hr
);
2181 *Scanline
= raster_status
.scan_line
;
2183 if (raster_status
.in_vblank
)
2184 return DDERR_VERTICALBLANKINPROGRESS
;
2189 static HRESULT WINAPI
ddraw4_GetScanLine(IDirectDraw4
*iface
, DWORD
*line
)
2191 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2193 TRACE("iface %p, line %p.\n", iface
, line
);
2195 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2198 static HRESULT WINAPI
ddraw2_GetScanLine(IDirectDraw2
*iface
, DWORD
*line
)
2200 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2202 TRACE("iface %p, line %p.\n", iface
, line
);
2204 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2207 static HRESULT WINAPI
ddraw1_GetScanLine(IDirectDraw
*iface
, DWORD
*line
)
2209 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2211 TRACE("iface %p, line %p.\n", iface
, line
);
2213 return ddraw7_GetScanLine(&ddraw
->IDirectDraw7_iface
, line
);
2216 static HRESULT WINAPI
ddraw7_TestCooperativeLevel(IDirectDraw7
*iface
)
2218 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2220 TRACE("iface %p.\n", iface
);
2222 return ddraw
->device_state
== DDRAW_DEVICE_STATE_LOST
? DDERR_NOEXCLUSIVEMODE
: DD_OK
;
2225 static HRESULT WINAPI
ddraw4_TestCooperativeLevel(IDirectDraw4
*iface
)
2227 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2229 TRACE("iface %p.\n", iface
);
2231 return ddraw7_TestCooperativeLevel(&ddraw
->IDirectDraw7_iface
);
2234 /*****************************************************************************
2235 * IDirectDraw7::GetGDISurface
2237 * Returns the surface that GDI is treating as the primary surface.
2238 * For Wine this is the front buffer
2241 * GDISurface: Address to write the surface pointer to
2244 * DD_OK if the surface was found
2245 * DDERR_NOTFOUND if the GDI surface wasn't found
2247 *****************************************************************************/
2248 static HRESULT WINAPI
ddraw7_GetGDISurface(IDirectDraw7
*iface
, IDirectDrawSurface7
**surface
)
2250 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2251 struct ddraw_surface
*ddraw_surface
;
2253 TRACE("iface %p, surface %p.\n", iface
, surface
);
2255 wined3d_mutex_lock();
2257 if (!ddraw
->gdi_surface
|| !(ddraw_surface
= wined3d_texture_get_sub_resource_parent(ddraw
->gdi_surface
, 0)))
2259 WARN("GDI surface not available.\n");
2261 wined3d_mutex_unlock();
2262 return DDERR_NOTFOUND
;
2264 *surface
= &ddraw_surface
->IDirectDrawSurface7_iface
;
2265 IDirectDrawSurface7_AddRef(*surface
);
2267 wined3d_mutex_unlock();
2272 static HRESULT WINAPI
ddraw4_GetGDISurface(IDirectDraw4
*iface
, IDirectDrawSurface4
**surface
)
2274 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2275 struct ddraw_surface
*surface_impl
;
2276 IDirectDrawSurface7
*surface7
;
2279 TRACE("iface %p, surface %p.\n", iface
, surface
);
2281 hr
= ddraw7_GetGDISurface(&ddraw
->IDirectDraw7_iface
, &surface7
);
2287 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2288 *surface
= &surface_impl
->IDirectDrawSurface4_iface
;
2289 IDirectDrawSurface4_AddRef(*surface
);
2290 IDirectDrawSurface7_Release(surface7
);
2295 static HRESULT WINAPI
ddraw2_GetGDISurface(IDirectDraw2
*iface
, IDirectDrawSurface
**surface
)
2297 struct ddraw
*ddraw
= impl_from_IDirectDraw2(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
->IDirectDrawSurface_iface
;
2312 IDirectDrawSurface_AddRef(*surface
);
2313 IDirectDrawSurface7_Release(surface7
);
2318 static HRESULT WINAPI
ddraw1_GetGDISurface(IDirectDraw
*iface
, IDirectDrawSurface
**surface
)
2320 struct ddraw
*ddraw
= impl_from_IDirectDraw(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 struct displaymodescallback_context
2343 LPDDENUMMODESCALLBACK func
;
2347 static HRESULT CALLBACK
EnumDisplayModesCallbackThunk(DDSURFACEDESC2
*surface_desc
, void *context
)
2349 struct displaymodescallback_context
*cbcontext
= context
;
2352 DDSD2_to_DDSD(surface_desc
, &desc
);
2353 return cbcontext
->func(&desc
, cbcontext
->context
);
2356 /*****************************************************************************
2357 * IDirectDraw7::EnumDisplayModes
2359 * Enumerates the supported Display modes. The modes can be filtered with
2360 * the DDSD parameter.
2363 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES. For old ddraw
2364 * versions (3 and older?) this is reserved and must be 0.
2365 * DDSD: Surface description to filter the modes
2366 * Context: Pointer passed back to the callback function
2367 * cb: Application-provided callback function
2371 * DDERR_INVALIDPARAMS if the callback wasn't set
2373 *****************************************************************************/
2374 static HRESULT WINAPI
ddraw7_EnumDisplayModes(IDirectDraw7
*iface
, DWORD Flags
,
2375 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMMODESCALLBACK2 cb
)
2377 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2378 struct wined3d_display_mode
*enum_modes
= NULL
;
2379 struct wined3d_display_mode mode
;
2380 unsigned int modenum
, fmt
;
2381 DDSURFACEDESC2 callback_sd
;
2382 unsigned enum_mode_count
= 0, enum_mode_array_size
= 16;
2383 DDPIXELFORMAT pixelformat
;
2385 static const enum wined3d_format_id checkFormatList
[] =
2387 WINED3DFMT_B8G8R8X8_UNORM
,
2388 WINED3DFMT_B5G6R5_UNORM
,
2392 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2393 iface
, Flags
, DDSD
, Context
, cb
);
2396 return DDERR_INVALIDPARAMS
;
2398 if (!(enum_modes
= heap_alloc(enum_mode_array_size
* sizeof(*enum_modes
))))
2399 return DDERR_OUTOFMEMORY
;
2401 wined3d_mutex_lock();
2403 pixelformat
.dwSize
= sizeof(pixelformat
);
2404 for(fmt
= 0; fmt
< ARRAY_SIZE(checkFormatList
); fmt
++)
2407 while (wined3d_output_get_mode(ddraw
->wined3d_output
, checkFormatList
[fmt
],
2408 WINED3D_SCANLINE_ORDERING_UNKNOWN
, modenum
++, &mode
) == WINED3D_OK
)
2413 ddrawformat_from_wined3dformat(&pixelformat
, mode
.format_id
);
2416 if (DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.width
!= DDSD
->dwWidth
)
2418 if (DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.height
!= DDSD
->dwHeight
)
2420 if (DDSD
->dwFlags
& DDSD_REFRESHRATE
&& mode
.refresh_rate
!= DDSD
->u2
.dwRefreshRate
)
2422 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
2423 && pixelformat
.u1
.dwRGBBitCount
!= DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
)
2427 /* DX docs state EnumDisplayMode should return only unique modes */
2428 for (i
= 0; i
< enum_mode_count
; i
++)
2430 if (enum_modes
[i
].width
== mode
.width
&& enum_modes
[i
].height
== mode
.height
2431 && enum_modes
[i
].format_id
== mode
.format_id
2432 && (enum_modes
[i
].refresh_rate
== mode
.refresh_rate
|| !(Flags
& DDEDM_REFRESHRATES
)))
2440 memset(&callback_sd
, 0, sizeof(callback_sd
));
2441 callback_sd
.dwSize
= sizeof(callback_sd
);
2442 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2444 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
|DDSD_REFRESHRATE
;
2445 if (Flags
& DDEDM_REFRESHRATES
)
2446 callback_sd
.u2
.dwRefreshRate
= mode
.refresh_rate
;
2448 callback_sd
.dwWidth
= mode
.width
;
2449 callback_sd
.dwHeight
= mode
.height
;
2451 callback_sd
.u4
.ddpfPixelFormat
=pixelformat
;
2453 /* Calc pitch and DWORD align like MSDN says */
2454 callback_sd
.u1
.lPitch
= (callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8) * mode
.width
;
2455 callback_sd
.u1
.lPitch
= (callback_sd
.u1
.lPitch
+ 3) & ~3;
2457 TRACE("Enumerating %dx%dx%d @%d\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
,
2458 callback_sd
.u2
.dwRefreshRate
);
2460 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
2462 TRACE("Application asked to terminate the enumeration\n");
2463 heap_free(enum_modes
);
2464 wined3d_mutex_unlock();
2468 if (enum_mode_count
== enum_mode_array_size
)
2470 struct wined3d_display_mode
*new_enum_modes
;
2472 enum_mode_array_size
*= 2;
2473 if (!(new_enum_modes
= heap_realloc(enum_modes
, enum_mode_array_size
* sizeof(*new_enum_modes
))))
2475 heap_free(enum_modes
);
2476 wined3d_mutex_unlock();
2477 return DDERR_OUTOFMEMORY
;
2480 enum_modes
= new_enum_modes
;
2482 enum_modes
[enum_mode_count
++] = mode
;
2486 TRACE("End of enumeration\n");
2487 heap_free(enum_modes
);
2488 wined3d_mutex_unlock();
2493 static HRESULT WINAPI
ddraw4_EnumDisplayModes(IDirectDraw4
*iface
, DWORD flags
,
2494 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK2 callback
)
2496 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2498 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2499 iface
, flags
, surface_desc
, context
, callback
);
2501 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
, context
, callback
);
2504 static HRESULT WINAPI
ddraw2_EnumDisplayModes(IDirectDraw2
*iface
, DWORD flags
,
2505 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2507 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2508 struct displaymodescallback_context cbcontext
;
2509 DDSURFACEDESC2 surface_desc2
;
2511 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2512 iface
, flags
, surface_desc
, context
, callback
);
2514 cbcontext
.func
= callback
;
2515 cbcontext
.context
= context
;
2517 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2518 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2519 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2522 static HRESULT WINAPI
ddraw1_EnumDisplayModes(IDirectDraw
*iface
, DWORD flags
,
2523 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2525 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2526 struct displaymodescallback_context cbcontext
;
2527 DDSURFACEDESC2 surface_desc2
;
2529 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2530 iface
, flags
, surface_desc
, context
, callback
);
2532 cbcontext
.func
= callback
;
2533 cbcontext
.context
= context
;
2535 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2536 return ddraw7_EnumDisplayModes(&ddraw
->IDirectDraw7_iface
, flags
,
2537 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2540 /*****************************************************************************
2541 * IDirectDraw7::EvaluateMode
2543 * Used with IDirectDraw7::StartModeTest to test video modes.
2544 * EvaluateMode is used to pass or fail a mode, and continue with the next
2548 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
2549 * Timeout: Returns the amount of seconds left before the mode would have
2550 * been failed automatically
2553 * This implementation always DD_OK, because it's a stub
2555 *****************************************************************************/
2556 static HRESULT WINAPI
ddraw7_EvaluateMode(IDirectDraw7
*iface
, DWORD Flags
, DWORD
*Timeout
)
2558 FIXME("iface %p, flags %#x, timeout %p stub!\n", iface
, Flags
, Timeout
);
2560 /* When implementing this, implement it in WineD3D */
2565 /*****************************************************************************
2566 * IDirectDraw7::GetDeviceIdentifier
2568 * Returns the device identifier, which gives information about the driver
2569 * Our device identifier is defined at the beginning of this file.
2572 * DDDI: Address for the returned structure
2573 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
2576 * On success it returns DD_OK
2577 * DDERR_INVALIDPARAMS if DDDI is NULL
2579 *****************************************************************************/
2580 static HRESULT WINAPI
ddraw7_GetDeviceIdentifier(IDirectDraw7
*iface
,
2581 DDDEVICEIDENTIFIER2
*DDDI
, DWORD Flags
)
2583 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2584 struct wined3d_adapter_identifier adapter_id
;
2587 TRACE("iface %p, device_identifier %p, flags %#x.\n", iface
, DDDI
, Flags
);
2590 return DDERR_INVALIDPARAMS
;
2592 if (Flags
& DDGDI_GETHOSTIDENTIFIER
)
2594 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
2595 * host adapter, if there's a secondary 3D adapter. This doesn't apply
2596 * to any modern hardware, nor is it interesting for Wine, so ignore it.
2597 * Size of DDDEVICEIDENTIFIER2 may be aligned to 8 bytes and thus 4
2598 * bytes too long. So only copy the relevant part of the structure
2601 memcpy(DDDI
, &deviceidentifier
, FIELD_OFFSET(DDDEVICEIDENTIFIER2
, dwWHQLLevel
) + sizeof(DWORD
));
2605 /* Drakan: Order of the Flame expects accurate D3D device information from ddraw */
2606 adapter_id
.driver
= DDDI
->szDriver
;
2607 adapter_id
.driver_size
= sizeof(DDDI
->szDriver
);
2608 adapter_id
.description
= DDDI
->szDescription
;
2609 adapter_id
.description_size
= sizeof(DDDI
->szDescription
);
2610 adapter_id
.device_name_size
= 0;
2611 wined3d_mutex_lock();
2612 hr
= wined3d_get_adapter_identifier(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, 0x0, &adapter_id
);
2613 wined3d_mutex_unlock();
2614 if (FAILED(hr
)) return hr
;
2616 DDDI
->liDriverVersion
= adapter_id
.driver_version
;
2617 DDDI
->dwVendorId
= adapter_id
.vendor_id
;
2618 DDDI
->dwDeviceId
= adapter_id
.device_id
;
2619 DDDI
->dwSubSysId
= adapter_id
.subsystem_id
;
2620 DDDI
->dwRevision
= adapter_id
.revision
;
2621 DDDI
->guidDeviceIdentifier
= adapter_id
.device_identifier
;
2622 DDDI
->dwWHQLLevel
= adapter_id
.whql_level
;
2626 static HRESULT WINAPI
ddraw4_GetDeviceIdentifier(IDirectDraw4
*iface
,
2627 DDDEVICEIDENTIFIER
*identifier
, DWORD flags
)
2629 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2630 DDDEVICEIDENTIFIER2 identifier2
;
2633 TRACE("iface %p, identifier %p, flags %#x.\n", iface
, identifier
, flags
);
2635 hr
= ddraw7_GetDeviceIdentifier(&ddraw
->IDirectDraw7_iface
, &identifier2
, flags
);
2636 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&identifier2
, identifier
);
2641 /*****************************************************************************
2642 * IDirectDraw7::GetSurfaceFromDC
2644 * Returns the Surface for a GDI device context handle.
2645 * Is this related to IDirectDrawSurface::GetDC ???
2648 * hdc: hdc to return the surface for
2649 * Surface: Address to write the surface pointer to
2652 * Always returns DD_OK because it's a stub
2654 *****************************************************************************/
2655 static HRESULT WINAPI
ddraw7_GetSurfaceFromDC(IDirectDraw7
*iface
,
2656 HDC dc
, IDirectDrawSurface7
**surface
)
2658 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2659 struct ddraw_surface
*surface_impl
;
2661 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2664 return E_INVALIDARG
;
2669 wined3d_mutex_lock();
2670 LIST_FOR_EACH_ENTRY(surface_impl
, &ddraw
->surface_list
, struct ddraw_surface
, surface_list_entry
)
2672 if (surface_impl
->dc
!= dc
)
2675 TRACE("Found surface %p for dc %p.\n", surface_impl
, dc
);
2676 *surface
= &surface_impl
->IDirectDrawSurface7_iface
;
2677 IDirectDrawSurface7_AddRef(*surface
);
2678 wined3d_mutex_unlock();
2681 wined3d_mutex_unlock();
2684 TRACE("No surface found for dc %p.\n", dc
);
2686 return DDERR_NOTFOUND
;
2689 static HRESULT WINAPI
ddraw4_GetSurfaceFromDC(IDirectDraw4
*iface
, HDC dc
,
2690 IDirectDrawSurface4
**surface
)
2692 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2693 struct ddraw_surface
*surface_impl
;
2694 IDirectDrawSurface7
*surface7
;
2697 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2699 if (!surface
) return E_INVALIDARG
;
2701 hr
= ddraw7_GetSurfaceFromDC(&ddraw
->IDirectDraw7_iface
, dc
, &surface7
);
2707 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2708 /* Tests say this is true */
2709 *surface
= (IDirectDrawSurface4
*)&surface_impl
->IDirectDrawSurface_iface
;
2710 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2711 IDirectDrawSurface7_Release(surface7
);
2716 static HRESULT CALLBACK
restore_callback(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*desc
, void *context
)
2718 IDirectDrawSurface_Restore(surface
);
2719 IDirectDrawSurface_Release(surface
);
2721 return DDENUMRET_OK
;
2724 static HRESULT WINAPI
ddraw7_RestoreAllSurfaces(IDirectDraw7
*iface
)
2726 TRACE("iface %p.\n", iface
);
2728 return IDirectDraw7_EnumSurfaces(iface
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
2729 NULL
, NULL
, restore_callback
);
2732 static HRESULT WINAPI
ddraw4_RestoreAllSurfaces(IDirectDraw4
*iface
)
2734 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2736 TRACE("iface %p.\n", iface
);
2738 return ddraw7_RestoreAllSurfaces(&ddraw
->IDirectDraw7_iface
);
2741 /*****************************************************************************
2742 * IDirectDraw7::StartModeTest
2744 * Tests the specified video modes to update the system registry with
2745 * refresh rate information. StartModeTest starts the mode test,
2746 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
2747 * isn't called within 15 seconds, the mode is failed automatically
2749 * As refresh rates are handled by the X server, I don't think this
2750 * Method is important
2753 * Modes: An array of mode specifications
2754 * NumModes: The number of modes in Modes
2755 * Flags: Some flags...
2758 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
2759 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
2762 *****************************************************************************/
2763 static HRESULT WINAPI
ddraw7_StartModeTest(IDirectDraw7
*iface
, SIZE
*Modes
, DWORD NumModes
, DWORD Flags
)
2765 FIXME("iface %p, modes %p, mode_count %u, flags %#x partial stub!\n",
2766 iface
, Modes
, NumModes
, Flags
);
2768 /* This looks sane */
2769 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
2771 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
2772 * As it is not, DDERR_TESTFINISHED is returned
2773 * (hopefully that's correct
2775 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
2776 * well, that value doesn't (yet) exist in the wine headers, so ignore it
2782 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
, DDSURFACEDESC2
*surface_desc
,
2783 IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
2785 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
2786 struct ddraw_surface
*impl
;
2789 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2790 iface
, surface_desc
, surface
, outer_unknown
);
2792 wined3d_mutex_lock();
2794 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2796 WARN("Cooperative level not set.\n");
2797 wined3d_mutex_unlock();
2798 return DDERR_NOCOOPERATIVELEVELSET
;
2801 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2803 WARN("Application supplied invalid surface descriptor\n");
2804 wined3d_mutex_unlock();
2805 return DDERR_INVALIDPARAMS
;
2814 WARN("Surface pointer %p is invalid.\n", surface
);
2815 wined3d_mutex_unlock();
2816 return DDERR_INVALIDPARAMS
;
2820 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2822 if (TRACE_ON(ddraw
))
2824 TRACE(" (%p) Requesting surface desc :\n", iface
);
2825 DDRAW_dump_surface_desc(surface_desc
);
2828 WARN("Application tried to create an explicit front or back buffer\n");
2829 wined3d_mutex_unlock();
2830 return DDERR_INVALIDCAPS
;
2833 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 7);
2834 wined3d_mutex_unlock();
2838 *surface
= &impl
->IDirectDrawSurface7_iface
;
2839 IDirectDraw7_AddRef(iface
);
2840 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2845 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
2846 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
2848 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
2849 struct ddraw_surface
*impl
;
2852 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2853 iface
, surface_desc
, surface
, outer_unknown
);
2855 wined3d_mutex_lock();
2857 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2859 WARN("Cooperative level not set.\n");
2860 wined3d_mutex_unlock();
2861 return DDERR_NOCOOPERATIVELEVELSET
;
2864 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
2866 WARN("Application supplied invalid surface descriptor\n");
2867 wined3d_mutex_unlock();
2868 return DDERR_INVALIDPARAMS
;
2877 WARN("Surface pointer %p is invalid.\n", surface
);
2878 wined3d_mutex_unlock();
2879 return DDERR_INVALIDPARAMS
;
2883 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2885 if (TRACE_ON(ddraw
))
2887 TRACE(" (%p) Requesting surface desc :\n", iface
);
2888 DDRAW_dump_surface_desc(surface_desc
);
2891 WARN("Application tried to create an explicit front or back buffer\n");
2892 wined3d_mutex_unlock();
2893 return DDERR_INVALIDCAPS
;
2896 hr
= ddraw_surface_create(ddraw
, surface_desc
, &impl
, outer_unknown
, 4);
2897 wined3d_mutex_unlock();
2901 *surface
= &impl
->IDirectDrawSurface4_iface
;
2902 IDirectDraw4_AddRef(iface
);
2903 impl
->ifaceToRelease
= (IUnknown
*)iface
;
2908 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
2909 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2911 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
2912 struct ddraw_surface
*impl
;
2914 DDSURFACEDESC2 surface_desc2
;
2916 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2917 iface
, surface_desc
, surface
, outer_unknown
);
2919 wined3d_mutex_lock();
2921 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2923 WARN("Cooperative level not set.\n");
2924 wined3d_mutex_unlock();
2925 return DDERR_NOCOOPERATIVELEVELSET
;
2928 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2930 WARN("Application supplied invalid surface descriptor\n");
2931 wined3d_mutex_unlock();
2932 return DDERR_INVALIDPARAMS
;
2941 WARN("Surface pointer %p is invalid.\n", surface
);
2942 wined3d_mutex_unlock();
2943 return DDERR_INVALIDPARAMS
;
2947 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2948 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
2950 if (TRACE_ON(ddraw
))
2952 TRACE(" (%p) Requesting surface desc :\n", iface
);
2953 DDRAW_dump_surface_desc((DDSURFACEDESC2
*)surface_desc
);
2956 WARN("Application tried to create an explicit front or back buffer\n");
2957 wined3d_mutex_unlock();
2958 return DDERR_INVALIDCAPS
;
2961 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 2);
2962 wined3d_mutex_unlock();
2966 *surface
= &impl
->IDirectDrawSurface_iface
;
2967 impl
->ifaceToRelease
= NULL
;
2972 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
2973 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
2975 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
2976 struct ddraw_surface
*impl
;
2978 DDSURFACEDESC2 surface_desc2
;
2980 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2981 iface
, surface_desc
, surface
, outer_unknown
);
2983 wined3d_mutex_lock();
2985 if (!(ddraw
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
2987 WARN("Cooperative level not set.\n");
2988 wined3d_mutex_unlock();
2989 return DDERR_NOCOOPERATIVELEVELSET
;
2992 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
2994 WARN("Application supplied invalid surface descriptor\n");
2995 wined3d_mutex_unlock();
2996 return DDERR_INVALIDPARAMS
;
3005 WARN("Surface pointer %p is invalid.\n", surface
);
3006 wined3d_mutex_unlock();
3007 return DDERR_INVALIDPARAMS
;
3011 if ((surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
))
3012 == (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
)
3013 || (surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
))
3014 == ((DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
)))
3016 WARN("Application tried to create an explicit front or back buffer.\n");
3017 wined3d_mutex_unlock();
3018 return DDERR_INVALIDCAPS
;
3021 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3022 hr
= ddraw_surface_create(ddraw
, &surface_desc2
, &impl
, outer_unknown
, 1);
3023 wined3d_mutex_unlock();
3027 *surface
= &impl
->IDirectDrawSurface_iface
;
3028 impl
->ifaceToRelease
= NULL
;
3034 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
3035 const DDPIXELFORMAT
*provided
)
3037 /* Some flags must be present in both or neither for a match. */
3038 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
3039 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
3040 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
3042 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3045 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
3048 if (requested
->dwFlags
& DDPF_FOURCC
)
3049 if (requested
->dwFourCC
!= provided
->dwFourCC
)
3052 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
3053 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3054 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
3057 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3058 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3059 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
3062 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
3063 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
3066 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
3067 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3069 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
3072 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
3073 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
3079 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3088 #define CMP(FLAG, FIELD) \
3089 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3090 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3092 static const struct compare_info compare
[] =
3094 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3095 CMP(BACKBUFFERCOUNT
, u5
.dwBackBufferCount
),
3097 CMP(CKDESTBLT
, ddckCKDestBlt
),
3098 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3099 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3100 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3101 CMP(HEIGHT
, dwHeight
),
3102 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3103 CMP(LPSURFACE
, lpSurface
),
3104 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3105 CMP(PITCH
, u1
/* lPitch */),
3106 /* PIXELFORMAT: manual */
3107 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3108 CMP(TEXTURESTAGE
, dwTextureStage
),
3109 CMP(WIDTH
, dwWidth
),
3110 /* ZBUFFERBITDEPTH: "obsolete" */
3117 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3120 for (i
=0; i
< ARRAY_SIZE(compare
); i
++)
3122 if (requested
->dwFlags
& compare
[i
].flag
3123 && memcmp((const char *)provided
+ compare
[i
].offset
,
3124 (const char *)requested
+ compare
[i
].offset
,
3125 compare
[i
].size
) != 0)
3129 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3131 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3132 &provided
->u4
.ddpfPixelFormat
))
3139 struct surfacescallback2_context
3141 LPDDENUMSURFACESCALLBACK2 func
;
3145 struct surfacescallback_context
3147 LPDDENUMSURFACESCALLBACK func
;
3151 static HRESULT CALLBACK
EnumSurfacesCallback2Thunk(IDirectDrawSurface7
*surface
,
3152 DDSURFACEDESC2
*surface_desc
, void *context
)
3154 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3155 struct surfacescallback2_context
*cbcontext
= context
;
3157 IDirectDrawSurface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
3158 IDirectDrawSurface7_Release(surface
);
3160 return cbcontext
->func(&surface_impl
->IDirectDrawSurface4_iface
,
3161 surface_desc
, cbcontext
->context
);
3164 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3165 DDSURFACEDESC2
*surface_desc
, void *context
)
3167 struct ddraw_surface
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3168 struct surfacescallback_context
*cbcontext
= context
;
3170 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
3171 IDirectDrawSurface7_Release(surface
);
3173 return cbcontext
->func(&surface_impl
->IDirectDrawSurface_iface
,
3174 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3177 /*****************************************************************************
3178 * IDirectDraw7::EnumSurfaces
3180 * Loops through all surfaces attached to this device and calls the
3181 * application callback. This can't be relayed to WineD3DDevice,
3182 * because some WineD3DSurfaces' parents are IParent objects
3185 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3186 * DDSD: Description to filter for
3187 * Context: Application-provided pointer, it's passed unmodified to the
3189 * Callback: Address to call for each surface
3192 * DDERR_INVALIDPARAMS if the callback is NULL
3195 *****************************************************************************/
3196 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD Flags
,
3197 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMSURFACESCALLBACK7 Callback
)
3199 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3200 struct ddraw_surface
*surf
;
3202 DDSURFACEDESC2 desc
;
3203 struct list
*entry
, *entry2
;
3205 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3206 iface
, Flags
, DDSD
, Context
, Callback
);
3208 all
= Flags
& DDENUMSURFACES_ALL
;
3209 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
3212 return DDERR_INVALIDPARAMS
;
3214 wined3d_mutex_lock();
3216 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
3217 LIST_FOR_EACH_SAFE(entry
, entry2
, &ddraw
->surface_list
)
3219 surf
= LIST_ENTRY(entry
, struct ddraw_surface
, surface_list_entry
);
3221 if (!surf
->iface_count
)
3223 WARN("Not enumerating surface %p because it doesn't have any references.\n", surf
);
3227 if (all
|| (nomatch
!= ddraw_match_surface_desc(DDSD
, &surf
->surface_desc
)))
3229 TRACE("Enumerating surface %p.\n", surf
);
3230 desc
= surf
->surface_desc
;
3231 IDirectDrawSurface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
3232 if (Callback(&surf
->IDirectDrawSurface7_iface
, &desc
, Context
) != DDENUMRET_OK
)
3234 wined3d_mutex_unlock();
3240 wined3d_mutex_unlock();
3245 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3246 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3248 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3249 struct surfacescallback2_context cbcontext
;
3251 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3252 iface
, flags
, surface_desc
, context
, callback
);
3254 cbcontext
.func
= callback
;
3255 cbcontext
.context
= context
;
3257 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
, surface_desc
,
3258 &cbcontext
, EnumSurfacesCallback2Thunk
);
3261 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3262 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3264 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3265 struct surfacescallback_context cbcontext
;
3266 DDSURFACEDESC2 surface_desc2
;
3268 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3269 iface
, flags
, surface_desc
, context
, callback
);
3271 cbcontext
.func
= callback
;
3272 cbcontext
.context
= context
;
3274 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3275 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3276 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3279 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3280 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3282 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3283 struct surfacescallback_context cbcontext
;
3284 DDSURFACEDESC2 surface_desc2
;
3286 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3287 iface
, flags
, surface_desc
, context
, callback
);
3289 cbcontext
.func
= callback
;
3290 cbcontext
.context
= context
;
3292 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3293 return ddraw7_EnumSurfaces(&ddraw
->IDirectDraw7_iface
, flags
,
3294 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3297 /*****************************************************************************
3298 * DirectDrawCreateClipper (DDRAW.@)
3300 * Creates a new IDirectDrawClipper object.
3303 * Clipper: Address to write the interface pointer to
3304 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3308 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3309 * E_OUTOFMEMORY if allocating the object failed
3311 *****************************************************************************/
3312 HRESULT WINAPI
DirectDrawCreateClipper(DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3314 struct ddraw_clipper
*object
;
3317 TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
3318 flags
, clipper
, outer_unknown
);
3321 return CLASS_E_NOAGGREGATION
;
3323 wined3d_mutex_lock();
3325 if (!(object
= heap_alloc_zero(sizeof(*object
))))
3327 wined3d_mutex_unlock();
3328 return E_OUTOFMEMORY
;
3331 hr
= ddraw_clipper_init(object
);
3334 WARN("Failed to initialize clipper, hr %#x.\n", hr
);
3336 wined3d_mutex_unlock();
3340 TRACE("Created clipper %p.\n", object
);
3341 *clipper
= &object
->IDirectDrawClipper_iface
;
3342 wined3d_mutex_unlock();
3347 /*****************************************************************************
3348 * IDirectDraw7::CreateClipper
3350 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3352 *****************************************************************************/
3353 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3354 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3356 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3357 iface
, Flags
, Clipper
, UnkOuter
);
3359 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3362 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
, DWORD flags
,
3363 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3365 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3367 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3368 iface
, flags
, clipper
, outer_unknown
);
3370 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3373 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
3374 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3376 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3378 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3379 iface
, flags
, clipper
, outer_unknown
);
3381 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3384 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
3385 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3387 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3389 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3390 iface
, flags
, clipper
, outer_unknown
);
3392 return ddraw7_CreateClipper(&ddraw
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3395 /*****************************************************************************
3396 * IDirectDraw7::CreatePalette
3398 * Creates a new IDirectDrawPalette object
3401 * Flags: The flags for the new clipper
3402 * ColorTable: Color table to assign to the new clipper
3403 * Palette: Address to write the interface pointer to
3404 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3408 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3409 * E_OUTOFMEMORY if allocating the object failed
3411 *****************************************************************************/
3412 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
3413 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
3415 struct ddraw
*ddraw
= impl_from_IDirectDraw7(iface
);
3416 struct ddraw_palette
*object
;
3419 TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
3420 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3423 return CLASS_E_NOAGGREGATION
;
3425 wined3d_mutex_lock();
3427 /* The refcount test shows that a cooplevel is required for this */
3428 if (!ddraw
->cooperative_level
)
3430 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3431 wined3d_mutex_unlock();
3432 return DDERR_NOCOOPERATIVELEVELSET
;
3435 if (!(object
= heap_alloc(sizeof(*object
))))
3437 ERR("Out of memory when allocating memory for a palette implementation\n");
3438 wined3d_mutex_unlock();
3439 return E_OUTOFMEMORY
;
3442 hr
= ddraw_palette_init(object
, ddraw
, Flags
, ColorTable
);
3445 WARN("Failed to initialize palette, hr %#x.\n", hr
);
3447 wined3d_mutex_unlock();
3451 TRACE("Created palette %p.\n", object
);
3452 *Palette
= &object
->IDirectDrawPalette_iface
;
3453 wined3d_mutex_unlock();
3458 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
, PALETTEENTRY
*entries
,
3459 IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3461 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3464 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3465 iface
, flags
, entries
, palette
, outer_unknown
);
3467 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3468 if (SUCCEEDED(hr
) && *palette
)
3470 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3471 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3472 IDirectDraw4_AddRef(iface
);
3473 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3478 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
3479 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3481 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3484 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3485 iface
, flags
, entries
, palette
, outer_unknown
);
3487 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3488 if (SUCCEEDED(hr
) && *palette
)
3490 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3491 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3492 impl
->ifaceToRelease
= NULL
;
3498 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
3499 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3501 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3504 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3505 iface
, flags
, entries
, palette
, outer_unknown
);
3507 hr
= ddraw7_CreatePalette(&ddraw
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3508 if (SUCCEEDED(hr
) && *palette
)
3510 struct ddraw_palette
*impl
= impl_from_IDirectDrawPalette(*palette
);
3511 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
3512 impl
->ifaceToRelease
= NULL
;
3518 /*****************************************************************************
3519 * IDirectDraw7::DuplicateSurface
3521 * Duplicates a surface. The surface memory points to the same memory as
3522 * the original surface, and it's released when the last surface referencing
3523 * it is released. I guess that's beyond Wine's surface management right now
3524 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3525 * test application to implement this)
3528 * Src: Address of the source surface
3529 * Dest: Address to write the new surface pointer to
3532 * See IDirectDraw7::CreateSurface
3534 *****************************************************************************/
3535 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
3536 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
3538 struct ddraw_surface
*src_surface
= unsafe_impl_from_IDirectDrawSurface7(Src
);
3540 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
3542 /* For now, simply create a new, independent surface */
3543 return IDirectDraw7_CreateSurface(iface
, &src_surface
->surface_desc
, Dest
, NULL
);
3546 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
, IDirectDrawSurface4
*src
,
3547 IDirectDrawSurface4
**dst
)
3549 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
3550 struct ddraw
*ddraw
= impl_from_IDirectDraw4(iface
);
3551 struct ddraw_surface
*dst_impl
;
3552 IDirectDrawSurface7
*dst7
;
3555 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3557 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3558 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3564 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3565 *dst
= &dst_impl
->IDirectDrawSurface4_iface
;
3566 IDirectDrawSurface4_AddRef(*dst
);
3567 IDirectDrawSurface7_Release(dst7
);
3572 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
3573 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
3575 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3576 struct ddraw
*ddraw
= impl_from_IDirectDraw2(iface
);
3577 struct ddraw_surface
*dst_impl
;
3578 IDirectDrawSurface7
*dst7
;
3581 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3583 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3584 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3587 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3588 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3589 IDirectDrawSurface_AddRef(*dst
);
3590 IDirectDrawSurface7_Release(dst7
);
3595 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
, IDirectDrawSurface
*src
,
3596 IDirectDrawSurface
**dst
)
3598 struct ddraw_surface
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3599 struct ddraw
*ddraw
= impl_from_IDirectDraw(iface
);
3600 struct ddraw_surface
*dst_impl
;
3601 IDirectDrawSurface7
*dst7
;
3604 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3606 hr
= ddraw7_DuplicateSurface(&ddraw
->IDirectDraw7_iface
,
3607 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3610 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3611 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3612 IDirectDrawSurface_AddRef(*dst
);
3613 IDirectDrawSurface7_Release(dst7
);
3618 /*****************************************************************************
3619 * IDirect3D7::EnumDevices
3621 * The EnumDevices method for IDirect3D7. It enumerates all supported
3622 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
3625 * callback: Function to call for each enumerated device
3626 * context: Pointer to pass back to the app
3629 * D3D_OK, or the return value of the GetCaps call
3631 *****************************************************************************/
3632 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
3634 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
3635 D3DDEVICEDESC7 device_desc7
;
3639 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3642 return DDERR_INVALIDPARAMS
;
3644 wined3d_mutex_lock();
3646 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3648 wined3d_mutex_unlock();
3652 for (i
= 0; i
< ARRAY_SIZE(device_list7
); i
++)
3656 device_desc7
.deviceGUID
= *device_list7
[i
].device_guid
;
3657 ret
= callback(device_list7
[i
].interface_name
, device_list7
[i
].device_name
, &device_desc7
, context
);
3658 if (ret
!= DDENUMRET_OK
)
3660 TRACE("Application cancelled the enumeration.\n");
3661 wined3d_mutex_unlock();
3666 TRACE("End of enumeration.\n");
3668 wined3d_mutex_unlock();
3673 /*****************************************************************************
3674 * IDirect3D3::EnumDevices
3676 * Enumerates all supported Direct3DDevice interfaces. This is the
3677 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
3679 * Versions 1, 2 and 3
3682 * callback: Application-provided routine to call for each enumerated device
3683 * Context: Pointer to pass to the callback
3686 * D3D_OK on success,
3687 * The result of IDirect3DImpl_GetCaps if it failed
3689 *****************************************************************************/
3690 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3692 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
3694 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3695 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
3696 D3DDEVICEDESC7 device_desc7
;
3699 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
3700 * name string. Let's put the string in a sufficiently sized array in
3701 * writable memory. */
3702 char device_name
[50];
3703 strcpy(device_name
,"Direct3D HEL");
3705 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3708 return DDERR_INVALIDPARAMS
;
3710 wined3d_mutex_lock();
3712 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &device_desc7
)))
3714 wined3d_mutex_unlock();
3717 ddraw_d3dcaps1_from_7(&device_desc1
, &device_desc7
);
3719 /* Do I have to enumerate the reference id? Note from old d3d7:
3720 * "It seems that enumerating the reference IID on Direct3D 1 games
3721 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
3723 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
3724 * EnumReference which enables / disables enumerating the reference
3725 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
3726 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
3727 * demo directory suggest this.
3729 * Some games(GTA 2) seem to use the second enumerated device, so I have
3730 * to enumerate at least 2 devices. So enumerate the reference device to
3733 * Other games (Rollcage) tell emulation and hal device apart by certain
3734 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
3735 * limitation flag), and it refuses all devices that have the perspective
3736 * flag set. This way it refuses the emulation device, and HAL devices
3737 * never have POW2 unset in d3d7 on windows. */
3738 if (ddraw
->d3dversion
!= 1)
3740 static CHAR reference_description
[] = "RGB Direct3D emulation";
3742 TRACE("Enumerating WineD3D D3DDevice interface.\n");
3743 hal_desc
= device_desc1
;
3744 hel_desc
= device_desc1
;
3745 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
3746 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3747 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3748 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3749 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3750 /* RGB, RAMP and MMX devices have a HAL dcmColorModel of 0 */
3751 hal_desc
.dcmColorModel
= 0;
3752 /* RGB, RAMP and MMX devices cannot report HAL hardware flags */
3753 hal_desc
.dwFlags
= 0;
3755 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
3756 device_name
, &hal_desc
, &hel_desc
, context
);
3757 if (hr
!= D3DENUMRET_OK
)
3759 TRACE("Application cancelled the enumeration.\n");
3760 wined3d_mutex_unlock();
3765 strcpy(device_name
,"Direct3D HAL");
3767 TRACE("Enumerating HAL Direct3D device.\n");
3768 hal_desc
= device_desc1
;
3769 hel_desc
= device_desc1
;
3771 /* The hal device does not have the pow2 flag set in hel, but in hal. */
3772 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3773 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3774 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3775 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3776 /* HAL devices have a HEL dcmColorModel of 0 */
3777 hel_desc
.dcmColorModel
= 0;
3779 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
3780 device_name
, &hal_desc
, &hel_desc
, context
);
3781 if (hr
!= D3DENUMRET_OK
)
3783 TRACE("Application cancelled the enumeration.\n");
3784 wined3d_mutex_unlock();
3788 TRACE("End of enumeration.\n");
3790 wined3d_mutex_unlock();
3795 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3797 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3799 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3801 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3804 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3806 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3808 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3810 return d3d3_EnumDevices(&ddraw
->IDirect3D3_iface
, callback
, context
);
3813 /*****************************************************************************
3814 * IDirect3D3::CreateLight
3816 * Creates an IDirect3DLight interface. This interface is used in
3817 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
3818 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
3819 * uses the IDirect3DDevice7 interface with D3D7 lights.
3821 * Versions 1, 2 and 3
3824 * light: Address to store the new interface pointer
3825 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3830 * DDERR_OUTOFMEMORY if memory allocation failed
3831 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3833 *****************************************************************************/
3834 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
,
3835 IUnknown
*outer_unknown
)
3837 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3838 struct d3d_light
*object
;
3840 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3843 return CLASS_E_NOAGGREGATION
;
3845 if (!(object
= heap_alloc_zero(sizeof(*object
))))
3847 ERR("Failed to allocate light memory.\n");
3848 return DDERR_OUTOFMEMORY
;
3851 d3d_light_init(object
, ddraw
);
3853 TRACE("Created light %p.\n", object
);
3854 *light
= &object
->IDirect3DLight_iface
;
3859 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3861 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3863 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3865 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3868 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
3870 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3872 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3874 return d3d3_CreateLight(&ddraw
->IDirect3D3_iface
, light
, outer_unknown
);
3877 /*****************************************************************************
3878 * IDirect3D3::CreateMaterial
3880 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
3881 * and older versions. The IDirect3DMaterial implementation wraps its
3882 * functionality to IDirect3DDevice7::SetMaterial and friends.
3884 * Versions 1, 2 and 3
3887 * material: Address to store the new interface's pointer to
3888 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3893 * DDERR_OUTOFMEMORY if memory allocation failed
3894 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3896 *****************************************************************************/
3897 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
,
3898 IUnknown
*outer_unknown
)
3900 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3901 struct d3d_material
*object
;
3903 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3905 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3907 object
= d3d_material_create(ddraw
);
3910 ERR("Failed to allocate material memory.\n");
3911 return DDERR_OUTOFMEMORY
;
3914 TRACE("Created material %p.\n", object
);
3915 *material
= &object
->IDirect3DMaterial3_iface
;
3920 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
,
3921 IUnknown
*outer_unknown
)
3923 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
3924 struct d3d_material
*object
;
3926 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3928 object
= d3d_material_create(ddraw
);
3931 ERR("Failed to allocate material memory.\n");
3932 return DDERR_OUTOFMEMORY
;
3935 TRACE("Created material %p.\n", object
);
3936 *material
= &object
->IDirect3DMaterial2_iface
;
3941 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
,
3942 IUnknown
*outer_unknown
)
3944 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
3945 struct d3d_material
*object
;
3947 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
3949 object
= d3d_material_create(ddraw
);
3952 ERR("Failed to allocate material memory.\n");
3953 return DDERR_OUTOFMEMORY
;
3956 TRACE("Created material %p.\n", object
);
3957 *material
= &object
->IDirect3DMaterial_iface
;
3962 /*****************************************************************************
3963 * IDirect3D3::CreateViewport
3965 * Creates an IDirect3DViewport interface. This interface is used
3966 * by Direct3D and earlier versions for Viewport management. In Direct3D7
3967 * it has been replaced by a viewport structure and
3968 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
3969 * uses the IDirect3DDevice7 methods for its functionality
3972 * Viewport: Address to store the new interface pointer
3973 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3978 * DDERR_OUTOFMEMORY if memory allocation failed
3979 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3981 *****************************************************************************/
3982 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
,
3983 IUnknown
*outer_unknown
)
3985 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
3986 struct d3d_viewport
*object
;
3988 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
3990 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3992 if (!(object
= heap_alloc_zero(sizeof(*object
))))
3994 ERR("Failed to allocate viewport memory.\n");
3995 return DDERR_OUTOFMEMORY
;
3998 d3d_viewport_init(object
, ddraw
);
4000 TRACE("Created viewport %p.\n", object
);
4001 *viewport
= &object
->IDirect3DViewport3_iface
;
4006 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
4008 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4010 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4012 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4016 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
4018 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4020 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4022 return d3d3_CreateViewport(&ddraw
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4026 static HRESULT
ddraw_find_device(struct ddraw
*ddraw
, const D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
,
4027 unsigned int guid_count
, const GUID
* const *guids
, DWORD device_desc_size
)
4029 struct ddraw_find_device_result_v1
4033 D3DDEVICEDESC_V1 hw_desc
;
4034 D3DDEVICEDESC_V1 sw_desc
;
4036 struct ddraw_find_device_result_v2
4040 D3DDEVICEDESC_V2 hw_desc
;
4041 D3DDEVICEDESC_V2 sw_desc
;
4043 D3DDEVICEDESC7 desc7
;
4044 D3DDEVICEDESC desc1
;
4048 TRACE("ddraw %p, fds %p, fdr %p, guid_count %u, guids %p, device_desc_size %u.\n",
4049 ddraw
, fds
, fdr
, guid_count
, guids
, device_desc_size
);
4052 return DDERR_INVALIDPARAMS
;
4054 if (fds
->dwSize
!= sizeof(*fds
))
4056 WARN("Got invalid search structure size %u.\n", fds
->dwSize
);
4057 return DDERR_INVALIDPARAMS
;
4060 if (fdr
->dwSize
!= sizeof(*fdr
) && fdr
->dwSize
!= sizeof(*fdr2
) && fdr
->dwSize
!= sizeof(*fdr1
))
4062 WARN("Got invalid result structure size %u.\n", fdr
->dwSize
);
4063 return DDERR_INVALIDPARAMS
;
4066 if (fds
->dwFlags
& D3DFDS_COLORMODEL
)
4067 WARN("Ignoring colour model %#x.\n", fds
->dcmColorModel
);
4069 if (fds
->dwFlags
& D3DFDS_GUID
)
4073 TRACE("Trying to match GUID %s.\n", debugstr_guid(&fds
->guid
));
4075 if ((ddraw
->flags
& DDRAW_NO3D
) && IsEqualGUID(&fds
->guid
, &IID_IDirect3DHALDevice
))
4077 WARN("HAL device not available without 3D support.\n");
4078 return DDERR_NOTFOUND
;
4081 for (i
= 0; i
< guid_count
; ++i
)
4083 if (IsEqualGUID(guids
[i
], &fds
->guid
))
4092 WARN("Failed to match GUID %s.\n", debugstr_guid(&fds
->guid
));
4093 return DDERR_NOTFOUND
;
4098 if (FAILED(hr
= ddraw_get_d3dcaps(ddraw
, &desc7
)))
4101 /* Now return our own GUID */
4102 ddraw_d3dcaps1_from_7(&desc1
, &desc7
);
4103 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4105 /* Note that "device_desc_size" doesn't necessarily have any relation to
4106 * the actual structure size. However, this matches the behaviour of
4107 * Windows since at least Windows 2000. */
4108 if (fdr
->dwSize
== sizeof(*fdr1
))
4110 fdr1
= (struct ddraw_find_device_result_v1
*)fdr
;
4111 memcpy(&fdr1
->hw_desc
, &desc1
, sizeof(fdr1
->hw_desc
));
4112 fdr1
->hw_desc
.dwSize
= device_desc_size
;
4113 memcpy(&fdr1
->sw_desc
, &desc1
, sizeof(fdr1
->sw_desc
));
4114 fdr1
->sw_desc
.dwSize
= device_desc_size
;
4116 else if (fdr
->dwSize
== sizeof(*fdr2
))
4118 fdr2
= (struct ddraw_find_device_result_v2
*)fdr
;
4119 memcpy(&fdr2
->hw_desc
, &desc1
, sizeof(fdr2
->hw_desc
));
4120 fdr2
->hw_desc
.dwSize
= device_desc_size
;
4121 memcpy(&fdr2
->sw_desc
, &desc1
, sizeof(fdr2
->sw_desc
));
4122 fdr2
->sw_desc
.dwSize
= device_desc_size
;
4126 fdr
->ddHwDesc
= desc1
;
4127 fdr
->ddHwDesc
.dwSize
= device_desc_size
;
4128 fdr
->ddSwDesc
= desc1
;
4129 fdr
->ddSwDesc
.dwSize
= device_desc_size
;
4132 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4137 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4139 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4140 static const GUID
* const guids
[] =
4142 &IID_D3DDEVICE_WineD3D
,
4143 &IID_IDirect3DHALDevice
,
4144 &IID_IDirect3DRGBDevice
,
4147 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4149 return ddraw_find_device(ddraw
, fds
, fdr
, ARRAY_SIZE(guids
), guids
, sizeof(D3DDEVICEDESC_V3
));
4152 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4154 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4155 static const GUID
* const guids
[] =
4157 &IID_D3DDEVICE_WineD3D
,
4158 &IID_IDirect3DHALDevice
,
4159 &IID_IDirect3DMMXDevice
,
4160 &IID_IDirect3DRGBDevice
,
4161 &IID_IDirect3DRampDevice
,
4164 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4166 return ddraw_find_device(ddraw
, fds
, fdr
, ARRAY_SIZE(guids
), guids
, sizeof(D3DDEVICEDESC_V2
));
4169 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4171 struct ddraw
*ddraw
= impl_from_IDirect3D(iface
);
4172 static const GUID
* const guids
[] =
4174 &IID_D3DDEVICE_WineD3D
,
4175 &IID_IDirect3DHALDevice
,
4176 &IID_IDirect3DRGBDevice
,
4177 &IID_IDirect3DRampDevice
,
4180 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4182 return ddraw_find_device(ddraw
, fds
, fdr
, ARRAY_SIZE(guids
), guids
, sizeof(D3DDEVICEDESC_V1
));
4185 /*****************************************************************************
4186 * IDirect3D7::CreateDevice
4188 * Creates an IDirect3DDevice7 interface.
4190 * Versions 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4191 * DirectDraw surfaces and are created with
4192 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4193 * create the device object and QueryInterfaces for IDirect3DDevice
4196 * refiid: IID of the device to create
4197 * Surface: Initial rendertarget
4198 * Device: Address to return the interface pointer
4202 * DDERR_OUTOFMEMORY if memory allocation failed
4203 * DDERR_INVALIDPARAMS if a device exists already
4205 *****************************************************************************/
4206 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4207 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4209 struct ddraw_surface
*target
= unsafe_impl_from_IDirectDrawSurface7(surface
);
4210 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4211 struct d3d_device
*object
;
4214 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4216 wined3d_mutex_lock();
4217 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, target
, (IUnknown
*)surface
, 7, &object
, NULL
)))
4219 *device
= &object
->IDirect3DDevice7_iface
;
4223 WARN("Failed to create device, hr %#x.\n", hr
);
4226 wined3d_mutex_unlock();
4231 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4232 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4234 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface4(surface
);
4235 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4236 struct d3d_device
*device_impl
;
4239 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4240 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4243 return CLASS_E_NOAGGREGATION
;
4245 wined3d_mutex_lock();
4246 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 3, &device_impl
, NULL
)))
4248 *device
= &device_impl
->IDirect3DDevice3_iface
;
4252 WARN("Failed to create device, hr %#x.\n", hr
);
4255 wined3d_mutex_unlock();
4260 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4261 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4263 struct ddraw_surface
*surface_impl
= unsafe_impl_from_IDirectDrawSurface(surface
);
4264 struct ddraw
*ddraw
= impl_from_IDirect3D2(iface
);
4265 struct d3d_device
*device_impl
;
4268 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4269 iface
, debugstr_guid(riid
), surface
, device
);
4271 wined3d_mutex_lock();
4272 if (SUCCEEDED(hr
= d3d_device_create(ddraw
, surface_impl
, (IUnknown
*)surface
, 2, &device_impl
, NULL
)))
4274 *device
= &device_impl
->IDirect3DDevice2_iface
;
4278 WARN("Failed to create device, hr %#x.\n", hr
);
4281 wined3d_mutex_unlock();
4286 /*****************************************************************************
4287 * IDirect3D7::CreateVertexBuffer
4289 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4295 * desc: Requested Vertex buffer properties
4296 * vertex_buffer: Address to return the interface pointer at
4297 * flags: Some flags, should be 0
4301 * DDERR_OUTOFMEMORY if memory allocation failed
4302 * DDERR_INVALIDPARAMS if desc or vertex_buffer is NULL
4304 *****************************************************************************/
4305 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4306 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4308 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4309 struct d3d_vertex_buffer
*object
;
4312 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
4313 iface
, desc
, vertex_buffer
, flags
);
4315 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4317 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4320 TRACE("Created vertex buffer %p.\n", object
);
4321 *vertex_buffer
= &object
->IDirect3DVertexBuffer7_iface
;
4324 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4329 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4330 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4332 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4333 struct d3d_vertex_buffer
*object
;
4336 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n",
4337 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4340 return CLASS_E_NOAGGREGATION
;
4341 if (!vertex_buffer
|| !desc
)
4342 return DDERR_INVALIDPARAMS
;
4344 hr
= d3d_vertex_buffer_create(&object
, ddraw
, desc
);
4347 TRACE("Created vertex buffer %p.\n", object
);
4348 *vertex_buffer
= (IDirect3DVertexBuffer
*)&object
->IDirect3DVertexBuffer7_iface
;
4351 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4356 /*****************************************************************************
4357 * IDirect3D7::EnumZBufferFormats
4359 * Enumerates all supported Z buffer pixel formats
4365 * callback: callback to call for each pixel format
4366 * context: Pointer to pass back to the callback
4370 * DDERR_INVALIDPARAMS if callback is NULL
4372 *****************************************************************************/
4373 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4374 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4376 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4377 struct wined3d_display_mode mode
;
4378 enum wined3d_device_type type
;
4382 /* Order matters. Specifically, BattleZone II (full version) expects the
4383 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4384 static const enum wined3d_format_id formats
[] =
4386 WINED3DFMT_S1_UINT_D15_UNORM
,
4387 WINED3DFMT_D16_UNORM
,
4388 WINED3DFMT_X8D24_UNORM
,
4389 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4390 WINED3DFMT_D24_UNORM_S8_UINT
,
4391 WINED3DFMT_D32_UNORM
,
4394 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4395 iface
, debugstr_guid(device_iid
), callback
, context
);
4397 if (!callback
) return DDERR_INVALIDPARAMS
;
4399 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4400 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4401 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4403 TRACE("Asked for HAL device.\n");
4404 type
= WINED3D_DEVICE_TYPE_HAL
;
4406 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4407 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4409 TRACE("Asked for SW device.\n");
4410 type
= WINED3D_DEVICE_TYPE_SW
;
4412 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4414 TRACE("Asked for REF device.\n");
4415 type
= WINED3D_DEVICE_TYPE_REF
;
4417 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4419 TRACE("Asked for NULLREF device.\n");
4420 type
= WINED3D_DEVICE_TYPE_NULLREF
;
4424 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4425 type
= WINED3D_DEVICE_TYPE_HAL
;
4428 wined3d_mutex_lock();
4429 /* We need an adapter format from somewhere to please wined3d and WGL.
4430 * Use the current display mode. So far all cards offer the same depth
4431 * stencil format for all modes, but if some do not and applications do
4432 * not like that we'll have to find some workaround, like iterating over
4433 * all imaginable formats and collecting all the depth stencil formats we
4435 if (FAILED(hr
= wined3d_get_adapter_display_mode(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, &mode
, NULL
)))
4437 ERR("Failed to get display mode, hr %#x.\n", hr
);
4438 wined3d_mutex_unlock();
4442 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
)
4444 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
,
4445 mode
.format_id
, 0, WINED3D_BIND_DEPTH_STENCIL
, WINED3D_RTYPE_TEXTURE_2D
, formats
[i
])))
4447 DDPIXELFORMAT pformat
;
4449 memset(&pformat
, 0, sizeof(pformat
));
4450 pformat
.dwSize
= sizeof(pformat
);
4451 ddrawformat_from_wined3dformat(&pformat
, formats
[i
]);
4453 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
4454 hr
= callback(&pformat
, context
);
4455 if (hr
!= DDENUMRET_OK
)
4457 TRACE("Format enumeration cancelled by application.\n");
4458 wined3d_mutex_unlock();
4464 /* Historically some windows drivers used dwZBufferBitDepth=24 for WINED3DFMT_X8D24_UNORM,
4465 * while others used dwZBufferBitDepth=32. In either case the pitch matches a 32 bits per
4466 * pixel format, so we use dwZBufferBitDepth=32. Some games expect 24. Windows Vista and
4467 * newer enumerate both versions, so we do the same(bug 22434) */
4468 if (SUCCEEDED(wined3d_check_device_format(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4469 0, WINED3D_BIND_DEPTH_STENCIL
, WINED3D_RTYPE_TEXTURE_2D
, WINED3DFMT_X8D24_UNORM
)))
4471 DDPIXELFORMAT x8d24
=
4473 sizeof(x8d24
), DDPF_ZBUFFER
, 0,
4474 {24}, {0x00000000}, {0x00ffffff}, {0x00000000}
4476 TRACE("Enumerating WINED3DFMT_X8D24_UNORM, dwZBufferBitDepth=24 version\n");
4477 callback(&x8d24
, context
);
4480 TRACE("End of enumeration.\n");
4482 wined3d_mutex_unlock();
4487 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
4488 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4490 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4492 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4493 iface
, debugstr_guid(device_iid
), callback
, context
);
4495 return d3d7_EnumZBufferFormats(&ddraw
->IDirect3D7_iface
, device_iid
, callback
, context
);
4498 /*****************************************************************************
4499 * IDirect3D7::EvictManagedTextures
4501 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
4502 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
4507 * D3D_OK, because it's a stub
4509 *****************************************************************************/
4510 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
4512 struct ddraw
*ddraw
= impl_from_IDirect3D7(iface
);
4514 TRACE("iface %p!\n", iface
);
4516 wined3d_mutex_lock();
4517 if (ddraw
->flags
& DDRAW_D3D_INITIALIZED
)
4518 wined3d_device_evict_managed_resources(ddraw
->wined3d_device
);
4519 wined3d_mutex_unlock();
4524 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
4526 struct ddraw
*ddraw
= impl_from_IDirect3D3(iface
);
4528 TRACE("iface %p.\n", iface
);
4530 return d3d7_EvictManagedTextures(&ddraw
->IDirect3D7_iface
);
4533 /*****************************************************************************
4534 * IDirectDraw7 VTable
4535 *****************************************************************************/
4536 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
4539 ddraw7_QueryInterface
,
4544 ddraw7_CreateClipper
,
4545 ddraw7_CreatePalette
,
4546 ddraw7_CreateSurface
,
4547 ddraw7_DuplicateSurface
,
4548 ddraw7_EnumDisplayModes
,
4549 ddraw7_EnumSurfaces
,
4550 ddraw7_FlipToGDISurface
,
4552 ddraw7_GetDisplayMode
,
4553 ddraw7_GetFourCCCodes
,
4554 ddraw7_GetGDISurface
,
4555 ddraw7_GetMonitorFrequency
,
4557 ddraw7_GetVerticalBlankStatus
,
4559 ddraw7_RestoreDisplayMode
,
4560 ddraw7_SetCooperativeLevel
,
4561 ddraw7_SetDisplayMode
,
4562 ddraw7_WaitForVerticalBlank
,
4564 ddraw7_GetAvailableVidMem
,
4566 ddraw7_GetSurfaceFromDC
,
4568 ddraw7_RestoreAllSurfaces
,
4569 ddraw7_TestCooperativeLevel
,
4570 ddraw7_GetDeviceIdentifier
,
4572 ddraw7_StartModeTest
,
4576 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
4579 ddraw4_QueryInterface
,
4584 ddraw4_CreateClipper
,
4585 ddraw4_CreatePalette
,
4586 ddraw4_CreateSurface
,
4587 ddraw4_DuplicateSurface
,
4588 ddraw4_EnumDisplayModes
,
4589 ddraw4_EnumSurfaces
,
4590 ddraw4_FlipToGDISurface
,
4592 ddraw4_GetDisplayMode
,
4593 ddraw4_GetFourCCCodes
,
4594 ddraw4_GetGDISurface
,
4595 ddraw4_GetMonitorFrequency
,
4597 ddraw4_GetVerticalBlankStatus
,
4599 ddraw4_RestoreDisplayMode
,
4600 ddraw4_SetCooperativeLevel
,
4601 ddraw4_SetDisplayMode
,
4602 ddraw4_WaitForVerticalBlank
,
4604 ddraw4_GetAvailableVidMem
,
4606 ddraw4_GetSurfaceFromDC
,
4608 ddraw4_RestoreAllSurfaces
,
4609 ddraw4_TestCooperativeLevel
,
4610 ddraw4_GetDeviceIdentifier
,
4613 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
4616 ddraw2_QueryInterface
,
4621 ddraw2_CreateClipper
,
4622 ddraw2_CreatePalette
,
4623 ddraw2_CreateSurface
,
4624 ddraw2_DuplicateSurface
,
4625 ddraw2_EnumDisplayModes
,
4626 ddraw2_EnumSurfaces
,
4627 ddraw2_FlipToGDISurface
,
4629 ddraw2_GetDisplayMode
,
4630 ddraw2_GetFourCCCodes
,
4631 ddraw2_GetGDISurface
,
4632 ddraw2_GetMonitorFrequency
,
4634 ddraw2_GetVerticalBlankStatus
,
4636 ddraw2_RestoreDisplayMode
,
4637 ddraw2_SetCooperativeLevel
,
4638 ddraw2_SetDisplayMode
,
4639 ddraw2_WaitForVerticalBlank
,
4641 ddraw2_GetAvailableVidMem
,
4644 static const struct IDirectDrawVtbl ddraw1_vtbl
=
4647 ddraw1_QueryInterface
,
4652 ddraw1_CreateClipper
,
4653 ddraw1_CreatePalette
,
4654 ddraw1_CreateSurface
,
4655 ddraw1_DuplicateSurface
,
4656 ddraw1_EnumDisplayModes
,
4657 ddraw1_EnumSurfaces
,
4658 ddraw1_FlipToGDISurface
,
4660 ddraw1_GetDisplayMode
,
4661 ddraw1_GetFourCCCodes
,
4662 ddraw1_GetGDISurface
,
4663 ddraw1_GetMonitorFrequency
,
4665 ddraw1_GetVerticalBlankStatus
,
4667 ddraw1_RestoreDisplayMode
,
4668 ddraw1_SetCooperativeLevel
,
4669 ddraw1_SetDisplayMode
,
4670 ddraw1_WaitForVerticalBlank
,
4673 static const struct IDirect3D7Vtbl d3d7_vtbl
=
4675 /* IUnknown methods */
4676 d3d7_QueryInterface
,
4679 /* IDirect3D7 methods */
4682 d3d7_CreateVertexBuffer
,
4683 d3d7_EnumZBufferFormats
,
4684 d3d7_EvictManagedTextures
4687 static const struct IDirect3D3Vtbl d3d3_vtbl
=
4689 /* IUnknown methods */
4690 d3d3_QueryInterface
,
4693 /* IDirect3D3 methods */
4696 d3d3_CreateMaterial
,
4697 d3d3_CreateViewport
,
4700 d3d3_CreateVertexBuffer
,
4701 d3d3_EnumZBufferFormats
,
4702 d3d3_EvictManagedTextures
4705 static const struct IDirect3D2Vtbl d3d2_vtbl
=
4707 /* IUnknown methods */
4708 d3d2_QueryInterface
,
4711 /* IDirect3D2 methods */
4714 d3d2_CreateMaterial
,
4715 d3d2_CreateViewport
,
4720 static const struct IDirect3DVtbl d3d1_vtbl
=
4722 /* IUnknown methods */
4723 d3d1_QueryInterface
,
4726 /* IDirect3D methods */
4730 d3d1_CreateMaterial
,
4731 d3d1_CreateViewport
,
4735 /*****************************************************************************
4738 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
4739 * if none was found.
4741 * This function is in ddraw.c and the DDraw object space because D3D7
4742 * vertex buffers are created using the IDirect3D interface to the ddraw
4743 * object, so they can be valid across D3D devices(theoretically. The ddraw
4744 * object also owns the wined3d device
4748 * fvf: Fvf to find the decl for
4751 * NULL in case of an error, the vertex declaration for the FVF otherwise.
4753 *****************************************************************************/
4754 struct wined3d_vertex_declaration
*ddraw_find_decl(struct ddraw
*This
, DWORD fvf
)
4756 struct wined3d_vertex_declaration
*pDecl
= NULL
;
4758 int p
, low
, high
; /* deliberately signed */
4759 struct FvfToDecl
*convertedDecls
= This
->decls
;
4761 TRACE("Searching for declaration for fvf %08x... ", fvf
);
4764 high
= This
->numConvertedDecls
- 1;
4765 while(low
<= high
) {
4766 p
= (low
+ high
) >> 1;
4768 if(convertedDecls
[p
].fvf
== fvf
) {
4769 TRACE("found %p\n", convertedDecls
[p
].decl
);
4770 return convertedDecls
[p
].decl
;
4771 } else if(convertedDecls
[p
].fvf
< fvf
) {
4777 TRACE("not found. Creating and inserting at position %d.\n", low
);
4779 hr
= wined3d_vertex_declaration_create_from_fvf(This
->wined3d_device
,
4780 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
4781 if (hr
!= S_OK
) return NULL
;
4783 if (This
->declArraySize
== This
->numConvertedDecls
)
4785 unsigned int grow
= max(This
->declArraySize
/ 2, 8);
4787 if (!(convertedDecls
= heap_realloc(convertedDecls
,
4788 (This
->numConvertedDecls
+ grow
) * sizeof(*convertedDecls
))))
4790 wined3d_vertex_declaration_decref(pDecl
);
4793 This
->decls
= convertedDecls
;
4794 This
->declArraySize
+= grow
;
4797 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
4798 convertedDecls
[low
].decl
= pDecl
;
4799 convertedDecls
[low
].fvf
= fvf
;
4800 This
->numConvertedDecls
++;
4802 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
4806 static inline struct ddraw
*ddraw_from_device_parent(struct wined3d_device_parent
*device_parent
)
4808 return CONTAINING_RECORD(device_parent
, struct ddraw
, device_parent
);
4811 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
4812 struct wined3d_device
*device
)
4814 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
4817 /* This is run from device_process_message() in wined3d, we can't take the
4819 /* FIXME: We only get mode change notifications in exclusive mode, but we
4820 * should mark surfaces as lost on mode changes in DDSCL_NORMAL mode as well. */
4821 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
4823 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4824 MONITORINFO monitor_info
;
4828 TRACE("device_parent %p.\n", device_parent
);
4830 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) || !ddraw
->swapchain_window
)
4832 TRACE("Nothing to resize.\n");
4836 monitor
= MonitorFromWindow(ddraw
->swapchain_window
, MONITOR_DEFAULTTOPRIMARY
);
4837 monitor_info
.cbSize
= sizeof(monitor_info
);
4838 if (!GetMonitorInfoW(monitor
, &monitor_info
))
4840 ERR("Failed to get monitor info.\n");
4844 r
= &monitor_info
.rcMonitor
;
4845 TRACE("Resizing window %p to %s.\n", ddraw
->swapchain_window
, wine_dbgstr_rect(r
));
4847 if (!SetWindowPos(ddraw
->swapchain_window
, HWND_TOP
, r
->left
, r
->top
,
4848 r
->right
- r
->left
, r
->bottom
- r
->top
, SWP_SHOWWINDOW
| SWP_NOACTIVATE
))
4849 ERR("Failed to resize window.\n");
4851 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_OK
);
4854 static void CDECL
device_parent_activate(struct wined3d_device_parent
*device_parent
, BOOL activate
)
4856 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4858 TRACE("device_parent %p, activate %#x.\n", device_parent
, activate
);
4862 ddraw
->device_state
= DDRAW_DEVICE_STATE_LOST
;
4863 exclusive_window
= NULL
;
4867 InterlockedCompareExchange(&ddraw
->device_state
, DDRAW_DEVICE_STATE_NOT_RESTORED
, DDRAW_DEVICE_STATE_LOST
);
4871 void ddraw_update_lost_surfaces(struct ddraw
*ddraw
)
4873 struct ddraw_surface
*surface
;
4875 if (ddraw
->device_state
!= DDRAW_DEVICE_STATE_NOT_RESTORED
)
4878 LIST_FOR_EACH_ENTRY(surface
, &ddraw
->surface_list
, struct ddraw_surface
, surface_list_entry
)
4880 surface
->is_lost
= TRUE
;
4882 ddraw
->device_state
= DDRAW_DEVICE_STATE_OK
;
4885 static HRESULT CDECL
device_parent_texture_sub_resource_created(struct wined3d_device_parent
*device_parent
,
4886 enum wined3d_resource_type type
, struct wined3d_texture
*wined3d_texture
, unsigned int sub_resource_idx
,
4887 void **parent
, const struct wined3d_parent_ops
**parent_ops
)
4889 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4890 struct ddraw_surface
*ddraw_surface
;
4892 TRACE("device_parent %p, type %#x, wined3d_texture %p, sub_resource_idx %u, parent %p, parent_ops %p.\n",
4893 device_parent
, type
, wined3d_texture
, sub_resource_idx
, parent
, parent_ops
);
4895 /* We have a swapchain or wined3d internal texture. */
4896 if (type
!= WINED3D_RTYPE_TEXTURE_2D
|| !wined3d_texture_get_parent(wined3d_texture
)
4897 || wined3d_texture_get_parent(wined3d_texture
) == ddraw
)
4900 *parent_ops
= &ddraw_null_wined3d_parent_ops
;
4905 if (!(ddraw_surface
= heap_alloc_zero(sizeof(*ddraw_surface
))))
4907 ERR("Failed to allocate surface memory.\n");
4908 return DDERR_OUTOFVIDEOMEMORY
;
4911 ddraw_surface_init(ddraw_surface
, ddraw
, wined3d_texture
, sub_resource_idx
, parent_ops
);
4912 *parent
= ddraw_surface
;
4914 ddraw_update_lost_surfaces(ddraw
);
4915 list_add_head(&ddraw
->surface_list
, &ddraw_surface
->surface_list_entry
);
4917 TRACE("Created ddraw surface %p.\n", ddraw_surface
);
4922 static void STDMETHODCALLTYPE
ddraw_frontbuffer_destroyed(void *parent
)
4924 struct ddraw
*ddraw
= parent
;
4925 ddraw
->wined3d_frontbuffer
= NULL
;
4928 static const struct wined3d_parent_ops ddraw_frontbuffer_parent_ops
=
4930 ddraw_frontbuffer_destroyed
,
4933 static HRESULT CDECL
device_parent_create_swapchain_texture(struct wined3d_device_parent
*device_parent
,
4934 void *container_parent
, const struct wined3d_resource_desc
*desc
, DWORD texture_flags
,
4935 struct wined3d_texture
**texture
)
4937 struct ddraw
*ddraw
= ddraw_from_device_parent(device_parent
);
4938 const struct wined3d_parent_ops
*parent_ops
;
4941 TRACE("device_parent %p, container_parent %p, desc %p, texture flags %#x, texture %p.\n",
4942 device_parent
, container_parent
, desc
, texture_flags
, texture
);
4944 if (!ddraw
->wined3d_frontbuffer
)
4945 parent_ops
= &ddraw_frontbuffer_parent_ops
;
4947 parent_ops
= &ddraw_null_wined3d_parent_ops
;
4949 if (FAILED(hr
= wined3d_texture_create(ddraw
->wined3d_device
, desc
, 1, 1,
4950 texture_flags
, NULL
, ddraw
, parent_ops
, texture
)))
4952 WARN("Failed to create texture, hr %#x.\n", hr
);
4956 if (!ddraw
->wined3d_frontbuffer
)
4957 ddraw
->wined3d_frontbuffer
= *texture
;
4962 static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops
=
4964 device_parent_wined3d_device_created
,
4965 device_parent_mode_changed
,
4966 device_parent_activate
,
4967 device_parent_texture_sub_resource_created
,
4968 device_parent_create_swapchain_texture
,
4971 HRESULT
ddraw_init(struct ddraw
*ddraw
, DWORD flags
, enum wined3d_device_type device_type
)
4973 struct wined3d_caps caps
;
4976 static const enum wined3d_feature_level feature_levels
[] =
4978 WINED3D_FEATURE_LEVEL_7
,
4979 WINED3D_FEATURE_LEVEL_6
,
4980 WINED3D_FEATURE_LEVEL_5
,
4983 ddraw
->IDirectDraw7_iface
.lpVtbl
= &ddraw7_vtbl
;
4984 ddraw
->IDirectDraw_iface
.lpVtbl
= &ddraw1_vtbl
;
4985 ddraw
->IDirectDraw2_iface
.lpVtbl
= &ddraw2_vtbl
;
4986 ddraw
->IDirectDraw4_iface
.lpVtbl
= &ddraw4_vtbl
;
4987 ddraw
->IDirect3D_iface
.lpVtbl
= &d3d1_vtbl
;
4988 ddraw
->IDirect3D2_iface
.lpVtbl
= &d3d2_vtbl
;
4989 ddraw
->IDirect3D3_iface
.lpVtbl
= &d3d3_vtbl
;
4990 ddraw
->IDirect3D7_iface
.lpVtbl
= &d3d7_vtbl
;
4991 ddraw
->device_parent
.ops
= &ddraw_wined3d_device_parent_ops
;
4992 ddraw
->numIfaces
= 1;
4995 flags
|= DDRAW_WINED3D_FLAGS
;
4996 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
4998 flags
|= WINED3D_NO3D
;
4999 if (!(ddraw
->wined3d
= wined3d_create(flags
)))
5001 WARN("Failed to create a wined3d object.\n");
5006 if (!(ddraw
->wined3d_adapter
= wined3d_get_adapter(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
)))
5008 WARN("Failed to get the default wined3d adapter.\n");
5009 wined3d_decref(ddraw
->wined3d
);
5013 if (!(ddraw
->wined3d_output
= wined3d_adapter_get_output(ddraw
->wined3d_adapter
, 0)))
5015 WARN("Failed to get the default wined3d output.\n");
5016 wined3d_decref(ddraw
->wined3d
);
5020 if (FAILED(hr
= wined3d_get_device_caps(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
, &caps
)))
5022 ERR("Failed to get device caps, hr %#x.\n", hr
);
5023 wined3d_decref(ddraw
->wined3d
);
5027 if (!(caps
.ddraw_caps
.caps
& WINEDDCAPS_3D
))
5029 WARN("Created a wined3d object without 3D support.\n");
5030 ddraw
->flags
|= DDRAW_NO3D
;
5033 if (FAILED(hr
= wined3d_device_create(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
,
5034 NULL
, 0, DDRAW_STRIDE_ALIGNMENT
, feature_levels
, ARRAY_SIZE(feature_levels
),
5035 &ddraw
->device_parent
, &ddraw
->wined3d_device
)))
5037 WARN("Failed to create a wined3d device, hr %#x.\n", hr
);
5038 wined3d_decref(ddraw
->wined3d
);
5042 list_init(&ddraw
->surface_list
);
5044 if (FAILED(hr
= wined3d_stateblock_create(ddraw
->wined3d_device
, NULL
, WINED3D_SBT_PRIMARY
, &ddraw
->state
)))
5046 ERR("Failed to create the primary stateblock, hr %#x.\n", hr
);
5047 wined3d_device_decref(ddraw
->wined3d_device
);
5048 wined3d_decref(ddraw
->wined3d
);